Esempio n. 1
0
        private int CreateAndEnqueueJob(QueueJob queueJob, IState state, DbConnection connection)
        {
            var insertedJob = JobEntity.FromQueueJob(queueJob);

            insertedJob.CreatedAt  = DateTime.UtcNow;
            insertedJob.RetryCount = 1;
            var jobId   = this._queryService.InsertJob(insertedJob, connection);
            var stateId = this._queryService.InsertJobState(
                StateEntity.FromIState(state,
                                       insertedJob.Id),
                connection);

            this._queryService.SetJobState(jobId, stateId, state.Name, connection);
            if (state is EnqueuedState)
            {
                this._queryService.InsertJobToQueue(jobId, queueJob.QueueName, connection);
            }
            foreach (var nextJob in queueJob.NextJobs)
            {
                this._queryService.InsertJobCondition(new JobConditionEntity()
                {
                    Finished    = false,
                    JobId       = nextJob,
                    ParentJobId = jobId
                }, connection);
            }
            return(jobId);
        }
Esempio n. 2
0
        private void DeleteProjects()
        {
            List <PublishedProject> projectList = new List <PublishedProject>();

            LV_ServerObjects.InvokeIfRequired(s =>
            {
                ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems;
                projectList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (PublishedProject)selectedItem.Tag));
            });
            if (!projectList.Any())
            {
                return;
            }
            int             projectCounter = 1;
            List <QueueJob> jobs           = projectList.Select(p =>
            {
                if (p.IsCheckedOut)
                {
                    QueueJob checkinJob = p.Draft.CheckIn(true);

                    CsomHelper.ExecuteAndWait(checkinJob, TB_Status);
                }

                QueueJob job = p.DeleteObject();
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Deleting project {0} of {1} with name {2}.", projectCounter++, projectList.Count, p.Name);
                return(job);
            }).ToList();

            Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeProjectsDelete, "Waiting for the Delete queue job to complete.");
            CsomHelper.ExecuteAndWait(jobs, TB_Status);
            Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeProjectsDelete, "Refreshing Projects.");
            LoadProjectsList();
        }
 public void SetPSAMInProjectName()
 {
     projContext.Load(projContext.Projects);
     projContext.ExecuteQuery();
     foreach (var pubProj in projContext.Projects)
     {
         int planZakazNumber = 0;
         try
         {
             planZakazNumber = Convert.ToInt32(pubProj.Name.Substring(0, 4));
         }
         catch
         {
         }
         string rsamName = "";
         if (planZakazNumber > 0)
         {
             rsamName = GetRSAMName(planZakazNumber).Replace("_", "-");
         }
         if (planZakazNumber > 1156 && rsamName != "" && pubProj.Name.Length == pubProj.Name.Replace("PCAM", "").Length&& GetVipusk(planZakazNumber) == false)
         {
             try
             {
                 DraftProject projectDraft = pubProj.CheckOut();
                 projContext.Load(projectDraft);
                 projContext.ExecuteQuery();
                 projectDraft.Name += "   " + rsamName;
                 Console.WriteLine(projectDraft.Name);
                 QueueJob job = projectDraft.Update();
                 job = projectDraft.Publish(true);
             }
             catch { }
         }
     }
 }
        /// <summary>
        /// Queries processing status of a task through its GUID and name
        /// </summary>
        /// <param name="customerGuid">Identify the linked contract tasks</param>
        /// <param name="customerTaskName">Name of the task you want to get processing status</param>
        /// <returns></returns>
        private string GetCustomersJSON(string customerGuid, string customerTaskName)
        {
            // Gets contract processing status
            var stt = QueueJob.ProcessStatus(customerGuid, customerTaskName);

            return(JsonConvert.SerializeObject(stt));
        }
Esempio n. 5
0
        public static void CreateQueueConsumerThreadBox <T>(string threadboxName, int coreThreadNum, int maxThreadNum, ThreadBoxHandler <T> handler, Queue <T> queue, int milliumsecondSleepTime = 100, bool isStopOnEmptyQueue = false)
        {
            if (threadboxName == "" || coreThreadNum <= 0 || maxThreadNum <= 0 || maxThreadNum < coreThreadNum || handler == null || queue == null)
            {
                throw new ArgumentException();
            }


            Box b = null;

            lock (dicBox)
            {
                if (dicBox.ContainsKey(threadboxName))
                {
                    throw new ArgumentException("threadboxName exist");
                }
                b = new Box(coreThreadNum, maxThreadNum);
                dicBox.Add(threadboxName, b);
            }
            QueueJob <T> j = new QueueJob <T>();

            j.isStop    = isStopOnEmptyQueue;
            j.sleepTime = milliumsecondSleepTime;
            j.queue     = queue;
            j.handler   = handler;
            //b.job = j;
            b.Start(j);
        }
