Пример #1
0
        /// <summary>
        /// This will overwrite all current channels - any channels that no longer exist will be blanked out on any pending local notifications
        /// </summary>
        /// <param name="channels"></param>
        /// <returns></returns>
        public static async Task SetChannels(this INotificationManager manager, params Channel[] channels)
        {
            var currentChannels = await manager.GetChannels();

            // if the current channel doesn't exist in the incoming channels, remove it and nullify channel ID from pending notifications
            foreach (var currentChannel in currentChannels)
            {
                // if the currentchannel doesn't exist in incoming channels, remove the channel
                var exists = channels.Any(x => x.Identifier.Equals(
                                              currentChannel.Identifier, StringComparison.InvariantCultureIgnoreCase
                                              ));
                if (!exists)
                {
                    await manager.RemoveChannel(currentChannel.Identifier);
                }
            }

            // if the incoming channels don't exist in the current channels, create them
            foreach (var channel in channels)
            {
                var exists = currentChannels.Any(x => x.Identifier.Equals(
                                                     channel.Identifier, StringComparison.InvariantCultureIgnoreCase
                                                     ));
                if (!exists)
                {
                    await manager.AddChannel(channel);
                }
            }
        }
Пример #2
0
        public ChannelCreateViewModel(INavigationService navigator,
                                      INotificationManager manager,
                                      IDialogs dialogs)
        {
            this.Create = ReactiveCommand.CreateFromTask
                          (
                async() =>
            {
                await manager.AddChannel(this.ToChannel());
                await navigator.GoBack();
            },
                this.WhenAny(
                    x => x.Identifier,
                    x => x.Description,
                    (id, desc) =>
                    !id.GetValue().IsEmpty() &&
                    !desc.GetValue().IsEmpty()
                    )
                          );

            this.PickImportance = dialogs.PickEnumValueCommand <ChannelImportance>(
                "Importance",
                x => this.Importance = x.ToString()
                );

            this.PickActionType1 = dialogs.PickEnumValueCommand <ChannelActionType>(
                "Action Type",
                x => this.Action1ActionType = x.ToString(),
                this.WhenAny(
                    x => x.UseAction1,
                    x => x.GetValue()
                    )
                );
            this.PickActionType2 = dialogs.PickEnumValueCommand <ChannelActionType>(
                "Action Type",
                x => this.Action2ActionType = x.ToString(),
                this.WhenAny(
                    x => x.UseAction2,
                    x => x.GetValue()
                    )
                );
        }