Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creatable receiver constructor
        /// </summary>
        /// <param name="tp">Transport proxy object reference</param>
        public BizTalkMessaging(IBTTransportProxy tp)
        {
            if (null == tp)
            {
                throw new ArgumentNullException("IBTTransportProxy may not be null");
            }

            this._tp = tp;
            _mf      = _tp.GetMessageFactory();

            _initialized = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialize the adapter by specifying the address of the receive location that uses the adapter
        /// </summary>
        /// <param name="tp">Transport proxy object reference</param>
        /// <param name="url">Address of the receive location</param>
        /// <param name="callBack">Reference to the configuration callback interface</param>
        private void InternalInitialize(IBTTransportProxy tp, string url, IBTTransportConfig callBack)
        {
            lock (this)
            {
                while (false == _initialized)
                {
                    IBTTransportConfig cb = null;

                    if (null == url)
                    {
                        throw new ArgumentNullException("Url may not be null");
                    }

                    if (null == callBack)
                    {
                        cb = this;
                    }
                    else
                    {
                        cb = callBack;
                    }

                    if (null == tp && null == _tp)
                    {
                        _tp = new IBTTransportProxy();
                    }
                    else if (null != tp)
                    {
                        _tp = tp;
                    }

                    _tp.RegisterIsolatedReceiver(url, cb);
                    _mf = _tp.GetMessageFactory();

                    _initialized = true;
                }
            }
        }
        private IBaseMessage BuildResponseMessage(WebResponse webResponse)
        {
            IBaseMessage btsResponse = null;

            // Get the response stream, create a new message attaching
            // the response stream...
            using (Stream s = webResponse.GetResponseStream())
            {
                // NOTE:
                // Copy the network stream into a virtual stream stream. If we were
                // to use a forward only stream (as in the response stream) we would
                // not be able to suspend the response data on failure. The virtual
                // stream will overflow to disc when it reaches a given threshold
                VirtualStream vs        = new VirtualStream();
                int           bytesRead = 0;
                byte[]        buff      = new byte[8 * 1024];
                while ((bytesRead = s.Read(buff, 0, buff.Length)) > 0)
                {
                    vs.Write(buff, 0, bytesRead);
                }

                webResponse.Close();

                // Seek the stream back to the start...
                vs.Position = 0;

                // Build BTS message from the stream
                IBaseMessageFactory mf = transportProxy.GetMessageFactory();
                btsResponse = mf.CreateMessage();
                IBaseMessagePart body = mf.CreateMessagePart();
                body.Data = vs;
                btsResponse.AddPart("Body", body, true);
            }

            return(btsResponse);
        }
		/// <summary>
		/// Creatable receiver constructor
		/// </summary>
		/// <param name="tp">Transport proxy object reference</param>
		public BizTalkMessaging(IBTTransportProxy tp)
		{
			if ( null == tp )
				throw new ArgumentNullException("IBTTransportProxy may not be null");

			this._tp = tp;
			_mf = _tp.GetMessageFactory();

			_initialized = true;
		}
        private IBaseMessage BuildResponseMessage(IBaseMessage message, IBaseMessageContext context, LoopBackTransmitProperties props)
        {
            Guid callToken  = TraceManager.CustomComponent.TraceIn();
            long startScope = TraceManager.CustomComponent.TraceStartScope("BuildResponseMessage", callToken);

            IBaseMessageFactory messageFactory = _transportProxy.GetMessageFactory();
            IBaseMessage        btsResponse    = messageFactory.CreateMessage();

            TraceManager.CustomComponent.TraceInfo("PropertyCopy: {0}", props.PropertyCopy);
            if (props.PropertyCopy)
            {
                btsResponse.Context = PipelineUtil.CloneMessageContext(context);
            }
            TraceManager.CustomComponent.TraceInfo("CustomPropertyCopy: {0}", props.CustomPropertyCopy);
            if (props.CustomPropertyCopy)
            {
                btsResponse.Context = messageFactory.CreateMessageContext();
                for (int i = 0; i < context.CountProperties; i++)
                {
                    string strName;
                    string strNamespace;
                    object oValue = context.ReadAt(i, out strName, out strNamespace);
                    if (!strNamespace.StartsWith("http://schemas.microsoft.com/BizTalk"))
                    {
                        if (context.IsPromoted(strName, strNamespace))
                        {
                            TraceManager.CustomComponent.TraceInfo("Promoted into context: {1}#{0}={2}", strName, strNamespace, oValue);
                            btsResponse.Context.Promote(strName, strNamespace, oValue);
                        }
                        else
                        {
                            TraceManager.CustomComponent.TraceInfo("Copied into context: {1}#{0}={2}", strName, strNamespace, oValue);
                            btsResponse.Context.Write(strName, strNamespace, oValue);
                        }
                    }
                }
            }
            TraceManager.CustomComponent.TraceInfo("PartCount: {0}", message.PartCount);
            for (int i = 0; i < message.PartCount; i++)
            {
                string        str;
                VirtualStream stream = new VirtualStream();
                StreamReader  rdr    = new StreamReader(message.GetPartByIndex(i, out str).GetOriginalDataStream(), true);
                StreamWriter  wrtr   = new StreamWriter(stream, rdr.CurrentEncoding);
                wrtr.Write(rdr.ReadToEnd());
                rdr.Close();
                wrtr.Flush();
                stream.Seek(0, SeekOrigin.Begin);
                IBaseMessagePart part = messageFactory.CreateMessagePart();
                if (props.PropertyCopy)
                {
                    part.Charset        = message.GetPart(str).Charset;
                    part.ContentType    = message.GetPart(str).ContentType;
                    part.PartProperties = PipelineUtil.CopyPropertyBag(message.GetPart(str).PartProperties, messageFactory);
                }
                btsResponse.AddPart(str, part, message.GetPart(str).PartID.Equals(message.BodyPart.PartID));
                btsResponse.GetPart(str).Data = stream;
            }

            TraceManager.CustomComponent.TraceEndScope("BuildResponseMessage", startScope, callToken);
            TraceManager.CustomComponent.TraceOut(callToken);

            return(btsResponse);
        }