Esempio n. 6
0
        private static bool ExecuteAndWaitInternal(QueueJob job, TextBox textbox)
        {
            bool queueJobCompleted = false;

            JobState[] jobStateToMarkAsProcessed =
            {
                JobState.Canceled,          JobState.CorrelationBlocked, JobState.Failed,
                JobState.FailedNotBlocking, JobState.Success,
            };

            Log.WriteVerbose(new SourceInfo(), textbox,
                             "Current Queue job State:{0}, Percent Complete:{1}, Job Type:{2}", job.JobState,
                             job.PercentComplete, job.MessageType);

            JobState jobState = ProjContext.WaitForQueue(job, 3);

            if (job.IsNull())
            {
                //Server returned a null object probably the job is completed and CSOM doesnt know about the job anymore.
                queueJobCompleted = true;
            }
            if (jobStateToMarkAsProcessed.Contains(jobState))
            {
                LogStatus(job, textbox);
                queueJobCompleted = true;
            }
            else
            {
                queueJobCompleted = false;
            }
            return(queueJobCompleted);
        }
Esempio n. 7
0
        private void AddLinkToProject(DraftProject project, IEnumerable <TaskCreationInformation> tasks)
        {
            // Load tasks
            IEnumerable <DraftTask> draftTasks = BaseProjectContext.LoadQuery(project.Tasks);

            BaseProjectContext.ExecuteQuery();

            // Disorder the tasks
            List <TaskCreationInformation> levelTasks = tasks.ToList();
            List <TaskCreationInformation> linkTasks  = new List <TaskCreationInformation>();

            while (levelTasks.Count > 0)
            {
                int taskIndex = RandomHelper.Random(0, levelTasks.Count - 1);
                linkTasks.Add(levelTasks[taskIndex]);
                levelTasks.RemoveAt(taskIndex);
            }

            // Add links
            for (int i = 0; i < linkTasks.Count - 1; i++)
            {
                TaskLinkCreationInformation linkInfo = NewFSTaskLink(linkTasks[i].Id, linkTasks[i + 1].Id);
                DraftTask task = draftTasks.Where(item => item.Id == linkInfo.StartId).FirstOrDefault();
                task.Successors.Add(linkInfo);
            }

            ExcuteJobWithRetries(() =>
            {
                QueueJob job = project.Update();
                WaitForJobComplete(job);
                BaseProjectContext.ExecuteQuery();
                LoggerHelper.Instance.Comment(string.Format("Finish Adding Links to Project: {0}", project.Name));
            }, "Add Links to project");
        }
Esempio n. 8
0
        public static string StartTask(string guid, string taskName)
        {
            try
            {
                // Create a new contract with a GUID identifier, add a handle to the task that will be executed.
                using (var c = new ContractSchedule(guid, taskName))
                {
                    // Adds an ACTION with delegate to the method that will perform the task
                    c.ActionTask = delegate
                    {
                        // Delegated method receiving parameter with processing status
                        Loading(c.Status);
                    };

                    // Add task in processing queue
                    QueueJob.AddTask(new ScheduledTask(c, c.ActionTask));
                }
                return("true");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(JsonConvert.SerializeObject("false"));
            }
        }
        public DraftProject CheckOutProject(PublishedProject publishedProject)
        {
            logger.LogAndSendMessage(null, "CheckOutProject",
                                     publishedProject.Id, winServiceIterationUid,
                                     $"CheckOutProject START publishedProject.Id: {publishedProject.Id}",
                                     false, null);
            DraftProject draftProject = publishedProject.CheckOut();

            try
            {
                draftProject = GetDraftProject(draftProject, publishedProject.Id);
            }
            catch (Exception exception)
            {
                logger.LogAndSendMessage(null, "CheckOutProject",
                                         publishedProject.Id, winServiceIterationUid,
                                         $"CheckOutProject publishedProject.Id: {publishedProject.Id}",
                                         false, exception);
                if (draftProject != null)
                {
                    QueueJob job = draftProject.CheckIn(true);
                    JobState jobState;
                    WaitForQueue(job, publishedProject.Id, draftProject, out jobState);
                    draftProject = null;
                }
                //ExecuteQuery();
            }
            logger.LogAndSendMessage(null, "CheckOutProject",
                                     publishedProject.Id, winServiceIterationUid,
                                     $"CheckOutProject END publishedProject.Id: {publishedProject.Id}",
                                     false, null);
            return(draftProject);
        }
        public static JobState WaitWithRetries(this ProjectContext projectContext, QueueJob queuedJob, int maxRetries, int waitingTimeInSeconds)
        {
            JobState result = JobState.Unknown;
            int      i      = 0;

            while (i < maxRetries)
            {
                var jobState = projectContext.WaitForQueue(queuedJob, waitingTimeInSeconds);

                if (jobState == JobState.Success)
                {
                    result = jobState;
                    break;
                }
                if (jobState == JobState.Canceled || jobState == JobState.Failed || jobState == JobState.FailedNotBlocking)
                {
                    result = jobState;
                    break;
                }

                i++;
            }

            return(result);
        }
