Why you need to go with cloud computing?

So you are in the right place. Your heart and mind is confused with questions like, what is this cloud computing and why I need to bother about the same. So in this small article I am going to talk about “Why you need to go with cloud computing”.

So your company developed a social networking site like facebook .This was something a funny application by some of your developers. You just hosted your web site in a single server and your social media site had only 10 users. All of the 10 were pretty happy. The scenario is given below.

Web site with single server

Wow here comes your headache lots of cute girls joined your social networking site that too with their pics. Something attracted them. Mark Zukerberg gona suffer. Facebook is suffering because of your new web site. Boys also started to join your site, quite natural. Each day 10000 members are joining your site. What to do??The CEO is happy he gonna get lots of money. Headache for the developers and System administrator.

So the company decided to set up a server farm to load balance the increased user interactions.
Company bought 10 servers worth 20 lakh and some hardware load balancers. Over all investment was about 25 lakh. Then appointed some system administrators their salary is about 50000/month. Then comes uninterrupted power supply, broadband etc..The current model is given below.


A web farm serving your site in a load balanced environment

As usual girls lost interest your site. They move on to other web sites for some more fun. The boys also went behind. So the visitors count reduced. Now there is no need for 10 servers to handle load. The company decided to switch off some servers, job cut to some system administrators all happened.CEO is troubled his hardware left unused.

I wish your company don’t face such a situation. In such situations you can opt for cloud computing.

In cloud computing the company don’t need to buy any hardware servers load balancers, uninterrupted power supply etc..

In cloud computing environment when your websites load increased you can ask the cloud providers to increase the resources.

Also when load is decreased you can reduce your server resources.

Clearly speaking in cloud you don’t need to worry about hardware just concentrates on programming.

So now onwards cute girls won’t be a problem for your company

Install SharePoint Foundation 2010 in Wndows 7

Good after noon friends.One more weekend gonna end soon.I tink i am so lazy now a days,havnt wrote any single thing after my last post.
Yesterday i got some time to learn something new.I am hearing about this sharepoint from 2007.But unfortunately i was unable to learn it because i don’t have any windows 2003 server to install sharepoint.Our company is planning to implement an internal portal to manage documents,blog,discussions etc.So i think why i cant study some sharepoint technology myself for some demonstrations of project management.
I started some basic study on sharepoint technology.I am listing out some point i got from net.

Hardware available with me
————————–

I am using a Dell Vostro 1014 lap with core2duo processor and 2gb ram.Core2duo is 64 bit,But dell only provide 32 bit drivers for my lap.No problem we can install Win 7 64 bit on this lap.

Software environment
———————

1. I bought a windows 7 64 bit.Installed it with my old windows 7 32 as dual-boot.

2. Downloded SQL SERVER 2008 R2 EXPRESS 64 bit(with tools) and installed it.SQL SERVER 2008 R2 EXPRESS is free it only support 10gb database.
LINK:http://www.microsoft.com/download/en/details.aspx?id=23650 (SQLEXPRWT_x64_ENU.exe)

3. Download and install SQL SERVER 2008 R2 Native Client
Link:http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=16177 (Find native client in the page and download)

4. Download sharepoint foundation 2010 and save in the given directory “C:\SharePointFiles”.
LINK:http://www.microsoft.com/download/en/details.aspx?id=5970 (SharePointFoundation.exe).

5. Save the setup in C:\SharePointFiles.

6. Open the command prompt and change to directory using the command “cd c:\SharePointFiles”.

7. Then issue the command “SharePointFoundation.exe /extract:c:\SharePointFiles”.This command extract files from setup and save in SharePointFiles folder.

8.Using a text editor such as Notepad, open the installation configuration file, config.xml, located in the following path: c:\SharePointFiles\files\Setup\config.xml
Add this line inside the tag.

<Setting Id="AllowWindowsClientInstall" Value="True"/>

9. Save the config file.

