Arthur Zubarev

Compudicted

  Home  |   Contact  |   Syndication    |   Login
  26 Posts | 1 Stories | 18 Comments | 0 Trackbacks

News

Visual Studio 2010 will launch on April 12th!

Twitter












Archives

Image Galleries

Computing

Monday, January 11, 2010 #

Last week I was asked to test a small applet written by my colleague that could make Windows Mobile 5 device's local (system) date and time updated or set based on date/time received from an outside. The application used the .Net technology.
 
What stroked me was how elegant and simple the application was.
I also knew how to do this on a Windows server or client machine, but then spotted a difference: the only change was in using coredll.dll versa kernel32.dll (for a PC)! So simple, but the difference can be more than subtle for someone. So I have decided to share the code:
 
01 using System;
02 using System.Runtime.InteropServices;
03 using System.Collections.Generic;
04 using System.Text;
05 using System.IO;
06
07 namespace TimeSyncer
08 {
09     class TimeSync
10     {
11         [DllImport("coredll.dll")]
12         private extern static uint SetSystemTime(ref
13         SYSTEMTIME lpSystemTime);
14
15         private struct SYSTEMTIME
16         {
17             public ushort wYear;
18             public ushort wMonth;
19             public ushort wDayOfWeek;
20             public ushort wDay;
21             public ushort wHour;
22             public ushort wMinute;
23             public ushort wSecond;
24             public ushort wMilliseconds;
25         }
26
27         static int Main(string[] args)
28         {
29
30             LogMsgToFile("Application Started.");
31
32             DateTime serverDateTime;
33
34             if (args.Length == 0)
35             {
36                 System.Environment.Exit(1);
37             }
38             else
39             {
40                 try
41                 {
42                     // Obtained the date and time from the
43                     outside, e.g. a time server
44                     serverDateTime = DateTime.Parse(args[0]);
45                 }
46                 catch (System.FormatException)
47                 {
48                     System.Environment.Exit(1);
49                 }
50             }
51
52             SYSTEMTIME st = new SYSTEMTIME();
53
54             TimeSync tsync = new TimeSync();
55
56             DateTime updatedDateTime = tsync.GetDateTime(
57             serverDateTime);
58
59             st.wYear = (ushort)updatedDateTime.Year;
60             st.wMonth = (ushort)updatedDateTime.Month;
61             st.wDay = (ushort)updatedDateTime.Day;
62             st.wHour = (ushort)updatedDateTime.Hour;
63             st.wMinute = (ushort)updatedDateTime.Minute;
64             st.wSecond = (ushort)updatedDateTime.Second;
65
66             uint nReturn = SetSystemTime(ref st);
67
68             return 0; // as success
69         }
70
71         public DateTime GetDateTime(DateTime currentDateTime)
72         {
73             int hourOffsetValue;
74
75             // *** Converting time to GMT
76             // e.g. add 5 hours to the server supplied time
77             to make it GMT if it was sent from EST
78             // * modify the value below to suite your time
79             server input zone location
80             hourOffsetValue = 5;
81             currentDateTime = currentDateTime.AddHours(
82             hourOffsetValue);
83
84             return currentDateTime;
85         }
86     }
87 }
Share it: submit to reddit Digg It! or Bookmark it!

Wednesday, December 16, 2009 #

Further to my post on MS "Velocity" - a must watch video http://microsoftpdc.com/Sessions/FT26 to expand your outlook.


Tuesday, November 17, 2009 #

Some time ago I was asked to fix the following issue on a MS Vista Home Premium SP1 desktop:

a user would be constantly getting a black or blank screen after booting into the PC.

After doing some initial research first using the most popular search engines I was not able to arrive to the proper solution.

How I did resolved it:

I noticed that I can click Ctrl-Shift-Esc after the OS booted to get to the Windows Task Manager.

What stroke me was that Explorer.exe process was not listed in it! As a side note, Explorer.exe is the process responsible for loading the Desktop [view].
This is exactly I thought what I need.

I started it by using File|New Task (Run...) and typing in Explorer.exe.
At this stage the Desktop magically appeared, hooray, no more black screen!

Now I needed to figure out why it would not come up again after a restart.

So I went to the Start menu and found the Windows Explorer in there (in Accessories), did a right-click on it,
and in the security tab I saw "Run as Administrator" enabled, that was not a typical setting, however that looked legit to me.
Nevertheless, I decided to disable that option and restart Windows.

