Rotem Bloom's Blog

Share knowledge on .NET development
Unlocker the tool that must for developers

Hi,

Have you ever bump into messeges like:

  • Cannot delete file: Access is denied
  • There has been a sharing violation.
  • The source or destination file may be in use.
  • The file is in use by another program or user.
  • Make sure the disk is not full or write-protected and that the file is not currently in use.

Well when such cases happeneds you really want to know which application lock your Files or Folders.

The Unlocker is the solution for you.

Just look for "unlocker" in Google or Bing or you can download it from here.

Bye Rotem

תוכנה נחמדה לשליחת הודעות טקסט לפלאפון בחינם
היי,
היום שלחה לי מישהי שעובדת איתי בשם: הילה אנינה תוכנה ממש נחמדה שמאפשרת שליחת SMS דרך המחשב בחינם.
אני בטוח שכבר יש תוכנות כאלו ממזמן אבל זו ממש נוחה, פשוטה ומדליקה עם ממשק בעברית.
דרך אגב בדקתי אותה וזה באמת עובד (לפחות בינתיים)
 
להורדה:

http://www.textme.eu.pn/

 
מאוד שימושי וחינםםםםםםםםםםםם תהנו.
 
How to find and reproduce bugs in multi thread applications - CHESS is to tool you must use!!!

Hi All,

If you want to test and reproduce multi thread applications bugs there is a new tool from Microsft called: CHESS.

CHESS is a tool for finding and reproducing Heisenbugs in concurrent programs. CHESS repeatedly runs a concurrent test ensuring that every run takes a different interleaving. If an interleaving results in an error, CHESS can reproduce the interleaving for improved debugging. CHESS is available for both managed and native programs.

Great movie that explain CHESS: An Automated Concurrency Testing Tool

You must adopt this tool for your future multi threaded (concurrent programs) programs.

More information on Threading in C# can be found on Joseph Albahari great article here.

Expert Days 2010 יוצא לדרך שווה ללכת
ימי המומחים מה שידוע גם כ-Expert Days יוצא לדרך ב-22 לנובמבר.
אז בתור אחד שהיה בכנס בשנה שעברה אני ממליץ בחום ללכת לכנס למסלול שמעניין אתכם.
השנה לפי מה שראיתי באתר הכנס שמו דגש על הטכנולוגיות החדשות שאמורות לצאת בשנה הקרובה, לכן אני חושב שכדאי ללכת ולהתעדכן בטכנולוגיות החדשות שאמורות לצאת בשנה הקרובה.
 

מסלולים

מסלול המה חדש בויז'ואל סטודיו 2010 ודוט-נט 4.0 סוקר את כל
החידושים שיהיו בשנת 2010. המסלול מנוהל ע"י ורדי אייל.
מסלול הווב מכסה את כל הנושאים החדשים בתחום הווב שיהיו בויז'ואל סטודיו 2010.
המסלול מנוהל ע"י לנגלייבן ליאון מחברת SRL.
יש הרבה שיטות להתחבר למסד נתונים, אך מהי הדרך הטובה ביותר לארגון?
במסלול זה תיחשפו לכל הטכנולוגיות החדשות בתחום. המסלול מנוהל ע"י ורדי אייל.
WPF או Silverlight זאת השאלה? מסלול זה מביא את כל הטכנולוגיות החדשות
לפיתוח ממשק משתמש. המסלול מנוהל ע"י קוגמן גל.
ויזואל סטודיו 2010 מביא איתו מהפכה בתחום התקשורת, ע"י שיפור משמעותי של
שתי טכנולוגיות קיימות WCF ו-WF והשילוב בניהם. המסלול מנוהל ע"י ורדי אייל.
מסלול SQL Server 2008 מכסה מקצה לקצה את כל התחומים של מסד הנתונים.
המסלול מנוהל ע"י גלנצר גיא מחברת Madeira Information Technologies.
טכנולוגית ה- CRM של מיקרוסופט נכנסה השנה למספר רב של ארגונים, כמערכת CRM וככלי
פיתוח ארגוני. המסלול מנוהל ע"י ארדיטי יניב מחברת E4D Solution.
 