10.Install .NET 4.0 Framework.
11.Install Microsoft FilterPack 2.0. At a command prompt, type the following: c:\SharePointFiles\PrerequisiteInstallerFiles\FilterPack\FilterPack.msi
12.Install Microsoft Sync Framework (http://go.microsoft.com/fwlink/?LinkID=141237).
13.Install Windows Identity Foundation (Windows6.1-KB974405-x64.msu) (http://support.microsoft.com/kb/974405)
14.Manually enable each of the required Windows Features. You can do this quickly by copying and running the following command in a Command Prompt window.Wait it will take sometime.

start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;^
IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;^
IIS-ApplicationDevelopment;IIS-ASPNET;IIS-NetFxExtensibility;^
IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-HealthAndDiagnostics;^
IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-HttpTracing;IIS-CustomLogging;IIS-ManagementScriptingTools;^
IIS-Security;IIS-BasicAuthentication;IIS-WindowsAuthentication;IIS-DigestAuthentication;^
IIS-RequestFiltering;IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;^
IIS-WebServerManagementTools;IIS-ManagementConsole;IIS-IIS6ManagementCompatibility;^
IIS-Metabase;IIS-WMICompatibility;WAS-WindowsActivationService;WAS-ProcessModel;^
WAS-NetFxEnvironment;WAS-ConfigurationAPI;WCF-HTTP-Activation;^
WCF-NonHTTP-Activation

15.To install SharePoint Server 2010 or SharePoint Foundation 2010, open a Command Prompt window, and then type the following at the command prompt:
c:\SharePointFiles\Setup.exe

16.On the Choose the installation you want page, click Standalone to install everything on one developer workstation.

17.After the installation is complete, you are prompted to start the SharePoint Products and Technologies Configuration Wizard.This step will create database files in sql server 2008 express.

18.Alternatively, you can choose not to run the wizard by clearing the SharePoint Products and Technologies Configuration Wizard check box and closing the completed installation dialog box.
then manually start the SharePoint Products and Technologies Configuration Wizard by opening a Command Prompt window and executing the following command:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\psconfigui.exe

19.After the configuration wizard is complete, you see the new SharePoint site.

Face Capture and Face Detection in c# using webcam PART 1

Hi Friends your friend vivek is here.The past month was very tough lots of emotional issues.Each days with .NET giving me new knowledge.
This time i was planning to develop an image based authentication system.My plan was to implement this system with in one day.

    Vivek’s Targets

1. Capture your face from your web cam.
2. Store that image and your information to a database.
3. Next time when you came to system,the system will check your face against the image stored in database.

In this article i just wanna implement the first step,that is how to capture image using a web cam.A small image of the application is given below.Hi hi i haven’t put my face on the application
because some of my friends always complain that i am writing blog for impressing girls.I don’t want that impression went to waste box.So put a match box in my hand.

OpenCV

    OpenCV is a tool developed by Intel in C++.OpenCV can do almost all image processing operations.Initially i planned to use OpenCV.Then i changed my mind because OpenCV
    is C++ oriented.After some Google search i found EMGU CV wrapper for .NET and c#.

    1. Capture your face from your web cam.

a. Download EmguCv and install it.
b. The installation folders bin folder contain all DLL’s for our development(C:\Emgu\emgucv-windows-x86 2.2.1.1150\bin).
c. Create a windows form project and add reference to Emgu.CV.dll,Emgu.CV.UI.dll,Emgu.Util.dll
d. Copy all OpenCV dll’s from Emgu’s bin folder(C:\Emgu\emgucv-windows-x86 2.2.1.1150\bin) to your applications Bin folder
e. Add Emgu controls to your visual studio toolbox from Emgu.CV.dll
f. Put an Emgu ImageBox in your form,in which we show captured image.
g. Put 2 buttons one to start capture image and next one to store that image to a database.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.Util;
namespace WebCamCapture
{
    public partial class Form1 : Form
    {
        private Capture _VivekCapTure;
        private bool _captureInProgress;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region if capture is not created, create it now
            if (_VivekCapTure == null)
            {
                try
                {
                    _VivekCapTure = new Capture();
                }
                catch (NullReferenceException excpt)
                {
                    MessageBox.Show(excpt.Message);
                }
            }
            #endregion
            if (_VivekCapTure != null)
            {
                if (_captureInProgress)
                {  //stop the capture
                    //captureButton.Text = "Start Capture";
                    Application.Idle -= ProcessFrame;
                }
                else
                {
                    //start the capture
                    //captureButton.Text = "Stop";
                    Application.Idle += ProcessFrame;
                }

                _captureInProgress = !_captureInProgress;
            }
        }
        private void ProcessFrame(object sender, EventArgs arg)
        {
            Image<Bgr, Byte> frame = _VivekCapTure.QueryFrame();
            captureImageBox.Image = frame;
            
        }
    }
}

POP3 client using c#

Hi Friends,

This time i am coming with a very small solution for POP3 mail download from mail services like gmail,yahoo etc.Our client was an aggressive guy who need an application to download mail from his mail server and store these mails and attachments into a database table.The time given was 24 hours.After some Google search we decided to use OpenPop.NET an open source library.You can download it from http://hpop.sourceforge.net/.

Below i am going to explain the basics steps to test the DLL.

1. Create a windows form application.
2. Add reference to OpenPop.NET.DLL
3. Put a button in the form and check the code behind
4. Provide your mail credentials.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using OpenPop.Mime;
using OpenPop.Mime.Header;
using OpenPop.Pop3;
using OpenPop.Pop3.Exceptions;
using OpenPop.Common.Logging;
using Message = OpenPop.Mime.Message;
namespace mailtest
{
    public partial class Form1 : Form
    {
        private Pop3Client pop3Client;
        private Dictionary<int, Message> messages;
        public Form1()
        {
            InitializeComponent();
            pop3Client = new Pop3Client();
            messages = new Dictionary<int, Message>();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ReceiveMails();
        }
        private void ReceiveMails()
        {
            try
            {
                if (pop3Client.Connected)
                    pop3Client.Disconnect();
                pop3Client.Connect("pop.gmail.com", 995, true);
                pop3Client.Authenticate("your@gmail.com", "yourpassword");
                int count = pop3Client.GetMessageCount();
                messages.Clear();
                int success = 0;
                int fail = 0;
                for (int i = count; i >= 1; i -= 1)
                {
                    try
                    {
                        Application.DoEvents();
                        string body;
                        Message message = pop3Client.GetMessage(i);
                        MessagePart plainTextPart = message.FindFirstPlainTextVersion();
                        if (plainTextPart != null)
                        {
                            // The message had a text/plain version - show that one
                            body = plainTextPart.GetBodyAsText();
                        }
                        else
                        {
                            // Try to find a body to show in some of the other text versions
                            List<MessagePart> textVersions = message.FindAllTextVersions();
                            if (textVersions.Count >= 1)
                                body = textVersions[0].GetBodyAsText();
                            else
                                body = "<<OpenPop>> Cannot find a text version body in this message to show <<OpenPop>>";
                        }
                        // Build up the attachment list
                        List<MessagePart> attachments = message.FindAllAttachments();
                        foreach (MessagePart attachment in attachments)
                        { }

                        // Add the message to the dictionary from the messageNumber to the Message
                        messages.Add(i, message);


                        success++;
                    }
                    catch (Exception e)
                    {

                        fail++;
                    }
                }
            }
            catch (InvalidLoginException)
            {
                //MessageBox.Show(this, "The server did not accept the user credentials!", "POP3 Server Authentication");
            }
            catch (PopServerNotFoundException)
            {
                //MessageBox.Show(this, "The server could not be found", "POP3 Retrieval");
            }
            catch (PopServerLockedException)
            {
                //MessageBox.Show(this, "The mailbox is locked. It might be in use or under maintenance. Are you connected elsewhere?", "POP3 Account Locked");
            }
            catch (LoginDelayException)
            {
                //MessageBox.Show(this, "Login not allowed. Server enforces delay between logins. Have you connected recently?", "POP3 Account Login Delay");
            }
            catch (Exception e)
            {
                //MessageBox.Show(this, "Error occurred retrieving mail. " + e.Message, "POP3 Retrieval");
            }
            finally
            {

            }
        }
    }
}

Facebook application development using ASP.NET and FacebookToolKit Version 3.0

It was an amazing day friends.After a long time of insanities in life,just got something great working out.I know you are familiar with facebook and Facebook applications like My Wedding Time,My Death Time etc.So i too got interested in facebook apps couple of days ago.I made some search on google to find how i can develop a sample one.To my surprise i found C# and ASP.NET based applications are supported by facebook.I am stopping the story and going directly to my today’s subject.

About Facebook application types:

———————————
Facebook allow us to develop apps based on FBML or IFRAME canvas.Unfortunately from 2011 facebook stopped supporting creation of new FBML based application.Old applications developed before 2011 on FBML will work fine.

So we can go with IFRAME based apps.

Prerequisites
————-

1. Visual studio 2008 or higher.
2. A hosting server with public URL that support ASP.NET 3.5,If you dont have a paid hosting server you can request a free ASP.NET hosting in aspspider.com.
3. Download latest FaceBookToolKit from http://facebooktoolkit.codeplex.com/ .
4. To create a facebook application you need a verified developer account in facebook.I will explain later about it.

So Let Us Start
—————

I have a paid domain for example let it be ‘http://example.com/’ ,i created a folder named ‘FBApp’ in the server where i want to put my code files.So my hosting location will be ‘http://example.com/FBApp/’

Confirming Developer Accounts
—————————–

To create applications your facebook account must be verified.Facebook supports 2 methods for verification mobile and credit card based.We will go for mobile based verification.

To verifies your mobile go to link ‘http://www.facebook.com/confirmphone.php’.If your account is already verified they show a message ‘Your mobile phone has been successfully verified’.Select your country and give your mobile number,Facebook will send verification code to your mobile.

To know more about read ‘http://developers.facebook.com/blog/post/386/

Create and setting your application properties in facebook

———————————————————-

1.Log in to your face book account.
2.In the search bar type ‘developer’ as shown in the below pic.

3.Clicking on developer opens the application creation page on that click ‘Set Up New App’.

4.Give your application name in next page as shown below.

5.Click on ‘Create App’ button.
6.Then comes a page as shown below it has side menus like ‘About’,'Website’,'Facebook Integration’.

5.In the ‘About’ page you can set icons and logo for your application.
6.Now click on the ‘WebSite’ link copy your Application Id and Application Secret.Both are needed for authentication.

7.Now click on ‘Facebook Integration’ link,this is a very importent page.Here you have to fill 2 entries Canvas page and Canvas URL
Canvas page is the link of your application in facebook like http://app.facebook.com/yourappname/.Canvas URL is the call back URL where we are hosting our asp.net code files.
As i told earlier i am going to host files in ‘http://example.com/’ ,i put the code files in a folder FBApp so my Canvas URL become ‘http://example.com/FBApp/’ .

Please not we are not completed,We just set application properties in face book your application URL will be ‘http://app.facebook.com/yourappname/’,You can share this link to your friends.
Now we can write code for our application.

The facebook tool kit includes some DLL files,Which are to be referenced in our ASP.NET application.

1. Create a new web site in VS2008.

2. Add reference to Facebook.dll,Facebook.Web.dll

3. Edit the Web.config file add an section with your api id and secretkey(Application Id and Application Secret)

  <appSettings>
    <add key="APIKey" value="YourApplicationid"/>
    <add key="Secret" value="Your application secret id"/>
    <add key="Callback" value="http://example.com/FBApp/"/>
    <add key="Suffix" value="project name in facebook"/>
  </appSettings>
  

4. Add an ASPX page with following mark up to include a label.

    <asp:label ID="labelUser" runat="server" text=""></asp:label> 

5. Add the following code in CS file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook;
using Facebook.Web;
using Facebook.Session;
using Facebook.Rest;
using System.Configuration;

public partial class _Default : CanvasIFrameBasePage
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        base.RequireLogin = true;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            labelUser.Text = Api.Users.GetInfo().name;

        }
    }
}

