Пример #1
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IChatConnectionService ccs, IWebSocketEventService wse,
                             ITwitchPubSubService pss)
        {
            //Title = "OakBot - YATB";
            Title = "Kelex";

            // Set dependency injection references
            _ccs = ccs;
            _wse = wse;
            _pss = pss;

            // Register for chat connection service events
            _ccs.Authenticated += _ccs_Authenticated;
            _ccs.Disconnected  += _ccs_Disconnected;

            // Load settings
            var loaded = BinaryFile.ReadEncryptedBinFile("LoginSettings");

            if (loaded != null && loaded is MainSettings)
            {
                // Success, set last saved settings
                _mainSettings = (MainSettings)loaded;

                // Set loaded settings values through properties for UI
                ChannelName    = _mainSettings.Channel;
                BotUsername    = _mainSettings.BotUsername;
                CasterUsername = _mainSettings.CasterUsername;
                IsUsingSSL     = _mainSettings.UseSecureConnection;

                // Set bot credentials
                if (!string.IsNullOrWhiteSpace(_mainSettings.BotOauthKey))
                {
                    IsBotOauthSet   = true;
                    _botCredentials = new TwitchCredentials(
                        _mainSettings.BotUsername, _mainSettings.BotOauthKey, false);
                }

                // Set caster credentials
                if (!string.IsNullOrWhiteSpace(_mainSettings.CasterOauthKey))
                {
                    IsCasterOauthSet   = true;
                    _casterCredentials = new TwitchCredentials(
                        _mainSettings.CasterUsername, _mainSettings.CasterOauthKey, true);

                    // Try connection PubSub
                    _pss.Connect(_casterCredentials);
                }
            }
            else
            {
                // Failure, load defaults
                _mainSettings = new MainSettings();
            }

            // Start WebSocket Event Service
            _wse.StartService(1337, "oakbotapitest");
        }