Esempio n. 1
0
        /// <summary>
        /// 获取Rpc调用器
        /// </summary>
        /// <param name="method">JSON-RPC方法名</param>
        /// <param name="option">自定义选项</param>
        private static RpcInvoker GetRpcInvoker(string method, RpcOption option)
        {
            string serviceAddress = (option != null && !string.IsNullOrWhiteSpace(option.ServiceAddress)) ? option.ServiceAddress : Configmanager.GetServiceUrlFromConfig
                                        (method);

            RpcInvoker invoker = null;

            if (string.Equals(serviceAddress, "local", StringComparison.InvariantCultureIgnoreCase))
            {
                invoker = new LocalRpcInvoker();
            }
            else if (serviceAddress.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) ||
                     serviceAddress.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
            {
                invoker = new HttpRpcInvoker();
            }
            else
            {
                throw new NotSupportedException("不支持的Rpc服务地址类型:" + serviceAddress);
            }

            invoker.ServiceAddress = serviceAddress;
            invoker.Option         = option;
            return(invoker);
        }
        private async Task <RpcInvoker.RpcResponse <TResult> > GetWithSafeAsync <TResult, TServerResponse>(Func <TServerResponse, TResult> converter, Func <Mage_Api_Model_Server_Wsi_HandlerPortTypeClient, string, Task <TServerResponse> > action, int abortAfter, bool suppressException = false, [CallerMemberName] string callerName = null) where TServerResponse : new() where TResult : class
        {
            var withSafeAsync = await RpcInvoker.SuppressExceptions(
                async() => await this.GetWithUnsafeAsync( converter, action, abortAfter ).ConfigureAwait(false)
                ).ConfigureAwait(false);

            return(withSafeAsync);
        }
        public virtual async Task <IEnumerable <RpcInvoker.RpcRequestResponse <PutStockItem, object> > > PutStockItemsAsync(List <PutStockItem> stockItems, Mark mark = null)
        {
            var methodParameters = stockItems.ToJson();

            try
            {
                var stockItemsProcessed = stockItems.Select(x =>
                {
                    var catalogInventoryStockItemUpdateEntity = (x.Qty > 0) ?
                                                                new catalogInventoryStockItemUpdateEntity()
                    {
                        is_in_stock = 1, is_in_stockSpecified = true, qty = x.Qty.ToString()
                    } :
                    new catalogInventoryStockItemUpdateEntity()
                    {
                        is_in_stock = 0, is_in_stockSpecified = false, qty = x.Qty.ToString()
                    };
                    return(Tuple.Create(x, catalogInventoryStockItemUpdateEntity));
                });

                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 1800000;

                var privateClient = this._clientFactory.GetClient();

                RpcInvoker.RpcResponse <catalogInventoryStockItemMultiUpdateResponse> serverResponse = null;
                await ActionPolicies.GetAsync.Do(async() =>
                {
                    var statusChecker = new StatusChecker(maxCheckCount);
                    TimerCallback tcb = statusChecker.CheckStatus;

                    privateClient = this._clientFactory.RefreshClient(privateClient);

                    var sessionId = await this.GetSessionId().ConfigureAwait(false);

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                    {
                        MagentoLogger.LogTraceStarted(this.CreateMethodCallInfo(methodParameters, mark));

                        var catalogInventoryStockItemUpdateEntities = stockItemsProcessed.Select(x => x.Item2).ToArray();

                        serverResponse = await RpcInvoker.SuppressExceptions(async() => await privateClient.catalogInventoryStockItemMultiUpdateAsync(sessionId.SessionId, stockItemsProcessed.Select(x => x.Item1.ProductId).ToArray(), catalogInventoryStockItemUpdateEntities).ConfigureAwait(false)).ConfigureAwait(false);

                        var updateBriefInfo = string.Format("{{Success:{0}}}", serverResponse.Result.result);
                        MagentoLogger.LogTraceEnded(CreateMethodCallInfo(methodParameters, mark: mark, methodResult: updateBriefInfo));
                    }
                }).ConfigureAwait(false);

                var result = stockItems.Select(y => new RpcInvoker.RpcRequestResponse <PutStockItem, object>(y, new RpcInvoker.RpcResponse <object>(serverResponse?.ErrorCode ?? RpcInvoker.SoapErrorCode.Unknown, serverResponse?.Result, serverResponse?.Exception)));
                return(result);
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException($"An error occured during PutStockItemsAsync({methodParameters})", exc);
            }
        }
Esempio n. 4
0
 public void Reset()
 {
     if (_enumeratorLazy.IsValueCreated)
     {
         _enumeratorLazy.Value.Reset();
     }
     else
     {
         RpcInvoker.CallMethod(_resetMethodName, _collectionID);
     }
 }
Esempio n. 5
0
 public void Dispose()
 {
     if (_enumeratorLazy.IsValueCreated)
     {
         _enumeratorLazy.Value.Dispose();
     }
     else
     {
         RpcInvoker.CallMethod(_disposeMethodName, _collectionID);
     }
 }