Note the points the page is inherited from ‘CanvasIFrameBasePage’ and PreInit is override.

6.Now copy your code files to FBApp folder in wwwroot of example.com and then go to facebook type your URL ‘http://app.facebook.com/yourappname/’
Your application is ready it shows your name.

Create proxy of WCF web service with svcutil

So dear friends today i am writing about how to consume a real world WCF service in your application.Below i am listing the steps you must follow.

1.Get the URL of our web service,like http://demo.myservice.com/Service/MyWebService.svc.

2.Open the visual studio command prompt type the following command

svcutil.exe http://demo.myservice.com/Service/MyWebService.svc?wsdl

3.Go to your visual studio command directory like (d:\Program Files\Microsoft Visual Studio 2008\VC).

4.You can find a c sharp class file named MyWebService.cs and an output.config file.

5.Add MyWebService.cs file to your project,Refer this in your classes.

6.The following name spaces should be needed in your consuming class.

using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Description;

7.Open the output.config file you obtained through svcutil.An output.config file is given below

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_ICarService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://demo.myservice.com/Service/MyWebService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="IMyService" name="BasicHttpBinding_IMyService" />
        </client>
    </system.serviceModel>
</configuration>

8.Note the enpoint address here is http://demo.myservice.com/Service/MyWebService.svc