Esempio n. 11
0
        private static void UpdateProjectCustomField(Guid ProjectId)
        {
            DraftProject projCheckedOut = null;

            try
            {
                Dictionary <string, object> projDict = new Dictionary <string, object>();


                using (ProjectContext projContext = new ProjectContext(PWAUrl))
                {
                    projContext.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;

                    var PrjList = projContext.LoadQuery(projContext.Projects.Where(proj => proj.Name == ""));

                    projContext.ExecuteQuery();
                    Guid pGuid = PrjList.First().Id;

                    PublishedProject proj2Edit = PrjList.First();
                    projCheckedOut = proj2Edit.CheckOut().IncludeCustomFields;
                    projContext.Load(projCheckedOut);
                    projContext.ExecuteQuery();

                    var cflist = projContext.LoadQuery(projContext.CustomFields.Where(cf => cf.Name == "Testcol"));
                    projContext.ExecuteQuery();
                    projCheckedOut.SetCustomFieldValue(cflist.FirstOrDefault().InternalName, "Entry_c8f0abff70f5e51180cc00155dd45b0a");

                    QueueJob qJob     = projCheckedOut.Publish(true);
                    JobState jobState = projContext.WaitForQueue(qJob, 70);
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 12
0
        /// <summary>
        /// 创建一个线程池去处理一个调用队列容器
        /// </summary>
        /// <typeparam name="T">队列容器中对象的类型</typeparam>
        /// <param name="threadboxName">线程池名称</param>
        /// <param name="threadNum">线程池线程数量</param>
        /// <param name="queue">调用队列容器</param>
        /// <param name="milliumsecondSleepTime">当队列为空时休息时间(毫秒),默认为100毫秒</param>
        /// <param name="isStopOnEmptyQueue">是否当队列为空时才关闭,默认为FALSE</param>
        public static void CreateQueueInvokeThreadBox <T>(string threadboxName, int threadNum, Queue <KeyValuePair <ThreadBoxHandler <T>, T> > queue, int milliumsecondSleepTime = 100, bool isStopOnEmptyQueue = false)
        {
            if (threadboxName == "" || threadNum <= 0 || queue == null)
            {
                throw new ArgumentException();
            }

            Box b = null;

            lock (dicBox)
            {
                if (dicBox.ContainsKey(threadboxName))
                {
                    throw new ArgumentException("threadboxName exist");
                }
                b = new Box(threadNum);
                dicBox.Add(threadboxName, b);
            }

            QueueJob <KeyValuePair <ThreadBoxHandler <T>, T> > job = new QueueJob <KeyValuePair <ThreadBoxHandler <T>, T> >();

            job.isStop    = isStopOnEmptyQueue;
            job.sleepTime = milliumsecondSleepTime;
            job.queue     = queue;
            job.handler   = InvokeThreadboxHandler;
            b.Start(job);
        }
Esempio n. 13
0
        public void CheckInDraftProject(DraftProject draft)
        {
            QueueJob publishJob = draft.Publish(true);
            JobState result     = projContext.WaitForQueue(publishJob, 3600);

            Console.WriteLine("publish job state is {0}", result);
        }
        protected void WaitForJobComplete(QueueJob job, int?seconds = null)
        {
            try
            {
                DateTime startTime = DateTime.Now;
                int      waitTime  = seconds ?? 300;
                JobState jobState  = JobState.Unknown;
                do
                {
                    jobState = BaseProjectContext.WaitForQueue(job, 3);
                }while (jobState != JobState.Success && startTime.AddSeconds(waitTime) > DateTime.Now);

                if (jobState == JobState.Success)
                {
                    LoggerHelper.Instance.Pass(job.Id.ToString());
                }
                else
                {
                    LoggerHelper.Instance.Fail(string.Format("The job status is {0}.", jobState));
                }
            }
            catch (Exception e)
            {
                job.Cancel();
                LoggerHelper.Instance.Fail(string.Format("Warning: The job is failed.\nMessage: {0}. \nMore:{1} \nRetrying...", e.Message, e.StackTrace));
            }
        }
Esempio n. 15
0
        private void PublishProjects()
        {
            List <PublishedProject> projectList = new List <PublishedProject>();

            LV_Projects.InvokeIfRequired(s =>
            {
                ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems;
                projectList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (PublishedProject)selectedItem.Tag));
            });
            if (!projectList.Any())
            {
                return;
            }
            List <QueueJob> jobs = projectList.Select(p =>
            {
                if (!p.IsCheckedOut)
                {
                    p.CheckOut();
                }
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Publishing project:{0}.", p.Name);
                QueueJob job = p.Draft.Publish(true);
                return(job);
            }).ToList();

            Log.WriteVerbose(new SourceInfo(), TB_Status, _backgroundExecutorWithStatus, "Waiting for the Publish queue job to complete.");
            CsomHelper.ExecuteAndWait(jobs, TB_Status);
            Log.WriteVerbose(new SourceInfo(), TB_Status, _backgroundExecutorWithStatus, "Refreshing Projects.");
            LoadProjects();
        }
Esempio n. 16
0
    static void Main(string[] args)
    {
        SecureString secpassword = new SecureString();

        foreach (char c in password.ToCharArray())
        {
            secpassword.AppendChar(c);
        }


        ProjectContext pc = new ProjectContext(pwaPath);

        pc.Credentials = new SharePointOnlineCredentials(username, secpassword);

        //now you can query
        pc.Load(pc.Projects);
        pc.ExecuteQuery();
        foreach (var p in pc.Projects)
        {
            Console.WriteLine(p.Name);
        }

        //Or Create a new project
        ProjectCreationInformation newProj = new ProjectCreationInformation()
        {
            Id    = Guid.NewGuid(),
            Name  = "[your project name]",
            Start = DateTime.Today.Date
        };
        PublishedProject newPublishedProj = pc.Projects.Add(newProj);
        QueueJob         qJob             = pc.Projects.Update();

        JobState jobState = pc.WaitForQueue(qJob, /*timeout for wait*/ 10);
    }
Esempio n. 17
0
 public PublishedProject CreateProject(string prName, string description, DateTime startDate)
 {
     try
     {
         System.Console.Write("\nCreating project: {0} ...", prName);
         ProjectCreationInformation newProj = new ProjectCreationInformation();
         newProj.Id                      = Guid.NewGuid();
         newProj.Name                    = prName;
         newProj.Description             = description;
         newProj.Start                   = startDate;
         newProj.EnterpriseProjectTypeId = GetEptUid(basicEpt);
         PublishedProject newPublishedProj = _context.Projects.Add(newProj);
         QueueJob         qJob             = _context.Projects.Update();
         JobState         jobState         = _context.WaitForQueue(qJob, timeoutSeconds);
         if (jobState == JobState.Success)
         {
             return(newPublishedProj);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         System.Console.ForegroundColor = ConsoleColor.Red;
         System.Console.WriteLine("\nError: {0}", ex.Message);
         System.Console.ResetColor();
         return(null);
     }
 }
Esempio n. 18
0
        /// <summary>
        /// 执行Task
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="parameters"></param>
        public static void Invoke(string jobId, int taskId, params object[] parameters)
        {
            string dataCalculateNode = string.Empty;

            DataCalculateNodes = new List <string>()
            {
                "asfsdf"
            };
            //加锁,保证DataCalculate节点单线程运行
            lock (obj)
            {
                while (true)
                {
                    if (DataCalculateNodes.Count > 0)
                    {
                        dataCalculateNode = DataCalculateNodes.FirstOrDefault();
                        if (!string.IsNullOrEmpty(dataCalculateNode))
                        {
                            break;
                        }
                    }
                    Thread.Sleep(1000);
                }
            }

            var isSuccess = InvokeDataCalculate(dataCalculateNode, taskId, parameters);

            if (!isSuccess)
            {
                //dataCalculate节点执行方法
                //成功的话,取子task,筛选父节点全部执行完毕的子节点加入队列
                Expression <Action> expression = () => Invoke(jobId, taskId, null);
                QueueJob.AddOrUpdate(expression);
            }
        }
        private void RemoveResources()
        {
            PublishedProject            publishedProject = null;
            DraftProject                draftProject;
            List <DraftProjectResource> draftProjectResourceresList = new List <DraftProjectResource>();

            LV_Projects.InvokeIfRequired(s => publishedProject = (PublishedProject)s.SelectedItems[0].Tag);

            LV_ProjectResources.InvokeIfRequired(s =>
            {
                ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems;
                draftProjectResourceresList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (DraftProjectResource)selectedItem.Tag));
            });

            if (draftProjectResourceresList.Any())
            {
                draftProject = publishedProject.IsCheckedOut ? publishedProject.Draft : publishedProject.CheckOut();

                draftProjectResourceresList.ForEach(r =>
                {
                    Log.WriteVerbose(new SourceInfo(), TB_Status, "Removing Resource:{0} from Project:{1}.", r.Name, publishedProject.Draft.Name);
                    draftProject.ProjectResources.Remove(r);
                });
                QueueJob queueJob = draftProject.Update();
                Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeRemoveProjectResources, "Waiting for the Project Update job to complete.");
                CsomHelper.ExecuteAndWait(queueJob, TB_Status);
            }
            Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeRemoveProjectResources, "Refreshing Project resources.");
            GetDraftTeamForSelectedProject();
        }