פרטים נוספים באתר http://www.expertdays.co.il/
 
תהנו רותם
 
Sending .NET configuration section over the wire using WCF

Hi,

Have you ever needed to implement configuration sections for the application configuration file? Well probably you have.

Let's say you want to read the configuration section from your *.config file and send it thru WCF service. The default behavior when working with configuration object is use the System.Configuration namespace that doesn't support WCF.

So the question is what can we do?

A nice solution is to use the IConfigurationSectionHandler interface and mark the section implementation as a DataContract.

It will be something like:

[DataContract]

    public class MyConfigurationSectionHandler : IConfigurationSectionHandler

    {

        #region IConfigurationSectionHandler Members

 

        public object Create(object parent, object configContext, System.Xml.XmlNode section)

        {

            DataContractSerializer xs = new DataContractSerializer(typeof(MyConfigurationSectionHandler));

 

            using (XmlNodeReader xnr = new XmlNodeReader(section))

            {

                try

                {

                    var configSection = xs.ReadObject(xnr, false) as MyConfigurationSectionHandler;

                    if (configSection != null)

                    {

                        Applications = configSection.Applications;

                    }

                    return this;

                }

                catch (Exception ex)

                {

                    string s = ex.Message;

                    Exception iex = ex.InnerException;

                    while (iex != null)

                    {

                        s += "; " + iex.Message;

                        iex = iex.InnerException;

                    }

                    throw new ConfigurationErrorsException(

                    "Unable to deserialize an object of type \'" + GetType().FullName +

                    "\' from  the < " + section.Name + "> configuration section: " +

                    s,

                    ex,

                    section);

                }

            }

        }

 

        #endregion

 

        [DataMember(Name = "applications")]

        public Application[] Applications { get;set; }

    }

 

    [DataContract(Name = "application")]

    public class Application

    {

        [DataMember(Name = "name")]

        public string Name { get; set; }

    }

An example for an appropriate configuration section can be something like:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <configSections>

    <section name="MyConfigurationSectionHandler" type="DataContractConfiguration.MyConfigurationSectionHandler, DataContractConfiguration"/>

  </configSections>

  <MyConfigurationSectionHandler xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DataContractConfiguration">

    <applications>

      <application>

        <name>App1</name>

      </application>

      <application>

        <name>App2</name>

      </application>

    </applications>

  </MyConfigurationSectionHandler>

</configuration>

Now we can use the ConfigurationManager to get our configuration object that can also be send over the wire using WCF.

MyConfigurationSectionHandler section = (MyConfigurationSectionHandler)ConfigurationManager.GetSection("MyConfigurationSectionHandler");

I also add small application as an example you can download from here.

Enjoy :-)

Rotem

Insert and Update pattern for multiple threads application with SQL Server

Hi, 

Have you ever try to insert a row in to a SQL table if the key does not exist and update a row if a key exists. Well this is very common scenario.

Usually you would achieve this goal by writing SQL like:

if exists (select * from TestTable where ID = @id)

begin

    update TestTable set myCount = myCount+1  where ID = @id

end

else

begin

  insert into TestTable values (@id, 1)

end

This code will work fine for single threaded applications but will not work for multiple threads application. To solve this issue you need to handle primary key violations and fix up the transactional integrity of the batch.

 So now let's see the solutions:

Option 1:

begin tran

if exists (select * from TestTable with (updlock,serializable) where ID = @id)

begin

  update TestTable set myCount = myCount+1 where ID = @id

end

else

begin

  insert TestTable (ID, myCount) values (@id, 1)

end

commit tran

Option 2:

begin tran

  update TestTable with (serializable) set myCount = myCount + 1 where ID = @id
