Esempio n. 1
0
        /// <summary>
        /// Submitting a batch of files to BizTalk
        /// </summary>
        /// <param name="control"></param>
        /// <param name="filesInProcess"></param>
        internal void _SubmitFiles(ControlledTermination control, IList <string> filesInProcess)
        {
            try
            {
                if (Files == null || Files.Count == 0)
                {
                    return;
                }

                _filesInProcess = filesInProcess;

                TraceMessage(string.Format("[SftpReceiverEndpoint] SubmitFiles called. Submitting a batch of {0} files to BizTalk.", Files.Count));

                // This class is used to track the files associated with this ReceiveBatch. The
                // OnBatchComplete will be raised when BizTalk has consumed the message.
                using (ReceiveBatch batch = new ReceiveBatch(_transportProxy, control, OnBatchComplete, Files.Count))
                {
                    foreach (BatchMessage file in Files)
                    {
                        // Submit file to batch
                        batch.SubmitMessage(file.Message, file.UserData);
                    }
                    batch.Done(null);
                }
            }
            catch (Exception e)
            {
                throw ExceptionHandling.HandleComponentException(System.Reflection.MethodBase.GetCurrentMethod(),
                                                                 new SftpException("Could not submit files to BTS", e));
            }
        }
        public void TransactionalTask(IScheduledTaskStreamProvider2 provider)
        {
            //call GetStream
            CommittableTransaction transaction = null;

            Stream result = ((IScheduledTaskStreamProvider2)provider).GetStreams(this.adapterConfiguration.Task.TaskParameters, out transaction);

            if (result != null)
            {
                Batch batch = null;
                if (transaction != null)
                {
                    batch = new ReceiveTxnBatch(transportProxy, controlledTermination, transaction, batchFinished, this.adapterConfiguration.SuspendMessage);
                }
                else
                {
                    batch = new ReceiveBatch(transportProxy, controlledTermination, batchFinished, 0);
                }
                Stream readonlystream = new ReadOnlySeekableStream(result);
                IBaseMessageFactory messageFactory = this.transportProxy.GetMessageFactory();

                IBaseMessage message = this.CreateMessage(messageFactory, readonlystream, this.adapterConfiguration.Name);
                batch.SubmitMessage(message, new StreamAndUserData(readonlystream, null));
                batch.Done();
                this.batchFinished.WaitOne();
                ((IScheduledTaskStreamProvider2)provider).Done(batch.OverallSuccess);
            }
        }
        public void NonTransactionalTask(IScheduledTaskStreamProvider provider)
        {
            //call GetStream
            Stream result = ((IScheduledTaskStreamProvider)provider).GetStream(this.adapterConfiguration.Task.TaskParameters);

            if (result != null)
            {
                Stream readonlystream = new ReadOnlySeekableStream(result);

                ReceiveBatch batch = new ReceiveBatch(transportProxy, controlledTermination, batchFinished, 0);

                IBaseMessageFactory messageFactory = this.transportProxy.GetMessageFactory();
                IBaseMessage        message        = this.CreateMessage(messageFactory, readonlystream, this.adapterConfiguration.Name);
                batch.SubmitMessage(message, new StreamAndUserData(readonlystream, null));
                batch.Done();
                this.batchFinished.WaitOne();
            }
        }
        /// <summary>
        /// Given a List of Messages submit them to BizTalk for processing
        /// </summary>
        private void SubmitMessages(List <BatchMessage> items)
        {
            if (items == null || items.Count == 0)
            {
                throw new ArgumentException("SubmitMessages was called with an empty list of messages");
            }

            Trace.WriteLine(string.Format("[GrabCasterReceiverEndpoint] SubmitMessages called. Submitting a batch of {0} messages.", items.Count));

            //This class is used to track the messages associated with this ReceiveBatch
            BatchInfo batchInfo = new BatchInfo(items);

            using (ReceiveBatch batch = new ReceiveBatch(this.transportProxy, this.controlledTermination, batchInfo.OnBatchComplete, this.properties.MaximumNumberOfMessages))
            {
                foreach (BatchMessage item in items)
                {
                    // submit message to batch
                    batch.SubmitMessage(item.Message, item.UserData);
                }

                batch.Done(null);
            }
        }