Ejemplo n.º 1
0
        public dynamic CalendarList(int memberID)
        {
            var memberAct = GetMemberData(memberID, "f會員參加的活動編號");

            if (!string.IsNullOrEmpty(memberAct))
            {
                string[]         memberEvents         = memberAct.Split(',');
                CalendarEvents[] nowMemberTotalEvents = new CalendarEvents[memberEvents.Length - 1];
                int i = 0;
                foreach (var item in memberEvents)
                {
                    if (string.IsNullOrEmpty(item))
                    {
                        continue;
                    }
                    var            nowMemberAct  = db.tActivity.Where(t => t.f活動編號.ToString() == item).FirstOrDefault();
                    CalendarEvents calendarEvent = new CalendarEvents();
                    calendarEvent.title = nowMemberAct.f活動標題;

                    calendarEvent.start = nowMemberAct.f活動開始時間;
                    calendarEvent.end   =
                        nowMemberAct.f活動開始時間 == nowMemberAct.f活動結束時間 ? nowMemberAct.f活動結束時間 : nowMemberAct.f活動結束時間 + " 23:59:59";
                    calendarEvent.classNames = "CalendarEvent" + " " + "EventActID" + nowMemberAct.f活動編號;
                    nowMemberTotalEvents[i]  = calendarEvent;
                    i++;
                }
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                var obj = serializer.Serialize(nowMemberTotalEvents);
                return(obj);  //序列化後已是Json字串,傳到前端用JSON.parse即可轉成js物件
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 2
0
 // Termine la saison en cours seulement si CurrentDate est égal à la valeur maximale des clés du dictionnaire
 public static void FinishSeason()
 {
     if (CurrentDate == CalendarEvents.Keys.Max())
     {
         CalendarEvents.Clear();
         CurrentDate = 0;
         SeasonNumber++;
     }
 }
        public dynamic CalendarEvents()
        {
            var events = Repository.GetCalendarEvents().Select(e => new CalendarEvent(e)).ToArray();
            var model  = new CalendarEvents()
            {
                Events = events
            };

            return(GetView(model));
        }
Ejemplo n.º 4
0
 public IActionResult GetAllEvents(string calendarId)
 {
     try
     {
         CalendarEvents events = service.GetAllEvents(calendarId);
         return(events != null ? (IActionResult)Ok(events) : (IActionResult)BadRequest());
     }
     catch (Google.GoogleApiException e)
     {
         return(e.HttpStatusCode.Equals(HttpStatusCode.NotFound) ? (IActionResult)NotFound(e.Message) : e.HttpStatusCode.Equals(HttpStatusCode.InternalServerError) ? StatusCode(500, e.Message) : (IActionResult)BadRequest(e.Message));
     }
 }
Ejemplo n.º 5
0
        // Retourne la liste des évènements correspondants à la date passée en paramêtre
        public static List <ICalendarEvent> GetNextDate()
        {
            List <ICalendarEvent> result = null;

            CalendarEvents.TryGetValue(CurrentDate, out result);
            if (result != null)
            {
                foreach (var calendarEvent in result)
                {
                    calendarEvent.LaunchEvent();
                }
            }
            CurrentDate++;
            return(result);
        }
        private string GetEventName(CalendarEvents calEvent)
        {
            switch (calEvent)
            {
            case CalendarEvents.Birthday:
                return("Birthday");

            case CalendarEvents.WeddingAnniversary:
                return("Wedding Anniversary");

            case CalendarEvents.JoinedZionAnniversary:
                return("Joined Zion Anniversary");

            default:
                throw new ArgumentOutOfRangeException(nameof(calEvent), calEvent, null);
            }
        }
Ejemplo n.º 7
0
        // Ajoute un évènement à la liste correspondant à la date passée en paramêtre dans le dictionnaire
        public static void AddEvent(ICalendarEvent calendarEvent, int date)
        {
            List <ICalendarEvent> result = null;

            CalendarEvents.TryGetValue(date, out result);
            // Si la date n'existe pas dans le dictionnaire, on ajoute la clé correspondante avec l'événement
            if (result == null)
            {
                List <ICalendarEvent> calendarEventsNewList = new List <ICalendarEvent>();
                calendarEventsNewList.Add(calendarEvent);
                CalendarEvents.Add(date, calendarEventsNewList);
            }
            // Sinon, on ajoute l'évènement à la liste correspondant à la date dans le dictionnaire
            else
            {
                result.Add(calendarEvent);
            }
        }
        private DateTime GetEventDate(CalendarEvents calEvent, CCGMember member)
        {
            DateTime eventDate = DateTime.Today;

            switch (calEvent)
            {
            case CalendarEvents.Birthday:
            {
                if (member.BirthDate != null)
                {
                    eventDate = member.BirthDate.Value;
                }
                break;
            }

            case CalendarEvents.WeddingAnniversary:
            {
                if (member.AnniversaryDate != null)
                {
                    eventDate = member.AnniversaryDate.Value;
                }
                break;
            }

            case CalendarEvents.JoinedZionAnniversary:
            {
                if (member.DateJoinedZion != null)
                {
                    eventDate = member.DateJoinedZion.Value;
                }
                break;
            }

            default:
            {
                return(new DateTime());
            }
            }

            // Updates year to current year for the event date.
            // Eg., 5-25-1961 ==> 5-25-2017 (current year)
            return(new DateTime(_startDate.Year, eventDate.Month, eventDate.Day));
        }
Ejemplo n.º 9
0
        public dynamic getCalendar()
        {
            if (Session["member"] != null)
            {
                var LoginMember   = (tMember)Session["member"];
                var nowRealMember = db.tMember.Where(t => t.f會員編號 == LoginMember.f會員編號).FirstOrDefault();
                if (!string.IsNullOrEmpty(nowRealMember.f會員參加的活動編號))
                {
                    string[]         nowMemberEvents      = nowRealMember.f會員參加的活動編號.Split(',');
                    CalendarEvents[] NowMemberTotalEvents = new CalendarEvents[nowMemberEvents.Length - 1];
                    int i = 0;
                    foreach (var item in nowMemberEvents)
                    {
                        if (string.IsNullOrEmpty(item))
                        {
                            continue;
                        }
                        var            NowMemberAct  = db.tActivity.Where(t => t.f活動編號.ToString() == item).FirstOrDefault();
                        CalendarEvents CalendarEvent = new CalendarEvents();
                        CalendarEvent.title = NowMemberAct.f活動標題;

                        CalendarEvent.start = NowMemberAct.f活動開始時間;
                        CalendarEvent.end   =
                            NowMemberAct.f活動開始時間 == NowMemberAct.f活動結束時間 ?  NowMemberAct.f活動結束時間 : NowMemberAct.f活動結束時間 + " 23:59:59";
                        CalendarEvent.classNames = "CalendarEvent" + " " + "EventActID" + NowMemberAct.f活動編號;
                        NowMemberTotalEvents[i]  = CalendarEvent;
                        i++;
                    }
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    var obj = serializer.Serialize(NowMemberTotalEvents);
                    return(obj);  //序列化後已是Json字串,傳到前端用JSON.parse即可轉成js物件
                }
                else
                {
                    return("");
                }
            }
            else
            {
                return("1");
            }
        }
        private CalendarEvent SetCalendarEventProps(CCGMember member, CalendarEvents calEvent)
        {
            _counter++;
            var eventDate = GetEventDate(calEvent, member);
            var eventName = GetEventName(calEvent);

            return(new CalendarEvent
            {
                Id = _counter,
                Title = $"{eventName} - {member.LastName}",
                Description = $"{member.FirstName} {member.LastName}'s {eventName}",
                FirstName = member.FirstName,
                LastName = member.LastName,
                EventDate = eventDate,
                DateString = eventDate.ToLongDateString(),
                Url = $"/CcgMembers/Details/{member.Id}",
                PhoneNumber = member.PhoneNumber,
                CellPhoneNumber = member.CellPhoneNumber,
                EmailAddress = member.EmailAddress,
            });
        }
Ejemplo n.º 11
0
            protected async override Task <IEnumerable <Event> > Handle(Query request)
            {
                IEnumerable <string> calendarIds = _context.SalesPipelines
                                                   .Where(s => s.Stage == SaleStage.Proposal)
                                                   .Select(s => s.CalendarId).ToList();

                var events = new List <Event>();

                foreach (var calendarId in calendarIds)
                {
                    try
                    {
                        CalendarEvents calendarEvents = await _calendarApi.GetEvents(calendarId, request.AccessToken);

                        events.AddRange(calendarEvents.Items);
                    }
                    catch (Refit.ApiException)
                    {
                        continue;
                    }
                }

                return(events);
            }
Ejemplo n.º 12
0
        private void CalendarEvents_WeekdayPeriodChangeEvent(object sender, CalendarEvents.WeekdayPeriodEventArgs e)
        {
            this.weekday = e.Weekday;
            this.periods = e.Periods;

            this.RedrawGrid();
            this.UpdateContent();
        }
        /// <summary>
        /// Register runtime events
        /// </summary>
        /// <param name="serviceCollection"></param>
        /// <returns></returns>
        public static CalendarServiceCollection AddCalendarRuntimeEvents(this CalendarServiceCollection serviceCollection)
        {
            CalendarEvents.RegisterEvents();
            const string calendarLink = "<a href='/calendar'>here</a>";

            CalendarEvents.SystemCalendarEvents.OnEventCreated += async(sender, args) =>
            {
                var subject  = "Changes in the event " + args.Title;
                var message  = $"An event is created for which you are invited, more details {calendarLink}";
                var notifier = IoC.Resolve <INotify <GearRole> >();
                if (notifier == null)
                {
                    return;
                }
                var users = args.Invited?.Select(x => x.ToGuid()).ToList() ?? new List <Guid>();
                if (users.Any())
                {
                    await notifier.SendNotificationAsync(users, NotificationType.Info, subject, message);
                }
            };

            CalendarEvents.SystemCalendarEvents.OnEventUpdated += async(sender, args) =>
            {
                var subject  = "Changes in the event " + args.Title;
                var message  = $"Event {args.Title} has been modified, more details {calendarLink}";
                var notifier = IoC.Resolve <INotify <GearRole> >();
                var users    = args.Invited?.Select(x => x.ToGuid()).ToList() ?? new List <Guid>();
                if (users.Any())
                {
                    await notifier.SendNotificationAsync(users, NotificationType.Info, subject, message);
                }
            };

            CalendarEvents.SystemCalendarEvents.OnEventDeleted += async(sender, args) =>
            {
                var subject  = "Changes in the event " + args.Title;
                var message  = $"Event {args.Title} was canceled";
                var notifier = IoC.Resolve <INotify <GearRole> >();
                var users    = args.Invited?.Select(x => x.ToGuid()).ToList() ?? new List <Guid>();
                if (users.Any())
                {
                    await notifier.SendNotificationAsync(users, NotificationType.Info, subject, message);
                }
            };

            CalendarEvents.SystemCalendarEvents.OnUserChangeAcceptance += async(sender, args) =>
            {
                var userManager = IoC.Resolve <UserManager <GearUser> >();
                if (userManager == null)
                {
                    return;
                }
                var subject = "Changes in the event " + args.Title;
                var user    = await userManager.FindByIdAsync(args.Member.UserId.ToString());

                var message  = $"User {user.Email} responded with {args.AcceptanceState} to event {args.Title}";
                var notifier = IoC.Resolve <INotify <GearRole> >();
                await notifier.SendNotificationAsync(new List <Guid> {
                    args.Organizer
                }, NotificationType.Info, subject, message);
            };

            return(serviceCollection);
        }
 public CalendarEvent CreateCalendarEvent(CalendarEvents calendarEvent)
 {
     return SiteCalendarDataModel.InsertCalendarEvent(calendarEvent);
 }
 public void UpdateCalendarEventTime(CalendarEvents calendarEvent)
 {
     SiteCalendarDataModel.UpdateDataBaseCalendarEventTime(calendarEvent);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 週次改變事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CalendarEvents_WeekChangeEvent(object sender, CalendarEvents.WeekChangeEventArgs e)
 {
     if (e.Type.Equals(this.CalendarType) &&
         e.AssocID.Equals(this.AssocID))
     {
         UpdateContent();
     }
 }
Ejemplo n.º 17
0
        public List<CalendarEvents> LoadAllEventsInDateRange(DateTime start, DateTime end)
        {
            var fromDate = start;
             var toDate = end;

             using (Entities ent = new Entities())
             {
                 var rslt = ent.EventCalendars.Where(s => s.DateTimeScheduled >= fromDate
                     && s.EndDay <= toDate
                     && s.IsActive == true);

                 List<CalendarEvents> result = new List<CalendarEvents>();
                 foreach (var item in rslt)
                 {
                     CalendarEvents rec = new CalendarEvents();
                     rec.ID = item.ID;
                     rec.UserId = item.UserID;
                     string StringDate = string.Format("{0:yyyy-MM-dd}", item.DateTimeScheduled);
                     rec.StartDateString = item.DateTimeScheduled.ToString("yyyy-MM-dd");
                     rec.EndDateString = item.EndDay.ToString("yyyy-MM-dd");
                     int enColor = EventExpired(rec.ID, rec.EndDateString, item.StatusENUM);
                     rec.Title = item.Title;
                     rec.StatusString = Enums.GetName<EventStatus>((EventStatus)enColor);
                     rec.StatusColor = Enums.GetEnumDescription<EventStatus>(rec.StatusString);
                     string ColorCode = rec.StatusColor.Substring(0, rec.StatusColor.IndexOf(":"));
                     rec.ClassName = rec.StatusColor.Substring(rec.StatusColor.IndexOf(":") + 1, rec.StatusColor.Length - ColorCode.Length - 1);
                     rec.StatusColor = ColorCode;
                     rec.Address = item.Address;
                     rec.Descriptions = item.Description;
                     result.Add(rec);
                 }

                 return result;
             }
        }
Ejemplo n.º 18
0
 public Calendar()
 {
     this.Width   = 7;
     this._events = new CalendarEvents();
 }
Ejemplo n.º 19
0
 public EventsDetailsViewModel(CalendarEvents _calendarEvents)
 {
     calendarEvents = _calendarEvents;
 }
Ejemplo n.º 20
0
        public override void Run()
        {
            try
            {
                SlaTickets slaTickets = new SlaTickets(LoginUser);
                slaTickets.LoadPending();

                if (slaTickets != null && slaTickets.Count > 0)
                {
                    Logs.WriteEvent(string.Format("{0} pending tickets to calculate the SLA values for.", slaTickets.Count));
                }

                foreach (SlaTicket slaTicket in slaTickets)
                {
                    if (IsStopped)
                    {
                        break;
                    }
                    UpdateHealth();

                    try
                    {
                        Ticket ticket = Tickets.GetTicket(LoginUser, slaTicket.TicketId);

                        if (ticket != null)
                        {
                            bool     isStatusPaused                 = ticket.IsSlaStatusPaused();
                            bool     isClosed                       = ticket.DateClosed != null;
                            DateTime?newSlaViolationTimeClosed      = null;
                            DateTime?newSlaWarningTimeClosed        = null;
                            DateTime?newSlaViolationLastAction      = null;
                            DateTime?newSlaWarningLastAction        = null;
                            DateTime?newSlaViolationInitialResponse = null;
                            DateTime?newSlaWarningInitialResponse   = null;

                            if (!isClosed && !isStatusPaused)
                            {
                                DateTime?lastActionDateCreated = Actions.GetLastActionDateCreated(LoginUser, ticket.TicketID);
                                int      totalActions          = Actions.TotalActionsForSla(LoginUser, ticket.TicketID, ticket.OrganizationID);

                                Organization organization = Organizations.GetOrganization(LoginUser, ticket.OrganizationID);
                                SlaTrigger   slaTrigger   = SlaTriggers.GetSlaTrigger(LoginUser, slaTicket.SlaTriggerId);

                                if (slaTrigger == null)
                                {
                                    Logs.WriteEventFormat("Trigger {0} not found.", slaTicket.SlaTriggerId);
                                }

                                SlaTickets.BusinessHours businessHours = new SlaTickets.BusinessHours()
                                {
                                    DayStartUtc  = organization.BusinessDayStartUtc,
                                    DayEndUtc    = organization.BusinessDayEndUtc,
                                    BusinessDays = organization.BusinessDays
                                };

                                //Check if we should use SLA's business hours instead of Account's
                                if (!slaTrigger.UseBusinessHours &&
                                    !slaTrigger.NoBusinessHours &&
                                    slaTrigger.DayStartUtc.HasValue &&
                                    slaTrigger.DayEndUtc.HasValue)
                                {
                                    businessHours.DayStartUtc  = slaTrigger.DayStartUtc.Value;
                                    businessHours.DayEndUtc    = slaTrigger.DayEndUtc.Value;
                                    businessHours.BusinessDays = slaTrigger.Weekdays;
                                }
                                else if (!slaTrigger.UseBusinessHours && !slaTrigger.NoBusinessHours)
                                {
                                    Logs.WriteEventFormat("Using Account's business hours {0} to {1} because while the trigger is set to use sla's business hours one of them has no value. Sla DayStartUtc {2}, Sla DayEndUtc {3}",
                                                          organization.BusinessDayStartUtc.ToShortTimeString(),
                                                          organization.BusinessDayEndUtc.ToShortTimeString(),
                                                          slaTrigger.DayStartUtc.HasValue ? slaTrigger.DayStartUtc.Value.ToShortTimeString() : "NULL",
                                                          slaTrigger.DayEndUtc.HasValue ? slaTrigger.DayEndUtc.Value.ToShortTimeString() : "NULL");
                                }

                                Logs.WriteEvent(string.Format("Ticket #{0} id {1}. LastAction: {2}, TotalActions: {3}, Org({4}) {5}, SlaTriggerId {6}.", ticket.TicketNumber,
                                                              ticket.TicketID,
                                                              lastActionDateCreated == null ? "none" : lastActionDateCreated.Value.ToString(),
                                                              totalActions,
                                                              organization.OrganizationID,
                                                              organization.Name,
                                                              slaTrigger.SlaTriggerID));
                                List <DateTime> daysToPause    = SlaTriggers.GetSpecificDaysToPause(slaTrigger.SlaTriggerID);
                                bool            pauseOnHoliday = slaTrigger.PauseOnHoliday;
                                CalendarEvents  holidays       = new CalendarEvents(LoginUser);

                                if (pauseOnHoliday)
                                {
                                    holidays.LoadHolidays(organization.OrganizationID);
                                }

                                Dictionary <int, double> businessPausedTimes = new Dictionary <int, double>();

                                //We need to have two calculations for the paused time, one for the Time To Close and Initial Response which should count the paused time since the Ticket creation
                                //and another one for Last Action where it should only count starting from the last action added
                                TimeSpan totalPausedTimeSpan = SlaTickets.CalculatePausedTime(ticket.TicketID, organization, businessHours, slaTrigger, daysToPause, holidays, LoginUser, businessPausedTimes, Logs);
                                Logs.WriteEventFormat("Total Paused Time: {0}", totalPausedTimeSpan.ToString());

                                UpdateBusinessPausedTimes(LoginUser, businessPausedTimes);

                                newSlaViolationTimeClosed = SlaTickets.CalculateSLA(ticket.DateCreatedUtc, businessHours, slaTrigger, slaTrigger.TimeToClose, totalPausedTimeSpan, daysToPause, holidays);

                                if (newSlaViolationTimeClosed != null)
                                {
                                    newSlaWarningTimeClosed = SlaTickets.CalculateSLAWarning(newSlaViolationTimeClosed.Value,
                                                                                             businessHours,
                                                                                             slaTrigger.NoBusinessHours,
                                                                                             slaTrigger.TimeToClose,
                                                                                             slaTrigger.WarningTime,
                                                                                             daysToPause,
                                                                                             holidays);
                                }

                                TimeSpan pausedTimeSpanSinceLastAction = SlaTickets.CalculatePausedTime(ticket.TicketID,
                                                                                                        organization, businessHours,
                                                                                                        slaTrigger,
                                                                                                        daysToPause,
                                                                                                        holidays,
                                                                                                        LoginUser,
                                                                                                        businessPausedTimes,
                                                                                                        Logs,
                                                                                                        false,
                                                                                                        lastActionDateCreated.HasValue ? lastActionDateCreated.Value : (DateTime?)null);
                                Logs.WriteEventFormat("Total Paused Time: {0}", pausedTimeSpanSinceLastAction.ToString());

                                if (lastActionDateCreated == null)
                                {
                                    newSlaViolationLastAction = null;
                                    newSlaWarningLastAction   = null;
                                }
                                else
                                {
                                    newSlaViolationLastAction = SlaTickets.CalculateSLA(lastActionDateCreated.Value,
                                                                                        businessHours,
                                                                                        slaTrigger,
                                                                                        slaTrigger.TimeLastAction,
                                                                                        pausedTimeSpanSinceLastAction,
                                                                                        daysToPause,
                                                                                        holidays);

                                    if (newSlaViolationLastAction != null)
                                    {
                                        newSlaWarningLastAction = SlaTickets.CalculateSLAWarning((DateTime)newSlaViolationLastAction.Value,
                                                                                                 businessHours,
                                                                                                 slaTrigger.NoBusinessHours,
                                                                                                 slaTrigger.TimeLastAction,
                                                                                                 slaTrigger.WarningTime,
                                                                                                 daysToPause,
                                                                                                 holidays);
                                    }
                                }

                                if (slaTrigger.TimeInitialResponse < 1 || totalActions > 0)
                                {
                                    newSlaViolationInitialResponse = null;
                                    newSlaWarningInitialResponse   = null;
                                }
                                else
                                {
                                    newSlaViolationInitialResponse = SlaTickets.CalculateSLA(ticket.DateCreatedUtc,
                                                                                             businessHours,
                                                                                             slaTrigger,
                                                                                             slaTrigger.TimeInitialResponse,
                                                                                             totalPausedTimeSpan,
                                                                                             daysToPause,
                                                                                             holidays);

                                    if (newSlaViolationInitialResponse != null)
                                    {
                                        newSlaWarningInitialResponse = SlaTickets.CalculateSLAWarning((DateTime)newSlaViolationInitialResponse.Value,
                                                                                                      businessHours,
                                                                                                      slaTrigger.NoBusinessHours,
                                                                                                      slaTrigger.TimeInitialResponse,
                                                                                                      slaTrigger.WarningTime,
                                                                                                      daysToPause,
                                                                                                      holidays);
                                    }
                                }
                            }
                            else
                            {
                                Logs.WriteEventFormat("Ticket is {0}, clearing its SLA values.", isClosed ? "Closed" : "Status Paused");
                            }

                            if (HasAnySlaChanges(ticket,
                                                 newSlaViolationTimeClosed,
                                                 newSlaWarningTimeClosed,
                                                 newSlaViolationLastAction,
                                                 newSlaWarningLastAction,
                                                 newSlaViolationInitialResponse,
                                                 newSlaWarningInitialResponse))
                            {
                                ticket.SlaViolationTimeClosed      = newSlaViolationTimeClosed;
                                ticket.SlaWarningTimeClosed        = newSlaWarningTimeClosed;
                                ticket.SlaViolationLastAction      = newSlaViolationLastAction;
                                ticket.SlaWarningLastAction        = newSlaWarningLastAction;
                                ticket.SlaViolationInitialResponse = newSlaViolationInitialResponse;
                                ticket.SlaWarningInitialResponse   = newSlaWarningInitialResponse;
                                Tickets.UpdateTicketSla(LoginUser,
                                                        ticket.TicketID,
                                                        newSlaViolationInitialResponse,
                                                        newSlaViolationLastAction,
                                                        newSlaViolationTimeClosed,
                                                        newSlaWarningInitialResponse,
                                                        newSlaWarningLastAction,
                                                        newSlaWarningTimeClosed);
                                Logs.WriteEvent("Ticket SLA calculation completed.");

                                string signalRUrl = Settings.ReadString("SignalRUrl");

                                if (!string.IsNullOrEmpty(signalRUrl))
                                {
                                    //Dictionary<string, string> queryStringData = new Dictionary<string, string>();
                                    //queryStringData.Add("userID", "-1");
                                    //queryStringData.Add("organizationID", ticket.OrganizationID.ToString());
                                    //HubConnection connection = new HubConnection(signalRUrl, queryStringData);
                                    //IHubProxy signalRConnection = connection.CreateHubProxy("TicketSocket");

                                    //try
                                    //{
                                    //    connection.Start().Wait();
                                    //    signalRConnection.Invoke("RefreshSLA", ticket.TicketNumber);
                                    //}
                                    //catch (Exception ex)
                                    //{
                                    //    Logs.WriteEvent("Could not send signalR to refresh the SLA. Message: " + ex.Message);
                                    //}
                                }
                            }
                            else
                            {
                                Logs.WriteEvent("Ticket SLA calculation completed. SLA values did not change, ticket was not updated.");
                            }

                            slaTicket.IsPending = false;
                            slaTicket.Collection.Save();
                        }
                        else
                        {
                            SlaPausedTimes slaPausedTimes = new SlaPausedTimes(LoginUser);
                            slaPausedTimes.LoadByTicketId(slaTicket.TicketId);
                            slaPausedTimes.DeleteAll();
                            slaPausedTimes.Save();

                            slaTicket.Delete();
                            slaTicket.Collection.Save();
                            Logs.WriteEventFormat("Ticket id {0} does not exist anymore, deleted from SlaTickets.", slaTicket.TicketId);
                        }

                        System.Threading.Thread.Sleep(100);
                    }
                    catch (System.Data.SqlClient.SqlException sqlEx)
                    {
                        //Handle the deadlock exception, any other bubble up.
                        if (sqlEx.Number == 1205 || sqlEx.Message.Contains("deadlocked"))
                        {
                            ExceptionLogs.LogException(LoginUser, sqlEx, "SLA Calculator", "Sync");
                            Logs.WriteEventFormat("Exception. Message {0}{1}StackTrace {2}", sqlEx.Message, Environment.NewLine, sqlEx.StackTrace);
                            slaTicket.IsPending = true;
                            slaTicket.Collection.Save();
                            Logs.WriteEventFormat("SlaTicket: TicketId {0} TriggerId {1} still pending.", slaTicket.TicketId, slaTicket.SlaTriggerId);
                        }
                        else
                        {
                            throw;
                        }
                    }
                    catch (Exception ex)
                    {
                        ExceptionLogs.LogException(LoginUser, ex, "SLA Calculator", "Sync");
                        Logs.WriteEventFormat("Exception. Message {0}{1}StackTrace {2}", ex.Message, Environment.NewLine, ex.StackTrace);

                        slaTicket.IsPending = false;
                        slaTicket.Collection.Save();
                        Logs.WriteEventFormat("SlaTicket: TicketId {0} TriggerId {1} set to not pending.", slaTicket.TicketId, slaTicket.SlaTriggerId);
                    }
                }

                if (slaTickets != null && slaTickets.Count > 0)
                {
                    Logs.WriteEvent(string.Format("Completed processing the {0} pending tickets to calculate the SLA values for.", slaTickets.Count));
                }
            }
            catch (Exception ex)
            {
                ExceptionLogs.LogException(LoginUser, ex, "SLA Calculator", "Sync");
                Logs.WriteEvent(string.Format("Exception. Message {0}{1}StackTrace {2}", ex.Message, Environment.NewLine, ex.StackTrace));
            }
        }