Exemple #1
0
        private static string GetStringFromEmailByKey(IncidentInfo incidentInfo, string Key)
        {
            object objRetVal = null;

            Type incidentInfoType = typeof(IncidentInfo);

            FieldInfo fi = incidentInfoType.GetField(Key);
            if (fi != null)
            {
                objRetVal = fi.GetValue(incidentInfo);
            }
            else
            {
                PropertyInfo pi = incidentInfoType.GetProperty(Key);
                if (pi != null)
                {
                    objRetVal = pi.GetValue(incidentInfo, null);
                }
                else
                {
                    // TODO: Try to Calculate MetaFields
                }
            }

            return GetStringFromObject(objRetVal);
        }
Exemple #2
0
        public static int Create(
			string title,
			string description,
			int project_id,
			int type_id,
			int priority,
			int severity_id,
			int task_time,
			int expected_duration, 
			int expected_response_time,
			int expected_assign_time,
			int creator_id,
			ArrayList categories,
			ArrayList incident_categories,
			string FileName,
			System.IO.Stream _inputStream,
			bool IsEmail,
			DateTime creation_date, 
			int IncidentBoxId,
			PrimaryKeyId contactUid,
			PrimaryKeyId orgUid,
			int mustResponsibleId,
			bool useDuration,
			DateTime expResolveDate
			)
        {
            if (!Company.CheckDiskSpace())
                throw new MaxDiskSpaceException();

            if (!CanCreate(project_id))
                throw new AccessDeniedException();

            // DateTime creation_date = DateTime.UtcNow;

            title = title.Replace("<", "&lt;").Replace(">", "&gt;");

            object oProjectId = null;
            if (project_id > 0)
                oProjectId = project_id;

            IncidentBox box = null;

            if(IncidentBoxId <= 0)
            {
                IncidentInfo info = new IncidentInfo();
                info.Description = description;
                info.GeneralCategories = categories;
                info.IncidentCategories = incident_categories;
                info.PriorityId = priority;
                info.SeverityId = severity_id;
                info.Title = title;
                info.TypeId = type_id;
                info.ContactUid = contactUid;
                info.OrgUid = orgUid;

                if (project_id > 0)
                    info.ProjectId = project_id;

                if(creator_id < 0)
                    info.CreatorId = Security.CurrentUser.UserID;
                else
                    info.CreatorId = creator_id;

                box = IncidentBoxRule.Evaluate(info);
                if (box == null)
                    throw new ArgumentNullException("box");
                IncidentBoxId = box.IncidentBoxId;
            }
            else
                box = IncidentBox.Load(IncidentBoxId);

            // OZ: Fixed expected_duration and expected_response_time
            if (expected_duration <= 0)
                expected_duration = box.Document.GeneralBlock.ExpectedDuration;
            if (expected_response_time <= 0)
                expected_response_time = box.Document.GeneralBlock.ExpectedResponseTime;
            if (expected_assign_time <= 0)
                expected_assign_time = box.Document.GeneralBlock.ExpectedAssignTime;
            //

            if (task_time <= 0)
                task_time = box.Document.GeneralBlock.TaskTime;

            int stateId, managerId, responsibleId;
            bool isResposibleGroup;
            ArrayList users = new ArrayList();

            Issue2.GetIssueBoxSettings(IncidentBoxId, out stateId, out managerId, out responsibleId, out isResposibleGroup, users);

            // O.R. [2008-09-09]: Exclude inactive users
            if (responsibleId > 0 && User.GetUserActivity(responsibleId) != User.UserActivity.Active)
                responsibleId = -1;

            ArrayList activeUsers = new ArrayList();
            foreach (int userId in users)
            {
                if (User.GetUserActivity(userId) == User.UserActivity.Active)
                    activeUsers.Add(userId);
            }
            //

            //ak [2009-06-10] responsible from creation page (IncidentEdit1)
            if (mustResponsibleId > 0)
            {
                responsibleId = mustResponsibleId;
                isResposibleGroup = false;
            }

            if (useDuration)
                expResolveDate = DBCalendar.GetFinishDateByDuration(box.Document.GeneralBlock.CalendarId, creation_date, expected_duration);
            else
            {
                expResolveDate = User.GetUTCDate(expResolveDate);
                expected_duration = DBCalendar.GetDurationByFinishDate(box.Document.GeneralBlock.CalendarId, creation_date, expResolveDate);
            }

            int issueId;
            using(DbTransaction tran = DbTransaction.Begin())
            {
                issueId = DBIncident.Create(oProjectId, creator_id,
                    title, description, creation_date,
                    type_id, priority, stateId, severity_id, IsEmail, task_time,
                    IncidentBoxId, responsibleId, isResposibleGroup?1:0, contactUid, orgUid,
                    expected_duration, expected_response_time, expected_assign_time, expResolveDate, useDuration);

                string Identifier = TicketUidUtil.Create(box.IdentifierMask,issueId);
                DBIncident.UpdateIdentifier(issueId, Identifier);

                // Categories
                foreach(int CategoryId in categories)
                {
                    DBCommon.AssignCategoryToObject((int)INCIDENT_TYPE, issueId, CategoryId);
                }

                // Incident Categories
                foreach(int CategoryId in incident_categories)
                {
                    DBIncident.AssignIncidentCategory(issueId, CategoryId);
                }

                foreach(int UserId in activeUsers)
                {
                    DbIssue2.ResponsibleGroupAddUser(issueId, UserId);
                }

                ForumStorage.NodeContentType _type = (FileName != String.Empty && _inputStream != null) ?
                    ForumStorage.NodeContentType.TextWithFiles : ForumStorage.NodeContentType.Text;
                // Forum
                BaseIbnContainer destContainer = BaseIbnContainer.Create("FileLibrary", string.Format("IncidentId_{0}", issueId));
                ForumStorage forumStorage = (ForumStorage)destContainer.LoadControl("ForumStorage");

                if(description != String.Empty || (FileName != String.Empty && _inputStream != null))
                {
                    ForumThreadNodeInfo info = forumStorage.CreateForumThreadNode(description, creator_id, (int)_type);
                    if(FileName != String.Empty && _inputStream != null)
                    {
                        BaseIbnContainer forumContainer = BaseIbnContainer.Create("FileLibrary", string.Format("ForumNodeId_{0}", info.Id));
                        FileStorage fs = (FileStorage)forumContainer.LoadControl("FileStorage");
                        fs.SaveFile(FileName, _inputStream);
                    }

                    ForumThreadNodeSettingCollection settings1 = new ForumThreadNodeSettingCollection(info.Id);
                    settings1.Add(ForumThreadNodeSetting.Internal, "1");
                    settings1.Add(ForumThreadNodeSetting.Question, "1");
                }

                // O.R: Recalculating project TaskTime
                if (project_id > 0 && task_time > 0)
                    TimeTracking.RecalculateProjectTaskTime(project_id);

                // O.R.[2008-12-16]: Recalculate Current Responsible
                DBIncident.RecalculateCurrentResponsible(issueId);

                // O.R. [2009-06-15]: Recalculate project dates
                if (project_id > 0 && PortalConfig.UseIncidentDatesForProject && !useDuration)
                    Project.RecalculateDates(project_id);

                SystemEvents.AddSystemEvents(SystemEventTypes.Issue_Created, issueId);
                if(project_id > 0)
                    SystemEvents.AddSystemEvents(SystemEventTypes.Project_Updated_IssueList_IssueAdded, project_id, issueId);

                Issue2.SendAlertsForNewIssue(issueId, managerId, responsibleId, activeUsers, null);

                tran.Commit();
            }

            return issueId;
        }
