Ejemplo n.º 1
0
            /// <summary>
            /// Executes the operation asynchronous with single result.
            /// </summary>
            /// <typeparam name="T">The type of of entity.</typeparam>
            /// <param name="entitySet">The entity set.</param>
            /// <param name="entitySetTypeName">Type name of the entity set.</param>
            /// <param name="operation">The operation name.</param>
            /// <param name="isAction">True, if the operation is an action; false, if the operation is a function.</param>
            /// <param name="expandProperties">The navigation property names to be expanded.</param>
            /// <param name="operationParameters">The operation parameters.</param>
            /// <returns>The object of type T.</returns>
            public async Task <T> ExecuteOperationSingleResultAsync <T>(string entitySet, string entitySetTypeName, string operation, bool isAction, ICollection <string> expandProperties, params OperationParameter[] operationParameters)
            {
                if (BatchHelper.IsInBatchMode(this.batchId))
                {
                    if (isAction)
                    {
                        throw new NotSupportedException("Action is not supported in batch mode, only Read, ReadAll, and Functions are supported.");
                    }
                    else
                    {
                        Guid localBatchId = this.batchId.Value;

                        TaskCompletionSource <object> taskCompletionSource = this.parametersCache.PutParameters <T>(localBatchId, entitySet, entitySetTypeName, operation, null, null, operationParameters);

                        return(await taskCompletionSource.Task.ContinueWith <T>(this.GetSingleEntity <T>));
                    }
                }
                else
                {
                    string result = await Task.Run(async() => await AdaptorCaller.ExecuteAsync(GetRequestUri(entitySetTypeName, operation, operationParameters)));

                    result = AdaptorCaller.RemoveCommerceRuntimePrefix(result);

                    TryThrowAsCommerceException(result);
                    return(result.DeserializeJsonObject <T>());
                }
            }
        private async Task <IEnumerable <WriteConcernResult> > InsertMultipleBatchesAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var helper = new BatchHelper(_documentSource, _writeConcern, _continueOnError);

            while (_documentSource.HasMore)
            {
                WriteConcernResult result;
                try
                {
                    result = await ExecuteProtocolAsync(channel, helper.BatchWriteConcern, helper.ShouldSendGetLastError, cancellationToken).ConfigureAwait(false);
                }
                catch (MongoWriteConcernException ex)
                {
                    result = helper.HandleException(ex);
                    if (!_continueOnError)
                    {
                        return(null);
                    }
                }
                helper.AddResult(result);

                _documentSource.ClearBatch();
            }

            return(helper.CreateFinalResultOrThrow());
        }
