Raba - Defend your code RSS 2.0
# Monday, February 11, 2008

I've tried to write a simple code today GetEverythingButTheFirstElement() -> a code that get the all elements but the first one.

of course I've started with the old fashioned way:

   1:  string[] firstOne = new string[args.Count() - 1];
   2:  for (int i = 1; i < args.Count(); i++)
   3:  {
   5:      firstOne[i - 1] = args[i];
   7:  }

Now I've start refactoring it to something more C#3.0-able and it looks like this one:

   1:  // The method to use as the predicate for the where
   2:  public static bool GetAllElementsButTheFirstOne(string s, int i)
   3:  {
   4:      if (i == 0)
   5:          return false;
   7:      return true;
   8:  }
  10:  //The usage at my code
  11:  IEnumerable<string> secondTemp = args.Where(GetAllElementsButTheFirstOne);

Here happen something strange, the secondTemp do not hold objects in it, looks strange? no! it uses a lazy load thanks to the Linq defaults, so I've added this line at the end:

   12:  string[] secondOne = secondTemp.ToArray<string>();

So I decided to refactor this code a little bit more, I didn't like the string that the Where() force me to write, so I've added my own Where:

   1:  public static class Extensions
   2:  {
   3:      public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<int, bool> predicate)
   5:      {
   6:          for(int i=0; i < source.Count(); i++)
   7:          {
   8:              if (predicate(i))
   9:                 yield return source.ElementAt(i);
  10:          }
  11:      }
  12:  }

This looks awesome now I can write it just like this:

   1:  public static bool GetAllElementsButTheFirstOne(int i)
   2:  {
   3:      if (i == 0)
   4:          return false;
   5:      return true;
   6:  }

But Hey, what do you think about this code?

   1:  IEnumerable<string> thirdTemp = args.Where((int i) => { return i > 0; });

Haaa, now it looks good.

This is not the first time I am writing lambda expression but I still thinking to my self how much I should read&code so this will be my natural way of thinking... for now it take me more time to write it than in the casual way.


Monday, February 11, 2008 11:32:49 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
C#3.0 | LINQ

We are using the ArcGis Explorer as our 3d-Browser, and we would like to create a task.config file for each task. You can read more at my last post about Load config file dynamically (here).

Why this Architecture good for us?
Every one can install its explorer on his computer without any problem, we would like to add our own Task-Specific configurations for example: server-names to connect to, task-screen-size, links to web sites etc.
first, such details you cannot be save to the AGX-installation directory because it already installed. second, we would like to send them again and again every time the task will be updated and downloaded.

Any way, after reading this we still have two questions to answer:

1) how to get to the tasks directory
2) how to find our specific task

The answers for those questions are pretty simple:
1) To get to the task directory you should use this parameters:

   1:  Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\ESRI\ArcGIS Explorer\Tasks";

This answer will solve you the "how to found the tasks directory programmatically" but you'll still have to find the specific task directory that is interesting you.
Anyway, this is good but not good enough. I would like the E2 API to give me its Environment parameters and not to force me to code it by myself. It smell like something that can be change... and I'll be glad if the people at the ArcGis Explorer will create something like: public static class E2Environemnt which will implement such property. For now: we implement our own Environment extensions.

2) To Find the specific task you should dig the black box of E2 and you will find this cool factory:

   1:  ESRI.ArcGIS.E2API.E2TaskFactory factory = new ESRI.ArcGIS.E2API.E2TaskFactory();
   2:  string taskDirectoryName  = factory.GetTaskSubfolderNameFromAssemblyName(currentTask); 

So What's the catch I've asked? This is an internal implementation, ESRI don't like you if you'll use it... (you can read more about my question in the AGX forum). And I will ask just one simple question, why?! why not to make it internal or even private class. why we should read it at the XML comments?!

And here is my preferred solution (as Rob answered in the ArcGis Explorer forum), it make the job for me right now and it is the simple way to do it:

   1:  System.Reflection.Assembly.GetExecutingAssembly().Location;


Monday, February 11, 2008 6:10:38 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
.Net 2.0 | GIS | AGX | Software Development

There are time you would like to load your configuration data from a specific config file or maybe even from the config file but not from the main one, I'll explain it using an example from the real world (last week refactoring).
We have many client which run the ArcGis Explorer (AGX) client (Geographic application like Google Earth), this client can be installed on each and every client, and it has its own configuration files. Within our team we write tasks that running on that AGX. while opening the application it will download to your profile directory the relevant DLL's for running those tasks. but hey those DLL's will be in a separate directory, neither in the GAC nor in the AGX executable directory. You can find many examples for such scenarios.

Here you can see the two different directories: one for the E2.exe and its config file, and the specific task DLL's and its config file (Sample.dll.config)

