Exemplo n.º 1
0
        private string getBackupContent()
        {
            BackupContents bcs = new BackupContents();

            bcs.content = new List <BackupContent>();

            string contentStr = "";
            //数据备份
            BackupContent bc_dmp = new BackupContent();

            bc_dmp.Name = "dmp";
            bc_dmp.Type = new List <BackupContentType>();

            if (this.treeView1.Nodes[0].Nodes.Count > 0)
            {
                foreach (TreeNode tn in treeView1.Nodes[0].Nodes)
                {
                    if (tn.Checked == true)
                    {
                        BackupContentType type_dmp = new BackupContentType();
                        type_dmp.Name = (tn.Tag as DbUser).Name;
                        type_dmp.Type = (tn.Tag as DbUser).GetType().ToString();
                        type_dmp.Set  = new List <BackupContentSet>();
                        if (tn.Nodes != null)
                        {
                            foreach (TreeNode tablenode in tn.Nodes)
                            {
                                if (tablenode.Tag.ToString() == "remoteInfo")
                                {
                                    BackupContentSet bcs_table = new BackupContentSet();
                                    bcs_table.SetKey   = "remoteInfo";
                                    bcs_table.SetValue = tablenode.Text;
                                    type_dmp.Set.Add(bcs_table);
                                }
                                else if (tablenode.Tag.ToString() == "excludeTable")
                                {
                                    BackupContentSet bcs_table = new BackupContentSet();
                                    bcs_table.SetKey   = "excludeTable";
                                    bcs_table.SetValue = tablenode.Text;
                                    type_dmp.Set.Add(bcs_table);
                                }
                            }
                        }
                        bc_dmp.Type.Add(type_dmp);
                    }
                }
            }
            bcs.content.Add(bc_dmp);

            //程序备份
            BackupContent bc_app = new BackupContent();

            bc_app.Name = "app";
            bc_app.Type = new List <BackupContentType>();
            if (this.treeView2.Nodes[0].Nodes.Count > 0)
            {
                foreach (TreeNode tn in treeView2.Nodes[0].Nodes)
                {
                    if (tn.Checked == true)
                    {
                        BackupContentType type_app = new BackupContentType();
                        if (tn.Tag is ServiceApp)
                        {
                            type_app.Name = (tn.Tag as ServiceApp).Name;
                            type_app.Type = (tn.Tag as ServiceApp).GetType().ToString();
                        }
                        else if (tn.Tag is WebApp)
                        {
                            type_app.Name = (tn.Tag as WebApp).Name;
                            type_app.Type = (tn.Tag as WebApp).GetType().ToString();
                        }
                        else if (tn.Tag is App)
                        {
                            type_app.Name = (tn.Tag as App).Name;
                            type_app.Type = (tn.Tag as App).GetType().ToString();
                        }
                        else if (tn.Tag is Ftp)
                        {
                            type_app.Name = (tn.Tag as Ftp).Name;
                            type_app.Type = (tn.Tag as Ftp).GetType().ToString();
                        }
                        else if (tn.Tag is Gxml)
                        {
                            type_app.Name = (tn.Tag as Gxml).Name;
                            type_app.Type = (tn.Tag as Gxml).GetType().ToString();
                        }

                        type_app.Set = new List <BackupContentSet>();
                        if (tn.Nodes != null)
                        {
                            foreach (TreeNode tablenode in tn.Nodes)
                            {
                                if (tablenode.Tag.ToString() == "folder")
                                {
                                    BackupContentSet bcs_table = new BackupContentSet();
                                    bcs_table.SetKey   = "excludeFolder";
                                    bcs_table.SetValue = tablenode.Text;
                                    type_app.Set.Add(bcs_table);
                                }
                                else if (tablenode.Tag.ToString() == "file")
                                {
                                    BackupContentSet bcs_table = new BackupContentSet();
                                    bcs_table.SetKey   = "excludeFile";
                                    bcs_table.SetValue = tablenode.Text;
                                    type_app.Set.Add(bcs_table);
                                }
                            }
                        }
                        bc_app.Type.Add(type_app);
                    }
                }
            }
            bcs.content.Add(bc_app);

            //sde备份
            BackupContent bc_sde = new BackupContent();

            bc_sde.Name = "sde";
            bc_sde.Type = new List <BackupContentType>();
            if (this.treeView3.Nodes[0].Nodes.Count > 0)
            {
                foreach (TreeNode tn in treeView3.Nodes[0].Nodes)
                {
                    if (tn.Checked == true)
                    {
                        BackupContentType type_sde = new BackupContentType();
                        type_sde.Name = (tn.Tag as DbSdeUser).Name;
                        type_sde.Type = (tn.Tag as DbSdeUser).GetType().ToString();
                        type_sde.Set  = new List <BackupContentSet>();

                        bc_sde.Type.Add(type_sde);
                    }
                }
            }
            bcs.content.Add(bc_sde);

            return(contentStr = JsonClassHelper.Class2Json <BackupContents>(bcs));
        }