Esempio n. 20
0
        public JobState CheckInProjectForce(DraftProject draft)
        {
            //CheckIn
            QueueJob publishJob = draft.CheckIn(true);
            JobState result     = projContext.WaitForQueue(publishJob, 3600);

            return(result);
        }
Esempio n. 21
0
        private void CheckInCheckoutProjects()
        {
            List <PublishedProject> projectList = new List <PublishedProject>();

            LV_ServerObjects.InvokeIfRequired(s =>
            {
                ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems;
                projectList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (PublishedProject)selectedItem.Tag));
            });
            if (!projectList.Any())
            {
                return;
            }
            if (_checkin)
            {
                List <QueueJob> jobs = projectList.Where(s => s.IsCheckedOut).Select(p =>
                {
                    QueueJob job = null;
                    Log.WriteVerbose(new SourceInfo(), TB_Status, "Checking in Project {0}", p.Name);
                    job = p.Draft.CheckIn(true);
                    return(job);
                }).ToList();

                if (jobs.Count <= 0)
                {
                    return;
                }
                Log.WriteVerbose(new SourceInfo(), TB_Status, _backgroundExecutorWithStatus, "Waiting for the Queue jobs to complete");
                CsomHelper.ExecuteAndWait(jobs, TB_Status);
                Log.WriteVerbose(new SourceInfo(), TB_Status, _backgroundExecutorWithStatus, "Loading Projects");
                LoadProjects();
            }
            else
            {
                bool needExecute = false;
                projectList.ForEach(p =>
                {
                    if (p.IsCheckedOut)
                    {
                        return;
                    }
                    Log.WriteVerbose(new SourceInfo(), TB_Status, "Checking out Project {0}", p.Name);
                    p.CheckOut();
                    needExecute = true;
                });
                if (needExecute)
                {
                    ProjContext.ExecuteQuery();
                    LoadProjects();
                }
                else
                {
                    Log.WriteVerbose(new SourceInfo(), TB_Status, _backgroundExecutorWithStatus,
                                     "All selected projects are in checked out state.");
                }
            }
        }
 public bool WaitForQueue(QueueJob job, Guid projectUid, DraftProject draftProject, out JobState jobState)
 {
     logger.LogAndSendMessage(null, "WaitForQueue",
                              projectUid, winServiceIterationUid,
                              $"WaitForQueue {projectUid}",
                              false, null);
     jobState = ProjectContext.WaitForQueue(job, WaitForQueueTimeout);
     return(jobState == JobState.Success);
 }
        public DraftProject CheckOutProject(PublishedProject publishedProject, string systemNames, Guid projectUid)
        {
            DraftProject draftProject = null;

            try
            {
                if (publishedProject.IsCheckedOut)
                {
                    if (isOnline)
                    {
                        if (publishedProject.IsCheckedOut && publishedProject.CheckedOutBy?.Email != null)
                        {
                            EmailSender emailSender = new EmailSender();
                            emailSender.SendNotificationEmail(publishedProject.CheckedOutBy.Email,
                                                              $"Check-in project {publishedProject.Name} request",
                                                              $"Hello, {publishedProject.CheckedOutBy.Title}. This is 60i Administrator. I've found that several tasks in project {publishedProject.Name} should be synchronized with {systemNames}. " +
                                                              "Howerver I need to change some properties of these tasks, but project is checked-out to you. Please check-in it for a little time so I can do neccessary operations.");
                            return(null);
                        }
                    }
                    return(null);
                }
                draftProject = CheckOutProject(publishedProject);
                return(draftProject);
            }
            //catch (PropertyOrFieldNotInitializedException exception)
            //{
            //    logger.LogAndSendMessage($"CheckOutProject ProjectUid: {projectUid}");
            //    logger.LogAndSendMessage(exception);
            //    if (draftProject != null)
            //    {
            //        logger.LogAndSendMessage("ForceCheckInProject");
            //        QueueJob job = draftProject.CheckIn(true);
            //        WaitForQueue(job, projectUid, draftProject);
            //        //ExecuteQuery();
            //    }
            //}
            catch (Exception exception)
            {
                logger.LogAndSendMessage(null, "CheckOutProject",
                                         projectUid, winServiceIterationUid,
                                         $"CheckOutProject ProjectUid: {projectUid}",
                                         false, exception);
                if (draftProject != null)
                {
                    logger.LogAndSendMessage(null, "ForceCheckInProject",
                                             projectUid, winServiceIterationUid,
                                             $"ForceCheckInProject {draftProject.Id}",
                                             false, null);
                    QueueJob job = draftProject.CheckIn(true);
                    JobState jobState;
                    WaitForQueue(job, projectUid, draftProject, out jobState);
                }
            }
            return(null);
        }