All we wanted to make is a Task specific configuration. so we would like it to work on every other task we will create.
First you might know this bunch of code, this will help you load the Sample.dll.config file from the wanted directory (The Task directory).

   1:  // Get the application configuration file path.
   2:  string exeFilePath = @"C:\ShaniData\Projects2008\ConfigHandlerDemo\Sample.dll.config"; 
   4:  // Map to the application configuration file.
   5:  ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
   6:  configFile.ExeConfigFilename = exeFilePath;
   7:  System.Configuration.Configuration config =
   8:  ConfigurationManager.OpenMappedExeConfiguration(configFile,
   9:  ConfigurationUserLevel.None);
  11:  ConfigurationSection sec = config.GetSection("MailManagerConfiguration");

In this situation we should use the .Net default ConfigurationSection implementations (for example: the ApplicationSettingsSection). Those of you who think of using the DictionarySectionHandler or NameValueSectionHandler will found it returning the DefaultSection instead.

Pay also attention that your code is running from the AGX installation directory so if you'll write your own section it won't work unless it was installed on the given computer (in GAC or in the AGX installation directory).

Monday, February 11, 2008 3:38:38 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
.Net 2.0 | GIS | AGX

Following my last post about LINQ, Expression Trees & Lambda Expressions I've found this Linq Quiz:

C# 3.0 in a nutshell - LINQ Quiz

