Esempio n. 1
0
        public async Task RemoveObserverAsync(StoreNotificationType notificationType, Uri observer)
        {
            try
            {
                var listenersDict = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, List <Uri> > >("ListenersDictionary");

                using (ITransaction tx = this.StateManager.CreateTransaction())
                {
                    List <Uri> newList = null;
                    var        result1 = await listenersDict.TryGetValueAsync(tx, notificationType.ToString());

                    if (result1.HasValue)
                    {
                        newList = new List <Uri>(result1.Value);
                    }
                    else
                    {
                        newList = new List <Uri>();
                    }

                    if (newList.Contains(observer))
                    {
                        newList.Remove(observer);
                    }
                    await listenersDict.SetAsync(tx, notificationType.ToString(), newList);

                    await tx.CommitAsync();
                }
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.Message(ex.Message);
            }
        }
Esempio n. 2
0
        public async Task RaiseNotificationAsync(StoreNotificationType notificationType, string product, AppDocument newDoc)
        {
            try
            {
                var listenersDict = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, List <Uri> > >("ListenersDictionary");

                using (ITransaction tx = this.StateManager.CreateTransaction())
                {
                    List <Uri> newList = null;
                    var        result1 = await listenersDict.TryGetValueAsync(tx, notificationType.ToString());

                    if (result1.HasValue)
                    {
                        newList = new List <Uri>(result1.Value);
                    }
                    else
                    {
                        newList = new List <Uri>();
                    }

                    foreach (var listener in newList)
                    {
                        // This only creates a proxy object, it does not activate an actor or invoke any methods yet.
                        var myActor = ActorProxy.Create <IAdapter>(new ActorId(product), listener);

                        // This will invoke a method on the actor. If an actor with the given ID does not exist, it will be activated by this method call.
                        await myActor.NewAppConfigAvailable(newDoc);
                    }

                    await tx.CommitAsync();
                }
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.Message(ex.Message);
            }
        }