/// <summary> /// /// </summary> /// <param name="context"></param> public async Task TransmitAsync(DistributeContext context) { if (context == null) { throw new ArgumentNullException("context"); } var response = await TransmitCoreAsync(context); if (response != null) { Status responseStateCode; if (!response.Body.Event.Status.TryParse(out responseStateCode)) { context.Exception = new AnycmdException("响应节点返回了意外的状态码" + response.Body.Event.Status.ToString()); } context.Result.UpdateStatus(responseStateCode, response.Body.Event.Description); if (response.Body.InfoValue != null) { foreach (var item in response.Body.InfoValue) { context.Result.ResultDataItems.Add(new DataItem(item.Key, item.Value)); } } } else { if (context.Exception == null) { context.Exception = new AnycmdException("远端服务未返回值"); } } }
/// <summary> /// 通过网络传输命令到服务端执行。 /// <remarks>即使命令的响应节点是本节点该方法依旧通过网络传送命令。</remarks> /// </summary> /// <returns></returns> public IMessageDto Request() { var context = new DistributeContext(this, this._responseNode); MessageRequester.Instance.Request(context); return(context.Result); }
protected async override Task <IMessageDto> TransmitCoreAsync(DistributeContext context) { try { var client = new JsonServiceClient(context.Responder.AnycmdApiAddress); return(await client.GetAsync(GetRequest(context))); } catch (Exception ex) { context.Exception = ex; return(null); } }
protected sealed override IMessageDto TransmitCore(DistributeContext context) { try { var client = new JsonServiceClient(context.Responder.AnycmdApiAddress); return(client.Get(GetRequest(context))); } catch (Exception ex) { context.Exception = ex; return(null); } }
protected async override Task<IMessageDto> TransmitCoreAsync(DistributeContext context) { try { var client = new JsonServiceClient(context.Responder.AnycmdApiAddress); return await client.GetAsync(GetRequest(context)); } catch (Exception ex) { context.Exception = ex; return null; } }
protected sealed override IMessageDto TransmitCore(DistributeContext context) { try { var client = new JsonServiceClient(context.Responder.AnycmdApiAddress); return client.Get(GetRequest(context)); } catch (Exception ex) { context.Exception = ex; return null; } }
private Message GetRequest(DistributeContext context) { var command = context.Command; var ticks = DateTime.UtcNow.Ticks; var request = new Message { Verb = command.Verb.Code, Ontology = command.Ontology, MessageType = command.MessageType.ToName(), Body = new BodyData(command.DataTuple.IdItems.Items.ToDto(), command.DataTuple.ValueItems.Items.ToDto()) { Event = new EventData { SourceType = command.EventSourceType, Subject = command.EventSubjectCode, ReasonPhrase = command.ReasonPhrase, Status = command.Status } }, TimeStamp = command.TimeStamp.ToUniversalTime().Ticks, MessageId = command.MessageId, Version = command.Version, IsDumb = command.IsDumb, Credential = new CredentialData { ClientType = ClientType.Node.ToName(), UserType = UserType.None.ToName(), CredentialType = CredentialType.Signature.ToName(), SignatureMethod = SignatureMethod.HMAC_SHA1.ToName(), ClientId = context.ClientAgent.PublicKey, UserName = command.UserName,// UserName Ticks = ticks } }; // 签名 request.Credential.Password = Signature.Sign(request.ToOrignalString(request.Credential), context.ClientAgent.SecretKey); return(request); }
/// <summary> /// 通过网络传输命令到服务端执行。 /// <remarks>即使命令的响应节点是本节点该方法依旧通过网络传送命令。</remarks> /// </summary> /// <returns></returns> public IMessageDto Request() { var context = new DistributeContext(this, this._responseNode); MessageRequester.Instance.Request(context); return context.Result; }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> protected abstract Task <IMessageDto> TransmitCoreAsync(DistributeContext context);
/// <summary> /// 转移 /// </summary> /// <param name="context">发送事件参数</param> protected abstract IMessageDto TransmitCore(DistributeContext context);
private Message GetRequest(DistributeContext context) { var command = context.Command; var ticks = DateTime.UtcNow.Ticks; var request = new Message { Verb = command.Verb.Code, Ontology = command.Ontology, MessageType = command.MessageType.ToName(), Body = new BodyData(command.DataTuple.IdItems.Items.ToDto(), command.DataTuple.ValueItems.Items.ToDto()) { Event = new EventData { SourceType = command.EventSourceType, Subject = command.EventSubjectCode, ReasonPhrase = command.ReasonPhrase, Status = command.Status } }, TimeStamp = command.TimeStamp.ToUniversalTime().Ticks, MessageId = command.MessageId, Version = command.Version, IsDumb = command.IsDumb, Credential = new CredentialData { ClientType = ClientType.Node.ToName(), UserType = UserType.None.ToName(), CredentialType = CredentialType.Signature.ToName(), SignatureMethod = SignatureMethod.HMAC_SHA1.ToName(), ClientId = context.ClientAgent.PublicKey, UserName = command.UserName,// UserName Ticks = ticks } }; // 签名 request.Credential.Password = Signature.Sign(request.ToOrignalString(request.Credential), context.ClientAgent.SecretKey); return request; }
/// <summary> /// /// </summary> /// <param name="context"></param> public async Task TransmitAsync(DistributeContext context) { if (context == null) { throw new ArgumentNullException("context"); } var response = await TransmitCoreAsync(context); if (response != null) { Status responseStateCode; if (!response.Body.Event.Status.TryParse(out responseStateCode)) { context.Exception = new AnycmdException("响应节点返回了意外的状态码" + response.Body.Event.Status.ToString()); } context.Result.UpdateStatus(responseStateCode, response.Body.Event.Description); if (response.Body.InfoValue != null) { foreach (var item in response.Body.InfoValue) { context.Result.ResultDataItems.Add(new DataItem(item.Key, item.Value)); } } } else { if (context.Exception == null) { context.Exception = new AnycmdException("远端服务未返回值"); } } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> protected abstract Task<IMessageDto> TransmitCoreAsync(DistributeContext context);
/// <summary> /// 转移 /// </summary> /// <param name="context">发送事件参数</param> protected abstract IMessageDto TransmitCore(DistributeContext context);