public void OnConnection(object application)
        {
            this.framework = (IFramework)application;

            logger.Info("解压核心程序...");
            try
            {
                bool flag = ProcessHelper.KillProcess(Arguments.PHANTOMJS_PROCESS_NAME);
                if (flag == true)
                {
                    ExtractHelper.Extract(Arguments.TEMP_FOLDER, Arguments.PHANTOMJS_NAME, Arguments.SCRIPT_NAME);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Extract core failed.", ex);
                throw new BasicException("Extract core failed.");
            }

            logger.Info("解压核心程序结束.");

            if (File.Exists(Path.Combine(Arguments.TEMP_FOLDER, Arguments.PHANTOMJS_NAME)) == false)
            {
                throw new BasicException("Webkit未找到,请重新安装软件或联系客服。");
            }

            VerifyDirectory();
        }
예제 #2
0
        /// <summary>
        /// Extract JSON object from HTML template.
        /// </summary>
        /// <param name="text">HTML template</param>
        /// <returns>JSON object</returns>
        public static object Extract(string text)
        {
            var obj = new ExpandoObject() as IDictionary <string, object>;

            while (true)
            {
                var props = ExtractHelper.ExtractProps(text);
                var tag   = props.FirstOrDefault(x => x.StartsWith("for", StringComparison.CurrentCultureIgnoreCase));

                if (string.IsNullOrEmpty(tag))
                {
                    break;
                }

                var tagName = tag.Replace("for", string.Empty).Trim();

                string newText;
                var    childObjects = ExtractHelper.GetChildObjects(tagName, text, out newText);

                text = newText;

                obj.Add(tagName, childObjects);
            }

            var parents = ExtractHelper.ExtractProps(text);

            foreach (var propName in parents)
            {
                obj.Add(propName, string.Empty);
            }

            return(obj);
        }
예제 #3
0
    static void Main(string[] args)
    {
        var lines = ExtractHelper.IterateProps(typeof(Container)).ToArray();

        foreach (var line in lines)
        {
            Console.WriteLine(line);
        }
        Console.ReadLine();
    }
        public TicketSearchFieldsResult GetTicketSearchFields()
        {
            var ticket       = TicketSearchParams.EmptyTicketSearchParams();
            var searchFields = ExtractHelper.Flatten(ticket).ToList();

            return(new TicketSearchFieldsResult
            {
                Ticket = ticket,
                SearchFields = searchFields
            });
        }
예제 #5
0
        public override void Extract()
        {
            Trace.Assert(string.IsNullOrWhiteSpace(SourcePackagePath));
            Trace.Assert(string.IsNullOrWhiteSpace(DestinationDirectoryPath));

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

            //msiexec.exe /a windows8.1-kb3081403-x64.msi /qb TargetDir=\\localhost\D$\HotfixDB\qfe-2015-09\handextract\windows8.1-kb3081403-x64
            ExtractHelper.ExecuteExternalCommand(CommandFilePath, string.Format(@"/a ""{0}"" /qb TargetDir=""{1}""", SourcePackagePath, DestinationDirectoryPath));
        }
예제 #6
0
        protected override async Task <int> OnExecuteAsync(CommandLineApplication app)
        {
            Identifier = Identifier.ToLower();

            if (Name.IsNullOrWhiteSpace())
            {
                var defaultName = string.Empty;
                var promptText  = string.Empty;
                switch (Identifier)
                {
                case "console":
                    defaultName = Consts.DefaultConsoleName;
                    promptText  = Consts.Descriptions.New.NameConsolePrompt;
                    break;

                case "module":
                    defaultName = Consts.DefaultModuleName;
                    promptText  = Consts.Descriptions.New.NameModulePrompt;
                    break;

                default:
                    break;
                }

                Name = Prompt.GetString(promptText, defaultValue: defaultName);
            }

            var tplFinder = new TemplateFinder(TemplateName);

            var tplFilePath = await tplFinder.Fetch();

            var projectFolder = Path.Combine(Directory.GetCurrentDirectory(),
                                             $".{Path.DirectorySeparatorChar}src{Path.DirectorySeparatorChar}{Name}");

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

            ExtractHelper.ExtractZipFile(tplFilePath, projectFolder, Identifier);

            if (Identifier == "module")
            {
                Placeholder = $"{Placeholder}.{DefaultModuleNamePlaceholder}";
            }

            RenameHelper.RenameFolders(projectFolder, Placeholder, Name, false, null);

            return(0);
        }
예제 #7
0
        public override void Extract()
        {
            Trace.Assert(!string.IsNullOrWhiteSpace(SourcePackagePath));
            Trace.Assert(!string.IsNullOrWhiteSpace(DestinationDirectoryPath));

            // Create destination directory if not exist.
            if (!Directory.Exists(DestinationDirectoryPath))
            {
                Directory.CreateDirectory(DestinationDirectoryPath);
            }

            // Extract files from .cab file.
            string commandParameter = string.Format(@"-f:* ""{0}"" ""{1}""", SourcePackagePath, DestinationDirectoryPath);

            ExtractHelper.ExecuteExternalCommand(CommandFilePath, commandParameter);
        }
예제 #8
0
        public async Task <int> Execute(IReadOnlyList <string> args)
        {
            int argumentsResult =
                this.SetArguments(args);

            if (argumentsResult != 0)
            {
                return(argumentsResult);
            }

            try
            {
                byte[] passwordHash = null;

                if (!string.IsNullOrEmpty(this._Password))
                {
                    System.Security.Cryptography.MD5CryptoServiceProvider md5 =
                        new System.Security.Cryptography.MD5CryptoServiceProvider();
                    passwordHash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(this._Password));
                }

                ExtractHelper extractHelper =
                    new ExtractHelper();
                await Task.Factory.StartNew(
                    () => extractHelper.Extract(
                        Path.Combine(this._XeoraDomainPath, "app.xeora"),
                        passwordHash,
                        this._ListContent,
                        this._OutputLocation
                        )
                    );

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Extract operation has been failed!");
                Console.WriteLine($"   Reason: {e.Message}");
                return(1);
            }
        }
