Пример #1
0
        /// <summary>
        /// Retrieve the local object.
        /// </summary>
        /// <param name="receiveContext">Context to find the local object by an identifier.</param>
        /// <param name="localContextAction">How to modify the resolveContext once the object was retrieved.</param>
        /// <returns>Local object.</returns>
        public T Retrieve(ILocalReceiveContext receiveContext, LocalContextAction localContextAction)
        {
            object output    = null;
            bool   itemFound = receiveContext.GuidToLocalObjects.TryGetValue(GlobalIdentifier, out output);
            T      item      = (output != null) ? (T)output : default(T);

            switch (localContextAction)
            {
            case LocalContextAction.LookupInsertIfNotFound:
                if (!itemFound)
                {
                    item = CreateLocalObject(receiveContext, localContextAction);
                    if (item != null)
                    {
                        receiveContext.GuidToLocalObjects[GlobalIdentifier] = item;
                    }
                }
                if (item != null)
                {
                    return(item);
                }
                break;

            case LocalContextAction.Delete:
                if (!itemFound)
                {
                    item = CreateLocalObject(receiveContext, localContextAction);
                }
                receiveContext.GuidToLocalObjects.Remove(GlobalIdentifier);
                return(item);
            }

            return(item);
        }
Пример #2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="streamProvider">Stream provider to be used.</param>
 /// <param name="receiveContext"></param>
 /// <param name="tearDownFunc">Function to be executed after tear down.</param>
 /// <param name="items"></param>
 public TransactionalStreamRemoteObjectConsumer(IStreamProvider streamProvider, ILocalReceiveContext receiveContext, Func <Task> tearDownFunc = null, IList <T> items = null) : base(streamProvider, tearDownFunc)
 {
     Items          = items ?? new List <T>();
     ReceiveContext = receiveContext;
 }
Пример #3
0
 protected abstract T CreateLocalObject(ILocalReceiveContext resolveContext, LocalContextAction localContextAction);
Пример #4
0
 /// <summary>
 /// Retrieve the local object.
 /// </summary>
 /// <param name="receiveContext">Context to find the local object by an identifier.</param>
 /// <param name="localContextAction">How to modify the receiveContext once the object was retrieved.</param>
 /// <returns>Local object.</returns>
 object IObjectRemoteValue.Retrieve(ILocalReceiveContext receiveContext, LocalContextAction localContextAction)
 {
     return(Retrieve(receiveContext, localContextAction));
 }