//public bool LoadArchiveRelatedItems(int entityID) //{ // using (var projectContext = new DataAccess.MyProjectEntities()) // { // return projectContext.TableDrivedEntity.First(x => x.ID == entityID).LoadArchiveRelatedItems==true; // } // return true; //} public bool UpdateArchiveTag(ArchiveTagDTO message) { List <ArchiveTagDTO> result = new List <ArchiveTagDTO>(); using (var projectContext = new DataAccess.MyProjectEntities()) { ArchiveTag dbitem = null; if (message.ID != 0) { dbitem = projectContext.ArchiveTag.First(x => x.ID == message.ID); } else { dbitem = new ArchiveTag(); } dbitem.Name = message.Name; dbitem.TableDrivedEntityID = (message.EntityID == 0 ? (int?)null : message.EntityID); if (dbitem.ID == 0) { projectContext.ArchiveTag.Add(dbitem); } projectContext.SaveChanges(); } return(true); }
public ArchiveTagDTO ToArchiveTagDTO(ArchiveTag item) { ArchiveTagDTO result = new ArchiveTagDTO(); result.ID = item.ID; result.Name = item.Name; result.EntityID = item.TableDrivedEntityID ?? 0; return(result); }
/// <summary> /// Archives a message. /// </summary> /// <param name="pipelineContext">The pipeline context of the message to be archived.</param> /// <param name="baseMessage">The message to be archived.</param> /// <param name="expiryMinutes">The amount of time (in minutes) before the archived message expires and will be automatically deleted from the archive. Specify a value of 0 to use the default configured expiry time.</param> /// <param name="includeProperties">A flag indicating if properties should be archived along with the message.</param> /// <param name="tag">A tag value to be associated with the archived message.</param> /// <returns>The id of the archived message.</returns> public string ArchiveMessage(IPipelineContext pipelineContext, IBaseMessage baseMessage, int expiryMinutes, bool includeProperties, string tag) { try { ArchiveTag archiveTag = new ArchiveTag(tag); ArchiveBizTalkMessage bizTalkMessage = new ArchiveBizTalkMessage(pipelineContext, baseMessage, archiveTag); messageId = bizTalkMessage.Message.MessageId.ToString(); ArchiveMessageAsync(bizTalkMessage, expiryMinutes, includeProperties, archiveTag); } catch (Exception ex) { Logger.WriteWarning(string.Format("Error archiving a message {0} \r\n Details: {1}", this.GetType().Name, ex.ToString()), 14005); } return(messageId); }
/// <summary> /// Archive the message and its parts and optionally archives the message and part properties. /// </summary> /// <param name="expiryMinutes">The amount of time (in minutes) before the archived message expires and will be automatically deleted from the archive.</param> /// <param name="includeProperties">A flag indicating if properties should be archived along with the message.</param> /// <param name="tag">An ArchiveTag to be associated with the archived message.</param> public Task Archive(int expiryMinutes, bool includeProperties, ArchiveTag tag) { return(Task.Factory.StartNew(() => { try { if (tag.ArchiveType.Active) { using (SqlServerConnection connection = new SqlServerConnection("MessageArchive")) { connection.RefreshConfiguration(); connection.Open(); connection.BeginTransaction(); try { ArchiveMessage(expiryMinutes, connection); if (includeProperties) { ArchiveMessageProperties(connection); } ArchiveParts(connection); if (includeProperties) { ArchivePartProperties(connection); } connection.Commit(); } catch (Exception ex) { if (connection.IsOpen()) { connection.Rollback(); } throw ex; } } } } catch (Exception ex) { Logger.WriteError(string.Format("Error archiving a message to database. The message will be writen to archive directory for later archival. \r\n Details: {0}", ex.ToString()), 128); HandleFailedArchiveMessage(); } })); }
/// <summary> /// Archives a message. /// </summary> /// <param name="message">The message to be archived.</param> /// <param name="expiryMinutes">The amount of time (in minutes) before the archived message expires and will be automatically deleted from the archive. Specify a value of 0 to use the default configured expiry time.</param> /// <param name="includeProperties">A flag indicating if properties should be archived along with the message.</param> /// <param name="tag">A tag value to be associated with the archived message.</param> /// <param name="autoDisposeXLangMessage">When called from an orchestration, this flag should be set to true to dispose XLANGMessage after use.</param> /// <returns>The id of the archived message.</returns> public string ArchiveMessage(XLANGMessage xLangMessage, int expiryMinutes, bool includeProperties, string tag, bool autoDisposeXLangMessage) { try { ArchiveTag archiveTag = new ArchiveTag(tag); ArchiveBizTalkMessage bizTalkMessage = new ArchiveBizTalkMessage(xLangMessage, archiveTag, false); messageId = bizTalkMessage.Message.MessageId.ToString(); ArchiveMessageAsync(bizTalkMessage, expiryMinutes, includeProperties, archiveTag); } catch (Exception ex) { Logger.WriteWarning(string.Format("Error archiving a message {0} \r\n Details: {1}", this.GetType().Name, ex.ToString()), 14005); } finally { if (autoDisposeXLangMessage) { xLangMessage.Dispose(); } } return(messageId); }
/// <summary> /// Archives a message asynchronously /// </summary> /// <param name="bizTalkMessage"></param> /// <param name="expiryMinutes"></param> /// <param name="includeProperties"></param> /// <param name="archiveTag"></param> private async void ArchiveMessageAsync(ArchiveBizTalkMessage bizTalkMessage, int expiryMinutes, bool includeProperties, ArchiveTag archiveTag) { try { if (expiryMinutes <= 0) { expiryMinutes = archiveTag.ArchiveType.DefaultExpiry; } await bizTalkMessage.Archive(expiryMinutes, includeProperties, archiveTag); //Log success Logger.WriteInformation("Message " + bizTalkMessage.Message.MessageId.ToString() + " has been archived.", 325); } catch (Exception ex) { Logger.WriteWarning(string.Format("Error archiving a message asynchronously {0} \r\n Details: {1}", this.GetType().Name, ex.ToString()), 14005); } }
/// <summary> /// /// </summary> /// <param name="xLangMessage"></param> /// <param name="tag"></param> /// <param name="autoDispose"></param> public ArchiveBizTalkMessage(XLANGMessage xLangMessage, ArchiveTag tag, bool autoDispose = true) { this.Message = new Message(); this.MessageProperties = new List <MessageProperty>(); this.Parts = new List <Part>(); this.PartsProperties = new List <PartProperty>(); Guid messageId = Guid.NewGuid(); try { if (xLangMessage is MessageWrapperForUserCode) { //------------------------------------------------------------------------- // Add Message. //------------------------------------------------------------------------- this.Message.MessageId = messageId; if (tag.ArchiveType.Id >= 0) { this.Message.ArchiveTypeId = tag.ArchiveType.Id; } this.Message.Tag = tag.Tag; if (tag.SourceSystem.Id >= 0) { this.Message.SourceSystemId = tag.SourceSystem.Id; } if (tag.TargetSystem.Id >= 0) { this.Message.TargetSystemId = tag.TargetSystem.Id; } this.Message.Description = tag.Description; this.Message.InsertedDate = DateTime.UtcNow; Type messageWrapperType = typeof(MessageWrapperForUserCode); msgUnwrapMethod = messageWrapperType.GetMethod("Unwrap", BindingFlags.Instance | BindingFlags.NonPublic); MessageWrapperForUserCode messageWrapper = (MessageWrapperForUserCode)xLangMessage; XMessage xMessage = (XMessage)(msgUnwrapMethod.Invoke(messageWrapper, null)); if (xMessage != null) { try { //------------------------------------------------------------------------- // Add the parts. //------------------------------------------------------------------------- int partCount = xLangMessage.Count; for (int partIndex = 0; partIndex < partCount; partIndex++) { XLANGPart part = xLangMessage[partIndex]; try { Part prt = GetMessagePart(messageId, partIndex, xMessage, part); if (prt != null) { this.Parts.Add(prt); //------------------------------------------------------------------------- // Add the parts properties. //------------------------------------------------------------------------- List <PartProperty> prtProperties = GetPartProperties(prt.PartId, part); foreach (PartProperty p in prtProperties) { this.PartsProperties.Add(p); } } } finally { // part is actually a PartWrapperForUserCode. Calling its Dispose method causes // the PartWrapperForUserCode to be detached from the owning MessageWrapperForUserCode. part.Dispose(); } } //------------------------------------------------------------------------- // Add the message properties. //------------------------------------------------------------------------- Hashtable propertyHashTable = xMessage.GetContextProperties(); if (propertyHashTable != null) { XmlQNameTable propertyTable = new XmlQNameTable(propertyHashTable); int propertyIndex = 0; MessageProperty msgProperties = new MessageProperty(); msgProperties.MessageId = messageId; XElement ContextData = new XElement("ContextData"); List <string> listOfContextProperties = new List <string>(); listOfContextProperties = GetListOfContextProperties(); foreach (DictionaryEntry property in propertyTable) { XmlQName qName = (XmlQName)property.Key; if (listOfContextProperties.Contains(qName.Name)) { ContextData.Add( new XElement("Property", new XAttribute("Name", qName.Name), new XAttribute("Namespace", qName.Namespace), new XAttribute("Value", property.Value.ToString()))); } if (qName.Namespace == "http://schemas.microsoft.com/BizTalk/2003/system-properties") { if (qName.Name == "InterchangeID") { string value = property.Value.ToString().Trim(); this.Message.InterchangeId = GetGUIDWithoutBraces(value); } else if (qName.Name == "MessageType") { this.Message.MessageType = property.Value.ToString(); } } else if (qName.Namespace == "http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties") { if (qName.Name == "ActivityIdentity") { string value = property.Value.ToString().Trim(); this.Message.ActivityId = GetGUIDWithoutBraces(value); } } propertyIndex++; } msgProperties.ContextData = ContextData.ToString(); this.MessageProperties.Add(msgProperties); // If the message type is still unknown, try to get it from part[0]. if (string.IsNullOrEmpty(this.Message.MessageType) || this.Message.MessageType == "Unknown") { if (!string.IsNullOrEmpty(partType)) { this.Message.MessageType = partType; } } } } finally { // When the MessageWrapperForUserCode is unrwapped the reference count // for the message is incremented, so we must release it now. xMessage.Release(); } } else { throw new Exception("Could not unwrap XMessage from MessageWrapperForUserCode."); } } else { throw new Exception("Expected XLANGMessage to be a MessageWrapperForUserCode. " + xLangMessage.GetType().FullName + " is not a recognized XLANGMessage type."); } } catch (Exception ex) { Logger.WriteTrace(string.Format("Error constructing BizTalkMessage from XLangMessage {0} \r\n Details: {1}", this.GetType().Name, ex.ToString())); throw ex; } finally { if (autoDispose) { xLangMessage.Dispose(); } } }
/// <summary> /// /// </summary> /// <param name="pipelineContext"></param> /// <param name="message"></param> /// <param name="tag"></param> public ArchiveBizTalkMessage(IPipelineContext pipelineContext, IBaseMessage message, ArchiveTag tag) { this.Message = new Message(); this.MessageProperties = new List <MessageProperty>(); this.Parts = new List <Part>(); this.PartsProperties = new List <PartProperty>(); Guid messageId = Guid.NewGuid(); try { //------------------------------------------------------------------------- // Add message. //------------------------------------------------------------------------- this.Message.MessageId = messageId; if (tag.ArchiveType.Id >= 0) { this.Message.ArchiveTypeId = tag.ArchiveType.Id; } this.Message.Tag = tag.Tag; if (tag.SourceSystem.Id >= 0) { this.Message.SourceSystemId = tag.SourceSystem.Id; } if (tag.TargetSystem.Id >= 0) { this.Message.TargetSystemId = tag.TargetSystem.Id; } this.Message.Description = tag.Description; this.Message.InsertedDate = DateTime.UtcNow; //------------------------------------------------------------------------- // Add the parts. //------------------------------------------------------------------------- int partCount = message.PartCount; for (int partIndex = 0; partIndex < partCount; partIndex++) { string partName = string.Empty; IBaseMessagePart part = message.GetPartByIndex(partIndex, out partName); Part prt = GetMessagePart(messageId, partIndex, pipelineContext, part, partName); if (prt != null) { this.Parts.Add(prt); //------------------------------------------------------------------------- // Add the parts properties. //------------------------------------------------------------------------- List <PartProperty> prtProperties = GetPartProperties(prt.PartId, part); foreach (PartProperty p in prtProperties) { this.PartsProperties.Add(p); } } } //------------------------------------------------------------------------- // Add the message properties. //------------------------------------------------------------------------- int propertyCount = (int)message.Context.CountProperties; MessageProperty msgProperties = new MessageProperty(); msgProperties.MessageId = messageId; XElement ContextData = new XElement("ContextData"); List <string> listOfContextProperties = new List <string>(); listOfContextProperties = GetListOfContextProperties(); for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++) { string propertyName = null; string propertyNamespace = null; object propertyValue = message.Context.ReadAt(propertyIndex, out propertyName, out propertyNamespace); if (listOfContextProperties.Contains(propertyName)) { ContextData.Add( new XElement("Property", new XAttribute("Name", propertyName), new XAttribute("Namespace", propertyNamespace), new XAttribute("Value", propertyValue.ToString()))); } if (propertyNamespace == "http://schemas.microsoft.com/BizTalk/2003/system-properties") { if (propertyName == "InterchangeID") { string value = propertyValue.ToString().Trim(); this.Message.InterchangeId = GetGUIDWithoutBraces(value); } else if (propertyName == "MessageType") { this.Message.MessageType = propertyValue.ToString(); } } else if (propertyNamespace == "http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties") { if (propertyName == "ActivityIdentity") { string value = propertyValue.ToString().Trim(); this.Message.ActivityId = GetGUIDWithoutBraces(value); } } } msgProperties.ContextData = ContextData.ToString(); this.MessageProperties.Add(msgProperties); // If the message type is still unknown, try to get it from part[0]. if (string.IsNullOrEmpty(this.Message.MessageType) || this.Message.MessageType == "Unknown") { if (!string.IsNullOrEmpty(partType)) { this.Message.MessageType = partType; } } } catch (Exception ex) { Logger.WriteTrace(string.Format("Error constructing BizTalkMessage from IBaseMessage {0} \r\n Details: {1}", this.GetType().Name, ex.ToString())); throw ex; } }