protected override void LoadOrganization(TeamSupport.Data.Organization organization) { base.LoadOrganization(organization); LoadTicketTypes(organization); LoadCustomFieldTypes(); LoadCustomFields(); }
public static TimeSpan CalculatePausedTime(LoginUser loginUser, Organization organization, SlaTrigger slaTrigger, DateTime pausedOn, DateTime resumedOn, SlaTickets.BusinessHours businessHours, List <DateTime> daysToPause, CalendarEvents holidays, Logs logs = null) { TimeSpan pausedTime = new TimeSpan(); int adjustedMinutes = 0; bool slaUseBusinessHours = slaTrigger.UseBusinessHours; int slaBusinessDays = businessHours.BusinessDays; DateTime?slaDayStart = businessHours.DayStartUtc; DateTime?slaDayEnd = businessHours.DayEndUtc; int startOfDayMinutes = slaDayStart.Value.Minute + (slaDayStart.Value.Hour * 60); int endOfDayMinutes = slaDayEnd.Value.Minute + (slaDayEnd.Value.Hour * 60); int minutesInOneDay = (24 * 60); //When converted the input to UTC the end time might be less than the start time. E.g. central 8 to 22, is stored as utc 14 to 4 if (businessHours.DayEndUtc.Hour < businessHours.DayStartUtc.Hour && businessHours.DayEndUtc.Day > businessHours.DayStartUtc.Day) { adjustedMinutes = slaDayStart.Value.Minute + slaDayStart.Value.Hour * 60; slaDayStart = slaDayStart.Value.AddMinutes(-adjustedMinutes); slaDayEnd = slaDayEnd.Value.AddMinutes(-adjustedMinutes); pausedOn = pausedOn.AddMinutes(-adjustedMinutes); resumedOn = resumedOn.AddMinutes(-adjustedMinutes); startOfDayMinutes = slaDayStart.Value.Minute + (slaDayStart.Value.Hour * 60); endOfDayMinutes = slaDayEnd.Value.Minute + (slaDayEnd.Value.Hour * 60); } if (pausedOn.Date == resumedOn.Date && (slaUseBusinessHours || (!slaUseBusinessHours && !slaTrigger.NoBusinessHours)) && //the last condition means it is using sla custom hours ( (!SlaTickets.IsValidDay(pausedOn, slaBusinessDays, daysToPause, holidays) && !SlaTickets.IsValidDay(resumedOn, slaBusinessDays, daysToPause, holidays)) || (pausedOn.TimeOfDay.TotalSeconds < slaDayStart.Value.TimeOfDay.TotalSeconds && resumedOn.TimeOfDay.TotalSeconds < slaDayStart.Value.TimeOfDay.TotalSeconds) || (pausedOn.TimeOfDay.TotalSeconds > slaDayEnd.Value.TimeOfDay.TotalSeconds && resumedOn.TimeOfDay.TotalSeconds > slaDayEnd.Value.TimeOfDay.TotalSeconds) ) ) { if (logs != null) { logs.WriteEvent("Paused and Resumed on the same non-valid day and time (non-business day, holiday, day to pause, outside business hours), so no time to add."); } } else if (pausedOn.Date == resumedOn.Date && (slaUseBusinessHours || (!slaUseBusinessHours && !slaTrigger.NoBusinessHours)) && //the last condition means it is using sla custom hours ( (SlaTickets.IsValidDay(pausedOn, slaBusinessDays, daysToPause, holidays) && SlaTickets.IsValidDay(resumedOn, slaBusinessDays, daysToPause, holidays)) && (pausedOn.TimeOfDay.TotalSeconds > slaDayStart.Value.TimeOfDay.TotalSeconds && pausedOn.TimeOfDay.TotalSeconds < slaDayEnd.Value.TimeOfDay.TotalSeconds) && (resumedOn.TimeOfDay.TotalSeconds > slaDayStart.Value.TimeOfDay.TotalSeconds && resumedOn.TimeOfDay.TotalSeconds < slaDayEnd.Value.TimeOfDay.TotalSeconds) ) ) { pausedTime = resumedOn - pausedOn; if (logs != null) { logs.WriteEvent("Paused and Resumed on the same valid day and time (business day, non-holiday, not day to pause, inside business hours), simple resumedon - pausedon."); } } else { if ((slaUseBusinessHours && slaBusinessDays == 0) || (!slaUseBusinessHours && DateTime.Compare(slaDayStart.Value, slaDayEnd.Value) == 0 && slaBusinessDays == 127) || //127 means all days are selected. slaTrigger.NoBusinessHours) { pausedTime = resumedOn - pausedOn; logs.WriteEvent("24/7, simple resumedon - pausedon."); } else { //Make sure endOfDayMinutes is greater than startOfDayMinutes if (startOfDayMinutes >= endOfDayMinutes) { //Add 1 day worth of minutes endOfDayMinutes = endOfDayMinutes + minutesInOneDay; } int minutesInBusinessDay = endOfDayMinutes - startOfDayMinutes; //Make sure the pausedon and resumedon are business days while (!SlaTickets.IsValidDay(pausedOn, slaBusinessDays, daysToPause, holidays)) { pausedOn = SlaTickets.GetNextBusinessDay(pausedOn, slaBusinessDays); } while (!SlaTickets.IsValidDay(resumedOn, slaBusinessDays, daysToPause, holidays)) { resumedOn = SlaTickets.GetNextBusinessDay(resumedOn, slaBusinessDays); } //If the pause spans to more than one (and same) days then loop, set a tempResumedOn to end of business days and moving the pausedOn to next business day start of day while (DateTime.Compare(pausedOn, resumedOn) < 0) { DateTime tempResumedOn = new DateTime(); if (DateTime.Compare(pausedOn.Date, resumedOn.Date) < 0) { tempResumedOn = new DateTime(pausedOn.Year, pausedOn.Month, pausedOn.Day, slaDayEnd.Value.Hour, slaDayEnd.Value.Minute, 0); } else if (DateTime.Compare(pausedOn.Date, resumedOn.Date) == 0) { tempResumedOn = resumedOn; } //...do the calculation int secondsPaused = 0; while (pausedOn.Date < tempResumedOn.Date) { int pausedOnSecond = (pausedOn.Minute + (pausedOn.Hour * 60)) * 60; if (pausedOnSecond < (startOfDayMinutes * 60) || pausedOnSecond > (endOfDayMinutes * 60)) { pausedOnSecond = startOfDayMinutes * 60; } secondsPaused = (endOfDayMinutes * 60) - pausedOnSecond; pausedTime = pausedTime.Add(TimeSpan.FromSeconds(secondsPaused)); pausedOn = SlaTickets.GetNextBusinessDay(pausedOn, slaBusinessDays); pausedOn = new DateTime(pausedOn.Year, pausedOn.Month, pausedOn.Day, slaDayStart.Value.Hour, slaDayStart.Value.Minute, 0); } //same day if (pausedOn.Date == tempResumedOn.Date && pausedOn.TimeOfDay < tempResumedOn.TimeOfDay) { int resumedOnMinute = tempResumedOn.Minute + (tempResumedOn.Hour * 60); int resumedOnSecond = resumedOnSecond = (resumedOnMinute * 60) + tempResumedOn.Second; if (resumedOnMinute < startOfDayMinutes) { resumedOnMinute = startOfDayMinutes; resumedOnSecond = resumedOnSecond = (resumedOnMinute * 60) + tempResumedOn.Second; } if (resumedOnMinute > endOfDayMinutes) { resumedOnMinute = endOfDayMinutes; resumedOnSecond = resumedOnSecond = (resumedOnMinute * 60) + tempResumedOn.Second; } if (resumedOnSecond < (startOfDayMinutes * 60)) { resumedOnSecond = (startOfDayMinutes * 60); } if (resumedOnSecond > (endOfDayMinutes * 60)) { resumedOnSecond = (endOfDayMinutes * 60); } secondsPaused = resumedOnSecond - ((((pausedOn.Hour * 60) + pausedOn.Minute) * 60) + pausedOn.Second); pausedTime = pausedTime.Add(TimeSpan.FromSeconds(secondsPaused)); } //get the next valid day to start pausedOn = SlaTickets.GetNextBusinessDay(pausedOn, slaBusinessDays); pausedOn = new DateTime(pausedOn.Year, pausedOn.Month, pausedOn.Day, slaDayStart.Value.Hour, slaDayStart.Value.Minute, 0); while (!SlaTickets.IsValidDay(pausedOn, slaBusinessDays, daysToPause, holidays)) { pausedOn = SlaTickets.GetNextBusinessDay(pausedOn, slaBusinessDays); pausedOn = new DateTime(pausedOn.Year, pausedOn.Month, pausedOn.Day, slaDayStart.Value.Hour, slaDayStart.Value.Minute, 0); } } } } return(pausedTime); }
public static void WriteEvent(TSEventLogEventType tsEventLogEventType, HttpRequest httpRequest = null, User user = null, Organization organization = null, string[] extraInfo = null) { try { string source = "TeamSupport"; if (EventLog.SourceExists(source)) { List <object> prams = extraInfo == null ? new List <object>() : new List <object>(extraInfo); EventLogEntryType eventLogEntryType = EventLogEntryType.Information; switch (tsEventLogEventType) { case TSEventLogEventType.LoginSuccess: prams.Add("User logged in"); eventLogEntryType = EventLogEntryType.SuccessAudit; break; case TSEventLogEventType.LogoutSuccess: prams.Add("User logged out"); eventLogEntryType = EventLogEntryType.SuccessAudit; break; case TSEventLogEventType.FailedLoginAttempt: prams.Add("Failed log in attempt"); eventLogEntryType = EventLogEntryType.FailureAudit; break; case TSEventLogEventType.AccountLocked: prams.Add("Account locked out"); eventLogEntryType = EventLogEntryType.Warning; break; default: break; } if (httpRequest != null) { prams.Add(string.Format("IPAddress: {0}", httpRequest.UserHostAddress)); } if (organization != null) { prams.Add(string.Format("OrganizationID: {0}", organization.OrganizationID.ToString())); prams.Add(string.Format("Account: {0}", organization.Name)); } if (user != null) { prams.Add(string.Format("UserID: {0}", user.UserID.ToString())); prams.Add(string.Format("User: {0}", user.FirstLastName)); prams.Add(string.Format("Email: {0}", user.Email)); } EventLog.WriteEvent(source, new EventInstance((int)tsEventLogEventType, 0, eventLogEntryType), prams.ToArray()); //EventLog.WriteEntry(source, message, eventLogEntryType, (int)tsEventLogEventType, (short)tsEventLogCategoryType); } else { // ExceptionLogs.AddLog(LoginUser.Anonymous, "TeamSupport has not been setup as a source in the event logs."); } } catch (Exception ex) { ExceptionLogs.LogException(LoginUser.Anonymous, ex, "Event Logs", "Error writing event log"); } }