if @@rowcount = 0

begin

  insert TestTable (ID, myCount) values (@id,1)

end

commit tran

That's all.

Enjoy Rotem

ASP.NET 4.0 and Visual Studio 2010 Enhancements

 Hi All,

If you want to know more about the new ASP.NET 4.0 and Visual Studio 2010 enhancements you can find great screencast here.

Screencast main topics:

Visual Studio 2010

Visual Studio 2010 will feature expanded snippets available in the HTML editor window. These snippets will dramatically change the way you write ASPX markup. For instance, if you were to add a TextBox to the page as soon as you begin typing <asp:TextBox... the snippet will take over and add in the ID and runat attribute.

Further, consider adding a RequiredFieldValidator to the page and the amount of work required in the past to properly configure the control. With the new snippets if you add a validator directly next to the TextBox you created previously, the snippet will automatically fill out the markup for the control, populating the ControlToValidate attribute, add the id and runat attributes and position your cursor inside the ErrorMessage attribute. Hand-coding has never been so easy!

Note: You’ll never have to type runat="server" again!

Further enhancements include the ability to triple-click an expansive element like a table and the editor selects the entire table’s markup. Want to surround that table with some additional markup? Just start typing with the table selected and your markup is inserted around the selected code.

ASP.NET Innovation

The ASP.NET platform has enjoyed a number of out-of-band updates in the form of AJAX, Dynamic Data and MVC, but the core of WebForms has remained without an update for a while. The reason is that the core of WebForms is dependent on System.Web, which is loaded by IIS.

This limitation has the attention of the ASP.NET team and in the future they are looking for ways to ship out-of-band releases on the core of WebForms. Until then we wait for the official release of ASP.NET 4.0 which will include the follow updates to WebForms:

  • Control of Control IDs: ASP.NET developers will finally have total control over the ClientID that is rendered to the page for each control. For simple scenarios you simply provide the ID value and in a data-bound context you can provide the key and replacement tag. For instance if you have a control in a data-bound control and you want the key to be "lbl" then the controls will have IDs consistent with lbl1, lbl2, lbl3 and so on.

    Scott Galloway has an excellent post on the upcoming client ID changes: Way too much information on Control IDs and ASP.NET 4.0 Client Id Enhancements

  • Humble ViewState: Programming on the web often requires storing state somewhere. Using session state is prone to timeouts and can create problems in a server farm/garden environment. Many times the best place to persist data is in the HTML document itself. This logic is what drove the ASP.NET team to first implement ViewState, but an eager implementation (requiring parent controls to enable ViewState and other requirements) created bloated pages with unnecessary ViewState shoved up to the client.

    The next generation of ViewState allows for granular control over which controls require ViewState. The default template for "4.0" project may even have ViewState turned off by default.

  • Dynamic Image Support: ASP.NET will feature rich image support giving developers an easy way to manipulate and maintain images on the web. Features include an image handler base class that is responsible for converting byte arrays to images and back again. A server control that calls the handler and helps pass parameters for uniquely identifying image data as well as stamping for cache support. The cache may be configured to cache on the server, the client or in both locations. Images are manipulated by a set of transforms which include resizing and watermarking among others.

  • IQueryable BusinessLogicDataSource: This new data source will feature query blocks which expose a declarative LINQ syntax to help create dynamic where clauses to append to search queries. The SearchExpression query block allows you to easily add "starts with", "ends with" and "contains" type of constraints to a query. The RangeExpression will read minimum and maximum values to constrain the range of a field. The LINQ syntax is generated when the page data binds sends the fully-constrained to the query to the server once all the parameters are known. Attributes associated with methods on the business logic layer will tell the data source which methods to run to select, insert, update and delete objects. The data source will work against a provider to interface with Linq to SQL, Linq to Enties, POCOs and more.

Dynamic Data