예제 #9
0
        public override void Extract()
        {
            Trace.Assert(!string.IsNullOrWhiteSpace(SourcePackagePath));
            Trace.Assert(!string.IsNullOrWhiteSpace(DestinationDirectoryPath));

            // Create destination directory if not exist.
            if (!Directory.Exists(DestinationDirectoryPath))
            {
                Directory.CreateDirectory(DestinationDirectoryPath);
            }

            // Extract files from NDP*.exe file.
            string commandFilePath  = SourcePackagePath;
            string commandParameter = string.Format(@"/x:{0} /q", DestinationDirectoryPath);

            ExtractHelper.ExecuteExternalCommand(commandFilePath, commandParameter);

            //msix.exe NDP46-KB3057781.msp /out NDP46 - KB3057781 / ext
            //mkdir NDP46-KB3057781\NetFxSecurityUpdate
            //expand.exe "NDP46-KB3057781\NetFxSecurity Update.cab.cab" - F:*NDP46 - KB3057781\NetFxSecurityUpdate
        }
예제 #10
0
        public override void Extract()
        {
            Trace.Assert(!string.IsNullOrWhiteSpace(SourcePackagePath));
            Trace.Assert(!string.IsNullOrWhiteSpace(DestinationDirectoryPath));

            // Create destination directory if not exist.
            if (!Directory.Exists(DestinationDirectoryPath))
            {
                Directory.CreateDirectory(DestinationDirectoryPath);
            }

            // Extract *cab files from .msu file.
            string commandParameter = string.Format(@"-f:*.cab ""{0}"" ""{1}""", SourcePackagePath, DestinationDirectoryPath);

            ExtractHelper.ExecuteExternalCommand(CommandFilePath, commandParameter);

            // Retrieve inner cab file path.
            //string innerCabFilePath = getInnerCabFilePath();

            // Extract inner *.cab files.
            //extractInnerCabFiles(innerCabFilePath);
        }