At this point and onwards new sessions started normally, without the black/blank screen coming anymore.

PS: I do not know why this setting exists if by enabling that it leads to such serious consequences.


Tuesday, June 30, 2009 #

After some time working on another SQL CLR I am getting an error

Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=' failed.

This procedure needed to access a stored procedure on a remote server. Running that stored procedure within SQL Server Management Studio completed successfully. It just would not execute from my SQL CLR !

Doing online research did not lead to a solution.

Nearly completely tired I dropped by my DBA with this issue who decided to add SQL Account of the target SQL Server to the SQL Server box I was running this stored procedure on and bum no more issue !


I was doing some new CLR Stored Procedures in SQL Server 2005 and at a certain point received error:

CREATE ASSEMBLY failed because method 'MyMethod' on type 'StoredProcedures'
in safe assembly 'MyAssembly' is storing to a static field. Storing to a static field is not allowed in safe assemblies.

Interestingly, despite all the procedures inside SQL CLR stored procedures have to be declared as static, no static fields are allowed outside them. So in my case declaring a static variable outside SqlProcedure.

[Microsoft.SqlServer.Server.SqlProcedure]

attribute caused this error.

So if you really want to share state outside stored procedures using SQL Server 2005 you will need to be creative.

In SQL Server 2008 this can be done using table variables.


Monday, May 04, 2009 #

Developing With Velocity - Phase II

In my limited testing environment I have decided to try only the basic sample of MS Velocity found in CTP2 Samples, and what I thought would be the most often used properties of Velocity.

By default, the Velocity's DistributedCache service after the installation is not running and is set to manual start, so to begin working with it you will need to launch it. This can be done using the admin PowerShell applet or by starting the Microsoft project code named “Velocity” Windows Service. I opted for using the PowerShell Administration tool. To use it double-click the icon of the admin tool and type in Start-CacheCluster. You must see a success message in the following form:

Velocity Start

The service status column displaying word UP means the DistributedCache is running. If you have changed the default port then it is time to memorize it now before starting coding.

At this point one may want to review the settings of the Distributed Cache. To do so issue a Get-CacheConfig command and a window will populate with the basic configuration settings:

If you wondered what High/Low Watermark parameter means, it is a memory consumption threshold. This has to do with the eviction process of cached objects. Let's leave it out for now, but this is an interesting item to explore.

Now let's get our feet wet! To code against the DistributedCache one needs VS2008 and .NET 3.5 installed. Well, I would like to tell you right here that the CTP2 samples are not running out of the box with MS Velocity CTP3.

But do not get disappointed, I needed about 30 minutes to skim through the code and apply all the necessary changes to make the sample working. Besides, I can share my updated version of the SampleTest on demand with whoever does not wish spend time editing the code sample. The important thing that the help file accompanying CTP3 outlines all the changes between the two CTPs. This file is also very helpful in understanding the concepts behind and the base model of MS Velocity.

I guess any typical client app will require some preparations, so is in the sample, the first step is to configure the client.

We do it by defining the Cache Server Endpoint 

DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];

//  Parameter 1 = host name
//  Parameter 2 = cache port number
//  Parameter 3 = cache service name
servers[0] = new DataCacheServerEndpoint("localhost", +
             22233, "DistributedCacheService");

and create the cache factory

//Pass configuration settings to cacheFactory constructor
myCacheFactory = new DataCacheFactory(servers,false, true);

False is used here to specify that it is not a routing client and true is for using local cache.

The last step is to add the reference to the cache like that:

//Get reference to named cache called "NamedCache1"
myDefaultCache = myCacheFactory.GetCache("default");

Hooray, we are ready to run our sample tests!

The SampleTest CTP2 is a console application, but it is enough to provide one with enough information on the capabilities and get the sense of power the MS Velocity has to offer.

There is a number of tests that will be executed in a manner as displayed at the very top image. The code for the very first test looks like this:

I hope I encouraged you to explore Velocity further and do your own experiments.


Friday, May 01, 2009 #

Velocity - Installation Phase

Today I have proceeded with the installation of the MS Velocity CTP3.

I would like to mention that first one needs to verify one's system for prerequisites. Basically the most up to date components as a Service Pack of the Windows OS and the latest .Net Framework are needed, also PowerShell 1.0 is a required component because the administration can be later done using PowerShell applets.

