/// <summary> /// Returns the Provider to be used Default or Built-in /// </summary> /// /// <returns></returns> protected virtual IMessageArchiveProvider GetProvider() { IMessageArchiveProvider provider = null; try { provider = new MessageArchiver(); } catch (Exception exc) { throw new Exception(string.Format("Unable to create Message Archive Provider, Message: '{10}', Details: '{1}'", exc.Message, exc.ToString())); } return(provider); }
/// <summary> /// Archive To File /// </summary> /// <param name="provider"></param> /// <param name="msgId"></param> /// <param name="context"></param> /// <param name="msgStream"></param> protected virtual void ArchiveToFile(IMessageArchiveProvider provider, Guid msgId, IBaseMessageContext context, Stream msgStream, IBaseMessage inputMessage) { //Get Original FileName using FTP string ftpNs = @"http://schemas.microsoft.com/BizTalk/2003/ftp-properties"; string fileNs = @"http://schemas.microsoft.com/BizTalk/2003/file-properties"; string name = "ReceivedFileName"; //Get Filename by FileAdapter NS string fileName = GetPropertyContext(context, name, fileNs); if (string.IsNullOrEmpty(fileName)) { //Get Filename by FTP NS fileName = GetPropertyContext(context, name, ftpNs); } string origFileName = "NoFileName.txt"; string origFileNameExt = ".txt"; if (string.IsNullOrEmpty(fileName)) { fileName = origFileName; } else { //Get Filename without paths FileInfo fInfo = new FileInfo(fileName); origFileName = fInfo.Name; origFileNameExt = fInfo.Extension; } //Remove Extension origFileName = origFileName.Replace(origFileNameExt, ""); //Update Filename based on macro's string archiveFileName = FileNameMacroHelper.ResolveMacros(inputMessage, ArchiveFileName); //Set the fileName to message Id if blank if (string.IsNullOrEmpty(archiveFileName)) { archiveFileName = msgId.ToString() + ".part"; } else { //Apply Extension archiveFileName += origFileNameExt; } provider.ArchiveToFile(archiveFileName, FileArchiveBackupFolder, FileArchiveIsOverwriteFiles, msgStream, FileArchiveUserName, FileArchiveUserPwd, FileArchiveUserDomain); }
/// <summary> /// Archives the Msg to database /// </summary> /// <param name="provider"></param> /// <param name="msgStream"></param> /// <param name="props"></param> /// <param name="msgId"></param> protected virtual void ArchiveToDb(IMessageArchiveProvider provider, Stream msgStream, string props, Guid msgId) { //Set Variables Stream compressedStream = null; long length = 0; msgStream.Position = 0; length = msgStream.Length; compressedStream = new MemoryStream(new byte[msgStream.Length]); msgStream.CopyTo(compressedStream); // Todo: Add try/catch and logging here //Archive to Database provider.ArchiveToDb( DbConnStr, DbConnProvider, DbSPName, msgId, compressedStream, props, length); }