/// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionRequest" /> class.
 /// </summary>
 /// <param name="sourceType">sourceType (required).</param>
 /// <param name="device">device.</param>
 /// <param name="capability">capability.</param>
 /// <param name="mode">mode.</param>
 /// <param name="deviceLifecycle">deviceLifecycle.</param>
 /// <param name="deviceHealth">deviceHealth.</param>
 /// <param name="securityArmState">securityArmState.</param>
 /// <param name="hubHealth">hubHealth.</param>
 /// <param name="sceneLifecycle">sceneLifecycle.</param>
 public SubscriptionRequest(SubscriptionSource sourceType = default(SubscriptionSource), DeviceSubscriptionDetail device = default(DeviceSubscriptionDetail), CapabilitySubscriptionDetail capability = default(CapabilitySubscriptionDetail), ModeSubscriptionDetail mode = default(ModeSubscriptionDetail), DeviceLifecycleDetail deviceLifecycle = default(DeviceLifecycleDetail), DeviceHealthDetail deviceHealth = default(DeviceHealthDetail), SecurityArmStateDetail securityArmState = default(SecurityArmStateDetail), HubHealthDetail hubHealth = default(HubHealthDetail), SceneLifecycleDetail sceneLifecycle = default(SceneLifecycleDetail))
 {
     this.SourceType       = sourceType;
     this.Device           = device;
     this.Capability       = capability;
     this.Mode             = mode;
     this.DeviceLifecycle  = deviceLifecycle;
     this.DeviceHealth     = deviceHealth;
     this.SecurityArmState = securityArmState;
     this.HubHealth        = hubHealth;
     this.SceneLifecycle   = sceneLifecycle;
 }