Exemple #3
0
        private static bool EvaluateIsEqual(IncidentInfo incidentInfo, IncidentBoxRule Rule)
        {
            string KeyValue = GetStringFromEmailByKey(incidentInfo, Rule.Key);

            if (KeyValue == null || KeyValue == string.Empty)
                return false;

            ArrayList keyValues = GetKeyArray(KeyValue);
            ArrayList ruleValues = GetKeyArray(Rule.Value);

            foreach (string key in keyValues)
            {
                bool bFound = false;

                foreach (string rule in ruleValues)
                {
                    if (rule.IndexOfAny(new char[] { '*', '?' }) != -1)
                    {
                        if (Pattern.Match(key, rule))
                        {
                            bFound = true;
                            break;
                        }
                    }
                    else if (key == rule)
                    {
                        bFound = true;
                        break;
                    }
                }

                if (!bFound)
                    return false;
            }

            return true;
        }
Exemple #4
0
 private static bool EvaluateRegexMatch(IncidentInfo incidentInfo, IncidentBoxRule Rule)
 {
     string KeyValue = GetStringFromEmailByKey(incidentInfo, Rule.Key);
     Match match = Regex.Match(KeyValue, Rule.Value, RegexOptions.IgnoreCase);
     if ((match.Success && (match.Index == 0)) && (match.Length == KeyValue.Length))
         return true;
     return false;
 }
