Raba - Defend your code RSS 2.0
# Tuesday, March 18, 2008

I've read Avi Wortzel's great post "Host Multiple services in windows service". Avi create his own Windows Service which on start knows to also start other services such as: Simple Windows Service and WCF Service.
At my place one of my developers, Elad (blog-less), wrote a spike for running our own Windows Service which can manage all Wcf Services in a given dll, (we didn't like the usage of IService which cause us to change the Wcf Service and implement a specific methods for windows - while the WCF team works hard to cause the framework to be generic to all hosts) . In Elad's solution we will iterate over the dll's classes which had the [ServiceContractAttribute] above it. And now: while turning on\off the main (windows) Service it will also start\shutdown all existing WCF Services.

Today I dig a little bit the MSDN and the IDE directory and found WcfSvcHost.Exe which also knows to start\stop all Wcf Services in a given DLL.
This one is great, it even had its own UI to manage each service by itself.

running WcfService using WcfSvcHost
                        Here you can see me running Wortzel's WcfService using WcfSvcHost.exe with no code written at all.

I didn't test the whole functionality of this application, but it looks good enough for your basic services and samples, I still believe that on sophisticated scenarios we will still need to use Avi's-like-code.

Tuesday, March 18, 2008 11:18:30 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
.Net 3.5 | WinFX | WCF

# Monday, March 17, 2008

Next Month: 6-8 April, I'll participate at Teched.

I can't wait to meet the people and talk about technology, I invite you to communicate me using "Face2Face Meeting Service"

press the image below to redirect to the Face2Face Meeting Service

You can also leave a comment at my blog or contact me by Email.

 

Here are some of the subjects I am working with on  a daily basis, let's talk about it:

  • .Net & Architectures (WCF, Code Generators, LINQ, ASP.Net MVC, Silverlight)
  • Team foundation server (Scrum Templates, Continuous Integration, Daily Build)
  • Agile development (Scrum masters, TDD, Pair programming)
  • GIS (ESRI, Alt-ESRI, ArcGIS Explorer)

 

Let's Talk-Ed.

Monday, March 17, 2008 10:15:13 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
Life | My Site

# Monday, March 03, 2008

There is a new (google) group for the ArcDeveloper.Net (or may we call it Alt-ESRI)
Help us to give you a better API.

Monday, March 03, 2008 9:39:07 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
.Net 3.5 | GIS | ArcGis Server | Software Development | WCF

Last Thursday Nati & I gave two days lecture (as I've already talked about last week)

The first was day dedicated to explain SOA buzz & the WCF basic samples to resolve the plumbing's Hell.
The second day was dedicated to a deep_WCF_dive.
We also had two Hands On Labs samples to assist the students in practicing the daily issues.

Here you can find the two presentations (day #1, day #2) you can also read more about the two days course at Nati's post.

For me it was the first time doing such lecture & HOL - I had a great time and would probably do it again...

 


The presentations were inspired by:

Monday, March 03, 2008 9:20:12 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
Life | WCF

# Friday, February 22, 2008

This post is a test case

 

   1: using (AddIn.CodeSnippet())   
   2: {   
   3:     TestThisMethodInMyBlog();
   4:     I.HopeItWillFinallyWorkInBothBlogAndRssReaders();
   5: }

 

 

Hope it will work

Friday, February 22, 2008 4:58:09 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
My Site

Next week Nati & I going give a two days lecture (& hands-on-labs) about WCF.
I am setting some good tools on my laptop for the presentation, Here is part of the list I've installed till now:

  1. TestDriven.net: http://www.testdriven.net/
  2. ZoomIt v1.72:  http://www.microsoft.com/technet/sysinternals/Miscellaneous/ZoomIt.mspx
  3. ToDo List 2 - for organizing my tasks: http://www.codeproject.com/KB/applications/todolist2.aspx
  4. Cool Commands 4.0 (Vs 2008):

I am still looking for more cool tools.
feel free to leave a post about more cool tools - for a better show (presentation).

Friday, February 22, 2008 12:17:39 AM (GMT Standard Time, UTC+00:00)  #    Comments [2] - Trackback


# 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:  {
   4:   
   5:      firstOne[i - 1] = args[i];
   6:   
   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;
   6:   
   7:      return true;
   8:  }
   9:   
  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)
   4:    
   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.

Cheers.

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;

Enjoy.

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"; 
   3:   
   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);
  10:              
  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)

Enjoy.

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;
GoGoPowerRangers();
foreach(int i in currentList)
   Console.Write(i);
 
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.

Enjoy.

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

Archive
<March 2008>
SunMonTueWedThuFriSat
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345
Disclaimer

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

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