/// <summary> /// Deletes the user. /// </summary> /// <param name="UserId">The user id.</param> public static void DeleteUser(int UserId) { using (DbTransaction tran = DbTransaction.Begin()) { foreach (IncidentBox box in IncidentBox.List()) { bool bWasModified = false; if (box.Document.GeneralBlock.ResponsiblePool.Contains(UserId)) { box.Document.GeneralBlock.ResponsiblePool.Remove(UserId); bWasModified = true; } if (box.Document.EMailRouterBlock.InformationRecipientList.Contains(UserId)) { box.Document.EMailRouterBlock.InformationRecipientList.Remove(UserId); bWasModified = true; } if (bWasModified) { IncidentBoxDocument.Save(box.Document); } } tran.Commit(); } }
public static IncidentBoxDocument Load(int IncidentBoxId, string Xml) { IncidentBoxDocument retVal = new IncidentBoxDocument(IncidentBoxId); retVal.Load(Xml); return(retVal); }
/// <summary> /// Replases the user. /// </summary> /// <param name="OldUserId">The old user id.</param> /// <param name="NewUserId">The new user id.</param> public static void ReplaseUser(int OldUserId, int NewUserId) { using (DbTransaction tran = DbTransaction.Begin()) { foreach (IncidentBox box in IncidentBox.List()) { bool bWasModified = false; if (box.Document.GeneralBlock.AllowControl && box.Document.GeneralBlock.ControllerAssignType == ControllerAssignType.CustomUser && box.Document.GeneralBlock.Controller == OldUserId) { box.Document.GeneralBlock.Controller = NewUserId; bWasModified = true; } if (box.Document.GeneralBlock.Manager == OldUserId) { box.Document.GeneralBlock.Manager = NewUserId; bWasModified = true; } if (box.Document.GeneralBlock.ResponsibleAssignType == ResponsibleAssignType.CustomUser && box.Document.GeneralBlock.Responsible == OldUserId) { box.Document.GeneralBlock.Responsible = NewUserId; bWasModified = true; } if (box.Document.GeneralBlock.ResponsiblePool.Contains(OldUserId)) { box.Document.GeneralBlock.ResponsiblePool.Remove(OldUserId); bWasModified = true; } if (box.Document.EMailRouterBlock.InformationRecipientList.Contains(OldUserId)) { box.Document.EMailRouterBlock.InformationRecipientList.Remove(OldUserId); bWasModified = true; } if (bWasModified) { IncidentBoxDocument.Save(box.Document); } } tran.Commit(); } }
/// <summary> /// Loads the specified incident box id. /// </summary> /// <param name="IncidentBoxId">The incident box id.</param> /// <returns></returns> public static IncidentBoxDocument Load(int IncidentBoxId) { IncidentBoxDocument retVal = new IncidentBoxDocument(IncidentBoxId); IncidentBoxRow row = IncidentBoxRow.Load(IncidentBoxId); if (row.Document != string.Empty) { retVal.Load(row.Document); } return(retVal); }
public static int Create(string Name, string IdentifierMask, bool IsDefault, int Index) { if (!CanModify()) { throw new AccessDeniedException(); } try { IncidentBoxRow row = new IncidentBoxRow(); row.Name = Name; row.IdentifierMask = IdentifierMask; row.IsDefault = IsDefault; row.Index = Index; row.Update(); // Create Default IncidentBoxDocument IncidentBoxDocument doc = IncidentBoxDocument.Load(row.PrimaryKeyId); doc.GeneralBlock.Manager = Security.CurrentUser.UserID; doc.GeneralBlock.Responsible = Security.CurrentUser.UserID; IncidentBoxDocument.Save(doc); return(row.PrimaryKeyId); } catch (System.Data.SqlClient.SqlException ex) { if (ex.Message.IndexOf("'IX_IncidentBox_1'") != -1) { throw new IncidentBoxDuplicateIdentifierMaskException(); } else if (ex.Message.IndexOf("'IX_IncidentBox'") != -1) { throw new IncidentBoxDuplicateNameException(); } else { throw; } } }
public static void Update(IncidentBox box, IncidentBoxDocument document) { if (!CanModify()) { throw new AccessDeniedException(); } using (Database.DbTransaction tran = Database.DbTransaction.Begin()) { IncidentBox.Update(box); IncidentBoxDocument.Save(document); // O.R.[2008-12-16]: Recalculate Current Responsible DBIncident.RecalculateCurrentResponsibleByIncidentBox(box.IncidentBoxId); tran.Commit(); } }
/// <summary> /// Raises the document modifications. /// </summary> /// <param name="IncidentId">The incident id.</param> /// <param name="OldIncidentBoxId">The old incident box id.</param> /// <param name="NewIncidentBoxId">The new incident box id.</param> public static void RaiseModifications(int IncidentId, int OldIncidentBoxId, int NewIncidentBoxId) { if (OldIncidentBoxId == NewIncidentBoxId) { return; } IncidentBoxDocument oldDoc = IncidentBoxDocument.Load(OldIncidentBoxId); IncidentBoxDocument newDoc = IncidentBoxDocument.Load(NewIncidentBoxId); // Find Real Update if (oldDoc.GeneralBlock.AllowControl && !newDoc.GeneralBlock.AllowControl) { // Turn OffControling Incident.RaiseTurnOffControling(IncidentId, NewIncidentBoxId); } else if (newDoc.GeneralBlock.AllowControl) { if (oldDoc.GeneralBlock.Manager != newDoc.GeneralBlock.Manager && newDoc.GeneralBlock.ControllerAssignType == ControllerAssignType.Manager) { Incident.RaiseChangeController(IncidentId, NewIncidentBoxId, oldDoc.GeneralBlock.Manager, newDoc.GeneralBlock.Manager); } else if (newDoc.GeneralBlock.ControllerAssignType == ControllerAssignType.CustomUser && oldDoc.GeneralBlock.Controller != newDoc.GeneralBlock.Controller) { Incident.RaiseChangeController(IncidentId, NewIncidentBoxId, oldDoc.GeneralBlock.Controller, newDoc.GeneralBlock.Controller); } } if (oldDoc.GeneralBlock.Manager != newDoc.GeneralBlock.Manager) { Incident.RaiseChangeManager(IncidentId, NewIncidentBoxId, oldDoc.GeneralBlock.Manager, newDoc.GeneralBlock.Manager); } }
/// <summary> /// Loads the specified incident box id. /// </summary> /// <param name="IncidentBoxId">The incident box id.</param> /// <returns></returns> public static IncidentBoxDocument Load(int IncidentBoxId) { IncidentBoxDocument retVal = new IncidentBoxDocument(IncidentBoxId); IncidentBoxRow row = IncidentBoxRow.Load(IncidentBoxId); if(row.Document!=string.Empty) { retVal.Load(row.Document); } return retVal; }
public static void Update(IncidentBox box, IncidentBoxDocument document) { if(!CanModify()) throw new AccessDeniedException(); using(Database.DbTransaction tran = Database.DbTransaction.Begin()) { IncidentBox.Update(box); IncidentBoxDocument.Save(document); // O.R.[2008-12-16]: Recalculate Current Responsible DBIncident.RecalculateCurrentResponsibleByIncidentBox(box.IncidentBoxId); tran.Commit(); } }
public static void SetIncidentState(ForumStorage.NodeType nodeType, IncidentBoxDocument incidentBoxDocument, int IncidentId, int ThreadNodeId, ObjectStates state) { Issue2.SetStateByEmail(nodeType, incidentBoxDocument, IncidentId, ThreadNodeId, state); }
public static ArrayList Send(int IncidentId, EMailRouterPop3Box pop3Box, Pop3Message InMsg, string[] RecipientEmails) { ArrayList retVal = new ArrayList(); IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IncidentId)); EMailRouterIncidentBoxBlock settings = IncidentBoxDocument.Load(incidentBox.IncidentBoxId).EMailRouterBlock; if (pop3Box.IsInternal) { #region Internal -> Extrenal // Internal -> Internal Info // 2009-06-16 OZ: Add Chech send emails to internal users if (settings.AllowEMailRouting) { // 2007-02-12 OZ: "FN LN" <*****@*****.**> string FromEmail = string.Format("\"{0} {1}\" <{2}>", Security.CurrentUser.LastName, Security.CurrentUser.FirstName, pop3Box.EMailAddress); OutputMessageCreator output2Iternal = new OutputMessageCreator(InMsg, IncidentId, pop3Box.EMailAddress, FromEmail); // Exclude a message sender //output2Iternal.AddIgnoreRecipient(EMailMessage.GetSenderEmail(InMsg)); // Load InternalUser foreach (int UserId in GetInternalUsersByIncidentId(IncidentId)) { output2Iternal.AddRecipient(UserId); retVal.Add(UserId); } // Load InformationRecipientList // foreach(int infoRecipient in IncidentBoxDocument.Load(incidentBox.IncidentBoxId).EMailRouterBlock.InformationRecipientList) // { // output2Iternal.AddRecipient(infoRecipient); // } foreach (OutputMessage outputMsg in output2Iternal.Create()) { //try //{ SmtpClientUtility.SendMessage(OutgoingEmailServiceType.HelpDeskEmailBox, pop3Box.EMailRouterPop3BoxId, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data); //} //catch(Exception ex) //{ // System.Diagnostics.Trace.WriteLine(ex); // Log.WriteError(ex.ToString()); //} } } // Internal -> Extrenal string publicEmail = FindEMailRouterPublicEmail(IncidentId); if (publicEmail != string.Empty) { //EMailRouterPop3Box externalPop3Box = EMailRouterPop3Box.Load(realEMailBoxId); OutputMessageCreator output2External = new OutputMessageCreator(InMsg, IncidentId, publicEmail, publicEmail); // Load External Senders // foreach(string exRecipient in EMailMessage.GetExternalSendersByIncidentId(IncidentId)) // { // output2External.AddRecipient(exRecipient); // } // Load External Senders foreach (EMailIssueExternalRecipient exRecipient in EMailIssueExternalRecipient.List(IncidentId)) { output2External.AddRecipient(exRecipient.EMail); } // 2007-03-12 RecipientEmails Addon if (RecipientEmails != null) { foreach (string exItem in RecipientEmails) { int emailUserId = DBUser.GetUserByEmail(exItem, false); if (emailUserId > 0) { if (!retVal.Contains(emailUserId)) { output2External.AddRecipient(exItem); retVal.Add(emailUserId); } } else { output2External.AddRecipient(exItem); } } } // int emailBoxId = EMail.EMailRouterOutputMessage.FindEMailRouterPublicId(IncidentId); foreach (OutputMessage outputMsg in output2External.Create()) { //try //{ SmtpClientUtility.SendMessage(OutgoingEmailServiceType.HelpDeskEmailBox, emailBoxId, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data); //} //catch(Exception ex) //{ // System.Diagnostics.Trace.WriteLine(ex); // Log.WriteError(ex.ToString()); //} } } #endregion } else { if (!settings.AllowEMailRouting) { return(retVal); } EMailRouterPop3Box internalPop3Box = EMailRouterPop3Box.ListInternal(); if (internalPop3Box == null) { return(retVal); } #region // External -> Internal // External -> Internal string SenderName = EMailMessage.GetSenderName(InMsg); string FromEmail = SenderName == string.Empty?internalPop3Box.EMailAddress: string.Format("\"{0}\" <{1}>", SenderName, internalPop3Box.EMailAddress); OutputMessageCreator output = new OutputMessageCreator(InMsg, IncidentId, internalPop3Box.EMailAddress, FromEmail); string Subject = (InMsg.Subject == null?string.Empty:InMsg.Subject); if (Subject == string.Empty) { // OZ: Maybe: Set Default Inicdent Title if subject is empty //Subject = Incident.GetIncidentTitle(IncidentId); } if (TicketUidUtil.LoadFromString(Subject) == string.Empty) { output.Subject = string.Format("[{0}] {1}", TicketUidUtil.Create(incidentBox.IdentifierMask, IncidentId), Subject); } foreach (int UserId in GetInternalUsersByIncidentId(IncidentId)) { output.AddRecipient(UserId); retVal.Add(UserId); } // IncidentBoxDocument incidentDoc = IncidentBoxDocument.Load(incidentBox.IncidentBoxId); // // foreach(int infoRecipient in incidentDoc.EMailRouterBlock.InformationRecipientList) // { // output.AddRecipient(infoRecipient); // } foreach (OutputMessage outputMsg in output.Create()) { //try //{ SmtpClientUtility.SendMessage(OutgoingEmailServiceType.HelpDeskEmailBox, internalPop3Box.EMailRouterPop3BoxId, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data); //} //catch(Exception ex) //{ // System.Diagnostics.Trace.WriteLine(ex); // Log.WriteError(ex.ToString()); //} } #endregion } return(retVal); }
public static void SetStateByEmail(ForumStorage.NodeType nodeType, IncidentBoxDocument incidentBoxDocument, int IncidentId, int ThreadNodeId, ObjectStates state) { //if(ForumStorage.NodeType.Outgoing == nodeType || ForumStorage.NodeType.Internal == nodeType) { int stateId = (int)state; int oldStateId = -1; int responsibleId = -1; bool oldIsGroupResponsobility = false; using(IDataReader reader = Incident.GetIncidentTrackingState(IncidentId, false)) { if(reader.Read()) { oldStateId = (int)reader["StateId"]; responsibleId = (int)reader["ResponsibleId"]; oldIsGroupResponsobility = (bool)reader["IsResponsibleGroup"]; } } if(stateId==(int)ObjectStates.ReOpen && oldStateId==(int)ObjectStates.Active) return; using(DbTransaction tran = DbTransaction.Begin()) { if(stateId != oldStateId) UpdateStateAndNotifyController(IncidentId, stateId, ThreadNodeId); if(stateId == (int)ObjectStates.Active || stateId == (int)ObjectStates.ReOpen || stateId == (int)ObjectStates.Upcoming) { //set responsible if it's incoming and resp not set if(responsibleId <= 0) { DbIssue2.UpdateResponsibility(IncidentId, Security.UserID, false); // O.R.[2008-12-16]: Recalculate Current Responsible DBIncident.RecalculateCurrentResponsible(IncidentId); SystemEvents.AddSystemEvents(SystemEventTypes.Issue_Updated_Responsible_Assigned, IncidentId, Security.UserID); IncidentForum.AddForumMesageWithResponsibleChange(IncidentId, ThreadNodeId, Security.UserID); } } tran.Commit(); } } }
public static void Save(IncidentBoxDocument document) { using(DbTransaction tran = DbTransaction.Begin()) { IncidentBoxRow row = IncidentBoxRow.Load(document.OwnerIncidentBoxId); IncidentBoxDocument prevDocument = IncidentBoxDocument.Load(document.OwnerIncidentBoxId, row.Document); row.Document = document.GetDocumentString(); row.ManagerId = document.GeneralBlock.Manager; if(document.GeneralBlock.AllowControl) { if(document.GeneralBlock.ControllerAssignType== ControllerAssignType.CustomUser) row.ControllerId = document.GeneralBlock.Controller; if (document.GeneralBlock.ControllerAssignType == ControllerAssignType.Manager) row.ControllerId = document.GeneralBlock.Manager; if (document.GeneralBlock.ControllerAssignType == ControllerAssignType.Creator) row.ControllerId = 0; } else row.ControllerId = -1; row.CalendarId = document.GeneralBlock.CalendarId; row.ExpectedDuration = document.GeneralBlock.ExpectedDuration; row.ExpectedResponseTime = document.GeneralBlock.ExpectedResponseTime; row.ExpectedAssignTime = document.GeneralBlock.ExpectedAssignTime; row.TaskTime = document.GeneralBlock.TaskTime; row.Update(); // Find Real Update if(prevDocument.GeneralBlock.AllowControl && !document.GeneralBlock.AllowControl) { // Turn OffControling Incident.RaiseTurnOffControling(document.OwnerIncidentBoxId); } else if (document.GeneralBlock.AllowControl) { if (prevDocument.GeneralBlock.Manager!=document.GeneralBlock.Manager && document.GeneralBlock.ControllerAssignType == ControllerAssignType.Manager) { Incident.RaiseChangeController(document.OwnerIncidentBoxId, prevDocument.GeneralBlock.Manager, document.GeneralBlock.Manager); } else if(document.GeneralBlock.ControllerAssignType == ControllerAssignType.CustomUser && prevDocument.GeneralBlock.Controller!=document.GeneralBlock.Controller) { Incident.RaiseChangeController(document.OwnerIncidentBoxId, prevDocument.GeneralBlock.Controller, document.GeneralBlock.Controller); } } if (prevDocument.GeneralBlock.Manager!=document.GeneralBlock.Manager) { Incident.RaiseChangeManager(document.OwnerIncidentBoxId, prevDocument.GeneralBlock.Manager, document.GeneralBlock.Manager); } tran.Commit(); } }
/// <summary> /// Processes the X ibn headers. /// </summary> /// <param name="IncidentId">The incident id.</param> /// <param name="ThreadNodeId">The thread node id.</param> /// <param name="Msg">The MSG.</param> /// <returns></returns> public static bool ProcessXIbnHeaders(int IncidentId, int ThreadNodeId, Pop3Message Msg) { bool bRetVal = true; ForumStorage.NodeType nodeType = ForumStorage.NodeType.Internal; ForumThreadNodeSettingCollection settings = new ForumThreadNodeSettingCollection(ThreadNodeId); if (settings.Contains(ForumThreadNodeSetting.Incoming)) { nodeType = ForumStorage.NodeType.Incoming; } else if (settings.Contains(ForumThreadNodeSetting.Outgoing)) { nodeType = ForumStorage.NodeType.Outgoing; } bool bSetIncidentState = false; ObjectStates cmdObjectStates = ObjectStates.Active; int newResponsibleId = 0; foreach (string HeaderName in Msg.Headers.AllKeys) { string UpHeaderName = HeaderName.ToUpper(); if (UpHeaderName.StartsWith("X-IBN-")) { switch (UpHeaderName) { case "X-IBN-STATE": if (Msg.Headers[HeaderName].Trim() != "0") { cmdObjectStates = (ObjectStates)Enum.Parse(typeof(ObjectStates), Msg.Headers[HeaderName]); if (cmdObjectStates >= ObjectStates.Upcoming && cmdObjectStates <= ObjectStates.OnCheck) { bSetIncidentState = true; } else { // OZ: Wrong Object State cmdObjectStates = ObjectStates.Active; } } break; case "X-IBN-PRIVATEMSG": if (Msg.Headers[HeaderName].Trim() != "0") { XIbnHeaderCommand.SetPrivateStatus(ThreadNodeId); nodeType = ForumStorage.NodeType.Internal; bRetVal = false; } break; case "X-IBN-RESOLUTION": if (Msg.Headers[HeaderName].Trim() != "0") { XIbnHeaderCommand.SetResolutionStatus(ThreadNodeId); } break; case "X-IBN-WORKAROUND": if (Msg.Headers[HeaderName].Trim() != "0") { XIbnHeaderCommand.SetWorkaroundStatus(ThreadNodeId); } break; case "X-IBN-RESPONSIBLE": if (Msg.Headers[HeaderName].Trim() != "0") { newResponsibleId = int.Parse(Msg.Headers[HeaderName]); } break; default: XIbnHeaderCommand.Unknown(IncidentId, Msg.Headers[HeaderName]); break; } } } // Set Default IBN Object State if (!bSetIncidentState) { if (nodeType == ForumStorage.NodeType.Incoming) { IncidentBoxDocument document = IncidentBoxDocument.Load(Incident.GetIncidentBox(IncidentId)); switch (document.EMailRouterBlock.IncomingEMailAction) { case ExternalEMailActionType.None: break; case ExternalEMailActionType.SetReOpenState: XIbnHeaderCommand.SetIncidentState(nodeType, document, IncidentId, ThreadNodeId, ObjectStates.ReOpen); break; } } else if (nodeType == ForumStorage.NodeType.Outgoing) { IncidentBoxDocument document = IncidentBoxDocument.Load(Incident.GetIncidentBox(IncidentId)); switch (document.EMailRouterBlock.OutgoingEMailAction) { case InternalEMailActionType.None: break; case InternalEMailActionType.SendToCheck: XIbnHeaderCommand.SetIncidentState(nodeType, document, IncidentId, ThreadNodeId, ObjectStates.OnCheck); break; case InternalEMailActionType.SetCompletedState: XIbnHeaderCommand.SetIncidentState(nodeType, document, IncidentId, ThreadNodeId, ObjectStates.Completed); break; case InternalEMailActionType.SetSuspendState: XIbnHeaderCommand.SetIncidentState(nodeType, document, IncidentId, ThreadNodeId, ObjectStates.Suspended); break; } } } else { IncidentBoxDocument document = IncidentBoxDocument.Load(Incident.GetIncidentBox(IncidentId)); XIbnHeaderCommand.SetIncidentState(nodeType, document, IncidentId, ThreadNodeId, cmdObjectStates); } // OZ: 2008-11-24 ChangeResponsible, -1 = NotSet, -2 = Group if (newResponsibleId != 0) { XIbnHeaderCommand.ChangeResponsible(IncidentId, newResponsibleId); } return(bRetVal); }
public static IncidentBoxDocument Load(int IncidentBoxId, string Xml) { IncidentBoxDocument retVal = new IncidentBoxDocument(IncidentBoxId); retVal.Load(Xml); return retVal; }
public static void Save(IncidentBoxDocument document) { using (DbTransaction tran = DbTransaction.Begin()) { IncidentBoxRow row = IncidentBoxRow.Load(document.OwnerIncidentBoxId); IncidentBoxDocument prevDocument = IncidentBoxDocument.Load(document.OwnerIncidentBoxId, row.Document); row.Document = document.GetDocumentString(); row.ManagerId = document.GeneralBlock.Manager; if (document.GeneralBlock.AllowControl) { if (document.GeneralBlock.ControllerAssignType == ControllerAssignType.CustomUser) { row.ControllerId = document.GeneralBlock.Controller; } if (document.GeneralBlock.ControllerAssignType == ControllerAssignType.Manager) { row.ControllerId = document.GeneralBlock.Manager; } if (document.GeneralBlock.ControllerAssignType == ControllerAssignType.Creator) { row.ControllerId = 0; } } else { row.ControllerId = -1; } row.CalendarId = document.GeneralBlock.CalendarId; row.ExpectedDuration = document.GeneralBlock.ExpectedDuration; row.ExpectedResponseTime = document.GeneralBlock.ExpectedResponseTime; row.ExpectedAssignTime = document.GeneralBlock.ExpectedAssignTime; row.TaskTime = document.GeneralBlock.TaskTime; row.Update(); // Find Real Update if (prevDocument.GeneralBlock.AllowControl && !document.GeneralBlock.AllowControl) { // Turn OffControling Incident.RaiseTurnOffControling(document.OwnerIncidentBoxId); } else if (document.GeneralBlock.AllowControl) { if (prevDocument.GeneralBlock.Manager != document.GeneralBlock.Manager && document.GeneralBlock.ControllerAssignType == ControllerAssignType.Manager) { Incident.RaiseChangeController(document.OwnerIncidentBoxId, prevDocument.GeneralBlock.Manager, document.GeneralBlock.Manager); } else if (document.GeneralBlock.ControllerAssignType == ControllerAssignType.CustomUser && prevDocument.GeneralBlock.Controller != document.GeneralBlock.Controller) { Incident.RaiseChangeController(document.OwnerIncidentBoxId, prevDocument.GeneralBlock.Controller, document.GeneralBlock.Controller); } } if (prevDocument.GeneralBlock.Manager != document.GeneralBlock.Manager) { Incident.RaiseChangeManager(document.OwnerIncidentBoxId, prevDocument.GeneralBlock.Manager, document.GeneralBlock.Manager); } tran.Commit(); } }