示例#1
0
        /// <summary>
        /// 检查作业和进程是否匹配
        /// </summary>
        /// <returns><c>true</c>, if job and process match was checked, <c>false</c> otherwise.</returns>
        /// <param name="osProcess">Os process.</param>
        /// <param name="jobName">Job name.</param>
        /// <param name="jobId">Job identifier.</param>
        /// <param name="method">Method.</param>
        public static bool CheckJobAndProcessMatch(Process osProcess, string jobName, string jobId, string method)
        {
            SwiftProcessCommandLine commandLine = null;

            try
            {
                commandLine = SwiftProcessCommandLine.Get(osProcess, EnumExecutableFileType.DirectExe | EnumExecutableFileType.DotNet);
            }
            catch (Exception ex)
            {
                LogWriter.Write(string.Format("获取并格式化进程命令行异常:{0}", osProcess.Id), ex, LogLevel.Info);
            }

            if (commandLine == null)
            {
                return(false);
            }

            if (!commandLine.Paras.TryGetValue("-jn", out string cJobName))
            {
                return(false);
            }

            if (!commandLine.Paras.TryGetValue("-jr", out string cJobRecordId))
            {
                return(false);
            }

            if (method == "SplitJob" && !commandLine.Paras.ContainsKey("-d"))
            {
                return(false);
            }

            if (method == "CollectTaskResult" && !commandLine.Paras.ContainsKey("-m"))
            {
                return(false);
            }

            if (jobName == cJobName && jobId == cJobRecordId)
            {
                return(true);
            }

            return(false);
        }
示例#2
0
        /// <summary>
        /// 检查任务和进程是否匹配
        /// </summary>
        /// <returns><c>true</c>, if task and process match was checked, <c>false</c> otherwise.</returns>
        /// <param name="osProcess">Process.</param>
        /// <param name="jobName">Job name.</param>
        /// <param name="jobId">Job identifier.</param>
        /// <param name="taskId">Task identifier.</param>
        public static bool CheckTaskAndProcessMatch(Process osProcess, string jobName, string jobId, int taskId)
        {
            SwiftProcessCommandLine commandLine = null;

            try
            {
                commandLine = SwiftProcessCommandLine.Get(osProcess, EnumExecutableFileType.DirectExe | EnumExecutableFileType.DotNet);
            }
            catch (Exception ex)
            {
                LogWriter.Write(string.Format("获取并格式化进程命令行异常:{0}", osProcess.Id), ex, LogLevel.Info);
            }

            if (commandLine == null)
            {
                return(false);
            }

            if (!commandLine.Paras.TryGetValue("-jn", out string cJobName))
            {
                return(false);
            }

            if (!commandLine.Paras.TryGetValue("-jr", out string cJobRecordId))
            {
                return(false);
            }

            if (!commandLine.Paras.TryGetValue("-t", out string cTaskId))
            {
                return(false);
            }

            if (jobName == cJobName && jobId == cJobRecordId && taskId == int.Parse(cTaskId))
            {
                return(true);
            }

            return(false);
        }
示例#3
0
        /// <summary>
        /// 检查进程和任务是否匹配
        /// </summary>
        /// <returns>The task and process match.</returns>
        /// <param name="task">Task.</param>
        /// <param name="process">Process.</param>
        private static bool CheckTaskAndProcessMatch(JobTask task, Process process, out SwiftProcessCommandLine commandLine)
        {
            commandLine = null;

            if (task == null || process == null)
            {
                return(false);
            }

            var job = task.Job;

            try
            {
                if (job.ExeType == "exe")
                {
                    LogWriter.Write("将按照DirectExe格式解析进程命令行", LogLevel.Debug);
                    commandLine = SwiftProcessCommandLine.Get(process, EnumExecutableFileType.DirectExe);
                }
                else if (job.ExeType == "dotnet")
                {
                    LogWriter.Write("将按照DotNet格式解析进程命令行", LogLevel.Debug);
                    commandLine = SwiftProcessCommandLine.Get(process, EnumExecutableFileType.DotNet);
                }
                else
                {
                    throw new NotSupportedException("not supported executable file type: " + job.ExeType);
                }

                if (commandLine == null)
                {
                    return(false);
                }

                LogWriter.Write("已经成功解析进程命令行:" + JsonConvert.SerializeObject(commandLine), LogLevel.Trace);

                if (!commandLine.Paras.TryGetValue("-jn", out string jobName))
                {
                    jobName = string.Empty;
                }

                if (!commandLine.Paras.TryGetValue("-jr", out string jobRecordId))
                {
                    jobRecordId = string.Empty;
                }

                if (!commandLine.Paras.TryGetValue("-t", out string taskId))
                {
                    taskId = string.Empty;
                }

                if (jobName == job.Name && jobRecordId == job.Id && task.Id.ToString() == taskId)
                {
                    LogWriter.Write("进程命令和任务匹配", LogLevel.Debug);
                    return(true);
                }

                LogWriter.Write("进程命令和任务不匹配", LogLevel.Debug);
            }
            catch (Exception ex)
            {
                LogWriter.Write("analysis process commndline go exception.", ex, LogLevel.Info);
            }

            return(false);
        }