The Dynamic Data updates are spread among solutions for WebForms as well as MVC. Really the term "Dynamic Data" does injustice to the features as really they are becoming simply features of existing and new controls which are really just ASP.NET data controls.

For what you think of today as Dynamic Data, expect to see further work in the following areas:

  • Entity Templates: Much like a field template, but more of a container for markup and DynamicControls which can provide templating for an entire row of data rather than a single field.

  • Database Inheritance: Provide scaffold pages that will recognize database inheritance and provide CRUD capabilities for these tables.

  • Many to Many Relationships: Scaffolding will render check box lists to allow selection of many to many related data. (David Ebbo writes about this new feature in: A ‘Many To Many’ field template for Dynamic Data)

Use the Dynamic Control in a non-List Scenario?

The team is working on strategies for using the DynamicControl in situations where you are displaying a single record (and are outside the context of a list control).

Today a single record would bind to the FormView which supports the DynamicControl. Unfortunately FormView renders as a table in order provide places to hook in CSS classes. The FormView will soon feature a mode where you can turn off markup rendering all together so only the markup you provide is rendered.

There is talk among Scott and his team of the creation of an ItemView which may be a more natural fit for this type of scenario to compliment the ListView control.

Dyanmic Data & MVC

Out of respect of the culture surrounding MVC the team has chosen to implement Dynamic Data support backward to MVC. They began with adding HTML helpers and implementations for field/entity templates and databinding logic, leaving scaffolding for the end. This will ensure that Dynamic Data will work under MVC for those who choose to opt out of the scaffolding features.

In a seemingly controversial move, the team is implementing a version of ViewState for MVC! While the implementation details differ from traditional ViewState found in WebForms the technique of state persistence in a hidden HTML element will find its way to MVC.

In the interview, Scott poses the question of how one might implement optimistic concurrency in an MVC application. You may choose to implement a time stamp field or set aside the previous values for later comparison. If you choose to review old values then the state of this object must persist somewhere. So the team is looking to support developers who may choose a number of different approaches to the same problem.

Future Dynamic Data implementations for MVC will feature a controller with virtual methods for insert, update and delete. Using virtual methods obviously means that developers will have the option to over-ride and replace any methods they see fit.

Resources

Browser and Operating System Detection In ASP.NET

Hi,

Detect user Browser and Operating System version in ASP.NET is very simple using the C# code:

Request.Browser

This code retuns the HttpBrowserCapabilities class that has the information we desire.

Unfortunately the default Browser Caps configuration that come with ASP.NET 2.0 does not include browsers like Google Chrome and I could not find a way of getting the operating system version.

Finally I came up with solution that solve my problem as describe below:

  • On my ASP.NET application I open new ASP.NET folder: App_Browsers.
  • I download updated *.browser files that contain the information on the Google Chrome browser and also the operating system version and copy them to the App_Browsers folder. You can get the updated files from here.

I also attach small ASP.NET project that explain the solution. You can download it from here.

Enjoy Rotem :-)

TreeSize Free - Tells you where precious space has gone to

Hi All,

I use a nice tool that helps me figure out which folders holds the most disk space on my computer. The tool called TreeSize Free and it highly recommended.

Description: 

Every hard disk is too small if you just wait long enough. TreeSize Free tells you where precious space has gone to. TreeSize Free can be started from the context menu of a folder or drive and shows you the size of this folder, including its subfolders. You can expand this folder in Explorer-like style and you will see the size of every subfolder. Scanning is done in a thread, so you can already see results while TreeSize Free is working. The space, which is wasted by the file system, can be displayed and the results can be printed in a report. TreeSize Free is freeware for Windows 2000/XP/Vista.

Screen shot:

TreeSize Free

Visual Source Safe Tip: Open VSS 2005 client without enter user name and password

