Beispiel #1
0
        public void Load(string xmlFile)
        {
            if (!File.Exists(xmlFile))
            {
                return;
            }

            var xml = File.ReadAllText(xmlFile);

            if (string.IsNullOrEmpty(xml))
            {
                return;
            }
            var config = Serializer.Deserialize(xml);

            Sessions.Clear();
            Connections.Clear();
            Subscriptions.Clear();
            DataCaptures.Clear();

            Sessions.AddRange(config.Sessions);
            Connections.AddRange(config.Connections);
            Subscriptions.AddRange(config.Subscriptions);
            SavedMessages.AddRange(config.SavedMessages);
            DataCaptures.AddRange(config.DataCaptures);
        }
        public void AddRange(IEnumerable <string> subscriptions)
        {
            if (Subscriptions == null)
            {
                Subscriptions = new List <string>();
            }

            Subscriptions.AddRange(subscriptions);
        }
Beispiel #3
0
        public Subscribe(IEnumerable <Subscription> subscriptions, MessageId messageId)
            : this(new FixedHeader(CommandMessage.SUBSCRIBE), null)
        {
            Header.QualityOfService = QualityOfService.AtLeastOnce;

            if (subscriptions != null)
            {
                Subscriptions.AddRange(subscriptions);
            }

            MessageId = messageId;
        }
Beispiel #4
0
        public async Task Init()
        {
            await DB.Initialize();

            var subs = DB.Connection.Table <NotificationSubscription>();

            if (await subs.CountAsync() > 0)
            {
                Subscriptions.AddRange(await subs.ToListAsync());
            }
            OnPropertyChanged(nameof(ShowEmptyView));
        }
Beispiel #5
0
        public IDisposable Subscribe(Subscription[] subscriptions, SubscriptionOptions options = SubscriptionOptions.Default)
        {
            lock (Subscriptions)
            {
                Subscriptions.AddRange(subscriptions);
            }

            return(new DisposableAction(() =>
            {
                lock (Subscriptions)
                {
                    Subscriptions.RemoveRange(subscriptions);
                }
            }));
        }
Beispiel #6
0
        public void MakeItSmart()
        {
            if (Interlocked.CompareExchange(ref _state, States.Enabled, States.New) != States.New)
            {
                return;
            }

            using (Initializing())
            {
                Subscriptions.AddRange(CreateHubs() ?? Enumerable.Empty <IDisposable>());
                CreateRooms();
                Subscriptions.AddRange(CreateDevices() ?? Enumerable.Empty <IDisposable>());
                Subscriptions.AddRange(CreateScenes() ?? Enumerable.Empty <IDisposable>());
                Subscriptions.AddRange(CreateAutomations() ?? Enumerable.Empty <IDisposable>());
            }
        }
Beispiel #7
0
 public RecipeListViewModel(IRecipeCollectionService recipeService, IMvxMessenger messenger)
 {
     if (recipeService == null)
     {
         throw new ArgumentNullException(nameof(recipeService));
     }
     if (messenger == null)
     {
         throw new ArgumentNullException(nameof(messenger));
     }
     Query          = new RecipeQuery();
     _recipeService = recipeService;
     _messenger     = messenger;
     Recipes        = new ObservableCollection <RecipeListItemViewModel>();
     Subscriptions.AddRange(new List <IDisposable>
     {
         _messenger.Subscribe <RecipeAdded>(OnRecipeAdded),
         _messenger.Subscribe <RecipeFavoriteTagChanging>(OnRecipeFavoriteTagChanging),
         _messenger.Subscribe <RecipeFavoriteTagChanged>(OnRecipeFavoriteTagChanged),
         _messenger.Subscribe <RecipeUpdated>(OnRecipeUpdated),
         _messenger.Subscribe <RecipeRemoved>(OnRecipeRemoved),
     });
 }
Beispiel #8
0
        public IDisposable Subscribe(Subscription[] subscriptions, Action <IMessage> handler)
        {
            lock (Subscriptions)
            {
                Subscriptions.AddRange(subscriptions);
            }

            var handlerKeys = subscriptions.Select(x => new HandlerKey(x.MessageTypeId.GetMessageType(), default(PeerId))).ToList();

            foreach (var handlerKey in handlerKeys)
            {
                _handlers[handlerKey] = x =>
                {
                    handler(x);
                    return(null);
                };
            }

            return(new DisposableAction(() =>
            {
                _handlers.RemoveRange(handlerKeys);
                Subscriptions.RemoveRange(subscriptions);
            }));
        }
Beispiel #9
0
 public Subscriber(Uri uri, IEnumerable <Subscription> subscriptions)
 {
     Uri = uri;
     Subscriptions.AddRange(subscriptions);
 }