Exemple #5
0
        private static bool EvaluateContains(IncidentInfo incidentInfo, IncidentBoxRule Rule)
        {
            string KeyValue = GetStringFromEmailByKey(incidentInfo, Rule.Key);

            if (KeyValue == null || KeyValue == string.Empty)
                return false;

            ArrayList keyValues = GetKeyArray(KeyValue);
            ArrayList ruleValues = GetKeyArray(Rule.Value);

            bool bIsNumber = true;

            foreach (string rule in ruleValues)
            {
                if (!IsNumber(rule))
                {
                    bIsNumber = false;
                    break;
                }
            }

            foreach (string rule in ruleValues)
            {
                bool bFound = false;

                foreach (string key in keyValues)
                {
                    if (key == rule)
                    {
                        bFound = true;
                        break;
                    }
                    else
                        if (!bIsNumber && Pattern.Match(key, string.Format("*{0}*", rule)))
                        {
                            bFound = true;
                            break;
                        }
                }

                if (!bFound)
                    return false;
            }

            return true;
        }
Exemple #6
0
        private static bool EvaluateFunction(IncidentInfo incidentInfo, IncidentBoxRule Rule)
        {
            int FunctionId = int.Parse(Rule.Key);

            IncidentBoxRuleFunction function = IncidentBoxRuleFunction.Load(FunctionId);

            ArrayList paramItems = new ArrayList();

            foreach (Match match in Regex.Matches(Rule.Value, "\"(?<Param>[^\"]+)\";?", RegexOptions.IgnoreCase | RegexOptions.Singleline))
            {
                string Value = match.Groups["Param"].Value;
                if (Value.StartsWith("[") && Value.EndsWith("]"))
                {
                    Value = GetStringFromEmailByKey(incidentInfo, Value.Trim('[', ']'));
                }

                paramItems.Add(Value);
            }

            return function.Invoke((string[])paramItems.ToArray(typeof(string)));
        }
Exemple #7
0
        /// <summary>
        /// Evaluates the specified incident box id.
        /// </summary>
        /// <param name="IncidentBoxId">The incident box id.</param>
        /// <returns></returns>
        public static bool Evaluate(int IncidentBoxId, IncidentInfo incidentInfo)
        {
            IncidentBoxRule[] ruleList = IncidentBoxRule.List(IncidentBoxId);

            if (ruleList.Length == 0)
                return false;

            int Index = 0;
            return EvaluateBlock(true, string.Empty, incidentInfo, ruleList, ref Index);
        }
