コード例 #1
0
        /// <summary>
        /// 根据dto定义,得到ServiceResponse
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public static ServiceResponse Create(DTObject dto)
        {
            var status      = dto.GetObject("status", ServiceHostUtil.Success);
            var returnValue = dto.GetObject("returnValue", DTObject.Empty);

            return(new ServiceResponse(status, returnValue));
        }
コード例 #2
0
        /// <summary>
        /// 根据dto定义,得到ServiceRequest
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public static ServiceRequest Create(DTObject dto)
        {
            var serviceName = dto.GetValue <string>("serviceName", string.Empty);
            var identity    = dto.GetObject("identity", DTObject.Empty);
            var argument    = dto.GetObject("argument", DTObject.Empty);

            return(new ServiceRequest(serviceName, identity, argument));
        }
コード例 #3
0
 internal void SetSource(ScriptView view, DTObject source)
 {
     this.Id       = source.GetValue <string>("id", string.Empty);
     this.Name     = source.GetValue <string>("name", string.Empty);
     this.Metadata = source.GetObject("metadata");
     this.View     = view;
 }
コード例 #4
0
        public IContractEvent Create(DTObject dto)
        {
            var typeName = dto.GetValue <string>("type", string.Empty);

            if (string.IsNullOrEmpty(typeName))
            {
                throw new ServiceException("没有定义IContractEvent的类型,无法实例化ContractEvent");
            }
            var type = _getEventType(typeName);

            if (type == null)
            {
                throw new ServiceException("没有找到" + typeName + "的类型,无法实例化ContractEvent");
            }

            var dtoArgs = dto.GetObject("args", DTObject.Empty);
            var args    = GetArgs(dtoArgs);
            var ce      = Activator.CreateInstance(type, args) as IContractEvent;

            if (ce == null)
            {
                throw new TypeMismatchException(type, typeof(IContractEvent));
            }
            return(ce);
        }
コード例 #5
0
        protected override object[] GetArgs(DTObject args)
        {
            var contractId  = args.GetValue <string>("contractId", string.Empty);
            var responseDTO = args.GetObject("response", DTObject.Empty);
            var response    = ServiceResponse.Create(responseDTO);

            return(new object[] { contractId, response });
        }
コード例 #6
0
 /// <summary>
 /// 获得视图的提交者
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public T GetSender <T>() where T : ScriptElement
 {
     if (_sender == null)
     {
         if (_input == null)
         {
             throw new XamlException("视图没有提交者");
         }
         var sender = _input.GetObject("sender", null);//{sender:{},elements:[{id:'xxxx',metadata:xxxx}]}
         if (sender == null)
         {
             throw new XamlException("视图没有提交者");
         }
         _sender = ElementFactory.Create <T>(this, sender);
     }
     return(_sender as T);
 }
コード例 #7
0
        /// <summary>
        /// 完成远程事件
        /// </summary>
        /// <param name="event"></param>
        private static void CompleteRemoteEvent(Guid queueId, DTObject @event, EventKey key)
        {
            if (!TimeoutManager.End(key))
            {
                return;                           //如果结束失败,证明已超时了
            }
            //首先释放资源,删除为了收取信息而建立的临时队列
            CleanupRemoteEventResult(key.EventName, key.EventId);

            //再处理结果
            var success = @event.GetValue <bool>("success");
            var message = @event.GetValue <string>("message");

            if (!success)
            {
                //如果没有执行成功,那么抛出异常
                throw new RemoteEventFailedException(message);
            }

            var args = @event.GetObject("args");

            DataContext.NewScope(() =>
            {
                var queue = EventQueue.Find(queueId);
                if (queue.IsEmpty())
                {
                    //短期内事件队列不存在只有一个原因,那就是由于回逆而被删除了
                    //长期内事件不存在,那是因为为防止数据过多导致性能下降,已完成的过期队列会被删除,这种情况下不可能被继续调用,不会执行到这里来
                    throw new DomainEventException(string.Format(Strings.QueueNotExistWithCallbackTip, queue.Id));
                }

                var entry = queue.GetEntry(key.EventId);
                if (entry.IsEmpty())
                {
                    throw new DomainEventException(string.Format(Strings.EventEntryNotExistWithCallbackTip, queue.Id, entry.EventId));
                }

                if (entry.IsLocal) //本地事件是不能继续触发的,这明显是个致命错误
                {
                    throw new DomainEventException(string.Format(Strings.ContinueNotWithLocal, entry.EventName));
                }

                if (entry.Status == EventStatus.TimedOut) //已经超时了,抛出异常
                {
                    throw new RemoteEventFailedException(Strings.ExecuteRemoteEventTimeout);
                }

                //远程事件执行完毕后,用它所在的源事件接受结果
                var source = entry.GetSourceEvent();
                source.ApplyResult(entry.EventName, args);

                entry.Status = EventStatus.Raised;

                EventQueue.Update(queue);
            }, true);
        }
