Exemplo n.º 1
0
        protected override async void OnStartup(StartupEventArgs e)
        {
            WindowsServicesManager servicesManager = new WindowsServicesManager();

            servicesManager.Initialize();

            FileLoggerHandler.Initialize(servicesManager.FileService);

            DispatcherHelper.RegisterDispatcher(new WindowsDispatcher(this.Dispatcher));

            DialogHelper.Initialize(new WPFDialogShower());

            Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException       += CurrentDomain_UnhandledException;

            await ChannelSession.Initialize(servicesManager);

            WindowsIdentity id = WindowsIdentity.GetCurrent();

            ChannelSession.IsElevated = id.Owner != id.User;

            Logger.ForceLog(LogLevel.Information, "Application Version: " + ChannelSession.Services.FileService.GetApplicationVersion());
            if (ChannelSession.IsDebug() || ChannelSession.AppSettings.DiagnosticLogging)
            {
                Logger.SetLogLevel(LogLevel.Debug);
            }
            else
            {
                Logger.SetLogLevel(LogLevel.Error);
            }

            this.SwitchTheme(ChannelSession.AppSettings.ColorScheme, ChannelSession.AppSettings.BackgroundColor, ChannelSession.AppSettings.FullThemeName);

            base.OnStartup(e);
        }
Exemplo n.º 2
0
        public GeneralSettingsControlViewModel()
        {
            this.OptOutOfDataTracking = new GenericToggleSettingsOptionControlViewModel(MixItUp.Base.Resources.OptOutofDataTracking,
                                                                                        ChannelSession.Settings.OptOutTracking, (value) => { ChannelSession.Settings.OptOutTracking = value; }, MixItUp.Base.Resources.OptOutofDataTrackingTooltip);

            this.AutoLogIn = new GenericToggleSettingsOptionControlViewModel(MixItUp.Base.Resources.AutoLogInCurrentAccount,
                                                                             (ChannelSession.AppSettings.AutoLogInID == ChannelSession.Settings.ID),
                                                                             (value) => { ChannelSession.AppSettings.AutoLogInID = (value) ? ChannelSession.Settings.ID : Guid.Empty; },
                                                                             MixItUp.Base.Resources.AutoLogInCurrentAccountTooltip);

            this.PreviewProgram = new GenericToggleSettingsOptionControlViewModel(MixItUp.Base.Resources.UpdatePreviewProgram,
                                                                                  ChannelSession.AppSettings.PreviewProgram, (value) => { ChannelSession.AppSettings.PreviewProgram = value; }, MixItUp.Base.Resources.UpdatePreviewProgramTooltip);

            var languageOptions = EnumHelper.GetEnumList <LanguageOptions>().ToList();

            if (!ChannelSession.IsDebug())
            {
                languageOptions.Remove(LanguageOptions.Pseudo);
            }
            this.Language = new GenericComboBoxSettingsOptionControlViewModel <LanguageOptions>(MixItUp.Base.Resources.Language,
                                                                                                languageOptions.OrderBy(l => l.ToString()), ChannelSession.AppSettings.LanguageOption, (value) =>
            {
                ChannelSession.AppSettings.SettingsChangeRestartRequired = true;
                ChannelSession.AppSettings.LanguageOption = value;
            });

            this.DefaultStreamingSoftware = new GenericComboBoxSettingsOptionControlViewModel <StreamingSoftwareTypeEnum>(MixItUp.Base.Resources.DefaultStreamingSoftware,
                                                                                                                          new List <StreamingSoftwareTypeEnum>()
            {
                StreamingSoftwareTypeEnum.OBSStudio, StreamingSoftwareTypeEnum.XSplit, StreamingSoftwareTypeEnum.StreamlabsOBS
            },
                                                                                                                          ChannelSession.Settings.DefaultStreamingSoftware, (value) => { ChannelSession.Settings.DefaultStreamingSoftware = value; });

            string defaultAudioOption = SoundAction.DefaultAudioDevice;

            if (!string.IsNullOrEmpty(ChannelSession.Settings.DefaultAudioOutput))
            {
                defaultAudioOption = ChannelSession.Settings.DefaultAudioOutput;
            }

            List <string> audioOptions = new List <string>();

            audioOptions.Add(SoundAction.DefaultAudioDevice);
            audioOptions.AddRange(ChannelSession.Services.AudioService.GetOutputDevices());

            this.DefaultAudioOutput = new GenericComboBoxSettingsOptionControlViewModel <string>(MixItUp.Base.Resources.DefaultAudioOutput,
                                                                                                 audioOptions, defaultAudioOption, (value) =>
            {
                if (value.Equals(SoundAction.DefaultAudioDevice))
                {
                    ChannelSession.Settings.DefaultAudioOutput = null;
                }
                else
                {
                    ChannelSession.Settings.DefaultAudioOutput = value;
                }
            });
            this.DefaultAudioOutput.Width = 250;
        }
