public static void MakeContextMenuForRunningJobBatch(JJobType jobType, List <ToolStripItem> menuItemList, IContentContainer docPanelContainer)
        {
            ToolStripMenuItem menuItem = null;

            if (jobType != null)
            {
                if (RunningJobStageEnum.running.ToString().Equals(jobType.JobBatchStage) && jobType.JobBatchObject != null)
                {
                    menuItem        = new ToolStripMenuItem();
                    menuItem.Text   = FrwCRUDRes.Try_to_cancel_job_batch;
                    menuItem.Click += (s, em) =>
                    {
                        try
                        {
                            JobManager.Instance.CancelAsyncJobBatch(jobType);
                        }
                        catch (Exception ex)
                        {
                            Log.ShowError(ex);
                        }
                    };
                    menuItemList.Add(menuItem);

                    menuItem        = new ToolStripMenuItem();
                    menuItem.Text   = FrwCRUDRes.Kill_job_batch_thread;
                    menuItem.Click += (s, em) =>
                    {
                        try
                        {
                            JobManager.Instance.AbortJobBatch(jobType);
                        }
                        catch (Exception ex)
                        {
                            Log.ShowError(ex);
                        }
                    };
                    menuItemList.Add(menuItem);
                }

                string   logFileName = JobManager.Instance.GetJobTypeLogFileName(jobType);
                FileInfo logFile     = new FileInfo(logFileName);
                if (jobType.JobBatchLog != null || logFile.Exists)
                {
                    menuItem        = new ToolStripMenuItem();
                    menuItem.Text   = FrwCRUDRes.Show_job_batch_console;
                    menuItem.Click += (s, em) =>
                    {
                        try
                        {
                            JobTypeConsoleWindow consoleWindow = (JobTypeConsoleWindow)AppManager.Instance.CreateContent(docPanelContainer, typeof(JobTypeConsoleWindow),
                                                                                                                         new Dictionary <string, object> {
                                { "JobType", jobType }
                            });
                            if (consoleWindow != null)
                            {
                                if (jobType.JobBatchLog != null)
                                {
                                    jobType.JobBatchLog.ExternalWriter = consoleWindow.ConsoleWriter;
                                }
                                else if (logFile.Exists)
                                {
                                    consoleWindow.ConsoleWriter.Write(File.ReadAllText(logFile.FullName));
                                }
                                consoleWindow.ProcessView();
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.ShowError(ex);
                        }
                    };
                    menuItemList.Add(menuItem);
                }
            }
        }
        /// <summary>
        /// Creates new job and job type (if needs)
        /// </summary>
        /// <param name="jjobTypeId"></param>
        /// <param name="jobTypeName"></param>
        /// <param name="additionalJobName"></param>
        /// <param name="concurType"></param>
        /// <returns></returns>
        public JRunningJob CreateJob(string jjobTypeId, string jobTypeName, string additionalJobName, JobConcurrentTypeEnum concurType = JobConcurrentTypeEnum.Wait)
        {
            DateTime time = DateTime.Now;

            if (jjobTypeId == null)
            {
                throw new ArgumentException();
            }
            JJobType jobType = (JJobType)Dm.Instance.Find(typeof(JJobType), jjobTypeId);
            bool     created = false;

            if (jobType == null)
            {
                jobType                = (JJobType)Dm.Instance.EmptyObject(typeof(JJobType), null);
                jobType.JJobTypeId     = jjobTypeId;
                jobType.ConcurrentType = concurType.ToString();
                if (JobConcurrentTypeEnum.Allow.ToString().Equals(jobType.ConcurrentType))
                {
                    jobType.MaxThreadCount = JJobType.DEFAULT_MAX_THREAD_COUNT;
                }
                if (jobTypeName != null)
                {
                    jobType.Name = jobTypeName;
                }
                else
                {
                    jobType.Name = jjobTypeId;
                }
                Dm.Instance.SaveObject(jobType);
                created = true;
            }
            if (jobType.JobBatchLog == null)
            {
                jobType.JobBatchLog             = new JobLog();
                jobType.JobBatchLog.LogFileName = GetJobTypeLogFileName(jobType);
                JobTypeConsoleWindow consoleWindow = (JobTypeConsoleWindow)AppManager.Instance.FindContent(typeof(JobTypeConsoleWindow), null, new Dictionary <string, object> {
                    { "JobType", jobType }
                });
                if (consoleWindow != null)
                {
                    if (jobType.JobBatchLog != null)
                    {
                        jobType.JobBatchLog.ExternalWriter = consoleWindow.ConsoleWriter;
                    }
                }
            }
            if (created)
            {
                jobType.JobBatchLog.Debug("Job type" + jobType.JJobTypeId + " created new");
            }
            else
            {
                jobType.JobBatchLog.Debug("Job type" + jobType.JJobTypeId + " found");
            }

            JRunningJob job = null;

            job       = (JRunningJob)Dm.Instance.EmptyObject(typeof(JRunningJob), null);
            job.Stage = RunningJobStageEnum.initial.ToString();

            job.CreateDate = time;
            if (additionalJobName != null)
            {
                job.Name = (jobType.Name) + " " + additionalJobName;
            }
            else
            {
                job.Name = (jobType.Name) + " " + time.ToString("yyyy/MM/dd HH:mm:ss");
            };
            job.JJobType           = jobType;
            job.JobLog             = new JobLog();
            job.JobLog.ParentLog   = jobType.JobBatchLog;//paren ref
            job.JobLog.LogFileName = GetJobLogFileName(job);
            Dm.Instance.SaveObject(job);
            job.JobLog.Debug("Job " + job.JRunningJobId + " created");
            return(job);
        }