private void VerifyFileSize(ISftp sftp, string filePath, long expectedFileSize) { FileEntry f = sftp.GetFileEntry(filePath, this._properties.DebugTrace); if (f.Size != expectedFileSize) { try { sftp.Delete(filePath); } catch (Exception ex) { throw new Exception("Exception during Delete currupt file.", ex); } throw new SftpException("Corrupt file " + filePath + ". Expected " + expectedFileSize + " bytes, actual was " + f.Size + " bytes. " + "File deleted from remote system. " + "Will retry if BizTalk configured retry attempts are not exhausted."); } }
/// <summary> /// Called when the BizTalk Batch has been submitted. If all the messages were submitted (good or suspended) /// we delete the files from the folder /// </summary> internal void OnBatchComplete(object sender, StatusEventArgs e) { string fileName = "Could not get fileName"; try { if (e.OverallStatus) //Batch completed { lock (_filesInProcess) { //Delete the files foreach (BatchMessage batchMessage in Files) { try { //Close the stream so we can delete this file batchMessage.Message.BodyPart.Data.Close(); fileName = batchMessage.UserData.ToString(); // Delete orginal file if (fileName != Emptybatchfilename) { if (batchMessage.AfterGetAction == SftpReceiveProperties.AfterGetActions.Delete) { _sftp.Delete(fileName); } // Greg Killins 2010/06/07 - originally the following line was simply an "else" and // and assumed the AfterGetAction would be "Rename". // I added the explicit check to see if it is "Rename" because now there is the // the third valid option of "DoNothing" as the AfterGetAction. else if (batchMessage.AfterGetAction == SftpReceiveProperties.AfterGetActions.Rename) { string renameFileName = CommonFunctions.CombinePath(Path.GetDirectoryName(fileName), batchMessage.AfterGetFilename); renameFileName = renameFileName.Replace("%SourceFileName%", Path.GetFileName(fileName)); /* John C. Vestal 2010/04/07 - Added DateTime and UniversalDateTime to macro list. */ if (renameFileName.IndexOf("%DateTime%") > -1) { string dateTime = DateTime.Now.ToString(); dateTime = dateTime.Replace("/", "-"); dateTime = dateTime.Replace(":", ""); renameFileName = renameFileName.Replace("%DateTime%", dateTime); } if (renameFileName.IndexOf("%UniversalDateTime%") > -1) { string dateTime = DateTime.Now.ToUniversalTime().ToString(); dateTime = dateTime.Replace("/", "-"); dateTime = dateTime.Replace(":", ""); renameFileName = renameFileName.Replace("%UniversalDateTime%", dateTime); } // Peter Lindgren 2014-05-22: Added datetime macro that works exactly as the corresponding macro in the standard FTP and FILE adapters. if (renameFileName.IndexOf("%datetime%") > -1) { string dateTime = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHHmmss"); renameFileName = renameFileName.Replace("%datetime%", dateTime); } _sftp.Rename(fileName, renameFileName); } } // Remove filename from _filesInProcess _filesInProcess.Remove(fileName); if (_useLoadBalancing) { string uri = batchMessage.Message.Context.Read(Constants.BizTalkSystemPropertyNames.Inboundtransportlocation, Constants.BiztalkSystemPropertiesNamespace).ToString(); DataBaseHelper.CheckInFile(uri, Path.GetFileName(fileName), _traceFlag); } } catch (Exception ex) { TraceMessage(string.Format("[SftpReceiverEndpoint] ERROR: Could not remove {0} from its location.", ex.Message)); } } } TraceMessage(string.Format("[SftpReceiverEndpoint] OnBatchComplete called. overallStatus == {0}.", true)); } } catch (Exception ex) { Trace.WriteLine("[SftpReceiverEndpoint] OnBatchComplete EXCEPTION!"); lock (_filesInProcess) { _filesInProcess.Remove(fileName); } throw ExceptionHandling.HandleComponentException(System.Reflection.MethodBase.GetCurrentMethod(), ex); } }