Ejemplo n.º 1
0
        public StreamingPlatformAccountControlViewModel(StreamingPlatformTypeEnum platform)
        {
            this.Platform = platform;

            if (this.IsUserAccountConnected)
            {
                if (this.Platform == StreamingPlatformTypeEnum.Twitch && ChannelSession.TwitchUserNewAPI != null)
                {
                    this.UserAccountAvatar   = ChannelSession.TwitchUserNewAPI.profile_image_url;
                    this.UserAccountUsername = ChannelSession.TwitchUserNewAPI.display_name;
                }
            }
            if (this.IsBotAccountConnected)
            {
                if (this.Platform == StreamingPlatformTypeEnum.Twitch && ChannelSession.TwitchBotNewAPI != null)
                {
                    this.BotAccountAvatar   = ChannelSession.TwitchBotNewAPI.profile_image_url;
                    this.BotAccountUsername = ChannelSession.TwitchBotNewAPI.display_name;
                }
            }

            this.UserAccountCommand = this.CreateCommand(async(parameter) =>
            {
                if (this.IsUserAccountConnected)
                {
                    //if (this.Platform == StreamingPlatformTypeEnum.Mixer)
                    //{
                    //    ChannelSession.DisconnectMixerUser();
                    //}
                    //this.UserAccountAvatar = null;
                    //this.UserAccountUsername = null;
                }
                else
                {
                    Result result = new Result(false);
                    if (this.Platform == StreamingPlatformTypeEnum.Twitch)
                    {
                        result = await ChannelSession.ConnectTwitchUser();
                        if (result.Success && ChannelSession.TwitchUserNewAPI != null)
                        {
                            this.UserAccountAvatar   = ChannelSession.TwitchUserNewAPI.profile_image_url;
                            this.UserAccountUsername = ChannelSession.TwitchUserNewAPI.display_name;
                        }
                    }

                    if (!result.Success)
                    {
                        this.UserAccountAvatar   = null;
                        this.UserAccountUsername = null;

                        await DialogHelper.ShowMessage(result.Message);
                    }
                }
                this.NotifyAllProperties();
            });

            this.BotAccountCommand = this.CreateCommand(async(parameter) =>
            {
                if (this.IsBotAccountConnected)
                {
                    if (this.Platform == StreamingPlatformTypeEnum.Twitch)
                    {
                        await ChannelSession.DisconnectTwitchBot();
                        ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken = null;
                    }
                    this.BotAccountAvatar   = null;
                    this.BotAccountUsername = null;
                }
                else
                {
                    Result result = new Result(false);
                    if (this.Platform == StreamingPlatformTypeEnum.Twitch)
                    {
                        result = await ChannelSession.ConnectTwitchBot();
                        if (result.Success)
                        {
                            if (ChannelSession.TwitchBotNewAPI.id.Equals(ChannelSession.TwitchUserNewAPI?.id))
                            {
                                await ChannelSession.DisconnectTwitchBot();
                                result = new Result(MixItUp.Base.Resources.BotAccountMustBeDifferent);
                            }
                            else if (ChannelSession.TwitchBotNewAPI != null)
                            {
                                this.BotAccountAvatar   = ChannelSession.TwitchBotNewAPI.profile_image_url;
                                this.BotAccountUsername = ChannelSession.TwitchBotNewAPI.display_name;
                            }
                        }
                    }

                    if (!result.Success)
                    {
                        this.BotAccountAvatar   = null;
                        this.BotAccountUsername = null;

                        await DialogHelper.ShowMessage(result.Message);
                    }
                }
                this.NotifyAllProperties();
            });
        }