Пример #1
0
        /// <summary>
        /// Runs health checks. Checks are ran in NO PARTICULAR order.
        /// This method can not be called twice
        /// </summary>
        public void Run(NameValueCollection parameters)
        {
            if (m_Status != CheckListStatus.Created)
            {
                throw new HealthCheckListException(StringConsts.CHECK_LIST_ALREADY_RUN_ERROR);
            }

            try
            {
                m_Status   = CheckListStatus.Running;
                m_RunStart = App.LocalizedTime;
                foreach (var check in m_Checks)
                {
                    if (check.CanRun)
                    {
                        check.Run(parameters);
                    }
                    else
                    {
                        check.Result.Skipped = true;
                    }
                }
            }
            finally
            {
                m_Status    = CheckListStatus.Run;
                m_RunFinish = App.LocalizedTime;
            }
        }
Пример #2
0
        public int UpdateStatus(int id, CheckListStatus status)
        {
            var setting = _context.CheckList.First(x => x.Id == id);

            setting.Status = (int)status;

            _context.CheckList.Update(setting);
            _context.SaveChanges();
            return(setting.Id);
        }
Пример #3
0
        public static void SetStatusCheckListStep(int id, CheckListStatus clStatus)
        {
            using (AppDb context = new AppDb())
            {
                CheckListInstanceStep completeStep = context.CheckListInstanceSteps.FirstOrDefault(p => p.Id == id);
                if (completeStep != null)
                {
                    completeStep.Status = (byte?)clStatus;
                    if (completeStep.StepProcessStart == null)
                    {
                        completeStep.StepProcessStart = DateTime.Now;
                    }
                    completeStep.StepProcessEnd = DateTime.Now;

                    if (completeStep.EmailNotification != null)
                    {
                        //TODO:send email notification
                    }
                }

                context.SaveChanges();

                //update checklistinfo progress
                byte status        = (byte)CheckListStatus.Complete;
                int  countComplete =
                    context.CheckListInstanceSteps.Count(
                        p => p.CheckListInstanceInfoId == completeStep.CheckListInstanceInfoId && p.Status == status);

                status = (byte)CheckListStatus.InComplete;
                int countInComplete =
                    context.CheckListInstanceSteps.Count(
                        p =>
                        p.CheckListInstanceInfoId == completeStep.CheckListInstanceInfoId &&
                        (p.Status == status || p.Status == null));
                decimal percentComplete = (Convert.ToDecimal(countComplete) / Convert.ToDecimal(countInComplete + countComplete)) * 100;

                CheckListInstanceInfo clInfo =
                    context.CheckListInstanceInfoes.FirstOrDefault(
                        p => p.Id == completeStep.CheckListInstanceInfoId);
                if (clInfo != null)
                {
                    clInfo.LastActivity = completeStep.StepName;
                    clInfo.Progress     = percentComplete;
                    clInfo.ModifiedDate = DateTime.Now;
                }

                context.SaveChanges();
            }
        }
Пример #4
0
 /// <summary>
 /// Runs health checks. Checks are ran in NO PARTICULAR order.
 /// This method can not be called twice
 /// </summary>
 public void Run(NameValueCollection parameters)
 {
    if (m_Status != CheckListStatus.Created)
     throw new HealthCheckListException(StringConsts.CHECK_LIST_ALREADY_RUN_ERROR); 
    
    try
    {
      m_Status = CheckListStatus.Running;
      m_RunStart = App.LocalizedTime;
      foreach(var check in m_Checks)
       if (check.CanRun)
        check.Run(parameters);
       else
        check.Result.Skipped = true;
    }
    finally
    {
      m_Status = CheckListStatus.Run;
      m_RunFinish = App.LocalizedTime;
    }
 }
        public HttpResponseMessage GetExecutePSCheckListActionOnItem(int checklist_action_xref_id)
        {
            checklist_action_xref data = db.CheckListActionsXref.Find(checklist_action_xref_id);

            if (data == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }


            try
            {
                CommonPowerShell cpshell                 = new CommonPowerShell();
                string           powershell_script       = data.powershell_script;
                StringBuilder    powershell_returnoutput = new StringBuilder();

                int powershell_script_timedout = Convert.ToInt32(data.powershell_script_timedout);

                if (powershell_script_timedout <= 0)
                {
                    powershell_script_timedout = Constants.DEFAULT_PS_TIMEDOUT;
                    powershell_returnoutput.Append("There was no/0 timed out set. New default timed out is set : " + Constants.DEFAULT_PS_TIMEDOUT + " ms.");
                }
                var task = Task.Run(() => cpshell.ExecutePowerShellSynechronously(powershell_script, powershell_script_timedout));
                if (task.Wait(TimeSpan.FromMilliseconds(powershell_script_timedout)))
                {
                    powershell_returnoutput.AppendLine(task.Result);
                }
                else
                {
                    powershell_returnoutput.AppendLine("Timed out error. Current timeout setting for this PS is : " + powershell_script_timedout.ToString() + " ms.");
                }

                // powershell_returnoutput = cpshell.ExecutePowerShellSynechronously(powershell_script, powershell_script_timedout);

                if (powershell_returnoutput.ToString().Contains("[STATUS:"))
                {
                    int    firstposition = powershell_returnoutput.ToString().IndexOf("[STATUS:");
                    int    lastposition  = powershell_returnoutput.ToString().IndexOf("]", firstposition);
                    string getstatus     = powershell_returnoutput.ToString().Substring(firstposition + "[STATUS:".Length, lastposition - (firstposition + "[STATUS:".Length));

                    try
                    {
                        CheckListStatus checkListStatus = (CheckListStatus)Enum.Parse(typeof(CheckListStatus), getstatus);
                        data.status_id = Convert.ToInt16(checkListStatus);
                    }
                    catch {
                        powershell_returnoutput.AppendLine("ERROR : " + getstatus + " is not valid status. Please use valid status to be returned from Powershell script output. Eg. [STATUS:COMPLETED]");
                        data.status_id = Convert.ToInt16(CheckListStatus.NOTSTARTED);
                    }
                }

                data.powershell_script_execution_comments = powershell_returnoutput.ToString();
                data.powershell_script_timedout           = powershell_script_timedout;
                data.comments += "PS executed on : " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "\n";

                db.Entry(data).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, data));
        }