9.Binding is BasicHttpBinding.

10.Create binding using the following code.

            BasicHttpBinding binding = new BasicHttpBinding();
            binding.Name = "BasicHttpBinding_IMyService";
            binding.CloseTimeout = TimeSpan.FromMinutes(1);
            binding.OpenTimeout = TimeSpan.FromMinutes(1);
            binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
            binding.SendTimeout = TimeSpan.FromMinutes(1);
            binding.AllowCookies = false;
            binding.BypassProxyOnLocal = false;
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.MaxBufferSize = 65536;
            binding.MaxBufferPoolSize = 524288;
            binding.MessageEncoding = WSMessageEncoding.Text;
            binding.TextEncoding = System.Text.Encoding.UTF8;
            binding.TransferMode = TransferMode.Buffered;
            binding.UseDefaultWebProxy = true;

            binding.ReaderQuotas.MaxDepth = 32;
            binding.ReaderQuotas.MaxStringContentLength = 8192;
            binding.ReaderQuotas.MaxArrayLength = 16384;
            binding.ReaderQuotas.MaxBytesPerRead = 4096;
            binding.ReaderQuotas.MaxNameTableCharCount = 16384;

            binding.Security.Mode = BasicHttpSecurityMode.None;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
            binding.Security.Transport.Realm = "";
            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            binding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;

