private int downloadAndExtractZipFiles()
        {
            try
            {
                crm = CRMName;
                crm += "_CRM";
                Assembly ass = Assembly.GetEntryAssembly();
                filename = crm + ".zip";

                #region Download Zip File using WCF FileTranserService

                try
                {
                    BasicHttpClient bhcFtsj = new BasicHttpClient();
                    
                    clientHttpFileTransfer = (IHTTPFileTransferService)bhcFtsj.OpenClient<IHTTPFileTransferService>("http://" + VMuktiInfo.BootStrapIPs[0] + ":80/VMukti/HttpFileTransferService");
                    clientHttpFileTransfer.svcHTTPFileTransferServiceJoin();
                    DownloadRequest request = new DownloadRequest();
                    RemoteFileInfo rfi = new RemoteFileInfo();
                    request.FileName = filename;
                    request.FolderWhereFileIsStored = "CRMs";

                    

                    rfi = clientHttpFileTransfer.svcHTTPFileTransferServiceDownloadFile(request);

                    //rfi = clientHttpFileTransfer.svcHTTPFileTransferServiceDownloadFile(destination);
                    
                    //rfi=clientHttpFileTransfer.svcHTTPFileTransferServiceDownloadFile( ("D:\Users\KLS\CRMDesignerTestApplication\CRMDesigner_TestApplication\bin\Debug");

                    if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"CRMs")))
                    {
                        Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"CRMs"));
                    }

                    destination = ass.Location.Replace("VMukti.Presentation.exe", @"CRMs");

                    filePath = destination + "\\" + filename;
                    System.IO.Stream inputStream = rfi.FileByteStream;

                    using (System.IO.FileStream writeStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create, System.IO.FileAccess.Write, FileShare.ReadWrite))
                    {
                        int chunkSize = 2048;
                        byte[] buffer = new byte[chunkSize];

                        do
                        {
                            // read bytes from input stream
                            int bytesRead = inputStream.Read(buffer, 0, chunkSize);
                            if (bytesRead == 0) break;

                            // write bytes to output stream
                            writeStream.Write(buffer, 0, bytesRead);

                        } while (true);
                        writeStream.Close();
                    }

                }
                catch (Exception ex)
                {
                    VMuktiHelper.ExceptionHandler(ex, "downloadAndExtractZipFiles(Download Zip File)", "ctlCRMDesigner.xaml.cs");
                    return -1;
                }
                #endregion


                #region Extracting


                if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"CRMModules")))
                {
                    Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"CRMModules"));
                }

                try
                {
                    crm = CRMName;
                    crm += "_CRM";
                    Assembly ass2 = Assembly.GetEntryAssembly();
                    crmModPath = ass2.Location.Replace("VMukti.Presentation.exe", @"CRMModules");
                }
                catch (Exception ex)
                {
                    VMuktiHelper.ExceptionHandler(ex, "downloadAndExtractZipFiles(Extracting)", "ctlCRMDesigner.xaml.cs");
                }

                try
                {

                    VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
                    //ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();


                    //if (!Directory.Exists(crmModPath + "\\" + crm))
                    {
                        //fz.ExtractZip(destination + "\\" + filename, crmModPath , null);
                        fz.ExtractZip(destination + "\\" + filename, crmModPath + "\\" + crm, null);
                    }
                }
                catch (Exception ex)
                {
                    VMuktiHelper.ExceptionHandler(ex, "downloadAndExtractZipFiles(creating zip)", "ctlCRMDesigner.xaml.cs");
                }
                
                
                #endregion

            }
            catch (Exception ex)
            {
                //VMuktiHelper.ExceptionHandler(ex, "downloadAndExtractZipFiles(Outer)", "ctlCRMDesigner.xaml.cs");
                return -1;
            }
            return 0;
        }
        void FncSaveFiles()
        {
            g = 0;
            try
            {
                Assembly ass2 = Assembly.GetEntryAssembly();

                crmModPath = ass2.Location.Replace("VMukti.Presentation.exe", @"CRMModules");

                DirectoryInfo d = new DirectoryInfo(crmModPath);


                //  MessageBox.Show(strModPath);
                foreach (DirectoryInfo subDir in d.GetDirectories())
                {
                    // ShowDirectory(subDir);
                    // MessageBox.Show(subDir.Name);
                    foreach (DirectoryInfo subDir2 in subDir.GetDirectories())
                    {
                        string[] del = { crm };
                        if (subDir2.Name.Contains(crm))
                        {
                            string[] name = null;
                            name = subDir2.Name.Split(del, StringSplitOptions.None);

                            //  MessageBox.Show(name[1]+"   b");
                            if (name[1].Trim().Equals(""))
                            {
                                //do nothing

                            }
                            else
                            {
                                if (Int32.Parse(name[1]) > g)
                                    g = Int32.Parse(name[1]);


                            }

                        }
                    }
                }
                g++;
                // MessageBox.Show(g + "");
                if (g != 0)
                {
                    crm += g.ToString();
                    // MessageBox.Show(g.ToString());
                    //if (!Directory.Exists(strModPath + "\\" + str, true))
                    //{
                    //    Directory.CreateDirectory(strModPath+"\\"+str , true);
                    //}
                }
                else
                {


                }
            }
            catch (Exception e)
            {
                //  MessageBox.Show("dengu    "+e.Message);
                g++;
            }
            if (flag == false)
            {
                
                CRMName += "_CRM";
                //_ScriptName += "_CRM";  //Extending _Script with the script name so that it doesn't create conflicts with CRM with same name.
                server = CRMName;

                CRMName += g.ToString();
                

                flag = true;
            }


            if (startQuestion == "")
            {
                startQuestion = "CRMDesigner";
                startQuestionID = 1;
            }

            #region Saving Files

            CurrentQueCount = -1;
            
            for (int j = 0; j < 1; j++)
            {
                CurrentQueCount++;
                int Counter = 0;
                string strCode = "";
                

                #region Creating .XAML File
            
                string strXML = "";
                strXML = "<UserControl x:Class=\"CRM.Presentation.UserControl" +  Convert.ToString(1) + "\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" Height=\"300\" Width=\"300\"  VerticalAlignment=\"Top\">";
                strXML = strXML + char.ConvertFromUtf32(13) + "<Canvas Name=\"cnvPaint" + "\" Height=\"" + (tbcMain.Height + 5).ToString() + "\" Width=\"" + (tbcMain.Width + 5).ToString() + "\" Background=\"Transparent\">";
                strXML = strXML + char.ConvertFromUtf32(13) + "<TabControl Name=\"tbcMain" + "\" Height=\"" + tbcMain.Height + "\" Width=\"" + tbcMain.Width + "\" Canvas.Left=\"0\" Canvas.Top=\"0\">";
                foreach (TabItem t in tbcMain.Items)
                {
                    pageCount++;
                    strXML = strXML + char.ConvertFromUtf32(13) + "<TabItem Header=\"" + t.Header.ToString() +"\">";
                    strXML = strXML + char.ConvertFromUtf32(13) + "<Canvas Name=\"cnvPaint" + pageCount.ToString() + "\" Height=\"" + tbcMain.Height + "\" Width=\"" + tbcMain.Width + "\" Background=\"Transparent\">";
                    
                foreach (object o in ((Canvas)t.Content).Children)
                {
                    if (o.GetType() == typeof(ctlPOD))
                    {
                        foreach (object chl in ((ctlPOD)o).cnvPOD.Children)
                        {
                            Counter++;
                            if (chl.GetType() == typeof(TextBox))
                            {
                               strXML = strXML + char.ConvertFromUtf32(13) + "<TextBox Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((TextBox)chl).Background + "\" Foreground=\"" + ((TextBox)chl).Foreground + "\" Tag=\"" + ((TextBox)chl).Tag + "\" Text=\"" + ((TextBox)chl).Text + "\" FontFamily=\"" + ((TextBox)chl).FontFamily + "\" FontSize=\"" + ((TextBox)chl).FontSize + "\" IsEnabled=\"" + ((ctlPOD)o).IsEnabled + "\" FontWeight=\"" + ((TextBox)chl).FontWeight + "\" FontStyle=\"" + ((TextBox)chl).FontStyle + "\"/>";
                            }


                            else if (chl.GetType() == typeof(Label))
                            {
                                strXML = strXML + char.ConvertFromUtf32(13) + "<Label Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((Label)chl).Background + "\" Foreground=\"" + ((Label)chl).Foreground + "\" Tag=\"" + ((Label)chl).Tag + "\" Content=\"" + ((Label)chl).Content + "\" FontFamily=\"" + ((Label)chl).FontFamily + "\" FontSize=\"" + ((Label)chl).FontSize + "\" FontWeight=\"" + ((Label)chl).FontWeight + "\" FontStyle=\"" + ((Label)chl).FontStyle + "\"/>";
                            }

                        }
                    }
                }
                strXML = strXML + char.ConvertFromUtf32(13) + "</Canvas></TabItem>";
                }
                strXML = strXML + "</TabControl>";
                strXML = strXML + " <Button Name=\"btnSave\" Height=\"25\" Width=\"70\" Canvas.Top=\"" + int.Parse((int.Parse(tbcMain.Height.ToString()) + 5).ToString()).ToString() + "\" Canvas.Left=\"100\" Content=\"Save\" Click=\"btnSave_Click\" /> <Button Name=\"btnCancel\" Height=\"25\" Width=\"70\" Canvas.Top=\"" + int.Parse((int.Parse(tbcMain.Height.ToString()) + 5).ToString()).ToString() + "\" Canvas.Left=\"200\" Content=\"Cancel\" Click=\"btnCancel_Click\" /> </Canvas></UserControl>";

                TextWriter tw = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\" + startQuestion.ToString() + ".Xaml"));
                tw.WriteLine(strXML);
                tw.Close();

                TextReader tr101 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll","\\CRMPages\\Binded Data.txt"));
                string str101 = tr101.ReadToEnd();
                tr101.Close();


                
                strXML = "using System;" + char.ConvertFromUtf32(13) +
                         "using System.Collections.Generic;" + char.ConvertFromUtf32(13) +
                         "using System.Linq;" + char.ConvertFromUtf32(13) +
                         "using System.Text;" + char.ConvertFromUtf32(13) +
                         "using System.Windows;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Controls;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Data;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Documents;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Input;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Media;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Media.Imaging;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Navigation;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Shapes;" + char.ConvertFromUtf32(13) +
                         "using CRM.Business;" + char.ConvertFromUtf32(13) +
                         char.ConvertFromUtf32(13) +

                         "namespace CRM.Presentation" + char.ConvertFromUtf32(13) +
                         "{" + char.ConvertFromUtf32(13) + 
                          "" + char.ConvertFromUtf32(13) +
                            "public partial class UserControl" + Convert.ToString(1) + ": UserControl" + char.ConvertFromUtf32(13) +
                                "{" + char.ConvertFromUtf32(13) + "" + char.ConvertFromUtf32(13) +
                                    "public UserControl" + Convert.ToString(1) + "()" + char.ConvertFromUtf32(13) +
                                     "{" + char.ConvertFromUtf32(13) +
                                     "InitializeComponent();" + char.ConvertFromUtf32(13)  + char.ConvertFromUtf32(13) +
                                     "VMuktiAPI.VMuktiHelper.RegisterEvent(\"SetLeadIDCRM\").VMuktiEvent += new VMuktiAPI.VMuktiEvents.VMuktiEventHandler(SetLeadIDCRM_VMuktiEvent);" + char.ConvertFromUtf32(13) +
                                     "}" + "public Canvas GetCanvas()" + char.ConvertFromUtf32(13) + "{" + char.ConvertFromUtf32(13) +
                                        "return this.cnvPaint;" +
                                    "}" + str101 + char.ConvertFromUtf32(13) + char.ConvertFromUtf32(13) + strCode + char.ConvertFromUtf32(13) +
                                     "}" + char.ConvertFromUtf32(13) +
                                     "}"; 

                TextWriter tw1 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\" + startQuestion.ToString() + ".Xaml.Cs"));
                tw1.WriteLine(strXML);
                tw1.Close();

                AddRef1_2 = AddRef1_2 + char.ConvertFromUtf32(13) + "<Page Include=\"" + startQuestion.ToString() + ".xaml\">"
                + char.ConvertFromUtf32(13) + "<Generator>MSBuild:Compile</Generator>"
                + char.ConvertFromUtf32(13) + "<SubType>Designer</SubType>"
                + char.ConvertFromUtf32(13) + "</Page>";

                AddRef2_3 = AddRef2_3 + char.ConvertFromUtf32(13) + "<Compile Include=\"" + startQuestion.ToString() + ".Xaml.Cs\">"
                + char.ConvertFromUtf32(13) + "<DependentUpon>" + startQuestion.ToString() + ".Xaml</DependentUpon>"
                + char.ConvertFromUtf32(13) + "<SubType>Code</SubType>"
                + char.ConvertFromUtf32(13) + "</Compile>";


                #endregion
            }

            #region Create Project File


            TextWriter tw11 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\CRM.Presentation.csproj"));

            TextReader tr1 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRMPages\\1.txt"));
            string str1 = tr1.ReadToEnd();
            tr1.Close();

            TextReader tr2 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRMPages\\2.txt"));
            string str2 = tr2.ReadToEnd();
            tr2.Close();

            TextReader tr3 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRMPages\\3.txt"));
            string str3 = tr3.ReadToEnd();
            tr3.Close();

            tw11.WriteLine(str1 + AddRef2_3 + str2 + AddRef1_2 + str3);
            str1 = "";
            str2 = "";
            str3 = "";
            AddRef1_2 = "";
            AddRef2_3 = "";
            tw11.Close();

            TextWriter twStart = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\clsStartClass.cs"));
            TextReader trClassRead = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRMPages\\ClassRead.txt"));
            string strClassRead = trClassRead.ReadToEnd();
            trClassRead.Close();

            string strBetween = char.ConvertFromUtf32(13) + "public static string strStartQuesion = \"UserControl" + startQuestionID.ToString() + "\";" + char.ConvertFromUtf32(13) + "public static int LeadID = 1;" + char.ConvertFromUtf32(13) + "public static int CallID;" + char.ConvertFromUtf32(13) + "public static string StateName = null;" + char.ConvertFromUtf32(13) + "public static string ZipCode = null;" + char.ConvertFromUtf32(13) + "}" + char.ConvertFromUtf32(13) + "}";

            twStart.WriteLine(strClassRead + strBetween);
            twStart.Close();

            #endregion


            #region After Integration
            //if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "CRM_src\\Script.DataAccess\\ReferencedAssemblies"))
            //{
            //    Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "CRM_src\\Script.DataAccess\\ReferencedAssemblies");
            //}

            //File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"\Script_src\Script.DataAccess\ReferencedAssemblies\VMuktiAPI.dll"));
            
            #endregion

            
            //#region Building the solution File

            //TextWriter tw1111 = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");
            //tw1111.WriteLine("cd\\");
            //tw1111.WriteLine("C:");
            //tw1111.WriteLine("cd \"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\"");
            //tw1111.WriteLine("msbuild \"" + AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Script.sln\" /t:Rebuild /p:Configuration=Debug");
            //tw1111.Close();

            //System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");

            //#endregion

            //MessageBox.Show("Working Till Now");

            #region DLL File Naming

            if (cmbCRM.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a CRM Name");
            }
            else
            {
                //string crmName = ((ComboBoxItem)cmbCRM.SelectedItem).Content.ToString();
                string crmName = ((ComboBoxItem)cmbCRM.SelectedItem).Tag.ToString();

                TextReader txtReader = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\CRM.Presentation.csproj"));
                string txtString = txtReader.ReadToEnd();
                txtReader.Close();

                txtString = txtString.Replace("<AssemblyName>CRM.Presentation</AssemblyName>", "<AssemblyName>" + CRMName + ".Presentation</AssemblyName>");

                TextWriter txtWriter = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\CRM.Presentation.csproj"));
                txtWriter.WriteLine(txtString);
                txtWriter.Close();



                TextReader txtReader1 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Business\\CRM.Business.csproj"));
                string txtString1 = txtReader1.ReadToEnd();
                txtReader1.Close();

                txtString1 = txtString1.Replace("<AssemblyName>CRM.Business</AssemblyName>", "<AssemblyName>" + CRMName + ".Business</AssemblyName>");

                TextWriter txtWriter1 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Business\\CRM.Business.csproj"));
                txtWriter1.WriteLine(txtString1);
                txtWriter1.Close();



                TextReader txtReader2 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Common\\CRM.Common.csproj"));
                string txtString2 = txtReader2.ReadToEnd();
                txtReader2.Close();

                txtString2 = txtString2.Replace("<AssemblyName>CRM.Common</AssemblyName>", "<AssemblyName>" + CRMName + ".Common</AssemblyName>");

                TextWriter txtWriter2 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Common\\CRM.Common.csproj"));
                txtWriter2.WriteLine(txtString2);
                txtWriter2.Close();

                TextReader txtReader3 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.DataAccess\\CRM.DataAccess.csproj"));
                string txtString3 = txtReader3.ReadToEnd();
                txtReader3.Close();

                txtString3 = txtString3.Replace("<AssemblyName>CRM.DataAccess</AssemblyName>", "<AssemblyName>" + CRMName + ".DataAccess</AssemblyName>");

                TextWriter txtWriter3 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.DataAccess\\CRM.DataAccess.csproj"));
                txtWriter3.WriteLine(txtString3);
                txtWriter3.Close();

            #endregion

                #region Building the solution File

                string winDir = Environment.GetFolderPath(Environment.SpecialFolder.System);
                winDir = winDir.Substring(0, winDir.LastIndexOf(@"\"));

                Process buildProcess = new Process();

                if (!File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", @"\CRM_src\CRM.DataAccess\ReferencedAssemblies\VMuktiAPI.dll")))
                    File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", @"\CRM_src\CRM.DataAccess\ReferencedAssemblies\VMuktiAPI.dll"));
                
                //MessageBox.Show(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location);
                //MessageBox.Show(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"Script_src\Script.Presentation\ReferencedAssemblies\VMuktiAPI.dll"));
                if (!File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", @"CRM_src\CRM.Presentation\ReferencedAssemblies\VMuktiAPI.dll")))
                    File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", @"CRM_src\CRM.Presentation\ReferencedAssemblies\VMuktiAPI.dll"));
                

                buildProcess.OutputDataReceived += new DataReceivedEventHandler(buildProcess_OutputDataReceived);
                //TextWriter tw1111 = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");
                //tw1111.WriteLine("cd\\");
                //tw1111.WriteLine("C:");
                //tw1111.WriteLine("cd \"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\"");
                //tw1111.WriteLine("msbuild \"" + AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Script.sln\" /t:Rebuild /p:Configuration=Debug");
                //tw1111.Close();
                //System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");

                try
                {

                    if (System.IO.Directory.Exists(winDir + @"\Microsoft.NET\Framework\v3.5\"))
                    {
                        //buildProcess.StartInfo.UseShellExecute = false;
                        buildProcess.StartInfo.WorkingDirectory = winDir + @"\Microsoft.NET\Framework\v3.5\";
                        buildProcess.StartInfo.FileName = "msbuild";
                        buildProcess.StartInfo.Arguments = @" """ + Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"\CRM_src\CRM.sln"" /t:Rebuild /p:Configuration=Debug";
                        buildProcess.Start();
                        buildProcess.WaitForExit();
                    }
                    else
                    {
                        MessageBox.Show("Microsoft .Net framework is not installed at --> \" " + winDir + @"\Microsoft.NET\Framework\v3.5\" + " \"!!");
                    }
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message.ToString());
                }

                #endregion

                try
                {
                    //if (Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM"))
                    if (Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName))
                    {
                        //Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM", true);
                        Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName, true);
                    }
                    Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName);
                    Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName + "\\" + CRMName);
                    Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName + "\\" + CRMName + @"\BAL");
                    Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName + "\\" + CRMName + @"\DAL");
                    Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName + "\\" + CRMName + @"\Control");

                    //Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM");
                    //Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM");
                    //Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\BAL");
                    //Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\DAL");
                    //Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\Control");


                }
                catch (Exception exp)
                {
                    MessageBox.Show("Creating Directories" + exp.Message);
                }

                try
                {
                    copyDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Presentation\bin\Debug", Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName);
                    //copyDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Presentation\bin\Debug", Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM");
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Creating Directories" + exp.Message);
                }

                try
                {
                    //string[] filesToDelete = Directory.GetFiles(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM", "*.pdb");
                    string[] filesToDelete = Directory.GetFiles(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName, "*.pdb");
                    for (int i = 0; i < filesToDelete.Length; i++)
                    {
                        File.Delete(filesToDelete[i]);
                    }
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Deleting Files" + exp.Message);
                }

                try
                {

                    //string[] filesToMove = Directory.GetFiles(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM", "*.dll");
                    string[] filesToMove = Directory.GetFiles(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName, "*.dll");
                    for (int i = 0; i < filesToMove.Length; i++)
                    {
                        if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("Business"))
                        {
                            //File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\BAL" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                            File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName + "\\" + CRMName + "\\BAL\\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                        else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("Common"))
                        {
                            File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName + "\\" + CRMName + "\\BAL\\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                        else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("DataAccess"))
                        {
                            File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName + "\\" + CRMName + "\\DAL\\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                        else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("Presentation"))
                        {
                            File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName + "\\" + CRMName + "\\Control\\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                        else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("VMuktiAPI"))
                        {

                            File.Delete(filesToMove[i]);

                            //File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"Script\Control\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                    }

                }
                catch (Exception exp)
                {
                    MessageBox.Show("Move Files" + exp.Message);
                }

                try
                {

                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Presentation\bin", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Presentation\obj", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Business\bin", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Business\obj", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Common\bin", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Common\obj", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.DataAccess\bin", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.DataAccess\obj", true);
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Deleting Files" + exp.Message);
                }

                VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
                //ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
                try
                {
                    fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src.zip", Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src", true, "");
                    //fz.CreateZip(AppDomain.CurrentDomain.BaseDirectory + @"CRM_src.zip", AppDomain.CurrentDomain.BaseDirectory + @"CRM_src", true, "");
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Create Zip" + exp.Message);
                }

                try
                {
                    //fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + @".zip", Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM", true, "");
                    fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + server + @".zip", Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName, true, "");
                    //fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + server + @".zip", Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM", true, "");
                    //fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + server + @".zip", Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName , true, "");
                    //fz.CreateZip(AppDomain.CurrentDomain.BaseDirectory + @"CRM.zip", AppDomain.CurrentDomain.BaseDirectory + @"CRM", true, "");
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Create Zip" + exp.Message);
                }

                try
                {
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src", true);
                    //Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + @"CRM_src", true);
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Delete Directory" + exp.Message);
                }

                try
                {
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + CRMName, true);
                    //Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM", true);
                    //Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + @"CRM", true);
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Delete Directory" + exp.Message);
                }

                try
                {
                    System.Windows.Forms.DialogResult sfdRes;
                    System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
                    sfd.Filter = "Zip file(s) (*.zip)|*.zip";
                    sfd.Title = "Save the source file of script to edit manualy!!";
                    sfd.FileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\CRM_src.zip";
                    sfdRes = sfd.ShowDialog();

                    if (sfdRes == System.Windows.Forms.DialogResult.OK)
                    {
                        if (File.Exists(sfd.FileName))
                        {
                            File.Delete(sfd.FileName);
                        }
                        File.Move(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src.zip", sfd.FileName);
                    }

                    //sfd.Title = "Save the file of script to add as a module in VMukti plateform!!";
                    //sfd.FileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + crmName + @".zip";
                    //sfdRes = sfd.ShowDialog();
                    //if (sfdRes == System.Windows.Forms.DialogResult.OK)
                    //{
                    //    if (File.Exists(sfd.FileName))
                    //    {
                    //        File.Delete(sfd.FileName);
                    //    }

                    #region UploadFile

                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + @".zip");
                    System.IO.FileStream stream = new System.IO.FileStream(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + @".zip", System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    RemoteFileInfo rfi = new RemoteFileInfo();
                    rfi.FileName = fileInfo.Name;
                    rfi.Length = fileInfo.Length;
                    rfi.FileByteStream = stream;
                    rfi.FolderNameToStore = "CRMs";
                    clientHttpFileTransfer.svcHTTPFileTransferServiceUploadFileToInstallationDirectory(rfi);
                    stream.Close();
                    if (File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + server + @".zip"))
                    {
                        File.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + server + @".zip");
                    }


                    #endregion

                }
                catch (Exception exp)
                {
                    VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles()", "ctlCRMDesigner.xaml.cs");
                }

                MessageBox.Show("New Design is saved");

            #endregion
            }
        }