Ejemplo n.º 3
0
            /// <summary>
            /// Sends the batch request to the server and clears the cache and the batchId.
            /// </summary>
            /// <param name="context">The context that sends the request.</param>
            /// <param name="cache">The cache containing the parameters of cached methods.</param>
            /// <param name="batchId">The batchId to retrieve the cached parameters.</param>
            /// <returns>A Task.</returns>
            internal static async Task ExecuteBatch(IContext context, ParametersCache cache, ThreadLocal <Guid> batchId)
            {
                if (!BatchHelper.IsInBatchMode(batchId))
                {
                    throw new InvalidOperationException("The calling thread was trying to do batch operation but it didn't begin the batch operations before.");
                }

                Guid localBatchId = batchId.Value;

                // Clears the batchId before executing the batch operation since after do "await" the original
                // thread will be used to do ExecuteBatchAsync and a new thread will be created to do the rest work.
                // So we will not be able to clear the original thread any more.
                batchId.Value = Guid.Empty;

                List <ParametersGroup> requests             = cache.GetParameters(localBatchId);
                List <TaskCompletionSource <object> > tasks = cache.GetTasks(localBatchId);

                try
                {
                    await context.ExecuteBatchAsync(requests, tasks);
                }
                catch
                {
                    throw;
                }
                finally
                {
                    // Clear the cache for this thread.
                    cache.Clear(localBatchId);
                }
            }
        public DataSet Calculate(AnalyzerTaskResult analyzerResult)
        {
            #region Argument exceptions

            if (analyzerResult == null)
            {
                throw new ArgumentNullException("analyzerResult");
            }

            #endregion

            var store = new DataSet();

            EventsNotifier.Instance.Notify(ProcedureEvents.ProcedureAnalyzeStepCalculateResult);

            store.Tables.Add(_procedureContext.ToExecutionInfoTable());

            switch (_procedureContext.ExecutionMode)
            {
            case ProcedureExecutionMode.Live:
                var bag = new ConcurrentBag <DataTable>();

                using (var task = Task.Factory.StartNew(() =>
                {
                    Task.Factory.StartNew(() => bag.Add(analyzerResult.Profiler.ToEnginePerformanceTable()), TaskCreationOptions.AttachedToParent);
                    Task.Factory.StartNew(() => bag.Add(analyzerResult.Profiler.ToAggregationsReadTable()), TaskCreationOptions.AttachedToParent);
                    Task.Factory.StartNew(() => bag.Add(analyzerResult.Profiler.ToPartitionsReadTable()), TaskCreationOptions.AttachedToParent);
                    Task.Factory.StartNew(() => bag.Add(analyzerResult.Profiler.ToCachesReadTable()), TaskCreationOptions.AttachedToParent);

                    store.Tables.Add(analyzerResult.QueryResult.ToQueryResultTable());
                    foreach (var table in analyzerResult.Performance.ToTables())
                    {
                        store.Tables.Add(table);
                    }
                    foreach (var table in analyzerResult.Profiler.ToTables())
                    {
                        store.Tables.Add(table);
                    }
                }))
                {
                    task.Wait();
                }

                foreach (var table in bag)
                {
                    store.Tables.Add(table);
                }
                break;

            case ProcedureExecutionMode.Batch:
                BatchHelper.Calculate(_procedureContext);
                break;
            }

            EventsNotifier.Instance.Notify(ProcedureEvents.ProcedureAnalyzeStepSendResult);
            store.Tables.Add(EventsNotifier.Instance.NotifiedEvents.ToProcedureEventTable());

            return(store);
        }
Ejemplo n.º 5
0
        public void GetSortModel(int value, int expectedSkip, int expectedTake)
        {
            var actual = BatchHelper.GetSortModel(value);

            Assert.Equal(expectedSkip, actual.Skip);
            Assert.Equal(expectedTake, actual.Take);
            Assert.Equal(expectedSkip + expectedTake, actual.RecordRequestNumber);
        }
Ejemplo n.º 6
0
            /// <summary>
            /// Executes the authentication operation asynchronous with a single result.
            /// </summary>
            /// <typeparam name="T">The type of the result.</typeparam>
            /// <param name="operation">The operation name.</param>
            /// <param name="operationParameters">The operation parameters.</param>
            /// <returns>No return.</returns>
            public async Task <T> ExecuteAuthenticationOperationSingleResultAsync <T>(string operation, params OperationParameter[] operationParameters)
            {
                if (BatchHelper.IsInBatchMode(this.batchId))
                {
                    throw new NotSupportedException("Authentication operations are not supported in batch mode.");
                }

                return(await this.ExecuteAsync(null, operation, async (context) => await context.ExecuteAuthenticationOperationSingleResultAsync <T>(operation, operationParameters)));
            }
