示例#1
0
        public void ReSpawn()
        {
            DictionaryEntry[] clone = new DictionaryEntry[threads.Count];
            threads.CopyTo(clone, 0);
            foreach (DictionaryEntry entry in clone)
            {
                (entry.Value as Tuple <Thread, ManualResetEvent>).Item2?.Set();

                ThreadDefinition threadDefinition = usedDefinitions.Find((ThreadDefinition obj) => obj.name.Equals(entry.Key));
                if (threadDefinition != null)
                {
                    usedDefinitions.Remove(threadDefinition);
                    threads.Remove(entry.Key);
                    Spawn(threadDefinition);
                }

                ParameterizedThreadDefinition parameterizedThreadDefinition = usedParameterizedDefinitions.Find((ParameterizedThreadDefinition obj) => obj.name.Equals(entry.Key));
                if (parameterizedThreadDefinition != null)
                {
                    usedParameterizedDefinitions.Remove(parameterizedThreadDefinition);
                    threads.Remove(entry.Key);
                    ManagedSpawn(parameterizedThreadDefinition);
                }
            }
        }
示例#2
0
        public void Spawn(ThreadDefinition definition)
        {
            Thread thread = new Thread(definition.callback);

            thread.Start();
            usedDefinitions.Add(definition);
            threads.Add(definition.name, new Tuple <Thread, ManualResetEvent>(thread, null));
        }
示例#3
0
        public void SanityCheck()
        {
            DictionaryEntry[] clone = new DictionaryEntry[threads.Count];
            threads.CopyTo(clone, 0);
            foreach (DictionaryEntry entry in clone)
            {
                if ((entry.Value as Tuple <Thread, ManualResetEvent>).Item1.IsAlive)
                {
                    continue;
                }

                ThreadDefinition usedDefinition = usedDefinitions.Find((ThreadDefinition definition) => definition.name.Equals(entry.Key));
                usedDefinitions.Remove(usedDefinition);
                threads.Remove(entry.Key);
                Spawn(usedDefinition);
            }
        }
示例#4
0
        public void DeSpawn()
        {
            Tuple <Thread, ManualResetEvent> thread = (Tuple <Thread, ManualResetEvent>)threads[threads.Count - 1];

            thread.Item2?.Set();

            ThreadDefinition threadDefinition = usedDefinitions.Find((ThreadDefinition obj) => obj.name.Equals(thread.Item1.Name));

            if (threadDefinition != null)
            {
                usedDefinitions.Remove(threadDefinition);
                threads.Remove(thread.Item1.Name);
            }

            ParameterizedThreadDefinition parameterizedThreadDefinition = usedParameterizedDefinitions.Find((ParameterizedThreadDefinition obj) => obj.name.Equals(thread.Item1.Name));

            if (parameterizedThreadDefinition != null)
            {
                usedParameterizedDefinitions.Remove(parameterizedThreadDefinition);
                threads.Remove(thread.Item1.Name);
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eArgs) =>
            {
                _quitMain.Set();
                eArgs.Cancel = true;
            };

            using (WebClient wc = new WebClient())
            {
                dynamic json = JsonConvert.DeserializeObject <dynamic>(wc.DownloadString("https://api.streamelements.com/kappa/v2/chatstats/giantwaffle/stats"));
                ConnectionMultiplexer _redisConnection = ConnectionMultiplexer.Connect(configuration: "localhost");
                IDatabase             redis            = _redisConnection.GetDatabase();
                foreach (dynamic emote in json.bttvEmotes)
                {
                    AddEmote(emote, redis);
                }

                foreach (dynamic emote in json.ffzEmotes)
                {
                    AddEmote(emote, redis);
                }
            }

            ThreadManager manager = new ThreadManager();


            Bot bot = new Bot();

            ManualResetEvent robotBlocker          = new ManualResetEvent(false);
            ThreadDefinition robotThreadDefinition = new ThreadDefinition
            {
                name     = "RobotThread",
                callback = () =>
                {
                    Console.WriteLine("Robot thread started");
                    bot.Connect();
                    robotBlocker.WaitOne();
                    bot.Disconnect();
                    Console.WriteLine("Robot thread terminated");
                }
            };

            manager.Spawn(robotThreadDefinition);

            FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();

            fileSystemWatcher.Changed += (object sender, FileSystemEventArgs e) =>
            {
                if (e.Name.Equals(".#config.json"))
                {
                    Console.WriteLine("Configuration has changed reloading commands and counters");
                    bot.PauseAutoScaler();
                    bot.LoadCommands();
                    bot.LoadCounters();
                    bot.RestartAutoScaler();
                }
            };

            fileSystemWatcher.Path = Directory.GetCurrentDirectory();
            fileSystemWatcher.EnableRaisingEvents = true;

            Console.WriteLine("File watching enabled");

            _quitMain.WaitOne();
            robotBlocker.Set();
            Console.WriteLine("Terminating");
        }