Try yourself to see what your is your level and where you can get if you read\code more of this stuff (tip: C# 3.0 in  a nutshell is a great book)


Monday, February 11, 2008 3:13:29 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
C#3.0 | LINQ

# Sunday, February 03, 2008

James, Dave & Doron wrote about the ESRI's API, you could read it here:

  1. Doron's post about replacing the Web-ADF
  2. James Fee - posting about replacing the ADF
  3. Dave Bouwman posting about James & Doron  posting about replacing the Web-ADF

I might add my post, for calling you all GIS Bloggers to help us (in Dave's idea) to create an ALT-ESRI API.
I'll be write even more in the near future...

Sunday, February 03, 2008 11:49:56 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback

# Friday, January 18, 2008

After updating the blog to the 1.9 dasblog version - I hope that now I could write my code better.

int j = 5;
foreach(int i in currentList)
Friday, January 18, 2008 7:49:08 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
My Site

# Wednesday, January 16, 2008

I am not going to explain here nor about MVC neither about the ASP.NET 3.6 (yes it is 3.6, they didn't tell you that?!) I just gonna write a little bit about a sample application I wrote to myself.
Those of you who want to learn more about MVC (the pattern itself) - you can read in Martin Fowler's post or maybe here at wiki anyway there is even a better place to learn this in the Head First - Design Patterns book.
Also you might read about the new asp.net MVC Framework (CTP), you can choose whether to read this (long but very important article) or you can see the intro webcast (damn you lazy programmers)

Microsoft are doing well to cause us work harder just to learn the technology, this asp.net MVC implementation is awesome but It is a huge change for all of you ASP.NET people, I hope I find the time to write more about it, but here is one sample I wrote for myself.

                                       From Request to Response through the MVC Flow

On each request there is a place that the Controller has its constructor calls and this will initiate your logic, I found it very useful to manage this controller creation. In this example I create my own Factory and there I manage to create the controller using another constructor (not the default one), moreover I can also add my own logic such as Security Check (in our sample) or something else useful.

Here is my own Controller Factory logic:

1 public class ShaniControllerFactory : IControllerFactory 2 { 3 #region IControllerFactory Members 4 public bool IsUserExists 5 { 6 get 7 { //Put here your great Logic 8 return false; 9 } 10 } 11 public bool IsUserAuthorizedForEdit 12 { 13 get 14 { //Again Special Logic for Checking Authorization 15 return false; 16 } 17 } 18 19 public IController CreateController(RequestContext context, Type controllerType) 20 { 21 IController controller = null; 22 if (!IsUserExists) 23 { 24 controller = new NotAuthorizedController(); 25 return controller; 26 } 27 28 //Distinct between those two 29 if (!IsUserAuthorizedForEdit) 30 { 31 controller = Activator.CreateInstance(controllerType,(object) false) as IController; 32 } 33 else 34 { 35 controller = Activator.CreateInstance(controllerType, (object)true) as IController; 36 } 37 return controller; 38 } 39 40 #endregion 41 }

You can simply see the CreateController method (lines: 19-38) where I put my logic for the Controls initiation, and I simply prefer creating them using my constructor (the one with the bool parameter) and not using the default one.
But, How will we have this Controller Factory running instead of the generic factory? It is very simple:

1 protected void Application_Start(object sender, EventArgs e) 2 { 3 ControllerBuilder.Current.SetDefaultControllerFactory(typeof(ShaniControllerFactory)); 4 5 RouteTable.Routes.Add(new Route 6 { 7 Url = "[controller]/[action]/[id]", 8 Defaults = new { action = "Index", id = (string)null }, 9 RouteHandler = typeof(ShaniRouteHandler) 10 }); 11 12 RouteTable.Routes.Add(new Route 13 { 14 Url = "Default.aspx", 15 Defaults = new { controller = "Home", action = "Index", id = (string)null }, 16 RouteHandler = typeof(ShaniRouteHandler) 17 }); 18 } 19

You can see at line 3 (within the Global.asax), this is all I had to do for setting my controller factory as the default factory.

You can also think about another good examples on your own, I've found a great post about TDD and Dependency injection with asp.net MVC by Phil Haack - Read the whole post it is a great one, at the end he is creating his own factory for managing the Control creation using Dependency Injection.


Wednesday, January 16, 2008 12:04:15 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
Asp.net MVC

# Tuesday, January 01, 2008

My managers came to me and told me that I must take a vacation for the end of the year. So I found myself yesterday on the night of the new year at the kitchen start cooking a special dinner to my girlfriend (vacation means no work at home too).
I already cooked before but this time I tried Sushi, all you out there it is damn easy (and delicious), try this at home.

Here are some pictures from my first Sushi (pictures taken using my Logitech Quickcam) -


Here are some good links (Sushi-Casts) for all of you PC-boys out there (without kitchen experience):


Sushi & Software development:

Making Sushi (or food) is like coding, first you need to know the language (ingredients), afterward you need a little debugging while cooking or doing your stuff (integrating the ingredients together) and at the end you need to listen to the users, So: I am waiting to you, my friends, to come and taste it.

You also need a prototype for starting, after the first prototype you will probably need to make some changes, this things you can't learn from watching videos or reading books alone, you need to roll up your sleeves and start working.

Special thanks to Nati (the Sushi master).

Tuesday, January 01, 2008 2:36:35 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback

# Friday, December 21, 2007

The new version of AGX is out, you can found more details in here.

Here are some things I found out:

  • My old tasks works
  • Tab index (inside the tasks) is finally working properly
  • The streaming looks slow - even very slow I'm not sure if this is because of my networks problems or because of ESRI's servers but it was better with the previous version
  • Better handling the outer links (having a bug while opening a site it also opens: "about:blank" empty window near it)
  • More cool icons for instead of the simple pushpins

Still (really) missing

  • Scale bar (on the bottom of the page, or even in task)
  • Simple "Add connection" to Google Maps (servers) & Virtual Earth (servers)
  • SDK for 2008 (The given one fits to 2005 only)

Here is a simple result I make using the new popup window:


Friday, December 21, 2007 1:42:07 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback

# Saturday, December 15, 2007

After one year of implementing Scrum at my place, I was asked to give a lecture to a new Team-Leaders, This Wednesday I will have my first Scrum Session, I spent a lot of time for the last few weeks to create a cool Presentation, I've also spent some time reading lots of data (some of them even more than once) about the Agile manifesto and its different methodologies.

I will update later on about the first session (next week). But to my readers I will give one great tip, two books bonus for a better start for your agile development:

Agile Software Development - Alistair CockBurn

This two books are "better together" - While reading them both you will understand:

  1. Why to choose Agile (Or: The Values of the Agile manifesto)
  2. Better Understanding for the problems within methodologies (Not only the non-Scrum ones)
  3. What is agile at all - I've found many people not understanding the meaning of being Agile.
  4. What is the difference between the methodologies (Scrum, XP, Crystal etc.)
  5. Implementation (especially Scrum at Ken Schwaber's book)
  6. and many samples from the experienced writers.

And here are some bonus links to my learning phase for the last year (stories from the last year as a Scrum-Master):

  1. Scrum methodology - the scrum master
  2. Trying to manage the team-pace better (or- Entering to Scrum For TeamSystem Template)
  3. Improve your scrum Environment
  4. Scrum for Team system feature requests

And here is one article I've found while start writing (back in the past while I didn't even know about being Agile)

  1. Acceptance Tests

I hope you will enjoy those books (and links).

Saturday, December 15, 2007 11:31:58 AM (GMT Standard Time, UTC+00:00)  #    Comments [1] - Trackback
Agile | Scrum

<February 2008>

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2015
Shani Raba
Sign In
Total Posts: 146
This Year: 0
This Month: 0
This Week: 0
Comments: 97
Cool Stuff
Add to Technorati Favorites
Pick a theme:
All Content © 2015, Shani Raba
DasBlog theme 'Business' created by Christoph De Baene (delarou)