コード例 #1
0
        /// <summary>
        /// call back method for asynchronous batch execution.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="eventArgs">The <see cref="Intuit.Ipp.Core.AsyncCallCompletedEventArgs"/> instance containing the event data.</param>
        private void BatchAsyncompleted(object sender, AsyncCallCompletedEventArgs eventArgs)
        {
            BatchExecutionCompletedEventArgs batchCompletedEventArgs = new BatchExecutionCompletedEventArgs();

            try
            {
                if (eventArgs.Error == null)
                {
                    try
                    {
                        IEntitySerializer responseSerializer = CoreHelper.GetSerializer(this.serviceContext, false);
                        IntuitResponse    restResponse       = (IntuitResponse)responseSerializer.Deserialize <IntuitResponse>(eventArgs.Result);
                        foreach (object obj in restResponse.AnyIntuitObjects)
                        {
                            BatchItemResponse batchItemResponse = obj as BatchItemResponse;
                            this.batchResponses.Add(batchItemResponse);

                            // process batch item
                            this.intuitBatchItemResponses.Add(ProcessBatchItemResponse(batchItemResponse));
                        }

                        batchCompletedEventArgs.Batch = this;
                        this.OnBatchExecuteAsyncCompleted(this, batchCompletedEventArgs);
                    }
                    catch (SystemException systemException)
                    {
                        IdsException idsException = new IdsException("Batch execution failed", systemException);
                        this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, idsException.ToString());
                        batchCompletedEventArgs.Error = idsException;
                        this.OnBatchExecuteAsyncCompleted(this, batchCompletedEventArgs);
                    }
                }
                else
                {
                    batchCompletedEventArgs.Error = eventArgs.Error;
                    this.OnBatchExecuteAsyncCompleted(this, batchCompletedEventArgs);
                }
            }
            catch (Exception e)
            {
                IdsException idsException = new IdsException("Batch execution failed", e);
                this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, idsException.ToString());
                batchCompletedEventArgs.Error = idsException;
                this.OnBatchExecuteAsyncCompleted(this, batchCompletedEventArgs);
            }
        }
コード例 #2
0
        /// <summary>
        /// This method executes the batch request Asynchronously.
        /// </summary>
        public void ExecuteAsync()
        {
            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Started Executing Method ExecuteAsync for Batch");
            AsyncRestHandler asyncRestHandler = new AsyncRestHandler(this.serviceContext);

            asyncRestHandler.OnCallCompleted += new EventHandler <AsyncCallCompletedEventArgs>(this.BatchAsyncompleted);
            BatchExecutionCompletedEventArgs batchCompletedEventArgs = new BatchExecutionCompletedEventArgs();

            // Create Intuit Batch Request
            IntuitBatchRequest intuitBatchRequest = new IntuitBatchRequest();

            intuitBatchRequest.BatchItemRequest = this.batchRequests.ToArray <BatchItemRequest>();
            string uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/batch", Utility.CoreConstants.VERSION, this.serviceContext.RealmId);

            // Creates request parameters
            RequestParameters parameters;

            if (this.serviceContext.IppConfiguration.Message.Request.SerializationFormat == Intuit.Ipp.Core.Configuration.SerializationFormat.Json)
            {
                parameters = new RequestParameters(uri, HttpVerbType.POST, Utility.CoreConstants.CONTENTTYPE_APPLICATIONJSON);
            }
            else
            {
                parameters = new RequestParameters(uri, HttpVerbType.POST, Utility.CoreConstants.CONTENTTYPE_APPLICATIONXML);
            }

            // Prepares request
            HttpWebRequest request = asyncRestHandler.PrepareRequest(parameters, intuitBatchRequest);

            try
            {
                // gets response
                asyncRestHandler.GetResponse(request);
            }
            catch (SystemException systemException)
            {
                IdsException idsException = new IdsException(systemException.Message);
                this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, idsException.ToString());
                batchCompletedEventArgs.Error = idsException;
                this.OnBatchExecuteAsyncCompleted(this, batchCompletedEventArgs);
            }
        }