Esempio n. 6
0
        public bool MoveNext()
        {
            var entity = RpcInvoker.CallMethod <CollectionItemEntity>(_nextMethodName, _collectionID);

            if (entity == null || !entity.Success)
            {
                return(false);
            }

            Current = (TItem)entity.Item;
            return(true);
        }
Esempio n. 7
0
 public static Guid?Login(String loginName, String password, bool encryptedPassword)
 {
     try
     {
         return(RpcInvoker.InvokeMethod <Guid?>(loginName, password, encryptedPassword));
     }
     catch (Exception ex)
     {
         LogError.Log("ErrorLog_PinService_", ex, stream =>
         {
             stream.WriteLine(String.Format("HMIS Login Error: {0}", ex.Message
                                            ));
         });
         throw;
     }
 }
Esempio n. 8
0
 public static PersonContract GetPersonInfo(Guid loginToken, Guid?moduleID, String personalID)
 {
     try
     {
         return(RpcInvoker.InvokeMethod <PersonContract>(loginToken, moduleID, personalID));
     }
     catch (Exception ex)
     {
         LogError.Log("ErrorLog_PinService_", ex, stream =>
         {
             stream.WriteLine(String.Format("HMIS GetPersonInfo Error: {0}", ex.Message
                                            ));
         });
         throw;
     }
 }
Esempio n. 9
0
 public static bool IsTokenActual(Guid token)
 {
     return(RpcInvoker.InvokeMethod <bool>(token));
 }
Esempio n. 10
0
 public static void Logout(Guid token)
 {
     RpcInvoker.InvokeMethod(token);
 }
Esempio n. 11
0
 public static Dictionary <String, String> GetUserAttributesDictionary(Guid token, Guid userID, Guid projectID)
 {
     return(RpcInvoker.InvokeMethod <Dictionary <String, String> >(token, userID, projectID));
 }
Esempio n. 12
0
 public static PermissionContract GetResourcePermission(Guid token, String resourcePath)
 {
     return(RpcInvoker.InvokeMethod <PermissionContract>(token, resourcePath));
 }
Esempio n. 13
0
 public static PasswordChangeResultEnum ChangePassword(Guid token, String newPassword, String oldPassword)
 {
     return(RpcInvoker.InvokeMethod <PasswordChangeResultEnum>(token, newPassword, oldPassword));
 }
Esempio n. 14
0
 public static List <UserAttributeContract> GetUserAttributes(Guid token, Guid userID, Guid projectID)
 {
     return(RpcInvoker.InvokeMethod <List <UserAttributeContract> >(token, userID, projectID));
 }
Esempio n. 15
0
 public static List <GroupAttributeContract> GetGroupAttributes(Guid token, Guid groupID)
 {
     return(RpcInvoker.InvokeMethod <List <GroupAttributeContract> >(token, groupID));
 }
        public virtual async Task <IEnumerable <RpcInvoker.RpcRequestResponse <PutStockItem, object> > > PutStockItemsAsync(List <PutStockItem> stockItems, Mark mark = null)
        {
            var methodParameters = stockItems.ToJson();

            try
            {
                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 1800000;

                var magentoStockItemsResponse = await this.GetStockItemsOldAsync(stockItems.Select(item => item.Sku)).ConfigureAwait(false);

                var magentoStockItems = magentoStockItemsResponse.Responses.Select(item => item as CatalogInventoryDataStockItemInterface).Where(item => item != null);

                var privateClient = this._clientFactory.CreateMagentoCatalogInventoryStockServiceClient();

                var res = new ConcurrentQueue <RpcInvoker.RpcRequestResponse <PutStockItem, object> >();

                await stockItems.DoInBatchAsync(10, async x =>
                {
                    await ActionPolicies.GetAsync.Do(async() =>
                    {
                        var statusChecker = new StatusChecker(maxCheckCount);
                        TimerCallback tcb = statusChecker.CheckStatus;

                        privateClient = this._clientFactory.RefreshMagentoCatalogInventoryStockServiceClient(privateClient);

                        using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                        {
                            MagentoLogger.LogTraceStarted(this.CreateMethodCallInfo(methodParameters, mark: mark));

                            var productId = int.Parse(x.ProductId);
                            var catalogInventoryDataStockItemInterface = magentoStockItems.FirstOrDefault(i => i.productId == productId);
                            if (catalogInventoryDataStockItemInterface == null)
                            {
                                MagentoLogger.LogTrace($"PutStockItemsAsync. Can't find StockItem with ProductId={x.ProductId} (SKU={x.Sku}).", mark);
                                catalogInventoryDataStockItemInterface = new CatalogInventoryDataStockItemInterface
                                {
                                    productId                      = productId,
                                    productIdSpecified             = true,
                                    isInStock                      = false,
                                    isQtyDecimal                   = false,
                                    showDefaultNotificationMessage = false,
                                    useConfigMinQty                = true,
                                    minQty = 0,
                                    useConfigMinSaleQty     = 1,
                                    minSaleQty              = 1,
                                    useConfigMaxSaleQty     = true,
                                    maxSaleQty              = 10000,
                                    useConfigBackorders     = true,
                                    backorders              = 0,
                                    useConfigNotifyStockQty = true,
                                    notifyStockQty          = 1,
                                    useConfigQtyIncrements  = true,
                                    qtyIncrements           = 0,
                                    useConfigEnableQtyInc   = false,
                                    enableQtyIncrements     = false,
                                    useConfigManageStock    = true,
                                    manageStock             = true,
                                    //lowStockDate = "2016-02-29 20:48:26",
                                    isDecimalDivided       = false,
                                    stockStatusChangedAuto = 1
                                };
                            }
                            catalogInventoryDataStockItemInterface.qty        = x.Qty.ToString();
                            catalogInventoryDataStockItemInterface.isInStock |= x.Qty > 0;

                            var catalogInventoryStockRegistryV1UpdateStockItemBySkuRequest = new CatalogInventoryStockRegistryV1UpdateStockItemBySkuRequest()
                            {
                                productSku = x.Sku,
                                stockItem  = catalogInventoryDataStockItemInterface
                            };

                            RpcInvoker.IRpcResponse <object> response = await RpcInvoker.SuppressExceptions(async() => await privateClient.catalogInventoryStockRegistryV1UpdateStockItemBySkuAsync(catalogInventoryStockRegistryV1UpdateStockItemBySkuRequest).ConfigureAwait(false)).ConfigureAwait(false);
                            var reqResp = new RpcInvoker.RpcRequestResponse <PutStockItem, object>(x, response);
                            res.Enqueue(reqResp);
                        }
                    }).ConfigureAwait(false);
                }).ConfigureAwait(false);

                MagentoLogger.LogTraceEnded(this.CreateMethodCallInfo(methodParameters, mark: mark, methodResult: res.ToJson()));
                //return errors count instead of true false;
                return(res);
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException($"An error occured during PutStockItemsAsync({methodParameters})", exc);
            }
        }
