/// <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); } }
public void Reset() { if (_enumeratorLazy.IsValueCreated) { _enumeratorLazy.Value.Reset(); } else { RpcInvoker.CallMethod(_resetMethodName, _collectionID); } }
public void Dispose() { if (_enumeratorLazy.IsValueCreated) { _enumeratorLazy.Value.Dispose(); } else { RpcInvoker.CallMethod(_disposeMethodName, _collectionID); } }
public bool MoveNext() { var entity = RpcInvoker.CallMethod <CollectionItemEntity>(_nextMethodName, _collectionID); if (entity == null || !entity.Success) { return(false); } Current = (TItem)entity.Item; return(true); }
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; } }
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; } }
public static bool IsTokenActual(Guid token) { return(RpcInvoker.InvokeMethod <bool>(token)); }
public static void Logout(Guid token) { RpcInvoker.InvokeMethod(token); }
public static Dictionary <String, String> GetUserAttributesDictionary(Guid token, Guid userID, Guid projectID) { return(RpcInvoker.InvokeMethod <Dictionary <String, String> >(token, userID, projectID)); }
public static PermissionContract GetResourcePermission(Guid token, String resourcePath) { return(RpcInvoker.InvokeMethod <PermissionContract>(token, resourcePath)); }
public static PasswordChangeResultEnum ChangePassword(Guid token, String newPassword, String oldPassword) { return(RpcInvoker.InvokeMethod <PasswordChangeResultEnum>(token, newPassword, oldPassword)); }
public static List <UserAttributeContract> GetUserAttributes(Guid token, Guid userID, Guid projectID) { return(RpcInvoker.InvokeMethod <List <UserAttributeContract> >(token, userID, projectID)); }
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); } }
private IEnumerator <Object> LoadWhole() { var list = RpcInvoker.CallMethod <List <Object> >(_loadWholeMethodName, _collectionID); return(list.GetEnumerator()); }
public static List <UserContract> GetAllUsers(Guid token, bool deleteds) { return(RpcInvoker.InvokeMethod <List <UserContract> >(token, deleteds)); }
public static UserContract GetUser(Guid token, Guid userID) { return(RpcInvoker.InvokeMethod <UserContract>(token, userID)); }
public static List <ProjectContract> GetProjects() { return(RpcInvoker.InvokeMethod <List <ProjectContract> >()); }
public static Guid?Login(String loginName, String password, bool encryptedPassword) { return(RpcInvoker.InvokeMethod <Guid?>(loginName, password, encryptedPassword)); }
public static List <GroupContract> GetUserGroups(Guid token, Guid userID, Guid projectID) { return(RpcInvoker.InvokeMethod <List <GroupContract> >(token, userID, projectID)); }
public static List <UserContract> GetGroupUsers(Guid token, Guid groupID) { return(RpcInvoker.InvokeMethod <List <UserContract> >(token, groupID)); }
public static List <ProjectContract> GetProjectByUserToken(Guid token) { return(RpcInvoker.InvokeMethod <List <ProjectContract> >(token)); }
public static List <AttributeValueContract> GetAttributeValues(Guid token, Guid parentID) { return(RpcInvoker.InvokeMethod <List <AttributeValueContract> >(token, parentID)); }
public static List <MessageContract> GetMessages(Guid token, Guid?projectID) { return(RpcInvoker.InvokeMethod <List <MessageContract> >(token, projectID)); }
public static List <PermissionContract> GetAllResourcesPermissions(Guid token, Guid?projectID) { return(RpcInvoker.InvokeMethod <List <PermissionContract> >(token, projectID)); }
public static bool HasMessages(Guid token, Guid?projectID) { return(RpcInvoker.InvokeMethod <bool>(token, projectID)); }
public static Dictionary <Guid, Dictionary <String, String> > GetAllUsersGlobalAttribetes(Guid token, bool deleteds) { return(RpcInvoker.InvokeMethod <Dictionary <Guid, Dictionary <String, String> > >(token, deleteds)); }
public static UserContract GetCurrentUser(Guid token) { return(RpcInvoker.InvokeMethod <UserContract>(token)); }