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
            }
        }
        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;
        }
Esempio n. 3
0
        //dispatture function which is started from thread which is started from loadmodule function.
        public void dispMethLoadModule(object objModuleParams)
        {
            try
            {
                object[] obj = (object[])objModuleParams;

                #region Collaborative

                if (obj.Length == 3) // it is true than objModuleParams is having http uri, else it is of net.p2p
                {
                    VMukti.Business.VMuktiGrid.ClsModule objModule = ClsModule.GetPodModule(this.ModuleID);

                    #region Downloading ZipFile

                    Uri zipFileURL = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + objModule.ZipFile);
                    if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
                    {
                        Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
                    }
                    string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");
                    if (!File.Exists(destination + "\\" + objModule.ZipFile))
                    {
                        WebClient wc = new WebClient();
                        wc.DownloadFile(zipFileURL, destination + "\\" + objModule.ZipFile);
                    }

                    #endregion

                    //if we add new identifiers for POD in a zip file u can find it over here and have to change accordingly
                    #region Extracting

                    string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
                    VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
                    if (!Directory.Exists(strModPath + "\\" + objModule.ZipFile.Split('.')[0]))
                    {
                        fz.ExtractZip(destination + "\\" + objModule.ZipFile, strModPath, null);
                    }

                    string strXmlPath = strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\Control\\configuration.xml";
                    if (File.Exists(strXmlPath))
                    {
                        #region Parsing XML

                        XmlParser xp = new XmlParser();
                        xp.Parse(strXmlPath);

                        #endregion

                        try
                        {
                            if (!string.IsNullOrEmpty(xp.xMain.SWFFileName))
                            {
                                if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.SWFFileName))
                                {
                                    FileInfo fi = new FileInfo(strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\Control\\" + xp.xMain.SWFFileName);
                                    fi.CopyTo(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.SWFFileName);
                                }
                            }

                            if (!string.IsNullOrEmpty(xp.xMain.TextFileName))
                            {
                                if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.TextFileName))
                                {
                                    FileInfo fi = new FileInfo(strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\Control\\" + xp.xMain.TextFileName);
                                    fi.CopyTo(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.TextFileName);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "dispMethLoadModule--copying swf n txt files", "Domains\\SuperNodeServiceDomain.cs");
                        }

                    }


                    #endregion

                    #region Loading ReferencedAssemblies

                    //DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath);
                    DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + objModule.ZipFile.Split('.')[0]);
                    ShowDirectory(dirinfomodule);


                    #region extracting imagefile
                    string imagefilename = strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\" + "Control\\" + objModule.ZipFile.Split('.')[0] + ".png";
                    if (File.Exists(imagefilename))
                    {
                        BitmapImage objimage = new BitmapImage();
                        objimage.BeginInit();
                        objimage.UriSource = new Uri(imagefilename);
                        objimage.EndInit();
                        imgPODIcon.BeginInit();
                        imgPODIcon.Source = objimage;
                        imgPODIcon.EndInit();
                    }
                    #endregion

                    //following code will load bal and dal from reflaction in RAM
                    for (int j = 0; j < al.Count; j++)
                    {
                        string[] arraysplit = al[j].ToString().Split('\\');
                        if (arraysplit[arraysplit.Length - 1].ToString() == objModule.AssemblyFile)
                        {
                            a = Assembly.LoadFrom(al[j].ToString());
                            AssemblyName[] an = a.GetReferencedAssemblies();

                            for (int alcount = 0; alcount < al.Count; alcount++)
                            {
                                string strsplit = al[alcount].ToString();
                                string[] strold = strsplit.Split('\\');
                                string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

                                for (int asscount = 0; asscount < an.Length; asscount++)
                                {
                                    if (an[asscount].Name == strnew)
                                    {
                                        Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
                                        AssemblyName[] anbal = assbal.GetReferencedAssemblies();
                                        for (int andal = 0; andal < al.Count; andal++)
                                        {
                                            string strsplitdal = al[andal].ToString();
                                            string[] strolddal = strsplitdal.Split('\\');
                                            string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

                                            for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
                                            {
                                                if (anbal[asscountdal].Name == strnewdal)
                                                {
                                                    Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            Type[] t1 = a.GetTypes();

                            #region CreatingObject

                            for (int k = 0; k < t1.Length; k++)
                            {
                                if (t1[k].Name == objModule.ClassName)
                                {
                                    try
                                    {
                                        ConstructorInfo[] ci = t1[k].GetConstructors();

                                        for (int constcount = 0; constcount < ci.Length; constcount++)
                                        {
                                            ParameterInfo[] pi = ci[constcount].GetParameters();
                                            if (pi.Length == 4)
                                            {
                                                //if module is collaborative, it will be haveing more than one (nearly 4) parameters and so it will come here and will create object with required parameter.
                                                if (pi[0].ParameterType.Name == "PeerType")
                                                {
                                                    object[] objArg = new object[4];
                                                    objArg[0] = VMuktiInfo.CurrentPeer.CurrPeerType;
                                                    objArg[1] = obj[0].ToString();
                                                    objArg[2] = obj[1];
                                                    if (_strFromWhere == "fromOtherPeer")
                                                    {
                                                        objArg[3] = "Guest";
                                                    }
                                                    else if (_strFromWhere == "fromLeftPane" || _strFromWhere == "fromDatabase")
                                                    {
                                                        objArg[3] = "Host";
                                                    }

                                                    //Object of module will be created here by reflaction
                                                    object obj1 = Activator.CreateInstance(t1[k], BindingFlags.CreateInstance, null, objArg, new System.Globalization.CultureInfo("en-US"));
                                                    grdBody.Tag = t1[k].ToString();


                                                    grdBody.Children.Remove(animImage);
                                                    grdBody.Children.Add((UIElement)obj1);

                                                    if (!this.IsTwoPanel)
                                                    {
                                                        #region changes for pod resize
                                                        ItemsControl objItem = (ItemsControl)(this.Parent);
                                                        if (objItem.Name != "TopPanelContainer" && objItem.Name != "BottomPanelContainer")
                                                        {

                                                            ColumnDefinitionCollection ColCollection = ((Grid)(objItem.Parent)).ColumnDefinitions;
                                                            int colNo = Convert.ToInt32(objItem.Tag) - 1;
                                                            GridLength WidthToBeSet = new GridLength((((UserControl)obj1).Width) / 100, GridUnitType.Star);
                                                            double previousActualWidth = -1;
                                                            if (ColCollection[colNo].Width.Value > 100)
                                                            {
                                                                previousActualWidth = (ColCollection[colNo].Width.Value / 100);
                                                            }
                                                            else
                                                            {
                                                                previousActualWidth = ColCollection[colNo].Width.Value;
                                                                string strPAW = previousActualWidth.ToString();

                                                                int intPAW = Convert.ToInt32(previousActualWidth);
                                                                switch (intPAW)
                                                                {
                                                                    case 1:
                                                                        previousActualWidth = 4;
                                                                        break;
                                                                    case 2:
                                                                        previousActualWidth = 4;
                                                                        break;
                                                                    case 3:
                                                                        previousActualWidth = 4;
                                                                        break;
                                                                    case 4:
                                                                        previousActualWidth = 4;
                                                                        break;
                                                                    case 5:
                                                                        previousActualWidth = 5.5;
                                                                        break;
                                                                    case 6:
                                                                        previousActualWidth = 6.5;
                                                                        break;
                                                                    default:
                                                                        previousActualWidth = 7;
                                                                        break;
                                                                }


                                                            }

                                                            if (previousActualWidth < WidthToBeSet.Value)
                                                            {
                                                                ColCollection[1].Width = new GridLength(0, GridUnitType.Star);
                                                                ColCollection[2].Width = new GridLength(0, GridUnitType.Star);
                                                                ColCollection[0].Width = new GridLength(0, GridUnitType.Star);
                                                                switch (colNo)
                                                                {
                                                                    case 0:
                                                                        ColCollection[1].Width = new GridLength(1, GridUnitType.Star);
                                                                        ColCollection[2].Width = new GridLength(1, GridUnitType.Star);
                                                                        break;
                                                                    case 1:
                                                                        ColCollection[0].Width = new GridLength(1, GridUnitType.Star);
                                                                        ColCollection[2].Width = new GridLength(1, GridUnitType.Star);
                                                                        break;
                                                                    case 2:
                                                                        ColCollection[0].Width = new GridLength(1, GridUnitType.Star);
                                                                        ColCollection[1].Width = new GridLength(1, GridUnitType.Star);
                                                                        break;
                                                                }
                                                                int objint = Convert.ToInt32(WidthToBeSet.Value);
                                                                switch (objint)
                                                                {
                                                                    case 1:
                                                                        ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                                        break;
                                                                    case 2:
                                                                        ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                                        break;
                                                                    case 3:
                                                                        ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                                        break;
                                                                    case 4:
                                                                        ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                                        break;
                                                                    case 5:
                                                                        ColCollection[colNo].Width = new GridLength(2, GridUnitType.Star);
                                                                        break;
                                                                    case 6:
                                                                        ColCollection[colNo].Width = new GridLength(2.5, GridUnitType.Star);
                                                                        break;
                                                                    default:
                                                                        ColCollection[colNo].Width = new GridLength(2.5, GridUnitType.Star);
                                                                        break;
                                                                }

                                                            }

                                                        }
                                                        #endregion
                                                    }

                                                    break;
                                                }
                                            }
                                            else
                                            {
                                                object obj1 = Activator.CreateInstance(t1[k]); ((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
                                                ((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

                                                grdBody.Tag = t1[k].ToString();


                                                grdBody.Children.Remove(animImage);
                                                grdBody.Children.Add((UIElement)obj1);
                                                if (!this.IsTwoPanel)
                                                {
                                                    #region changes for pod resize
                                                    ItemsControl objItem = (ItemsControl)(this.Parent);
                                                    if (objItem.Name != "TopPanelContainer" && objItem.Name != "BottomPanelContainer")
                                                    {

                                                        ColumnDefinitionCollection ColCollection = ((Grid)(objItem.Parent)).ColumnDefinitions;
                                                        int colNo = Convert.ToInt32(objItem.Tag) - 1;
                                                        GridLength WidthToBeSet = new GridLength((((UserControl)obj1).Width) / 100, GridUnitType.Star);
                                                        double previousActualWidth = -1;
                                                        if (ColCollection[colNo].Width.Value > 100)
                                                        {
                                                            previousActualWidth = (ColCollection[colNo].Width.Value / 100);
                                                        }
                                                        else
                                                        {
                                                            previousActualWidth = ColCollection[colNo].Width.Value;
                                                            string strPAW = previousActualWidth.ToString();

                                                            int intPAW = Convert.ToInt32(previousActualWidth);
                                                            switch (intPAW)
                                                            {
                                                                case 1:
                                                                    previousActualWidth = 4;
                                                                    break;
                                                                case 2:
                                                                    previousActualWidth = 4;
                                                                    break;
                                                                case 3:
                                                                    previousActualWidth = 4;
                                                                    break;
                                                                case 4:
                                                                    previousActualWidth = 4;
                                                                    break;
                                                                case 5:
                                                                    previousActualWidth = 5.5;
                                                                    break;
                                                                case 6:
                                                                    previousActualWidth = 6.5;
                                                                    break;
                                                                default:
                                                                    previousActualWidth = 7;
                                                                    break;
                                                            }


                                                        }

                                                        if (previousActualWidth < WidthToBeSet.Value)
                                                        {
                                                            ColCollection[1].Width = new GridLength(0, GridUnitType.Star);
                                                            ColCollection[2].Width = new GridLength(0, GridUnitType.Star);
                                                            ColCollection[0].Width = new GridLength(0, GridUnitType.Star);
                                                            switch (colNo)
                                                            {
                                                                case 0:
                                                                    ColCollection[1].Width = new GridLength(1, GridUnitType.Star);
                                                                    ColCollection[2].Width = new GridLength(1, GridUnitType.Star);
                                                                    break;
                                                                case 1:
                                                                    ColCollection[0].Width = new GridLength(1, GridUnitType.Star);
                                                                    ColCollection[2].Width = new GridLength(1, GridUnitType.Star);
                                                                    break;
                                                                case 2:
                                                                    ColCollection[0].Width = new GridLength(1, GridUnitType.Star);
                                                                    ColCollection[1].Width = new GridLength(1, GridUnitType.Star);
                                                                    break;
                                                            }
                                                            int objint = Convert.ToInt32(WidthToBeSet.Value);
                                                            switch (objint)
                                                            {
                                                                case 1:
                                                                    ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                                    break;
                                                                case 2:
                                                                    ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                                    break;
                                                                case 3:
                                                                    ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                                    break;
                                                                case 4:
                                                                    ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                                    break;
                                                                case 5:
                                                                    ColCollection[colNo].Width = new GridLength(2, GridUnitType.Star);
                                                                    break;
                                                                case 6:
                                                                    ColCollection[colNo].Width = new GridLength(2.5, GridUnitType.Star);
                                                                    break;
                                                                default:
                                                                    ColCollection[colNo].Width = new GridLength(2.5, GridUnitType.Star);
                                                                    break;
                                                            }

                                                        }

                                                    }
                                                    #endregion
                                                }
                                                break;
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "CreatingObject--5", "Controls\\VMuktiGrid\\Grid\\ctlPOD.xaml.cs");
                                    }
                                    break;
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion
                }
                #endregion

                #region NonCollaborative
                //it will create an object of p2p node
                else
                {
                    VMukti.Business.VMuktiGrid.ClsModule objModule = ClsModule.GetPodModule(this.ModuleID);

                    #region Downloading ZipFile

                    Uri zipFileURL = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + objModule.ZipFile);
                    if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
                    {
                        Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
                    }
                    string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");
                    if (!File.Exists(destination + "\\" + objModule.ZipFile))
                    {
                        WebClient wc = new WebClient();
                        wc.DownloadFile(zipFileURL, destination + "\\" + objModule.ZipFile);
                    }

                    #endregion

                    #region Extracting

                    string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
                    VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();

                    if (!Directory.Exists(strModPath + "\\" + objModule.ZipFile.Split('.')[0]))
                    {
                        fz.ExtractZip(destination + "\\" + objModule.ZipFile, strModPath, null);
                    }

                    string strXmlPath = strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\Control\\configuration.xml";
                    if (File.Exists(strXmlPath))
                    {
                        #region Parsing XML

                        XmlParser xp = new XmlParser();
                        xp.Parse(strXmlPath);

                        #endregion

                        try
                        {
                            if (!string.IsNullOrEmpty(xp.xMain.SWFFileName))
                            {
                                if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.SWFFileName))
                                {
                                    FileInfo fi = new FileInfo(strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\Control\\" + xp.xMain.SWFFileName);
                                    fi.CopyTo(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.SWFFileName);
                                }
                            }

                            if (!string.IsNullOrEmpty(xp.xMain.TextFileName))
                            {
                                if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.TextFileName))
                                {
                                    FileInfo fi = new FileInfo(strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\Control\\" + xp.xMain.TextFileName);
                                    fi.CopyTo(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.TextFileName);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "dispMethLoadModule-NonCol--copying swf n txt files", "Domains\\SuperNodeServiceDomain.cs");
                        }

                    }


                    #endregion

                    #region Loading ReferencedAssemblies

                    DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + objModule.ZipFile.Split('.')[0]);
                    ShowDirectory(dirinfomodule);


                    #region extracting imagefile
                    string imagefilename = strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\" + "Control\\" + objModule.ZipFile.Split('.')[0] + ".png";
                    if (File.Exists(imagefilename))
                    {
                        BitmapImage objimage = new BitmapImage();
                        objimage.BeginInit();
                        objimage.UriSource = new Uri(imagefilename);
                        objimage.EndInit();
                        imgPODIcon.BeginInit();
                        imgPODIcon.Source = objimage;
                        imgPODIcon.EndInit();
                    }
                    #endregion


                    for (int j = 0; j < al.Count; j++)
                    {
                        string[] arraysplit = al[j].ToString().Split('\\');
                        if (arraysplit[arraysplit.Length - 1].ToString() == objModule.AssemblyFile)
                        {
                            a = Assembly.LoadFrom(al[j].ToString());
                            AssemblyName[] an = a.GetReferencedAssemblies();

                            for (int alcount = 0; alcount < al.Count; alcount++)
                            {
                                string strsplit = al[alcount].ToString();
                                string[] strold = strsplit.Split('\\');
                                string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

                                for (int asscount = 0; asscount < an.Length; asscount++)
                                {
                                    if (an[asscount].Name == strnew)
                                    {
                                        Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
                                        AssemblyName[] anbal = assbal.GetReferencedAssemblies();
                                        for (int andal = 0; andal < al.Count; andal++)
                                        {
                                            string strsplitdal = al[andal].ToString();
                                            string[] strolddal = strsplitdal.Split('\\');
                                            string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

                                            for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
                                            {
                                                if (anbal[asscountdal].Name == strnewdal)
                                                {
                                                    Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            Type[] t1 = a.GetTypes();

                            #region CreatingObject

                            for (int k = 0; k < t1.Length; k++)
                            {
                                if (t1[k].Name == objModule.ClassName)
                                {
                                    try
                                    {
                                        object[] objArg = new object[1];
                                        objArg[0] = obj[0];

                                        object obj1 = Activator.CreateInstance(t1[k], objArg);
                                        ((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
                                        ((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

                                        grdBody.Tag = t1[k].ToString();
                                        grdBody.Children.Remove(animImage);
                                        grdBody.Children.Add((UIElement)obj1);

                                        if (!this.IsTwoPanel)
                                        {
                                            #region changes for pod resize
                                            ItemsControl objItem = (ItemsControl)(this.Parent);
                                            ColumnDefinitionCollection ColCollection = ((Grid)(objItem.Parent)).ColumnDefinitions;
                                            int colNo = Convert.ToInt32(objItem.Tag) - 1;
                                            GridLength WidthToBeSet = new GridLength((((UserControl)obj1).Width) / 100, GridUnitType.Star);
                                            double previousActualWidth = -1;
                                            if (ColCollection[colNo].Width.Value > 100)
                                            {
                                                previousActualWidth = (ColCollection[colNo].Width.Value / 100);
                                            }
                                            else
                                            {
                                                previousActualWidth = ColCollection[colNo].Width.Value;
                                                string strPAW = previousActualWidth.ToString();

                                                int intPAW = Convert.ToInt32(previousActualWidth);
                                                switch (intPAW)
                                                {
                                                    case 1:
                                                        previousActualWidth = 4;
                                                        break;
                                                    case 2:
                                                        previousActualWidth = 4;
                                                        break;
                                                    case 3:
                                                        previousActualWidth = 4;
                                                        break;
                                                    case 4:
                                                        previousActualWidth = 4;
                                                        break;
                                                    case 5:
                                                        previousActualWidth = 5.5;
                                                        break;
                                                    case 6:
                                                        previousActualWidth = 6.5;
                                                        break;
                                                    default:
                                                        previousActualWidth = 7;
                                                        break;
                                                }


                                            }

                                            if (previousActualWidth < WidthToBeSet.Value)
                                            {
                                                ColCollection[1].Width = new GridLength(0, GridUnitType.Star);
                                                ColCollection[2].Width = new GridLength(0, GridUnitType.Star);
                                                ColCollection[0].Width = new GridLength(0, GridUnitType.Star);
                                                switch (colNo)
                                                {
                                                    case 0:
                                                        ColCollection[1].Width = new GridLength(1, GridUnitType.Star);
                                                        ColCollection[2].Width = new GridLength(1, GridUnitType.Star);
                                                        break;
                                                    case 1:
                                                        ColCollection[0].Width = new GridLength(1, GridUnitType.Star);
                                                        ColCollection[2].Width = new GridLength(1, GridUnitType.Star);
                                                        break;
                                                    case 2:
                                                        ColCollection[0].Width = new GridLength(1, GridUnitType.Star);
                                                        ColCollection[1].Width = new GridLength(1, GridUnitType.Star);
                                                        break;
                                                }
                                                int objint = Convert.ToInt32(WidthToBeSet.Value);
                                                switch (objint)
                                                {
                                                    case 1:
                                                        ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                        break;
                                                    case 2:
                                                        ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                        break;
                                                    case 3:
                                                        ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                        break;
                                                    case 4:
                                                        ColCollection[colNo].Width = new GridLength(1, GridUnitType.Star);
                                                        break;
                                                    case 5:
                                                        ColCollection[colNo].Width = new GridLength(2, GridUnitType.Star);
                                                        break;
                                                    case 6:
                                                        ColCollection[colNo].Width = new GridLength(2.5, GridUnitType.Star);
                                                        break;
                                                    default:
                                                        ColCollection[colNo].Width = new GridLength(2.5, GridUnitType.Star);
                                                        break;
                                                }

                                            }
                                            #endregion
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "CreatingObject--7", "Controls\\VMuktiGrid\\Grid\\ctlPOD.xaml.cs");
                                        grdBody.Children.Add(new UIElement());
                                    }

                                }
                            }
                            #endregion
                        }
                    }
                    #endregion

                }
                #endregion

                al.Clear();
                //this part of the code is for infoming back the user who droped this user that module is loaded so that u can now show the user in ur buddy list.
                //if (_objPageInfo != null)
                //{

                //    clsBuddyRetPageInfo objBuddyRetPageInfo = new clsBuddyRetPageInfo();
                //    List<clsBuddyRetTabInfo> lstBuddyRetTabInfo = new List<clsBuddyRetTabInfo>();
                //    List<clsBuddyRetPodInfo> lstBuddyRetPodInfo = new List<clsBuddyRetPodInfo>();

                //    objBuddyRetPageInfo.intOwnerID = _objPageInfo.intOwnerID;
                //    objBuddyRetPageInfo.intOwnerPageIndex = _objPageInfo.intOwnerPageIndex;
                //    objBuddyRetPageInfo.intPageID = _objPageInfo.intPageID;
                //    objBuddyRetPageInfo.strDropType = _objPageInfo.strDropType;
                //    int ownerindex = ((VMuktiGrid.ctlTab.TabItem)((ctlGrid)((Grid)((ItemsControl)this.Parent).Parent).Parent).Parent).OwnerTabIndex;
                //    for (int i = 0; i < _objPageInfo.objaTabs.Length; i++)
                //    {
                //        if (ownerindex == _objPageInfo.objaTabs[i].intOwnerTabIndex)
                //        {
                //            int lstBuddyRetTabInfoCount = lstBuddyRetTabInfo.Count - 1;
                //            lstBuddyRetTabInfo.Add(new clsBuddyRetTabInfo());
                //            lstBuddyRetTabInfo[lstBuddyRetTabInfoCount].intOwnerTabIndex = _objPageInfo.objaTabs[i].intOwnerTabIndex;
                //            lstBuddyRetTabInfo[lstBuddyRetTabInfoCount].intTabID = _objPageInfo.objaTabs[i].intTabID;

                //            for (int j = 0; j < _objPageInfo.objaTabs[i].objaPods.Length; j++)
                //            {
                //                if (this.OwnerPodIndex == _objPageInfo.objaTabs[i].objaPods[j].intOwnerPodIndex)
                //                {
                //                    lstBuddyRetPodInfo.Add(new clsBuddyRetPodInfo());
                //                    lstBuddyRetPodInfo[lstBuddyRetTabInfoCount].intColumnNumber = _objPageInfo.objaTabs[i].objaPods[j].intColumnNumber;
                //                    lstBuddyRetPodInfo[lstBuddyRetTabInfoCount].intModuleId = _objPageInfo.objaTabs[i].objaPods[j].intModuleId;
                //                    lstBuddyRetPodInfo[lstBuddyRetTabInfoCount].intOwnerPodIndex = _objPageInfo.objaTabs[i].objaPods[j].intOwnerPodIndex;
                //                    lstBuddyRetPodInfo[lstBuddyRetTabInfoCount].straPodBuddies = _objPageInfo.objaTabs[i].objaPods[j].straPodBuddies;
                //                }
                //            }

                //            lstBuddyRetTabInfo[lstBuddyRetTabInfoCount].objaPods = lstBuddyRetPodInfo.ToArray();
                //        }
                //    }

                //    objBuddyRetPageInfo.objaTabs = lstBuddyRetTabInfo.ToArray();
                //    objBuddyRetPageInfo.strFrom = _objPageInfo.strTo;
                //    objBuddyRetPageInfo.strTo = _objPageInfo.strFrom;
                //    objBuddyRetPageInfo.strMsg = "MODULE_LOADED";


                //}
            }
            catch (Exception ex)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "dispMethoadModule()", "Controls\\VMuktiGrid\\Grid\\ctlPOD.xaml.cs");
            }
        }
Esempio n. 4
0
        void bwDownloadZips_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                ClsModuleCollection cmc = (ClsModuleCollection)e.Argument;
                Assembly ass = Assembly.GetAssembly(typeof(pgHome));

                for (int i = 0; i < cmc.Count; i++)
                {
                    #region Downloading ZipFile

                    string filename = cmc[i].ZipFile;
                    Uri u = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + filename);
                    if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
                    {
                        Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
                    }
                    string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");

                    try
                    {
                        if (!File.Exists(destination + "\\" + filename))
                        {
                            WebClient wc = new WebClient();
                            wc.DownloadFile(u, destination + "\\" + filename);
                        }

                    #endregion

                        #region Extracting

                        string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
                        VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
                        if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
                        {
                            fz.ExtractZip(destination + "\\" + filename, strModPath, null);
                        }

                        string strXmlPath = strModPath + "\\" + filename.Split('.')[0] + "\\Control\\configuration.xml";
                        if (File.Exists(strXmlPath))
                        {
                            #region Parsing XML

                            XmlParser xp = new XmlParser();
                            xp.Parse(strXmlPath);

                            #endregion

                            try
                            {
                                if (!string.IsNullOrEmpty(xp.xMain.SWFFileName))
                                {
                                    if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.SWFFileName))
                                    {
                                        FileInfo fi = new FileInfo(strModPath + "\\" + filename.Split('.')[0] + "\\Control\\" + xp.xMain.SWFFileName);
                                        fi.CopyTo(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.SWFFileName);
                                    }
                                }

                                if (!string.IsNullOrEmpty(xp.xMain.TextFileName))
                                {
                                    if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.TextFileName))
                                    {
                                        FileInfo fi = new FileInfo(strModPath + "\\" + filename.Split('.')[0] + "\\Control\\" + xp.xMain.TextFileName);
                                        fi.CopyTo(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.TextFileName);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "bwDownloadZips_DoWork--copying swf n txt files", "Domains\\SuperNodeServiceDomain.cs");
                            }

                        }

                    }
                    catch (Exception exp)
                    {
                        VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "bwDownloadZips_DoWork--File " + filename + " Not Found", "pgHome.xaml.cs");
                    }
                        #endregion



                }
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "beDownloadZips_DoWork()", "pgHome.xaml.cs");
            }
        }
Esempio n. 5
0
        public void LoadPod4MultipleBuddies(object objModuleParams)
        {
            try
            {
                object[] obj = (object[])objModuleParams;

                #region Collaborative

                if (obj.Length == 3)
                {
                    VMukti.Business.VMuktiGrid.ClsModule objModule = ClsModule.GetPodModule(this.ModuleID);

                    #region Downloading ZipFile

                    Uri zipFileURL = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + objModule.ZipFile);
                    if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
                    {
                        Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
                    }
                    string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");
                    if (!File.Exists(destination + "\\" + objModule.ZipFile))
                    {
                        WebClient wc = new WebClient();
                        wc.DownloadFile(zipFileURL, destination + "\\" + objModule.ZipFile);
                    }

                    #endregion

                    #region Extracting

                    string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
                    VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
                    if (!Directory.Exists(strModPath + "\\" + objModule.ZipFile.Split('.')[0]))
                    {
                        fz.ExtractZip(destination + "\\" + objModule.ZipFile, strModPath, null);
                    }

                    string strXmlPath = strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\Control\\configuration.xml";
                    if (File.Exists(strXmlPath))
                    {
                        #region Parsing XML

                        XmlParser xp = new XmlParser();
                        xp.Parse(strXmlPath);

                        #endregion

                        try
                        {
                            if (!string.IsNullOrEmpty(xp.xMain.SWFFileName))
                            {
                                if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.SWFFileName))
                                {
                                    FileInfo fi = new FileInfo(strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\Control\\" + xp.xMain.SWFFileName);
                                    fi.CopyTo(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.SWFFileName);
                                }
                            }

                            if (!string.IsNullOrEmpty(xp.xMain.TextFileName))
                            {
                                if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.TextFileName))
                                {
                                    FileInfo fi = new FileInfo(strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\Control\\" + xp.xMain.TextFileName);
                                    fi.CopyTo(AppDomain.CurrentDomain.BaseDirectory + xp.xMain.TextFileName);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "LoadPod4MultipleBuddies--copying swf n txt files", "Domains\\SuperNodeServiceDomain.cs");
                        }

                    }


                    #endregion

                    #region Loading ReferencedAssemblies

                    DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + objModule.ZipFile.Split('.')[0]);
                    ShowDirectory(dirinfomodule);


                    #region extracting imagefile
                    string imagefilename = strModPath + "\\" + objModule.ZipFile.Split('.')[0] + "\\" + "Control\\" + objModule.ZipFile.Split('.')[0] + ".png";
                    if (File.Exists(imagefilename))
                    {
                        BitmapImage objimage = new BitmapImage();
                        objimage.BeginInit();
                        objimage.UriSource = new Uri(imagefilename);
                        objimage.EndInit();
                        imgPODIcon.BeginInit();
                        imgPODIcon.Source = objimage;
                        imgPODIcon.EndInit();
                    }
                    #endregion

                    for (int j = 0; j < al.Count; j++)
                    {
                        string[] arraysplit = al[j].ToString().Split('\\');
                        if (arraysplit[arraysplit.Length - 1].ToString() == objModule.AssemblyFile)
                        {
                            a = Assembly.LoadFrom(al[j].ToString());
                            AssemblyName[] an = a.GetReferencedAssemblies();

                            for (int alcount = 0; alcount < al.Count; alcount++)
                            {
                                string strsplit = al[alcount].ToString();
                                string[] strold = strsplit.Split('\\');
                                string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

                                for (int asscount = 0; asscount < an.Length; asscount++)
                                {
                                    if (an[asscount].Name == strnew)
                                    {
                                        Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
                                        AssemblyName[] anbal = assbal.GetReferencedAssemblies();
                                        for (int andal = 0; andal < al.Count; andal++)
                                        {
                                            string strsplitdal = al[andal].ToString();
                                            string[] strolddal = strsplitdal.Split('\\');
                                            string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

                                            for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
                                            {
                                                if (anbal[asscountdal].Name == strnewdal)
                                                {
                                                    Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            Type[] t1 = a.GetTypes();

                            #region CreatingObject

                            for (int k = 0; k < t1.Length; k++)
                            {
                                if (t1[k].Name == objModule.ClassName)
                                {
                                    try
                                    {
                                        ConstructorInfo[] ci = t1[k].GetConstructors();

                                        for (int constcount = 0; constcount < ci.Length; constcount++)
                                        {
                                            ParameterInfo[] pi = ci[constcount].GetParameters();
                                            if (pi.Length == 4)
                                            {
                                                if (pi[0].ParameterType.Name == "PeerType")
                                                {
                                                    object[] objArg = new object[4];
                                                    objArg[0] = VMuktiInfo.CurrentPeer.CurrPeerType;
                                                    objArg[1] = obj[0].ToString();
                                                    objArg[2] = obj[1];
                                                    if (_strFromWhere == "fromOtherPeer")
                                                    {
                                                        objArg[3] = "Guest";
                                                    }
                                                    else if (_strFromWhere == "fromLeftPane" || _strFromWhere == "fromDatabase")
                                                    {
                                                        objArg[3] = "Host";
                                                    }

                                                    object obj1 = Activator.CreateInstance(t1[k], BindingFlags.CreateInstance, null, objArg, new System.Globalization.CultureInfo("en-US"));
                                                    grdBody.Tag = t1[k].ToString();

                                                    grdBody.Children.Remove(animImage);
                                                    grdBody.Children.Add((UIElement)obj1);
                                                    break;
                                                }
                                            }
                                            else
                                            {
                                                object obj1 = Activator.CreateInstance(t1[k]);
                                                ((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
                                                ((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

                                                grdBody.Tag = t1[k].ToString();

                                                grdBody.Children.Remove(animImage);
                                                grdBody.Children.Add((UIElement)obj1);
                                                break;

                                            }
                                        }
                                    }
                                    catch (Exception exp)
                                    {
                                        VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "CreatingObject--5", "Controls\\VMuktiGrid\\Grid\\ctlPOD.xaml.cs");
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion

                }
                #endregion

                al.Clear();

                #region dhaval
                if (_strFromWhere == "fromPeer")
                {
                    for (int onlineBuddyCnt = 0; onlineBuddyCnt < onlineBuddy.Count; onlineBuddyCnt++)
                    {
                        this.AddBuddy(onlineBuddy[onlineBuddyCnt]);
                    }
                }
                #endregion dhaval

                if (_strFromWhere != "fromPeer")
                {
                    InformMultipleBuddy();
                }
            }
            catch (Exception ex)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "PageThread()", "Controls\\VMuktiGrid\\Grid\\ctlPOD.xaml.cs");
            }
        }
Esempio n. 6
0
        int DownloadAndExtractZipFile()
        {
            str = CRMName;
            str = str + "_CRM";

            //Retrives the Assembly of the Zip file.
            Assembly ass = Assembly.GetEntryAssembly();

            #region Downloading ZipFile

            //Set the Variable.
            filename = str + ".zip";

            //string strModPath = "";


            #region Download Zip File using WCF FileTranserService

            //Download file using WCF FileTransferService


            try
            {
                //Create object of the HTTP Client.
                BasicHttpClient bhcFts = new BasicHttpClient();

                //Open Client.
                clientHttpFileTransfer = (IHTTPFileTransferService)bhcFts.OpenClient <IHTTPFileTransferService>("http://" + VMuktiInfo.BootStrapIPs[0] + ":80/VMukti/HttpFileTransferService");

                //Join the network.
                clientHttpFileTransfer.svcHTTPFileTransferServiceJoin();

                //Create request to download File from Bootstrap.
                DownloadRequest request = new DownloadRequest();

                //Providing the information of the file that needs to download.
                RemoteFileInfo rfi = new RemoteFileInfo();
                request.FileName = filename;
                request.FolderWhereFileIsStored = "CRMs";

                //Calling the WCF Function for downloading the File.
                rfi = clientHttpFileTransfer.svcHTTPFileTransferServiceDownloadFile(request);


                //Checking for Directory Existence.
                //if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"CRMs")))
                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");

                //Checking for File Existance.
                if (File.Exists((destination + "\\" + filename)))
                {
                    File.Delete((destination + "\\" + filename));
                }

                filePath = destination + "\\" + filename;

                System.IO.Stream inputStream = rfi.FileByteStream;


                using (System.IO.FileStream writeStream = new System.IO.FileStream(filePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
                {
                    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)
            {
                //MessageBox.Show("Download Zip: " + ex.Message);
                VMuktiHelper.ExceptionHandler(ex, "DownloadAndExtractZipFile()", "CtlCRMContainer.xaml.cs");
                if (ex.InnerException != null)
                {
                    //MessageBox.Show("Download Zip Inner Exception: " + ex.InnerException.Message);
                    VMuktiHelper.ExceptionHandler(ex, "DownloadAndExtractZipFile()", "CtlCRMContainer.xaml.cs");
                }
            }

            #endregion

            #region Downloading using Web Client --------Commented
            //try
            //{
            //    Uri u = new Uri("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/CRMs/" + filename);
            //    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");
            //    if (!File.Exists(destination + "\\" + filename))
            //    {
            //        WebClient wc = new WebClient();
            //        try
            //        {
            //            wc.DownloadFile(u, destination + "\\" + filename);
            //        }
            //        catch (Exception exp)
            //        {
            //            MessageBox.Show(exp.Message);
            //        }
            //    }
            //}
            //catch (Exception exp)
            //{
            //    MessageBox.Show("Down Load Error - " + exp.Message);
            //}
            #endregion

            #endregion

            #region Extracting

            //Code for Extracting the .zip file.
            try
            {
                //Checking for the Existance of the Directory.

                if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"CRMModules")))
                {
                    Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"CRMModules"));
                }
                str = CRMName;
                str = str + "_CRM";
                Assembly ass2 = Assembly.GetEntryAssembly();
                strModPath = ass2.Location.Replace("VMukti.Presentation.exe", @"CRMModules");

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

                //FastZip fz = new FastZip();
                //if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
                //{
                try
                {
                    //Extracting the zip file.
                    fz.ExtractZip(destination + "\\" + filename, strModPath + "\\" + str, null);
                }
                catch (Exception exp)
                {
                    //MessageBox.Show(exp.Message + " First Desgine Required CRM Using CRMDesginer");
                    VMuktiHelper.ExceptionHandler(exp, "DownloadAndExtractZipFile()", "CtlCRMContainer.xaml.cs");
                }
                // }
            }
            catch (Exception exp)
            {
                VMuktiHelper.ExceptionHandler(exp, "DownloadAndExtractZipFile(Outer)", "CtlCRMContainer.xaml.cs");
                return(-1);
            }

            #endregion
            return(0);
        }
        void DBReports()
        {
            try
            {
                ClsWidgetsCollection objGetAll = ClsWidgetsCollection.GetAllWidgets();
                foreach (ClsWidgets wid in objGetAll)
                {
                    if (wid.ModuleTitle.Contains("Report-"))
                    {
                        TabItem tbItemRpt = new TabItem();
                        tbItemRpt.Height = 40;
                        tbItemRpt.Header = wid.ModuleTitle.Replace("Report-", "").Trim();


                        try
                        {
                            #region Downloading ZipFile

                            string filename = wid.ZipFile;
                            Uri u = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + filename);
                            if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory+ "Zip Files"))
                            {
                                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Zip Files");
                            }
                            string destination = AppDomain.CurrentDomain.BaseDirectory + "Zip Files";
                            if (!File.Exists(destination + "\\" + filename))
                            {
                                WebClient wc = new WebClient();
                                wc.DownloadFile(u, destination + "\\" + filename);
                            }

                            #endregion

                            #region Extracting

                            string strModPath = AppDomain.CurrentDomain.BaseDirectory + "Modules";
                            VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
                            if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
                            {
                                fz.ExtractZip(destination + "\\" + filename, strModPath, null);
                            }

                            #endregion

                            #region Loading ReferencedAssemblies

                            DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + wid.ZipFile.Split('.')[0]);
                            ShowDirectory(dirinfomodule);


                            for (int j = 0; j < al.Count; j++)
                            {
                                string[] arraysplit = al[j].ToString().Split('\\');
                                if (arraysplit[arraysplit.Length - 1].ToString() == wid.AssemblyFile)
                                {
                                    a = Assembly.LoadFrom(al[j].ToString());
                                    AssemblyName[] an = a.GetReferencedAssemblies();

                                    for (int alcount = 0; alcount < al.Count; alcount++)
                                    {
                                        string strsplit = al[alcount].ToString();
                                        string[] strold = strsplit.Split('\\');
                                        string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

                                        for (int asscount = 0; asscount < an.Length; asscount++)
                                        {
                                            if (an[asscount].Name == strnew)
                                            {
                                                Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
                                                AssemblyName[] anbal = assbal.GetReferencedAssemblies();
                                                for (int andal = 0; andal < al.Count; andal++)
                                                {
                                                    string strsplitdal = al[andal].ToString();
                                                    string[] strolddal = strsplitdal.Split('\\');
                                                    string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

                                                    for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
                                                    {
                                                        if (anbal[asscountdal].Name == strnewdal)
                                                        {
                                                            Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    Type[] t1 = a.GetTypes();

                                    #region CreatingObject

                                    for (int k = 0; k < t1.Length; k++)
                                    {
                                        if (t1[k].Name == wid.ClassName)
                                        {
                                            try
                                            {
                                                object[] objArg = new object[1];
                                                objArg[0] = new ModulePermissions[] { ModulePermissions.Add, ModulePermissions.Delete, ModulePermissions.Edit, ModulePermissions.View };

                                                object obj1 = Activator.CreateInstance(t1[k], objArg);


                                                tbItemRpt.Content = obj1;                                                
                                            }
                                            catch (Exception ex)
                                            {
                                                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "CreatingObject--7", "Controls\\VMuktiGrid\\Grid\\ctlPOD.xaml.cs");
                                                
                                            }

                                        }
                                    }
                                    #endregion
                                }
                            }
                            #endregion
                           
                        }
                        catch (Exception ex)
                        {
                            VMuktiHelper.ExceptionHandler(ex, "DBReports()--creating object", "ctlDashBoardContainer.xaml.cs");
                        }                       
                        tbItemRpt.Tag = wid;
                        tbCnt.Items.Add(tbItemRpt);                     
                    }
                }
            }

            catch (Exception ex)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "DBReports", "ctlDashBoardContainer.xaml.cs");
            }
        }
        int DownloadAndExtractZipFile()
        {
            str = CRMName;
                str = str + "_CRM";

                //Retrives the Assembly of the Zip file.
                Assembly ass = Assembly.GetEntryAssembly();

                #region Downloading ZipFile

                //Set the Variable.
                filename = str + ".zip";
                
                //string strModPath = "";


                #region Download Zip File using WCF FileTranserService

                //Download file using WCF FileTransferService
                

                try
                {
                    //Create object of the HTTP Client.
                    BasicHttpClient bhcFts = new BasicHttpClient();

                    //Open Client.
                    clientHttpFileTransfer = (IHTTPFileTransferService)bhcFts.OpenClient<IHTTPFileTransferService>("http://" + VMuktiInfo.BootStrapIPs[0] + ":80/VMukti/HttpFileTransferService");

                    //Join the network.
                    clientHttpFileTransfer.svcHTTPFileTransferServiceJoin();

                    //Create request to download File from Bootstrap.
                    DownloadRequest request = new DownloadRequest();

                    //Providing the information of the file that needs to download.
                    RemoteFileInfo rfi = new RemoteFileInfo();
                    request.FileName = filename;
                    request.FolderWhereFileIsStored = "CRMs";

                    //Calling the WCF Function for downloading the File.
                    rfi = clientHttpFileTransfer.svcHTTPFileTransferServiceDownloadFile(request);


                    //Checking for Directory Existence.
                    //if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"CRMs")))
                    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");

                    //Checking for File Existance.
                    if (File.Exists((destination + "\\" + filename)))
                    {
                        File.Delete((destination + "\\" + filename));
                    }

                    filePath = destination + "\\" + filename;

                    System.IO.Stream inputStream = rfi.FileByteStream;


                    using (System.IO.FileStream writeStream = new System.IO.FileStream(filePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
                    {
                        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)
                {
                    //MessageBox.Show("Download Zip: " + ex.Message);
                    VMuktiHelper.ExceptionHandler(ex, "DownloadAndExtractZipFile()", "CtlCRMContainer.xaml.cs");
                    if (ex.InnerException != null)
                    {
                        //MessageBox.Show("Download Zip Inner Exception: " + ex.InnerException.Message);
                        VMuktiHelper.ExceptionHandler(ex, "DownloadAndExtractZipFile()", "CtlCRMContainer.xaml.cs");
                    }
                }

                #endregion

                #region Downloading using Web Client --------Commented
                //try
                //{
                //    Uri u = new Uri("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/CRMs/" + filename);
                //    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");
                //    if (!File.Exists(destination + "\\" + filename))
                //    {
                //        WebClient wc = new WebClient();
                //        try
                //        {
                //            wc.DownloadFile(u, destination + "\\" + filename);
                //        }
                //        catch (Exception exp)
                //        {
                //            MessageBox.Show(exp.Message);
                //        }
                //    }
                //}
                //catch (Exception exp)
                //{
                //    MessageBox.Show("Down Load Error - " + exp.Message);
                //}
                #endregion

                #endregion

                #region Extracting

                //Code for Extracting the .zip file.
                try
                {
                    //Checking for the Existance of the Directory.

                    if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"CRMModules")))
                    {
                        Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"CRMModules"));
                    }
                    str = CRMName;
                    str = str + "_CRM";
                    Assembly ass2 = Assembly.GetEntryAssembly();
                    strModPath = ass2.Location.Replace("VMukti.Presentation.exe", @"CRMModules");

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

                    //FastZip fz = new FastZip();
                    //if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
                    //{
                        try
                        {
                            //Extracting the zip file.
                            fz.ExtractZip(destination + "\\" + filename, strModPath+"\\"+str, null);
                        }
                        catch (Exception exp)
                        {
                            //MessageBox.Show(exp.Message + " First Desgine Required CRM Using CRMDesginer");
                            VMuktiHelper.ExceptionHandler(exp, "DownloadAndExtractZipFile()", "CtlCRMContainer.xaml.cs");
                        }
                   // }
                }
                catch (Exception exp)
                {
                    VMuktiHelper.ExceptionHandler(exp, "DownloadAndExtractZipFile(Outer)", "CtlCRMContainer.xaml.cs");
                    return -1;
                }

                #endregion
                return 0;

        }
Esempio n. 9
0
        void DBReports()
        {
            try
            {
                ClsWidgetsCollection objGetAll = ClsWidgetsCollection.GetAllWidgets();
                foreach (ClsWidgets wid in objGetAll)
                {
                    if (wid.ModuleTitle.Contains("Report-"))
                    {
                        TabItem tbItemRpt = new TabItem();
                        tbItemRpt.Height = 40;
                        tbItemRpt.Header = wid.ModuleTitle.Replace("Report-", "").Trim();


                        try
                        {
                            #region Downloading ZipFile

                            string filename = wid.ZipFile;
                            Uri    u        = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + filename);
                            if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Zip Files"))
                            {
                                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Zip Files");
                            }
                            string destination = AppDomain.CurrentDomain.BaseDirectory + "Zip Files";
                            if (!File.Exists(destination + "\\" + filename))
                            {
                                WebClient wc = new WebClient();
                                wc.DownloadFile(u, destination + "\\" + filename);
                            }

                            #endregion

                            #region Extracting

                            string strModPath = AppDomain.CurrentDomain.BaseDirectory + "Modules";
                            VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
                            if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
                            {
                                fz.ExtractZip(destination + "\\" + filename, strModPath, null);
                            }

                            #endregion

                            #region Loading ReferencedAssemblies

                            DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + wid.ZipFile.Split('.')[0]);
                            ShowDirectory(dirinfomodule);


                            for (int j = 0; j < al.Count; j++)
                            {
                                string[] arraysplit = al[j].ToString().Split('\\');
                                if (arraysplit[arraysplit.Length - 1].ToString() == wid.AssemblyFile)
                                {
                                    a = Assembly.LoadFrom(al[j].ToString());
                                    AssemblyName[] an = a.GetReferencedAssemblies();

                                    for (int alcount = 0; alcount < al.Count; alcount++)
                                    {
                                        string   strsplit = al[alcount].ToString();
                                        string[] strold   = strsplit.Split('\\');
                                        string   strnew   = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

                                        for (int asscount = 0; asscount < an.Length; asscount++)
                                        {
                                            if (an[asscount].Name == strnew)
                                            {
                                                Assembly       assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
                                                AssemblyName[] anbal  = assbal.GetReferencedAssemblies();
                                                for (int andal = 0; andal < al.Count; andal++)
                                                {
                                                    string   strsplitdal = al[andal].ToString();
                                                    string[] strolddal   = strsplitdal.Split('\\');
                                                    string   strnewdal   = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

                                                    for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
                                                    {
                                                        if (anbal[asscountdal].Name == strnewdal)
                                                        {
                                                            Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    Type[] t1 = a.GetTypes();

                                    #region CreatingObject

                                    for (int k = 0; k < t1.Length; k++)
                                    {
                                        if (t1[k].Name == wid.ClassName)
                                        {
                                            try
                                            {
                                                object[] objArg = new object[1];
                                                objArg[0] = new ModulePermissions[] { ModulePermissions.Add, ModulePermissions.Delete, ModulePermissions.Edit, ModulePermissions.View };

                                                object obj1 = Activator.CreateInstance(t1[k], objArg);


                                                tbItemRpt.Content = obj1;
                                            }
                                            catch (Exception ex)
                                            {
                                                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "CreatingObject--7", "Controls\\VMuktiGrid\\Grid\\ctlPOD.xaml.cs");
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            VMuktiHelper.ExceptionHandler(ex, "DBReports()--creating object", "ctlDashBoardContainer.xaml.cs");
                        }
                        tbItemRpt.Tag = wid;
                        tbCnt.Items.Add(tbItemRpt);
                    }
                }
            }

            catch (Exception ex)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "DBReports", "ctlDashBoardContainer.xaml.cs");
            }
        }