コード例 #8
0
        public static Participant DeserializeParticipant(string orgin, byte[] data)
        {
            DTObject dto = DTObject.Create(data);

            var id         = dto.GetValue <string>("id");
            var name       = dto.GetValue <string>("name");
            var extensions = dto.GetObject("extensions");

            return(new Participant(id, name, extensions)
            {
                Orgin = orgin
            });
        }
コード例 #9
0
        public static MockContract Create(DTObject dto, IContractPackage package)
        {
            var id          = dto.GetValue <string>("id", string.Empty);
            var description = dto.GetValue <string>("description", string.Empty);

            //request
            var requestDTO = dto.GetObject("request", DTObject.Empty);
            var request    = ServiceRequest.Create(requestDTO);

            //response
            var responseDTO = dto.GetObject("response", DTObject.Empty);
            var response    = ServiceResponse.Create(responseDTO);

            var events = dto.GetList("events", false) ?? DTObjects.Empty;
            List <IContractEvent> ces = new List <IContractEvent>(events.Count);

            foreach (var e in events)
            {
                ces.Add(ContractEventFactory.CreateCE(e));
            }

            return(new MockContract(id, description, request, response, ces.ToArray(), package));
        }
コード例 #10
0
        /// <summary>
        /// 接入事件,也就是收到对方的调用事件
        /// </summary>
        /// <param name="event"></param>
        public static void Accept(DTObject @event)
        {
            var key     = EventEntry.GetEventKey(@event);
            var args    = @event.GetObject("args");
            var source  = EventFactory.GetLocalEvent(key.EventName, args, true);
            var queueId = key.EventId;

            EventRestorer.UseQueue(queueId, true, (callback) =>
            {
                EventTrigger.Start(key.EventId, source, true, callback); //我们把调用方指定的事件编号作为本地的事件队列编号
            },
                                   (ex) =>
            {
                //发生了错误就发布出去,通知失败了
                EventTrigger.PublishRaiseFailed(AppContext.Identity, key, ex.GetCompleteInfo()); //再恢复
            });
        }
コード例 #11
0
        public DTObject Invoke(string method, DTObject arg)
        {
            var bus = _busItem.Item;

            _result        = null;
            _correlationId = Guid.NewGuid().ToString();

            DTObject dto = DTObject.CreateReusable();

            dto["method"] = method;
            dto["arg"]    = arg;

            var routingKey = RPC.GetServerQueue(method.ToLower()); //将服务器端的方法名称作为路由键,统一转为小写表示不区分大小写

            bus.Publish(string.Empty, routingKey, dto, (properties) =>
            {
                properties.ReplyTo       = _queue;
                properties.CorrelationId = _correlationId;
            });
            _signal.WaitOne(_millisecondsTimeout);


            if (_result == null)
            {
                _correlationId = string.Empty;
                throw new RabbitMQException(string.Format(Strings.RequestTimedout, method));
            }

            if (_result.GetValue <string>("status") == "fail")
            {
                var msg = _result.GetValue <string>("message");
                throw new RabbitMQException(string.Format(msg));
            }

            return(_result.GetObject("returnValue"));
        }
コード例 #12
0
        private void InitIdentity(DTObject arg)
        {
            var identity = arg.GetObject("identity");

            AppSession.Identity = identity;
        }
コード例 #13
0
 public void Handle(string eventName, DTObject arg)
 {
     AppSession.Identity = arg.GetObject("identity"); //先初始化身份
     Handle(arg);
 }