Skip to main content

Posts

Silverlight: Access template control programmatically

If you are working on a Silverlight application, it's very imperative that you will end up wanting to assess a control from a design template. Let's say I have a template where a CheckBox control is defined and if I want to access this control in my code behind, there is no direct way to do it. ... < ControlTemplate .. > < Grid >... < CheckBox x : Name ="chkAll" ... /> </ Grid > </ ControlTemplate /> ... The following method will recursively look for this control hiding anywhere in the control template against its name and return it when found. private object GetChildControl( DependencyObject parent, string name) { Object control = null ; int count = VisualTreeHelper.GetChildrenCount(parent); for ( int counter = 0; counter < count; counter++) { control = VisualTreeHelper.GetChild(parent, counter); //name supplied then Return Control if t...

A simple jQuery slideshow

I have used jQuery animate() method to create a simple slideshow. I am toggling the opacity of the image from 0 to 1 and also changing the URL of the image. Script: function AnimateImg() { var imgUrls = new Array("picture1.png", "picture2.png", " picture3.png "); var opacVal = 0; var currentImage = imgUrls[0]; var index = 0; var DELAY = 1000; setInterval(function() { $("#animate-img").animate({ opacity: opacVal }, DELAY, function() { if (opacVal == 0) { opacVal = 1; } else { opacVal = 0; } if (index == imgUrls.length) { index = 0; } if (opacVal == 0) { currentImage = imgUrls[index++]; $("#animate-img").attr("src", currentImage); } }); }, DELAY ); } HTML: ...

A jQuery modal wait dialog

The jQuery UI modal dialogs are great add-ons but they don’t necessary fit well when you just have to show a wait message. There are issues with removing the title bar and styling the dialog. BlockUI is another alternative but I find it little hard to style using css. This is how I came up with a wait dialog. I am using two divs here. First div will cover the page content in such a way that the content is still visible but user cannot perform any action. For this, I need a div with near transparent background (opacity of 0.8).        #loading-div-background       {         display : none ;         position : fixed ;         top : 0 ;         left : 0 ;         background : black ;         width : 100% ;  ...

Android PC ??

Looks like you will be carrying your PC in your pocket. A company has built a USB which connects your andriod phone to a display panel through HDMI interface. You can also connect it to your PC and android will appear as your virtualized desktop.

TFS Build Error Copying Silverlight XAP file

I was trying to automate build for Silverlight project using Team Foundation Server and build was failing with the following error. Copying my.xap file failed. Access to path '..' denied. Digging deep in the build log, I found that this is happening while copying the source files from TFS to the build folder for compilation. Since xap is an output file it is not required during the compilation. I avoided the download/copy of the xap file by denying access to the build agent. The steps are mentioned here .

Specifying Reference Paths in TFS 2010 build definition

While creating build definition using TFS 2008, we could specify the path(s) where the build server could look for the references. This was of great help as it avoided installing dependent assemblies in the GAC in the build server. It was easily done by editing the project file and adding <AdditionalReferencePath> element. In Team Foundation Server 2010 , the build definition are workflow based and if you are creating any build definition using default template, there is no option to specify the additional reference paths. Since, new template also supports the msbuild arguments, we have to specify the reference path as a build argument. For this we have to add "ReferencePath" as property to the msbuild arguments. Go to Team Explorer >> Build Defintion >> Edit Build Definition >> Process >> Advanced Section >> MSBuild Arguments and Add the following: /p:ReferencePath=”{File path}” We can specify multiple reference paths separat...

The type 'System.Xml.IXmlLineInfo' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'

I have been getting this weird exception out of nowhere while compiling my solution. Turns out I had two projects in my solution using different System.Xml assembly. One using straight from .NET Framework 2.0 and other using assembly 2.0.5.0. ( from Silverlight runtime). Referenced path were C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll & C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Xml.dll respectively. If a project file does not specify the exact reference assembly, compiler tries to use any matching assembly present in its cache. I could see the following reference in my csproj file. <Reference Include="System.Xml"/> I updated this reference with the correct version (along with the PublicKeyToken and Culture info) and made the SpecificVersion=True, enforcing compiler to use the specified assembly <Reference Include="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934...

Sporadic 'ORA-01001 Invalid cursor' error in Oracle 11g

According to the Oracle documentation, " The ORA-01001 error occurs when: A host language program call gave an invalid cursor for use The value of the MAXOPENCURSORS option in the precompiler command was too small You can fix the ORA-01001 error by: Checking your problematic call statement for any issues Specifying a correct LDA area or open the cursor as required Increasing the MAXOPENCURSORS option value before precompiling As a note, the ORA-01001 error does not exist in Oracle 10g" After debugging for almost a day following the above hints, I came to realise there is nothing wrong with my PL/SQL or with the configuration settings. Sporadic "ORA-01001: invalid cursor" error occurs in Oracle 11g if there are RAM memory issues on the server. If the same client call works once and fails the other minute with this error, you can check the server for memory issues before debugging further.

Windows Sleep command

I have a really long bat file where I need to introduce delay between subsequent commands. But there is no sleep command in DOS. There is an workaround for this, we can use ping command to emulate sleep. Usage ping 1.1.1.1 -n 1 -w 10000 switch -n specifies number of echo request to be sent. switch -w specifies number of milliseconds to wait for each reply.

Public Key Token of an assembly

There are times when you need to get the public key token of an assembly. Okay the only time is when you need to put in config files. The answers is same old sn.exe . That's right the same .NET strong name tool we use to generate snk files. Usage: sn -T helloWorld.dll This gives you the public key token of the strong named assembly. Just wanted to share.

Passing parameters to a function in setTimeout()

While working on some 'animation' effect on one of my pages, I came across a problem when using setTimeout() . I am using it to call a function repeatedly in certain interval. I am not much into javascript so had quite a trouble figuring it out. If the function which is being called does not have any input parameters, setTimeout(MyFunc(),10); // calls 'MyFunc' function every 10 ms. But my 'Animate' function takes a parameter ( divId ),so I tried setTimeout(Animate(divId),10); // wrong !! This did not work. The correct way to call a function with parameters in setTimeout function is. setTimeout( function (){Animate(divId);}, 10); This concept is called 'Closure' in javascript. Just wanted to share...

Database Indexes

I went through a lot of articles to find out the exact differences between clustered and non-clustered indexes. I have "simplified" the findings, especially for the people (like me) who like to learn things in brief. Non-Clustered Index The index in the back of any book is good example of a non-clustered index. Any topic may be easily found in the book by first finding it in the book index and the index will give the page number of the topic. So, it requires two "look ups" to find a topic. Now in database context we need to first find the position of the index entry and the go to the data page where the rows are present. The leaf node of the B-Tree (data structure index are built on) are the data pages where the rows are stored physically. Clustered Index A Phonebook is good example of a clustered index i.e. data and index both are merged together. It requires just one look up to find the data row. Since the data are stored as per the order of the index, there can b...

Code Metrics for a developer

Here are some code metrics each developer should be tracking all along. Cyclomatic complexity: Cyclomatic complexity of a program is the count of the number of linearly independent paths of execution. If the source code contained no decision points ( such as 'if' 'switch' 'while' ), the complexity would be 1, FLAT CODE, since there is only a single path through the code. If the code has a single ‘if’ statement there would be two paths through the code, one path where the ‘if’ statement is evaluated as true and one path where the ‘if’ statement is evaluated as false. So the complexity increasing with number of decision points in your code. If you have not written your decision statements properly, it will lead you into unnecessary conditions and hence complexity of the program increases. Measuring CC tells you 2 important things. How many ways your execution may end up. If you have higher CC, then maybe you can re-write your logic to make fewer conditions. It t...

Extension Methods

It's been a while working on Visual Studio 2008 but there are new features I still didn't use. Extension method is one of them.Extension methods, are a way to call static method by an instance using instance method syntax. There are occasions when you call static methods where you pass an instance as first parameter. for e.g: We often copy arrays as Array .Copy(source,destination....); would not it be more readable if we can invoke it like source.Copy (Destination); Extension methods make it possible. But example above has hardly anything to do with the word 'Extension'. So, the main idea of a extension method is to enable developers to write a method outside its class definition (of course on requirement basis) and use it just like any instance method. Let's say I want to extend functionality of an existing type string . I want to add a new method IsValidPinCode , just like IsNullOrEmpty or any other pre-defined methods. I can do it easily by "EXTENDING"...

Functional Programming

You must have seen the amount of interest that is being generated for LINQ, Lamba Expressions with the release of C# 3.0.The entire Data Access Architecture has been focused on to LINQ to SQL, LINQ to XML and LINQ to Objects and more. So what exactly is Functional programming ? FP is a programming model that treates computation as the evaluation of mathematical function. For e.g, if we define two functions like given below f(x) = x^2 + x + 1 g(x,y) = x * y A problem f (g (2, 2) ) will be evaluated by compiler as g(2*2)^2 + g(2*2) + 1 (4)^2 + (4) + 1 16+ 4 + 1 21 It is a declarative way of programming, where we leave the compiler to do the evaluation as late as possible. The user is only bothered about the result and not on how it is being evaluated.The focus is never on in the state transition of the variables, so one need not bother about the side effects. Advantages:  As the functional units do not have side effects, so their orders could be reversed.  They can be performed ...

XMPP

eXtensible Messaging and Presence Protocol (XMPP) is a protocol to stream XML elements for messaging, presence and request-response services. It is mainly used in building IM and presence based applications. The protocol is not coupled to any network architecture, but it’s generally used in client-server architecture. An XMPP server can communicate with its clients (recommended port: 5222) or with other XMPP servers (recommended port: 5269) over a TCP connection. An example network architecture could be like The gateway is necessary to translate the messages between a non-XMPP server and an XMPP server. All XMPP messaging happens in the form of Streams and Stanzas. Stream is the container for all messages sent from one entity to the other. A stream is initiated with a stream > tag and is destroyed with a / stream > tag. Multiple XML elements can be sent over the connection before the stream is closed. These streams are unidirectional i.e. if a client initiates a stream with the s...

LINQ - Introduction

LINQ (Language Integrated Query) introduces a generic and standard pattern for querying and updating data store of any kind. Basically a query is an expression that retrieves data from a data source. Queries are usually expressed in a specialized query language. I assume LINQ is intoduced to decouple the query language from the datasource. This avoids a lot of "unnecessary" learnings, because literally there is query language for each type of data source be it SQL databases, ADO.NET datasets, Collections types and XML documents. A LINQ query operations has there distinct phases:   Recognizing the Data Source With LINQ, there is another concept that has been introduced called Queryable, implementing interface IQueryable. Any Enumerable type is a queryable type and it requires no modification as a LINQ data source. If the source data is not already in memory as a queryable type, the LINQ provider must represent it as such. For example, LINQ to XML loads an XML document into a q...

Marshalling Array of Structures

It is fairly easy to Marshal simple structures in .NET but when it comes to sending a whole bunch of structures as parameter it’s little head scratching task if you have not done it already. The worst part is you won’t find any articles on how one should go about it. When I had to marshal an array of structures, every time I ran into same state of confusion. I decided to blog it this time (for future reference of course :) ) So let’s assume there is a structure called StructType and structArray be an array of StructType . //Lets not bother about how the array was populated StructType [] structArray = new GetStructArray(); // Get the size of each element int structSize = Marshal .SizeOf(structArray [0]); Here int can be replaced with long (depends on 32 bit or 64 bit addressing) // Total size of the memory block IntPtr ptr = Marshal .AllocHGlobal(structSize * structArray.Length); int addr = ( int )ptr; for ( int index = 0; index {     Marshal ....