예제 #11
0
        protected override async Task <int> OnExecuteAsync(CommandLineApplication app)
        {
            if (!Mpa)
            {
                //switch to personball/module-zero-core-template to reduce size of project template zip file
                if (TemplateName == Consts.DefaultProjectTemplateName)
                {
                    TemplateName = Consts.DefaultProjectTemplateForSPA;
                }

                if (string.IsNullOrWhiteSpace(SpaType))
                {
                    SpaType = Prompt.GetString(Consts.Descriptions.Init.SpaTypeDescription, defaultValue: "vue");
                    SpaType = SpaType.ToLower();
                    if ("vue,ng,react".IndexOf(SpaType) == -1)
                    {
                        SpaType = "vue";
                    }
                }
            }

            Console.WriteLine($"TemplateName\t:{TemplateName}");
            Console.WriteLine($"Placeholder\t:{Placeholder}");
            Console.WriteLine($"ProjectName\t:{ProjectName}");
            Console.WriteLine($"MPA\t\t:{Mpa}");
            Console.WriteLine($"SpaType\t\t:{SpaType}");
            Console.WriteLine($"RenameBackup\t:{RenameBackup}");

            //Create Target folder
            var projectFolder = Path.Combine(Directory.GetCurrentDirectory(), ProjectName);

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

            var tplFinder = new TemplateFinder(TemplateName);

            var tplFilePath = await tplFinder.Fetch();

            ExtractHelper.ExtractZipFile(tplFilePath, projectFolder);

            var excludeFolders = new List <string>();

            InitExcludedFolders.ForEach(s =>
            {
                excludeFolders.Add(s);
            });

            if (!Mpa)
            {
                excludeFolders.Add($"./aspnet-core/src/{Placeholder}.Web.Mvc");
                //TODO@personball remove web.mvc entry in vs solution file(sln).
                switch (SpaType.ToLower())
                {
                case "ng":
                    excludeFolders.Remove("./angular");
                    break;

                case "react":
                    excludeFolders.Remove("./reactjs");
                    break;

                case "vue":
                default:
                    excludeFolders.Remove("./vue");
                    break;
                }
            }

            // Placeholder as AbpCompanyName.AbpProjectName
            // ProjectName as CompanyName.ProjectName or just ProjectName
            RenameHelper.RenameFolders(projectFolder, Placeholder, ProjectName, RenameBackup, excludeFolders);

            Console.WriteLine("Init Completed!");
            return(0);
        }
