コード例 #1
0
            public DTObject Process(string method, DTObject args)
            {
                Console.WriteLine(string.Format("调用方法:{0},参数:{1}", method, args.GetCode()));
                var result = DTObject.CreateReusable();

                result["value"] = 1;
                return(result);
            }
コード例 #2
0
        public void CreateSocketMessageDTO()
        {
            DTObject dto  = DTObject.CreateReusable("{\"RCN\":\"ControlBigScreenCapability\",\"REN\":\"PlayEvent\",\"MT\":7,\"Ds\":[\"[::ffff:192.168.0.13]:59714\"]}");
            var      ds   = dto.GetList("Ds");
            var      code = dto.GetCode();

            Assert.AreEqual("[::ffff:192.168.0.13]:59714", ds[0].GetValue());
        }
コード例 #3
0
        public void Set(System.DateTime start, System.DateTime end)
        {
            DTObject value = DTObject.CreateReusable();

            value.SetValue("start", start);
            value.SetValue("end", end);
            this.View.WriteCode(string.Format("{0}.proxy().set({1});", this.Id, value.GetCode(false, false)));
        }
コード例 #4
0
        /// <summary>
        /// 绑定下拉数据,该方法仅在单级下拉框中有效
        /// </summary>
        /// <param name="data"></param>
        public void Bind(DTObject data)
        {
            StringBuilder code = new StringBuilder();

            code.AppendFormat("var items{0}={1}.items;", this.Id, data.GetCode());
            code.AppendFormat("{0}.proxy().options(items{0});", this.Id);

            this.View.WriteCode(code.ToString());
        }
コード例 #5
0
        public void CreateHaveValueDTO()
        {
            DTObject dto = DTObject.CreateReusable("{id:1,name:\"Louis\"}");

            Assert.AreEqual(1, dto.GetValue <int>("id"));
            Assert.AreEqual("Louis", dto.GetValue <string>("name"));
            Assert.AreEqual("{\"id\":1,\"name\":\"Louis\"}", dto.GetCode());
            //Assert.AreEqual("{\"id\",\"name\"}", dto.GetCode(false));
        }
コード例 #6
0
        /// <summary>
        /// 绑定选项,请确保<paramref name="data"/>里有成员为rows的集合作为绑定项
        /// </summary>
        /// <param name="data"></param>
        public void Options(DTObject data)
        {
            using (var temp = StringPool.Borrow())
            {
                var code = temp.Item;

                code.AppendFormat("{0}.proxy().options({1}.rows);", this.Id, data.GetCode(false, false));

                this.View.WriteCode(code.ToString());
            }
        }
コード例 #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());
        }
コード例 #8
0
        private static void Write(EventLog log, EventOperation operation, DTObject content)
        {
            //写入日志条目
            var index       = log.EntryCount;
            var contentCode = content.IsEmpty() ? "{}" : content.GetCode();
            var entry       = new EventLogEntry(log, operation, contentCode, index);
            var repository  = Repository.Create <IEventLogEntryRepository>();

            repository.Add(entry);

            log.EntryCount++;
            UpdateLog(log);
        }
コード例 #9
0
        /// <summary>
        /// 进度写入到文件,以便外界读取
        /// </summary>
        /// <param name="progressFileName"></param>
        /// <param name="g"></param>
        /// <param name="gt"></param>
        private static void RaiseCallback(string progressFileName, Progress g, DTObject gt)
        {
            gt["completedCount"] = g.CompletedCount;
            gt["pageCount"]      = g.PageCount;
            var code = gt.GetCode();

            using (var fs = new FileStream(progressFileName, FileMode.Open, FileAccess.Write, FileShare.Read))
            {
                fs.SetLength(0);
                using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8))
                {
                    writer.Write(code);
                }
            }
        }
コード例 #10
0
        public void Send(WebPageContext context, object result)
        {
            DTObject dto = result as DTObject;

            if (dto != null)
            {
                context.Response.Write(dto.GetCode(false, false));
                return;
            }
            var code = result as string;

            if (code != null)
            {
                context.Response.Write(code);
                return;
            }
            throw new DTOSenderException("DTOSender对象仅能发送 DTObject 或者 string 类型的对象!当前被发送的对象类型为:" + result.GetType().FullName);
        }
コード例 #11
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"));
        }
コード例 #12
0
        public void CreateDTOByPerformance()
        {
            DTObject dto = DTObject.CreateReusable("{id,name,childs:[{id,name}]}");

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

            var child0 = dto.CreateAndPush("childs");

            child0.SetValue("id", 2);
            child0.SetValue("name", "赵云");

            var child1 = dto.CreateAndPush("childs");

            child1.SetValue("id", 3);
            child1.SetValue("name", "马超");

            //Assert.AreEqual("{\"id\",\"name\",\"childs\":[{\"id\",\"name\"}]}", dto.GetCode(false));

            StringBuilder code = new StringBuilder();

            code.Append("{\"childs\":[");
            code.Append("{\"id\":2,\"name\":\"赵云\"},");
            code.Append("{\"id\":3,\"name\":\"马超\"}");
            code.Append("],\"id\":1,\"name\":\"刘备\"}");

            Assert.AreEqual(code.ToString(), dto.GetCode(true));

            //var data = TimeMonitor.Oversee(() =>
            //{
            //    for (var i = 0; i < 10000; i++)
            //    {
            //        DTObject.Create("{id,name,childs:[{id,name}]}");
            //    }
            //});
            //Assert.IsTrue(false, data.GetTime(0).ElapsedMilliseconds.ToString());
        }