Ejemplo n.º 7
0
        public void DbConnectionTest()
        {
            List <MSH> msh;

            using (ExportQueueTable exp = new ExportQueueTable(GeneralHelper.ConnectionString, 0, ProcessStageFilterEnum.Lookup, ProcessStateFilterEnum.Failed, "ResolveHealthConditions"))
            {
                msh = BatchHelper.LoadBatches(exp.Items_ExportQueue);
            }
        }
        public override List <MSH> GetMSH()
        {
            const int NO_OF_RECORDS = 25;

            using (ExportQueueTable exp = new ExportQueueTable(GeneralHelper.ConnectionString, 0, ProcessStageFilterEnum.Lookup, ProcessStateFilterEnum.Failed, "ResolveHealthConditions"))
            {
                // Return 25 for now
                return(BatchHelper.LoadBatches(exp.Items_ExportQueue.Take(NO_OF_RECORDS).ToList()));
            }
        }
        private async Task <BulkWriteOperationResult> ExecuteBatchesAsync(RetryableWriteContext context, CancellationToken cancellationToken)
        {
            var helper = new BatchHelper(_requests, _writeConcern, _isOrdered);

            foreach (var batch in helper.GetBatches())
            {
                batch.Result = await ExecuteBatchAsync(context, batch, cancellationToken).ConfigureAwait(false);
            }
            return(helper.CreateFinalResultOrThrow(context.Channel));
        }
Ejemplo n.º 10
0
        public async Task <BulkWriteOperationResult> ExecuteAsync(RetryableWriteContext context, CancellationToken cancellationToken)
        {
            var helper = new BatchHelper(this, context.Channel);

            foreach (var batch in helper.GetBatches())
            {
                batch.Result = await EmulateSingleRequestAsync(context.Channel, batch.Request, batch.OriginalIndex, cancellationToken).ConfigureAwait(false);
            }
            return(helper.GetFinalResultOrThrow());
        }
        private BulkWriteOperationResult ExecuteBatches(RetryableWriteContext context, CancellationToken cancellationToken)
        {
            var helper = new BatchHelper(_requests, _writeConcern, _isOrdered);

            foreach (var batch in helper.GetBatches())
            {
                batch.Result = ExecuteBatch(context, batch, cancellationToken);
            }
            return(helper.CreateFinalResultOrThrow(context.Channel));
        }
Ejemplo n.º 12
0
            /// <summary>
            /// Updates the specified entity set.
            /// </summary>
            /// <typeparam name="T">The type of of entity.</typeparam>
            /// <param name="entitySet">The entity set.</param>
            /// <param name="entity">The entity.</param>
            /// <returns>
            /// The object of type T.
            /// </returns>
            public async Task <T> Update <T>(string entitySet, T entity)
                where T : CommerceEntity
            {
                if (BatchHelper.IsInBatchMode(this.batchId))
                {
                    throw new NotSupportedException("Update operation is not supported in batch mode, only Read, ReadAll, and Functions are supported.");
                }

                return(await this.ExecuteAsync(entitySet, ActionNames.Update, async (context) => await context.Update <T>(entitySet, entity)));
            }
Ejemplo n.º 13
0
        // public methods
        public BulkWriteOperationResult Execute(RetryableWriteContext context, CancellationToken cancellationToken)
        {
            var helper = new BatchHelper(this, context.Channel);

            foreach (var batch in helper.GetBatches())
            {
                batch.Result = EmulateSingleRequest(context.Channel, batch.Request, batch.OriginalIndex, cancellationToken);
            }
            return(helper.GetFinalResultOrThrow());
        }
        private async Task <BulkWriteOperationResult> ExecuteBatchesAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var decoratedRequests = DecorateRequests(_requests);
            var helper            = new BatchHelper(decoratedRequests, _writeConcern, _isOrdered);

            foreach (var batch in helper.Batches)
            {
                batch.Result = await ExecuteBatchAsync(channel, batch.RequestSource, batch.OriginalIndex, cancellationToken).ConfigureAwait(false);
            }
            return(helper.CreateFinalResultOrThrow(channel));
        }