Exemplo n.º 3
0
        public async Task Connect(string connectionURL)
        {
            this.connectionURL = connectionURL;

            this.DisconnectEvents();

            if (ChannelSession.IsDebug())
            {
                this.socket.HandledEventReceived   += Socket_HandledEventReceived;
                this.socket.UnhandledEventReceived += Socket_UnhandledEventReceived;
            }
            this.socket.Connected         += Socket_Connected;
            this.socket.Disconnected      += Socket_Disconnected;
            this.socket.ErrorReceived     += Socket_ErrorReceived;
            this.socket.ExceptionOccurred += Socket_ExceptionOccurred;

            await this.socket.ConnectAsync(new Uri(this.connectionURL));
        }
Exemplo n.º 4
0
        public async Task Initialize()
        {
            if (this.IsStreamer)
            {
                if (!ChannelSession.Services.FileService.FileExists(this.DatabaseFilePath))
                {
                    await ChannelSession.Services.FileService.CopyFile(SettingsV2Model.SettingsTemplateDatabaseFileName, this.DatabaseFilePath);
                }

                foreach (StreamingPlatformTypeEnum platform in StreamingPlatforms.Platforms)
                {
                    this.UsernameLookups[platform] = new Dictionary <string, Guid>();
                }

                await ChannelSession.Services.Database.Read(this.DatabaseFilePath, "SELECT * FROM Users", (Dictionary <string, object> data) =>
                {
                    UserDataModel userData     = JSONSerializerHelper.DeserializeFromString <UserDataModel>((string)data["Data"]);
                    this.UserData[userData.ID] = userData;
                    if (userData.Platform.HasFlag(StreamingPlatformTypeEnum.Twitch))
                    {
                        this.TwitchUserIDLookups[userData.TwitchID] = userData.ID;
                        if (!string.IsNullOrEmpty(userData.TwitchUsername))
                        {
                            this.UsernameLookups[StreamingPlatformTypeEnum.Twitch][userData.TwitchUsername.ToLowerInvariant()] = userData.ID;
                        }
                    }
#pragma warning disable CS0612 // Type or member is obsolete
                    else if (userData.Platform.HasFlag(StreamingPlatformTypeEnum.Mixer))
                    {
                        if (!string.IsNullOrEmpty(userData.MixerUsername))
                        {
                            this.UsernameLookups[StreamingPlatformTypeEnum.Mixer][userData.MixerUsername.ToLowerInvariant()] = userData.ID;
                        }
                    }
#pragma warning restore CS0612 // Type or member is obsolete
                });

                this.UserData.ClearTracking();

                await ChannelSession.Services.Database.Read(this.DatabaseFilePath, "SELECT * FROM Quotes", (Dictionary <string, object> data) =>
                {
                    string json = (string)data["Data"];
                    if (json.Contains("MixItUp.Base.ViewModel.User.UserQuoteViewModel"))
                    {
                        json = json.Replace("MixItUp.Base.ViewModel.User.UserQuoteViewModel", "MixItUp.Base.Model.User.UserQuoteModel");
                        this.Quotes.Add(new UserQuoteViewModel(JSONSerializerHelper.DeserializeFromString <UserQuoteModel>(json)));
                    }
                    else
                    {
                        this.Quotes.Add(new UserQuoteViewModel(JSONSerializerHelper.DeserializeFromString <UserQuoteModel>((string)data["Data"])));
                    }
                });

                this.Quotes.ClearTracking();

                await ChannelSession.Services.Database.Read(this.DatabaseFilePath, "SELECT * FROM Commands", (Dictionary <string, object> data) =>
                {
                    CommandTypeEnum type = (CommandTypeEnum)Convert.ToInt32(data["TypeID"]);
                    if (type == CommandTypeEnum.Chat)
                    {
                        this.ChatCommands.Add(JSONSerializerHelper.DeserializeFromString <ChatCommand>((string)data["Data"]));
                    }
                    else if (type == CommandTypeEnum.Event)
                    {
                        this.EventCommands.Add(JSONSerializerHelper.DeserializeFromString <EventCommand>((string)data["Data"]));
                    }
                    else if (type == CommandTypeEnum.Timer)
                    {
                        this.TimerCommands.Add(JSONSerializerHelper.DeserializeFromString <TimerCommand>((string)data["Data"]));
                    }
                    else if (type == CommandTypeEnum.ActionGroup)
                    {
                        this.ActionGroupCommands.Add(JSONSerializerHelper.DeserializeFromString <ActionGroupCommand>((string)data["Data"]));
                    }
                    else if (type == CommandTypeEnum.Game)
                    {
                        this.GameCommands.Add(JSONSerializerHelper.DeserializeFromString <GameCommandBase>((string)data["Data"]));
                    }
                    else if (type == CommandTypeEnum.TwitchChannelPoints)
                    {
                        this.TwitchChannelPointsCommands.Add(JSONSerializerHelper.DeserializeFromString <TwitchChannelPointsCommand>((string)data["Data"]));
                    }
                    else if (type == CommandTypeEnum.Custom)
                    {
                        CustomCommand command           = JSONSerializerHelper.DeserializeFromString <CustomCommand>((string)data["Data"]);
                        this.CustomCommands[command.ID] = command;
                    }
#pragma warning disable CS0612 // Type or member is obsolete
                    else if (type == CommandTypeEnum.Interactive)
                    {
                        MixPlayCommand command = JSONSerializerHelper.DeserializeFromString <MixPlayCommand>((string)data["Data"]);
                        if (command is MixPlayButtonCommand || command is MixPlayTextBoxCommand)
                        {
                            this.OldMixPlayCommands.Add(command);
                        }
                    }
#pragma warning restore CS0612 // Type or member is obsolete
                });

                this.ChatCommands.ClearTracking();
                this.EventCommands.ClearTracking();
                this.TimerCommands.ClearTracking();
                this.ActionGroupCommands.ClearTracking();
                this.GameCommands.ClearTracking();
                this.TwitchChannelPointsCommands.ClearTracking();
                this.CustomCommands.ClearTracking();

                foreach (CounterModel counter in this.Counters.Values.ToList())
                {
                    if (counter.ResetOnLoad)
                    {
                        await counter.ResetAmount();
                    }
                }
            }

            if (string.IsNullOrEmpty(this.TelemetryUserID))
            {
                if (ChannelSession.IsDebug())
                {
                    this.TelemetryUserID = "MixItUpDebuggingUser";
                }
                else
                {
                    this.TelemetryUserID = Guid.NewGuid().ToString();
                }
            }

            // Mod accounts cannot use this feature, forcefully disable on load
            if (!this.IsStreamer)
            {
                this.TrackWhispererNumber = false;
            }

            this.InitializeMissingData();
        }
