Exemplo n.º 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));
        }
Exemplo n.º 2
0
        protected override DTObject DynamicInvoke(dynamic arg)
        {
            Guid[] roleIds = Array.Empty <Guid>();
            if (arg.RoleMarkedCode != null)
            {
                string markedCode = arg.RoleMarkedCode.ToString();
                var    role       = RoleCommon.FindByMarkedCode(markedCode, QueryLevel.None);
                if (!role.IsEmpty())
                {
                    roleIds = new Guid[] { role.Id };
                }
            }
            else
            {
                roleIds = arg.RoleIds != null?arg.RoleIds?.OfType <Guid>() : Array.Empty <Guid>();
            }

            var cmd = new CreateUser(arg.AccountName, arg.Password, arg.DiskSize ?? VirtualDisk.Size1G) //默认给予1G的大小
            {
                Email                                   = arg.Email,
                LocationId                              = arg.LocationId,
                MobileNumber                            = arg.MobileNumber,
                Name                                    = arg.Name,
                NickName                                = arg.NickName,
                PhotoId                                 = arg.PhotoId,
                RoleIds                                 = arg.RoleIds != null?arg.RoleIds?.OfType <Guid>() : Array.Empty <Guid>(),
                                              Sex       = arg.Sex,
                                              IsEnabled = arg.IsEnabled
            };

            var user = cmd.Execute();

            return(DTObject.CreateReusable("{id}", user));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建一个rtp能力可以识别的消息
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="header"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        private Message CreateResponseMessage(string eventName, DTObject header, byte[] content, string error, bool isCompleted)
        {
            var rtpData = new RtpData(this.Data.Participant, header, content);
            var data    = RtpDataAnalyzer.Serialize(rtpData);
            var msg     = RtpCapability.CreateCallMessage(this.Name, eventName, data, this.RequestId, (mh) =>
            {
                if (!string.IsNullOrEmpty(this.Destination))
                {
                    mh.SetValue(MessageField.Destination, this.Destination);
                }
                else if (this.Destinations != null)
                {
                    mh.SetValue(MessageField.Destinations, this.Destinations);
                }

                if (!string.IsNullOrEmpty(error))
                {
                    mh.SetValue(RtpCapability.FieldRtpCallErrorMessage, error);
                }
                mh.SetValue(RtpCapability.FieldRtpCallIsCompleted, isCompleted);
            });

            msg.Origin = this.Data.Participant.Orgin;
            return(msg);
        }
Exemplo n.º 4
0
        protected override DTObject DynamicInvoke(dynamic arg)
        {
            var cmd  = new CreateVirtualFile(arg.Name, arg.Extension, arg.StoreKey, arg.Size, arg.DirectoryId);
            var file = cmd.Execute();

            return(DTObject.CreateReusable("{id,name,storeKey,extension,size}", file));
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="I">输入参数的类型</typeparam>
        /// <typeparam name="O">输出参数的类型</typeparam>
        /// <param name="arg">输入参数</param>
        /// <returns></returns>
        public DTObject Process(DTObject arg)
        {
            var request  = MapRequest(arg);
            var response = _handler.Process(request);

            return(MapResponse(response));
        }
Exemplo n.º 6
0
        internal static EventKey GetEventKey(DTObject @event)
        {
            var eventId   = @event.GetValue <Guid>("eventId");
            var eventName = @event.GetValue <string>("eventName");

            return(new EventKey(eventId, eventName));
        }
 public ServiceRequest(string ns, string name, DTObject identity, DTObject argument)
 {
     this.Namespace = ns;
     this.Name      = name;
     this.Identity  = identity ?? DTObject.Empty;
     this.Argument  = argument ?? DTObject.Empty;
 }
Exemplo n.º 8
0
 private Future <bool> Call(string eventName, DTObject header, byte[] body, Action <RtpData, bool> process, IEnumerable <string> destinations)
 {
     return(Call(eventName, header, body, process, (mh) =>
     {
         mh.SetValue(MessageField.Destinations, destinations);
     }));
 }
Exemplo n.º 9
0
 protected Future <bool> Call(string eventName, DTObject header, byte[] content, Action <RtpData, bool> process)
 {
     return(Call(eventName, header, content, process, (mh) =>
     {
         mh.SetValue(MessageField.Destination, this.Channel.HostAddress);
     }));
 }
Exemplo n.º 10
0
        private static DTObject Load(string language, string fileName, string group)
        {
            DTObject dto = DTObject.Create("{childs:[{name,icon,code,childs:[{}]}]}");

            try
            {
                var groupNode = GetGroupNode(fileName, group);
                if (groupNode != null)
                {
                    foreach (XmlNode node in groupNode.ChildNodes)
                    {
                        if (node.NodeType != XmlNodeType.Element)
                        {
                            continue;
                        }
                        var child = dto.CreateAndPush("childs");
                        FillMenuItem(child, node, language);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(dto);
        }
Exemplo n.º 11
0
 /// <summary>
 /// 发送信息
 /// </summary>
 /// <param name="header"></param>
 /// <param name="body"></param>
 /// <param name="destinations"></param>
 protected Future <bool> RaiseEvent(string eventName, DTObject header, byte[] body, IEnumerable <string> destinations)
 {
     return(RaiseEvent(eventName, header, body, (mh) =>
     {
         mh.SetValue(MessageField.Destinations, destinations);
     }));
 }
Exemplo n.º 12
0
        public static TransferData Deserialize(byte[] content)
        {
            using (var temp = ByteBuffer.Borrow(content.Length))
            {
                var source = temp.Item;
                source.Write(content);

                var dtoLength = source.ReadInt32();
                var dtoData   = source.ReadBytes(dtoLength);

                DTObject dto = DTObject.Create(dtoData);

                int    binaryLength = 0;
                byte[] binaryData   = Array.Empty <byte>();

                if (source.ReadPosition < source.Length)
                {
                    binaryLength = source.ReadInt32();
                    var thisTimeLength = source.ReadInt32();
                    binaryData = source.ReadBytes(thisTimeLength);
                }

                return(new TransferData(dto, binaryLength, binaryData));
            }
        }
        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);
        }
        protected override DTObject InvokeImpl(DTObject arg)
        {
            var tip = GetTip(arg);
            var obj = FindObject(tip, arg);

            return(DTObject.CreateReusable(tip.SchemaCode, obj));
        }
Exemplo n.º 15
0
        public static T Create <T>(ScriptView view, DTObject element) where T : ScriptElement
        {
            var se = Activator.CreateInstance(typeof(T)) as ScriptElement;

            se.SetSource(view, element);
            return((T)se);
        }
Exemplo n.º 16
0
 protected Future <bool> Call(string eventName, DTObject header, Action <RtpData, bool> process, IEnumerable <string> destinations)
 {
     return(Call(eventName, header, Array.Empty <byte>(), process, (mh) =>
     {
         mh.SetValue(MessageField.Destinations, destinations);
     }));
 }
Exemplo n.º 17
0
 /// <summary>
 /// 获得事件条目的参数
 /// </summary>
 /// <returns></returns>
 public DTObject GetArgs()
 {
     if (this.Source.IsEmpty())
     {
         //根条目
         return(DTObject.CreateReusable(this.ArgsCode));
     }
     else if (this.IsLocal)
     {
         if (string.IsNullOrEmpty(this.ArgsCode))
         {
             //对于本地事件,如果参数代码为空,表示还没有初始化过,要初始化
             var source = this.GetSourceEvent();
             var args   = source.GetArgs(this.EventName);
             this.ArgsCode = args.GetCode(); //保存代码
             return(args);
         }
         else
         {
             return(DTObject.CreateReusable(this.ArgsCode)); //如果已经有代码,那么直接使用
         }
     }
     else
     {
         //远程事件,直接从源事件中得到参数
         var source = this.GetSourceEvent();
         return(source.GetArgs(this.EventName));
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// 从dto中加载数据
        /// </summary>
        /// <param name="data"></param>
        public void Load(DTObject data)
        {
            var properties = this.Define.Properties;

            foreach (var property in properties)
            {
                var value = data.GetValue(property.Name, false);
                if (value == null)
                {
                    continue;
                }

                var obj = value as DTObject;
                if (obj != null)
                {
                    this.SetValue(property, GetObjectValue(property, obj));
                    continue;
                }

                var objs = value as DTObjects;
                if (objs != null)
                {
                    this.SetValue(property, GetListValue(property, objs));
                    continue;
                }
                this.SetValue(property, GetPrimitiveValue(property, value));
            }
        }
Exemplo n.º 19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="serviceName">服务的名称,可以带命名空间,如果不带命名空间使用当前项目配置的默认命名空间</param>
 /// <param name="identity"></param>
 /// <param name="argument"></param>
 public ServiceRequest(string serviceName, DTObject identity, DTObject argument)
 {
     this.Namespace = _getNamespace(serviceName);
     this.Name      = _getName(serviceName);
     this.Identity  = identity ?? DTObject.Empty;
     this.Argument  = argument ?? DTObject.Empty;
 }
Exemplo n.º 20
0
        public DTObject GetData()
        {
            var data       = DTObject.CreateReusable();
            var properties = this.Define.Properties;

            foreach (var property in properties)
            {
                var value = this.GetValue(property);
                var obj   = value as DynamicObject;
                if (obj != null)
                {
                    value = obj.GetData();  //对象
                    data.SetValue(property.Name, value);
                    continue;
                }

                var list = value as IEnumerable <DynamicEntity>;
                if (list != null)
                {
                    //集合
                    data.Push(property.Name, list, (item) =>
                    {
                        return(item.GetData());
                    });
                    continue;
                }

                data.SetValue(property.Name, value); //值
            }
            return(data);
        }
Exemplo n.º 21
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;
 }
Exemplo n.º 22
0
        /// <summary>
        /// 下载地址表
        /// </summary>
        /// <returns></returns>
        private ServiceAddressTable DownloadAddressTable(string serviceNamespace, DTObject identity)
        {
            MultiDictionary <string, string> table = new MultiDictionary <string, string>(false);

            var routerAddresses = WebServiceModelConfiguration.Current.Client.GetAddresses(serviceNamespace);
            var routerAddress   = Algorithm.Balance <string>(routerAddresses);

            if (routerAddress == null)
            {
                return(new ServiceAddressTable(serviceNamespace, table));
            }


            //根据请求端身份,获取服务地址表
            DTObject arg = DTObject.CreateReusable();

            arg.SetValue("namespace", serviceNamespace); //提交服务的命名空间
            var request  = new ServiceRequest("getServiceAddressTable", identity, arg);
            var response = WebServiceProxy.Instance.Invoke(request, routerAddress);

            response.TryCatch();
            var result = response.ReturnValue;

            result.Each("table", (item) =>
            {
                var address  = item.GetValue <string>("address");
                var services = item.GetList("services").ToArray <string>();

                foreach (var service in services)
                {
                    table.Add(service, address);
                }
            });
            return(new ServiceAddressTable(serviceNamespace, table));
        }
Exemplo n.º 23
0
 internal Participant(string id, string name, DTObject extensions)
 {
     this.Id         = id;
     this.Name       = name;
     this.Extensions = extensions;
     this.Data       = DataAnalyzer.SerializeParticipant(this);
 }
Exemplo n.º 24
0
        public new DTObject GetIdentity()
        {
            var identity = DTObject.CreateReusable();

            identity["language"] = this.Language;
            return(identity);
        }
Exemplo n.º 25
0
        public DTObject Process(Action <DTObject> fillArg)
        {
            var arg = DTObject.CreateReusable();

            fillArg(arg);
            return(Process(arg));
        }
Exemplo n.º 26
0
        private static Message BuildHeartBeat()
        {
            var header = DTObject.Create();

            header.SetValue(MessageField.MessageType, (byte)MessageType.HeartBeatRequest);
            return(new Message(header, Array.Empty <byte>()));
        }
Exemplo n.º 27
0
 protected override void Handle(DTObject arg)
 {
     UseDefines(arg, (define, id) =>
     {
         RemotePortal.UpdateObject(define, id);
     });
 }
Exemplo n.º 28
0
 internal Message(DTObject content, IBasicProperties properties, Action ack, Action <bool> reject)
 {
     this.Content    = content;
     this.Properties = properties;
     _ack            = ack;
     _reject         = reject;
 }
Exemplo n.º 29
0
        private static void Rollback(EventLog log, EventLogEntry logEntry, Exception reason)
        {
            var queueId = log.Id;

            if (logEntry.Operation == EventOperation.Raise)
            {
                var content = DTObject.CreateReusable(logEntry.ContentCode);
                var entryId = content.GetValue <int>("entryId");

                var queue = EventQueue.Find(queueId);
                if (queue.IsEmpty())
                {
                    return;
                }
                var entry = queue.GetEntry(entryId);
                if (!entry.IsEmpty())
                {
                    Reverse(queue, entry);
                }
                EventQueue.Update(queue);
            }
            else if (logEntry.Operation == EventOperation.Start)
            {
                EventQueue.Delete(queueId);
            }
        }
Exemplo n.º 30
0
        void IMessageHandler.Handle(Message message)
        {
            var bus = _busItem.Item;

            AppSession.Using(() =>
            {
                try
                {
                    var content = message.Content;
                    var method  = content.GetValue <string>("method");
                    var arg     = content.GetObject("arg");

                    var result = DTObject.CreateReusable();
                    Process(method, arg, result);

                    var routingKey = message.Properties.ReplyTo; //将客户端的临时队列名称作为路由key
                    bus.Publish(string.Empty, routingKey, result, (replyProps) =>
                    {
                        replyProps.CorrelationId = message.Properties.CorrelationId;
                    });
                }
                catch (Exception ex)
                {
                    LogWrapper.Default.Fatal(ex);

                    var arg = new RPCEvents.ServerErrorArgs(ex);
                    RPCEvents.RaiseServerError(this, arg);
                }
                finally
                {
                    message.Success();
                }
            }, true);
        }