Ejemplo n.º 1
0
        public static bool IsValidDay(DateTime day, int businessDays, List <DateTime> daysToPause, CalendarEvents holidays)
        {
            bool IsValid = false;

            //Checks:

            /*
             *           1) Use business days to check: org business or trigger business
             *           2) Skip PausedOn days
             *           3) Skip Holidays
             */

            //1
            IsValid = IsBusinessDay(day, businessDays);

            //2
            if (IsValid && daysToPause != null && daysToPause.Where(p => p.Date.CompareTo(day.Date) == 0).Any())
            {
                IsValid = false;
            }

            //3
            try
            {
                //holidays might only have items if the sla is set to pause on holidays. See Run()
                if (IsValid && holidays != null && holidays.Where(p => p.StartDateUTCUtc.Value.Date.CompareTo(day.Date) == 0 || p.EndDateUTCUtc.Value.Date.CompareTo(day.Date) == 0).Any())
                {
                    IsValid = false;
                }
            }
            catch (Exception ex)
            {
                ExceptionLogs.AddLog(LoginUser.Anonymous, "SlaProcessor", ex.Message, "IsValidDay", ex.StackTrace, "", "");
            }

            return(IsValid);
        }
Ejemplo n.º 2
0
        private string SendAPIRequest(HttpWebRequest request)
        {
            string ResponseText = "";

            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    if (request.HaveResponse && response != null)
                    {
                        using (StreamReader reader = new StreamReader(response.GetResponseStream(), ASCIIEncoding.UTF8))
                        {
                            ResponseText = reader.ReadToEnd();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogs.LogException(LoginUser.Anonymous, ex, "Deflector");
            }

            return(ResponseText);
        }
Ejemplo n.º 3
0
        private async Task <string> SendAPIAsyncRequest(HttpWebRequest request)
        {
            string ResponseText = "";

            try
            {
                using (WebResponse response = await request.GetResponseAsync().ConfigureAwait(false))
                {
                    if (request.HaveResponse && response != null)
                    {
                        using (StreamReader reader = new StreamReader(response.GetResponseStream(), ASCIIEncoding.UTF8))
                        {
                            ResponseText = reader.ReadToEnd();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogs.LogException(LoginUser.Anonymous, ex, "Deflector");
            }

            return(ResponseText);
        }
Ejemplo n.º 4
0
 public ExceptionLog(DataRow row, ExceptionLogs exceptionLogs) : base(row, exceptionLogs)
 {
     _exceptionLogs = exceptionLogs;
 }
Ejemplo n.º 5
0
        public SlaLevel Clone(string cloneName = null)
        {
            int       cloneSlaLevelId = 0;
            LoginUser loginUser       = Collection.LoginUser;
            SlaLevels slaLevels       = new SlaLevels(loginUser);
            SlaLevel  clone           = slaLevels.AddNewSlaLevel();

            clone.OrganizationID = OrganizationID;

            if (string.IsNullOrEmpty(cloneName))
            {
                clone.Name = Name + " (Clone)";
            }
            else
            {
                clone.Name = cloneName;
            }

            clone.Collection.Save();
            cloneSlaLevelId = clone.SlaLevelID;

            string actionLog = string.Format("{0} cloned SLA Level {1} into {2}.", loginUser.GetUserFullName(), this.Name, clone.Name);

            ActionLogs.AddActionLog(loginUser, ActionLogType.Insert, ReferenceType.Sla, cloneSlaLevelId, actionLog);

            //Clone SLA's triggers
            SlaTriggers clonedSlaTriggers   = new SlaTriggers(loginUser);
            SlaTriggers originalSlaTriggers = new SlaTriggers(loginUser);

            try
            {
                originalSlaTriggers.LoadBySlaLevel(OrganizationID, SlaLevelID);

                foreach (SlaTrigger slaTrigger in originalSlaTriggers.OrderBy(o => o.SlaTriggerID).ToList())
                {
                    SlaTrigger clonedSlaTrigger = clonedSlaTriggers.AddNewSlaTrigger();
                    slaTrigger.ClonePropertiesTo(clonedSlaTrigger);
                    clonedSlaTrigger.SlaLevelID = cloneSlaLevelId;
                }

                clonedSlaTriggers.BulkSave();
            }
            catch (Exception ex)
            {
                actionLog = string.Format("Failed to clone sla {0} Triggers into {1}.", this.SlaLevelID, clone.SlaLevelID);
                ActionLogs.AddActionLog(loginUser, ActionLogType.Insert, ReferenceType.Sla, cloneSlaLevelId, actionLog);
                ExceptionLogs.LogException(loginUser, ex, "Cloning Sla Triggers", "SlaLevels.Clone - Triggers");
            }

            //Clone SLA's Pause on specific days
            try
            {
                clonedSlaTriggers = new SlaTriggers(loginUser);
                clonedSlaTriggers.LoadBySlaLevel(OrganizationID, cloneSlaLevelId);

                foreach (SlaTrigger slaTrigger in originalSlaTriggers)
                {
                    SlaPausedDays clonedSlaPausedDays   = new SlaPausedDays(loginUser);
                    SlaPausedDays originalSlaPausedDays = new SlaPausedDays(loginUser);
                    originalSlaPausedDays.LoadByTriggerID(slaTrigger.SlaTriggerID);
                    int newTriggerId = clonedSlaTriggers.Where(p => p.TicketTypeID == slaTrigger.TicketTypeID && p.TicketSeverityID == slaTrigger.TicketSeverityID && p.SlaLevelID == cloneSlaLevelId).First().SlaTriggerID;

                    foreach (SlaPausedDay slaPausedDay in originalSlaPausedDays.OrderBy(o => o.DateToPause).ToList())
                    {
                        SlaPausedDay clonedSlaPausedDay = clonedSlaPausedDays.AddNewSlaPausedDay();
                        clonedSlaPausedDay.SlaTriggerId = newTriggerId;
                        clonedSlaPausedDay.DateToPause  = slaPausedDay.DateToPauseUtc;
                    }

                    clonedSlaPausedDays.BulkSave();
                }
            }
            catch (Exception ex)
            {
                actionLog = string.Format("Failed to clone sla {0} DaysToPause into {1}.", this.SlaLevelID, clone.SlaLevelID);
                ActionLogs.AddActionLog(loginUser, ActionLogType.Insert, ReferenceType.Sla, cloneSlaLevelId, actionLog);
                ExceptionLogs.LogException(loginUser, ex, "Cloning Sla Pause On Days", "SlaLevels.Clone - Pause On Days");
            }

            return(clone);
        }
Ejemplo n.º 6
0
        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");
            }
        }
Ejemplo n.º 7
0
        private void GetChildrenByParentValue(int organizationID, int?auxID, int ticketID, int parentID, string parentValue, int?productID, ref DataTable result)
        {
            SqlCommand command = new SqlCommand();

            command.CommandText = @"
        SELECT 
            Distinct
            cv.CustomValueID, 
            cv.RefID, 
            cv.CustomValue, 
            cv.DateCreated, 
            cv.DateModified, 
            cv.CreatorID, 
            cv.ModifierID, 
            cv.ImportFileID,
            cf.Name, 
            cf.ApiFieldName, 
            cf.FieldType, 
            cf.ListValues, 
            cf.Description, 
            cf.RefType, 
            cf.AuxID, 
            cf.Position, 
            cf.IsVisibleOnPortal, 
            cf.IsFirstIndexSelect,
            cf.IsRequired,
            cf.OrganizationID, 
            cf.CustomFieldID,
            cf.IsRequiredToClose,
            cf.Mask,
            cf.CustomFieldCategoryID,
            CASE WHEN EXISTS(SELECT NULL FROM CustomFields cf2 WHERE cf2.ParentCustomFieldID = cf.CustomFieldID) THEN 1 ELSE 0 END As IsConditionalParent
        FROM
            CustomFields cf
            LEFT JOIN CustomValues cv
                ON cv.CustomFieldID = cf.CustomFieldID 
                AND cv.RefID = @RefID
        WHERE
            cf.OrganizationID = @OrganizationID
            AND cf.IsVisibleOnPortal = 1
            AND cf.RefType = 17
            AND (cf.AuxID = @AuxID OR @AuxID < 0)
            AND cf.ParentCustomFieldID = @ParentID
            AND 
            (
                cf.ParentCustomValue = @ParentValue
                OR
                (
                    @ParentValue IS NULL
                    AND cf.ParentCustomValue IS NULL
                )
            )
            AND
            (
                cf.ParentProductID = @ProductID
                OR cf.ParentProductID IS NULL
            )
        ORDER BY
            cf.Position";
            command.CommandType = CommandType.Text;
            command.Parameters.AddWithValue("@OrganizationID", organizationID);
            command.Parameters.AddWithValue("@RefID", ticketID);
            command.Parameters.AddWithValue("@AuxID", auxID ?? -1);
            command.Parameters.AddWithValue("@ParentID", parentID);
            command.Parameters.AddWithValue("@ParentValue", parentValue);
            command.Parameters.AddWithValue("@ProductID", productID ?? -1);

            DataTable children = new DataTable();

            using (SqlConnection connection = new SqlConnection(LoginUser.ConnectionString))
            {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);

                command.Connection  = connection;
                command.Transaction = transaction;
                try
                {
                    using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                    {
                        adapter.Fill(children);
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    ExceptionLogs.LogException(LoginUser, ex, "Children Custom Values", DataUtils.GetCommandTextSql(command));
                    throw;
                }
                connection.Close();
            }

            int    childID    = -1;
            string childValue = string.Empty;

            for (int i = 0; i < children.Rows.Count; i++)
            {
                result.ImportRow(children.Rows[i]);
                childID    = (int)children.Rows[i]["CustomFieldID"];
                childValue = children.Rows[i]["CustomValue"].ToString();
                GetChildrenByParentValue(organizationID, auxID, ticketID, childID, childValue, productID, ref result);
            }
        }
Ejemplo n.º 8
0
        private DataTable GetParentsByReferenceType(int organizationID, int?auxID, int ticketID, int?parentProductID)
        {
            SqlCommand command = new SqlCommand();

            command.CommandText = @"
        SELECT 
            Distinct 
            cv.CustomValueID, 
            cv.RefID, 
            cv.CustomValue, 
            cv.DateCreated, 
            cv.DateModified, 
            cv.CreatorID, 
            cv.ModifierID, 
            cv.ImportFileID,
            cf.Name, 
            cf.ApiFieldName, 
            cf.FieldType, 
            cf.ListValues, 
            cf.Description, 
            cf.RefType, 
            cf.AuxID, 
            cf.Position, 
            cf.IsVisibleOnPortal, 
            cf.IsFirstIndexSelect,
            cf.IsRequired,
            cf.OrganizationID, 
            cf.CustomFieldID,
            cf.IsRequiredToClose,
            cf.Mask,
            cf.CustomFieldCategoryID,
            CASE WHEN EXISTS(SELECT NULL FROM CustomFields cf2 WHERE cf2.ParentCustomFieldID = cf.CustomFieldID) THEN 1 ELSE 0 END As IsConditionalParent
        FROM
            CustomFields cf
            LEFT JOIN CustomValues cv
                ON cv.CustomFieldID = cf.CustomFieldID 
                AND cv.RefID = @RefID
        WHERE
            cf.OrganizationID = @OrganizationID
            AND cf.IsVisibleOnPortal = 1
            AND cf.RefType = 17
            AND (cf.AuxID = @AuxID OR @AuxID < 0)
            AND cf.ParentCustomFieldID IS NULL 
            AND (cf.ParentProductID IS NULL OR cf.ParentProductID = @ParentProductID)
        ORDER BY
            cf.CustomFieldCategoryID asc, cf.Position asc";
            command.CommandType = CommandType.Text;
            command.Parameters.AddWithValue("@OrganizationID", organizationID);
            command.Parameters.AddWithValue("@RefID", ticketID);
            command.Parameters.AddWithValue("@AuxID", auxID ?? -1);
            command.Parameters.AddWithValue("@ParentProductID", parentProductID ?? -1);

            DataTable result = new DataTable();

            using (SqlConnection connection = new SqlConnection(LoginUser.ConnectionString))
            {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);

                command.Connection  = connection;
                command.Transaction = transaction;
                try
                {
                    using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                    {
                        adapter.Fill(result);
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    ExceptionLogs.LogException(LoginUser, ex, "Parent Custom Values", DataUtils.GetCommandTextSql(command));
                    throw;
                }
                connection.Close();
            }

            return(result);
        }