Esempio n. 1
0
        public CommandResult Execute()
        {
            try
            {
                minerConfig = MinerConfig.ReadFromFile();
            }
            catch (TargetExecutionException ex)
            {
                logger.WriteLog(3, 0, "Read config file failed: " + ex.Message);
                return(CommandResult.ErrorResult(ex));
            }

            if (minerConfig == null || minerManager == null)
            {
                logger.WriteLog(3, 0, "Cannot Execute due to previous initialization failure.");
                return(CommandResult.ErrorResult(DaemonErrorCode.INITIALIZE_FAILED, "Cannot Execute due to previous initialization failure."));
            }

            List <CommandInstance> commands = ConsoleCommand.ParseCommands(rawArguments);

            if (commands.Count == 0)
            {
                // Do nothing is there is no command
                return(CommandResult.ErrorResult(DaemonErrorCode.COMMAND_MISSING, "Missing command here."));
            }

            if (commands.Count > 1)
            {
                // Not Supported
                return(CommandResult.ErrorResult(DaemonErrorCode.COMMAND_TOO_MANY, "Curent not supporting multiple commands."));
            }


            // Disable the Console output during the command call
            TextWriter defaultOutput = Console.Out;

            try
            {
                Console.SetOut(TextWriter.Null);
                return(commands[0].Execute());
            }
            catch (TargetExecutionException ex)
            {
                return(CommandResult.ErrorResult(ex));
            }
            catch (Exception ex)
            {
                return(CommandResult.ErrorResult(DaemonErrorCode.UNKNOWN_ERROR, ex.Message));
            }
            finally
            {
                Console.SetOut(defaultOutput);
            }
        }
Esempio n. 2
0
        public static MinerConfig ReadFromFile()
        {
            var location      = System.Reflection.Assembly.GetEntryAssembly().Location;
            var directoryPath = Path.GetDirectoryName(location);

            using (StreamReader sr = new StreamReader(directoryPath + "/" + defaultConfigFileName))
            {
                string          jsonString = sr.ReadToEnd();
                MinerConfigFile configFile = Newtonsoft.Json.JsonConvert.DeserializeObject <MinerConfigFile>(jsonString);

                MinerConfig config = new MinerConfig(configFile);
                return(config);
            }
        }
Esempio n. 3
0
        public MainConsole(string[] args)
        {
            rawArguments = args;

            minerManager = new MinerManager();
            logger       = new ConsoleLogger();
            minerManager.SetLogger(logger);

            try
            {
                minerConfig = MinerConfig.ReadFromFile();
            }
            catch (Exception ex)
            {
                logger.WriteLog(3, 0, "Read config file failed: " + ex.ToString());
            }
        }