Esempio n. 17
0
        private IEnumerator <Object> LoadWhole()
        {
            var list = RpcInvoker.CallMethod <List <Object> >(_loadWholeMethodName, _collectionID);

            return(list.GetEnumerator());
        }
Esempio n. 18
0
 public static List <UserContract> GetAllUsers(Guid token, bool deleteds)
 {
     return(RpcInvoker.InvokeMethod <List <UserContract> >(token, deleteds));
 }
Esempio n. 19
0
 public static UserContract GetUser(Guid token, Guid userID)
 {
     return(RpcInvoker.InvokeMethod <UserContract>(token, userID));
 }
Esempio n. 20
0
 public static List <ProjectContract> GetProjects()
 {
     return(RpcInvoker.InvokeMethod <List <ProjectContract> >());
 }
Esempio n. 21
0
 public static Guid?Login(String loginName, String password, bool encryptedPassword)
 {
     return(RpcInvoker.InvokeMethod <Guid?>(loginName, password, encryptedPassword));
 }
Esempio n. 22
0
 public static List <GroupContract> GetUserGroups(Guid token, Guid userID, Guid projectID)
 {
     return(RpcInvoker.InvokeMethod <List <GroupContract> >(token, userID, projectID));
 }
Esempio n. 23
0
 public static List <UserContract> GetGroupUsers(Guid token, Guid groupID)
 {
     return(RpcInvoker.InvokeMethod <List <UserContract> >(token, groupID));
 }
Esempio n. 24
0
 public static List <ProjectContract> GetProjectByUserToken(Guid token)
 {
     return(RpcInvoker.InvokeMethod <List <ProjectContract> >(token));
 }
Esempio n. 25
0
 public static List <AttributeValueContract> GetAttributeValues(Guid token, Guid parentID)
 {
     return(RpcInvoker.InvokeMethod <List <AttributeValueContract> >(token, parentID));
 }
Esempio n. 26
0
 public static List <MessageContract> GetMessages(Guid token, Guid?projectID)
 {
     return(RpcInvoker.InvokeMethod <List <MessageContract> >(token, projectID));
 }
Esempio n. 27
0
 public static List <PermissionContract> GetAllResourcesPermissions(Guid token, Guid?projectID)
 {
     return(RpcInvoker.InvokeMethod <List <PermissionContract> >(token, projectID));
 }
Esempio n. 28
0
 public static bool HasMessages(Guid token, Guid?projectID)
 {
     return(RpcInvoker.InvokeMethod <bool>(token, projectID));
 }
Esempio n. 29
0
 public static Dictionary <Guid, Dictionary <String, String> > GetAllUsersGlobalAttribetes(Guid token, bool deleteds)
 {
     return(RpcInvoker.InvokeMethod <Dictionary <Guid, Dictionary <String, String> > >(token, deleteds));
 }
Esempio n. 30
0
 public static UserContract GetCurrentUser(Guid token)
 {
     return(RpcInvoker.InvokeMethod <UserContract>(token));
 }