Beispiel #1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public WebPackager(PackageControl pc)
 {
     ExceptFiles      = new List <string>();
     ExceptDirs       = new List <string>();
     ExceptExtensions = new List <string>();
     AllFolders       = new List <string>();
     LastUpdateTime   = DateTime.Now.Date.AddDays(-3);
     WebId            = "";
     pcFrom           = pc;
 }
Beispiel #2
0
        /// <summary>
        /// 根据模版内容建立实例
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static WebPackager FromFile(string file, PackageControl pc)
        {
            if (!System.IO.File.Exists(file))
            {
                return(null);
            }

            string[] rows = System.IO.File.ReadAllLines(file, Encoding.GetEncoding("UTF-8"));

            WebPackager pack = new WebPackager(pc);

            pack.ExceptDirs       = new List <string>();
            pack.ExceptExtensions = new List <string>();
            pack.ExceptFiles      = new List <string>();
            pack.AllFolders       = new List <string>();
            FileInfo fileInfo = new FileInfo(file);

            pack.Name          = fileInfo.Name.Replace(".pack", "");
            pack.FileName      = file;
            pack.useAllFolders = false;

            //一行一行的读取
            foreach (string item in rows)
            {
                string row = item.Trim();
                //#号代表注释
                if (!row.StartsWith("#"))
                {
                    Match m;

                    //源文件目录
                    if ((m = Regex.Match(row, "(?<=src(\\s)*=(\\s)*).+")).Success)
                    {
                        pack.SourcePath = m.Value;
                    }
                    else if ((m = Regex.Match(row, "(?<=dest(\\s)*=(\\s)*).+")).Success)
                    {
                        pack.DestinationPath = m.Value;
                    }
                    else if ((m = Regex.Match(row, "(?<=time(\\s)*=(\\s)*).+")).Success)
                    {
                        DateTime dt;
                        if (DateTime.TryParse(m.Value, out dt))
                        {
                            pack.LastUpdateTime = dt;
                        }
                    }
                    else if ((m = Regex.Match(row, "(?<=web_id(\\s)*=(\\s)*).+")).Success)
                    {
                        pack.WebId = m.Value;
                    }
                    else if ((m = Regex.Match(row, "(?<=theme(\\s)*=(\\s)*).+")).Success)
                    {
                        pack.Theme = m.Value;
                    }
                    else if ((m = Regex.Match(row, "(?<=except_dir(\\s)*=(\\s)*).+")).Success)
                    {
                        pack.ExceptDirs.Add(m.Value);
                    }
                    else if ((m = Regex.Match(row, "(?<=except_extension(\\s)*=(\\s)*).+")).Success)
                    {
                        pack.ExceptExtensions.Add(m.Value);
                    }
                    else if (!(m = Regex.Match(row, @"(?<=all_enable(\s)*=(\s)*).+")).Success && (m = Regex.Match(row, @"(?<=all_folders(\s)*=(\s)*).+")).Success)
                    {
                        pack.AllFolders.Add(m.Value);
                    }
                }
            }

            return(pack);
        }