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)); }
private static void FillMenuItem(DTObject item, XmlNode node, string language) { string url = GetNodeValue(node, "url"), target = GetNodeValue(node, "target"); var codeDTO = DTObject.Create(); if (!string.IsNullOrEmpty(url)) { codeDTO.SetValue("url", url); if (!string.IsNullOrEmpty(target)) { codeDTO.SetValue("target", target); } } string name = GetNodeValue(node, "name"); name = ParseName(name, language); string icon = GetNodeValue(node, "icon"); string iconFontSize = GetNodeValue(node, "iconFontSize"); string tags = GetNodeValue(node, "tags"); string roles = GetNodeValue(node, "roles"); if (!string.IsNullOrEmpty(icon)) { item.SetValue("icon", icon); } if (!string.IsNullOrEmpty(iconFontSize)) { item.SetValue("iconFontSize", iconFontSize); } if (!string.IsNullOrEmpty(tags)) { var temp = tags.Split(','); item.Push("tags", temp, (t, tag) => { t.SetValue(tag); }); } if (!string.IsNullOrEmpty(roles)) { var temp = roles.Split(','); item.Push("roles", temp, (t, role) => { t.SetValue(role); }); } item.SetValue("name", name); item.SetObject("code", codeDTO); foreach (XmlNode childNode in node.ChildNodes) { if (childNode.NodeType != XmlNodeType.Element) { continue; } var child = item.CreateAndPush("childs"); FillMenuItem(child, childNode, language); } }
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))); }
private Message CreateLeaveMessage(string multicastAddress) { DTObject header = DTObject.Create(); header.SetValue(MessageField.MessageType, (byte)MessageType.Leave); header.SetValue(MessageField.MulticastAddress, multicastAddress); return(new Message(header, this.Host.Data)); }
public static DTObject CreateFailed(Exception ex) { DTObject failed = DTObject.Create(); failed.SetValue("status", "failed"); failed.SetValue("message", GetMessage(ex)); return(failed); }
private Message CreateIAmNotHereMessage(string multicastAddress) { DTObject header = DTObject.Create(); header.SetValue(MessageField.MessageType, (byte)MessageType.IAmNotHere); header.SetValue(MessageField.MulticastAddress, multicastAddress); return(new Message(header, Array.Empty <byte>())); }
private Message CreateIAmHereMessage(Multicast multicast, string destination) { DTObject header = DTObject.Create(); header.SetValue(MessageField.MessageType, (byte)MessageType.IAmHere); header.SetValue(MessageField.MulticastAddress, multicast.Address); header.SetValue(MessageField.Destination, destination); return(new Message(header, multicast.Host.Data)); }
public static DTObject CreateFailed(Exception ex) { DTObject failed = DTObject.Create(); failed.SetValue("status", "failed"); failed.SetValue("message", GetMessage(ex)); failed.SetValue("userError", ex is UserUIException); //用户错误 return(failed); }
private Message CreateUpdateParticipant(string multicastAddress) { DTObject header = DTObject.Create(); header.SetValue(MessageField.MessageType, (byte)MessageType.ParticipantUpdated); header.SetValue(MessageField.MulticastAddress, multicastAddress); header.SetValue(MessageField.Destination, multicastAddress); return(new Message(header, this.Host.Data)); }
/// <summary> /// 登录 /// </summary> /// <param name="data"></param> /// <returns></returns> protected virtual bool SignIn(DTObject data) { data.Transform("username=>flag"); data.SetValue("photoWidth", 80); data.SetValue("photoHeight", 80); var handler = ModuleController.GetHandler("login"); var result = handler.Process(data); return(result.GetValue <bool>("success")); }
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()); }
protected virtual string GetMenuCodeActionProduce() { DTObject para = DTObject.Create(); para.SetValue("markedCode", this.RootMenu); para.SetValue("isLocal", this.IsLocalMenu); var handler = ModuleController.GetHandler("menu.show"); var result = handler.Process(para); return(result.GetValue <string>("menuCode")); }
public T GetElement <T>(string elementId) where T : ScriptElement { ScriptElement e = null; if (!_elementsCache.TryGetValue(elementId, out e)) { lock (_elementsCache) { if (!_elementsCache.TryGetValue(elementId, out e)) { DTObject element = GetElementById(elementId); if (element == null) { //没有找到输入项时,采用自由模式 element = DTObject.Create("{id,metadata:{}}"); element.SetValue("id", elementId); _scriptHeader.AppendFormat("var {0} = $('#{0}');", elementId); } //if (element == null) throw new XamlException("没有找到编号为" + elementId + "的脚本元素"); e = ElementFactory.Create <T>(this, element) as T; _elementsCache.Add(elementId, e); } } } return((T)e); }
/// <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)); }
/// <summary> /// 脚本视图输出dto格式的指令 /// </summary> /// <returns></returns> public DTObject Output() { var code = GetCode(); DTObject output = DTObject.Create(); output.SetValue("process", code.ToBase64(Encoding.UTF8)); //进行编码,此处编码不是因为DTO的转义而是避免script等特殊标签令客户端执行的时候代码冲突报错, return(output); }
public void Serialize(DTObject owner, string name) { if (this.IsEmpty()) { return; } owner.SetValue(name, this.GetData()); }
public void CreateGuidDTO() { DTObject dto = DTObject.CreateReusable("{id}"); dto.SetValue("id", Guid.Empty); Assert.AreEqual(Guid.Empty, dto.GetValue <Guid>("id")); }
public void CreateStringDTO() { DTObject dto = DTObject.CreateReusable("{name}"); dto.SetValue("name", string.Empty); Assert.AreEqual(string.Empty, dto.GetValue <string>("name")); }
public void CreateBoolDTO() { DTObject dto = DTObject.CreateReusable("{isShow}"); dto.SetValue("isShow", true); Assert.AreEqual(true, dto.GetValue <bool>("isShow")); }
public void CreateDateTimeDTO() { DTObject dto = DTObject.CreateReusable("{time}"); dto.SetValue("time", DateTime.Parse("2031-08-05")); Assert.AreEqual(DateTime.Parse("2031-08-05"), dto.GetValue <DateTime>("time")); }
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)); }
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")); }
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); }
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()); }
public void Fill(DTObject dto) { dto.SetValue("pageIndex", this.PageIndex); dto.SetValue("pageSize", this.PageSize); }
static DefaultIdentityProvider() { _identity.SetValue("name", Configuration.Current.Authentication.Identity.Name); _identity.SetValue("tokenKey", string.Empty); }
public override void Write(DTObject data) { var value = _input.Text; data.SetValue(this.MemberName, value); }
/// <summary> /// 设置会话数据,该方法会向客户端发射一条命令 /// </summary> /// <param name="name"></param> /// <param name="value"></param> public void Set(string name, object value) { _data.SetValue(name, value); _owner.WriteCode(string.Format("$$view.session.set('{0}',{1});", name, JSON.GetCode(value))); }