int DownloadAndExtractZipFile()
        {
            #region Download and Extract Zip file
            try
            {





                str = ScriptName;
                str += "_Script";

                Assembly ass = Assembly.GetEntryAssembly();
                // this maybe something like "using Vmuktiapi"
                filename = str + ".zip";

                #region Download Zip File using WCF FileTranserService

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

                    request.FileName = filename;
                    request.FolderWhereFileIsStored = "Scripts";
                    rfi = clientHttpFileTransfer.svcHTTPFileTransferServiceDownloadFile(request);

                

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

                 
                    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)
                {
                   
                    VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "DownloadAndExtractZipFile", "ctlScriptdesigner.xaml.cs");
                    return -1;
                }

                #endregion

                #region Downloading ZipFile Using WebClient  -----Commented


                #endregion

                #region Extracting

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



              
                try
                {
                    str = ScriptName;
                    str += "_Script";

                    Assembly ass2 = Assembly.GetEntryAssembly();

                    strModPath = ass2.Location.Replace("VMukti.Presentation.exe", @"ScriptModules");

                
                    
                  
                   
                }
                catch (Exception e)
                {
                    VMuktiAPI.VMuktiHelper.ExceptionHandler(e, "DownloadAndExtractZipFile", "ctlScriptdesigner.xaml.cs");
                }





            
                ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();

               // if (!Directory.Exists(strModPath + "\\" + str  ))
                {
                    fz.ExtractZip(destination + "\\" + filename, strModPath+ "\\"+str, null);
                   
                }
                
              

                #endregion
            }
            catch (Exception ex)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "DownloadAndExtractZipFile", "ctlScriptdesigner.xaml.cs");
                return -1;
            }
            #endregion
            return 0;
        }
        void FncSaveFiles()
        {
            g = 0;
            try
            {
                Assembly ass2 = Assembly.GetEntryAssembly();

                strModPath = ass2.Location.Replace("VMukti.Presentation.exe", @"ScriptModules");

                DirectoryInfo d = new DirectoryInfo(strModPath);


                //  MessageBox.Show(strModPath);
                foreach (DirectoryInfo subDir in d.GetDirectories())
                {
                    // ShowDirectory(subDir);
                    // MessageBox.Show(subDir.Name);
                    foreach (DirectoryInfo subDir2 in subDir.GetDirectories())
                    {
                        string[] del = { str };
                        if (subDir2.Name.Contains(str))
                        {
                            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)
                {
                    str += g.ToString();
                   // MessageBox.Show(g.ToString());
                    //if (!Directory.Exists(strModPath + "\\" + str, true))
                    //{
                    //    Directory.CreateDirectory(strModPath+"\\"+str , true);
                    //}
                }
                else
                {


                }
            }
            catch(Exception e)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(e, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
                g++;
            }
            if (flag == false)
            {
                _ScriptName += "_Script";  //Extending _Script with the script name so that it doesn't create conflicts with CRM with same name.
               server = ScriptName;
                
                _ScriptName += g.ToString();

                
                flag = true;
            }

           #region Create Base Solution

            try
            {
                if (Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "SS")))
                {
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS"), true);
                }
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "SS"));
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            //MessageBox.Show(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "ScriptBase"));
            //MessageBox.Show(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "SS"));

            copyDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "ScriptBase"), Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "SS"));
            if (!Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.DataAccess\ReferencedAssemblies")))
            {
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.DataAccess\ReferencedAssemblies"));
            }

            if (!Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies")))
            {
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies"));
            }
            
           #endregion



            if (startQuestion == "")
            {
                startQuestion = objQueCollection[CurrentQueCount - 1].QuestionName;
                startQuestionID = objQueCollection[CurrentQueCount - 1].ID;
            }

            #region Saving Files

            CurrentQueCount = -1;

            //MessageBox.Show(lstCanvas.Count.ToString());

            for (int j = 0; j < lstCanvas.Count; j++)
            {
                CurrentQueCount++;
                int Counter = 0;
                string strCode = "";
                pageCount++;

                #region Creating .XAML File

                string strXML = "";
                strXML = "<UserControl x:Class=\"Script.Presentation.UserControl" + objQueCollection[CurrentQueCount].ID.ToString() + "\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" Height=\"" + lstCanvas[j].Height + "\" Width=\"" + lstCanvas[j].Width + "\">";
                strXML = strXML + char.ConvertFromUtf32(13) + "<Canvas Name=\"cnvPaint" + "\" Height=\"" + lstCanvas[j].Height + "\" Width=\"" + lstCanvas[j].Width + "\" Background=\"" + lstCanvas[j].Background + "\">";

                foreach (object o in lstCanvas[j].Children)
                {
                    if (o.GetType() == typeof(ctlPOD))
                    {
                        foreach (object chl in ((ctlPOD)o).cnvPOD.Children)
                        {
                            Counter++;
                            if (chl.GetType() == typeof(Button))
                            {
                                if (((Button)chl).Tag != null)
                                {
                                   // if (((Button)chl).Tag.ToString().ToLower() != "")
                                    {
                                     //   MessageBox.Show(((Button)chl).Content.ToString() + "     1");
                                        string[] chkStr = ((Button)chl).Tag.ToString().Split('-');

                                        if (chkStr[0] == "DISPOSITION")
                                        {
                                            strCode = strCode + char.ConvertFromUtf32(13) + " void control" + Counter.ToString() + "_Click(object sender, RoutedEventArgs e)" + char.ConvertFromUtf32(13) +
                                                "{" + char.ConvertFromUtf32(13) +
                                                "clsStartClass.sCurrentDispositionID = \"" + chkStr[1] + "\";" +
                                                char.ConvertFromUtf32(13) +
                                                //"VMuktiAPI.VMuktiHelper.CallEvent(\"HangUp\", this, new VMuktiAPI.VMuktiEventArgs(\"ScriptRender\", int.Parse(clsStartClass.sCurrentChannelID) + 1));" + char.ConvertFromUtf32(13) +
                                                "((MainPage)((Canvas)((Canvas)((Canvas)this.Parent).Parent).Parent).Parent).SetDispositionCanvas();" + char.ConvertFromUtf32(13) +
                                                char.ConvertFromUtf32(13) +
                                                "}";
                                        }
                                        else
                                        {

                                            TextReader tr = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\ScriptPages\\FixedCode.txt"));
                                            string abc = tr.ReadToEnd();
                                            tr.Close();

                                            strCode = strCode + char.ConvertFromUtf32(13) + " void control" + Counter.ToString() + "_Click(object sender, RoutedEventArgs e)" + char.ConvertFromUtf32(13) +
                                                "{" + char.ConvertFromUtf32(13) +
                                                "ClsQuestionCollectionR objQueCollection = ClsQuestionCollectionR.GetAll(int.Parse(\"" + _ScriptID.ToString() + "\"));" + char.ConvertFromUtf32(13) +
                                                abc + char.ConvertFromUtf32(13) +
                                                "}";
                                        }
                                        string strContent = ((Button)chl).Content.ToString();
                                        strContent = strContent.Replace("&", "&amp;");
                                        strContent = strContent.Replace("\"", "&quot;");
                                        strContent = strContent.Replace("<", "&lt;");
                                        strContent = strContent.Replace(">", "&gt;");

                                        strXML = strXML + char.ConvertFromUtf32(13) + "<Button 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=\"" + ((Button)chl).Background + "\" Foreground=\"" + ((Button)chl).Foreground + "\" Tag=\"" + ((Button)chl).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((Button)chl).FontFamily + "\" FontSize=\"" + ((Button)chl).FontSize + "\" FontWeight=\"" + ((Button)chl).FontWeight + "\" FontStyle=\"" + ((Button)chl).FontStyle + "\" Click=\"control" + Counter.ToString() + "_Click" + "\"/>";
                                    }
                                    //else
                                    {
                                     //   MessageBox.Show(((Button)chl).Content.ToString() + "     2");
                                    }
                                }
                                else
                                {
                                   // MessageBox.Show(((Button)chl).Content.ToString() + "     3");
                                    string strContent = ((Button)chl).Content.ToString();
                                    strContent = strContent.Replace("&", "&amp;");
                                    strContent = strContent.Replace("\"", "&quot;");
                                    strContent = strContent.Replace("<", "&lt;");
                                    strContent = strContent.Replace(">", "&gt;");

                                    strXML = strXML + char.ConvertFromUtf32(13) + "<Button 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=\"" + ((Button)chl).Background + "\" Foreground=\"" + ((Button)chl).Foreground + "\" Tag=\"" + ((Button)chl).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((Button)chl).FontFamily + "\" FontSize=\"" + ((Button)chl).FontSize + "\" FontWeight=\"" + ((Button)chl).FontWeight + "\" FontStyle=\"" + ((Button)chl).FontStyle + "\"/>";
                                }
                            }

                            else if (chl.GetType() == typeof(TextBox))
                            {
                                string strContent = ((TextBox)chl).Text.ToString();
                                strContent = strContent.Replace("&", "&amp;");
                                strContent = strContent.Replace("\"", "&quot;");
                                strContent = strContent.Replace("<", "&lt;");
                                strContent = strContent.Replace(">", "&gt;");

                                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=\"" + strContent + "\" FontFamily=\"" + ((TextBox)chl).FontFamily + "\" FontSize=\"" + ((TextBox)chl).FontSize + "\" FontWeight=\"" + ((TextBox)chl).FontWeight + "\" FontStyle=\"" + ((TextBox)chl).FontStyle + "\"/>";
                            }

                            else if (chl.GetType() == typeof(TextBlock))
                            {
                                string strContent = ((TextBlock)chl).Text.ToString();
                                strContent = strContent.Replace("&", "&amp;");
                                strContent = strContent.Replace("\"", "&quot;");
                                strContent = strContent.Replace("<", "&lt;");
                                strContent = strContent.Replace(">", "&gt;");

                                strXML = strXML + char.ConvertFromUtf32(13) + "<TextBlock 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=\"" + ((TextBlock)chl).Background + "\" Foreground=\"" + ((TextBlock)chl).Foreground + "\" Tag=\"" + ((TextBlock)chl).Tag + "\" Text=\"" + strContent + "\" FontFamily=\"" + ((TextBlock)chl).FontFamily + "\" FontSize=\"" + ((TextBlock)chl).FontSize + "\" FontWeight=\"" + ((TextBlock)chl).FontWeight + "\" FontStyle=\"" + ((TextBlock)chl).FontStyle + "\" TextWrapping=\"Wrap\" />";
                            }

                            else if (chl.GetType() == typeof(Label))
                            {
                                string strContent = ((Label)chl).Content.ToString();
                                strContent = strContent.Replace("&", "&amp;");
                                strContent = strContent.Replace("\"", "&quot;");
                                strContent = strContent.Replace("<", "&lt;");
                                strContent = strContent.Replace(">", "&gt;");

                                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=\"" + strContent + "\" FontFamily=\"" + ((Label)chl).FontFamily + "\" FontSize=\"" + ((Label)chl).FontSize + "\" FontWeight=\"" + ((Label)chl).FontWeight + "\" FontStyle=\"" + ((Label)chl).FontStyle + "\"/>";
                            }

                            else if (chl.GetType() == typeof(ComboBox))
                            {
                                strXML = strXML + char.ConvertFromUtf32(13) + "<ComboBox 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=\"" + ((ComboBox)chl).Background + "\" Foreground=\"" + ((ComboBox)chl).Foreground + "\" Tag=\"" + ((ComboBox)chl).Tag + "\" FontFamily=\"" + ((ComboBox)chl).FontFamily + "\" FontSize=\"" + ((ComboBox)chl).FontSize + "\" FontWeight=\"" + ((ComboBox)chl).FontWeight + "\" FontStyle=\"" + ((ComboBox)chl).FontStyle + "\">";
                                for (int i = 0; i < ((ComboBox)chl).Items.Count; i++)
                                {
                                    Counter++;

                                    string strContent = ((ComboBoxItem)((ComboBox)chl).Items[i]).Content.ToString();
                                    strContent = strContent.Replace("&", "&amp;");
                                    strContent = strContent.Replace("\"", "&quot;");
                                    strContent = strContent.Replace("<", "&lt;");
                                    strContent = strContent.Replace(">", "&gt;");

                                    strXML = strXML + char.ConvertFromUtf32(13) + "<ComboBoxItem Name=\"control" + Counter.ToString() + "\" Background=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).Background + "\" Foreground=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).Foreground + "\" Tag=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).FontFamily + "\" FontSize=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).FontSize + "\" FontWeight=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).FontWeight + "\" FontStyle=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).FontStyle + "\"/>";
                                }
                                strXML = strXML + char.ConvertFromUtf32(13) + "</ComboBox>";
                            }

                            else if (chl.GetType() == typeof(ListBox))
                            {
                                strXML = strXML + char.ConvertFromUtf32(13) + "<ListBox 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=\"" + ((ListBox)chl).Background + "\" Foreground=\"" + ((ListBox)chl).Foreground + "\" Tag=\"" + ((ListBox)chl).Tag + "\" FontFamily=\"" + ((ListBox)chl).FontFamily + "\" FontSize=\"" + ((ListBox)chl).FontSize + "\" FontWeight=\"" + ((ListBox)chl).FontWeight + "\" FontStyle=\"" + ((ListBox)chl).FontStyle + "\">";
                                for (int i = 0; i < ((ListBox)chl).Items.Count; i++)
                                {
                                    Counter++;

                                    string strContent = ((ListBoxItem)((ListBox)chl).Items[i]).Content.ToString();
                                    strContent = strContent.Replace("&", "&amp;");
                                    strContent = strContent.Replace("\"", "&quot;");
                                    strContent = strContent.Replace("<", "&lt;");
                                    strContent = strContent.Replace(">", "&gt;");

                                    strXML = strXML + char.ConvertFromUtf32(13) + "<ListBoxItem Name=\"control" + Counter.ToString() + "\" Background=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).Background + "\" Foreground=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).Foreground + "\" Tag=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).FontFamily + "\" FontSize=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).FontSize + "\" FontWeight=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).FontWeight + "\" FontStyle=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).FontStyle + "\"/>";
                                }
                                strXML = strXML + char.ConvertFromUtf32(13) + "</ListBox>";
                            }

                            else if (chl.GetType() == typeof(RadioButton))
                            {
                                string strContent = ((RadioButton)chl).Content.ToString();
                                strContent = strContent.Replace("&", "&amp;");
                                strContent = strContent.Replace("\"", "&quot;");
                                strContent = strContent.Replace("<", "&lt;");
                                strContent = strContent.Replace(">", "&gt;");

                                strXML = strXML + char.ConvertFromUtf32(13) + "<RadioButton 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=\"" + ((RadioButton)chl).Background + "\" Foreground=\"" + ((RadioButton)chl).Foreground + "\" Tag=\"" + ((RadioButton)chl).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((RadioButton)chl).FontFamily + "\" FontSize=\"" + ((RadioButton)chl).FontSize + "\" FontWeight=\"" + ((RadioButton)chl).FontWeight + "\" FontStyle=\"" + ((RadioButton)chl).FontStyle + "\"/>";
                            }

                            else if (chl.GetType() == typeof(CheckBox))
                            {
                                string strContent = ((CheckBox)chl).Content.ToString();
                                strContent = strContent.Replace("&", "&amp;");
                                strContent = strContent.Replace("\"", "&quot;");
                                strContent = strContent.Replace("<", "&lt;");
                                strContent = strContent.Replace(">", "&gt;");

                                strXML = strXML + char.ConvertFromUtf32(13) + "<CheckBox 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=\"" + ((CheckBox)chl).Background + "\" Foreground=\"" + ((CheckBox)chl).Foreground + "\" Tag=\"" + ((CheckBox)chl).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((CheckBox)chl).FontFamily + "\" FontSize=\"" + ((CheckBox)chl).FontSize + "\" FontWeight=\"" + ((CheckBox)chl).FontWeight + "\" FontStyle=\"" + ((CheckBox)chl).FontStyle + "\"/>";
                            }

                        }
                    }
                }
                strXML = strXML + "</Canvas></UserControl>";

                //TextWriter tw = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Presentation\\" + objQueCollection[CurrentQueCount].QuestionName.ToString() + ".Xaml"));
                TextWriter tw = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Presentation\\" + objQueCollection[CurrentQueCount].ID.ToString() + ".Xaml"));
                tw.WriteLine(strXML);
                tw.Close();

                TextReader tr101 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll","\\ScriptPages\\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 Script.Business;" + char.ConvertFromUtf32(13) +
                         char.ConvertFromUtf32(13) +

                         "namespace Script.Presentation" + char.ConvertFromUtf32(13) +
                         "{" + char.ConvertFromUtf32(13) + char.ConvertFromUtf32(13) + "public partial class UserControl" + objQueCollection[CurrentQueCount].ID.ToString() + ": UserControl" + char.ConvertFromUtf32(13) +
                           "{" + char.ConvertFromUtf32(13) +
                               "public UserControl" + objQueCollection[CurrentQueCount].ID.ToString() + "()" + char.ConvertFromUtf32(13) +
                                   "{" + char.ConvertFromUtf32(13) +
                                   "InitializeComponent();" + char.ConvertFromUtf32(13) +
                    //"VMuktiAPI.VMuktiHelper.RegisterEvent(\"SetLeadIDCRM\").VMuktiEvent += new VMuktiAPI.VMuktiEvents.VMuktiEventHandler(SetLeadIDCRM_VMuktiEvent);" + char.ConvertFromUtf32(13) +
                                   "FncRefresh();" + char.ConvertFromUtf32(13) +
                                   "}" + char.ConvertFromUtf32(13) +
                                   "public Canvas GetCanvas()" + char.ConvertFromUtf32(13) +
                                   "{" + char.ConvertFromUtf32(13) +
                                        "return this.cnvPaint;" +
                                    "}" + char.ConvertFromUtf32(13) +
                                     str101 + char.ConvertFromUtf32(13) +
                                     strCode + char.ConvertFromUtf32(13) +
                                     //char.ConvertFromUtf32(13) + "}" + char.ConvertFromUtf32(13) + str101 + char.ConvertFromUtf32(13) + strCode + char.ConvertFromUtf32(13) +
                           
                            "}" + char.ConvertFromUtf32(13) +
                            "}";
                //}
                //else {

                    //strXML = strXML + char.ConvertFromUtf32(13) +
                    //   "public partial class UserControl" + objQueCollection[CurrentQueCount].ID.ToString() + ": UserControl" + char.ConvertFromUtf32(13) +
                    //       "{"  + char.ConvertFromUtf32(13) + "ModulePermissions[] _MyPermissions;" + char.ConvertFromUtf32(13) +
                    //           "public UserControl" + objQueCollection[CurrentQueCount].ID.ToString() + "()" + char.ConvertFromUtf32(13) +
                    //               "{" + char.ConvertFromUtf32(13) +
                    //               "InitializeComponent();" + char.ConvertFromUtf32(13) +
                    //               "VMuktiAPI.VMuktiHelper.RegisterEvent(\"SetLeadIDScript\").VMuktiEvent += new VMuktiAPI.VMuktiEvents.VMuktiEventHandler(Script_VMuktiEvent);" + char.ConvertFromUtf32(13) +
                    //               "}" + char.ConvertFromUtf32(13) + str101 + char.ConvertFromUtf32(13) + strCode + char.ConvertFromUtf32(13) +
                    //       "}" + char.ConvertFromUtf32(13) +
                    //        "}";
                //}
                TextWriter tw1 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Presentation\\" + objQueCollection[CurrentQueCount].ID.ToString() + ".Xaml.Cs"));
                //TextWriter tw1 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Presentation\\" + objQueCollection[CurrentQueCount].QuestionName.ToString() + ".Xaml.Cs"));
                tw1.WriteLine(strXML);
                tw1.Close();

                AddRef1_2 = AddRef1_2 + char.ConvertFromUtf32(13) + "<Page Include=\"" + objQueCollection[CurrentQueCount].ID.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=\"" + objQueCollection[CurrentQueCount].ID.ToString() + ".Xaml.Cs\">"
                + char.ConvertFromUtf32(13) + "<DependentUpon>" + objQueCollection[CurrentQueCount].ID.ToString() + ".Xaml</DependentUpon>"
                + char.ConvertFromUtf32(13) + "<SubType>Code</SubType>"
                + char.ConvertFromUtf32(13) + "</Compile>";

                #endregion
            }

            //MessageBox.Show("Now Creating Project Files");

            #region Create Project File

            TextWriter tw11 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll","\\SS\\Script.Presentation\\Script.Presentation.csproj"));

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

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

            TextReader tr3 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\ScriptPages\\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("ScriptDesigner.Presentation.dll",  "\\SS\\Script.Presentation\\clsStartClass.cs"));
            TextReader trClassRead = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll","\\ScriptPages\\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 = 0;" + char.ConvertFromUtf32(13) + "public static string sCurrentChannelID  = \"\";" + char.ConvertFromUtf32(13) + "public static string sCurrentDispositionID  = \"\";" + char.ConvertFromUtf32(13) + "public static string sCallingType  = \"\";" + 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) + "public static string sPhoneNumber = null;" + char.ConvertFromUtf32(13) + "}" + char.ConvertFromUtf32(13) + "}";

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

            #endregion


            #region DLL File Naming

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

            txtString = txtString.Replace("<AssemblyName>Script.Presentation</AssemblyName>", "<AssemblyName>" + _ScriptName + ".Presentation</AssemblyName>");

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



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

            txtString1 = txtString1.Replace("<AssemblyName>Script.Business</AssemblyName>", "<AssemblyName>" + _ScriptName + ".Business</AssemblyName>");

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



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

            txtString2 = txtString2.Replace("<AssemblyName>Script.Common</AssemblyName>", "<AssemblyName>" + _ScriptName + ".Common</AssemblyName>");

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

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

            txtString3 = txtString3.Replace("<AssemblyName>Script.DataAccess</AssemblyName>", "<AssemblyName>" + _ScriptName + ".DataAccess</AssemblyName>");

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

            #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

            #region Building the solution File

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

            Process buildProcess = new Process();

            //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");

            if (!File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"\SS\Script.DataAccess\ReferencedAssemblies\VMuktiAPI.dll")))
                 File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"\SS\Script.DataAccess\ReferencedAssemblies\VMuktiAPI.dll"));
            //MessageBox.Show(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location);
            //MessageBox.Show(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMuktiAPI.dll"));
            if (!File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMuktiAPI.dll")))
            File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMuktiAPI.dll"));
            if (!File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMukti.CtlDatePicker.Presentation.dll")))
                File.Copy(Assembly.GetExecutingAssembly().Location.Replace("ScriptDesigner.Presentation.dll", "VMukti.CtlDatePicker.Presentation.dll"), Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMukti.CtlDatePicker.Presentation.dll"));
                //File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMukti.CtlDatePicker.Presentation.dll"));
            

            if (System.IO.Directory.Exists(winDir + @"\Microsoft.NET\Framework\v3.5\"))
            {
                buildProcess.StartInfo.WorkingDirectory = winDir + @"\Microsoft.NET\Framework\v3.5\";
                buildProcess.StartInfo.FileName = "msbuild";
                buildProcess.StartInfo.Arguments = @" """ + Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll","") + @"\SS\Script.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\" + " \"!!");
            }


            #endregion

            try
            {
                if (Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName))
                {
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName, true);
                }
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName);
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName);
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\BAL");
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\DAL");
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\Control");
                //Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"Script\Common");
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                copyDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Presentation\bin\Debug", Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName);
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncsaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                string[] filesToDelete = Directory.GetFiles(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName, "*.pdb");
                for (int i = 0; i < filesToDelete.Length; i++)
                {
                    File.Delete(filesToDelete[i]);
                }
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                string[] filesToMove = Directory.GetFiles(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName, "*.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("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName +  "\\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("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\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("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\DAL\\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                    }
                    else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("Presentation"))
                    {
                        if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("CtlDatePicker"))
                        {
                            File.Delete(filesToMove[i]);
                        }
                        else
                        {
                        File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\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)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Presentation\bin", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Presentation\obj", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Business\bin", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Business\obj", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Common\bin", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Common\obj", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.DataAccess\bin", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.DataAccess\obj", true);
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            try
            {
                //MessageBox.Show("File Name - " + Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS.zip");
                //MessageBox.Show("Source - " + Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS");
                fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS.zip", Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS", true, "");
                
                
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + server + @".zip", Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName, true, "");
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS", true);
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName, true);
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }
            
            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) + @"\SS.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("ScriptDesigner.Presentation.dll", "") + @"SS.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) + @"\ScriptRender.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("ScriptDesigner.Presentation.dll", "") + @"ScriptRender.zip", sfd.FileName);
                //}

                
                
                #region UploadFile
                try
                {
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + server + @".zip");
                    System.IO.FileStream stream = new System.IO.FileStream(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + server + @".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 = "Scripts";
                clientHttpFileTransfer.svcHTTPFileTransferServiceUploadFileToInstallationDirectory(rfi);
                stream.Close();
                    if (File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + server + @".zip"))
                    {
                        File.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + server + @".zip");
                    }
                }
                catch (Exception er)
                {
                    MessageBox.Show(er.Message);
                }
                #endregion
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }
            


            #endregion
        }