コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: FlashPros/OakBot
        /// <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");
        }
コード例 #2
0
        public GiveawaysViewModel(IChatConnectionService chatService, IWebSocketEventService wsEventService)
        {
            // Store references to services
            _chatService    = chatService;
            _wsEventService = wsEventService;

            // Subscribe to system messages
            Messenger.Default.Register <bool>(this, "SystemChatConnectionChanged", (status) => SystemChatConnectionChanged(status));

            // Use one seeded pseudo-random generator for all giveaway modules
            _rnd = new Random();

            // Set giveaway modules
            _modules = new ObservableCollection <GiveawayViewModel>
            {
                new GiveawayViewModel(1, _rnd, _chatService, _wsEventService),
                new GiveawayViewModel(2, _rnd, _chatService, _wsEventService),
                new GiveawayViewModel(3, _rnd, _chatService, _wsEventService)
            };
        }
コード例 #3
0
        public EnvironmentSensorClient(AppSettings settings)
        {
            var uri = new Uri($"{settings.Remote.Scheme}://{settings.Remote.Host}:{settings.Remote.Port}{settings.Remote.Path}");

            logger.Info($"Remote address: {uri}");

            this.m_listener    = new WebSocketListenerService(uri, settings.Listener.SubscriptionInterval, LogManager.GetLogger("EnvironmentWebSocketClientService"));
            this.m_pingService = new PingService(TimeSpan.FromSeconds(5), this.m_listener);
            this.m_settings    = settings;

            var storageService = new MeasurementStorageService(new AuthorizationService(),
                                                               settings.Remote.StorageUri,
                                                               settings.Listener.ApiKey,
                                                               LogManager.GetLogger(nameof(MeasurementStorageService)));

            this.m_parser = new EnvironmentSensorParserService(storageService, new ParserSettings {
                ApiKey  = settings.Listener.ApiKey,
                Sensors = settings.Listener.Sensors
            }, LogManager.GetLogger(nameof(EnvironmentSensorParserService)));
        }
コード例 #4
0
ファイル: GiveawayViewModel.cs プロジェクト: ocgineer/OakBot
        /// <summary>
        /// Initializes a new Giveaway module, seperate from other modules.
        /// </summary>
        /// <param name="id">Id of the module, must be unique and can't be lower than 1.</param>
        /// <param name="rndGen">A preseeded pseudo random generator to be used in the module.</param>
        /// <param name="ccs">Chat Service to receive and send messages.</param>
        /// <param name="wes">WebSocket Event Service to push out giveaway events to websocket.</param>
        public GiveawayViewModel(int id, Random rndGen, IChatConnectionService ccs, IWebSocketEventService wes)
        {
            // Store references
            _moduleId       = id;
            _rndGen         = rndGen;
            _chatService    = ccs;
            _wsEventService = wes;

            // Initialize collections and lists
            _listEntries        = new ObservableCollection <GiveawayEntry>();
            _listWinners        = new ObservableCollection <GiveawayEntry>();
            _listMessagesWinner = new ObservableCollection <TwitchChatMessage>();

            // Initialize MediaPlayer
            _mediaPlayer = new MediaPlayer();

            // Set initial timestamps and spans
            _timestampOpened       = new DateTime(0);
            _timestampClosed       = new DateTime(0);
            _timestampDraw         = new DateTime(0);
            _elapsedOpenTime       = new TimeSpan(0);
            _elapsedNoResponseTime = new TimeSpan(0);
            _elapsedInterval       = new TimeSpan(0, 0, 1);

            // Initialize timers
            _timerOpen = new Timer()
            {
                AutoReset = false
            };
            _timerOpen.Elapsed += _TimerOpen_Elapsed;
            _timerResponse      = new Timer()
            {
                AutoReset = false
            };
            _timerResponse.Elapsed += _TimerResponse_Elapsed;
            _timerElapsed           = new Timer(_elapsedInterval.TotalMilliseconds);
            _timerElapsed.Elapsed  += _TimerElapsed_Elapsed;
            _timerElapsed.Start();

            // Set a 'winner' to display
            _selectedWinner = new GiveawayEntry {
                DisplayName = "WINNER"
            };
            _WinnerHasReplied = true;

            // Load in previous saved settings else use new default settings
            var loaded = BinaryFile.ReadBinFile($"GivewawayModule{ID}");

            if (loaded != null && loaded is GiveawayModuleSettings)
            {
                // Success, set last saved settings and set previous winners
                _moduleSettings = (GiveawayModuleSettings)loaded;
                if (_moduleSettings.SavedWinnersList?.Count > 0)
                {
                    _listWinners = new ObservableCollection <GiveawayEntry>(_moduleSettings.SavedWinnersList);
                }
            }
            else
            {
                // Failure, load defaults
                _moduleSettings = new GiveawayModuleSettings();
            }

            // Transmit WS event
            _wsEventService.SendRegisteredEvent("GIVEAWAY_DONE",
                                                new GiveawayWebsocketEventBase(_moduleId));

            // Register to service events and system broadcast messages
            _chatService.ChatMessageReceived += _chatService_ChatMessageReceived;
        }