Ejemplo n.º 15
0
        private BulkWriteOperationResult ExecuteBatches(IChannelHandle channel, ICoreSessionHandle session, CancellationToken cancellationToken)
        {
            var decoratedRequests = DecorateRequests(_requests);
            var helper            = new BatchHelper(decoratedRequests, _writeConcern, _isOrdered);

            foreach (var batch in helper.Batches)
            {
                batch.Result = ExecuteBatch(channel, session, batch.RequestSource, batch.OriginalIndex, cancellationToken);
            }
            return(helper.CreateFinalResultOrThrow(channel));
        }
        public async Task <List <ClientTradeEntity> > GetTradesByLimitOrderKeysAsync(IEnumerable <string> limitOrderIds)
        {
            var result = await BatchHelper.BatchGetDataAsync(
                null,
                _partitionKey,
                limitOrderIds,
                _storage,
                _log);

            return(result);
        }
Ejemplo n.º 17
0
        private void BatchImportForm_Load(object sender, EventArgs e)
        {
            BatchHelper h = new BatchHelper(MainForm.CurrentProject, _records, "UDTService.DML.Command");

            h.Size = 200;
            this.progressBar1.Maximum = h.BatchCount;
            this.progressBar1.Value   = 0;
            h.CompleteOne            += new EventHandler(h_CompleteOne);
            h.CompleteAll            += new EventHandler(h_CompleteAll);
            h.OccuredError           += new System.IO.ErrorEventHandler(h_OccuredError);
            h.Start();
        }
Ejemplo n.º 18
0
 /// <inheritdoc/>
 public async Task <BulkWriteOperationResult> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
 {
     using (EventContext.BeginOperation())
         using (var context = await RetryableWriteContext.CreateAsync(binding, _retryRequested, cancellationToken).ConfigureAwait(false))
         {
             context.DisableRetriesIfAnyWriteRequestIsNotRetryable(_requests);
             var helper = new BatchHelper(_requests, _isOrdered, _writeConcern);
             foreach (var batch in helper.GetBatches())
             {
                 batch.Result = await ExecuteBatchAsync(context, batch, cancellationToken).ConfigureAwait(false);
             }
             return(helper.GetFinalResultOrThrow(context.Channel.ConnectionDescription.ConnectionId));
         }
 }
Ejemplo n.º 19
0
 protected virtual IEnumerable <SortModel> GetSortModels(DataLoading dataLoading, int recordRequestNumber)
 {
     if (dataLoading == DataLoading.BatchLoad)
     {
         foreach (var batch in BatchHelper.GetSortModels(recordRequestNumber))
         {
             yield return(batch);
         }
     }
     else
     {
         yield return(new SortModel(recordRequestNumber, int.MaxValue));
     }
 }
Ejemplo n.º 20
0
            /// <summary>
            /// Executes the authentication operation asynchronous with no result.
            /// </summary>
            /// <param name="operation">The operation name.</param>
            /// <param name="operationParameters">The operation parameters.</param>
            /// <returns>No return.</returns>
            public async Task ExecuteAuthenticationOperationAsync(string operation, params OperationParameter[] operationParameters)
            {
                if (BatchHelper.IsInBatchMode(this.batchId))
                {
                    throw new NotSupportedException("Authentication operations are not supported in batch mode.");
                }

                if (this.authenticationProvider == null)
                {
                    throw new NotSupportedException("Authentication provider is not set.");
                }

                await this.authenticationProvider.ExecuteAuthenticationSingleResultOperationAsync <object>(operation, operationParameters);
            }
 /// <inheritdoc/>
 public async Task <BulkWriteOperationResult> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
 {
     using (EventContext.BeginOperation())
         using (var channelSource = await binding.GetWriteChannelSourceAsync(cancellationToken).ConfigureAwait(false))
             using (var channel = await channelSource.GetChannelAsync(cancellationToken).ConfigureAwait(false))
             {
                 var helper = new BatchHelper(this, channel);
                 foreach (var batch in helper.GetBatches())
                 {
                     batch.Result = await ExecuteBatchAsync(channel, channelSource.Session, batch.Run, batch.IsLast, cancellationToken).ConfigureAwait(false);
                 }
                 return(helper.GetFinalResultOrThrow());
             }
 }
 // public methods
 /// <inheritdoc/>
 public BulkWriteOperationResult Execute(IWriteBinding binding, CancellationToken cancellationToken)
 {
     using (EventContext.BeginOperation())
         using (var channelSource = binding.GetWriteChannelSource(cancellationToken))
             using (var channel = channelSource.GetChannel(cancellationToken))
             {
                 var helper = new BatchHelper(this, channel);
                 foreach (var batch in helper.GetBatches())
                 {
                     batch.Result = ExecuteBatch(channel, channelSource.Session, batch.Run, batch.IsLast, cancellationToken);
                 }
                 return(helper.GetFinalResultOrThrow());
             }
 }
