//Tracking the commit messages.
        public Task TrackingCommitMessages(StreamMessage msg)
        {
            if (commitTrackingMap.ContainsKey(msg.BatchID))
            {
                var targetBatch = commitTrackingMap[msg.BatchID];
                Functions.CheckNotNull(msg.barrierOrCommitInfo);
                targetBatch.AddBarrierOrCommitMsgTrackingHelper(msg.barrierOrCommitInfo);
            }
            else if (msg.BatchID >= 0 && !committedBatch.Contains(msg.BatchID))
            {
                PrettyConsole.Line("Committing a new batch" + msg.BatchID);
                StreamBatch newBatch = new StreamBatch(msg.BatchID);
                //The name should be changed
                Functions.CheckNotNull(msg.barrierOrCommitInfo);
                newBatch.AddBarrierOrCommitMsgTrackingHelper(msg.barrierOrCommitInfo);
                commitTrackingMap.Add(msg.BatchID, newBatch);
                //PrettyConsole.Line("Add batch " + msg.BatchID + " to the commitTrackingMap");
            }
            else
            {
                throw new InvalidOperationException("Batch ID less 0 or the message of that batch ahs been committed");
            }

            return(Task.CompletedTask);
        }
Exemple #2
0
        public void Initialize()
        {
            var dbName = DbConfig.DatabaseName;

            if (Process.GetProcesses().FirstOrDefault(x => x.ProcessName == "Raven.Server") == null)
            {
                PrettyConsole.Log(LogSeverity.Error, "Database", "Please make sure RavenDB is running.");
                Console.ReadLine();
                Environment.Exit(0);
            }


            _store = new Lazy <IDocumentStore>(
                () => new DocumentStore {
                Database = DbConfig.DatabaseName, Urls = new[] { DbConfig.DatabaseUrl }
            }
                .Initialize(),
                true).Value;
            if (_store == null)
            {
                PrettyConsole.Log(LogSeverity.Error, "Database", "Failed to build document store.");
            }


            if (_store.Maintenance.Server.Send(new GetDatabaseNamesOperation(0, 5)).All(x => x != dbName))
            {
                _store.Maintenance.Server.Send(new CreateDatabaseOperation(new DatabaseRecord(dbName)));
            }

            _store.AggressivelyCacheFor(TimeSpan.FromMinutes(30));


            using (var session = _store.OpenSession())
            {
                if (session.Advanced.Exists("Config"))
                {
                    return;
                }
                PrettyConsole.Log(LogSeverity.Info, "Arcade's Bot", "Enter Bot's Token:");
                var token = Console.ReadLine();
                PrettyConsole.Log(LogSeverity.Info, "Arcade's Bot", "Enter Bot's Prefix:");
                var prefix = Console.ReadLine();
                var model  = new ConfigModel
                {
                    Prefix     = prefix.Trim(),
                    Blacklist  = new List <ulong>(),
                    Namespaces = new List <string>(),
                    ApiKeys    = new Dictionary <string, string>
                    {
                        { "Giphy", "dc6zaTOxFJmzC" },
                        { "Google", "" },
                        { "Discord", token.Trim() },
                        { "Imgur", "" },
                        { "Cleverbot", "" }
                    }
                };
                var id = "Config";
                Create <ConfigModel>(ref id, model);
            }
        }
 //Commit
 public Task StartCommit(int ID)
 {
     PrettyConsole.Line("Start Commit Batch " + ID);
     commitMsg.BatchID = ID;
     topologyManager.Commit(commitMsg);
     return(Task.CompletedTask);
 }
        public async Task <bool> HandleCallbackAsync(SocketReaction reaction)
        {
            var emote = reaction.Emote;

            if (emote.Equals(_options.HitEmote))
            {
                _userClicked = true;
                await Message.DeleteAsync();

                Interactive.RemoveReactionCallback(Message);
                await Task.Run(async() =>
                {
                    await DisplayAsync();
                });


                //BlackJackService.RemovePlayerFromMatch(Context.User.Id);
                PrettyConsole.Log(LogSeverity.Info, "Callback", "User clicked HitEmote");
            }
            if (emote.Equals(_options.StandEmote))
            {
                _userClicked = true;
                //BlackJackService.RemovePlayerFromMatch(Context.User.Id);
                PrettyConsole.Log(LogSeverity.Info, "Callback", "User clicked StandEmote");
            }
            await Message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

            //await RenderAsync().ConfigureAwait(false);
            return(false);
        }
        public Task RemoveCustomDownStreamOperator(Guid guid)
        {
            int index = -1;

            for (int i = 0; i < downStreamOperators.Count; i++)
            {
                if (downStreamOperators[i].GetPrimaryKey() == guid)
                {
                    index = i;
                    break;
                }
            }
            if (index != -1)
            {
                downStreamOperators.RemoveAt(index);
                PrettyConsole.Line("Remove old stateful from upper stream");
                operatorSettings.RemoveOperatorFromDict(guid);
                topologyManager.UpdateOperatorSettings(this.GetPrimaryKey(), operatorSettings);
            }
            else
            {
                throw new ArgumentException();
            }

            return(Task.CompletedTask);
        }
 private bool CheckCount(StreamMessage msg)
 {
     if (!upStreamMessageCountMaps.ContainsKey(msg.BatchID))
     {
         if (msg.Count == 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else if (upStreamMessageCountMaps[msg.BatchID].ContainsKey(msg.From) && msg.Count == upStreamMessageCountMaps[msg.BatchID][msg.From])
     {
         return(true);
     }
     else if (!upStreamMessageCountMaps[msg.BatchID].ContainsKey(msg.From) && msg.Count == 0)
     {
         return(true);
     }
     else
     {
         PrettyConsole.Line("The count in stateless operator is not equal!");
         return(false);
     }
 }
 public Task MarkOperatorAsFailed()
 {
     isOperatorFailed   = true;
     isARestartOperator = true;
     PrettyConsole.Line("Mark this as failed!");
     return(Task.CompletedTask);
 }
        public static void GracefulShutdownMiner(Process minerProcess, Process commandLineProcess)
        {
            if (minerProcess == null)
            {
                return;
            }

            PrettyConsole.WriteLine($"Freezing Miner Process ({minerProcess.Id})", ConsoleColor.Magenta);

            try
            {
                SuspendProcess(minerProcess.Id);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                PrettyConsole.WriteLine($"Miner Process Has Exited: {minerProcess.HasExited}");
            }
            finally
            {
                Thread.Sleep(5000);
            }

            KillProcess(minerProcess);

            KillProcess(commandLineProcess);
        }
Exemple #9
0
        private void PrintMarker(float cpuUsage, int size)
        {
            var progressLines = (int)Math.Round(cpuUsage / 100 * size);

            Console.Write("\t[");
            var greenLines  = 0;
            var yellowLines = 0;
            var redLines    = 0;
            var empty       = 0;

            if (cpuUsage < 80)
            {
                greenLines = progressLines;
            }
            else if (cpuUsage >= 80 && cpuUsage < 95)
            {
                greenLines  = 80 * size / 100;
                yellowLines = progressLines - greenLines;
            }
            else if (cpuUsage > 95)
            {
                greenLines  = 80 * size / 100;
                yellowLines = 15 * size / 100;
                redLines    = progressLines - greenLines - yellowLines;
            }
            empty = size - progressLines;
            PrettyConsole.WriteColor(ConsoleColor.Green, new string('|', greenLines));
            PrettyConsole.WriteColor(ConsoleColor.Yellow, new string('|', yellowLines));
            PrettyConsole.WriteColor(ConsoleColor.Red, new string('|', redLines));
            PrettyConsole.WriteColor(ConsoleColor.DarkGray, new string(' ', empty));
            Console.WriteLine(']');
        }
Exemple #10
0
        public async Task <Task> Commit(StreamMessage msg)
        {
            List <TopologyUnit> units = topology.GetAllTopologyUnits();

            PrettyConsole.Line("Number of units: " + units.Count);
            msg.barrierOrCommitInfo         = new BarrierOrCommitMsgTrackingInfo(Guid.NewGuid(), units.Count);
            msg.barrierOrCommitInfo.BatchID = msg.BatchID;
            await batchTracker.TrackingCommitMessages(msg);

            foreach (TopologyUnit unit in units)
            {
                if (unit.OperatorType == OperatorType.Source)
                {
                    IStreamSource source = GrainFactory.GetGrain <IStreamSource>(unit.PrimaryKey);
                    source.Commit(msg);
                }
                else if (unit.OperatorType == OperatorType.Stateful)
                {
                    IStatefulOperator statefulOperator = GrainFactory.GetGrain <IStatefulOperator>(unit.PrimaryKey, Constants.Stateful_Operator_Prefix);
                    statefulOperator.Commit(msg);
                }
                else if (unit.OperatorType == OperatorType.Stateless)
                {
                    IStatelessOperator statelessOperator = GrainFactory.GetGrain <IStatelessOperator>(unit.PrimaryKey, Constants.Stateless_Operator_Prefix);
                    statelessOperator.Commit(msg);
                }
                else
                {
                    throw new ArgumentException("Commit: The operator type is in valid!");
                }
            }
            return(Task.CompletedTask);
        }
Exemple #11
0
        private static void RedirectStandardError(object sendingProcess, DataReceivedEventArgs outLine)
        {
            if (string.IsNullOrEmpty(outLine?.Data))
            {
                return;
            }

            var info = outLine.Data.ToLower();

            bool         output      = false;
            ConsoleColor outputColor = ConsoleColor.White;

            foreach (var s in DisplayKeywords)
            {
                if (info.Contains(s))
                {
                    output      = true;
                    outputColor = ConsoleColor.Green;
                    break;
                }
            }

            foreach (var s in ShareFoundKeywords)
            {
                if (info.Contains(s))
                {
                    _solutionsFound++;
                    outputColor = ConsoleColor.Green;
                    break;
                }
            }

            foreach (var s in RejectedShareKeywords)
            {
                if (info.Contains(s))
                {
                    _rejectedSolutions++;
                    outputColor = ConsoleColor.Yellow;
                    break;
                }
            }

            foreach (var s in ErrorKeywords)
            {
                if (info.Contains(s))
                {
                    PrettyConsole.WriteLine(outLine.Data, ConsoleColor.Red);
                    Log.Error(outLine.Data);
                    KillMiner();
                    return;
                }
            }

            if (VerboseOutput || output)
            {
                PrettyConsole.WriteLine(outLine.Data, outputColor);
            }

            UpdateAverageHashRate(outLine.Data);
        }
        //Recovery
        public async Task <Task> CompleteOneOperatorRecovery(BarrierOrCommitMsgTrackingInfo msgInfo)
        {
            if (!recoveryTrackingMap.ContainsKey(msgInfo.BatchID))
            {
                //Multiple batch has that problem
                PrettyConsole.Line("The recovery key " + msgInfo.BatchID + " is not exist");
            }
            else
            {
                //PrettyConsole.Line("Finish Tracking one message in batchID: " + msgInfo.BatchID);
                StreamBatch targetBatch = recoveryTrackingMap[msgInfo.BatchID];
                targetBatch.CompleteOneMessageTracking(msgInfo);
                if (targetBatch.readForCommitting)
                {
                    if (batchCoordinator != null)
                    {
                        PrettyConsole.Line("Batch: " + msgInfo.BatchID + " commit has been successfully recoveryed");
                        await batchCoordinator.CompleteRecovery(msgInfo.BatchID);

                        recoveryTrackingMap.Remove(msgInfo.BatchID);
                    }
                }
            }
            return(Task.CompletedTask);
        }
Exemple #13
0
        private static void EnterMainMenu()
        {
            _exitFlag = false;
            while (!_exitFlag)
            {
                Console.WriteLine("-=Главное меню=-");
                foreach (var item in _mainMenu)
                {
                    Console.WriteLine(item.Key + " - " + item.Value.MenuText);
                }
                var key = Console.ReadKey();
                Console.Clear();

                try
                {
                    if (_mainMenu.ContainsKey(key.Key))
                    {
                        _mainMenu[key.Key].MenuAction.Invoke();
                    }
                }
                catch (Exception exp)
                {
                    PrettyConsole.WriteLineColor(ConsoleColor.Red, exp.Message);
                }
            }
        }
Exemple #14
0
        private async Task RunAsync()
        {
            try
            {
                while (true)
                {
                    await Task.Delay(_postEvery);

                    int index    = _random.Next(0, _messages.Count());
                    var selected = _messages.ElementAtOrDefault(index);

                    if (selected == null)
                    {
                        await _log.SendMessageAsync("I couldn't find any messages to swindle <:ShibeSad:231546068960018433>");

                        return;
                    }

                    var mediaIds = await GetMediaIdsAsync(selected);

                    var status = await _twitter.Statuses.UpdateAsync(selected.Resolve(), possibly_sensitive : true, media_ids : mediaIds);

                    await _log.SendMessageAsync("", embed : TwitterHelper.GetPostedEmbed(selected, status.Id));

                    _ = _manager.LogAsync(status.Id, selected, _messages);
                    _messages.Clear();
                }
            }
            catch (Exception ex)
            {
                await PrettyConsole.LogAsync(LogSeverity.Error, "SwindleService", ex.ToString());
            }
        }
        public void CompleteMatch(ref ChessMatchModel chessMatch)
        {
            var statId = _statsHandler.AddStat(chessMatch);

            chessMatch.IdOfStat = statId;
            PrettyConsole.Log(LogSeverity.Info, "Complete ChessMatch",
                              $"Completed Chess Match With Id: {chessMatch.Id}");
        }
 public override Task OnNextAsync(ChatMsg item, StreamSequenceToken token = null)
 {
     if (item.Author == "System")
     {
         PrettyConsole.Line($"==== System message: '{item.Text}'", ConsoleColor.Green);
     }
     return(Task.CompletedTask);
 }
Exemple #17
0
        public async Task StartAsync()
        {
            await _commands.AddModulesAsync(Assembly.GetEntryAssembly());

            _discord.MessageReceived += OnMessageReceivedAsync;

            await PrettyConsole.LogAsync(LogSeverity.Info, "Services", $"Enabled CommandHandlingService with {_commands.Modules.Count()} modules and {_commands.Commands.Count()} commands");
        }
Exemple #18
0
            public static ErrorCodes HandleClientException(IClientException <ErrorData> exception)
            {
                Console.Clear();
                var res = HandleClientExceptionErrorData(exception);

                PrettyConsole.WriteLineColor(ConsoleColor.Red, "Ошибка: {0}", res.Item2);
                return(res.Item1);
            }
Exemple #19
0
 //Replay Logic
 public async Task <Task> ReplayTheMessageOnRecoveryCompleted()
 {
     PrettyConsole.Line("Start Replay!");
     foreach (StreamMessage msg in messagesForRecovery)
     {
         await ProcessNormalMessage(msg);
     }
     return(Task.CompletedTask);
 }
Exemple #20
0
        private async Task <Task> DetectPossibleFailures(object org)
        {
            PrettyConsole.Line("Start Detect Failures");
            Dictionary <Guid, Task <int> > taskMap  = new Dictionary <Guid, Task <int> >();
            List <Task <int> >             taskList = new List <Task <int> >();
            var topologyManager = GrainFactory.GetGrain <ITopology>(Constants.Topology_Manager);
            var operatorUnits   = await topologyManager.GetAllUnits();

            foreach (TopologyUnit unit in operatorUnits)
            {
                if (unit.OperatorType == OperatorType.Source)
                {
                    IStreamSource source = GrainFactory.GetGrain <IStreamSource>(unit.PrimaryKey);
                    var           task   = source.DetectErrors();
                    taskMap.Add(unit.PrimaryKey, task);
                }
                else if (unit.OperatorType == OperatorType.Stateful)
                {
                    IStatefulOperator statefulOperator = GrainFactory.GetGrain <IStatefulOperator>(unit.PrimaryKey, Constants.Stateful_Operator_Prefix);
                    var task = statefulOperator.DetectErrors();
                    taskMap.Add(unit.PrimaryKey, task);
                }
                else if (unit.OperatorType == OperatorType.Stateless)
                {
                    IStatelessOperator statelessOperator = GrainFactory.GetGrain <IStatelessOperator>(unit.PrimaryKey, Constants.Stateless_Operator_Prefix);
                    var task = statelessOperator.DetectErrors();
                    taskMap.Add(unit.PrimaryKey, task);
                }
                else
                {
                    throw new ArgumentException("Commit: The operator type is in valid!");
                }
            }

            try
            {
                await Task.WhenAny(Task.WhenAll(taskMap.Values), Task.Delay(TimeSpan.FromSeconds(2)));
            }
            catch (Exception e)
            {
                PrettyConsole.Line(e.ToString());
            }

            foreach (var task in taskMap)
            {
                if (task.Value.Status != TaskStatus.RanToCompletion)
                {
                    PrettyConsole.Line("Replace!");
                    await topologyManager.ReplaceTheOldOperator(task.Key);

                    disposable.Dispose();
                    break;
                }
            }

            return(Task.CompletedTask);
        }
 private Task TellTrackMessageSent(StreamMessage item)
 {
     if (tracker != null)
     {
         tracker.CompleteTracking(item);
         PrettyConsole.Line("Complete one barrier");
     }
     return(Task.CompletedTask);
 }
        protected async Task <Task> ExecuteMessagesByDownStreamOperators(StreamMessage msg, IAsyncStream <StreamMessage> stream, IOperator op)
        {
            if (downStreamOperators.Count > 0)
            {
                int batchID   = msg.BatchID;
                var targetKey = op.GetPrimaryKey();
                try
                {
                    msg.From = this.GetPrimaryKey();
                    //if is barrier message, set the message count
                    if (msg.Value == Constants.Barrier_Value)
                    {
                        if (downStreamMessageCountMaps.ContainsKey(batchID))
                        {
                            if (downStreamMessageCountMaps[batchID].ContainsKey(op.GetPrimaryKey()))
                            {
                                msg.Count = downStreamMessageCountMaps[batchID][op.GetPrimaryKey()];
                            }
                            else
                            {
                                msg.Count = 0;
                            }
                        }
                        else
                        {
                            msg.Count = 0;
                        }
                    }
                    //if it is a normal message, increment the count map
                    else if (msg.Value != Constants.System_Key)
                    {
                        if (!downStreamMessageCountMaps.ContainsKey(batchID))
                        {
                            downStreamMessageCountMaps.Add(batchID, new Dictionary <Guid, int>());
                        }

                        var key = op.GetPrimaryKey();
                        if (downStreamMessageCountMaps[batchID].ContainsKey(key))
                        {
                            downStreamMessageCountMaps[batchID][key] = downStreamMessageCountMaps[batchID][key] + 1;
                        }
                        else
                        {
                            downStreamMessageCountMaps[batchID].Add(key, 1);
                        }
                    }
                    op.ExecuteMessage(msg, stream);
                }
                catch (Exception e)
                {
                    PrettyConsole.Line("Get Exception : " + e + "; Start Receovry");
                    topologyManager.ReplaceTheOldOperator(targetKey);
                }
            }
            return(Task.CompletedTask);
        }
Exemple #23
0
        public override Task OnNextAsync(ChatMsg item, StreamSequenceToken token = null)
        {
            var textHasMention = item.Text.Contains("@");

            if (textHasMention)
            {
                PrettyConsole.Line($"==== MENTION DETECTED: '{item.Author}' mentions someone. Sending a notification email.", ConsoleColor.Green);
            }
            return(Task.CompletedTask);
        }
Exemple #24
0
        public void Update <T>(object id, object data)
        {
            using (var session = _store.OpenSession())
            {
                session.Store((T)data, $"{id}");
                session.SaveChanges();
            }

            PrettyConsole.Log(LogSeverity.Info, "Database", $"Updated {typeof(T).Name} with {id} id.");
        }
Exemple #25
0
        private static void VerifyProcesses()
        {
LoopStart:

            if (!_running || _paused)
            {
                return;
            }

            if (_minerProcess != null && (_minerProcess.HasExited || !_minerProcess.Responding))
            {
                PrettyConsole.WriteLine(
                    $"{MinerExe}.exe is not running or not responding. Attempting to restart...",
                    ConsoleColor.Yellow);
                KillMiner();
                Thread.Sleep(1000);
            }

            if (_minerProcess == null && !_paused)
            {
                PrettyConsole.WriteLine($"Starting {MinerExe}.exe now.", ConsoleColor.Yellow);

                //Start a new cmd window so that it doesn't intercept ctrl+c in windows 7 and crash drivers during a process kill
                string commandLine = $"/K START /B {MinerLocation} {MinerCommandLineParameters}";

                ProcessStartInfo pInfo = new ProcessStartInfo("cmd.exe", commandLine)
                {
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    //RedirectStandardInput = true
                    //Todo: Redirect standard input for miners that accept key commands
                };

                _commandLineProcess = Process.Start(pInfo);

                if (_commandLineProcess != null)
                {
                    //Note: Redirecting Standard Output/Error will only work if the mining sub process flushes console buffers, some miners (eg: xmr-stak) provide a flag to force console buffer flushing
                    _commandLineProcess.EnableRaisingEvents = true;
                    _commandLineProcess.OutputDataReceived += RedirectStandardOutput;
                    _commandLineProcess.ErrorDataReceived  += RedirectStandardError;
                    _commandLineProcess.BeginOutputReadLine();
                    _commandLineProcess.BeginErrorReadLine();
                }

                Thread.Sleep(5000);

                Console.Out.Flush();

                _minerProcess = Process.GetProcessesByName(MinerExe).FirstOrDefault();

                goto LoopStart;
            }
        }
Exemple #26
0
        public async Task InitializeAsync(DiscordSocketClient c, CommandService service)
        {
            PrettyConsole.Log(LogSeverity.Info, "Commands", $"Loading SQLite commands");
            _client  = c;
            _service = service;

            await _service.AddModulesAsync(Assembly.GetEntryAssembly());

            _client.MessageReceived += HandleCommandAsync;
            PrettyConsole.Log(LogSeverity.Info, "Commands", $"Ready, loaded {_service.Commands.Count()} commands");
        }
Exemple #27
0
        public void Delete <T>(object id)
        {
            using (var session = _store.OpenSession(_store.Database))
            {
                PrettyConsole.Log(LogSeverity.Info, "Database", $"Removed {typeof(T).Name} with {id} id.");
                session.Delete(session.Load <T>($"{id}"));

                session.SaveChanges();
                session.Dispose();
            }
        }
        public override Task OnActivateAsync()
        {
            currentBatchID  = 0;
            committedID     = -1;
            tracker         = GrainFactory.GetGrain <IBatchTracker>(Utils.Constants.Tracker);
            topologyManager = GrainFactory.GetGrain <ITopology>(Constants.Topology_Manager);
            PrettyConsole.Line("Register Timer");
            var streamProvider = GetStreamProvider(Constants.FaultTolerantStreamProvider);

            return(base.OnActivateAsync());
        }
Exemple #29
0
 public void FightAgainstCorruption()
 {
     try
     {
         _game.FightAgainstInflation();
     }
     catch (Exception exp)
     {
         PrettyConsole.WriteLineColor(ConsoleColor.Red, "Error: {0}", exp);
     }
     DisplayGameData(GetGameData());
 }
Exemple #30
0
 public void BuyFundDriver(ConsoleKeyInfo keyInfo)
 {
     try
     {
         _game.BuyFundDriver((int)keyInfo.Key - 64);
     }
     catch (Exception exp)
     {
         PrettyConsole.WriteLineColor(ConsoleColor.Red, "Error: {0}", exp);
     }
     DisplayGameData(GetGameData());
 }