Exemple #8
0
        private static bool EvaluateBlock(bool AndBlock, string BlockOutlineLevel, IncidentInfo incidentInfo, IncidentBoxRule[] ruleList, ref int Index)
        {
            if (Index >= ruleList.Length)
                return false;

            // Empty block is false ...
            bool bResult = false;

            for (; Index < ruleList.Length; Index++)
            {
                IncidentBoxRule Rule = ruleList[Index];

                if (Rule.OutlineLevel.Length <= BlockOutlineLevel.Length)
                {
                    Index--;
                    return bResult;
                }

                bResult = AndBlock ? true : false;

                switch (Rule.RuleType)
                {
                    case IncidentBoxRuleType.AndBlock:
                        #region AndBlock
                        Index++; // Increase Index to move next element
                        bResult = EvaluateBlock(true, Rule.OutlineLevel, incidentInfo, ruleList, ref Index);
                        #endregion
                        break;
                    case IncidentBoxRuleType.OrBlock:
                        #region OrBlock
                        Index++; // Increase Index to move next element
                        bResult = EvaluateBlock(false, Rule.OutlineLevel, incidentInfo, ruleList, ref Index);
                        #endregion
                        break;
                    case IncidentBoxRuleType.Contains:
                        bResult = EvaluateContains(incidentInfo, Rule);
                        break;
                    case IncidentBoxRuleType.FromEMailBox:
                        //bResult = EvaluateFromEMailBox(EMailRouterPop3BoxId, Rule);
                        break;
                    case IncidentBoxRuleType.IsEqual:
                        bResult = EvaluateIsEqual(incidentInfo, Rule);
                        break;
                    case IncidentBoxRuleType.RegexMatch:
                        bResult = EvaluateRegexMatch(incidentInfo, Rule);
                        break;
                    case IncidentBoxRuleType.Function:
                        bResult = EvaluateFunction(incidentInfo, Rule);
                        break;
                    case IncidentBoxRuleType.NotContains:
                        bResult = !EvaluateContains(incidentInfo, Rule);
                        break;
                    case IncidentBoxRuleType.NotIsEqual:
                        bResult = !EvaluateIsEqual(incidentInfo, Rule);
                        break;
                }

                if (AndBlock)
                {
                    if (!bResult)
                    {
                        GoToBlockEnd(BlockOutlineLevel, ruleList, ref Index);
                        return false;
                    }
                }
                else
                {
                    if (bResult)
                    {
                        GoToBlockEnd(BlockOutlineLevel, ruleList, ref Index);
                        return true;
                    }
                }

            }

            return bResult;
        }
Exemple #9
0
        public static IncidentBox Evaluate(IncidentInfo incidentInfo, bool returnDefault)
        {
            IncidentBox defaultBox = null;

            // Load incidentInfo Row
            foreach (IncidentBox box in IncidentBox.ListWithRules())
            {
                if (Evaluate(box.IncidentBoxId, incidentInfo))
                    return box;

                //if (box.IsDefault)
                //    defaultBox = box;
            }

            // OZ: Find Default Box
            if (defaultBox == null && returnDefault)
            {
                foreach (IncidentBox box in IncidentBox.List())
                {
                    if (box.IsDefault)
                    {
                        defaultBox = box;
                        break;
                    }
                }
            }

            return defaultBox;
        }
