internal static EventKey GetEventKey(DTObject @event) { var eventId = @event.GetValue <Guid>("eventId"); var eventName = @event.GetValue <string>("eventName"); return(new EventKey(eventId, eventName)); }
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; }
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)); }
/// <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); }
private string GenerateHtml(DTObject item) { var type = item.GetValue <string>("type"); var label = item.GetValue <string>("name"); var message = item.GetValue <string>("message", string.Empty); var required = item.GetValue <bool>("required", false); switch (type) { case "text": { StringBuilder code = new StringBuilder(); code.AppendFormat("<ms:input type=\"text\" max=\"200\" required=\"{0}\" name=\"{1}\" >", (required ? "true" : "false"), label); code.AppendLine(); code.AppendFormat("<label xs=\"12\">{0}</label>", label); code.AppendLine(); code.AppendLine("<core xs=\"12\"></core>"); code.AppendFormat("<help xs=\"12\">{0}</help>", message); code.AppendLine(); code.AppendLine("</ms:input>"); return(code.ToString()); } case "textarea": { StringBuilder code = new StringBuilder(); code.AppendFormat("<ms:input type=\"textarea\" max=\"2000\" required=\"{0}\" name=\"{1}\" rows=\"4\" >", (required ? "true" : "false"), label); code.AppendLine(); code.AppendFormat("<label xs=\"12\">{0}</label>", label); code.AppendLine(); code.AppendLine("<core xs=\"12\"></core>"); code.AppendFormat("<help xs=\"12\">{0}</help>", message); code.AppendLine(); code.AppendLine("</ms:input>"); return(code.ToString()); } case "radio": return(GetRadioSelectHtml(item, type, label, message, required)); case "dropdown": return(GetDropdownSelectHtml(item, type, label, message, required)); case "checkbox": return(GetCheckboxSelectHtml(item, type, label, message, required)); case "day": case "minute": case "month": return(GetDateTimeHtml(item, type, label, message, required, type)); } return(string.Empty); }
protected void UseDefines(DTObject arg, Action <AggregateRootDefine, object> action) { var typeName = arg.GetValue <string>("typeName"); var defines = RemoteType.GetDefines(typeName); foreach (var define in defines) { var idProperty = DomainProperty.GetProperty(define.MetadataType, EntityObject.IdPropertyName); var id = DataUtil.ToValue(arg.GetValue(EntityObject.IdPropertyName), idProperty.PropertyType); action((AggregateRootDefine)define, id); } }
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()); }
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 }); }
private static RegionRule Create(int id, DTObject dto) { var ruleType = dto.GetValue <string>("ruleType"); //这句话的意思是,我们约定每一个JSON定义里,一定会定义了规则的类型 var factory = _getFactory(ruleType); return(factory.Create(id, dto)); }
public long Size(DTObject info) { try { _info = info; _info["requestId"] = Guid.NewGuid(); _future = new Future <bool>(); //使用该对象监视进度 _future.Start(); UseClient((client) => { var msg = CreateSizeMessage(info); client.Send(msg); }); _future.Wait(); if (_error != null) { throw new ApplicationException(_error); } return(_info.GetValue <long>("size")); } catch (Exception ex) { throw ex; } finally { ClearUp(); //全部执行完毕后清理 } }
public RegionRule Create(int ruleId, DTObject dto) { var content = dto.GetValue <string>("content"); var hardcode = new Hardcode(ruleId, content); return(hardcode); }
public RegionRule Create(int ruleId, DTObject dto) { var width = dto.GetValue <int>("width"); var incrementByMonth = new IncrementByMonth(ruleId, width); return(incrementByMonth); }
/// <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)); } }
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); }
public void CreateStringDTO() { DTObject dto = DTObject.CreateReusable("{name}"); dto.SetValue("name", string.Empty); Assert.AreEqual(string.Empty, dto.GetValue <string>("name")); }
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")); }
/// <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)); }
public void CreateBoolDTO() { DTObject dto = DTObject.CreateReusable("{isShow}"); dto.SetValue("isShow", true); Assert.AreEqual(true, dto.GetValue <bool>("isShow")); }
public void CreateGuidDTO() { DTObject dto = DTObject.CreateReusable("{id}"); dto.SetValue("id", Guid.Empty); Assert.AreEqual(Guid.Empty, dto.GetValue <Guid>("id")); }
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 }); }
private object FindObject(RemotableAttribute tip, DTObject arg) { var idProperty = DomainProperty.GetProperty(tip.ObjectType, EntityObject.IdPropertyName); var id = DataUtil.ToValue(arg.GetValue("id"), idProperty.PropertyType); var repository = Repository.Create(tip.ObjectType); return(repository.Find(id, QueryLevel.None)); }
private static void FillItems(DTObject itemData, List <UIMenuItem> items) { var name = itemData.GetValue <string>("name", string.Empty); var icon = itemData.GetValue <string>("icon", string.Empty); var iconFontSize = itemData.GetValue <string>("iconFontSize", string.Empty); var tags = string.Join(",", itemData.GetList("tags").ToArray <string>()); var code = itemData.GetValue <string>("code", string.Empty); UIMenuItem item = new UIMenuItem(name, icon, iconFontSize, tags, code); var childs = itemData.GetList("childs", false); if (childs != null) { item.AddChilds(MapChildItems(childs)); } items.Add(item); }
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); }
private string GetSchemaCode(RemotableAttribute tip, DTObject arg) { var metadataSchemaCode = arg.GetValue("schemaCode", string.Empty); if (string.IsNullOrEmpty(metadataSchemaCode)) { return(tip.SchemaCode); //外界没有传递对象代码,那么使用默认的代码 } if (string.IsNullOrEmpty(tip.SchemaCode)) { return(metadataSchemaCode); //没有设置默认代码,表示不限制外界方面的数据 } return(_isSafe(tip.SchemaCode)(metadataSchemaCode) ? metadataSchemaCode : tip.SchemaCode); //外界的代码超出规定,那么仅用限定的代码 }
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)); }
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")); }
private static IEnumerable <UIMenuItem> MapMenuItems(DTObject data) { List <UIMenuItem> items = new List <UIMenuItem>(); if (data.GetValue <int>("dataCount") == 0) { return(items); } foreach (var itemData in data.GetList("rows")) { FillItems(itemData, items); } return(items); }
internal static IContractEvent CreateCE(DTObject dto) { var typeName = dto.GetValue <string>("type", string.Empty); if (string.IsNullOrEmpty(typeName)) { throw new ServiceException("没有定义IContractEvent的类型,无法实例化ContractEvent"); } var factoryType = _getFactoryType(typeName); if (factoryType == null) { throw new ServiceException("没有找到" + typeName + "的类型创建工厂,无法实例化ContractEvent"); } var factory = SafeAccessAttribute.CreateInstance <IContractEventFactory>(factoryType); return(factory.Create(dto)); }