private bool Migrate(ManagedItem sourceManagedItem) { _itemNumber = sourceManagedItem._itemNumber; _isOrphaned = sourceManagedItem._isOrphaned; //Changed for Multiple Documents this.Documents = sourceManagedItem.Documents; CopyExtensions(sourceManagedItem.Extensions); _attachments = new List<Attachment>(sourceManagedItem.Attachments); foreach (Term term in BasicTerms) { term.MigrateReset(); Term sourceTerm = sourceManagedItem.FindTerm(term.ID, term.Name); if (sourceTerm != null && !(sourceTerm is ComplexList) && term.TermType == sourceTerm.TermType) term.Migrate(sourceTerm); else { term.Migrate(null); } } foreach (Term term in sourceManagedItem.BasicTerms) { if (!term.Runtime.Migrated) term.Delete(); } for (int index = 0;index < ComplexLists.Count;index++) { ComplexList term = (ComplexList)ComplexLists[index]; Term sourceTerm = sourceManagedItem.FindTerm(term.ID, term.Name); if (sourceTerm != null && (sourceTerm is ComplexList)) { if (ComplexList.ModifyItems(sourceTerm as ComplexList, term)) term = (ComplexList)term.RetroCopy(false, this); term.Migrate(sourceTerm); ComplexLists[index] = term; } else term.Migrate(null); } foreach (Term term in sourceManagedItem.ComplexLists) { if (!term.Runtime.Migrated) term.Delete(); } int count = Comments.Count; //Cause the setting of _commentsLoaded Comments = new List<Comment>(sourceManagedItem.Comments); Event.Migrate(sourceManagedItem.Events, Events); Event.Migrate(sourceManagedItem.Workflow.Events, Workflow.Events); //The ActiveWorkflow is determined by the source template (that was used to create 'this'). //The ActiveWorkflow will not change. //If the sourceManagedItem happens to have the same ActiveWorkflow as the source template, and a match //can be made on the state, then keep the state. Otherwise, set the state to the base state. State currentState = null; if (ActiveWorkflowID.Equals(sourceManagedItem.ActiveWorkflowID) || Workflow.Name.Equals(sourceManagedItem.Workflow.Name)) { currentState = Workflow.FindState(sourceManagedItem.State.ID); if (currentState == null) currentState = Workflow.FindState(sourceManagedItem.State.Name); } State = currentState == null ? Workflow.FindBaseState() : currentState; return currentState == null; }
public string Send(ManagedItem managedItem, ITATSystem system, string sEnvironment, List<int> owningFacilityIDs) { //If the subject or body or recipients are empty, then do not send anything if ((string.IsNullOrEmpty(Subject)) || (string.IsNullOrEmpty(this.Text)) || (this.Recipients == null) || (this.Recipients.Count == 0)) return string.Empty; string sError = string.Empty; string from = null; string subject = null; string text = null; Kindred.Common.Security.NameEmailPair[] emailRecipients = null; try { Kindred.Common.Email.Email email = new Kindred.Common.Email.Email(); from = XMLNames._M_EmailFrom; subject = string.IsNullOrEmpty(Subject) ? "Subject Missing" : Subject; text = string.IsNullOrEmpty(Text) ? "Text Missing" : Text; Term.SubstituteBasicTerms(managedItem, ref text); Term.SubstituteSpecialTerms(ref text, managedItem); //Now complete the 'ManagedItemReference' email links - fill in the dynamically supplied info if (!string.IsNullOrEmpty(system.Name)) text = text.Replace(XMLNames._M_SystemNameHolder, system.Name); if (!string.IsNullOrEmpty(sEnvironment)) text = text.Replace(XMLNames._M_EnvironmentHolder, sEnvironment); text = text.Replace(XMLNames._M_ManagedItemIdHolder, managedItem.ManagedItemID.ToString()); List<int> facilityIDs = null; if (owningFacilityIDs != null) facilityIDs = new List<int>(owningFacilityIDs); else facilityIDs = new List<int>(); bool overrideFacilities = false; //Note - HasOwningFacility trumps use of filterFacilityTerm if (!(system.HasOwningFacility ?? false)) { if (FilterFacilityTermID.HasValue) { Term filterFacilityTerm = managedItem.FindTerm(FilterFacilityTermID.Value); if (filterFacilityTerm != null) { FacilityTerm facilityTerm = null; if (filterFacilityTerm.TermType == TermType.Facility) facilityTerm = filterFacilityTerm as FacilityTerm; else facilityTerm = new FacilityTerm(false, managedItem, filterFacilityTerm); if (facilityTerm != null) { facilityIDs = facilityTerm.SelectedFacilityIDs; overrideFacilities = true; } } } } List<int> allRecipientFacilityIDs = new List<int>(); if ((system.HasOwningFacility ?? false) || overrideFacilities) { foreach (string recipient in Recipients) { List<int> absoluteLevels = null; List<int> relativeLevels = null; system.GetFacilityLevels(recipient, ref absoluteLevels, ref relativeLevels); List<int> recipientFacilityIDs = FacilityCollection.FacilityAncestry(facilityIDs, absoluteLevels, relativeLevels); foreach (int facilityID in recipientFacilityIDs) if (!allRecipientFacilityIDs.Contains(facilityID)) allRecipientFacilityIDs.Add(facilityID); } emailRecipients = SecurityHelper.GetEmailRecipients(system, Recipients, allRecipientFacilityIDs); } else { emailRecipients = SecurityHelper.GetEmailRecipients(system, Recipients); } EmailHelper.SendEmail(from, subject, text, emailRecipients, system, Recipients, allRecipientFacilityIDs); } catch (Exception e) { sError = string.Format("Email={0} Exception={1}", EmailInfo(from, emailRecipients, subject, text), e.ToString()); } return sError; }