Beispiel #2
0
        private void ShowNewVideosToastNotification(Subscription subscription, SubscriptionSource source, IEnumerable <Database.NicoVideo> newItems)
        {
            var mylistMan = (App.Current as App).Container.Resolve <UserMylistManager>();

            // TODO: プレイリスト毎にまとめたほうがいい?

            foreach (var dest in subscription.Destinations)
            {
                Interfaces.IMylist list = null;
                if (dest.Target == SubscriptionDestinationTarget.LocalPlaylist)
                {
                    list = MylistHelper.FindMylistInCached(dest.PlaylistId, PlaylistOrigin.Local);
                }
                else if (dest.Target == SubscriptionDestinationTarget.LoginUserMylist)
                {
                    list = MylistHelper.FindMylistInCached(dest.PlaylistId, PlaylistOrigin.LoginUser);
                }

                IList <Database.NicoVideo> videoList;
                if (NewItemsPerPlayableList.TryGetValue(list, out var cacheVideoList))
                {
                    videoList = cacheVideoList.Item1;

                    if (!cacheVideoList.Item2.Contains(subscription))
                    {
                        cacheVideoList.Item2.Add(subscription);
                    }
                }
                else
                {
                    videoList = new List <Database.NicoVideo>();
                    NewItemsPerPlayableList.Add(list, new Tuple <IList <Database.NicoVideo>, IList <Subscription> >(videoList, new List <Subscription>()
                    {
                        subscription
                    }));
                }

                foreach (var video in newItems)
                {
                    videoList.Add(video);
                }
            }


            try
            {
                foreach (var pair in NewItemsPerPlayableList)
                {
                    var playableList    = pair.Key;
                    var newItemsPerList = pair.Value.Item1;
                    var subscriptions   = pair.Value.Item2;

                    ToastVisual visual = new ToastVisual()
                    {
                        BindingGeneric = new ToastBindingGeneric()
                        {
                            Children = { }
                        }
                    };

                    visual.BindingGeneric.Children.Insert(0, new AdaptiveText()
                    {
                        Text      = $"『{playableList.Label}』に新着動画を追加",
                        HintStyle = AdaptiveTextStyle.Base
                    });

                    foreach (var item in newItemsPerList)
                    {
                        visual.BindingGeneric.Children.Add(new AdaptiveText()
                        {
                            Text      = item.Title,
                            HintStyle = AdaptiveTextStyle.BaseSubtle
                        });
                    }



                    ToastActionsCustom action = new ToastActionsCustom()
                    {
                        Buttons =
                        {
                            new ToastButton("視聴する",  new LoginRedirectPayload()
                            {
                                RedirectPageType = HohoemaPageType.VideoPlayer,RedirectParamter                             = newItemsPerList.First().RawVideoId
                            }.ToParameterString())
                            {
                                ActivationType = ToastActivationType.Foreground,
                            },
                            new ToastButton("購読を管理", new LoginRedirectPayload()
                            {
                                RedirectPageType = HohoemaPageType.Subscription
                            }.ToParameterString())
                            {
                                ActivationType = ToastActivationType.Foreground,
                            },
                        }
                    };

                    ToastContent toastContent = new ToastContent()
                    {
                        Visual  = visual,
                        Actions = action,
                    };

                    var toast = new ToastNotification(toastContent.GetXml());

                    var notifier = ToastNotificationManager.CreateToastNotifier();

                    toast.Tag   = playableList.Id;
                    toast.Group = TOAST_GROUP;
                    notifier.Show(toast);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
Beispiel #3
0
        private async void ShowNewVideosToastNotification(Subscription subscription, SubscriptionSource source, IEnumerable <IVideoContent> newItems)
        {
            var mylistMan = App.Current.Container.Resolve <UserMylistManager>();

            // TODO: プレイリスト毎にまとめたほうがいい?

            foreach (var dest in subscription.Destinations)
            {
                Interfaces.IPlaylist list = null;
                list = await _playlistAggregate.FindPlaylistAsync(dest.PlaylistId);

                if (list == null)
                {
                    // TODO: 購読で利用できない追加先プレイリストを通知する
                    continue;
                }

                IList <IVideoContent> videoList;
                if (NewItemsPerPlayableList.TryGetValue(list, out var cacheVideoList))
                {
                    videoList = cacheVideoList.Item1;

                    if (!cacheVideoList.Item2.Contains(subscription))
                    {
                        cacheVideoList.Item2.Add(subscription);
                    }
                }
                else
                {
                    videoList = new List <IVideoContent>();
                    NewItemsPerPlayableList.Add(list, new Tuple <IList <IVideoContent>, IList <Subscription> >(videoList, new List <Subscription>()
                    {
                        subscription
                    }));
                }

                foreach (var video in newItems)
                {
                    videoList.Add(video);
                }
            }


            try
            {
                foreach (var pair in NewItemsPerPlayableList)
                {
                    var playableList    = pair.Key;
                    var newItemsPerList = pair.Value.Item1;
                    var subscriptions   = pair.Value.Item2;

                    ToastVisual visual = new ToastVisual()
                    {
                        BindingGeneric = new ToastBindingGeneric()
                        {
                            Children = { }
                        }
                    };

                    visual.BindingGeneric.Children.Insert(0, new AdaptiveText()
                    {
                        Text      = "InAppNotification_AddItemToSubscription".Translate(playableList.Label),
                        HintStyle = AdaptiveTextStyle.Base
                    });

                    foreach (var item in newItemsPerList)
                    {
                        visual.BindingGeneric.Children.Add(new AdaptiveText()
                        {
                            Text      = item.Label,
                            HintStyle = AdaptiveTextStyle.BaseSubtle
                        });
                    }



                    ToastActionsCustom action = new ToastActionsCustom()
                    {
                        Buttons =
                        {
                            new ToastButton("WatchVideo".Translate(),           new LoginRedirectPayload()
                            {
                                RedirectPageType = HohoemaPageType.VideoPlayer, RedirectParamter           = $"id={newItemsPerList.First().Id}&playlist_id=@view"
                            }.ToParameterString())
                            {
                                ActivationType = ToastActivationType.Foreground,
                            },
                            new ToastButton("SubscriptionSettings".Translate(), new LoginRedirectPayload()
                            {
                                RedirectPageType = HohoemaPageType.Subscription
                            }.ToParameterString())
                            {
                                ActivationType = ToastActivationType.Foreground,
                            },
                        }
                    };

                    ToastContent toastContent = new ToastContent()
                    {
                        Visual  = visual,
                        Actions = action,
                    };

                    var toast = new ToastNotification(toastContent.GetXml());

                    var notifier = ToastNotificationManager.CreateToastNotifier();

                    toast.Tag   = playableList.Id;
                    toast.Group = TOAST_GROUP;
                    notifier.Show(toast);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
        public bool SubscribeStalk(IrcUserMask mask, IIrcChannel channel, IStalk stalk, out SubscriptionSource source)
        {
            if (channel.Identifier != stalk.Channel)
            {
                throw new Exception("Mismatch between stalk channel and channel!");
            }

            var stalkSubscriber   = stalk.Subscribers.FirstOrDefault(x => x.Mask.ToString() == mask.ToString());
            var channelSubscriber = channel.Users.FirstOrDefault(x => x.Mask.ToString() == mask.ToString());

            this.logger.DebugFormat(
                "Subscription request for {0} to {1} in {2}",
                mask,
                stalk.Identifier,
                channel.Identifier);

            if (stalkSubscriber != null)
            {
                if (stalkSubscriber.Subscribed)
                {
                    if (channelSubscriber != null)
                    {
                        if (channelSubscriber.Subscribed)
                        {
                            // subscribed to channel
                            // subscribed to stalk
                            this.logger.WarnFormat(
                                "Found subscription request from stalk- ({0}) and channel-subscribed ({1}) user ({2})",
                                stalk.Identifier,
                                channel.Identifier,
                                mask);

                            this.logger.DebugFormat(
                                "Unsubscribing from stalk - already subscribed to stalk and channel");
                            stalk.Subscribers.Remove(stalkSubscriber);
                            source = SubscriptionSource.Channel;
                            return(false);
                        }
                        else
                        {
                            // not subscribed to channel
                            // subscribed to stalk
                            this.logger.DebugFormat("Not subscribing - already subscribed to stalk");
                            source = SubscriptionSource.Stalk;
                            return(false);
                        }
                    }
                    else
                    {
                        // not subscribed to channel
                        // subscribed to stalk
                        this.logger.DebugFormat("Not subscribing - already subscribed to stalk");
                        source = SubscriptionSource.Stalk;
                        return(false);
                    }
                }
                else
                {
                    if (channelSubscriber != null)
                    {
                        if (channelSubscriber.Subscribed)
                        {
                            // forcibly unsubscribed from stalk
                            // subscribed to channel
                            this.logger.DebugFormat("Removing forced unsubscribe - already subscribed to channel");
                            stalk.Subscribers.Remove(stalkSubscriber);
                            source = SubscriptionSource.Channel;
                            return(true);
                        }
                        else
                        {
                            // forcibly unsubscribed from stalk
                            // not subscribed to channel
                            this.logger.WarnFormat(
                                "Found subscription request from stalk-force-unsubscribed ({0}) and channel-unsubscribed ({1}) user ({2})",
                                stalk.Identifier,
                                channel.Identifier,
                                mask);
                            this.logger.DebugFormat("Converting forced unsubscribe to stalk subscription");
                            stalkSubscriber.Subscribed = true;
                            source = SubscriptionSource.Stalk;
                            return(true);
                        }
                    }
                    else
                    {
                        // forcibly unsubscribed from stalk
                        // not subscribed to channel
                        this.logger.WarnFormat(
                            "Found subscription request from stalk-force-unsubscribed ({0}) and channel-unsubscribed ({1}) user ({2})",
                            stalk.Identifier,
                            channel.Identifier,
                            mask);
                        this.logger.DebugFormat("Converting forced unsubscribe to stalk subscription");
                        stalkSubscriber.Subscribed = true;
                        source = SubscriptionSource.Stalk;
                        return(true);
                    }
                }
            }
            else
            {
                if (channelSubscriber != null)
                {
                    if (channelSubscriber.Subscribed)
                    {
                        // already subscribed to channel
                        // not subscribed to stalk
                        source = SubscriptionSource.Channel;
                        return(false);
                    }
                    else
                    {
                        // not subscribed to channel
                        // not subscribed to stalk
                        this.logger.DebugFormat("Subscribing to stalk");
                        stalkSubscriber = new StalkUser(mask, true);
                        stalk.Subscribers.Add(stalkSubscriber);
                        source = SubscriptionSource.Stalk;
                        return(true);
                    }
                }
                else
                {
                    // not subscribed to channel
                    // not subscribed to stalk
                    this.logger.DebugFormat("Subscribing to stalk");
                    stalkSubscriber = new StalkUser(mask, true);
                    stalk.Subscribers.Add(stalkSubscriber);
                    source = SubscriptionSource.Stalk;
                    return(true);
                }
            }
        }