Exemple #10
0
 //public static IncidentBox Evaluate(int pop3BoxId, string emalFilePath)
 //{
 //    DefaultEMailIncidentMapping mapping = new DefaultEMailIncidentMapping();
 //    IncidentInfo info = mapping.Create(EMailRouterPop3Box.Load(pop3BoxId), emalFilePath);
 //    return Evaluate(info);
 //}
 /// <summary>
 /// Evaluates the specified E mail message id.
 /// </summary>
 /// <param name="EMailincidentInfoId">The E mail message id.</param>
 /// <returns></returns>
 public static IncidentBox Evaluate(IncidentInfo incidentInfo)
 {
     return Evaluate(incidentInfo, true);
 }
        public IncidentInfo Create(EMailRouterPop3Box box, Mediachase.Net.Mail.Pop3Message msg)
        {
            IncidentInfo retVal = new IncidentInfo();

            retVal.CreatorId = box.Settings.DefaultEMailIncidentMappingBlock.DefaultCreator;

            retVal.EMailBox = box.EMailRouterPop3BoxId;

            retVal.Title = msg.Subject==null?string.Empty:msg.Subject;

            if(retVal.Title==string.Empty)
            {
                // Set Default Inicdent Title if subject is empty
                string SenderID = EMailMessage.GetSenderName(msg);
                if(SenderID==string.Empty)
                    SenderID = EMailMessage.GetSenderEmail(msg);
                retVal.Title = string.Format("{0} ({1})", SenderID, DateTime.Now.ToString("d"));
            }

            // OZ: 2008-07-30 Added description defenition rules
            if (box.Settings.DefaultEMailIncidentMappingBlock.DescriptionId == -1)
            {
                retVal.Description = string.Empty;
                retVal.EMailBody = EMailMessageInfo.ExtractTextFromHtml(msg);

            }
            else
            {
                retVal.Description = EMailMessageInfo.ExtractTextFromHtml(msg);
                retVal.EMailBody = retVal.Description;
            }
            //

            int priorityId = GetPriorityId(box, msg);

            if (priorityId < 0) // <0 From Email
            {
                retVal.PriorityId = 500;

                string importance = msg.Importance;
                if (importance != null)
                {
                    switch (importance.ToLower())
                    {
                        case "low":
                            retVal.PriorityId = 0;
                            break;
                        case "normal":
                            retVal.PriorityId = 500;
                            break;
                        case "high":
                            retVal.PriorityId = 750;
                            break;
                    }
                }
            }
            else
            {
                retVal.PriorityId = priorityId;
            }

            retVal.MailSenderEmail = EMailMessage.GetSenderEmail(msg);

            retVal.SeverityId = GetSeverityId(box, msg);
            retVal.TypeId = GetTypeId(box, msg);
            retVal.GeneralCategories.AddRange(GetGeneralCategories(box, msg));
            retVal.IncidentCategories.AddRange(GetIncidentCategories(box, msg));

            // OZ: 2007-01-11
            retVal.ProjectId = box.Settings.DefaultEMailIncidentMappingBlock.ProjectId;
            retVal.IncidentBoxId = box.Settings.DefaultEMailIncidentMappingBlock.IncidentBoxId;

            // OZ: 2007-01-22
            retVal.OrgUid = box.Settings.DefaultEMailIncidentMappingBlock.OrgUid;
            retVal.ContactUid = box.Settings.DefaultEMailIncidentMappingBlock.ContactUid;

            return retVal;
        }
        public IncidentInfo Create(EMailRouterPop3Box box, Mediachase.Net.Mail.Pop3Message msg)
        {
            IncidentInfo retVal = new IncidentInfo();

            retVal.CreatorId = box.Settings.DefaultEMailIncidentMappingBlock.DefaultCreator;

            retVal.EMailBox = box.EMailRouterPop3BoxId;

            retVal.Title = msg.Subject == null?string.Empty:msg.Subject;

            if (retVal.Title == string.Empty)
            {
                // Set Default Inicdent Title if subject is empty
                string SenderID = EMailMessage.GetSenderName(msg);
                if (SenderID == string.Empty)
                {
                    SenderID = EMailMessage.GetSenderEmail(msg);
                }
                retVal.Title = string.Format("{0} ({1})", SenderID, DateTime.Now.ToString("d"));
            }

            // OZ: 2008-07-30 Added description defenition rules
            if (box.Settings.DefaultEMailIncidentMappingBlock.DescriptionId == -1)
            {
                retVal.Description = string.Empty;
                retVal.EMailBody   = EMailMessageInfo.ExtractTextFromHtml(msg);
            }
            else
            {
                retVal.Description = EMailMessageInfo.ExtractTextFromHtml(msg);
                retVal.EMailBody   = retVal.Description;
            }
            //

            int priorityId = GetPriorityId(box, msg);

            if (priorityId < 0)             // <0 From Email
            {
                retVal.PriorityId = 500;

                string importance = msg.Importance;
                if (importance != null)
                {
                    switch (importance.ToLower())
                    {
                    case "low":
                        retVal.PriorityId = 0;
                        break;

                    case "normal":
                        retVal.PriorityId = 500;
                        break;

                    case "high":
                        retVal.PriorityId = 750;
                        break;
                    }
                }
            }
            else
            {
                retVal.PriorityId = priorityId;
            }


            retVal.MailSenderEmail = EMailMessage.GetSenderEmail(msg);

            retVal.SeverityId = GetSeverityId(box, msg);
            retVal.TypeId     = GetTypeId(box, msg);
            retVal.GeneralCategories.AddRange(GetGeneralCategories(box, msg));
            retVal.IncidentCategories.AddRange(GetIncidentCategories(box, msg));

            // OZ: 2007-01-11
            retVal.ProjectId     = box.Settings.DefaultEMailIncidentMappingBlock.ProjectId;
            retVal.IncidentBoxId = box.Settings.DefaultEMailIncidentMappingBlock.IncidentBoxId;

            // OZ: 2007-01-22
            retVal.OrgUid     = box.Settings.DefaultEMailIncidentMappingBlock.OrgUid;
            retVal.ContactUid = box.Settings.DefaultEMailIncidentMappingBlock.ContactUid;

            return(retVal);
        }
