예제 #1
0
        public void ProcessIncomingUpdate(IDictionary <string, object> payload, PayloadDelegate reply)
        {
            // properties
            var properties = payload.Where(e => !e.Key.StartsWith("#") && !e.Key.StartsWith("!")).ToDictionary(e => e.Key, e => e.Value);

            foreach (IFacet facet in facets)
            {
                if (properties.Count > 0)
                {
                    // properties can be mutated by this call
                    facet.Set(properties);
                }
            }

            // the remaining property keys haven't been recognized by any facets
            if (properties.Count > 0)
            {
                throw new PayloadException("Incoming payload contains invalid keys: " + string.Join(", ", properties.Keys));
            }

            // children
            foreach (var entry in payload.Where(e => e.Key.StartsWith("#")))
            {
                string name         = entry.Key.Substring(1);
                var    childPayload = (Dictionary <string, object>)entry.Value;

                ChildEntity child;
                // childPayload can be mutated by this call
                if (!TryResolve(name, childPayload, out child))
                {
                    throw new PayloadException("Cannot resolve child named: " + name);
                }

                // childPayload can and likely will be mutated by this call
                child.ProcessIncomingUpdate(childPayload, reply);
            }

            // methods
            foreach (var entry in payload.Where(e => e.Key.StartsWith("!")))
            {
                string   name = entry.Key.Substring(1);
                object[] args = ((IList <object>)entry.Value).ToArray();
                foreach (var facet in facets)
                {
                    if (facet.TryInvoke(name, args, reply))
                    {
                        break;
                    }
                }
            }
        }
예제 #2
0
        // The default implementation tries to invoke a public method of this facet.
        public virtual bool TryInvoke(string name, object[] args, PayloadDelegate reply)
        {
            MethodInfo method = GetType().GetMethod(name, BindingFlags.Public | BindingFlags.Instance);

            if (method != null)
            {
                if (reply != null)
                {
                    args = args.Concat(new object[] { reply }).ToArray();
                }
                method.Invoke(this, args);
                return(true);
            }
            return(false);
        }
예제 #3
0
 public DataDelegateRequest Send(PayloadDelegate payloadDelegate)
 {
     _dataDelegateRequest.Init(payloadDelegate);
     return(_dataDelegateRequest);
 }
예제 #4
0
 public DataDelegateRequest Send(PayloadDelegate payloadDelegate)
 {
     _dataDelegateRequest.Init(payloadDelegate);
     return _dataDelegateRequest;
 }