Example #1
0
        /// <summary>
        /// 递归创建
        /// </summary>
        /// <param name="node"></param>
        private void makeWebPacker(TreeNode node)
        {
            if (node.Checked)
            {
                if (node.Tag != null)
                {
                    string tag = node.Tag.ToString();
                    string tp  = tag.Substring(0, 1);
                    //文件节点
                    if (tp == "2")
                    {
                        string filePath = tag.Substring(1);
                        //string content = File.ReadAllText(filePath, Encoding.GetEncoding("GB2312"));
                        WebPackager pack = WebPackager.FromFile(filePath, packageControl1);
                        lstPacker.Add(pack);
                    }
                }
            }

            //子节点
            if (node.Nodes.Count > 0)
            {
                foreach (TreeNode item in node.Nodes)
                {
                    makeWebPacker(item);
                }
            }
        }
Example #2
0
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode node = e.Node;

            if (node.Tag != null)
            {
                string str = node.Tag.ToString();
                if (str.Substring(0, 1) == "2")
                {
                    string      file     = str.Substring(1);
                    WebPackager packager = WebPackager.FromFile(file);
                    FileInfo    info     = new FileInfo(file);
                    this.packageControl1.WebPackager = packager;
                    this.packageControl1.FilePath    = file;
                }
            }
        }
Example #3
0
 private void makeWebPacker(TreeNode node)
 {
     if (node.Checked && (node.Tag != null))
     {
         string str = node.Tag.ToString();
         if (str.Substring(0, 1) == "2")
         {
             WebPackager item = WebPackager.FromFile(str.Substring(1));
             this.lstPacker.Add(item);
         }
     }
     if (node.Nodes.Count > 0)
     {
         foreach (TreeNode node2 in node.Nodes)
         {
             this.makeWebPacker(node2);
         }
     }
 }
Example #4
0
        /// <summary>
        /// 获取配置对象
        /// </summary>
        /// <returns></returns>
        void MakeWebPackage()
        {
            if (webPackager == null)
            {
                webPackager = new WebPackager(this);
            }
            //网站ID
            webPackager.WebId = txtSiteId.Text.Trim();
            //网站模板名称
            webPackager.Theme = txtTheme.Text.Trim();
            //
            webPackager.LastUpdateTime = dateTimePickerLastUpdate.Value;
            //原目录
            webPackager.SourcePath = textBoxSrc.Text.Trim();
            //目标目录
            webPackager.DestinationPath = textBoxDest.Text.Trim();
            //排除的后缀名
            webPackager.ExceptExtensions = new List <string>();
            Regex           reg    = new Regex("\\S+");
            MatchCollection matchs = reg.Matches(textBoxExceptExt.Text);

            foreach (Match item in matchs)
            {
                webPackager.ExceptExtensions.Add(item.Value);
            }

            //排除的目录
            webPackager.ExceptDirs = new List <string>();
            reg    = new Regex("\\S+");
            matchs = reg.Matches(textBoxExceptDir.Text);
            foreach (Match item in matchs)
            {
                webPackager.ExceptDirs.Add(item.Value);
            }

            //是否只打包更新时间
            webPackager.IsOnlyEditTime = chkOnlyEditTime.Checked;
            webPackager.useAllFolders  = this.chkAllFolders.Checked;
        }
Example #5
0
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode node = e.Node;

            if (node.Tag == null)
            {
                return;
            }

            string tag = node.Tag.ToString();
            string tp  = tag.Substring(0, 1);

            //文件节点
            if (tp == "2")
            {
                string filePath = tag.Substring(1);
                //string content = File.ReadAllText(filePath, Encoding.GetEncoding("GB2312"));
                WebPackager pack = WebPackager.FromFile(filePath, packageControl1);

                FileInfo file = new FileInfo(filePath);
                packageControl1.WebPackager = pack;
                packageControl1.FilePath    = filePath;
            }
        }
Example #6
0
        public static WebPackager FromFile(string file)
        {
            if (!File.Exists(file))
            {
                return(null);
            }
            string[]    strArray = File.ReadAllLines(file, Encoding.GetEncoding("UTF-8"));
            WebPackager packager = new WebPackager {
                ExceptDirs       = new List <string>(),
                ExceptExtensions = new List <string>(),
                ExceptFiles      = new List <string>(),
                AllFolders       = new List <string>()
            };
            FileInfo info = new FileInfo(file);

            packager.Name          = info.Name.Replace(".pack", "");
            packager.FileName      = file;
            packager.useAllFolders = false;
            foreach (string str in strArray)
            {
                string input = str.Trim();
                if (!input.StartsWith("#"))
                {
                    Match match;
                    if ((match = Regex.Match(input, @"(?<=src(\s)*=(\s)*).+")).Success)
                    {
                        packager.SourcePath = match.Value;
                    }
                    else if ((match = Regex.Match(input, @"(?<=dest(\s)*=(\s)*).+")).Success)
                    {
                        packager.DestinationPath = match.Value;
                    }
                    else if ((match = Regex.Match(input, @"(?<=time(\s)*=(\s)*).+")).Success)
                    {
                        DateTime time;
                        if (DateTime.TryParse(match.Value, out time))
                        {
                            packager.LastUpdateTime = time;
                        }
                    }
                    else if ((match = Regex.Match(input, @"(?<=web_id(\s)*=(\s)*).+")).Success)
                    {
                        packager.WebId = match.Value;
                    }
                    else if ((match = Regex.Match(input, @"(?<=theme(\s)*=(\s)*).+")).Success)
                    {
                        packager.Theme = match.Value;
                    }
                    else if ((match = Regex.Match(input, @"(?<=except_dir(\s)*=(\s)*).+")).Success)
                    {
                        packager.ExceptDirs.Add(match.Value);
                    }
                    else if ((match = Regex.Match(input, @"(?<=except_extension(\s)*=(\s)*).+")).Success)
                    {
                        packager.ExceptExtensions.Add(match.Value);
                    }
                    else if (!(match = Regex.Match(input, @"(?<=all_enable(\s)*=(\s)*).+")).Success && (match = Regex.Match(input, @"(?<=all_folders(\s)*=(\s)*).+")).Success)
                    {
                        packager.AllFolders.Add(match.Value);
                    }
                }
            }
            return(packager);
        }
Example #7
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);
        }