Tuesday, May 10, 2011

C# - Spell Check

    public void SpellCheck(TextBox tBox, Label lLbl)
        {
            int iErrorCount = 0;
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            if (tBox.Text.Length > 0)
            {
                app.Visible=false;
                // Setting these variables is comparable to passing null to the function.
                // This is necessary because the C# null cannot be passed by reference.
                object template=Missing.Value;
                object newTemplate=Missing.Value;
                object documentType=Missing.Value;
                object visible=true;
                object optional = Missing.Value;
           
                _Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
                doc.Words.First.InsertBefore (tBox.Text );
                ProofreadingErrors we =  doc.SpellingErrors;
                iErrorCount = we.Count;

                doc.CheckSpelling( ref optional, ref optional, ref optional, ref optional,
                    ref optional, ref optional, ref optional,
                    ref optional, ref optional, ref optional, ref optional, ref optional);
   
                if (iErrorCount == 0)
                    lLbl.Text = "Spelling is correct. No errors corrected ";
                else if (iErrorCount == 1)
                    lLbl.Text = "Spelling is correct now. 1 error corrected ";
                else
                    lLbl.Text = "Spelling is correct now. " + iErrorCount + " errors corrected ";
                object first=0;
                object last=doc.Characters.Count -1;            
           
                tBox.Text = doc.Range(ref first, ref last).Text;                
            }
            else
                lLbl.Text = "Textbox is empty";

            object saveChanges = false;
            object originalFormat = Missing.Value;
            object routeDocument = Missing.Value;
            app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
        }

Ethical Hacking


Prevent Dll to be decompiled or disassembled

By design .NET embeds rich Meta data inside the executable code using MSIL. Any one can easily decompile or disassemble your DLL using tools like ILDASM (owned by Microsoft) or Reflector for .NET which is a third party.

Secondly there are many third party tools which make this decompiling process a click away. So any one can easily look in to your assemblies and reverse engineer them back in to actual source code and understand your logic which can make it easy to crack your application.
The process by which you can stop this reverse engineering is using “obfuscation”.

It’s a technique which will foil the decompilers. There are many third parties (Dotfuscator, XenoCode, Demeanor for .NET, Crypto Obfuscator, etc…) which provide an obfuscation solution.  When evaluating obfuscators, they are not all equal in quality.   Most do not handle XAML well if at all.  Also, some products are more sophisticated than others with basic obfuscation as well as string encryption.  Cheaper is not always better.

Microsoft includes Dotfuscator Community Edition with Visual Studio.NET but it may not be sophisticated enough for your application.

Cloud Computing – SaaS+PaaS+IaaS+Daas

Trying to understand the complexities of Cloud-based services can be like navigating through a minefield, particularly if you’re an ISV looking to broaden your product offering. With that said, here’s a quick 101 in the basic concepts of cloud services, which should help clear the muddy waters a little.
SaaS – Software-as-a-Service is a model of software deployment whereby a provider licenses an application to customers for use as a service on demand. One example of SaaS is the Salesforce.com CRM application.
IaaS – Infrastructure-as-a-Service is the delivery of computer infrastructure (typically a platform virtualization environment) as a service. Rather than purchasing servers, software, data center space or network equipment, clients instead buy those resources as a fully outsourced service. One such example of this is the Amazon web services.
PaaS – Platform-as a-Service is the delivery of a computing platform and solution stack as a service. It facilitates the deployment of applications without the cost and complexity of buying and managing the underlying hardware and software layers. PaaS provides the facilities required to support the complete lifecycle of building and delivering web applications and services. An example of this would the GoogleApps.
DaaS – Desktop-as-a-Service enables users to use their desktops virtually from anywhere. Commonly known as “Desktop Virtualization”, this concept separates personal computer desktop environments from the physical machine through a client-server computing model. Nowadays, with the rise of SaaS and RIA (Rich Internet Applications) this method of usage is becoming obsolete.
So what does all this mean to you? Well, as a precursor to adopting the Cloud Computing model, you first need to have an application that is “Cloud ready”

10 excuses your boss doesn’t want to hear

1: I didn’t understand the assignment
2: The deadline was impossible
3: A valuable resource was not available
4: The requirements shifted
5: I have personal issues
6: I don’t have enough time
7: I don’t know what went wrong
8: We ran into blockages
9: The only copy of the work got destroyed
10: The dog ate my homework

BizTalk – How does one create a Singleton Orchestration?

1.    Create a correlation type with the property “BTS.ReceivePortName;” this will ensure a single instance of an orchestration, since all the messages come from a single receive location.

2.    Create a correlation set with the correlation type created in the previous step.

3.    In the first Receive Shape (Activate = true), set the property “Initializing Correlation Sets” as the correlation set (created in the previous step) and in the Second receive shape (Activate = false), set the property “Following Correlation Sets” as the correlation type (created in the previous step).

NOTE: Any promoted property which would be the same across all the messages can also be used as the correlation type property.

The first message that arrives at the Receive port creates a new instance of the Orchestration. All other messages would use the same Orchestration for processing.

A BizTalk Correlation would ensure that the messages which arrive into the Orchestration have at least one similar property.  For example, the messages arrive from the same Receive Port or they have the same InstanceID or flag property. For a single Orchestration to exist, all the messages which arrive at the orchestration must have one common property. This common property of the messages must be encapsulated into a Correlation set.

The Correlation set created above shall be initialized on the receipt of the first message which creates the Singleton Orchestration, all other subsequent messages would use the same Correlation set and, therefore, the same Orchestration instance.

Cannot open database “db1″ requested by the login. The login failed for user ‘Machine\ASPNET’

Here’s a quick breakdown of some options:
1.)  Use a user name and password in the connection string
2.)  Have the application run under a different account that has permission to access the database
3.)  Grant permission to the ASP.NET account
4.)  Consider having ASP.NET impersonate the current user
I hope this information proves helpful.
———————————————–
Try executing a query like:
exec sp_grantlogin ‘MachineName\ASPNET’
———————————————–
<identity impersonate=”true”
userName=”domain\user”
password=”password” />