Esempio n. 24
0
 private void PublishProject(DraftProject project)
 {
     ExcuteJobWithRetries(() =>
     {
         LoggerHelper.Instance.Comment("About to Pubilsh Project with Name: " + project.Name);
         QueueJob job = project.Publish(true);
         BaseProjectContext.ExecuteQuery();
         LoggerHelper.Instance.Comment("Finish Pubilsh Project with Name: " + project.Name);
     }, "Publish Project");
 }
Esempio n. 25
0
 public void RaiseOnReschedule(QueueJob queueJob, string serverId, string workerId, Exception failException, DateTime nextRun)
 {
     try
     {
         _eventSubscriber.OnReschedule(_monitoringApi, queueJob, serverId, workerId, failException, nextRun);
     }
     catch (Exception ex)
     {
         Logger.Log(LogLevel.Error, $"Error in event subscriber method '{nameof(_eventSubscriber.OnReschedule)}'", ex);
     }
 }
Esempio n. 26
0
 public void RaiseOnProcessing(QueueJob queueJob, string serverId, string workerId)
 {
     try
     {
         _eventSubscriber.OnProcessing(_monitoringApi, queueJob, serverId, workerId);
     }
     catch (Exception ex)
     {
         Logger.Log(LogLevel.Error, $"Error in event subscriber method '{nameof(_eventSubscriber.OnProcessing)}'", ex);
     }
 }
