예제 #1
0
        static void SetProgramCs(ProjectDocument document, string ExecuteFile, ExecuteFileTypes ExecuteFileType)
        {
            string link = @"Properties\Program.cs";

            string templatePath = Properties.Settings.Default.TemplatePath;
            string basePath     = document.BasePath;

            string srcFile  = Path.Combine(templatePath, link);
            string destFile = Path.Combine(basePath, link);

            string destPath = Path.GetDirectoryName(destFile);

            if (!Directory.Exists(destPath))
            {
                Directory.CreateDirectory(destPath);
            }
            File.Copy(srcFile, destFile, true);

            string text = File.ReadAllText(destFile, Encoding.UTF8);

            text = System.Text.RegularExpressions.Regex.Replace(text,
                                                                "^        public const string ExecuteFile = @\"ShopAsstX.exe\";$",
                                                                string.Format("        public const string ExecuteFile = @\"{0}\";", ExecuteFile)
                                                                );
            text = System.Text.RegularExpressions.Regex.Replace(text,
                                                                "^        public const bool IsCLR = true;$",
                                                                string.Format("        public const bool IsCLR = {0};", (ExecuteFileType == ExecuteFileTypes.CLR) ? "true" : "false")
                                                                );
            File.WriteAllText(destFile, text, Encoding.UTF8);

            //指定 Program.cs 文件
            CompileItem compileItem = null;

            foreach (CompileItem item in document.ItemGroupCompiles)
            {
                if (item.Link == link || item.FullName.EndsWith(link, StringComparison.OrdinalIgnoreCase))
                {
                    compileItem = item;
                    break;
                }
            }
            if (compileItem != null)
            {
                document.ItemGroupCompiles.Remove(compileItem.FullName);
            }

            string fullName = Path.GetFullPath(destFile);

            document.ItemGroupCompiles.Add(new CompileItem(basePath, fullName, link));
        }
예제 #2
0
 public BlurCompiler(BlurFunctionHandler filter, double accuracy = 1D)
 {
     _compileItem = Compile(filter, accuracy);
 }
예제 #3
0
 public BlurCompiler(double accuracy = 1D)
 {
     _compileItem = Compile(DefaultFilter, accuracy);
 }
예제 #4
0
        /// <summary>
        /// 根据指定的AssemblyInfo.cs文件的内容,生成需要的AssemblyInfo.cs文件。
        /// </summary>
        /// <param name="document"></param>
        /// <param name="AssemblyInfoFile"></param>
        static void SetAssemblyInfoCs(ProjectDocument document, string AssemblyInfoFile)
        {
            string link = @"Properties\AssemblyInfo.cs";

            string templatePath = Properties.Settings.Default.TemplatePath;
            string basePath     = document.BasePath;

            //模板文档
            string templateFile = Path.Combine(templatePath, link);
            string destFile     = Path.Combine(basePath, link);

            string destPath = Path.GetDirectoryName(destFile);

            if (!Directory.Exists(destPath))
            {
                Directory.CreateDirectory(destPath);
            }

            //读取模板
            string[] templateLines = File.ReadAllLines(Path.Combine(templatePath, link));

            //存储最终生成的内容
            string[] destLines = templateLines;
            if (!string.IsNullOrEmpty(AssemblyInfoFile) && File.Exists(AssemblyInfoFile))
            {//如果指定 AssemblyInfo.cs 文件,则根据源内容,替换指定的值
                //存储源文件的赋值键对
                Dictionary <string, string> dicValues = new Dictionary <string, string>();
                string          srcContent            = File.ReadAllText(AssemblyInfoFile);
                string          pattern = @"^(?<tab>\s*)\[assembly:\s*(?<key>\w+)\s*\((?<value>.+?)\)\s*\]\s*$";
                Regex           regex   = new Regex(pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                MatchCollection matches = regex.Matches(srcContent);
                foreach (Match m in matches)
                {
                    if (m.Success)
                    {
                        string key   = m.Groups["key"].Value;
                        string value = m.Groups["value"].Value;
                        if (!dicValues.ContainsKey(key))
                        {
                            dicValues.Add(key, value);
                        }
                    }
                }
                regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase);
                for (int i = 0; i < destLines.Length; i++)
                {
                    Match match = regex.Match(destLines[i]);
                    if (match.Success)
                    {//如果匹配,则替换值
                        string key = match.Groups["key"].Value;
                        if (dicValues.ContainsKey(key))
                        {
                            destLines[i] = string.Format("{0}[assembly: {1}({2})]",
                                                         match.Groups["tab"].Value,
                                                         key,
                                                         dicValues[key]);
                        }
                    }
                }
            }
            File.WriteAllLines(destFile, destLines, Encoding.UTF8);

            CompileItem compileItem = null;

            foreach (CompileItem item in document.ItemGroupCompiles)
            {
                if (item.Link == link || item.FullName.EndsWith(link, StringComparison.OrdinalIgnoreCase))
                {
                    compileItem = item;
                    break;
                }
            }
            if (compileItem != null)
            {
                document.ItemGroupCompiles.Remove(compileItem.FullName);
            }

            string fullName = Path.GetFullPath(destFile);

            document.ItemGroupCompiles.Add(new CompileItem(basePath, fullName, link));
        }