I also recommend reading the velocity_help.chm file that can be downloaded separately. It includes very valuable information on the ways of installing the product. It helped me to understand the concepts of the implementation and make decisions about how I want Velocity configured in my environment.

Because my goal was to experiment with Velocity and because it was a CTP I have decided to install it and its shared cache on my computer locally using the Folder Share mode. By the way it is a very acceptable scenario for a production system too.

I have made a folder of my choice shared accepting the defaults and without doing any special security settings. Need to note here that the setup will add the Network Service to it allowing change and read operations.

The actual download was actually small so in a few seconds I was presented with the setup screen and asked to fill in the basic info as the project installation location.

Overall, the installation tool is very intuitive, so one should feel comfortable about the whole setup process.

Next, I was asked by the Windows Firewall if to allow communicating with the Velocity instance and I agreed.

Then, while the main installation window continued running, a Cache Host Configuration screen (above) popped up that contained initial set up information parameters. I have changed the settings to reflect my choice. One small side note I would like to mention: if you are installing on a local machine to a shared folder you will need to type the path to it in as UNC path.

Next I was able to test the settings and name my cluster instance. At this stage I saw two MS SQL Server Compact databases named ClusterConfig.sdf and ConfigStore.sdf created in the shared folder.

I was able to see the final success message on the installer tool and a shortcut put onto the Desktop leading to the PowesShell based Administration tool for Microsoft Distributed Cache.

That's it, I am ready to test the waters!



Thursday, April 30, 2009 #

Here at work we have recently came to a need to share lots of data between a large amount of data consumers.

The data share had to be highly available, reliable, yet fast and simple to access.

Without thinking twice creating a database looked like an option. However, given the complexity it adds to maintain yet another database and the costs associated we rushed ourselves to a quest of seeking for alternatives.

While some were poking around the Web I reached out to Scott Hanselman who instantly suggested we use Velocity and who also had a Podcast on it back in June 2008. Besides, since then the Microsoft's project has advanced to CTP3 stage and seems like it is nearing the RTM.

As per the MSDN, Velocity is an implementation of a "highly scalable in-memory application cache for all kinds of data".

At first I murmured to myself, why another if we already have the in-memory caching capabilities with .Net Enterprise Library Caching Block?

Well, nothing is all that simple, it turned out, Velocity has a number of superior features. To me most notable are:

  • Auto-balancing
  • Access to cache is simple, any CLR object can be used to put inside it
  • Can be part of a database (clustered) or in a folder share or even in embedded mode
  • Can work with ASP.NET
  • Concurency model includes pessimistic or optimistic conflict resolution
  • Nearly any programming language can be used to develop with Velocity
  • Can be implemented probably on several dozen servers, thus providing enormous redundancy and scalability

This array (besides, it is only a subset) of features looks very impressive to me and wet my appetite to try the product out.

For most recent news or changes I suggest you refer to the team's blog at http://blogs.msdn.com/velocity/

The product has an active forum at http://social.msdn.microsoft.com/forums/en-US/velocity/threads/

I would recommend architects or lead developers to get yourself familiar with the forthcoming product.

I would download the latest CTP to try to experiment with it, time permits, and report back to you how does it feel like working with Velocity.

 

 


Sunday, April 26, 2009 #

Code Camp 2009

Toronto Code Camp 2009

It was my second attendance of the Toronto Code Camp and it is another success.

As you can see on the left we also had lots of fun, on the picture Joey deVilla who's blog I am reading regularly came to cheer the audience up, he was singing Britney's "One more time" with his accordion!

This event is always free and never happens during work week, lunch is also provided which makes it a great opportunity to spend some time and get some "fresh [development] air".

I have especially enjoyed the presentation by Kristina Mandekic on ADO.NET Data Services, I am looking forward to implementing this technology at work.

For those who did not attend or missed a presentation - stay tuned and visit the Toronto Code Camp's website some time later to get the video-casts of the material presented.


Thursday, April 23, 2009 #

Everyone knows what Twitter is today. Has anybody heard of Jaiku? Well, me neither, until today!

Apparently Twitter got competition. My cursory look revealed that Jaiku is more feature reach and options laden than Twitter.

Jaiku is operated by Google, so if you already have GMail getting in contact with your friends is a breeze. Additionally, anyone can operate its engine (JaikuEngine) and it is Open Source (sweet)! Go to http://tinyurl.com/awkpcf for more info.

Just go and explore it or join me on Jaiku http://arthurz.jaiku.com/

 My Jaiku presence

Cheers!