Dimitar Kapitanov's blog Dimitar Kapitanov's blog http://blogs.telerik.com/DimitarKapitanov/Posts.aspx http://backend.userland.com/rss Getting Started with ADO.NET Data Services and Telerik Open Access &ndash; Step IV <p>Just a quick follow-up: we uploaded the application sample as a code library item named <em><strong>"Using OpenAccess with SilverLight and Ado.Net Data Services"</strong></em> <p>and it is available at: <a href="http://www.telerik.com/community/code-library/orm/general/using-openaccess-with-silverlight-and-ado-net-data-services.aspx">http://www.telerik.com/community/code-library/orm/general/using-openaccess-with-silverlight-and-ado-net-data-services.aspx</a></p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-12-16/getting_started_with_ado_net_data_services_and_telerik_open_access_ndash_step_iv.aspx Dimitar Kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-12-16/getting_started_with_ado_net_data_services_and_telerik_open_access_ndash_step_iv.aspx 7057e5cc-dea1-4f3f-89d5-2ef1a9826a92 Tue, 16 Dec 2008 11:59:32 GMT Getting Started with ADO.NET Data Services and Telerik Open Access &ndash; Step III <p>After we prepared our data service it is time to put some client UI into it. I must apologize in advance as the only UI that I’ve used is a ListBox control, and it looks… well pretty much ugly. The goal was to proof that the whole setup works as expected, not to design a profound UI solution. I am pretty sure that as a follow up, our SilverLight team will enhance the sample to a full-scale integration example very soon. <p>To start with, add a SilverLight application in your solution: <p>&nbsp;</p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_2_2.sflb"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="257" alt="image" src="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_thumb_2.sflb" width="396" border="0"></a> </p> <p>&nbsp;</p> <p>In the process of adding you will have to setup where the SilverLight will be hosted: <p><a href="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_4_1.sflb"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="253" alt="image" src="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_thumb_1_1.sflb" width="284" border="0"></a> </p> <p>This is also doable from the settings of the web project: invoke the context menu on your web site project then go to <b>Property Pages &gt; SilverLight Applications &gt; New… </b>and add/setup the SilverLight project. <p><a href="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_6_1.sflb"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="219" alt="image" src="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_thumb_2_1.sflb" width="383" border="0"></a> </p> <p>&nbsp;</p> <p>After we successfully have made the setup, we can start enhancing our SilverLight application. <p>The first thing to notice is inside the code-behind class generated for the data service. It includes two classes named : <pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">OADataContext </span>: <span style="color: blue">global</span>::System.Data.Services.Client.<span style="color: #2b91af">DataServiceContext</span></pre><a href="http://11011.net/software/vspaste"></a> <p>and</p><pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">Product</span></pre><a href="http://11011.net/software/vspaste"></a> <p>The first class implements the client-side data context (you can name it a proxy if you want) that is the entry point for the service. The <strong>Product</strong> class is the entity that is being handled by the service. <p>To be able to track changes to the entities that are processed in the <strong>SilverLight</strong> we have to implement the <strong>INotifyPropertyChanged</strong> interface for the <strong>Product</strong> entity. It is not implemented by default; my guess is because that way the code is not polluted with an enormous set of auto-generated overrides or partial implementations. We can do so in a partial class. Just add a class file named <strong>ProductPartial.cs</strong>, and inside define the partial class like:<pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">Product </span>: <span style="color: #2b91af">INotifyPropertyChanged</span></pre><a href="http://11011.net/software/vspaste"></a> <p>What we have generated inside the Product class are properties like: <p>&nbsp;</p><pre class="code"><span style="color: gray">/// &lt;summary&gt; /// </span><span style="color: green">There are no comments for Property ProductName in the schema. </span><span style="color: gray">/// &lt;/summary&gt; </span><span style="color: blue">public string </span>ProductName { <span style="color: blue">get </span>{ <span style="color: blue">return this</span>._ProductName; } <span style="color: blue">set </span>{ <span style="color: blue">this</span>.OnProductNameChanging(<span style="color: blue">value</span>); <span style="color: blue">this</span>._ProductName = <span style="color: blue">value</span>; <span style="color: blue">this</span>.OnProductNameChanged(); } } <span style="color: blue">private string </span>_ProductName;</pre> <p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p> <p>The basic pattern is to not allow overrides of the properties, but rather implement partial methods that have their signatures generated for example <strong>OnProductIDChanging(value)</strong> and <strong>OnProductIDChanged()</strong> that are called prior to and after setting the field value. We are interested only in the event that gets fired after the value is changed, so we will override for example the <strong>OnProductNameChanged</strong> method so that it will fire the change notification event:<pre class="code"><span style="color: blue">partial void </span>OnProductNameChanged() { FirePropertyChanged(<span style="color: #a31515">"ProductName"</span>); }</pre> <p><span style="color: gray">/// &lt;summary&gt;<br>/// </span><span style="color: green">Fires the property changed.<br></span><span style="color: gray">/// &lt;/summary&gt;<br>/// &lt;param name="propertyName"&gt;</span><span style="color: green">Name of the property.</span><span style="color: gray">&lt;/param&gt;<br></span><span style="color: blue">void </span>FirePropertyChanged(<span style="color: blue">string </span>propertyName)<br>{<br>&nbsp;&nbsp;&nbsp; <span style="color: blue">if </span>(PropertyChanged != <span style="color: blue">null</span>)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PropertyChanged(<span style="color: blue">this</span>, <span style="color: blue">new </span><span style="color: #2b91af">PropertyChangedEventArgs</span>(propertyName));<br>&nbsp;&nbsp;&nbsp; }<br>}</p> <p>&nbsp;</p> <p>We iterate the operation for all Product properties that we know will be changed, and we require the change to be persisted on the server. Actually there is a lot of “data plumbing” code to be written in SilverLight, but I am sure the guys at Microsoft will address this issue pretty soon. <p>&nbsp;</p> <p>So after we implemented the missing part of our Product entity, lets see how the actual UI is bind and behaves. What I have put on the page is a simple ListBox that shows the products and two buttons – the first one changes the <b>ProductName</b> property of the first product in the list, and the second one pushes the change back to the server.</p> <p>&nbsp;</p> <p>The definition of the listbox is the bare minimum to show data: <p>XAML</p><pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">ListBox </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="listBox1" </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">="Stretch" </span><span style="color: red">Grid.RowSpan</span><span style="color: blue">="1" </span><span style="color: red">Grid.Row</span><span style="color: blue">="0" </span><span style="color: red">VerticalAlignment</span><span style="color: blue">="Stretch" </span><span style="color: red">ItemsSource</span><span style="color: blue">="{</span><span style="color: #a31515">Binding </span><span style="color: red">Mode</span><span style="color: blue">=OneWay}" &gt; &lt;</span><span style="color: #a31515">ListBox.ItemTemplate</span><span style="color: blue">&gt; &lt;</span><span style="color: #a31515">DataTemplate</span><span style="color: blue">&gt; &lt;</span><span style="color: #a31515">StackPanel </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="DisplayListData" </span><span style="color: red">Orientation</span><span style="color: blue">="Horizontal" </span><span style="color: red">VerticalAlignment</span><span style="color: blue">="Bottom" </span><span style="color: red">Margin</span><span style="color: blue">="5" &gt; &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="ProductID" </span><span style="color: red">Text</span><span style="color: blue">="{</span><span style="color: #a31515">Binding </span><span style="color: red">ProductID</span><span style="color: blue">}" </span><span style="color: red">Margin</span><span style="color: blue">="5,0,0,0" </span><span style="color: red">VerticalAlignment</span><span style="color: blue">="Bottom" </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">="Left" </span><span style="color: red">FontSize</span><span style="color: blue">="12"&gt; &lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt; &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="ProductName" </span><span style="color: red">Text</span><span style="color: blue">="{</span><span style="color: #a31515">Binding </span><span style="color: red">ProductName</span><span style="color: blue">}" </span><span style="color: red">Margin</span><span style="color: blue">="5,0,0,0" </span><span style="color: red">VerticalAlignment</span><span style="color: blue">="Bottom" </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">="Left" </span><span style="color: red">FontSize</span><span style="color: blue">="12"&gt; &lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt; &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="UnitPrice" </span><span style="color: red">Text</span><span style="color: blue">="{</span><span style="color: #a31515">Binding </span><span style="color: red">UnitPrice</span><span style="color: blue">}" </span><span style="color: red">Margin</span><span style="color: blue">="5,0,0,0" </span><span style="color: red">VerticalAlignment</span><span style="color: blue">="Bottom" </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">="Left" </span><span style="color: red">FontSize</span><span style="color: blue">="12"&gt; &lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt; &lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt; &lt;/</span><span style="color: #a31515">DataTemplate</span><span style="color: blue">&gt; &lt;/</span><span style="color: #a31515">ListBox.ItemTemplate</span><span style="color: blue">&gt; &lt;/</span><span style="color: #a31515">ListBox</span><span style="color: blue">&gt;</span></pre> <p><a href="http://11011.net/software/vspaste"></a>and the two buttons:</p> <p>XAML</p><pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Button </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="Push" </span><span style="color: red">Grid.Row</span><span style="color: blue">="1"&gt; &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="BProductName" </span><span style="color: red">Text</span><span style="color: blue">="Change object named {Binding ProductName} to ModifiedXXX" </span><span style="color: red">Margin</span><span style="color: blue">="5,0,0,0" </span><span style="color: red">VerticalAlignment</span><span style="color: blue">="Bottom" </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">="Left" </span><span style="color: red">FontSize</span><span style="color: blue">="12"&gt; &lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt; &lt;/</span><span style="color: #a31515">Button</span><span style="color: blue">&gt; &lt;</span><span style="color: #a31515">Button </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="Save" </span><span style="color: red">Grid.Row</span><span style="color: blue">="2"&gt; &lt;</span><span style="color: #a31515">TextBlock </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="SaveText" </span><span style="color: red">Text</span><span style="color: blue">="Save Changes to the server using ADS." </span><span style="color: red">Margin</span><span style="color: blue">="5,0,0,0" </span><span style="color: red">VerticalAlignment</span><span style="color: blue">="Bottom" </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">="Left" </span><span style="color: red">FontSize</span><span style="color: blue">="12"&gt; &lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt; &lt;/</span><span style="color: #a31515">Button</span><span style="color: blue">&gt;</span></pre> <p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p> <p>The first thing that we do inside the code-behind is to initialize the data service context in the constructor:</p><pre class="code"><span style="color: blue">public </span>Page() { InitializeComponent(); <span style="color: green">// Create the Service class specifying the location of the ADO.NET Data Services </span>context = <span style="color: blue">new </span><span style="color: #2b91af">OADataContext</span>(<span style="color: blue">new </span><span style="color: #2b91af">Uri</span>(<span style="color: #a31515">"OADataService.svc"</span>, <span style="color: #2b91af">UriKind</span>.Relative)); <span style="color: green">// We use the Async pattern (BeginExecute/EndExecute) everywhere because oft the disconnected nature of // the application. </span>context.BeginExecute&lt;<span style="color: #2b91af">Product</span>&gt;(<span style="color: blue">new </span><span style="color: #2b91af">Uri</span>(<span style="color: #a31515">"Products"</span>, <span style="color: #2b91af">UriKind</span>.Relative), loadProductsCallback, context); }</pre> <p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p> <p>What you really have to understand is that we always use asynchronous way of working with data in SilverLight, because of the nature of the data services that we use. The real job is done in the callback method that gets executed when the service logic finishes processing the communication part:</p><pre class="code"><span style="color: blue">private void </span>loadProductsCallback(<span style="color: #2b91af">IAsyncResult </span>asyncResult) { <span style="color: #2b91af">DataServiceContext </span>ctx = asyncResult.AsyncState <span style="color: blue">as </span><span style="color: #2b91af">DataServiceContext</span>; <span style="color: blue">this</span>.products = ctx.EndExecute&lt;<span style="color: #2b91af">Product</span>&gt;(asyncResult).ToList(); <span style="color: blue">foreach </span>(<span style="color: #2b91af">Product </span>product <span style="color: blue">in </span>products) { <span style="color: green">// Wireup Change Notification </span>product.PropertyChanged += <span style="color: blue">new </span><span style="color: #2b91af">PropertyChangedEventHandler</span>(product_PropertyChanged); } <span style="color: blue">this</span>.listBox1.DataContext = products; <span style="color: green">// ctx.EndExecute&lt;Product&gt;(asyncResult); </span><span style="color: blue">this</span>.Push.Click += <span style="color: blue">new </span><span style="color: #2b91af">RoutedEventHandler</span>(Push_Click); <span style="color: blue">this</span>.Save.Click += <span style="color: blue">new </span><span style="color: #2b91af">RoutedEventHandler</span>(Save_Click); }</pre> <p>The most important part was the logic that wires the PropertyChanged&nbsp; event of every entity to be tracked down (pretty messy isn't it?). The logic that gets executed updates the state of the entity inside the service's data context:</p><pre class="code"><span style="color: blue">void </span>product_PropertyChanged(<span style="color: blue">object </span>sender, <span style="color: #2b91af">PropertyChangedEventArgs </span>e) { <span style="color: #2b91af">Product </span>product = (<span style="color: #2b91af">Product</span>)sender; context.UpdateObject(product); }</pre><a href="http://11011.net/software/vspaste"></a> <p>&nbsp;</p> <p>Also in the callback we prepare a list out of the query, set the list as a data provider to the&nbsp; listbox's DataContext property, wire the buttons events and are ready to roll.</p> <p>How about pushing the changes back to the server? Well it is pretty straight-forward too - we initiate an asynchronous operation again, and provide a callback that implements the real operation:</p><pre class="code"><span style="color: blue">void </span>Save_Click(<span style="color: blue">object </span>sender, <span style="color: #2b91af">RoutedEventArgs </span>e) { context.BeginSaveChanges(<span style="color: #2b91af">SaveChangesOptions</span>.ContinueOnError, <span style="color: blue">new </span><span style="color: #2b91af">AsyncCallback</span>(OnSaveAllComplete), <span style="color: blue">null</span>); }</pre> <p>&nbsp;</p> <p>and here is the callback:</p><pre class="code"><span style="color: blue">void </span>OnSaveAllComplete(<span style="color: #2b91af">IAsyncResult </span>result) { <span style="color: blue">bool </span>succeeded = <span style="color: blue">true</span>; <span style="color: blue">try </span>{ <span style="color: #2b91af">DataServiceResponse </span>response = (<span style="color: #2b91af">DataServiceResponse</span>)context.EndSaveChanges(result); <span style="color: blue">foreach </span>(<span style="color: #2b91af">OperationResponse </span>opResponse <span style="color: blue">in </span>response) { <span style="color: blue">if </span>(opResponse.Error != <span style="color: blue">null</span>) { succeeded = <span style="color: blue">false</span>; } } } <span style="color: blue">catch </span>(<span style="color: #2b91af">Exception </span>ex) { succeeded = <span style="color: blue">false</span>; } <span style="color: green">// Alert the User </span>}</pre> <p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p> <p>Well that was all of it - no fancy stuff, but what we accomplished so far is great: we pushed data back and forth through an Ado.Net DataService, we had a SQL database that was handled through OpenAccess on the server side, and on the client-side we had a SilverLight application as a front-end. Stay tuned as I expect that the SilverLight team will cook a real case and way more slick (in terms of UI) example for all of us. </p> <p>Enjoy!</p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-12-16/getting_started_with_ado_net_data_services_and_telerik_open_access_ndash_step_iii.aspx Dimitar Kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-12-16/getting_started_with_ado_net_data_services_and_telerik_open_access_ndash_step_iii.aspx 8c8515f0-67b9-4a77-bc83-4ee45fb05c41 Tue, 16 Dec 2008 09:14:17 GMT Getting Started with ADO.NET Data Services and Telerik Open Access &ndash; Step II <p>In my previous <a href="http://blogs.telerik.com/blogs/08-12-12/Getting_Started_with_ADO_NET_Data_Services_and_Telerik_Open_Access_-_The_First_step.aspx">post</a> we looked into providing data to the client using <b>ADO.NET Data Services and Telerik OpenAccess. </b>However it is very rare just to present data, as usually some processing is done by the application on the client side, data gets modified and it is pushed back to the server for persistence. With <b>ADO.NET Data Services </b>this is done by implementing the <b><a href="http://msdn.microsoft.com/en-us/library/system.data.services.iupdatable.aspx">IUpdateable</a></b> interface by the data context class used on the server. <p><em>NOTE: We do not implement <b><a href="http://msdn.microsoft.com/en-us/library/system.data.services.iexpandprovider.aspx">IExpandProvider</a></b> at the moment.</em> <p>They say that a picture is worth a thousand words, so same is true for the code – I just present you the code required for updates:<pre class="code"><span style="color: blue">#region </span>IUpdatable Members <span style="color: blue">public object </span>CreateResource(<span style="color: blue">string </span>containerName, <span style="color: blue">string </span>fullTypeName) { <span style="color: #2b91af">Type </span>t = <span style="color: #2b91af">Type</span>.GetType(fullTypeName); <span style="color: #2b91af">Debug</span>.Assert(t != <span style="color: blue">null</span>); <span style="color: green">// assume can find type </span><span style="color: blue">object </span>resource = <span style="color: #2b91af">Activator</span>.CreateInstance(t); Scope.Add(resource); <span style="color: blue">return </span>resource; } <span style="color: blue">public object </span>GetResource(<span style="color: #2b91af">IQueryable </span>query, <span style="color: blue">string </span>fullTypeName) { <span style="color: blue">object </span>resource = <span style="color: blue">null</span>; <span style="color: blue">foreach </span>(<span style="color: blue">object </span>o <span style="color: blue">in </span>query) { <span style="color: blue">if </span>(resource != <span style="color: blue">null</span>) { <span style="color: blue">throw new </span><span style="color: #2b91af">Exception</span>(<span style="color: #a31515">"Expected a single response"</span>); } resource = o; } <span style="color: blue">if </span>(resource == <span style="color: blue">null</span>) <span style="color: blue">return new </span>Exceptions.<span style="color: #2b91af">NoSuchObjectException</span>(<span style="color: #a31515">"Object cannot be found."</span>, <span style="color: blue">null</span>); <span style="color: blue">if </span>(fullTypeName != <span style="color: blue">null </span>&amp;&amp; resource.GetType() != <span style="color: #2b91af">Type</span>.GetType(fullTypeName)) <span style="color: blue">throw new </span><span style="color: #2b91af">Exception</span>(<span style="color: #a31515">"Unexpected type for resource"</span>); <span style="color: blue">return </span>resource; } <span style="color: blue">public object </span>ResetResource(<span style="color: blue">object </span>resource) { <span style="color: #2b91af">Debug</span>.Assert(resource != <span style="color: blue">null</span>); Scope.Refresh(resource); <span style="color: blue">return </span>resource; } <span style="color: blue">public void </span>SetValue(<span style="color: blue">object </span>targetResource, <span style="color: blue">string </span>propertyName, <span style="color: blue">object </span>propertyValue) { <span style="color: #2b91af">PropertyInfo </span>pi = targetResource.GetType().GetProperty(propertyName); <span style="color: blue">if </span>(pi == <span style="color: blue">null</span>) <span style="color: blue">throw new </span><span style="color: #2b91af">Exception</span>(<span style="color: #a31515">"Can't find property"</span>); pi.SetValue(targetResource, propertyValue, <span style="color: blue">null</span>); } <span style="color: blue">public object </span>GetValue(<span style="color: blue">object </span>targetResource, <span style="color: blue">string </span>propertyName) { <span style="color: #2b91af">PropertyInfo </span>pi = targetResource.GetType().GetProperty(propertyName); <span style="color: blue">if </span>(pi == <span style="color: blue">null</span>) <span style="color: blue">throw new </span><span style="color: #2b91af">Exception</span>(<span style="color: #a31515">"Can't find property"</span>); <span style="color: blue">return </span>pi.GetValue(targetResource, <span style="color: blue">null</span>); } <span style="color: blue">public void </span>SetReference(<span style="color: blue">object </span>targetResource, <span style="color: blue">string </span>propertyName, <span style="color: blue">object </span>propertyValue) { SetValue(targetResource, propertyName, propertyValue); } <span style="color: blue">public void </span>AddReferenceToCollection(<span style="color: blue">object </span>targetResource, <span style="color: blue">string </span>propertyName, <span style="color: blue">object </span>resourceToBeAdded) { <span style="color: #2b91af">PropertyInfo </span>pi = targetResource.GetType().GetProperty(propertyName); <span style="color: blue">if </span>(pi == <span style="color: blue">null</span>) <span style="color: blue">throw new </span><span style="color: #2b91af">Exception</span>(<span style="color: #a31515">"Can't find property"</span>); <span style="color: #2b91af">IList </span>collection = (<span style="color: #2b91af">IList</span>)pi.GetValue(targetResource, <span style="color: blue">null</span>); collection.Add(resourceToBeAdded); } <span style="color: blue">public void </span>RemoveReferenceFromCollection(<span style="color: blue">object </span>targetResource, <span style="color: blue">string </span>propertyName, <span style="color: blue">object </span>resourceToBeRemoved) { <span style="color: #2b91af">PropertyInfo </span>pi = targetResource.GetType().GetProperty(propertyName); <span style="color: blue">if </span>(pi == <span style="color: blue">null</span>) <span style="color: blue">throw new </span><span style="color: #2b91af">Exception</span>(<span style="color: #a31515">"Can't find property"</span>); <span style="color: #2b91af">IList </span>collection = (<span style="color: #2b91af">IList</span>)pi.GetValue(targetResource, <span style="color: blue">null</span>); collection.Remove(resourceToBeRemoved); } <span style="color: blue">public void </span>DeleteResource(<span style="color: blue">object </span>targetResource) { Scope.Remove(targetResource); } <span style="color: blue">public void </span>SaveChanges() { Scope.Transaction.Commit(); } <span style="color: blue">public object </span>ResolveResource(<span style="color: blue">object </span>resource) { Scope.Retrieve(resource);<span style="color: green"> </span><span style="color: blue">return </span>resource; } <span style="color: blue">public void </span>ClearChanges() { Scope.Transaction.Rollback(); } <span style="color: blue">#endregion</span></pre> <p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p> <p>Yes, this is just what you need to accomplish to have updates pushed back to the server in this example. <p>To see the service up and running make your web site the startup site and just hit F5. This will start the test web server and the service. Then open a browser and navigate to the service: <strong>"</strong><a href="http://localhost:"><strong>http://localhost:</strong></a><strong>&lt;port&gt;/OADataServices/OADataService.svc"</strong> <p>&nbsp; <p><a href="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_2_1.sflb"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="169" alt="image" src="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_thumb_1.sflb" width="428" border="0"></a> <p>&nbsp; <p>Basically this is all about the server part of the application. In the next post I will guide you how to create extremely simple SilverLight test application that interacts with the provided service. Also I will try to implement the whole sample application in VB.NET as there is strong demand for that. Enjoy!</p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-12-15/getting_started_with_ado_net_data_services_and_telerik_open_access_ndash_step_ii.aspx Dimitar Kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-12-15/getting_started_with_ado_net_data_services_and_telerik_open_access_ndash_step_ii.aspx 1bb85169-773d-45fa-ae3d-f34e34620cb7 Mon, 15 Dec 2008 10:20:48 GMT Getting Started with ADO.NET Data Services and Telerik Open Access - The First step <p>To my opinion the day the Astoria incubation project was unveiled,&nbsp; all about querying and pushing data through a webservice changed for good. I was pretty amazed to see that the <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a> paradigm was so easily embraced in the .NET world. Now some time later, this is an official release and it is called ADO.NET Data Services. For all of you that are not familiar with ADO.NET Data Services you can find more information <a href="http://msdn.microsoft.com/en-us/data/bb931106.aspx ">here</a>. </p> <p>To put it shortly: <i>&lt;quote&gt;“The goal of the ADO.Net Data Services framework is to facilitate the creation of flexible data services that are naturally integrated with the web, using URIs to point to pieces of data and simple, well-known formats to represent that data, such as JSON and plain XML.”<i>&lt;/quote&gt;.</i></i></p> <p>In other words it gives a lightweight, though robust HTTP communication layer above the data sources, that serves remote parts of the application, for example a SilverLight or ASP.NET UI front-ends. </p> <p>Natively ADS supports only EntityFramework, but they do provide also LINQ support. Having LINQ in the game means that we could query almost any data provider underneath – including <a href="http://www.telerik.com/products/orm.aspx">Telerik Open Access ORM</a> tool. Yes, that’s right because we support LINQ and <b>IQueryable</b> we are able to provide ADS support as well. <p>&nbsp; <p>To start we have to create a web site first that will host our data service. This is pretty much straight forward as you probably know: <p><a href="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_2.sflb"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="236" alt="image" src="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_thumb.sflb" width="358" border="0"></a> <p>After creating the site we add a ADO.NET Data Service item named <b>OADataService.svc</b>: <p><a href="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_4.sflb"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="244" alt="image" src="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_thumb_1.sflb" width="363" border="0"></a> <p><strong>Note:</strong> If you have installed .NET SP1 you should have the ADO.NET Data Service template in your “Add New Item” dialog. <p>&nbsp; <p>After that you will end up with a code file inside your App_Code folder like this:<pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">WebDataService </span>: DataService&lt; <span style="color: green">/* TODO: put your data source class name here */ </span>&gt; { <span style="color: green">// This method is called only once to initialize service-wide policies. </span><span style="color: blue">public static void </span>InitializeService(IDataServiceConfiguration config) { <span style="color: green">// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. // Examples: // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead); // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All); </span>} }</pre> <p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p> <p>We will modify the file contents (it is not compilable even at the beginning), but first we have to build our data model. <p>To do so add a library project to the solution. The library project will host our data model and that way we will have a better separation of concerns. <p><a href="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_6.sflb"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="254" alt="image" src="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_thumb_2.sflb" width="390" border="0"></a> <p>&nbsp; <p>After we have the library project in the solution we have to build our model using the Open Access tool. For the purpose of this example we will add only the Products table inside our model. <p>To do so first enable the project to use Open Access. You can do so by starting the wizard from two places in Visual Studio: <p>1. <strong>Main menu &gt; OpenAccess &gt; “Enable Project to use ORM…”</strong> <p>2. Invoking the context menu on the library project (named Model for the purpose of this example), then go to <strong>OpenAccess &gt; Enable Project</strong> <p>The wizard will guide you through few steps and we are ready to roll: <p><a href="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_8.sflb"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="302" alt="image" src="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_thumb_3.sflb" width="391" border="0"></a> <p>After the project gets “Open Access enhanced” we can start the Reverse Mapping wizard (<strong>Main Menu &gt; OpenAccess &gt; Reverse Mapping (Table to Classes)</strong>) and have the Products entities generated: <p><a href="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_10.sflb"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="302" alt="image" src="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-image_thumb_4.sflb" width="394" border="0"></a> <p>The wizard will guide you through the whole procedure and eventually will generate the Product entity file that looks like:<pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">Product </span>{ <span style="color: blue">int </span>productID; <span style="color: green">//The 'no-args' constructor required by OpenAccess. </span><span style="color: blue">public </span>Product() { } [Telerik.OpenAccess.FieldAlias(<span style="color: #a31515">"productID"</span>)] <span style="color: blue">public int </span>ProductID { <span style="color: blue">get </span>{ <span style="color: blue">return </span>productID; } <span style="color: blue">set </span>{ <span style="color: blue">this</span>.productID = <span style="color: blue">value</span>; } }</pre><pre class="code">.</pre><pre class="code">.</pre><pre class="code">. }</pre><a href="http://11011.net/software/vspaste"></a> <p>After we generated the entities we have to provide a data context implementation for our <strong>OADataService</strong> data service. Add a class named <strong>OADataContext.cs</strong> in your <strong>Model</strong> project. <p>What do we need inside the class to provide all resources needed for the data service? Actually the ADS team allowed us to have quite broad implementation of the class: What we really need are properties that implement the <a href="http://msdn.microsoft.com/en-us/library/system.linq.iqueryable.aspx">IQueryable</a> interface thus exposing the underlying data in a standard way to the ADS communications stack above. So for the <strong>Products</strong> entities we put a property like:<pre class="code"><span style="color: blue">public </span><span style="color: #2b91af">IQueryable</span>&lt;<span style="color: #2b91af">Product</span>&gt; Products { <span style="color: blue">get </span>{ <span style="color: blue">return this</span>.scope.Extent&lt;<span style="color: #2b91af">Product</span>&gt;(); } } </pre> <p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p> <p>The scope variable is actually an instance of <a href="http://www.telerik.com/help/openaccess-orm/openaccess-database-connection----the-object-scope.html">IObjectScope</a> – Open Access implements the actual data context through this interface. So to start providing data we need a couple of lines of code and they look like:<pre class="code"><span style="color: gray">/// &lt;summary&gt; /// </span><span style="color: green">Summary description for OADataContext </span><span style="color: gray">/// &lt;/summary&gt; </span><span style="color: blue">public partial class </span><span style="color: #2b91af">OADataContext </span>: <span style="color: #2b91af">IDisposable </span>{ <span style="color: green">// Fields </span>IObjectScope scope = <span style="color: blue">null</span>; <span style="color: blue">public </span>OADataContext() { <span style="color: blue">this</span>.scope = <span style="color: blue">this</span>.ProvideScope(); } <span style="color: blue">public </span>OADataContext(IObjectScope scope) { <span style="color: blue">this</span>.scope = scope; } <span style="color: blue">public virtual </span>IObjectScope Scope { <span style="color: blue">get </span>{ <span style="color: blue">if </span>(<span style="color: blue">this</span>.scope == <span style="color: blue">null</span>) { <span style="color: green">// Attempt to get the Scope </span><span style="color: blue">this</span>.scope = <span style="color: blue">this</span>.ProvideScope(); } <span style="color: blue">return this</span>.scope; } } <span style="color: blue">public </span><span style="color: #2b91af">IQueryable</span>&lt;Product&gt; Products { <span style="color: blue">get </span>{ <span style="color: blue">return this</span>.scope.Extent&lt;Product&gt;(); } } <span style="color: blue">protected virtual </span>IObjectScope ProvideScope() { IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope(); scope.TransactionProperties.AutomaticBegin = <span style="color: blue">true</span>; <span style="color: blue">return </span>scope; } <span style="color: blue">#region </span>IDisposable Members <span style="color: blue">public void </span>Dispose() { <span style="color: blue">if </span>(scope != <span style="color: blue">null</span>) { scope.Dispose(); scope = <span style="color: blue">null</span>; } } <span style="color: blue">#endregion </span>}</pre> <p>&nbsp;</p> <p>Then we have to update the file we generated for our OADataService (it generates with compilation errors, and I believe they did it on purpose :) ) <p>Having a data context means that we will modify the OADataService file like this:<pre class="code">[System.ServiceModel.<span style="color: #2b91af">ServiceBehavior</span>(IncludeExceptionDetailInFaults = <span style="color: blue">true</span>)] <span style="color: blue">public class </span><span style="color: #2b91af">OADataService </span>: DataService&lt;OADataContext&gt; { <span style="color: blue">protected override void </span>HandleException(HandleExceptionArgs args) { <span style="color: blue">base</span>.HandleException(args); } <span style="color: green">// This method is called only once to initialize service-wide policies. //We overide it to enable all CRUD operations by setting EntitySetRights.All </span><span style="color: blue">public static void </span>InitializeService(IDataServiceConfiguration config) { config.SetEntitySetAccessRule(<span style="color: #a31515">"*"</span>, EntitySetRights.All); } }</pre> <p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p> <p>You should note the following: <p>- You have to refer the Model project from the web site or you will not be able to access the <strong>OADataContext</strong> type. <p>- The WCF attribute <strong>[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)] </strong>is very helpful when troubleshooting the service – without it you will not be able to gather enough information about the errors that may arise. <p>- the OADataContext source code is already distributed with the product installer as of <strong><a href="http://www.telerik.com/account/free-trials.aspx">version 2008.3 1205</a>.</strong> <h6>&nbsp;</h6> <p>In the next post I will guide you how not only to feed data to the client, but also to implement all CRUD operations on the server based on Open Access O/R tool. <p>Enjoy!</p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-12-12/getting_started_with_ado_net_data_services_and_telerik_open_access_-_the_first_step.aspx Dimitar Kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-12-12/getting_started_with_ado_net_data_services_and_telerik_open_access_-_the_first_step.aspx e9db2cc9-fcad-48f9-b287-2aa876349b03 Fri, 12 Dec 2008 07:14:43 GMT Enabling Asp.net development on Vista 64 <p></p> <p>Well as I figured it out it was not a complicated thing, but there are some specifics of course:</p> <p><strong>Installing IIS</strong> </p> <p>By default IIS7 is included in the distribution (I use the Enterprise edition of Windows Vista), but is not installed by default. To do so open <strong>ControlPanel &gt; Programs and Features</strong>. </p> <p>On the right side of the window click the &quot;Turn Windows features on or off&quot; link and a dialog will open:</p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-settings.sflb"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="244" alt="settings" src="http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-settings_thumb.sflb" width="191" border="0" /></a> </p> <p><strong></strong></p> <p><strong>Installing required features</strong></p> <p>You can select and check the <strong>Internet Information Services</strong> feature. By default not everything required gets selected. You have to check also the <strong>Internet Information Services&gt;World Wide Web Services&gt;Security&gt; Windows Authentication</strong> and <strong>Internet Information Services&gt;World Wide Web Services&gt;Application Development Features&gt; ASP.NET</strong></p> <p>This is pretty much all that you have to do to be able to run an asp.net site for example. Enjoy!</p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-12-12/enabling_asp_net_development_on_vista_64.aspx Dimitar Kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-12-12/enabling_asp_net_development_on_vista_64.aspx 3a36efca-281f-4ce5-90fb-65ae5aa78540 Fri, 12 Dec 2008 04:42:16 GMT The Object Relational &ldquo;Impedance Mismatch&rdquo; <p></p> <p>Now I know that most of you are familiar with this &#8220;as old as the world&#8221; problem, so to ease the uprising tension I will not go into the theoretical and architectural kind of stuff. Rather I want to remind to all of us why the (O)bject (R)elational mapping software domain exists nowadays.</p> <p>In general there are few major obstacles to overcome when designing an efficient N-Tier application. The persistence storage of a modern application is usually a <a href="http://en.wikipedia.org/wiki/Relational_database_management_system">RDBMS</a>. These kinds of systems store information in a highly efficient way and allow fast retrieval, information queries and scalability, and all that because of the <a href="http://en.wikipedia.org/wiki/Database_normalization">normalization theory</a> and <a href="http://en.wikipedia.org/wiki/Edgar_F._Codd">Edgar F. Codd</a>. In a typical database you have tables, which consist of columns and rows. The columns represent the schema of the data, whereas the rows contain the real information bound to the particular schema. The tables are bound in so called relations that represent the dependencies amongst the different data sets.</p> <p>On the other side, majority of the applications are developed using OOD and OOP approaches. In the OOP world you just don&#8217;t have strict &#8220;schemas&#8221; and normalization process, the data is described by using different types, and of course, by using object references (which is different than relations).</p> <p>So you have two completely different worlds, not just as programming paradigms, but also completely alien in terms of technology approaches. The interrelations between both models are crucial for the application&#8217;s stability, performance, and scalability, but suffer because of the following differences:</p> <p>- <b>Encapsulation</b> &#8211; in OOP every class has internal and private implementation that is contained and maintained by the class instance. The external entities do not have access to this &#8220;reserved&#8221; part of the class instance &#8211; it is accessible in a manner to guarantee the class <a href="http://en.wikipedia.org/wiki/Class_invariant">invariant behavior</a>. The public methods should define the &#8220;contract&#8221; with the outside world. The goals are to have a set of rules that guarantee the valid state of the object instance throughout its lifecycle. <br />Opposite to that the RDBMS use of public data, which must be amenable to upgrade, inspection and queries. Significantly fewer constraints are applied on the data that represent object characteristics, for example there are no formal &#8220;private&#8221; and &#8220;public&#8221; fields that are embedded in the RDBMS technology platforms.</p> <p>- <b>Data type differences</b> &#8211; no pointer/reference data types are allowed in the relational systems. Even more, there are substantial differences between the scalar data types in both OOP and RDBMS models, which cause translation/mapping difficulties.</p> <p>- <b>Structure and integrity</b> &#8211; in OOP it is considered normal to have highly nested structures (objects containing sets of different objects recursively, thus producing quite complicated object graphs). This poses difficulties in translating these structures to relational schemas, where all data is represented in a named set of global, flat relation variables. Also most of the constraints in the relational models are declaratively defined, whereas in the OOP systems this is mostly implemented as verification procedures that rise exceptions and/or implement error handling.</p> <p>- <b>Manipulating the model</b> &#8211; maybe the biggest difference of all is the way we &#8220;handle&#8221; both models. The relational models have a formalized and well defined set of operators and primitives to query and handle data. The OOP models, on the opposite, use lower level, case and technology specific access, and imperative operations.</p> <p>- <b>Transactions</b> &#8211; a well defined, mission-critical part of the RDBMS systems are the transactions that encapsulate the smallest unit of work performed by RDBMS. Their scope is larger and even not typical for any OO generic system at present. In OO systems at present mostly field-scope or property-scope changes are tracked in transaction mechanisms, which is not even near to what database transactions are capable of. Transaction and consistency are only ensured for changes of primitive typed fields at most in OO systems. In general, no isolation mechanisms are used as well.</p> <p>&#160;</p> <p>So, enough said on what are the real approaches to solving the impedance mismatch problem in object-relational models mapping. There is no complete or universal solution to this, but there are two approaches to solving it: through <b>compensation</b> and through <b>minimization (</b>the second approach is less popular). Minimization generally refers to building object-oriented database systems or having extensions to the programming languages that incorporate the relational models into the OO world (example: transitional memory paradigm). The compensation is typically done trough intermediate frameworks that tend to map the data model entities to the ones used in the OO systems. Such &#8220;translation&#8221; layers are generally referred to as O/R mappers. Of course there is always the possibility to &#8220;cook&#8221; something yourself, but personally I prefer using mature and widely used frameworks, whether free or commercial.</p> <p>Generally they do have a few technical aspects that are used to accomplish their target goals. The most widely used approach is the <a href="http://en.wikipedia.org/wiki/Source_code_generation">code generation</a>, where based on some entities model, real code is generated in the project. The code in the form of classes implements the entities from the data model in an OO manner that is easy and simplistic to use in imperative OO languages. Because of its OO nature, the classes encapsulate all the logic that is required to interact correctly with the <b>O/R</b> mapping framework.</p> <p>So how to solve the <b>O/R</b> impedance mismatch in practice? What frameworks are there on the market? Should you use an Open Source or a commercial vendor product? Maybe just use a code generator with DAL templates instead? </p> <p>Well, I will be going through all of these questions and lot more in a series of articles that I am starting on the <b>O/R</b> mapping domain. </p> <p>The journey begins with evaluating general purpose code generation techniques that use templates to generate Data Access Layers. Then I will go through presenting some of the most popular O/R tools on the market. After a short assessment, every O/R tool will be demonstrated in a simple example that includes our RadGridView for Windows Forms control, and possibly RadChart. In the course of doing it, I will present the special features, i.e. the &#8220;bells and whistles&#8221; of the O/R mappers and our UI components. Then the final verdict on O/R mappers will be issued &#8211; the tool that will be used to prepare a real life application based on patterns and best practices&#8230; </p> <p>And understandable styled using our UI components (I will start with Windows Forms, but if there is enough interest, will continue with ASP.NET AJAX, WPF, Silverlight, you name it). I will be experimenting with IoC frameworks on top of the O/R mapping as well.</p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-10-08/the_object_relational_ldquo_impedance_mismatch_rdquo.aspx kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-10-08/the_object_relational_ldquo_impedance_mismatch_rdquo.aspx 5ae11879-d2e4-42c0-89c8-01fb13f2b23e Wed, 08 Oct 2008 07:39:47 GMT Wrapping a .NET user control as an ActiveX <p>Before even asking why one should do anything like this, let me clarify that this is a good technique to spice up a bit your VB6 application. Now I know this is not cutting edge but still it is important to a lot of people (as I found out already).</p> <p>So let&#8217;s start then...</p> <p>Create a new solution that includes a Windows Forms application (to test easily the functionality provided by the user control). Then add a library project that will wrap our user control. </p> <p>What is demonstrated by this example is a very simple example that includes a label, and a button inside of a user control. When the button is clicked, the code in the Click eventhandler changes the text content of the label.</p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-project.sflb"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="project" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-project_thumb.sflb" width="143" border="0" /></a>&#160; </p> <p><strong>The library</strong></p> <p>&#160;</p> <p>Open <b>Property Settings</b> window, select the <b>Application</b> tab (if not active). You should see an <b><i>&#8220;Assembly Information&#8230;&#8221;</i></b> button &#8211; click on it and it will open a dialog form with various assembly settings.</p> <p>You will see a checkbox named <b><i>&#8220;Make assembly COM-visible&#8221;</i></b>. The checkbox must be checked. </p> <p>&#160;</p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-appSettings.sflb"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="178" alt="appSettings" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-appSettings_thumb.sflb" width="244" border="0" /></a>&#160;</p> <p><strong>Application Settings Tab</strong></p> <p>Also you will see a GUID field &#8211; it is used to set the ID of the typelib if this project is exposed to COM.</p> <p>&#160;</p> <p>If you want automatic registration of the freshly created ActiveX wrapper you should check the <b><i>&#8220;Register for COM interop&#8221;</i></b> checkbox in the <b>Build</b> tab of the settings form.</p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-buildSettings.sflb"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="239" alt="buildSettings" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-buildSettings_thumb.sflb" width="244" border="0" /></a>&#160; </p> <p><strong>Build Settings</strong></p> <p>As far as I know the only thing it does is actually to run Regasm.exe after every build to register the types with COM (which you probably shouldn't do until you're stable because your COM GUIDs will change whenever you change the methods unless you specify GUIDs explicitly, so your registry could end up with a lot of registration junk for versions that will never be used).</p> <p>If you're using VB.NET, you also need a strong named assembly. But it is considered a good practice so I&#8217;ve done it even in the C# project.</p> <p>&#160;</p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-signSettings.sflb"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="169" alt="signSettings" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-signSettings_thumb.sflb" width="244" border="0" /></a>&#160; </p> <p><strong>Sign Settings</strong></p> <p>&#160;</p> <p>This is all you have to do in the project settings, but we have unfinished business with the code base as well.</p> <p>&#160;</p> <pre class="code">[<span style="color: #2b91af">ProgId</span>(<span style="color: #a31515">&quot;ActiveXTestLibrary.UserControl&quot;</span>)] [<span style="color: #2b91af">ClassInterface</span>(<span style="color: #2b91af">ClassInterfaceType</span>.AutoDispatch)] <span style="color: blue">public partial class </span><span style="color: #2b91af">UserControl1 </span>: <span style="color: #2b91af">UserControl </span>{</pre> <p>}</p> <p>What we have here is the <span style="color: #2b91af">ProgId</span> attribute which provides a unique name for the created ActiveX interface. It is uniquely identified by the assembly GUID, yet the GUIDs are not human-readable, and a second level of abstraction (easy referral) is provided by the (<b>Prog</b>rammatic <b>ID</b>entifier) or the <span style="color: #2b91af">ProgId</span> attribute. For example, the <strong>ProgID</strong> for the <strong>Word</strong> automation object is <strong><em>Word.Basic</em></strong>.</p> <p>&#160;</p> <p>The second <span style="color: #2b91af">ClassInterface</span> attribute states whether and how an COM interface will be generated for the managed assembly. The behavior is controlled through an <strong>enum</strong> named <span style="color: #2b91af">ClassInterfaceType. <font color="#000000">You can find more on the topic here: <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.classinterfacetype.aspx">http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.classinterfacetype.aspx</a></font></span></p> <p><span style="color: #2b91af"><font color="#000000"></font></span></p> <p><span style="color: #2b91af"><font color="#000000">Last but not least you can provide static methods that are invoked when the ActiveX is registered or unregistered through the Regasm.exe:</font></span></p> <pre class="code">[<span style="color: #2b91af">ComRegisterFunction</span>()] <span style="color: blue">public static void </span>RegisterClass(<span style="color: blue">string </span>key) { <span style="color: #2b91af"> StringBuilder </span>sb = <span style="color: blue">new </span><span style="color: #2b91af">StringBuilder</span>(key); sb.Replace(<span style="color: #a31515">@&quot;HKEY_CLASSES_ROOT\&quot;</span>, <span style="color: #a31515">&quot;&quot;</span>); <span style="color: green">// Open the CLSID\{guid} key for write access </span><span style="color: #2b91af">RegistryKey </span>k = <span style="color: #2b91af">Registry</span>.ClassesRoot.OpenSubKey(sb.ToString(), <span style="color: blue">true</span>); <span style="color: #2b91af"> RegistryKey </span>ctrl = k.CreateSubKey(<span style="color: #a31515">&quot;Control&quot;</span>); ctrl.Close(); <span style="color: green">// Next create the CodeBase entry - needed if not string named and GACced. </span><span style="color: #2b91af">RegistryKey </span>inprocServer32 = k.OpenSubKey(<span style="color: #a31515">&quot;InprocServer32&quot;</span>, <span style="color: blue">true</span>); inprocServer32.SetValue(<span style="color: #a31515">&quot;CodeBase&quot;</span>, <span style="color: #2b91af">Assembly</span>.GetExecutingAssembly().CodeBase); inprocServer32.Close(); k.Close(); } [<span style="color: #2b91af">ComUnregisterFunction</span>()] <span style="color: blue">public static void </span>UnregisterClass(<span style="color: blue">string </span>key) { <span style="color: #2b91af">StringBuilder </span>sb = <span style="color: blue">new </span><span style="color: #2b91af">StringBuilder</span>(key); sb.Replace(<span style="color: #a31515">@&quot;HKEY_CLASSES_ROOT\&quot;</span>, <span style="color: #a31515">&quot;&quot;</span>); <span style="color: green">// Open HKCR\CLSID\{guid} for write access </span><span style="color: #2b91af">RegistryKey </span>k = <span style="color: #2b91af">Registry</span>.ClassesRoot.OpenSubKey(sb.ToString(), <span style="color: blue">true</span>); <span style="color: green">// Delete the 'Control' key, but don't throw an exception if it does not exist </span><span style="color: blue">if </span>(k == <span style="color: blue">null</span>) { <span style="color: blue">return</span>; } k.DeleteSubKey(<span style="color: #a31515">&quot;Control&quot;</span>, <span style="color: blue">false</span>); <span style="color: green">// Next open up InprocServer32 </span><span style="color: #2b91af">RegistryKey </span>inprocServer32 = k.OpenSubKey(<span style="color: #a31515">&quot;InprocServer32&quot;</span>, <span style="color: blue">true</span>); <span style="color: green">// And delete the CodeBase key, again not throwing if missing </span>inprocServer32.DeleteSubKey(<span style="color: #a31515">&quot;CodeBase&quot;</span>, <span style="color: blue">false</span>); <span style="color: green">// Finally close the main key </span>inprocServer32.Close();</pre> <pre class="code"> k.Close(); }</pre> <a href="http://11011.net/software/vspaste"></a> <p><span style="color: #2b91af"><font color="#000000">The methods have predefined names (RegisterClass and UnregisterClass) and should be marked respectively with the <span style="color: #2b91af">ComRegisterFunction</span>/ <span style="color: #2b91af">ComUnregisterFunction</span> attributes. Here in this example we register the category of the ActiveX as a UI control.</font></span></p> <p><span style="color: #2b91af"><font color="#000000"></font></span></p> <p><span style="color: #2b91af"><font color="#000000"><strong>Testing the ActiveX control</strong></font></span></p> <p><span style="color: #2b91af"><font color="#000000">You can do so by using the tstcon32.exe (ActiveXControlTestContainer) that is provided with your Visual Studio installation. You can invoke it easily through the Visual Studio Command Prompt which has all variables and paths preset correctly.</font></span></p> <p><span style="color: #2b91af"><font color="#000000"></font></span></p> <p><span style="color: #2b91af"><font color="#000000"><strong>Unlocking locked assemblies</strong></font></span></p> <p><span style="color: #2b91af"><font color="#000000">You can end up with locked assemblies due to the tstcon32 test. What you can do is use file unlock utility to kill the locking process. Then you could unregister the COM interface using the Regasm.exe /unregister option and then delete the file.</font></span></p> <p><span style="color: #2b91af"><font color="#000000">&#160;</font></span></p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-09-17/wrapping_a_net_user_control_as_an_activex.aspx kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-09-17/wrapping_a_net_user_control_as_an_activex.aspx 8fcaea6b-4009-41d5-97b6-b86f3e785758 Wed, 17 Sep 2008 13:34:37 GMT Visual Studio Tooltips unplugged: How to use multiple monitors with Visual Studio efficiently. <p></p> <p>It is no urban legend that having more monitors results in greater productivity, and most of all tremendous increase in developer&#8217;s comfort. Even the Myth Busters (http://en.wikipedia.org/wiki/MythBusters) dudes know that.</p> <p>So imagine that your group&#8217;s budget allows installing a brand new (say 22 inches) TFT display as your second, or even better you already have the setup. </p> <p>What are your options with VS 2005/2008 for efficient management of the screen estate to bust productivity?</p> <p><b>Better code access</b></p> <p>You can vertically split the Visual Studio screen estate in two, and position the divider down the center of the two monitors. This can be done using the command <b>Window (main menu)&gt; New Vertical Tab Group. </b>You can position the properties window in the second screen also.<b></b></p> <p><b></b></p> <p><b>Debugging on the second monitor</b></p> <p>On the primary monitor you can have your application running, while on the second you can position (docked or undocked) the debugging windows like the Watch windows, Output, Breakpoints windows, etc.</p> <p><b>Using effectively help and documentation</b></p> <p>You can put the help viewer or the MSDN on your second monitor and use it in parallel with your main activity.</p> <p>*You can save the layout of the windows by using the wizard: <b>Tools (main menu) &gt; Import / Export Settings. <br /></b></p> <p>*remember that there are two layout to setup: in debugging and in standard mode</p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-09-16/visual_studio_tooltips_unplugged_how_to_use_multiple_monitors_with_visual_studio_efficiently.aspx kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-09-16/visual_studio_tooltips_unplugged_how_to_use_multiple_monitors_with_visual_studio_efficiently.aspx bf6dcae2-8732-4264-9290-1459b11dfcef Tue, 16 Sep 2008 05:57:33 GMT Visual Studio Tooltips unplugged: Drag and Drop code artifacts to Toolbox General Tab. <p>I bet you never thought about this feature! Me either&#8230; </p> <p>It&#8217;s good that there is a marvelous blog about all goodies in VS maintained by a <a href="http://blogs.msdn.com/saraford/default.aspx">nice lady</a>. </p> <p>I will be monitoring and making comments on the topics there that have excited me most.</p> <p>So what is on today&#8217;s menu? As you&#8217;ve probably figured it out already, I will comment on a fine (but unknown to me) feature of dragging and pasting code artifacts straight to the VS toolbox. At first I was a little bit skeptic, but it really worked out, let me show you how:</p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-VisualStudioTooltipsunpluggedDragandDro_EF10-selecting.sflb"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="138" alt="selecting" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-VisualStudioTooltipsunpluggedDragandDro_EF10-selecting_thumb.sflb" width="244" border="0" /></a> </p> <p><strong>1. Mark a code segment in the code editor</strong></p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-VisualStudioTooltipsunpluggedDragandDro_EF10-generalTab.sflb"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="183" alt="generalTab" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-VisualStudioTooltipsunpluggedDragandDro_EF10-generalTab_thumb.sflb" width="244" border="0" /></a> </p> <p><strong>2. Drag the selected code to the General Tab of the Toolbox</strong></p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-VisualStudioTooltipsunpluggedDragandDro_EF10-generalTabDragged.sflb"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="145" alt="generalTabDragged" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-VisualStudioTooltipsunpluggedDragandDro_EF10-generalTabDragged_thumb.sflb" width="244" border="0" /></a> </p> <p><strong>3. You will end up with a toolbox item that represents the code snippet.</strong></p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-VisualStudioTooltipsunpluggedDragandDro_EF10-generalTabPaste.sflb"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="232" alt="generalTabPaste" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-VisualStudioTooltipsunpluggedDragandDro_EF10-generalTabPaste_thumb.sflb" width="244" border="0" /></a> </p> <p><strong>4. Drag back to the code editor, or double click to insert at the cursors position.</strong></p> <p><strong></strong></p> <p>Yes, that was it really :) All worked as expected.</p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-09-12/visual_studio_tooltips_unplugged_drag_and_drop_code_artifacts_to_toolbox_general_tab.aspx kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-09-12/visual_studio_tooltips_unplugged_drag_and_drop_code_artifacts_to_toolbox_general_tab.aspx 940e1c75-5c25-40c8-ae12-6d14945963f2 Fri, 12 Sep 2008 05:59:15 GMT You said Windows 3.11? Did I hear right? <p>Well folks that's right - MS <a href="http://en.wikipedia.org/wiki/Windows_3.1">Windows for Workgroups 3.11</a> is pretty much still alive and kicking. First when I found out that this 15+ years old OS was still popular in the embedded segment (<em>please forgive my ignorance as embedded systems are not my core competency</em>) I couldn't believe my eyes. According to <a href="http://blogs.msdn.com/jcoyne/archive/2008/07/09/it-s-the-end-for-3-11.aspx">John Coyne</a> this fact changes starting October 1st, 2008 - from this date on OEM's will no longer be able to license Windows for Workgroups 3.11. <br />The comments and the flame that started at <a href="http://arstechnica.com/journals/microsoft.ars/2008/07/09/oem-licensing-for-windows-3-11-finally-to-end-in-4-months">ArsTechnica</a> are very interesting though. It looks like the guys that develop embedded applications really loved that OS. I wonder whether Windows Vista will still have place in our hearts 15 years from now. What is your opinion? Share it with the Telerik community :)</p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-09-11/you_said_windows_3_11_did_i_hear_right.aspx kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-09-11/you_said_windows_3_11_did_i_hear_right.aspx f2e2a289-a47e-4251-ae42-53846a362f74 Thu, 11 Sep 2008 06:42:51 GMT PDC approaching <p>Ever wondered what technologies MS has up its sleeve for the closest future? <br />I bet you've heard at least words like Live Mesh, Office Communications Server, SQL Server 2008, FAST, Silverlight, Oslo, Visual Studio Team System, Virtualization, SharePoint, Dynamics, XNA. <br />You didn't? So maybe you know about ASP.NET or perhaps IronRubby? <br />The technologies that I've mentioned will make it into the spotlight at PDC 2008 event. You can check out details on 50 of more than 200 sessions that will be <a href="https://sessions.microsoftpdc.com/public/sessions.aspx">presented</a> at PDC.</p> http://blogs.telerik.com/DimitarKapitanov/Posts/08-09-10/pdc_approaching.aspx kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-09-10/pdc_approaching.aspx 8ead9305-537b-45fa-aa28-d38c144d3ce0 Wed, 10 Sep 2008 06:24:04 GMT PNDs, UMPCs, MIDs – what’s it all about? <p>Let me clarify first that the title is a bit misleading. You may think that the story will comment on these devices in general, but you are wrong :). I will comment <a href="http://www.nvidia.com/page/handheld.html">NVidia</a>’s* entry in the handheld and portable devices business in particular, and what it means for the whole industry. Will they shape the landscape the way they did in the <a href="http://en.wikipedia.org/wiki/Graphics_processing_unit">GPU</a> market? Why is this event important enough to compel a guy that develops software to blog about hardware? Why the <a href="http://www.nvidia.com/page/pg_20050719919672.html">Nvidia Tegra</a>? Why not the <a href="http://www.engadget.com/2008/04/25/the-second-gen-iphone-3g-gps-only-slightly-thicker/">IPhone 3G</a>? Or the <a href="http://htc-diamond.com/">HTC Diamond</a>? A lot of tough questions to answer and I will try my best to give you a reasonable answer.</p> <p><strong>PNDs, UMPCs, MIDs – the common issues</strong></p> <p>Whether it is a <a href="http://en.wikipedia.org/wiki/Personal_navigation_device">PND</a> (Personal Navigation Device),&nbsp; <a href="http://en.wikipedia.org/wiki/Mobile_Internet_Device">MID</a> (Mobile Internet Device) or <a href="http://en.wikipedia.org/wiki/Umpc">UMPC</a> (Ultra-Mobile PC) or any other fancy acronym, the key goal of these devices is MOBILITY. One should be able to connect from various places, using various carriers, based on different technologies such as WiFi/Max, GPRS &nbsp;and 3G. Furthermore, it should feature positioning , and be able to use geospatial data based on <a href="http://en.wikipedia.org/wiki/Global_Positioning_System">GPS</a> , <a href="http://www.esa.int/esaNA/galileo.html">Galileo</a> or <a href="http://www.glonass-ianc.rsa.ru/pls/htmldb/f?p=202:1:4560502264575458796">GLONASS</a>, accept and broadcast live HD video. </p> <p><img alt="Tegra device" src="/Libraries/MetaBlog/nvidia2.sflb" />&nbsp;</p> <p>UI intensive applications demand a powerful CPU, while &nbsp;being truly mobile relies on low energy consumption. &nbsp;Sadly, these two &nbsp;qualities are mutually exclusive – the higher the frequency and the intensity of calculations processed by the CPU, the higher the amount of charge drained from the energy source. Furthermore, as we all know, advances in battery technology does not follow <a href="http://en.wikipedia.org/wiki/Moore%27s_law">Moore's law</a>, so ultra-compact and über-powerful energy sources are not expected anytime soon. This leaves us to attack the problem from the opposite end: to conserve as much energy as possible. For this purpose, a number of energy saving techniques have been developed, but frankly speaking, ALL of them have a negative impact on CPU performance. Well that’s the tradeoff folks, as they say, there is no such thing as a free lunch. Reducing the power consumption and extending the operational state of the device, comes with lower CPU productivity, and ultimately results in a less vibrant user experience and sluggish graphics. It might even render some applications virtually unacceptable for MIDs (e.g. high-end medical applications). </p> <p><strong>So, what’s so special about the Tegra device, and can it deliver? Why not a ü(ber)Phone?</strong></p> <p>&nbsp;<img alt="Tegra logo" src="/Libraries/MetaBlog/nvidia3.sflb" /></p> <p>Don’t get me wrong about all the *Phones – they are marvelous devices, a huge leap in UX, but they still are today’s technology, while here the story goes about what comes tomorrow. An important difference is that the NVidia Tegra is a <a href="http://en.wikipedia.org/wiki/System-on-a-chip">SoC</a> (System on a Chip) while the IPhone, or the HTC Diamond for example are consumer devices. Still, keep in mind that consumer products are built on chipsets and CPUs. By highlighting this new technology the good guys and gals at NVidia brought to us, I am lifting the curtain and revealing to you what the next generation mobile devices will most probably look like.</p> <p>Their architecture is <a href="http://www.arm.com/">ARM</a> based, which gives a complete energy saving technology stack far better than the one the x86 architecture has to offer (even in its <a href="http://www.arm.com/">Atom</a> incarnation). Furthermore, the ARM processor core provides Virtual Machine optimized instructions and a <a href="http://en.wikipedia.org/wiki/SIMD">SIMD</a> instruction set that is most suitable for multimedia applications. All of this, combined with NVidia’s low-micron fabrication process, it makes for a significant advantage. </p> <p>You can see a <a href="http://www.youtube.com/watch?v=XXYshhuJzh4&amp;feature=related">sample</a> of how NVIDIA Tegra packs more punch for less consumed power (or so they claim).&nbsp; What really amazed me is the demo UI interface that NVidia calls <a href="http://www.youtube.com/watch?v=nD4SrVZlcig&amp;feature=related">RayGun Navigator</a> (any resemblance with a game?) which clearly demonstrates the GPU capabilities (HD video, smooth animations, physics effects such as particles, optical effects). In additional, you can have a full flavored <a href="http://www.youtube.com/watch?v=_p69T3cWHBs">3D rendering</a>.</p> Well, so much for the info that has publicly been released so far. Nevertheless, expect more, as I will be monitoring this technology closely and will be posting updates here. <p>&nbsp;</p> <p>* The names of actual companies and products mentioned herein may be the trademarks of their respective owners. </p> <br /> http://blogs.telerik.com/DimitarKapitanov/Posts/08-06-26/pnds_umpcs_mids_–_what’s_it_all_about.aspx Dimitar Kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/08-06-26/pnds_umpcs_mids_%e2%80%93_what%e2%80%99s_it_all_about.aspx 9264a992-740c-4f91-a9d8-6e92db78f48e Thu, 26 Jun 2008 09:22:06 GMT New hardware surfacing from Redmond It went public at 12:01 a.m. on May 30 – Microsoft&#174; revealed the outcome of "<a href="http://gizmodo.com/gadgets/project-milan/">Project Milan</a>" now branded as Microsoft Surface&#8482; and scheduled to debut in November this year. The nature of the project is a "<em>multi-touch, gestural- and object-recognition interface technology on which Microsoft has been laboring for the past few years</em>".<br><br><img src="http://blogs.telerik.com/photos/storage/surface1.JPG"><br><br>Named "Surface" and five years in the making, it's set to establish a paradigm of what Microsoft calls "surface computers" which use touch as the sole method of input. The goal is to deliver a hardware/software platform very close to the people and to weave the technology into the texture of everyday life. What is about to happen is clearly demonstrated by <a href="http://www.ted.com/index.php/talks/view/id/65">Jeff Han</a>&nbsp;in his talk about the <a href="http://www.ted.com/index.php/talks/view/id/65">genius of multi-touch interface design</a>. The interest in this bleeding edge technology is very strong all around the industry as most of the major players believe it will bring a whole new way of using software/hardware technology to the market. In this quest the Redmond giant is not alone as hardware makers like Hewlett-Packard and <a href="http://www.research.philips.com/initiatives/entertaible/index.html">Philips</a>&nbsp;have publicly and independently (<a href="http://www.youtube.com/watch?v=SD9HXRWIHPw&amp;feature=PlayList&amp;p=461ED830D6FB8BCA&amp;index=5">a brief demonstration of Philips Entertaible concept</a>) demonstrated their own approaches to delivering surface-computing and gesture-recognition. Eon Reality, the 3D and virtual-reality software vendor which licensed Microsoft’s Touchlight technology last year, offers a product called <a href="http://www.eonreality.com/eon-products.html">Eon Touchlight</a>. As it is obvious that advanced UI interfaces require advanced hardware (not only for the presentation part but also for the human interaction interface)<br><br><img src="http://blogs.telerik.com/photos/storage/surface2.JPG"><br><br>more and more products from different vendors that are based on surface computing paradigm will emerge into the market. I believe introducing such hardware is part of the strategy at Redmond to bring the technology closer to the people, to make it far easier to use it and create content, even software for non-it specialists. On the software front it combines with recent MS presentation technology both for Windows (<a href="http://windowsclient.net/Default.aspx">WPF</a>) and the <a href="http://silverlight.net/Default.aspx">Internet</a>&nbsp;which allows the development of a very rich presentation layer not by developers, but by the people that <a href="http://www.microsoft.com/expression/">understand UX most</a>. It is obvious that the Surface&#8482; product line will be marketed as consumer electronics products where Microsoft delivers all the software artifacts and services, a question is rising whether the company is becoming more and more "<a href="http://blogs.zdnet.com/microsoft/?p=484">hardware oriented</a>". While presenting a whole pile of new game consoles, media players keyboards and mice the officials answer to this question is "NO". We will be monitoring the development of surface computing further. http://blogs.telerik.com/DimitarKapitanov/Posts/07-05-31/new_hardware_surfacing_from_redmond.aspx Dimitar Kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/07-05-31/new_hardware_surfacing_from_redmond.aspx 6760c2d0-b21f-4c9f-b1e0-61cbefab9859 Thu, 31 May 2007 12:02:00 GMT Origami: the next Big Small thing. <p><strong>Will Microsoft take on Apple and Palm with its all-in-one consumer/business ultra-portable device?<br></strong></p> <p>Well, you’ve probably heard the news already - Microsoft is entering the persona-portble-cool-weired-widgets market with their own device… The device code named Origami (official name is UMPC which is spelled out like <strong>U</strong>ltra <strong>M</strong>obile <strong>PC</strong>) is very compact all-in-one information device that is targeted as an iPod, Palm and BlackBerry competition. Origami sounds way cooler than UMPC though (I keep asking myself why the guys at MS are giving great code names like Indigo, Avalon and Origami, and the official naming is almost unpronounceable like WPF, WCF, UMPC, etc. ), so I’ll be mostly using the code name here. So where is the Origami project being developed? In MS research labs or in the marketing department? It looks like both are true:</p> <p><img src="http://blogs.telerik.com/photos/storage/origami_top.jpg"><br><br></p> <p>Microsoft hides neither its <a href="http://www.apple.com/ipod/">iPod</a> envy nor its lack of satisfaction with the Portable Media Center devices its partners have been producing. And no one from Redmond has denied reports that Microsoft has plans to get into the business of <a href="http://www.microsoft-watch.com/article2/0,2180,1916096,00.asp">building its own family of iPod killers.</a></p> <p></p> <p>But I’ am betting Microsoft won't classify Origami devices as an MP3 player... Instead, Microsoft will convince its wizards in the market-research business to create a whole new category of all-in-one mobile communicators (better than <a href="http://www.t-mobile.com/shop/phones/Detail.aspx?device=154e9bca-a74c-4299-99eb-48a1159c922b&amp;WT.srch=2">Sidekicks</a>; more comprehensive than <a href="http://www.palm.com/us/products/smartphones/">Treos</a>; able to leap even <a href="http://www.blackberry.com/">BlackBerries</a> in a single bound!) </p> <p>What's your take? Is it time for Apple, Palm and others to get some fresh competition? And is Microsoft the right company to deliver an all-in-one soaped-up device of this sort? Or are we way off-base in our educated guess that Origami will morph into a family of OrPods (OrigamiPods)?</p> <p>By the way they have few (to be more precise three) flash introductory commercials. They are very stylish and I got involved from the moment I saw them, take a look… <a href="http://www.origamiproject.com/1/">Commercial One</a>, <a href="http://www.origamiproject.com/2/">Commercial Two</a> and <a href="http://www.origamiproject.com/3/">Commercial Three</a>…</p> <p></p> <p>For those of you who already got hooked up, Microsoft announced a <a href="http://origamiproject.com/contest/contest.aspx">real deal contest</a>, the winners are getting a bundle of Origami devices produced by <a href="http://www.samsung.com/">Samsung</a> and a <b><a href="http://www.slingmedia.com/">Slingbox&#8482;</a></b><b> by SlingMedia. The only thing you have to do is </b>write an essay (no more than 250 words!) and being a legal resident of the 50 United States, and District of Columbia.</p> <p><img src="http://blogs.telerik.com/photos/storage/Samsung_contest.jpg">&nbsp;<img src="http://blogs.telerik.com/photos/storage/slingbox_contest.jpg"><br><br><br></p> <p><b>To recap, the device known as <a href="http://origamiproject.com/">Origami/Haiku</a> </b>has a bright and interesting future as this <a href="http://seattletimes.nwsource.com/html/businesstechnology/2002898672_origami30.html">article at the Seattle News</a> clearly shows, so we will monitor closely the activities there. Expect nothing less than turning the mobile devices market upside-down when a player like Microsoft creates a new market niche with a high-tech device like Origami. And by the way the Origami team got a <a href="http://origamiproject.com/blogs/team_blog/default.aspx">nice blog</a> where you can read very interesting things, like the <a href="http://origamiproject.com/blogs/team_blog/archive/2006/03/08/6.aspx">History of Origami by Otto</a> (five parts for now).<b></b></p> http://blogs.telerik.com/DimitarKapitanov/Posts/06-04-20/origami_the_next_big_small_thing.aspx Dimitar Kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/06-04-20/origami_the_next_big_small_thing.aspx f1692914-f0d8-482b-8149-e31f27ed1905 Thu, 20 Apr 2006 18:34:00 GMT Creating a simple code snippet in Visual Studio 2005 – Part II Hi All,<br /> This is the second installment of the series "Code snippets in Visual Studio 2005". Well it has been quite a while since&nbsp;I updated&nbsp;my blog. My apologies, I think we all got too wrapped up in developing our new products and preparation of Q1 2006 release&nbsp;to remember to keep writing. However now I (having the time) intend to do just that.<br /> <br /> <p>So creating a code snippet is a relatively easy task, however I will make a real case to demonstrate the creation process (refresh your mind on the topic <a href="http://blogs.telerik.com/dimitarkapitanov/posts/06-02-21/Code_snippets_in_Visual_Studio_2005_Part_I.aspx">here</a>):</p> <p></p> <p>- First create a text file (with your preferred editor, mine is Notepad) with a <strong>.snippet</strong> extension.<br /> </p> <p>- Now open the saved text file (it will be actually an XML file) and after careful review of the Code Snippets Schema Reference ( <a href="http://msdn2.microsoft.com/en-us/library/ms171418.aspx">http://msdn2.microsoft.com/en-us/library/ms171418.aspx</a> ), we are ready to proceed further.</p> <p></p> <p></p> <p>The file must provide a valid XML schema in the first line so we will begin by declaring:</p> <p><strong>&lt;CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;<br /> </strong>[ code snippet content here]<br /> <strong>&lt;/CodeSnippets&gt;</strong><strong></strong></p> <p></p> <p></p> <p>Inside the CodeSnippets section we declare the snippet container as follows:</p> <p><strong>&lt;CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;</strong><br /> <strong>&nbsp;&nbsp; &lt;CodeSnippet Format="1.0.0"&gt;<br /> </strong>&nbsp;&nbsp;&nbsp;&nbsp; [ code snippet content here]<br /> <strong>&nbsp;&nbsp; &lt;/CodeSnippet&gt;<br /> &lt;/CodeSnippets&gt;</strong></p> <p></p> <p>Then we proceed by declaring a header section</p> <p><strong>&lt;CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;<br /> &lt;CodeSnippet Format="1.0.0"&gt;</strong><br /> <strong>&lt;Header&gt;<br /> </strong><strong>&nbsp;&nbsp; &lt;Title&gt;</strong><strong>Telerik sample snippet</strong><strong>&lt;/Title&gt;<br /> </strong><strong>&nbsp;&nbsp; &lt;Shortcut&gt;ItemCommand&lt;/Shortcut&gt;<br /> </strong><strong>&lt;/Header&gt;<br /> </strong>[ code snippet content here]<br /> <strong>&lt;/CodeSnippet&gt;<br /> &lt;/CodeSnippets&gt;</strong></p> <p>* The shortcut element is used for easier insertion of the code snippet – type <br /> "ItemCommand" and press Tab to insert the code snippet in a VB.NET project, or press Tab twice if in C# project. </p> <p></p> <p>And the real code snippet goes to the Snippet section:<br /> </p> <p><strong>&lt;CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&lt;CodeSnippet Format="1.0.0"&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Header&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Title&gt;Telerik sample snippet&lt;/Title&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Header&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&lt;Snippet&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&lt;References&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Reference&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Assembly&gt;System.Windows.Forms.dll&lt;/Assembly&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Reference&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&lt;/References&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&lt;Code Language="VB"&gt;<br /> </strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;![CDATA[MessageBox.Show("Hello World")]]&gt;<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Code&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&lt;/Snippet&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&lt;/CodeSnippet&gt;<br /> &lt;/CodeSnippets&gt;<br /> <br /> </strong></p> <p>There you can implement References section (only Visual Basic supports this section) </p> <p><strong>&lt;Snippet&gt;<br /> &lt;References&gt;<br /> &lt;Reference&gt;<br /> &lt;Assembly&gt;System.Xml.dll&lt;/Assembly&gt;<br /> &lt;/Reference&gt;<br /> &lt;/References&gt;<br /> &lt;Code Language=" CSharp"&gt;<br /> &lt;/Code&gt;<br /> &lt;/Snippet&gt;</strong></p> <p></p> <p>…the Imports section which is very useful if one wants to include commonly used namespaces, say Telerik.WebControls, Telerik.WebControls.UI:</p> <p></p> <p><strong>&lt;Snippet&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Imports&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Import&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Namespace&gt;Telerik.WebControls&lt;/Namespace&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Import&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Import&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Namespace&gt; Telerik.WebControls.UI&lt;/Namespace&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Import&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Imports&gt;&nbsp;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Code Language=" CSharp"&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Code&gt;<br /> </strong><strong>&lt;/Snippet&gt;<br /> <br /> </strong></p> <p>* There must be exactly one Namespace element in an Import element<br /> </p> <p>... and Code section ( in a specified language supported by the CLR). I will use code for a common scenario regarding the usage of <strong>Custom Item Commands</strong> in our <strong>r.a.d.grid</strong> component:</p> <p></p> <p>&lt;Snippet&gt;<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Imports&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Import&gt;<br /> </strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Namespace&gt;Telerik.WebControls&lt;/Namespace&gt;<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Import&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Import&gt;<br /> </strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Namespace&gt; Telerik.WebControls.UI&lt;/Namespace&gt;<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Import&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Imports&gt;&nbsp;<br /> </strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Code Language="<strong> CSharp</strong>"&gt;<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;![CDATA[</strong></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)<br /> &nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (e.CommandName == "EditSelected")<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (RadGrid1.SelectedIndexes.Count == 0)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (GridDataItem item in RadGrid1.SelectedItems)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item.Edit = true;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.Rebind();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (e.CommandName == "UpdateEdited")<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (RadGrid1.EditIndexes.Count == 0)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p> <p></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (GridDataItem item in RadGrid1.EditItems)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RadGrid1.MasterTableView.PerformUpdate(item, true);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.Rebind();&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p> <p></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (e.CommandName == "DeleteSelected")<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (RadGrid1.SelectedIndexes.Count == 0)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p> <p></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (GridDataItem item in RadGrid1.SelectedItems)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.PerformDelete(item, true);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.Rebind();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p> <p></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (e.CommandName == "CancelAll")<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (GridDataItem item in RadGrid1.EditItems)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item.Edit = false;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.IsItemInserted = false;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.Rebind();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;}<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;]]&gt;<br /> </strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Code&gt;<br /> &lt;/Snippet&gt;</p> <p></p> <p>(Supported languages are <strong>VB,</strong> <strong>CSharp</strong>, <strong>VJSharp</strong>, and <strong>XML</strong><strong>). </strong>Also all snippet code must be placed between <strong>&lt;![CDATA[ </strong>and <strong>]]&gt;</strong> brackets.<strong></strong></p> <p>So finally here is the complete code:</p> <p><strong>&lt;CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;<br /> &lt;CodeSnippet Format="1.0.0"&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&lt;Header&gt;</strong><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Title&gt;Telerik sample snippet&lt;/Title&gt;<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Header&gt;<br /> &lt;Snippet&gt;</strong><br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Imports&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Import&gt;<br /> </strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Namespace&gt;Telerik.WebControls&lt;/Namespace&gt;<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Import&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Import&gt;<br /> </strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Namespace&gt; Telerik.WebControls.UI&lt;/Namespace&gt;<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Import&gt;<br /> </strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Imports&gt;&nbsp;<br /> </strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Code Language="<strong> CSharp</strong>"&gt;<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&lt;![CDATA[</strong></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)<br /> &nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (e.CommandName == "EditSelected")<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (RadGrid1.SelectedIndexes.Count == 0)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (GridDataItem item in RadGrid1.SelectedItems)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item.Edit = true;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.Rebind();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (e.CommandName == "UpdateEdited")<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (RadGrid1.EditIndexes.Count == 0)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p> <p></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (GridDataItem item in RadGrid1.EditItems)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RadGrid1.MasterTableView.PerformUpdate(item, true);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.Rebind();&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p> <p></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (e.CommandName == "DeleteSelected")<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (RadGrid1.SelectedIndexes.Count == 0)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p> <p></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (GridDataItem item in RadGrid1.SelectedItems)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.PerformDelete(item, true);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.Rebind();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p> <p></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (e.CommandName == "CancelAll")<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (GridDataItem item in RadGrid1.EditItems)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item.Edit = false;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.IsItemInserted = false;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Item.OwnerTableView.Rebind();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;}<br /> <strong>&nbsp;&nbsp;&nbsp;&nbsp;]]&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&lt;/Code&gt;<br /> &lt;/Snippet&gt;<br /> &lt;/CodeSnippet&gt;<br /> &lt;/CodeSnippets&gt;<br /> <br /> <br /> </strong>Additional reading: <br /> <a href="http://msdn2.microsoft.com/en-us/library/ms165396.aspx">http://msdn2.microsoft.com/en-us/library/ms165396.aspx</a><br /> <br /> <a href="http://msdn2.microsoft.com/en-us/library/wy5tazc9.aspx">http://msdn2.microsoft.com/en-us/library/wy5tazc9.aspx</a></p> http://blogs.telerik.com/DimitarKapitanov/Posts/06-03-21/creating_a_simple_code_snippet_in_visual_studio_2005_–_part_ii.aspx Dimitar Kapitanov http://blogs.telerik.com/DimitarKapitanov/Posts/06-03-21/creating_a_simple_code_snippet_in_visual_studio_2005_%e2%80%93_part_ii.aspx 51282a4f-127e-4842-b379-e8750cc9249d Tue, 21 Mar 2006 10:24:00 GMT