Пример #1
0
        /// <summary>
        /// Implementation for AsyncTransmitterEndpoint::ProcessMessage
        /// Transmit the message and optionally return the response message (for Request-Response support)
        /// </summary>
        public override IBaseMessage ProcessMessage(IBaseMessage message)
        {
            Stream source = message.BodyPart.Data;

            // build url
            DotNetFileTransmitProperties props = new DotNetFileTransmitProperties(message, propertyNamespace);
            string filePath = DotNetFileTransmitProperties.CreateFileName(message, props.Uri);

            // Create the new file
            using (FileStream fileStream = new FileStream(filePath, props.FileMode))
            {
                // Seek to the end of the file in case we're appending to existing data
                fileStream.Seek(0, SeekOrigin.End);

                source.Seek(0, SeekOrigin.Begin);

                // Copy the data from the msg to the file
                byte[] buffer = new byte[IO_BUFFER_SIZE];
                int    bytesRead;
                while (0 != (bytesRead = source.Read(buffer, 0, buffer.Length)))
                {
                    fileStream.Write(buffer, 0, bytesRead);
                }
            }

            return(null);
        }
        protected override void HandlerPropertyBagLoaded()
        {
            IPropertyBag config = this.HandlerPropertyBag;

            if (null != config)
            {
                XmlDocument handlerConfigDom = ConfigProperties.IfExistsExtractConfigDom(config);
                if (null != handlerConfigDom)
                {
                    DotNetFileTransmitProperties.ReadTransmitHandlerConfiguration(handlerConfigDom);
                }
            }
        }
Пример #3
0
        public ConfigProperties CreateProperties(string uri)
        {
            ConfigProperties properties = new DotNetFileTransmitProperties(uri);

            return(properties);
        }
Пример #4
0
        /// <summary>
        /// Used to transmit an individual message. The message stream is read into
        /// a buffer and written to disc. Note, we need to process the data in a
        /// streaming fashion, since the strean we receive is most likely a forward-
        /// only stream we have no idea how big it is. We therefore need to process
        /// it in a streaming fashion to avoid an out-of-memory (OOM) situation
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        private bool TransmitMessage(TransmitterMessage msg)
        {
            bool result = false;

            try
            {
                int    numBytesRead = 0;
                Stream s            = msg.Message.BodyPart.Data;

                // build url
                DotNetFileTransmitProperties props = (DotNetFileTransmitProperties)msg.Properties;
                string filePath = ConfigProperties.CreateFileName(msg.Message, props.Uri);

                byte[] buffer = new byte[DotNetFileTransmitProperties.BufferSize];

                // If we needed to use SSO to lookup the remote system credentials we will
                // need the following code.
                // Additionally:
                //   TransmitLocation.xsd in the design-time project must also be edited to
                //   expose the necessary SSO properties.
                //   DotNetFileProperties.cs within the run-time project must be edited
                //	 to load these properties from the XML configuration.

                /*
                 * string ssoAffiliateApplication = props.AffiliateApplication;
                 * if (ssoAffiliateApplication.Length > 0)
                 * {
                 *      SSOResult ssoResult = new SSOResult(msg, affiliateApplication);
                 *      string userName  = ssoResult.UserName;
                 *      string password  = ssoResult.Result[0];
                 *      string etcEtcEtc = ssoResult.Result[1]; // (you can have additional metadata associated with the login in SSO)
                 *
                 *      // use these credentials to login to the remote system
                 *      // ideally zero off the password memory once we are done
                 * }
                 */

                // Create the new file
                FileStream fs = new FileStream(filePath, props.FileMode);

                // Setup the stream writter and reader
                BinaryWriter w = new BinaryWriter(fs);
                w.BaseStream.Seek(0, SeekOrigin.End);

                if (s != null)
                {
                    s.Seek(0, SeekOrigin.Begin);

                    // Copy the data from the msg to the file
                    int n = 0;
                    do
                    {
                        n = s.Read(buffer, 0, DotNetFileTransmitProperties.BufferSize);

                        if (n == 0)                         // We're at EOF
                        {
                            break;
                        }

                        w.Write(buffer, 0, n);
                        numBytesRead += n;
                    } while (n > 0);
                }

                w.Flush();
                w.Close();

                result = true;
            }
            catch (Exception e)
            {
                // If we failed, we need to set the exception on
                // the message. BTS will include this exception in
                // the event log message and also in HAT
                msg.Message.SetErrorInfo(e);
            }

            return(result);
        }