Exemplo n.º 1
0
        public XmlContent ELEM(XElem e)
        {
            Add('<');
            Add(e.Tag);
            if (e.Attrs != null)
            {
                Roll <XAttr> attrs = e.Attrs;
                for (int i = 0; i < attrs.Count; i++)
                {
                    XAttr attr = attrs[i];
                    Add(' ');
                    Add(attr.Name);
                    Add('=');
                    Add('"');
                    AddEsc(attr.Value);
                    Add('"');
                }
            }
            Add('>');

            if (e.Text != null)
            {
                AddEsc(e.Text);
            }
            if (e.Count > 0)
            {
                for (int i = 0; i < e.Count; i++)
                {
                    ELEM(e.Child(i));
                }
            }
            Add("</");
            Add(e.Tag);
            Add('>');

            return(this);
        }
Exemplo n.º 2
0
        internal Client(Service service, string peerid, string raddr)
        {
            this.service = service;
            this.peerid  = peerid;

            Roll <EventInfo> eis = service?.Events;

            if (eis != null)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < eis.Count; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(',');
                    }
                    sb.Append(eis[i].Name);
                }
                x_event = sb.ToString();
            }

            BaseAddress = new Uri(raddr);
            Timeout     = TimeSpan.FromSeconds(5);
        }
Exemplo n.º 3
0
        // to obtain a string key from a data object.
        protected Work(WorkContext wc) : base(wc.Name, null)
        {
            this.ctx = wc;

            // gather actions
            actions = new Roll <ActionInfo>(32);
            Type typ = GetType();

            typeinfo = typ.GetTypeInfo();

            foreach (MethodInfo mi in typ.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                // verify the return type
                Type ret = mi.ReturnType;
                bool async;
                if (ret == typeof(Task))
                {
                    async = true;
                }
                else if (ret == typeof(void))
                {
                    async = false;
                }
                else
                {
                    continue;
                }

                ParameterInfo[] pis = mi.GetParameters();
                ActionInfo      ai;
                if (pis.Length == 1 && pis[0].ParameterType == typeof(ActionContext))
                {
                    ai = new ActionInfo(this, mi, async, false);
                }
                else if (pis.Length == 2 && pis[0].ParameterType == typeof(ActionContext) && pis[1].ParameterType == typeof(int))
                {
                    LimitAttribute limit = (LimitAttribute)pis[1].GetCustomAttribute(typeof(LimitAttribute));
                    ai = new ActionInfo(this, mi, async, true, limit?.Value ?? 20);
                }
                else
                {
                    continue;
                }

                actions.Add(ai);
                if (ai.Name.Equals("default"))
                {
                    @default = ai;
                }
            }

            // gather ui actions
            int btns = 0;
            List <ActionInfo> uias = null;

            for (int i = 0; i < actions.Count; i++)
            {
                ActionInfo ai = actions[i];
                if (ai.HasUi)
                {
                    if (uias == null)
                    {
                        uias = new List <ActionInfo>();
                    }
                    uias.Add(ai);
                    if (ai.Ui.IsButton)
                    {
                        btns++;
                    }
                }
            }
            uiActions = uias?.ToArray();
            buttons   = btns;
        }
Exemplo n.º 4
0
        protected Service(ServiceContext sc) : base(sc)
        {
            sc.Service = this;
            this.ctx   = sc;

            id = (Shard == null) ? sc.Name : sc.Name + "-" + Shard;

            // setup logging
            LoggerFactory factory = new LoggerFactory();

            factory.AddProvider(this);
            string     file = sc.GetFilePath('$' + DateTime.Now.ToString("yyyyMM") + ".log");
            FileStream fs   = new FileStream(file, FileMode.Append, FileAccess.Write);

            logWriter = new StreamWriter(fs, Encoding.UTF8, 1024 * 4, false)
            {
                AutoFlush = true
            };

            // create kestrel instance
            KestrelServerOptions options = new KestrelServerOptions();

            server = new KestrelServer(Options.Create(options), Application.Lifetime, factory);
            ICollection <string> addrcoll = server.Features.Get <IServerAddressesFeature>().Addresses;

            if (Addrs == null)
            {
                throw new ServiceException("missing 'addrs'");
            }
            foreach (string a in Addrs)
            {
                addrcoll.Add(a.Trim());
            }

            // events
            Type typ = GetType();

            foreach (MethodInfo mi in typ.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                // verify the return type
                Type ret = mi.ReturnType;
                bool async;
                if (ret == typeof(Task))
                {
                    async = true;
                }
                else if (ret == typeof(void))
                {
                    async = false;
                }
                else
                {
                    continue;
                }

                ParameterInfo[] pis = mi.GetParameters();
                EventInfo       evt;
                if (pis.Length == 1 && pis[0].ParameterType == typeof(EventContext))
                {
                    evt = new EventInfo(this, mi, async, false);
                }
                else if (pis.Length == 2 && pis[0].ParameterType == typeof(EventContext) && pis[1].ParameterType == typeof(string))
                {
                    evt = new EventInfo(this, mi, async, true);
                }
                else
                {
                    continue;
                }

                if (events == null)
                {
                    events = new Roll <EventInfo>(16);
                }
                events.Add(evt);
            }

            // cluster connectivity
            if (Cluster != null)
            {
                foreach (KeyValuePair <string, string> entry in Cluster)
                {
                    if (clients == null)
                    {
                        clients = new Roll <Client>(Cluster.Count * 2);
                    }
                    clients.Add(new Client(this, entry.Key, entry.Value));

                    if (queues == null)
                    {
                        queues = new Roll <EventQueue>(Cluster.Count * 2);
                    }
                    queues.Add(new EventQueue(entry.Key));
                }
            }

            // response cache
            cleaner = new Thread(Clean);
            cachies = new ConcurrentDictionary <string, Cachie>(Environment.ProcessorCount * 2, 1024);
        }