Exemplo n.º 5
0
        public async Task Initialize()
        {
            if (!ChannelSession.Services.FileService.FileExists(this.DatabaseFilePath))
            {
                await ChannelSession.Services.FileService.CopyFile(SettingsV3Model.SettingsTemplateDatabaseFileName, this.DatabaseFilePath);
            }

            foreach (StreamingPlatformTypeEnum platform in StreamingPlatforms.Platforms)
            {
                this.UsernameLookups[platform] = new Dictionary <string, Guid>();
            }

            await ChannelSession.Services.Database.Read(this.DatabaseFilePath, "SELECT * FROM Users", (Dictionary <string, object> data) =>
            {
                UserDataModel userData     = JSONSerializerHelper.DeserializeFromString <UserDataModel>(data["Data"].ToString());
                this.UserData[userData.ID] = userData;
                if (userData.Platform.HasFlag(StreamingPlatformTypeEnum.Twitch))
                {
                    this.TwitchUserIDLookups[userData.TwitchID] = userData.ID;
                    if (!string.IsNullOrEmpty(userData.TwitchUsername))
                    {
                        this.UsernameLookups[StreamingPlatformTypeEnum.Twitch][userData.TwitchUsername.ToLowerInvariant()] = userData.ID;
                    }
                }
#pragma warning disable CS0612 // Type or member is obsolete
                else if (userData.Platform.HasFlag(StreamingPlatformTypeEnum.Mixer))
                {
                    if (!string.IsNullOrEmpty(userData.MixerUsername))
                    {
                        this.UsernameLookups[StreamingPlatformTypeEnum.Mixer][userData.MixerUsername.ToLowerInvariant()] = userData.ID;
                    }
                }
#pragma warning restore CS0612 // Type or member is obsolete
            });

            this.UserData.ClearTracking();

            await ChannelSession.Services.Database.Read(this.DatabaseFilePath, "SELECT * FROM Quotes", (Dictionary <string, object> data) =>
            {
                DateTimeOffset.TryParse((string)data["DateTime"], out DateTimeOffset dateTime);
                this.Quotes.Add(new UserQuoteModel(Convert.ToInt32(data["ID"]), data["Quote"].ToString(), dateTime, data["GameName"].ToString()));
            });

            this.Quotes.ClearTracking();

            await ChannelSession.Services.Database.Read(this.DatabaseFilePath, "SELECT * FROM Commands", (Dictionary <string, object> data) =>
            {
                CommandModelBase command = null;
                CommandTypeEnum type     = (CommandTypeEnum)Convert.ToInt32(data["TypeID"]);

                string commandData = data["Data"].ToString();
                if (type == CommandTypeEnum.Chat)
                {
                    command = JSONSerializerHelper.DeserializeFromString <ChatCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.Event)
                {
                    command = JSONSerializerHelper.DeserializeFromString <EventCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.Timer)
                {
                    command = JSONSerializerHelper.DeserializeFromString <TimerCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.ActionGroup)
                {
                    command = JSONSerializerHelper.DeserializeFromString <ActionGroupCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.Game)
                {
                    commandData = commandData.Replace("MixItUp.Base.ViewModel.User.UserRoleEnum", "MixItUp.Base.Model.User.UserRoleEnum");
                    command     = JSONSerializerHelper.DeserializeFromString <GameCommandModelBase>(commandData);
                }
                else if (type == CommandTypeEnum.TwitchChannelPoints)
                {
                    command = JSONSerializerHelper.DeserializeFromString <TwitchChannelPointsCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.Custom)
                {
                    command = JSONSerializerHelper.DeserializeFromString <CustomCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.UserOnlyChat)
                {
                    command = JSONSerializerHelper.DeserializeFromString <UserOnlyChatCommandModel>(commandData);
                }

                if (command != null)
                {
                    this.Commands[command.ID] = command;
                }
            });

            this.Commands.ClearTracking();

            ChannelSession.ChatCommands.Clear();
            ChannelSession.EventCommands.Clear();
            ChannelSession.TimerCommands.Clear();
            ChannelSession.ActionGroupCommands.Clear();
            ChannelSession.GameCommands.Clear();
            ChannelSession.TwitchChannelPointsCommands.Clear();
            foreach (CommandModelBase command in this.Commands.Values.ToList())
            {
                if (command is ChatCommandModel)
                {
                    if (command is GameCommandModelBase)
                    {
                        ChannelSession.GameCommands.Add((GameCommandModelBase)command);
                    }
                    else if (command is UserOnlyChatCommandModel)
                    {
                    }
                    else
                    {
                        ChannelSession.ChatCommands.Add((ChatCommandModel)command);
                    }
                }
                else if (command is EventCommandModel)
                {
                    ChannelSession.EventCommands.Add((EventCommandModel)command);
                }
                else if (command is TimerCommandModel)
                {
                    ChannelSession.TimerCommands.Add((TimerCommandModel)command);
                }
                else if (command is ActionGroupCommandModel)
                {
                    ChannelSession.ActionGroupCommands.Add((ActionGroupCommandModel)command);
                }
                else if (command is TwitchChannelPointsCommandModel)
                {
                    ChannelSession.TwitchChannelPointsCommands.Add((TwitchChannelPointsCommandModel)command);
                }
            }

            foreach (CounterModel counter in this.Counters.Values.ToList())
            {
                if (counter.ResetOnLoad)
                {
                    await counter.ResetAmount();
                }
            }

            if (string.IsNullOrEmpty(this.TelemetryUserID))
            {
                if (ChannelSession.IsDebug())
                {
                    this.TelemetryUserID = "MixItUpDebuggingUser";
                }
                else
                {
                    this.TelemetryUserID = Guid.NewGuid().ToString();
                }
            }

            this.InitializeMissingData();
        }