Hi,
If you want to set VSS (Visual Source Safe) 2005 client default user name and password without type them all the time, you have to do the following steps:
1) right click on VSS 2005 client icon
2) select properties
3) on the "target" at the end add your desire user name and pssword as follow:
-Y,
So you target shuold look like something like:
"C:\Program Files\Microsoft Visual SourceSafe\ssexp.exe" -YMyUser,123456.

This will open your source safe client with current user without opening the user password screen.

Silverlight toolkit: An unknown error occurred running Code Analysis. Please contact Microsoft Product Support Services.

Hi,

I download the Silverlight Toolkit include source code from codeplex. I Open Silverlight.Controls.sln and try to compile it.

I got error saying: "An unknown error occurred running Code Analysis. Please contact Microsoft Product Support Services."

I'm using VS Team System 2008 SP1 with .NET 3.5 SP1.

In order to solve this error I need to go for each Silverlight Project and remove the "Enable Code Analysis on Build" check box. Very irritating don't you think??!!!!

Well I found better solution:

I download the latest FxCop version (1.36) from here and install it on the directory VS 2008 use the FxCop.

On my machine the location was under: C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop

This solve my problem without changing each project "Enable Code Analysis on Build" checkbox.

 I Hope it will help you also Bye Rotem.

Open Multiple Visio Instances (open different visio windows in taskbar)

Hi,

Open multiple Visio documents is possible, but the default Visio behavior is to open multiple document on the sane Visio instance. In order to view each document you need to go to "Windows" toolbar and switch between the Visio documents.

You can change this behavior by simply update the Visio registry key: SingleInstanceFileOpen.

First open Visio and select Tool --> Option --> Advanced and check "Put all settings in Windows Registry".

For Office 2007 the key locate under:

HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Visio\Application\SingleInstanceFileOpen

Update the value from 1 to 0.

Now each Visio document will open in different Visio instance.

לכל בעלי אייפון דור ראשון G2
לכל מי שיש אייפון דור ראשון G2 והוסיף תמיכה בעברית בוודאי שם לב כי לפעמים ישנם תקיעות בכמה מסכים כמו אנשי קשר וכו'...
אתמול פרצתי ושידרגתי את האייפון שלי (כן יש לי דור ראשון) לעברית גירסה 2.2 ובינתיים כל התקיעות הפסיקו והמכשיר עובד הרבה יותר טוב וחלק.
 
אז אני ממליץ לכם לעדכן את המכשיר לגירסה חדשה. מי שצריך עזרה עם העניין מוזמן לפנות אלי, אשמח לעזור.
 
ביי רתם
Amazing Free Uninstaller Application

Hi All,

There is an excellent free Uninstaller Application Revo Uninstaller.

Revo Uninstaller helps you to uninstall software and remove unwanted programs installed on your computer even if you have problems uninstalling and cannot uninstall them from "Windows Add or Remove Programs" control panel applet.

Revo Uninstaller is a much faster and more powerful alternative to "Windows Add or Remove Programs" applet!

How to change ASP.NET CheckBox control Enabled property using javascript. bug or behavior?

Changing status to enabled\disabled for regular input type checkbox in javascript is very simple. You just need to use the javascript code:

var checkBox = document.getElementById("chkToTest");

checkBox.disabled = true\false;

Well try to use this javascript code above on ASP.NET checkbox web control when you set the server side Enabled property to false like below:

chkToTest.Enabled = false;

I'm telling you it will not work!!!!

Do you ask how to solve this bug or behavior?

You just need to set the disabled property of the parent node also. something like this:

var checkBox = document.getElementById("chkToTest");

checkBox.disabled = true;

checkBox.parentNode.disabled = true;

I don't know why but when setting the Enabled property of ASP.NET checkbox web control to false the control also render extra <SPAN> container for the checkbox and put disabled on the <SPAN> container element. So you also have to set the disabled property for this <SPAN> element, otherwise the javascript code will not work.

I wrote small application that demonstrate the problem, you can download it here.

More Posts Next page »