Exemplo n.º 1
0
        /// <summary>
        /// 更新文件,被UpdateFiles调用。
        /// </summary>
        /// <param name="file"></param>
        static void UpdateFile(TemplateFileElement file)
        {
            if (!file.IsValided)
            {
                return;
            }
            string input = file.Input;

            if (!System.IO.File.Exists(input))
            {
                input = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, input);
            }

            string content;

            using (StreamReader r = new StreamReader(input))
            {
                content = r.ReadToEnd();
            }
            //版本
            content = content.Replace("$INSERTVERSION$", fullVersionNumber);
            //主版本
            content = content.Replace("$INSERTMAJORVERSION$", majorVersionNumber);
            //修订版本号
            content = content.Replace("$INSERTREVISION$", revisionNumber);
            //GIT提交HASH码
            content = content.Replace("$INSERTCOMMITHASH$", commitHash);
            content = content.Replace("$INSERTSHORTCOMMITHASH$", commitHash.Length < 8?commitHash:commitHash.Substring(0, 8));
            //插入日期
            content = content.Replace("$INSERTDATE$", DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture));
            //插入年份
            content = content.Replace("$INSERTYEAR$", DateTime.Now.Year.ToString());
            //Git分支名
            content = content.Replace("$INSERTBRANCHNAME$", branchName);
            //是否git默认分支
            bool isDefaultBranch = string.IsNullOrEmpty(branchName) || branchName == "master" || char.IsDigit(branchName, 0);

            //git分支
            content = content.Replace("$INSERTBRANCHPOSTFIX$", isDefaultBranch ? "" : ("-" + branchName));
            //版本名
            content = content.Replace("$INSERTVERSIONNAME$", versionName ?? "");
            //版本名后缀
            content = content.Replace("$INSERTVERSIONNAMEPOSTFIX$", string.IsNullOrEmpty(versionName) ? "" : "-" + versionName);

            if (File.Exists(file.Output))
            {
                using (StreamReader r = new StreamReader(file.Output))
                {
                    if (r.ReadToEnd() == content)
                    {
                        // nothing changed, do not overwrite file to prevent recompilation
                        // every time.
                        return;
                    }
                }
            }
            using (StreamWriter w = new StreamWriter(file.Output, false, Encoding.UTF8))
            {
                w.Write(content);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 执行程序版本号自动更新。
        /// </summary>
        /// <param name="args">
        /// --workdirectory
        /// --solutionname
        /// --branchname
        /// --REVISION
        /// </param>
        /// <returns></returns>
        public static int Main(string[] args)
        {
            try {
                string exeDir = Path.GetDirectoryName(typeof(MainClass).Assembly.Location);
                bool   createdNew;
                using (Mutex mutex = new Mutex(true, "UpdateAssemblyInfo" + exeDir.GetHashCode(), out createdNew)) {
                    if (!createdNew)
                    {
                        // multiple calls in parallel?
                        // it's sufficient to let one call run, so just wait for the other call to finish
                        try {
                            mutex.WaitOne(10000);
                        } catch (AbandonedMutexException) {
                        }
                        return(0);
                    }
                    //获取配置节信息
                    UpdateAssemblyInfoSection section = (UpdateAssemblyInfoSection)
                                                        System.Configuration.ConfigurationManager.GetSection("astronergy.mes.tools/updateAssemblyInfo");

                    fileName                       = section.FileName;
                    workDirectory                  = section.WorkDirectory;
                    srcCtrl                        = section.SourceControl;
                    globalAssembylInfo             = section.GlobalAssemblyInfo;
                    templateFiles                  = section.TemplateFiles;
                    globalAssemblyInfoTemplateFile = globalAssembylInfo.Input;
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i] == "--workdirectory" &&
                            i + 1 < args.Length &&
                            !string.IsNullOrEmpty(args[i + 1]))
                        {
                            workDirectory = args[i + 1];
                        }
                        else if (args[i] == "--filename" &&
                                 i + 1 < args.Length &&
                                 !string.IsNullOrEmpty(args[i + 1]))
                        {
                            fileName = args[i + 1];
                        }
                    }
                    string mainDir = Path.GetFullPath(workDirectory);
                    if (File.Exists(mainDir + "\\" + fileName))
                    {
                        Directory.SetCurrentDirectory(mainDir);
                    }
                    if (!File.Exists(fileName))
                    {
                        Console.WriteLine("Working directory must be " + fileName + "!");
                        return(2);
                    }
                    if (!System.IO.File.Exists(globalAssemblyInfoTemplateFile))
                    {
                        globalAssemblyInfoTemplateFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, globalAssemblyInfoTemplateFile);
                    }

                    RetrieveRevisionNumber();
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i] == "--branchname" && i + 1 < args.Length && !string.IsNullOrEmpty(args[i + 1]))
                        {
                            branchName = args[i + 1];
                        }
                    }
                    UpdateFiles();
                    if (args.Contains("--REVISION"))
                    {
                        var doc = new XDocument(new XElement(
                                                    "versionInfo",
                                                    new XElement("version", fullVersionNumber),
                                                    new XElement("revision", revisionNumber),
                                                    new XElement("commitHash", commitHash),
                                                    new XElement("branchName", branchName),
                                                    new XElement("versionName", versionName)
                                                    ));
                        doc.Save("REVISION");
                    }
                    return(0);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex);
                return(3);
            }
        }
Exemplo n.º 3
0
        // получение сообщений
        void ReceiveMessage()
        {
            while (true)
            {
                try
                {
                    EmigrationObject message;
                    int bytes = 0;
                    do
                    {
                        byte[] data = new byte[500000];
                        bytes   = stream.Read(data, 0, data.Length);
                        message = ByteArrayToObject(data) as EmigrationObject;
                        if (message.type == "file")
                        {
                            EmigrationFileInfo efi = (EmigrationFileInfo)message.message;
                            Tabs.Set(() => Tabs.Visibility = Visibility.Hidden);
                            DownloadFile(efi);
                            Tabs.Set(() => Tabs.Visibility = Visibility.Visible);
                        }
                    }while (stream.DataAvailable);

                    switch (message.type)
                    {
                    case "string":

                        break;

                    case "List<EmigrationPathInfo>":
                        List <EmigrationPathInfo> list = (List <EmigrationPathInfo>)message.message;
                        currentFTPpath = list[0].Name;
                        LabelPathFolder.Set(() => LabelPathFolder.Content = currentFTPpath);
                        list.RemoveAt(0);
                        FolderTreeView.Set(() => FolderTreeView.Items.Clear());
                        FolderTreeView.Set(() => {
                            list.ForEach(a => {
                                TemplateFileElement tfe = new TemplateFileElement();
                                tfe.isFile = a.isFile;
                                tfe.path   = a.Name;
                                tfe.icon   = ToImageSource(BytesToIcon(a.ImagePath));
                                FolderTreeView.Items.Add(tfe);
                            });
                        });
                        break;

                    case "DownloadComplete":
                        Tabs.Set(() => Tabs.Visibility = Visibility.Visible);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Tabs.Set(() => {
                        Tabs.Set(() => Tabs.SelectedIndex = 0);
                        Title = "Client: Disconnect.";
                        this.ShowMessageAsync("Error", ex.Message);
                    });
                    return;
                }
            }
        }