Ejemplo n.º 23
0
 public ActionResult Launch(string filePath)
 {
     try {
         CheckFilePath(filePath);
         var dataFile = new DataFile(filePath, (int)StatusHelper.Processing);
         Repositories.Files.Add(dataFile);
         Repositories.SaveChanges();
         BatchHelper.StartProcessing(dataFile);
         AddMessage(SUCCESS, Batch.Success_Launch);
     } catch (FunctionalException e) {
         AddMessage(ERROR, e.Message);
     }
     return(RedirectToAction("Index"));
 }
 // public methods
 /// <inheritdoc/>
 public BulkWriteOperationResult Execute(IWriteBinding binding, CancellationToken cancellationToken)
 {
     using (EventContext.BeginOperation())
         using (var context = RetryableWriteContext.Create(binding, _retryRequested, cancellationToken))
         {
             EnsureHintIsSupportedIfAnyRequestHasHint();
             context.DisableRetriesIfAnyWriteRequestIsNotRetryable(_requests);
             var helper = new BatchHelper(_requests, _isOrdered, _writeConcern);
             foreach (var batch in helper.GetBatches())
             {
                 batch.Result = ExecuteBatch(context, batch, cancellationToken);
             }
             return(helper.GetFinalResultOrThrow(context.Channel.ConnectionDescription.ConnectionId));
         }
 }