예제 #12
0
        public void Convert()
        {
            #region 创建esHelper、configHelper

            var esUrl = ConfigurationManager.AppSettings["EsUrl"];
            if (string.IsNullOrEmpty(esUrl))
            {
                LogWriter.Error(string.Format("文字提取程序异常:{0},错误:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "配置文件缺少EsUrl"));
                return;
            }
            var esHelper = EsBaseHelper.CreateEsHelper(esUrl);
            try
            {
                if (!esHelper.ExistsIndex(EsConst.defaultEsFileIndex))
                {
                    esHelper.CreateIndex <EsFile>(EsConst.defaultEsFileIndex);//创建es索引
                }
            }
            catch (Exception ex)
            {
                LogWriter.Error(ex, string.Format("文字提取程序异常:{0},错误:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ex.Message));
                return;
            }
            esHelper.DefaultIndex = EsConst.defaultEsFileIndex;//设置es默认索引

            SQLHelper configHelper = SQLHelper.CreateSqlHelper("DocConfigCntString");

            #endregion

            string spaceSql = "select * from dbo.S_DOC_Space ";
            var    spaceDt  = configHelper.ExecuteDataTable(spaceSql);

            string nodeConfigSQL = @"select NodeID ConfigID,SpaceID,AttrField Field,DataType,InputType,EnumKey,FulltextProp,AttrSort from S_DOC_NodeAttr
                                        where FulltextProp='True' 
                                        union
                                        select FileID ConfigID,SpaceID,FileAttrField Field,DataType,InputType,EnumKey,FulltextProp,AttrSort from S_DOC_FileAttr
                                        where FulltextProp='True' 
                                        order by AttrSort ";
            var    propFieldDt   = configHelper.ExecuteDataTable(nodeConfigSQL);
            var    enumFieldDt   = propFieldDt.Select("EnumKey is not null");
            var    enumDic       = new Dictionary <string, DataTable>();
            var    enumService   = Formula.FormulaHelper.GetService <Formula.IEnumService>();
            foreach (var item in enumFieldDt)
            {
                var enumKey = item["EnumKey"].ToString();
                if (enumDic.ContainsKey(enumKey))
                {
                    continue;
                }
                var enumDt = enumService.GetEnumTable(enumKey);
                enumDic.Add(enumKey, enumDt);
            }
            foreach (DataRow space in spaceDt.Rows)
            {
                try
                {
                    string constr = String.Format(conStrTemplate, space["Server"].ToString()
                                                  , space["UserName"].ToString(), space["Pwd"].ToString(), space["DbName"].ToString());
                    SQLHelper sqlHepler = new SQLHelper(constr);
                    string    sql       = @"select S_Attachment.*,S_FileInfo.ConfigID from S_Attachment 
left join S_FileInfo on S_FileInfo.ID = S_Attachment.FileID
where S_Attachment.State='Normal' and CurrentVersion='True' and S_FileInfo.State='Published'
and ((MainFile is not null and MainFile!='' ) or  (PDFFile is not null and PDFFile!='' ))
order by ID";
                    DataTable dt        = sqlHepler.ExecuteDataTable(sql);
                    var       SpaceID   = space["ID"].ToString();
                    int       i         = 1;
                    foreach (DataRow attItem in dt.Rows)
                    {
                        string logSql   = string.Empty;
                        var    Id       = SQLHelper.CreateGuid();
                        string mainFile = string.Empty;
                        if (attItem["PDFFile"] != DBNull.Value && attItem["PDFFile"] != null && !string.IsNullOrEmpty(attItem["PDFFile"].ToString()))
                        {
                            mainFile = attItem["PDFFile"].ToString();
                        }
                        if (string.IsNullOrEmpty(mainFile))
                        {
                            if (attItem["MainFile"] != DBNull.Value && attItem["MainFile"] != null && !string.IsNullOrEmpty(attItem["MainFile"].ToString()))
                            {
                                mainFile = attItem["MainFile"].ToString();
                            }
                        }
                        var    FileID       = attItem["FileID"].ToString();
                        var    NodeID       = attItem["NodeID"].ToString();
                        var    ConfigID     = attItem["ConfigID"].ToString();
                        var    AttrID       = attItem["ID"].ToString();
                        string FormatLogSql = @"INSERT INTO S_DOC_FulltextSearchConvertLog
                                                            ([ID],[FsFileID],[AttrID] ,[FileID] ,[NodeID] ,[SpaceID] ,[CreateDate] ,[ConvertState],[ErrorMeesage])
                                                            VALUES ('" + Id + "' ,'" + mainFile.Replace("'", "''") + "','" + AttrID + "','" + FileID + "' ,'" + NodeID + "' ,'" + SpaceID + "' ,'" + DateTime.Now + "','{0}','{1}')";
                        string updateSql    = "update S_Attachment Set State='Finish' where ID='" + attItem["ID"].ToString() + "'";
                        Console.WriteLine("文件信息:" + mainFile + " " + DateTime.Now.ToString());
                        var ext = GetFileExt(mainFile).ToLower();
                        try
                        {
                            string content = string.Empty;
                            //string fullPath = service.GetFileFullPath(mainFile);
                            var file = FileStoreHelper.GetFile(mainFile);
                            //Console.WriteLine("文件路径:" + fullPath);

                            #region 提取文字

                            switch (ext)
                            {
                            case "docx":
                            case "doc": content = ExtractHelper.GetWordText(file); break;

                            case "xls":
                            case "xlsx": content = ExtractHelper.GetExcelText(file); break;

                            case "pdf": content = ExtractHelper.GetPdfText_Itextsharp(file); break;

                            case "txt": content = ExtractHelper.GetTxtText(file); break;

                            default:
                            {
                                Console.WriteLine(ext + "文件跳过");
                                sqlHepler.ExecuteNonQuery(updateSql);
                                Console.Write(ext + " 格式不对跳过" + i.ToString() + "/" + dt.Rows.Count);
                                i++;
                                continue;
                            }
                            }
                            Console.WriteLine("获取信息内容完成");
                            #endregion
                            #region 属性json、全路径json
                            var fileDt = sqlHepler.ExecuteDataTable(@"select * from S_FileInfo where id='" + FileID + "'");
                            if (fileDt.Rows.Count == 0)
                            {
                                throw new Exception(string.Format("没有找到ID为【{0}】的S_FileInfo的记录", FileID));
                            }
                            var nodeFullID = fileDt.Rows[0]["FullNodeID"].ToString();
                            var nodeDt     = sqlHepler.ExecuteDataTable(@"select * from S_NodeInfo where id in ('" + nodeFullID.Replace(".", "','") + "')");
                            nodeDt.PrimaryKey = new DataColumn[] { nodeDt.Columns["ID"] };

                            string propertyJson = string.Empty; //属性,空格分隔的string,暂时不存Json
                            string nodePathJson = string.Empty; //全路径Json
                            var    nodePathList = new List <Dictionary <string, string> >();
                            nodePathList.Add(new Dictionary <string, string>()
                            {
                                { "id", SpaceID }, { "name", space["Name"].ToString() }, { "type", "space" }
                            });

                            foreach (var nid in nodeFullID.Split('.'))
                            {
                                var nodeRow = nodeDt.Rows.Find(nid);
                                if (nodeRow == null)
                                {
                                    continue;
                                }
                                //目录属性
                                var propString = GetPropStrings(propFieldDt, nodeRow, enumDic);
                                propertyJson += propString;

                                //全路径
                                string nname = nodeRow["Name"].ToString();
                                nodePathList.Add(new Dictionary <string, string>()
                                {
                                    { "id", nid }, { "name", nname }, { "type", "node" }
                                });
                            }
                            //文件节点目录
                            nodePathList.Add(new Dictionary <string, string>()
                            {
                                { "id", SpaceID }, { "name", fileDt.Rows[0]["Name"].ToString() }, { "type", "file" }
                            });
                            nodePathJson = JsonHelper.ToJson(nodePathList);
                            //文件属性
                            var filePropString = GetPropStrings(propFieldDt, fileDt.Rows[0], enumDic);
                            propertyJson += filePropString;
                            propertyJson  = propertyJson.TrimEnd();
                            #endregion
                            #region 插入Es

                            var esFile = new EsFile();
                            esFile.Id       = FileID;
                            esFile.SpaceID  = SpaceID;
                            esFile.NodeID   = NodeID;
                            esFile.FileID   = FileID;
                            esFile.AttrID   = AttrID;
                            esFile.ConfigID = ConfigID;
                            if (!string.IsNullOrEmpty(mainFile))
                            {
                                esFile.FsFileID = System.Convert.ToInt32(mainFile.Split('_')[0]);
                            }
                            esFile.Title        = GetFileName(mainFile);
                            esFile.Content      = content;
                            esFile.PropertyJson = propertyJson;
                            esFile.FullPathJson = nodePathJson;
                            if (attItem["CreateDate"] != null && attItem["CreateDate"] != DBNull.Value)
                            {
                                esFile.FileCreateDate = System.Convert.ToDateTime(attItem["CreateDate"]);
                            }
                            else
                            {
                                esFile.FileCreateDate = DateTime.Now; //归档日期
                            }
                            if (attItem["CreateUserName"] != null && attItem["CreateUserName"] != DBNull.Value)
                            {
                                esFile.FileCreateUser = attItem["CreateUserName"].ToString(); //归档人
                            }
                            esFile.SecretLevel = string.Empty;                                //密级
                            esHelper.AddDocument(esFile);
                            Console.WriteLine("更新Es数据完成");
                            #endregion

                            sqlHepler.ExecuteNonQuery(updateSql);
                            logSql = String.Format(FormatLogSql, "Success", "");
                            configHelper.ExecuteNonQuery(logSql);
                            Console.Write(" 成功" + i.ToString() + "/" + dt.Rows.Count);
                            i++;
                        }
                        catch (Exception ex)
                        {
                            logSql = String.Format(FormatLogSql, "Error", ex.Message);
                            configHelper.ExecuteNonQuery(logSql);
                            LogWriter.Error(ex, string.Format("文字提取程序异常:{0},错误:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ex.Message));
                            Console.WriteLine("失败跳过" + i.ToString() + "/" + dt.Rows.Count);
                            i++;
                            continue;
                        }
                    }
                }
                catch (Exception exp)
                {
                    LogWriter.Error(exp, string.Format("文字提取程序异常:{0},错误:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), exp.Message));

                    Console.WriteLine(exp.InnerException);
                    continue;
                }
            }
        }