Esempio n. 27
0
 public override int CreateAndEnqueueJob(QueueJob queueJob)
 {
     return(UseTransaction <int>((conn, tran) =>
     {
         var state = new EnqueuedState()
         {
             EnqueuedAt = DateTime.UtcNow, Queue = queueJob.QueueName, Reason = "Job enqueued"
         };
         var jobId = CreateAndEnqueueJob(queueJob, state, conn);
         return jobId;
     }));
 }
Esempio n. 28
0
        public static void ExecuteAndWait(List <QueueJob> queueJobs, TextBox textbox)
        {
            if (Settings.Default.WaitForQueue)
            {
                foreach (QueueJob queuejob in queueJobs)
                {
                    if (queuejob == null)
                    {
                        queueJobs.Remove(queuejob);
                    }
                    try
                    {
                        ProjContext.Load(queuejob);
                    }
                    catch (ClientRequestException cre)
                    {
                        Log.WriteError(new SourceInfo(), textbox, cre.Message);
                    }
                }
                ProjContext.ExecuteQuery();

                //considering one minute timeout for each queuejob.
                int      totalWaitTime = queueJobs.Count;
                DateTime startTime     = DateTime.Now;
                while (queueJobs.Count > 0)
                {
                    //Execute the first job in the list if completed remove it.
                    if (queueJobs[0] == null || ExecuteAndWaitInternal(queueJobs[0], textbox))
                    {
                        queueJobs.RemoveAt(0);
                    }
                    else
                    {
                        //Job needs to be checked again, so move it down below the list.
                        QueueJob currentJob = queueJobs[0];
                        queueJobs.RemoveAt(0);
                        queueJobs.Add(currentJob);
                    }
                    if (DateTime.Now - startTime <= TimeSpan.FromMinutes(totalWaitTime))
                    {
                        continue;
                    }
                    Log.WriteVerbose(new SourceInfo(), textbox,
                                     "Queue jobs did not complete within the timeout period: {0} Minutes.", totalWaitTime);
                    break;
                }
            }
            else
            {
                Log.WriteVerbose(new SourceInfo(), textbox,
                                 "Wait For Queue job is turned off. Not waiting for the queue jobs to complete.");
            }
        }
