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; } } } }
// 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); }
public DataDelegateRequest Send(PayloadDelegate payloadDelegate) { _dataDelegateRequest.Init(payloadDelegate); return(_dataDelegateRequest); }
public DataDelegateRequest Send(PayloadDelegate payloadDelegate) { _dataDelegateRequest.Init(payloadDelegate); return _dataDelegateRequest; }