示例#1
0
        /// <summary>
        /// Resolves reference type using promise
        /// </summary>
        /// <param name="promise">Promise</param>
        /// <param name="valueFactory">Function that obtains original value</param>
        /// <param name="hashFactory">Function that obtains hash of query</param>
        /// <param name="description">Function that obtains description of query</param>
        /// <typeparam name="T">Resolved reference-type</typeparam>
        /// <returns>Reference-type either resolved from test data or real one</returns>
        public static T ResolveReference <T>(this Promised <T> promise, Func <T> valueFactory, Func <string> hashFactory,
                                             Func <string> description = null, Func <T, T> clone = null)
            where T : class
        {
            try
            {
                T result;
                if (promise is Containing <T> c)
                {
                    var hashString = hashFactory();
                    result = c.Get(hashString, description?.Invoke());
                }
                else
                {
                    result = valueFactory();
                    if (promise is NotifyCompleted <T> nc)
                    {
                        nc.Fulfill(description?.Invoke());
                    }
                }

                if (promise is Demanding <T> d)
                {
                    var hashString = hashFactory();
                    if (clone != null)
                    {
                        d.Fulfill(result, clone(result), hashString, description?.Invoke());
                    }
                    else
                    {
                        d.Fulfill(result, hashString, description?.Invoke());
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                if (promise is Catching <T> d)
                {
                    d.Fulfill(ex, description?.Invoke());
                }

                throw;
            }
        }
示例#2
0
        /// <summary>
        /// A convenience method for creating an adapter for an inlet pair.
        /// This will automatically connect the adapter to the internal inlet and pass events between the adapter and external inlet.
        ///
        /// The external inlet should be the inlet the world can interact with, while the internal inlet is the corresponding inlet of
        /// our internal pipe system - the implementation of this pipe.
        /// </summary>
        protected IAdapterOutlet <TMessage> CreateAndConnectAdapter <TMessage>(IInlet <TMessage> internalInlet, IInlet <TMessage> externalInlet)
        {
            var promisedPipe = new Promised <IPipe>();

            promisedPipe.Fulfill(this);

            var adapterOutlet = new AdapterOutlet <TMessage>(promisedPipe);

            SharedResource.ConnectTo(adapterOutlet.SharedResource);

            adapterOutlets.Add(adapterOutlet);
            inletOutletBiLookup.Add(externalInlet, adapterOutlet);

            // Do not check if the graph forms a tree - it probably doesn't as all adapters are connected
            // to this pipe. However, messages should never be passed in a cycle or violate the "tree-ness" nevertheless.
            adapterOutlet.ConnectTo(internalInlet, false);
            return(adapterOutlet);
        }
 public void Post(string target, [FromBody] Promised message)
 {
     _queues.ProposerQueues[target].Enqueue(message);
 }