Esempio n. 29
0
 private static void LogStatus(QueueJob job, TextBox textbox)
 {
     if (job.JobState != JobState.Success)
     {
         Log.WriteWarning(new SourceInfo(), textbox, "Queue job failed. Job State:{0}, Job Type:{1}",
                          job.JobState, job.MessageType);
     }
     else
     {
         Log.WriteVerbose(new SourceInfo(), textbox,
                          "Queue job successfully completed. Job State:{0}, Job Type:{1}", job.JobState, job.MessageType);
     }
 }
Esempio n. 30
0
        private static Box CreateCommonThreadbox()
        {
            commonThreadboxQueue = new Queue <KeyValuePair <object, ThreadBoxHandler> >();
            Box cBox = new Box(1);

            QueueJob <KeyValuePair <object, ThreadBoxHandler> > job = new QueueJob <KeyValuePair <object, ThreadBoxHandler> >();

            job.queue     = commonThreadboxQueue;
            job.handler   = commonThreadboxHandler;
            job.isStop    = true;
            job.sleepTime = 50;
            cBox.Start(job);
            return(cBox);
        }
Esempio n. 31
0
        private static bool ExecuteAndWaitInternal(QueueJob job, TextBox textbox)
        {
            bool queueJobCompleted = false;
            JobState[] jobStateToMarkAsProcessed =
            {
                JobState.Canceled, JobState.CorrelationBlocked, JobState.Failed,
                JobState.FailedNotBlocking, JobState.Success,
            };

            Log.WriteVerbose(new SourceInfo(), textbox,
                "Current Queue job State:{0}, Percent Complete:{1}, Job Type:{2}", job.JobState,
                job.PercentComplete, job.MessageType);

            JobState jobState = ProjContext.WaitForQueue(job, 3);
            if (job.IsNull())
            {
                //Server returned a null object probably the job is completed and CSOM doesnt know about the job anymore.
                queueJobCompleted = true;
            }
            if (jobStateToMarkAsProcessed.Contains(jobState))
            {
                LogStatus(job, textbox);
                queueJobCompleted = true;
            }
            else
            {
                queueJobCompleted = false;
            }
            return queueJobCompleted;
        }
Esempio n. 32
0
 private static void LogStatus(QueueJob job, TextBox textbox)
 {
     if (job.JobState != JobState.Success)
     {
         Log.WriteWarning(new SourceInfo(), textbox, "Queue job failed. Job State:{0}, Job Type:{1}",
             job.JobState, job.MessageType);
     }
     else
     {
         Log.WriteVerbose(new SourceInfo(), textbox,
             "Queue job successfully completed. Job State:{0}, Job Type:{1}", job.JobState, job.MessageType);
     }
 }
Esempio n. 33
0
 public static void ExecuteAndWait(QueueJob queueJob, TextBox textbox)
 {
     ExecuteAndWait(new List<QueueJob> { queueJob }, textbox);
 }