Example #1
0
        /// <summary>
        /// Executes a database request.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="subscriber"></param>
        /// <returns></returns>
        private bool ExecuteDataRequest(PublishArgs args, IContact subscriber)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            if (subscriber == null)
            {
                throw new ArgumentNullException("subscriber");
            }

            try
            {
                DataRequest request = args.Publish.Message as DataRequest;

                if (request == null)
                {
                    throw new ProcessorException(
                              string.Format(
                                  "Cannot execute data request because the published message is not of type '{0}'.",
                                  typeof(DataRequest).AssemblyQualifiedName()));
                }

                ISubscription subscription = subscriber.ToSubscription();

                Message response = request.Execute(new DataRequestParameters
                {
                    BaseUrl   = subscriber.DataContextUrl(),
                    EntitySet = subscription.EntitySet,
                    Headers   = args.Publish.Headers.AsDictionary()
                });

                if (response != null)
                {
                    args.Peer.Callback(new Publish <Message>
                    {
                        Message = response
                    });
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Warn(string.Format("Could not deliver message to: '{0}'", subscriber.NodeId));
                if (!Kernel.Exceptions.Exception.IsEndpointDown(ex))
                {
                    Log.Error(ex);
                }
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Allows you to request an entity (from the store) and get a callback when load succeeds or fails.
        /// If the entity is not initially loaded, sends the usual notifications and then listens for updates
        /// </summary>
        public static Request <DataType> Resolve(
            string loadKey,
            HasEntities <DataType> store,
            Action <Request <DataType> > callback = null)
        {
            if (string.IsNullOrEmpty(loadKey))
            {
                var err = new LocalRequest <DataType>("Load key cannot be null or empty");
                err.Execute(callback);
                return(err);
            }
            var r = new DataRequest(NewResolveRequest(loadKey), store);

            r.Execute(callback);
            return(r);
        }