Ejemplo n.º 1
0
Archivo: RNOW.cs Proyecto: sap-sh/t
        private void ProcessSnowResponse(SnowTicket snowTicket, Requester requester, int daysLeft, int emailNotification, int NoAprrovalCancelRequired)
        {
            bool notification = false;
            if (snowTicket != null)
            {
                //update database status

                if (!string.IsNullOrEmpty(snowTicket.change_status))
                {
                    if (snowTicket.change_status.ToLower() == "approved")
                    {
                        string subject = Utility.GetEmailSubjects(8, DateTime.UtcNow, snowTicket.change_request_id);
                        string deploymentEventSescription = Utility.GetDeploymentEventSescriptions(4,  snowTicket.change_request_id);
                        if (Utility.UpdateSnowStatus(snowTicket.change_status, snowTicket.change_request_id, requester.snowId, 0, deploymentEventSescription,requester.RequesterId))
                        {
                            Utility.SendEmail(requester.RequesterEmail, subject, Utility.GetEmailBodyApproved(snowTicket.change_request_id), requester.RequesterDisplayName);
                        }
                    }
                    else if (snowTicket.change_status.ToLower() == "rejected")
                    {
                        CancelTicketAndRespondToUser(requester.RequesterId, snowTicket.change_request_id, Utility.VAL_APPROVER_REJECTED, snowTicket.start_date, requester);
                    }
                    else
                    {
                        if (daysLeft <= 0 && NoAprrovalCancelRequired <=1)
                        {

                            CancelTicketAndRespondToUser(requester.RequesterId, snowTicket.change_request_id, "", snowTicket.start_date, requester, false, snowTicket.Approvals);
                        }
                        else
                        {
                            string deploymentEventSescription = string.Empty;

                            notification = GetNotification(daysLeft, emailNotification);

                            if (notification)
                            {
                                string subject = Utility.GetEmailSubjects(9, DateTime.Now, snowTicket.change_request_id);

                                deploymentEventSescription = Utility.GetDeploymentEventSescriptions(5,snowTicket.change_request_id);

                                Utility.SendEmail(requester.RequesterEmail, subject, Utility.GetEmailBodyApprovalPending(snowTicket.change_request_id, snowTicket.start_date, daysLeft.ToString(), snowTicket.Approvals), requester.RequesterDisplayName);
                            }

                            Utility.UpdateSnowStatus(snowTicket.change_status, snowTicket.change_request_id, requester.snowId, (notification) ? daysLeft : 0, deploymentEventSescription,requester.RequesterId);
                        }

                    }

                }
            }
        }
