Example #1
0
        private void PublishBtn_Click(object sender, EventArgs e)
        {
            if (this.bdCountLbl.Text == "0")
            {
                MessageBox.Show("发布目录UpdateFiles下没有任何文件,不允许发布!");
                return;
            }
            configuration config = EventXml.Deserialize(typeof(configuration), LinqToXml.GetStringByXml("Publish.config")) as configuration;
            var           maxsub = config.MaxSubVersion;
            var           mainbb = config.MainVersion;
            var           minsub = config.MinSubVersion;
            var           nowsub = config.CurrVersion;
            var           count  = config.VersionCount;
            string        nowbb;

            if (int.Parse(nowsub) == int.Parse(maxsub))
            {
                //主版本加一,当前值为最小值
                config.CurrVersion = minsub;
                config.MainVersion = (int.Parse(mainbb) + 1).ToString();
                nowbb = config.MainVersion + "." + config.CurrVersion;
                config.VersionCount = (int.Parse(count) + 1).ToString();
                string       xml = EventXml.Serializer(typeof(configuration), config);
                StreamWriter sw  = new StreamWriter("Publish.config"); //这里写上你要保存的路径
                sw.WriteLine(xml);                                     //按行写
                sw.Close();                                            //关闭
            }
            else
            {
                //主版本不动,当前值加一
                config.CurrVersion = (int.Parse(nowsub) + 1).ToString();
                nowbb = config.MainVersion + "." + config.CurrVersion;
                config.VersionCount = (int.Parse(count) + 1).ToString();
                string       xml = EventXml.Serializer(typeof(configuration), config);
                StreamWriter sw  = new StreamWriter("Publish.config"); //这里写上你要保存的路径
                sw.WriteLine(xml);                                     //按行写
                sw.Close();                                            //关闭
            }
            foreach (var item in paths)
            {
                MoveFile.CopyDir("UpdateFiles", item, config.MainVersion, config.CurrVersion);
            }
            //备份完成
            MoveFile.BakLog("UpdateFiles", "UpdateHistory", nowbb);
            //修改版本号,取最大值,最小值,现在的值  修改现在的值 修改发布版本次数


            MessageBox.Show($"发布成功,当前补丁版本为:{nowbb}");
            MainForm_Load(sender, e);
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var appxml = LinqToXml.QueryElementsByFile();

            var elemtns = appxml.Element("FilePaths").Elements();

            foreach (var item in elemtns)
            {
                string name  = item.Element("Name").Value;
                string path  = item.Element("Path").Value;
                int    index = this.localtionSetting.Rows.Add();
                this.localtionSetting.Rows[index].Cells[0].Value = name;
                this.localtionSetting.Rows[index].Cells[1].Value = path;
            }

            this.MaxSubVersiontxt.Text = appxml.Element("MaxSubVersion").Value;
            this.MinSubVersiontxt.Text = appxml.Element("MinSubVersion").Value;
            this.currentlabel.Text     = appxml.Element("CurrVersion").Value;
            this.nowsublabel.Text      = appxml.Element("VersionCount").Value;
            this.MainVersiontxt.Text   = appxml.Element("MainVersion").Value;
        }
Example #3
0
        public static void CopyDir(string srcPath, string aimPath, string mainversion, string subversion)
        {
            try
            {
                string oldAimpath = aimPath;
                aimPath += "\\UpdateFiles";
                // 检查目标目录是否以目录分割字符结束如果不是则添加
                if (aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
                {
                    aimPath += System.IO.Path.DirectorySeparatorChar;
                }
                //// 判断目标目录是否存在如果不存在则新建,
                //if (!System.IO.Directory.Exists(aimPath))
                //{
                //    System.IO.Directory.CreateDirectory(aimPath);
                //}
                // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
                // 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
                // string[] fileList = Directory.GetFiles(srcPath);
                //将当前目录下的server.xml改信息

                string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
                if (fileList != null && fileList.Length != 0)
                {
                    ServerSetting serverSetting = EventXml.Deserialize(typeof(ServerSetting), LinqToXml.GetStringByXml(oldAimpath + "\\bin\\server.xml")) as ServerSetting;

                    // 遍历所有的文件和目录
                    foreach (string file in fileList)
                    {
                        FileInfo fileInfo = new FileInfo(file);
                        var      size     = fileInfo.Length.ToString();
                        var      name     = file.Split('\\')[1];
                        if (!serverSetting.UpdateFile.Where(s => name == s.SaveFileName).Any())
                        {
                            serverSetting.UpdateFile.Add(new ServerSettingUpdateFile {
                                SaveFileName  = name,
                                FileSize      = size,
                                NeedReStart   = "False",
                                ChildVersion  = subversion,
                                CopyType      = "0",
                                FilePath      = name,
                                GUID          = Guid.NewGuid().ToString("N"),
                                IsRollBack    = "False",
                                IsZipFile     = "False",
                                MainVersion   = mainversion,
                                NeedReg       = "False",
                                RuleType      = "1",
                                Title         = "批量发布:" + name,
                                SavePath      = "",
                                StartServices = "",
                                StopServices  = "",
                                Memo          = "",
                                NeedVersion   = "",
                                NewVersion    = ""
                            });
                        }
                        else
                        {
                            serverSetting.UpdateFile.ForEach(i =>
                            {
                                if (name == i.SaveFileName)
                                {
                                    i.MainVersion  = mainversion;
                                    i.ChildVersion = subversion;
                                    i.FileSize     = size;
                                }
                            });
                        }

                        File.Copy(file, aimPath + System.IO.Path.GetFileName(file), true);
                    }
                    string       xmlsss = EventXml.Serializer(typeof(ServerSetting), serverSetting);
                    string       xml    = xmlsss.Replace("xsi:type=\"xsd:string\"", "");
                    StreamWriter sw     = new StreamWriter(oldAimpath + "\\bin\\server.xml"); //这里写上你要保存的路径
                    sw.WriteLine(xml);                                                        //按行写
                    sw.Close();                                                               //关闭
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }