Пример #1
0
        public DTObject Process(Action <DTObject> fillArg)
        {
            var arg = DTObject.Create();

            fillArg(arg);
            return(Process(arg));
        }
Пример #2
0
        private static void Rollback(EventLog log, EventLogEntry logEntry, Exception reason)
        {
            var queueId = log.Id;

            if (logEntry.Operation == EventOperation.Raise)
            {
                var content = DTObject.Create(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);
            }
        }
Пример #3
0
        protected override DTObject DynamicInvoke(dynamic arg)
        {
            var result = (dynamic)DTObject.Create();

            result.MenuCode = MenuHelper.GetMenuCode(Language.Current.Name, arg.MarkedCode, arg.IsLocal);
            return(result);
        }
Пример #4
0
 /// <summary>
 /// 获得事件条目的参数
 /// </summary>
 /// <returns></returns>
 public DTObject GetArgs()
 {
     if (this.Source.IsEmpty())
     {
         //根条目
         return(DTObject.Create(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.Create(this.ArgsCode)); //如果已经有代码,那么直接使用
         }
     }
     else
     {
         //远程事件,直接从源事件中得到参数
         var source = this.GetSourceEvent();
         return(source.GetArgs(this.EventName));
     }
 }
Пример #5
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);
        }
Пример #6
0
        public DTObject GetData()
        {
            var data       = DTObject.Create();
            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 <DynamicObject>;
                if (list != null)
                {
                    //集合
                    data.Push(property.Name, list, (item) =>
                    {
                        return(item.GetData());
                    });
                    continue;
                }

                data.SetValue(property.Name, value); //值
            }
            return(data);
        }
        private static Message BuildHeartBeat()
        {
            var header = DTObject.Create();

            header.SetValue(MessageField.MessageType, (byte)MessageType.HeartBeatRequest);
            return(new Message(header, Array.Empty <byte>()));
        }
Пример #8
0
        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);
        }
        private static DTObject BuildTable(string serviceNamespace)
        {
            if (string.IsNullOrEmpty(serviceNamespace))
            {
                serviceNamespace = "default";
            }
            var fileName = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, string.Format("{0}.xml", serviceNamespace));
            var table    = Load(fileName);

            var dto = DTObject.Create();

            foreach (var item in table)
            {
                var row     = dto.CreateAndPush("table");
                var address = item.Key;
                row.SetValue("address", address);

                var services = item.Value;
                row.Push("services", services, (t, service) =>
                {
                    t.SetValue(service);
                });
            }
            return(dto);
        }
Пример #10
0
        public static TransferData Invoke(string method, Action <dynamic> fillArg)
        {
            var arg = DTObject.Create();

            fillArg(arg);
            return(Invoke(method, arg));
        }
Пример #11
0
        private static object CallWebMethod(UIElement component, object[] args)
        {
            var arg = args.Length == 0 ? DTObject.Create() : args[0] as DTObject;

            if (arg == null)
            {
                throw new XamlException("处理事件参数错误");
            }

            //{component,action,argument:{sender:{id,metadata:{}},elements:[{id,metadata:{}}]}}
            var actionName = arg.GetValue <string>("action", string.Empty);

            if (string.IsNullOrEmpty(actionName))
            {
                throw new XamlException("处理事件参数错误,没有指定action");
            }

            var componentName = arg.GetValue <string>("component", string.Empty);

            DTObject argument = null;

            if (!arg.TryGetObject("argument", out argument))
            {
                throw new XamlException("处理事件参数错误,没有指定argument");
            }

            var view = component.CallScriptAction(componentName, actionName, new ScriptView(argument)) as IScriptView;

            return(view.Output());
        }
Пример #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));
            }
        }
Пример #13
0
        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);
            }
        }
Пример #14
0
        public void SendError(WebPageContext context, string error)
        {
            var dto = DTObject.Create("{status,message}");

            dto.SetValue("status", "error");
            dto.SetValue("message", error);
            this.Send(context, dto);
        }
Пример #15
0
        public static DTObject CreateFailed(Exception ex)
        {
            DTObject failed = DTObject.Create();

            failed.SetValue("status", "failed");
            failed.SetValue("message", GetMessage(ex));
            return(failed);
        }
Пример #16
0
        /// <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);
        }
Пример #17
0
        private static DTObject GetEvent(int id)
        {
            var dto = DTObject.Create();

            dto["name"] = EventName;
            dto["id"]   = id;
            return(dto);
        }
Пример #18
0
        private static DTObject GetLocalIdentity()
        {
            var identity = DTObject.Create();

            identity.SetValue("name", CodeArt.Configuration.Current.IdentityName);
            identity.SetValue("language", CodeArt.Language.Current.Name);
            return(identity.AsReadOnly());
        }
Пример #19
0
        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));
        }
Пример #20
0
        public new DTObject GetIdentity()
        {
            var identity = DTObject.Create();

            identity["language"] = this.Language;
            identity["tenantId"] = this.TenantId;
            return(identity);
        }
Пример #21
0
        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>()));
        }
Пример #22
0
        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));
        }
        private Message BuildLoginReq()
        {
            var header = DTObject.Create();

            header.SetValue(MessageField.MessageType, MessageType.LoginRequest);
            header.SetObject(MessageField.LoginIdentity, this.Client.Config.IdentityProvider.GetIdentity());

            return(new Message(header, Array.Empty <byte>()));
        }
        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);
        }
Пример #25
0
        /// <summary>
        /// 写入并提交触发事件条目的日志
        /// </summary>
        /// <param name="queue"></param>
        /// <param name="content"></param>
        public static void FlushRaise(EventQueue queue, EventEntry entry)
        {
            var logId = queue.Id;
            //写入日志
            var content = DTObject.Create();

            content["entryId"] = entry.Id;
            EventLog.WriteAndFlush(logId, EventOperation.Raise, content);
        }
Пример #26
0
        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));
        }
Пример #27
0
        public static byte[] SerializeParticipant(Participant participant)
        {
            var dto = DTObject.Create();

            dto.SetValue("id", participant.Id);
            dto.SetValue("name", participant.Name);
            dto.SetObject("extensions", participant.Extensions);
            return(dto.ToData());
        }
Пример #28
0
        private static DTObject CreateEventArg(RemoteType remoteType, object id)
        {
            var arg = DTObject.Create();

            arg["identity"] = AppContext.Identity;
            arg["typeName"] = remoteType.FullName;
            arg["id"]       = id;
            return(arg);
        }
Пример #29
0
        private Message CreateLoadMessage(DTObject info, byte[] content)
        {
            var header = DTObject.Create();

            header.SetObject("info", info);
            header.SetValue(MessageField.MessageType, MessageType.Custom);
            header.SetValue(TransferCommand.LoadResult, true);
            return(new Message(header, content));
        }
Пример #30
0
        private Message CreateSizeMessage(DTObject info)
        {
            var header = DTObject.Create();

            header.SetObject("info", info);
            header.SetValue(MessageField.MessageType, MessageType.Custom);
            header.SetValue(TransferCommand.SizeResult, true);
            return(new Message(header, Array.Empty <byte>()));
        }