Ejemplo n.º 2
0
Archivo: RNOW.cs Proyecto: sap-sh/t
        private void ProcessRequestsByID(List<RnowDeploymentSchedule> Schedules, int snowId)
        {
            try
            {
                List<RnowDeploymentSchedule> deploymentSchedulebyId = GeDeploymentSchedulebyId(Schedules, snowId);

                if (deploymentSchedulebyId.Count() > 0)
                {
                    RnowDeploymentSchedule deploymentSchedule = deploymentSchedulebyId.FirstOrDefault();
                    Requester requester = new Requester() { RequesterId = Convert.ToString(deploymentSchedule.UserId), RequesterDisplayName = deploymentSchedule.UserDisplayName, RequesterEmail = deploymentSchedule.Email, snowId = deploymentSchedule.SnowId };
                    List<long> HostIds = GetHostIds(deploymentSchedulebyId);

                    if (deploymentSchedule.SnowStaus == "Requested")
                    {
                        //New Request
                        // List<long> HostIds = GetHostIds(deploymentSchedulebyId);
                        List<string> BuildingIds = GetBuildingIds(deploymentSchedulebyId);
                        List<DeploymentTask> deploymentTask = GetDeploymentTask(deploymentSchedulebyId);
                        string description = GetSnowDescription(deploymentTask);

                        SNOWTicketCreation(Convert.ToString(deploymentSchedule.UserId), deploymentSchedule.StartTime, deploymentSchedule.EndTime, HostIds, BuildingIds, deploymentTask, requester,description, deploymentSchedule.RequestID);
                    }
                    else if (deploymentSchedule.SnowStaus == "Cancel Requested")
                    {
                        CancelModifiedRequestByUser(requester.RequesterId, deploymentSchedule.RequestID, requester);
                    }
                    else
                    {
                        if (IsRequiredtoCheckStatus(deploymentSchedule))
                        {
                            SnowTicket snowTicket = GetTicketDetails(deploymentSchedule.RequestID, requester.RequesterId);

                            if (snowTicket.HostIds != null)
                            {
                                if (snowTicket.HostIds.Count > 0)
                                {
                                    List<long> removeCIsFromSnow = snowTicket.HostIds.Except(HostIds).ToList();
                                    if (removeCIsFromSnow.Count() > 0)
                                    {
                                        RemoveCIsFromSnow(removeCIsFromSnow, deploymentSchedulebyId, snowTicket.HostName);
                                    }

                                    List<long> removeCIsFromWDT = HostIds.Except(snowTicket.HostIds).ToList();
                                    if (removeCIsFromWDT.Count() > 0)
                                    {
                                        RemoveCIsFromWDT(removeCIsFromWDT, deploymentSchedulebyId);
                                    }
                                }
                            }

                            ProcessSnowResponse(snowTicket, requester, deploymentSchedule.DaysLeft, deploymentSchedule.EmailNotification, deploymentSchedule.NoAprrovalCancelRequired);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.HandleAndLogExceptions(ex);
            }
        }
Ejemplo n.º 3
0
Archivo: RNOW.cs Proyecto: sap-sh/t
        /// <summary>
        /// 
        /// </summary>
        private void CancelTicketAndRespondToUser(string userId, string ticketId, string reason, string startDate, Requester requester, bool IsCancelledByError = true, List<Approver> approvals = null)
        {
            SnowTicket CancelTicketResult = CancelTicket(userId, ticketId, reason);

            if (CancelTicketResult.IsSuccess && CancelTicketResult.change_detail != null && CancelTicketResult.faultcode == null)
            {
                if (CancelTicketResult.change_detail == Utility.VAL_REQUEST_CANCEL_SUCCESS)
                {
                    string subject = Utility.GetEmailSubjects(5, DateTime.UtcNow, ticketId);

                    if (Utility.UpdateSnowStatus(Utility.VAL_CHANGE_STATE_CANCEL, ticketId, requester.snowId, 0,"", requester.RequesterId))
                    {
                        if (IsCancelledByError)
                        {
                            if (!string.IsNullOrEmpty(reason))
                            {
                                Utility.SendEmail(requester.RequesterEmail, subject, Utility.GetEmailstartDateCancelledByError(startDate, reason),requester.RequesterDisplayName);
                            }
                        }
                        else {
                            Utility.SendEmail(requester.RequesterEmail, subject, Utility.GetEmailBodyCancelled(ticketId, startDate, approvals), requester.RequesterDisplayName);
                        }
                    }
                }
            }
            else
            {
                if (CancelTicketResult.change_status != Utility.VAL_CHANGE_STATE_CANCEL)
                {
                    string subject = Utility.GetEmailSubjects(6, DateTime.UtcNow, ticketId);

                    Utility.SendEmail(requester.RequesterEmail, subject, Utility.GetEmailstartDateCancelledByError(startDate, CancelTicketResult.faultstring),requester.RequesterDisplayName );
                }
            }
        }
Ejemplo n.º 4
0
Archivo: RNOW.cs Proyecto: sap-sh/t
        private void CancelModifiedRequestByUser(string userId, string ticketId, Requester requester)
        {
            try
            {
                if (!string.IsNullOrEmpty(ticketId))
                {
                    SnowTicket CancelTicketResult = CancelTicket(userId, ticketId, Utility.VAL_CANCEL_REASON);

                    if (CancelTicketResult.IsSuccess && CancelTicketResult.change_detail != null && CancelTicketResult.faultcode == null)
                    {
                        if (CancelTicketResult.change_detail == Utility.VAL_REQUEST_CANCEL_SUCCESS)
                        {
                            string deploymentEventSescription = Utility.GetDeploymentEventSescriptions(3, ticketId);
                            Utility.UpdateSnowStatus(Utility.VAL_CHANGE_STATE_CANCEL, ticketId, requester.snowId, 0, deploymentEventSescription,requester.RequesterId);
                        }
                    }
                    else
                    {
                        Utility.HandleAndLogExceptions(new Exception(CancelTicketResult.faultstring), ticketId);
                    }
                }
                else
                {
                    string deploymentEventSescription = Utility.GetDeploymentEventSescriptions(3, Convert.ToString(requester.snowId));
                    Utility.UpdateSnowStatus(Utility.VAL_CHANGE_STATE_CANCEL, "", requester.snowId, 0, deploymentEventSescription,requester.RequesterId);
                }
            }
            catch (Exception ex)
            {
                Utility.HandleAndLogExceptions(ex, ticketId);
            }
        }
Ejemplo n.º 5
0
Archivo: RNOW.cs Proyecto: sap-sh/t
        private bool AddDeployemntTasks(string userId, string ticketId, List<DeploymentTask> deploymentTasks, Requester requester)
        {
            int SuccessCount = 0;

            List<string> Errors = new List<string>();

            foreach (DeploymentTask deploymentTask in deploymentTasks)
            {
                SnowTicket CreateDeploymentTaskResult = CreateDeploymentTask(userId, ticketId, deploymentTask.plannedStartDate, deploymentTask.plannedEndDate,
                                                                                deploymentTask.assignmentGroup, deploymentTask.assignedTo, deploymentTask.DeploymenthostIds,deploymentTask.taskName);

                if (CreateDeploymentTaskResult.IsSuccess && CreateDeploymentTaskResult.deployment_task_id != null && CreateDeploymentTaskResult.faultcode == null)
                {
                    SuccessCount++;
                }
                else {
                    Errors.Add(deploymentTask.taskName + "<br/>" +    CreateDeploymentTaskResult.faultstring);
                }
            }

            if (Errors.Count() > 0)
            {
                string subject = Utility.GetEmailSubjects(4, DateTime.UtcNow, ticketId);
                Utility.SendEmail(requester.RequesterEmail, subject, Utility.GetEmailBodyProbleminAddingTasks(ticketId, Errors),requester.RequesterDisplayName);
            }

            return (SuccessCount > 0);
        }
Ejemplo n.º 6
0
Archivo: RNOW.cs Proyecto: sap-sh/t
        /// <summary>
        /// Complete work flow to create snow request 
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="hostIds"></param>
        /// <param name="buildingIds"></param>
        /// <param name="deploymentTask"></param>
        /// <param name="requester"></param>
        /// <param name="oldRequestID"></param>
        public void SNOWTicketCreation(string userId, DateTime startDate, DateTime endDate,
                                       List<long> hostIds, List<string> buildingIds,
                                       List<DeploymentTask> deploymentTask, Requester requester, string description,  string oldRequestID = "", 
                                       int retry = 0
                      )
        {
            //bool IsSuccess = false;
            string ErrorMessage = "";
            string TicketId = "";
            //string Deployment_task_id = "";

            try
            {
                //Creating ticket
                string shordescription = Utility.VAL_SHORT_DESCRIPTION;

                if (deploymentTask.Count > 0)
                {
                     shordescription = deploymentTask.FirstOrDefault().taskName;
                }

                SnowTicket CreateTicketResult = CreateTicket(userId, startDate, endDate, hostIds, buildingIds, description, shordescription);

                if (CreateTicketResult.IsSuccess && CreateTicketResult.change_request_id != null && CreateTicketResult.faultcode == null)
                {
                    TicketId = CreateTicketResult.change_request_id;

                    if (!string.IsNullOrEmpty(TicketId))
                    {
                        if (AddDeployemntTasks(userId, TicketId, deploymentTask, requester))
                        {
                            SnowTicket submitTicketResult = submitTicket(userId, TicketId);

                            if (submitTicketResult.IsSuccess && submitTicketResult.change_detail != null && submitTicketResult.faultcode == null)
                            {
                                if (submitTicketResult.change_detail == Utility.VAL_REQUEST_SUBMIT_SUCCESS || submitTicketResult.change_detail == Utility.VAL_REQUEST_CANCEL_SUCCESS)
                                {
                                    //Process completed and sending success mail to Requester
                                    //update database
                                    string deploymentEventSescription = GetDeploymentEventSescription(TicketId, oldRequestID);
                                    if (Utility.UpdateSnowStatus(Utility.VAL_CHANGE_STATE_SUBMIT, TicketId, requester.snowId, 0, deploymentEventSescription, requester.RequesterId))
                                    {
                                        string subject = Utility.GetEmailSubjects(1, startDate);
                                        Utility.SendEmail(requester.RequesterEmail, subject, Utility.GetEmailBodySubmit(TicketId, oldRequestID), requester.RequesterDisplayName);
                                    }
                                }
                                else
                                {
                                    if (retry >= 1)
                                    {
                                        string subject = Utility.GetEmailSubjects(2, startDate);
                                        Utility.SendEmail(requester.RequesterEmail, subject, Utility.GetEmailBodyError(Convert.ToString(requester.snowId)), requester.RequesterDisplayName);
                                    }
                                    else
                                    {
                                        SNOWTicketCreation(userId, startDate, endDate, hostIds, buildingIds, deploymentTask, requester, description, oldRequestID, 1);
                                    }
                                }
                            }
                            else if (submitTicketResult.faultcode != null && submitTicketResult.faultcode == "SN354")
                            {
                                //Conflict occurred
                                SnowTicket AcceptConflictResult = AcceptConflict(userId, TicketId);
                                if (AcceptConflictResult.IsSuccess && AcceptConflictResult.change_detail != null && AcceptConflictResult.faultcode == null)
                                {
                                    if (AcceptConflictResult.change_detail == Utility.VAL_REQUEST_CONFLICT_SUCCESS)
                                    {
                                        //Process completed and sending success mail to Requester
                                        string deploymentEventSescription = GetDeploymentEventSescription(TicketId, oldRequestID);
                                        if (Utility.UpdateSnowStatus(Utility.VAL_CHANGE_STATE_SUBMIT, TicketId, requester.snowId, 0, deploymentEventSescription,requester.RequesterId))
                                        {
                                            string subject = Utility.GetEmailSubjects(1, startDate);
                                            Utility.SendEmail(requester.RequesterEmail, subject, Utility.GetEmailBodySubmit(TicketId, oldRequestID), requester.RequesterDisplayName);
                                        }
                                    }
                                }
                                else
                                {
                                    CancelTicketAndRespondToUser(userId, TicketId, AcceptConflictResult.faultstring, startDate.ToString(Utility.VAL_DATETIME_FORMAT_STRING), requester);
                                }
                            }
                            else
                            {
                                CancelTicketAndRespondToUser(userId, TicketId, submitTicketResult.faultstring, startDate.ToString(Utility.VAL_DATETIME_FORMAT_STRING), requester);
                            }
                        }

                        else
                        {
                            CancelTicketAndRespondToUser(userId, TicketId, CreateTicketResult.faultstring, startDate.ToString(Utility.VAL_DATETIME_FORMAT_STRING), requester);
                        }
                    }
                }
                else
                {
                    ErrorMessage = CreateTicketResult.Error_Message;
                    string subject = Utility.GetEmailSubjects(3, startDate);

                    if (Utility.UpdateSnowStatus("Error", TicketId, requester.snowId, 0, Utility.VAL_REQUEST_FAILED_EVENTSMSG,requester.RequesterId))
                    {
                        Utility.SendEmail(requester.RequesterEmail, subject, Utility.GetEmailBodyErrorTicketCreation(ErrorMessage), requester.RequesterDisplayName);
                    }
                }

            }
            catch (Exception ex)
            {
                Utility.HandleAndLogExceptions(ex, TicketId);
            }
        }