Exemple #13
0
        public long CreateIncident47(string Title, string Description, int ProjectId, int TypeId, 
			int Priority, int SeverityId, int[] IncidentCategory, int IncidentBoxId,
			string ContactUid, string OrgUid,
			string SenderEmail)
        {
            try
            {
                int ObjectId = -1;
                if (errMsg == null)
                    errMsg = new ErrMsg();
                errMsg.DidUnderstand = true;
                Authenticate();

                if (IncidentBoxId <= 0)
                {
                    // Calculate Incident box
                    Mediachase.IBN.Business.EMail.IncidentInfo info = new Mediachase.IBN.Business.EMail.IncidentInfo();
                    info.Description = Description;
                    info.GeneralCategories = new ArrayList();
                    info.IncidentCategories = new ArrayList(IncidentCategory);
                    info.PriorityId = Priority;
                    info.SeverityId = SeverityId;
                    info.Title = Title;
                    info.TypeId = TypeId;
                    info.MailSenderEmail = SenderEmail??string.Empty;
                    info.ContactUid = PrimaryKeyId.Parse(ContactUid);
                    info.OrgUid = PrimaryKeyId.Parse(OrgUid);
                    info.CreatorId = Security.CurrentUser.UserID;

                    IncidentBoxId = IncidentBoxRule.Evaluate(info).IncidentBoxId;
                }

                ObjectId = Incident.Create(Title,
                    Description, ProjectId, TypeId, Priority, SeverityId,
                    int.Parse(PortalConfig.IncidentDefaultValueTaskTimeField),
                    0, 0, 0, Security.CurrentUser.UserID,
                    Mediachase.IBN.Business.Common.StringToArrayList(PortalConfig.IncidentDefaultValueGeneralCategoriesField),
                    new ArrayList(IncidentCategory), null, null,
                    false, DateTime.UtcNow, IncidentBoxId, PrimaryKeyId.Parse(ContactUid), PrimaryKeyId.Parse(OrgUid));

                // OZ 2008-08-19: Append email sender
                if(!string.IsNullOrEmpty(SenderEmail))
                    EMailIssueExternalRecipient.Create(ObjectId, SenderEmail);

                errMsg.msg = "OK";
                return ObjectId;
            }
            catch (UserNotAuthenticatedException)
            {
                errMsg.msg = "Your login or password is invalid.";
                return -1;
            }
            catch (Exception ex)
            {
                errMsg.msg = ex.Message;
                return -1;
            }
        }