コード例 #13
0
        public void CreateNestListDTO()
        {
            DTObject dto = DTObject.CreateReusable("{items:[{v,n,childs:[{v,n}]}]}");

            DTObject objItems = dto.CreateAndPush("items");

            objItems.SetValue("v", 0);
            objItems.SetValue("n", string.Format("item{0}", 0));

            objItems = dto.CreateAndPush("items");
            objItems.SetValue("v", 1);
            objItems.SetValue("n", string.Format("item{0}", 1));

            DTObject objChilds = objItems.CreateAndPush("childs");

            objChilds.SetValue("v", 10);
            objChilds.SetValue("n", string.Format("child{0}", 10));

            objChilds = objItems.CreateAndPush("childs");
            objChilds.SetValue("v", 20);
            objChilds.SetValue("n", string.Format("child{0}", 20));


            //Assert.AreEqual("{\"items\":[{\"v\",\"n\",\"childs\":[{\"v\",\"n\"}]}]}", dto.GetCode(false));
            Assert.AreEqual("{\"items\":[{\"childs\":[],\"n\":\"item0\",\"v\":0},{\"childs\":[{\"n\":\"child10\",\"v\":10},{\"n\":\"child20\",\"v\":20}],\"n\":\"item1\",\"v\":1}]}", dto.GetCode(true));
        }
コード例 #14
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));
        }
コード例 #15
0
 /// <summary>
 /// 接入数据,该方法与Set方法的区别是,会先重置表单,再设置数据
 /// </summary>
 /// <param name="data"></param>
 public void Accept(DTObject data)
 {
     this.View.WriteCode(string.Format("{0}.proxy().accept({1});", this.Id, data.GetCode(false, false)));
 }
コード例 #16
0
        /// <summary>
        /// 将dto消息发布到指定的交换机
        /// </summary>
        /// <param name="message"></param>
        public void Publish(string exchange, string routingKey, DTObject message, Action <IBasicProperties> setProperties = null)
        {
            var body       = message.ToData();
            var properties = this.Channel.CreateBasicProperties();

            properties.ContentEncoding = "utf-8";
            properties.ContentType     = "text/plain";

            if (setProperties != null)
            {
                setProperties(properties);
            }

            if (this.Policy.PersistentMessages)
            {
                properties.Persistent = true;
                if (!ConfirmPublish(exchange, routingKey, properties, body))
                {
                    throw new RabbitMQException(string.Format(Strings.PublishMessageFailed, message.GetCode()));
                }
            }
            else
            {
                properties.Persistent = false;
                this.Channel.BasicPublish(exchange, routingKey, properties, body);
            }
        }
コード例 #17
0
        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());
        }
コード例 #18
0
 /// <summary>
 /// 设置值
 /// </summary>
 public void SetValue(DTObject value)
 {
     this.View.WriteCode(string.Format("{0}.proxy().set('{1}');", this.Id, value.GetCode()));
 }
コード例 #19
0
        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));
        }
コード例 #20
0
 /// <summary>
 /// 在输出脚本中声明一个变量
 /// </summary>
 public void Var(string name, DTObject value)
 {
     _scriptBody.AppendFormat("var {0}={1};", name, value.GetCode(false, false));
 }
コード例 #21
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));
        }
コード例 #22
0
 /// <summary>
 /// 绑定数据
 /// </summary>
 public void Bind(DTObject data)
 {
     this.View.WriteCode(string.Format("{0}.proxy().bind({1}, {2});", this.Id, data.GetCode(), this.Id));
 }
コード例 #23
0
        ///// <summary>
        ///// 绑定数据
        ///// </summary>
        //public void Bind(DTObject data)
        //{
        //    this.View.WriteCode(string.Format("{0}.proxy().bind({1}, {2});", this.Id, data.GetCode(), this.Id));
        //}

        //public void SelectedItemsIsEmpty()
        //{
        //    this.View.WriteCode(string.Format("{0}.proxy().get().length == 0", this.Id));
        //}

        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="para">参数</param>
        public void Load(DTObject para)
        {
            this.View.WriteCode(string.Format("{0}.proxy().load({1});", this.Id, para == null ? string.Empty : para.GetCode()));
        }
コード例 #24
0
 public void Set(string name, DTObject value)
 {
     _data.SetValue(name, value);
     _owner.WriteCode(string.Format("$$view.session.set('{0}',{1});", name, value.GetCode()));
 }