Пример #1
0
        /// <summary>Downloads recent followers from Twitch, starts service, fires OnServiceStarted event.</summary>
        public async Task StartService()
        {
            if (ChannelData == null)
            {
                throw new UninitializedChannelDataException("ChannelData must be set before starting the FollowerService. Use SetChannelByName() or SetChannelById()");
            }

            if (ChannelIdentifier == Enums.ChannelIdentifierType.Username)
            {
                var response = await TwitchAPI.Follows.v3.GetFollowers(ChannelData, QueryCount);

                foreach (var follower in response.Followers)
                {
                    ActiveCache.Add(follower.User.Name);
                }
            }
            else
            {
                var response = await TwitchAPI.Channels.v5.GetChannelFollowers(ChannelData, QueryCount);

                foreach (var follower in response.Follows)
                {
                    ActiveCache.Add(follower.User.Name);
                }
            }

            _followerServiceTimer.Start();
            OnServiceStarted?.Invoke(this,
                                     new OnServiceStartedArgs {
                ChannelIdentifier = ChannelIdentifier, ChannelData = ChannelData, CheckIntervalSeconds = CheckIntervalSeconds, QueryCount = QueryCount
            });
        }
Пример #2
0
        private void Start(Action <HttpConfiguration> configure, bool useCors)
        {
            _selfHostServer = new SelfHostServer(_ipAddress, _port, true);

            _selfHostServer.Connect(configure, useCors);
            Console.WriteLine($"Service {_serviceDisplayName} started on {_ipAddress}:{_port}");
            OnServiceStarted?.Invoke();
        }
 private void Start()
 {
     Console.WriteLine("Service {0} started ", _serviceDisplayName);
     if (OnServiceStarted != null)
     {
         OnServiceStarted.Invoke();
     }
 }
Пример #4
0
        /// <summary>Downloads recent followers from Twitch, starts service, fires OnServiceStarted event.</summary>
        public async void StartService()
        {
            TwitchAPIClasses.FollowersResponse response = await TwitchApi.GetTwitchFollowers(Channel, QueryCount);

            ActiveCache = response.Followers;
            _followerServiceTimer.Start();
            OnServiceStarted?.Invoke(this,
                                     new OnServiceStartedArgs {
                Channel = Channel, CheckIntervalSeconds = CheckIntervalSeconds, QueryCount = QueryCount
            });
        }
Пример #5
0
        private void Start(Action <HttpConfiguration> configure, bool useCors)
        {
            _selfHostServer = new SelfHostServer(_port);

            _selfHostServer.Connect(configure, useCors);
            Console.WriteLine("Service {0} started on port {1}", _serviceDisplayName, _port);
            if (OnServiceStarted != null)
            {
                OnServiceStarted.Invoke();
            }
        }
Пример #6
0
        /// <summary>
        /// Starts the service.
        /// </summary>
        /// <exception cref="InvalidOperationException">When no channels have been added to the service</exception>
        /// <exception cref="InvalidOperationException">When the service has already been started.</exception>
        public virtual void Start()
        {
            if (ChannelsToMonitor == null)
            {
                throw new InvalidOperationException("You must atleast add 1 channel to service before starting it.");
            }

            if (_serviceTimer.Enabled)
            {
                throw new InvalidOperationException("The service has already been started.");
            }

            _serviceTimer.Start();

            OnServiceStarted?.Invoke(this, new OnServiceStartedArgs());
        }
Пример #7
0
 public virtual bool StartServices()
 {
     if (!IsRunning)
     {
         throw new Exception(string.Format("Services manager '{0}' is not running.", IdentifyableTechnicalName));
     }
     foreach (var service in _services)
     {
         if (service.IsRunning)
         {
             throw new Exception(string.Format("Can't start the {0} Service, service is already running.", service.IdentifyableTechnicalName));
         }
         service.Start();
         if (OnServiceStarted != null)
         {
             OnServiceStarted.Invoke(this, new ServiceStartedArgs(service));
         }
     }
     return(true);
 }
        public UnityFollowerService(ITwitchAPI api, int checkIntervalSeconds = 60, int queryCount = 25) : base(api, checkIntervalSeconds, queryCount)
        {
            ThreadDispatcher.EnsureCreated();

            base.OnServiceStarted       += ((object sender, OnServiceStartedArgs e) => { ThreadDispatcher.Enqueue(() => OnServiceStarted?.Invoke(sender, e)); });
            base.OnServiceStopped       += ((object sender, OnServiceStoppedArgs e) => { ThreadDispatcher.Enqueue(() => OnServiceStopped?.Invoke(sender, e)); });
            base.OnNewFollowersDetected += ((object sender, OnNewFollowersDetectedArgs e) => { ThreadDispatcher.Enqueue(() => OnNewFollowersDetected?.Invoke(sender, e)); });
        }
        public UnityFollowerService(ITwitchAPI api, int checkIntervalSeconds = 60, int queryCount = 25) : base(api, checkIntervalSeconds, queryCount)
        {
            _threadDispatcher = new GameObject("ThreadDispatcher");
            _threadDispatcher.AddComponent <ThreadDispatcher>();
            UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher);

            base.OnServiceStarted       += ((object sender, OnServiceStartedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnServiceStarted?.Invoke(sender, e)); });
            base.OnServiceStopped       += ((object sender, OnServiceStoppedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnServiceStopped?.Invoke(sender, e)); });
            base.OnNewFollowersDetected += ((object sender, OnNewFollowersDetectedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnNewFollowersDetected?.Invoke(sender, e)); });
        }
Пример #10
0
        public UnityLiveStreamMonitor(ITwitchAPI api, int checkIntervalSeconds = 60, int maxStreamRequestCountPerRequest = 100) : base(api, checkIntervalSeconds, maxStreamRequestCountPerRequest)
        {
            ThreadDispatcher.EnsureCreated();

            base.OnStreamOnline   += ((object sender, OnStreamOnlineArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamOnline?.Invoke(sender, e)); });
            base.OnStreamOffline  += ((object sender, OnStreamOfflineArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamOffline?.Invoke(sender, e)); });
            base.OnStreamUpdate   += ((object sender, OnStreamUpdateArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamUpdate?.Invoke(sender, e)); });
            base.OnServiceStarted += ((object sender, OnServiceStartedArgs e) => { ThreadDispatcher.Enqueue(() => OnServiceStarted?.Invoke(sender, e)); });
            base.OnServiceStopped += ((object sender, OnServiceStoppedArgs e) => { ThreadDispatcher.Enqueue(() => OnServiceStopped?.Invoke(sender, e)); });
            base.OnChannelsSet    += ((object sender, OnChannelsSetArgs e) => { ThreadDispatcher.Enqueue(() => OnChannelsSet?.Invoke(sender, e)); });
        }