internal static string ValidateReceiveLocation(XmlDocument doc) { XmlNode nodeSchedule = GetRequiredNode(doc, "schedule", "You must specify the Scheduling properties."); XmlNode nodeHost = GetRequiredNode(doc, "host", "You must specify an SSH host."); XmlNode nodePort = GetNode(doc, "port", false); XmlNode nodeRemotepath = GetPathProp(doc, "remotepath", false); XmlNode nodeRemotetempdir = GetPathProp(doc, "remotetempdir", false); XmlNode nodeFileMask = GetNode(doc, "filemask", "*"); XmlNode nodePassword = GetNode(doc, "password", false); XmlNode nodeIdentityFile = GetNode(doc, "identityfile", false); XmlNode nodeIdentityThumbprint = GetNode(doc, "identitythumbprint", false); XmlNode nodeSsoApplication = GetNode(doc, "ssoapplication", false); if (((nodePassword == null) || (nodePassword.InnerText.Length == 0)) && ((nodeIdentityFile == null) || (nodeIdentityFile.InnerText.Length == 0)) && ((nodeIdentityThumbprint == null) || (nodeIdentityThumbprint.InnerText.Length == 0)) && ((nodeSsoApplication == null) || (nodeSsoApplication.InnerText.Length == 0))) { throw new Exception("You must specify either Password, IdentityFile, IdentityThumbprint, or SSO Application"); } // Default values for After Get Actions: string textAfterGetAction = ""; XmlNode nodeAfterGetAction = GetNode(doc, "aftergetaction", false); if ((nodeAfterGetAction != null) && (nodeAfterGetAction.InnerText.Length > 0)) { textAfterGetAction = nodeAfterGetAction.InnerText; } // Check for invalid actions: (the Enum.IsDefined doesn't have an overload for ignore case, as Enum.Parse has) // Empty string is allowed, see SftpReceiveProperties for details. if ((!String.IsNullOrEmpty(textAfterGetAction))) { try { SftpReceiveProperties.AfterGetActions afterGetAction = (SftpReceiveProperties.AfterGetActions)Enum.Parse(typeof(SftpReceiveProperties.AfterGetActions), textAfterGetAction, true); } catch (ArgumentException) { throw new Exception("You must specify an After Get Action: Delete, Rename or DoNothing. Empty field equals DoNothing."); } } StringBuilder builder1 = new StringBuilder("SFTP://" + nodeHost.InnerText); if ((nodePort != null) && (nodePort.InnerText.Length > 0)) { builder1.Append(":" + nodePort.InnerText); } string text1 = (nodeRemotepath != null) ? nodeRemotepath.InnerText : "/"; if (!text1.StartsWith("/")) { text1 = "/" + text1; } builder1.Append(text1 + nodeFileMask.InnerText); return(builder1.ToString()); }
/// <summary> /// (1) Gets the file from the sftp host /// (2) Creates a IBaseMessage /// (3) Sets varius properties such as uri, messagepart, transporttype etc /// (4) Adds the message to the batch /// </summary> /// <param name="fileName"></param> /// <param name="uri"></param> /// <param name="size"></param> /// <param name="afterGetAction"></param> /// <param name="afterGetFilename"></param> /// <returns></returns> internal IBaseMessage CreateMessage(string fileName, string uri, long size, SftpReceiveProperties.AfterGetActions afterGetAction, string afterGetFilename) { try { TraceMessage("[SftpReceiverEndpoint] Reading file to stream " + fileName); // Retrieves the message from sftp server. var stream = _sftp.Get(fileName); stream.Position = 0; // Creates new message IBaseMessageFactory messageFactory = _transportProxy.GetMessageFactory(); IBaseMessagePart part = messageFactory.CreateMessagePart(); part.Data = stream; var message = messageFactory.CreateMessage(); message.AddPart(MessageBody, part, true); // Setting metadata SystemMessageContext context = new SystemMessageContext(message.Context) { InboundTransportLocation = uri, InboundTransportType = _transportType }; // Write/Promote any adapter specific properties on the message context message.Context.Write(Remotefilename, _propertyNamespace, fileName); SetReceivedFileName(message, fileName); message.Context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/" + _transportType.ToLower() + "-properties", fileName); message.Context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", fileName); // Add the file to the batch Files.Add(new BatchMessage(message, fileName, BatchOperationType.Submit, afterGetAction, afterGetFilename)); // Greg Sharp: Let the caller set this as the file size may be stale // Add the size of the file to the stream //if (message.BodyPart.Data.CanWrite) // message.BodyPart.Data.SetLength(size); return(message); } catch (Exception ex) { TraceMessage("[SftpReceiverEndpoint] Error Adding file [" + fileName + "]to batch. Error: " + ex.Message); if (_useLoadBalancing) { DataBaseHelper.CheckInFile(uri, Path.GetFileName(fileName), _traceFlag); } return(null); } }
internal BatchMessage(IBaseMessage message, object userData, BatchOperationType oppType, SftpReceiveProperties.AfterGetActions afterGetAction, string afterGetFilename) { Message = message; UserData = userData; OperationType = oppType; AfterGetAction = afterGetAction; AfterGetFilename = afterGetFilename; }
internal BatchMessage(IBaseMessage message, object userData, BatchOperationType oppType, SftpReceiveProperties.AfterGetActions afterGetAction, string afterGetFilename) { this._message = message; this._userData = userData; this._operationType = oppType; this._aftergetaction = afterGetAction; this._aftergetfilename = afterGetFilename; }