Exemplo n.º 6
0
        public async Task Initialize()
        {
            if (!ChannelSession.Services.FileService.FileExists(this.DatabaseFilePath))
            {
                await ChannelSession.Services.FileService.CopyFile(SettingsV3Model.SettingsTemplateDatabaseFileName, this.DatabaseFilePath);
            }

            await ChannelSession.Services.Database.Read(this.DatabaseFilePath, "SELECT * FROM Quotes", (Dictionary <string, object> data) =>
            {
                DateTimeOffset.TryParse((string)data["DateTime"], out DateTimeOffset dateTime);
                this.Quotes.Add(new UserQuoteModel(Convert.ToInt32(data["ID"]), data["Quote"].ToString(), dateTime, data["GameName"].ToString()));
            });

            this.Quotes.ClearTracking();

            await ChannelSession.Services.Database.Read(this.DatabaseFilePath, "SELECT * FROM Commands", (Dictionary <string, object> data) =>
            {
                CommandModelBase command = null;
                CommandTypeEnum type     = (CommandTypeEnum)Convert.ToInt32(data["TypeID"]);

                string commandData = data["Data"].ToString();
                if (type == CommandTypeEnum.Chat)
                {
                    command = JSONSerializerHelper.DeserializeFromString <ChatCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.Event)
                {
                    command = JSONSerializerHelper.DeserializeFromString <EventCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.Timer)
                {
                    command = JSONSerializerHelper.DeserializeFromString <TimerCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.ActionGroup)
                {
                    command = JSONSerializerHelper.DeserializeFromString <ActionGroupCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.Game)
                {
                    commandData = commandData.Replace("MixItUp.Base.ViewModel.User.UserRoleEnum", "MixItUp.Base.Model.User.UserRoleEnum");
                    command     = JSONSerializerHelper.DeserializeFromString <GameCommandModelBase>(commandData);
                }
                else if (type == CommandTypeEnum.TwitchChannelPoints)
                {
                    command = JSONSerializerHelper.DeserializeFromString <TwitchChannelPointsCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.StreamlootsCard)
                {
                    command = JSONSerializerHelper.DeserializeFromString <StreamlootsCardCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.Custom)
                {
                    command = JSONSerializerHelper.DeserializeFromString <CustomCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.UserOnlyChat)
                {
                    command = JSONSerializerHelper.DeserializeFromString <UserOnlyChatCommandModel>(commandData);
                }
                else if (type == CommandTypeEnum.Webhook)
                {
                    command = JSONSerializerHelper.DeserializeFromString <WebhookCommandModel>(commandData);
                }

                if (command != null)
                {
                    this.Commands[command.ID] = command;
                }
            });

            this.Commands.ClearTracking();

            foreach (CounterModel counter in this.Counters.Values.ToList())
            {
                if (counter.ResetOnLoad)
                {
                    await counter.ResetAmount();
                }
            }

            if (string.IsNullOrEmpty(this.TelemetryUserID))
            {
                if (ChannelSession.IsDebug())
                {
                    this.TelemetryUserID = "MixItUpDebuggingUser";
                }
                else
                {
                    this.TelemetryUserID = Guid.NewGuid().ToString();
                }
            }

            // Clear out unused Cooldown Groups and Command Groups
            var allUsedCooldownGroupNames   = this.Commands.Values.ToList().Select(c => c.Requirements?.Cooldown?.GroupName).Distinct();
            var allUnusedCooldownGroupNames = this.CooldownGroupAmounts.ToList().Where(c => !allUsedCooldownGroupNames.Contains(c.Key, StringComparer.InvariantCultureIgnoreCase));

            foreach (var unused in allUnusedCooldownGroupNames)
            {
                this.CooldownGroupAmounts.Remove(unused.Key);
            }

            var allUsedCommandGroupNames   = this.Commands.Values.ToList().Select(c => c.GroupName).Distinct();
            var allUnusedCommandGroupNames = this.CommandGroups.ToList().Where(c => !allUsedCommandGroupNames.Contains(c.Key, StringComparer.InvariantCultureIgnoreCase));

            foreach (var unused in allUnusedCommandGroupNames)
            {
                this.CommandGroups.Remove(unused.Key);
            }

            this.InitializeMissingData();
        }