11.Create an endpoint.

EndpointAddress ed = new EndpointAddress("http://demo.myservice.com/Service/MyWebService.svc");

12.Create a web service client of the proxy class using the binding and endpoint we created.

ServiceClient _client = new ServiceClient(binding, ed);

Create vertical text in internet explorer and mozilla using CSS

Do u want to show vertical text in browsers like below.

This is the code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        .test
        {
            display: block;
            writing-mode: tb-rl;
            -webkit-transform: rotate(-90deg);
            -moz-transform: rotate(-90deg);
            position: absolute;
            float: left;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <td class="test" style="font-size: xx-large">
                vivek
            </td>
        </tr>
    </table>
</body>
</html>

Adding assembly specific application configuration file

Hi friends vivek here.So you want to add a confifuration file to one of your assembly,and that assembly is used in an ASP.NET application.You cant achieve it directly. Because one aplication domain of ASP.NET support only one configuration file thats the web.config.But dont worry i have a solution for that.

1.Create an aseembly named Logger.
2.Add an application configuration file to this assembly name it as Logger.dll.config(The config file name should conatin your assembly name).
3.Wrte this tag in your configuraion file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <assemblySettings>
    <add key="OTA" value="Data Source=server\SQL2008;Initial Catalog=db;User ID=sdfx;Password=sdfs;Provider=SQLOLEDB"/>
  </assemblySettings>
</configuration>

4.Add a class named AssemblySettings.cs in your library with the below code.
using System;
using System.Reflection;
using System.Collections;
using System.Xml;
using System.Configuration;
using System.Runtime.CompilerServices;


namespace OTA.API.Logger
{
    internal class AssemblySettings
    {
        private IDictionary settings;

        [MethodImpl(MethodImplOptions.NoInlining)]
        public AssemblySettings()
            : this(Assembly.GetCallingAssembly())
        {
        }

        public AssemblySettings(Assembly asm)
        {
            settings = GetConfig(asm);
        }

        public string this[string key]
        {
            get
            {
                string settingValue = null;

                if (settings != null)
                {
                    settingValue = settings[key] as string;
                }

                return (settingValue == null ? "" : settingValue);
            }
        }

        public static IDictionary GetConfig()
        {
            return GetConfig(Assembly.GetCallingAssembly());
        }

        public static IDictionary GetConfig(Assembly asm)
        {
            // Open and parse configuration file for specified
            // assembly, returning collection to caller for future
            // use outside of this class.
            //
            try
            {
                string cfgFile = asm.CodeBase + ".config";
                const string nodeName = "assemblySettings";

                XmlDocument doc = new XmlDocument();
                doc.Load(new XmlTextReader(cfgFile));

                XmlNodeList nodes = doc.GetElementsByTagName(nodeName);

                foreach (XmlNode node in nodes)
                {
                    if (node.LocalName == nodeName)
                    {
                        DictionarySectionHandler handler = new DictionarySectionHandler();
                        return (IDictionary)handler.Create(null, null, node);
                    }
                }
            }
            catch
            {
            }

            return (null);
        }
    }
}

5.Create a class Log.cs from that class you can acess config file value as

AssemblySettings ASM = new AssemblySettings(System.Reflection.Assembly.GetExecutingAssembly());
String ConnectionString = ASM["OTA"].ToString(); 

Validate an XML aganist an XSD Schema stored as embeded resource in a DLL

STEPS
—–

1.Add the schema to your library
2.Right click on the schmema file select properties set build action as embed resuorce.
3.Write a class XMLSchema in your library as shown below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.IO;
using System.Configuration;
using System.Diagnostics;
using System.Reflection;
using System.Data;
namespace XMLParser
{
    public class XMLSchema
    {
        public bool ValidateXml(string xml,string xsdName)
        {
            try
            {
                //Declare a StreamReader and a StreamWriter
                StreamReader strmrStreamReader;
                //Extract the Resource using this line. Notice the namespace... ReadWriteResourceFromDLLorEXE!
                strmrStreamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("XMLParser."+xsdName));
                //Here we are creating a new file in the Application Startup path, and for fun
                //we are also changing the name to NewFile.txt
                System.Xml.Schema.XmlSchema xSchema = new System.Xml.Schema.XmlSchema();
                xSchema = XmlSchema.Read(strmrStreamReader, null);
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.Schemas.Add(xSchema);
                settings.ValidationType = ValidationType.Schema;
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(xml);
                XmlReader rdr = XmlReader.Create(new StringReader(xDoc.InnerXml), settings);
                while (rdr.Read())
                { }
               
            }
            catch
            {
                return false;
            }
            return true;


        }
        public bool ValidateXml(XmlDocument xml)
        {
            return false;
        }
    }
}

