public void Reserve()
        {
            DTObject dto = DTObject.CreateReusable(_code1);

            dto.Transform("~config.name,config.options,config.persons,description,id");
            Assert.AreEqual("{\"config\":[{\"name\":\"1\",\"options\":[\"选项1\",\"选项2\"],\"persons\":[{\"id\":\"1\",\"name\":\"姓名1\"},{\"id\":\"2\",\"name\":\"姓名2\"}]}],\"description\":\"111\",\"id\":7}", dto.GetCode());

            dto = DTObject.CreateReusable(_code1);
            dto.Transform("~config.name,config.options,config.persons.id,description,id");
            Assert.AreEqual("{\"config\":[{\"name\":\"1\",\"options\":[\"选项1\",\"选项2\"],\"persons\":[{\"id\":\"1\"},{\"id\":\"2\"}]}],\"description\":\"111\",\"id\":7}", dto.GetCode());
        }
        public void Remove()
        {
            DTObject dto = DTObject.CreateReusable(_code1);

            dto.Transform("!config.name,config.options,config.persons,description,id");
            Assert.AreEqual("{\"config\":[{\"message\":\"\",\"required\":true,\"type\":4}],\"markedCode\":\"1\",\"name\":\"123\",\"orderIndex\":1,\"rootId\":6}", dto.GetCode(true));

            dto = DTObject.CreateReusable(_code1);
            dto.Transform("!config.name,config.options,config.persons.id,description,id");
            Assert.AreEqual("{\"config\":[{\"message\":\"\",\"persons\":[{\"name\":\"姓名1\"},{\"name\":\"姓名2\"}],\"required\":true,\"type\":4}],\"markedCode\":\"1\",\"name\":\"123\",\"orderIndex\":1,\"rootId\":6}", dto.GetCode(true));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建列表数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rowSchemaCode"></param>
        /// <param name="objs"></param>
        /// <returns></returns>
        public static DTObject Create <T>(string rowSchemaCode, IEnumerable <T> objs)
        {
            var result = DTObject.CreateReusable();

            result.SetValue("dataCount", objs.Count());
            result.Push("rows", objs, (obj) =>
            {
                return(DTObject.CreateReusable(rowSchemaCode, obj));
            });
            return(result);
        }
Exemplo n.º 4
0
        public DTObject Process(string method, DTObject arg)
        {
            //先初始化会话身份
            InitIdentity(arg);

            var tip        = GetTip(arg);
            var obj        = FindObject(tip, arg);
            var schemaCode = GetSchemaCode(tip, arg);

            return(DTObject.CreateReusable(schemaCode, obj));
        }
Exemplo n.º 5
0
        protected override DTObject DynamicInvoke(dynamic arg)
        {
            var cmd = new UserSubsystem.InitSA(arg.Name, arg.Password)
            {
                Email = arg.Email
            };

            var user = cmd.Execute();

            return(DTObject.CreateReusable("{id}", user));
        }
        public void SetSelf()
        {
            var dto = DTObject.CreateReusable();

            dto.SetValue(2);
            Assert.AreEqual(2, dto.GetValue <int>());

            var newDTO = DTObject.CreateReusable("{id:3}");

            dto.SetValue(newDTO); //该表达式表示设置自己
            Assert.AreEqual("{\"id\":3}", dto.GetCode());
        }
Exemplo n.º 7
0
        public void CreateDTO()
        {
            DTObject dto = DTObject.CreateReusable("{id,name}");

            dto.SetValue("id", 1);
            dto.SetValue("name", "刘备");

            Assert.AreEqual(1, dto.GetValue <int>("id"));
            Assert.AreEqual("刘备", dto.GetValue <string>("name"));
            //Assert.AreEqual("{\"id\",\"name\"}", dto.GetCode(false));
            Assert.AreEqual("{\"id\":1,\"name\":\"刘备\"}", dto.GetCode());
        }
Exemplo n.º 8
0
        public ServiceResponse Invoke(ServiceRequest request)
        {
            DTObject args = DTObject.CreateReusable();

            args["serviceName"] = request.FullName;
            args["identity"]    = request.Identity;
            args["argument"]    = request.Argument;

            var result = RPCClient.Invoke(request.FullName, args);

            return(ServiceResponse.Create(result));
        }
        protected override DTObject DynamicInvoke(dynamic arg)
        {
            var cmd = new AccountSubsystem.UpdatePermission(arg.Id)
            {
                Name        = arg.Name,
                Description = arg.Description,
                MarkedCode  = arg.MarkedCode
            };
            var permission = cmd.Execute();

            return(DTObject.CreateReusable("{id,name,description,markedCode}", permission));
        }
Exemplo n.º 10
0
        /// <summary>
        /// 得到发布事件调用结果的参数
        /// </summary>
        /// <param name="queue"></param>
        /// <param name="eventName"></param>
        /// <param name="eventId"></param>
        /// <param name="success"></param>
        /// <param name="message"></param>
        /// <param name="argsCode"></param>
        /// <returns></returns>
        private static DTObject CreatePublishRaiseResultArg(DTObject identity, EventKey key, bool success, string message, string argsCode)
        {
            var arg = DTObject.CreateReusable();

            arg["eventName"] = key.EventName;
            arg["eventId"]   = key.EventId;
            arg["success"]   = success;
            arg["message"]   = message;
            arg["args"]      = DTObject.CreateReusable(argsCode);
            arg["identity"]  = identity.Clone();
            return(arg);
        }
Exemplo n.º 11
0
        protected override DTObject DynamicInvoke(dynamic arg)
        {
            var cmd = new CreatePermission(arg.Name)
            {
                Description = arg.Description,
                MarkedCode  = arg.MarkedCode
            };

            var permisson = cmd.Execute();

            return(DTObject.CreateReusable("{id}", permisson));
        }
Exemplo n.º 12
0
        public void MenuListMapDTO()
        {
            var menu = CreateMenu();

            var dto  = DTObject.CreateReusable("{name,childs:[{name,index}]}", menu);
            var code = dto.GetCode(true);

            Assert.AreEqual("{\"Childs\":[{\"Index\":2,\"Name\":\"子菜单1\"},{\"Index\":3,\"Name\":\"子菜单2\"},{\"Index\":4,\"Name\":\"子菜单3\"}],\"Name\":\"主菜单\"}", code);

            dto  = DTObject.CreateReusable("{name,childs}", menu);
            code = dto.GetCode(true);
            Assert.AreEqual("{\"Childs\":[{\"Childs\":[],\"Name\":\"子菜单1\"},{\"Childs\":[],\"Name\":\"子菜单2\"},{\"Childs\":[{\"Childs\":[],\"Name\":\"子菜单3-1\"},{\"Childs\":[],\"Name\":\"子菜单3-2\"}],\"Name\":\"子菜单3\"}],\"Name\":\"主菜单\"}", code);
        }
Exemplo n.º 13
0
        protected override DTObject DynamicInvoke(dynamic arg)
        {
            var cmd = new CreateRole(arg.Name, arg.PermissionIds?.OfType <Guid>(), arg.IsSystem)
            {
                Description    = arg.Description,
                MarkedCode     = arg.MarkedCode,
                OrganizationId = arg.OrganizationId
            };

            var role = cmd.Execute();

            return(DTObject.CreateReusable("{id}", role));
        }
Exemplo n.º 14
0
        public void CreateObjectDTO()
        {
            var      user    = new User(1, "Louis");
            DTObject dto     = DTObject.CreateReusable("{user}");
            var      dtoUser = DTObject.CreateReusable("{id,name}", user);

            dto.SetValue("user", dtoUser);

            dynamic result = dto.GetValue("user");

            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("Louis", result.Name);
        }
Exemplo n.º 15
0
        public void MenuMapDTO()
        {
            var menu = CreateMenu();

            var dto  = DTObject.CreateReusable("{name,index,parent:{name}}", menu);
            var code = dto.GetCode(true);

            Assert.AreEqual("{\"Index\":1,\"Name\":\"主菜单\",\"Parent\":{\"Name\":\"根菜单\"}}", code);

            dto  = DTObject.CreateReusable("{name,index,parent,owner}", menu);
            code = dto.GetCode(true);
            Assert.AreEqual("{\"Index\":1,\"Name\":\"主菜单\",\"Parent\":{\"Index\":0,\"Name\":\"根菜单\",\"Owner\":{\"Creator\":{\"Name\":\"创建人\",\"Sex\":\"男\"},\"Id\":\"project1\",\"Name\":\"项目1\"}}}", code);
        }
        /// <summary>
        /// 以dto的形式调用服务
        /// </summary>
        /// <param name="serviceName"></param>
        /// <param name="fillArg"></param>
        /// <returns></returns>
        public static DTObject Invoke(string serviceName, Action <DTObject> fillArg)
        {
            var arg = DTObject.CreateReusable();

            if (fillArg != null)
            {
                fillArg(arg);
            }
            ServiceRequest request  = new ServiceRequest(serviceName, DTObject.Empty, arg);
            var            provider = ServiceProviderFactory.Create(request);

            return(provider.Invoke(request));
        }
Exemplo n.º 17
0
        public void TransformListIsEmpty()
        {
            var      code = "{\"config\":[],\"description\":\"类型描述\",\"id\":13,\"markedCode\":\"test\",\"name\":\"测试\",\"orderIndex\":1}";
            DTObject dto  = DTObject.CreateReusable(code);

            dto.Transform("id=>typeId;config=>attached");
            dto.Transform("attached.options=options", (v) =>
            {
                var options = ((object[])v).Select((t) => { return((string)t); });
                return(string.Join(",", options));
            });
            Assert.AreEqual("{\"attached\":[],\"description\":\"类型描述\",\"markedCode\":\"test\",\"name\":\"测试\",\"orderIndex\":1,\"typeId\":13}", dto.GetCode(true));
        }
Exemplo n.º 18
0
        /// <summary>
        /// 获取事件的参数
        /// </summary>
        /// <param name="preEventName"></param>
        internal DTObject GetArgs(string eventName)
        {
            if (eventName.EqualsIgnoreCase(this.EventName))
            {
                //获取事件自身的数据
                return(this.GetArgs());
            }

            var args = DTObject.CreateReusable();

            FillArgs(eventName, args);
            return(args);
        }
Exemplo n.º 19
0
        public void MapInnerDTO()
        {
            var code = "{\"name\":\"类型名称\",\"orderIndex\":\"1\",\"markedCode\":\"markedCode\",\"description\":\"描述\",\"coverConfig\":[{\"name\":\"1\",\"width\":\"111\",\"height\":\"111\"}],\"dcSlimConfig\":{\"items\":[{\"name\":\"配置1\",\"type\":\"2\",\"required\":\"false\",\"options\":[\"选项1\",\"选项2\",\"选项3\"]},{\"name\":\"配置2\",\"type\":\"4\",\"required\":\"true\",\"options\":[\"选项1\",\"选项2\"]}]}}";
            var para = DTObject.CreateReusable(code);

            var temp = DTObject.Deserialize <MapInnerDTOClass>(para);

            Assert.AreEqual("\"dcSlimConfig\":{\"items\":[{\"name\":\"配置1\",\"options\":[\"选项1\",\"选项2\",\"选项3\"],\"required\":\"false\",\"type\":\"2\"},{\"name\":\"配置2\",\"options\":[\"选项1\",\"选项2\"],\"required\":\"true\",\"type\":\"4\"}]}", temp.DCSlimConfig.GetCode(true));

            var dto          = DTObject.Serialize(temp, false);
            var dcSlimConfig = dto.GetObject("dcSlimConfig");

            Assert.AreEqual("\"dcSlimConfig\":{\"items\":[{\"name\":\"配置1\",\"options\":[\"选项1\",\"选项2\",\"选项3\"],\"required\":\"false\",\"type\":\"2\"},{\"name\":\"配置2\",\"options\":[\"选项1\",\"选项2\"],\"required\":\"true\",\"type\":\"4\"}]}", temp.DCSlimConfig.GetCode(true));
        }
Exemplo n.º 20
0
        private void AsyncExecuteService(string serviceName, RemoteType remoteType, object id, IEnumerable <string> addresses)
        {
            AppSession.AsyncUsing(() =>
            {
                var arg         = DTObject.CreateReusable();
                arg["id"]       = id;
                arg["typeName"] = remoteType.FullName;

                var identity = DefaultIdentityProvider.Instance.GetIdentity();
                foreach (var address in addresses)
                {
                    ServiceContext.Invoke(serviceName, identity, arg, address);
                }
            }, true);
        }
Exemplo n.º 21
0
        /// <summary>
        /// 获得查询参数
        /// </summary>
        /// <returns></returns>
        public DTObject GetQuery()
        {
            var arg = DTObject.CreateReusable();

            arg["pageSize"]  = this.PageSize;
            arg["pageIndex"] = this.PageIndex;
            if (!this.Parameters.IsEmpty())
            {
                foreach (var p in this.Parameters.GetDictionary())
                {
                    arg[p.Key] = p.Value;
                }
            }
            return(arg);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 创建翻页数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rowSchemaCode"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public static DTObject Create <T>(string rowSchemaCode, Page <T> page)
        {
            var result = DTObject.CreateReusable();

            result.SetValue("dataCount", page.DataCount);
            result.SetValue("pageCount", page.GetPageCount());
            result.SetValue("pageIndex", page.PageIndex);
            result.SetValue("pageSize", page.PageSize);
            var objs = page.Objects;

            result.Push("rows", objs, (obj) =>
            {
                return(DTObject.CreateReusable(rowSchemaCode, obj));
            });
            return(result);
        }
Exemplo n.º 23
0
        private void ParseJSON(string code)
        {
            var dto   = DTObject.CreateReusable(code);
            var items = dto.GetList();

            foreach (var item in items)
            {
                var contract = MockContract.Create(item, this);
                _contracts.Add(contract.ServiceName, contract);

                if (!string.IsNullOrEmpty(contract.Id))
                {
                    _keyValues.Add(contract.Id, contract);
                }
            }
        }
Exemplo n.º 24
0
        protected override DTObject DynamicInvoke(dynamic arg)
        {
            var cmd     = new AccountSubsystem.Login(arg.Flag, arg.Password, arg.Ip);
            var account = cmd.Execute();

            if (account.IsEmpty())
            {
                return(Failed);
            }
            var user = UserCommon.FindById(account.Id, QueryLevel.None);

            var result = DTObject.CreateReusable("{id,displayName,photo:{storeKey},account:{email,roles:[{id,markedCode}]}}", user);

            result.Transform("email=account.email;roles=account.roles;!account");
            return(result);
        }
Exemplo n.º 25
0
 /// <summary>
 /// 获取该事件条目属于的事件源的事件实例
 /// </summary>
 /// <returns></returns>
 public DomainEvent GetSourceEvent()
 {
     if (this.IsRootSource)
     {
         //根事件源
         var args   = DTObject.CreateReusable(this.ArgsCode);
         var @event = EventFactory.GetLocalEvent(this.EventName, args, true);
         @event.Entry = this;
         return(@event);
     }
     else
     {
         var args   = this.Source.GetArgs();
         var @event = EventFactory.GetLocalEvent(this.Source.EventName, args, true);
         @event.Entry = this.Source;
         return(@event);
     }
 }
Exemplo n.º 26
0
        private void MessageReceived(object sender, BasicDeliverEventArgs e)
        {
            //此处必须异步,否则会阻塞接收处理消息,导致一个请求处理完后才处理下一个请求,吞吐量大幅度降低
            Task.Run(() =>
            {
                IBasicProperties properties = e.BasicProperties;

                DTObject content = DTObject.CreateReusable(e.Body);
                var message      = new Message(content, properties, () =>
                {
                    this.Channel.BasicAck(e.DeliveryTag, false);
                }, (requeue) =>
                {
                    this.Channel.BasicReject(e.DeliveryTag, requeue);
                });
                _messageHandler.Handle(message);
            });
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            AppInitializer.Initialize();


            Console.WriteLine("调用addGenerator的服务");


            //XY20170807
            //创建规则对象
            var hardcode = DTObject.CreateReusable();

            hardcode["ruleType"] = "hardcode";
            hardcode["content"]  = "XY";

            var dateCode = DTObject.CreateReusable();

            dateCode["ruleType"] = "dateCode";

            var rules = new DTObject[] { hardcode, dateCode };


            //以下是调用远程服务的代码
            var result = ServiceContext.InvokeDynamic("addGenerator", (arg) =>
            {
                arg.Name       = "第一个测试用的";
                arg.MarkedCode = "first";
                arg.Rules      = rules;
            });

            //Console.WriteLine("调用deleteGenerator的服务");
            //var permissionId = result.GetValue<Guid>("id");

            //ServiceContext.Invoke("deletePermission", (arg) =>
            //{
            //    arg.Id = permissionId;
            //});

            //Console.WriteLine("执行完毕,按任意键退出");

            AppInitializer.Cleanup();

            Console.ReadLine();
        }
Exemplo n.º 28
0
        public void CreateSymbolDTO()
        {
            DTObject dto = DTObject.CreateReusable("{id,name,sex,hobbys:[{v,n}]}");

            dto.SetValue("id", 1);
            dto.SetValue("name", "loui's");
            dto.SetValue("sex", 9);

            DTObject objHobbys = dto.CreateAndPush("hobbys");

            objHobbys.SetValue("v", "1");
            objHobbys.SetValue("n", "!@#09/");

            Assert.AreEqual(1, dto.GetValue <int>("id"));
            Assert.AreEqual("loui's", dto.GetValue <string>("name"));
            Assert.AreEqual(9, dto.GetValue <int>("sex"));
            //Assert.AreEqual("{\"id\",\"name\",\"sex\",\"hobbys\":[{\"v\",\"n\"}]}", dto.GetCode(false));
            Assert.AreEqual("{\"hobbys\":[{\"n\":\"!@#09/\",\"v\":\"1\"}],\"id\":1,\"name\":\"loui's\",\"sex\":9}", dto.GetCode(true));
        }
Exemplo n.º 29
0
        public void CreateListDTO()
        {
            DTObject dto = DTObject.CreateReusable("{id,name,hobby:[{v,n}]}");

            dto.SetValue("id", 1);
            dto.SetValue("name", "Louis");
            DTObject obj = dto.CreateAndPush("hobby");

            obj.SetValue("v", 0);
            obj.SetValue("n", string.Format("LS{0}", 0));

            obj = dto.CreateAndPush("hobby");
            obj.SetValue("v", 1);
            obj.SetValue("n", string.Format("LS{0}", 1));

            DTObjects list = dto.GetList("hobby");

            for (int i = 0; i < list.Count; i++)
            {
                Assert.AreEqual(i, list[i].GetValue <int>("v"));
                Assert.AreEqual(string.Format("LS{0}", i), list[i].GetValue <string>("n"));
            }

            Assert.AreEqual(1, dto.GetValue <int>("id"));
            Assert.AreEqual("Louis", dto.GetValue <string>("name"));
            //Assert.AreEqual("{\"id\",\"name\",\"hobby\":[{\"v\",\"n\"}]}", dto.GetCode(false));
            //Assert.AreEqual("{\"id\":1,\"name\":\"Louis\",\"hobby\":[{\"v\":0,\"n\":\"LS0\"},{\"v\":1,\"n\":\"LS1\"}]}", dto.GetCode());

            var code = dto.GetCode();
            var copy = DTObject.CreateReusable(code);

            list = dto.GetList("hobby");
            for (int i = 0; i < list.Count; i++)
            {
                Assert.AreEqual(i, list[i].GetValue <int>("v"));
                Assert.AreEqual(string.Format("LS{0}", i), list[i].GetValue <string>("n"));
            }

            Assert.AreEqual(1, dto.GetValue <int>("id"));
            Assert.AreEqual("Louis", dto.GetValue <string>("name"));
        }
Exemplo n.º 30
0
        protected override IEnumerable <string> GetPreEvents()
        {
            const string prefix = "NodeEvent";

            var           index = int.Parse(this.EventName.Substring(prefix.Length));
            List <string> ems   = new List <string>();

            var dto = DTObject.CreateReusable(this.Code);
            var pre = dto.GetList("pre", false);

            if (pre != null)
            {
                foreach (var e in pre)
                {
                    index++;
                    var em = string.Format("{0}{1}", prefix, index);
                    ems.Add(em);
                }
            }
            return(ems);
        }