Ejemplo n.º 25
0
 public ActionResult Continue(int idProcess)
 {
     try {
         CheckId(idProcess);
         DataFile dataFile = Repositories.Files.FindDistinctBy(x => x.Id == idProcess);
         if (dataFile != null)
         {
             BatchHelper.StartProcessing(dataFile);
             AddMessage(SUCCESS, Batch.Success_Continue);
         }
     } catch (FunctionalException e) {
         AddMessage(ERROR, e.Message);
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 26
0
            /// <summary>
            /// Deletes the specified entity set.
            /// </summary>
            /// <typeparam name="T">The type of of entity.</typeparam>
            /// <param name="entitySet">The entity set.</param>
            /// <param name="entity">The entity.</param>
            /// <returns>No return.</returns>
            public async Task Delete <T>(string entitySet, T entity)
                where T : ICommerceEntity
            {
                if (BatchHelper.IsInBatchMode(this.batchId))
                {
                    throw new NotSupportedException("Delete operation is not supported in batch mode, only Read, ReadAll, and Functions are supported.");
                }

                string result = await Task.Run(async() => await AdaptorCaller.ExecuteAsync(GetRequestUri(typeof(T).Name, "Delete", new OperationParameter()
                {
                    Name = "entity", Value = entity
                })));

                result = AdaptorCaller.RemoveCommerceRuntimePrefix(result);

                TryThrowAsCommerceException(result);
            }
Ejemplo n.º 27
0
        public void FirstSetupTest()
        {
            String dbConnection = ConfigurationManager.AppSettings["HL7ReportableDB"];

            List <MSH> msh;

            using (ExportQueueTable exp = new ExportQueueTable(dbConnection, 0, ProcessStageFilterEnum.Lookup, ProcessStateFilterEnum.Failed, "ResolveHealthConditions"))
            {
                msh = BatchHelper.LoadBatches(exp.Items_ExportQueue);
            }

            var result = TreeViewHelper.Transform(msh);

            TreeViewData td = new TreeViewData()
            {
                MSHData = msh, TreeData = result
            };
        }
Ejemplo n.º 28
0
        public void GetSortModelsTest(int value, int expectedBatchSize, int expectedFirstStepSize, int expectedNextStepSize)
        {
            var actualList = BatchHelper.GetSortModels(value).ToList();

            Assert.Equal(2, actualList.Count);
            var actualBatchSize = actualList.Max(x => x.RecordRequestNumber) - actualList.Min(x => x.Skip);

            Assert.Equal(expectedBatchSize, actualBatchSize);

            var actualFirstBatch = actualList.OrderBy(x => x.Skip).First();

            Assert.Equal(value, actualFirstBatch.Skip);
            Assert.Equal(expectedFirstStepSize, actualFirstBatch.Take);

            var actualLastBatch = actualList.OrderByDescending(x => x.Skip).First();

            Assert.Equal(value + actualFirstBatch.Take, actualLastBatch.Skip);
            Assert.Equal(expectedNextStepSize, actualLastBatch.Take);
        }
Ejemplo n.º 29
0
        void h_OccuredError(object sender, System.IO.ErrorEventArgs e)
        {
            lblInfo.Text = "批次發生錯誤 !!";
            Application.DoEvents();

            MessageBox.Show("匯入時發生錯誤 : \n" + e.GetException().Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);

            lblInfo.Text = "取消作業中 .....";
            Application.DoEvents();

            BatchHelper h = sender as BatchHelper;

            h.Cancel();

            lblInfo.Text = "取消完畢 !!";
            Application.DoEvents();

            this.Close();
        }
Ejemplo n.º 30
0
            /// <summary>
            /// Executes the authentication operation asynchronous with no result.
            /// </summary>
            /// <typeparam name="T">The type of the result.</typeparam>
            /// <param name="operation">The operation name.</param>
            /// <param name="operationParameters">The operation parameters.</param>
            /// <returns>No return.</returns>
            public async Task <T> ExecuteAuthenticationOperationSingleResultAsync <T>(string operation, params OperationParameter[] operationParameters)
            {
                if (BatchHelper.IsInBatchMode(this.batchId))
                {
                    throw new NotSupportedException("Authentication operations are not supported in batch mode.");
                }

                if (this.authenticationProvider == null)
                {
                    throw new NotSupportedException("Authentication provider is not set.");
                }

                T result = await this.authenticationProvider.ExecuteAuthenticationSingleResultOperationAsync <T>(operation, operationParameters);

                if (string.Equals(operation, CommerceAuthenticationProvider.AcquireTokenActionName))
                {
                    this.SetUserToken(result as UserToken);
                }

                return(result);
            }
 public async Task<BulkWriteOperationResult> ExecuteAsync(IChannelHandle channel, CancellationToken cancellationToken)
 {
     var helper = new BatchHelper(this, channel);
     foreach (var batch in helper.GetBatches())
     {
         batch.Result = await EmulateSingleRequestAsync(channel, batch.Request, batch.OriginalIndex, cancellationToken).ConfigureAwait(false);
     }
     return helper.GetFinalResultOrThrow();
 }
 // public methods
 public BulkWriteOperationResult Execute(IChannelHandle channel, CancellationToken cancellationToken)
 {
     var helper = new BatchHelper(this, channel);
     foreach (var batch in helper.GetBatches())
     {
         batch.Result = EmulateSingleRequest(channel, batch.Request, batch.OriginalIndex, cancellationToken);
     }
     return helper.GetFinalResultOrThrow();
 }