4.Create an instance of the XmlSchema class and call the method ValidateXml() with your xml and,the name of XSD u add as resource in your dll

Object oriented basics part 1

Hi
My dear friends once agaian after a long time i am again started to continue my articles on programming.Sorry friends i was in some personel issues so i was unable to find time for some knowledge sharing.This time i am coming with concepts behind object oriented programming,its a series on which i will discuss about.

1.Object and Classes
2.Features of OOPS like abstarction,encapsulation with real world examples
3.Inheritence polymorphisam with real word usage

So read first part

1.What is the difference between Object oriented programming and procedure oriented programming?
Procedural programming means breaking your program into functions; where each function performs an specific task. You pass data back and forth to these functions, each function processes the data just a bit. Hence functions are the basis of the code and data plays a secondary role.So this might be called “Functions Oriented” programming, or if you will, “Procedure based” programming AKA Procedural Programming.

With Object Oriented Programming, the data has bound functions (known as “methods”) that process the data they are bound to.So you no longer pass data back and forth between functions, you just call the functions that are bound to data (albeit you still may pass parameters as extra information for these functions to perform more specific tasks).
You might call this “Data Oriented Programming”, but in OOP, the data that has bound functions is known as Object, so it is called “Object Oriented Programming”

What is Object Oriented programming?

It is a technique to think real world in terms of objects.These objects are maped into software model.

What is a class?

A class describes all the attributes of objects ,as well as the methods that implement the behaviour of member objects.A
class can be considered as the blue print or template of an object.

For example i am modeling a point(a real world mathematical point with x and y co ordinates) as a class here.


class Point
{
// constructor
public Point(int a, int b)
{
this.x = a;
this.y = b;
}

// member fields
public int x;
public int y;

//Method
public void MovePoint(int a, int b)
{
this.x = x;
this.y = y;
}
}

Friends one thing i want to say,The class has no life.its just a text of code.
The above class has 2 member fields that represent the x and y co-ordinate of a point.
The constructor of the class is invoked on creating the object of the class.
MovePoint() is a method avialble in our class to move the point across x and y co ordinates.

What is an object?

An object is the nstance of the class
ex: we can create an object of the above Point class as

Point p=new Point(10,20);

What is the difference between Object and class?

Both looks same but different,as i told earlier a class is just a blue print,but object has life,the object is the thing
that is avilble in memory on creation

Follow

Get every new post delivered to your Inbox.