Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommerceRuntimeContext"/> class.
 /// </summary>
 /// <param name="getCrtConfigByHostFunc">The action to get CommerceRuntimeConfiguration object for a specific host.</param>
 /// <param name="specifiedRoles">The specified role collection.</param>
 /// <param name="authenticationProvider">The authentication provider.</param>
 /// <remarks>Once specified role collection is provided, the commerce runtime will be constructed by using these roles plus default unit number from the configuration file.</remarks>
 public CommerceRuntimeContext(Func <string, CommerceRuntimeConfiguration> getCrtConfigByHostFunc, string[] specifiedRoles, CommerceAuthenticationProvider authenticationProvider)
 {
     AdaptorCaller.SetGetConfigurationFunc(getCrtConfigByHostFunc);
     CommerceRuntimeManager.SpecifiedRoles = specifiedRoles;
     this.userToken = null;
     this.authenticationProvider = authenticationProvider;
 }
Example #2
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>());
                }
            }
Example #3
0
            /// <summary>
            /// Executes the operation asynchronous with no result.
            /// </summary>
            /// <param name="entitySet">The entity set.</param>
            /// <param name="entitySetTypeName">The entity set type name.</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="operationParameters">The operation parameters.</param>
            /// <returns>No return.</returns>
            public async Task ExecuteOperationAsync(string entitySet, string entitySetTypeName, string operation, bool isAction, params OperationParameter[] operationParameters)
            {
                string result = await Task.Run(async() => await AdaptorCaller.ExecuteAsync(GetRequestUri(entitySetTypeName, operation, operationParameters)));

                result = AdaptorCaller.RemoveCommerceRuntimePrefix(result);

                TryThrowAsCommerceException(result);
            }
Example #4
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);
            }
Example #5
0
            /// <summary>
            /// Commits the batch request.
            /// </summary>
            /// <param name="requests">The cached requests.</param>
            /// <param name="tasks">The cached tasks to return back the result.</param>
            /// <returns>A Task.</returns>
            public async Task ExecuteBatchAsync(List <ParametersGroup> requests, List <TaskCompletionSource <object> > tasks)
            {
                if (requests == null)
                {
                    throw new ArgumentNullException("requests");
                }

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

                if (requests.Count != tasks.Count)
                {
                    throw new ArgumentException("The count of cached requests does not equal to the count of cached tasks.");
                }

                for (int i = 0; i < requests.Count; ++i)
                {
                    string result = await Task.Run(async() => await AdaptorCaller.ExecuteAsync(GetRequestUri(requests[i].EntitySetType, requests[i].OperationName, requests[i].QueryResultSettings, requests[i].OperationParameters)));

                    tasks[i].SetResult(AdaptorCaller.RemoveCommerceRuntimePrefix(result));
                }
            }
Example #6
0
 /// <summary>
 /// Processes the request.
 /// </summary>
 /// <param name="allInOneUrl">A URL string to store CRT API call information.</param>
 /// <returns>The result as string.</returns>
 public static string Execute(string allInOneUrl)
 {
     return(AdaptorCaller.ExecuteAsync(allInOneUrl).Result);
 }