Ejemplo n.º 1
0
        private void AddCommand(ParameterTokenSet tokens, DroneFlags flags)
        {
            var files = tokens.Select(x => new { lower = x.Value.ToLower(), val = x.Value }).ToList();

            var sources = files
                .Where(x => x.lower.EndsWith(".cs"))
                .Select(x => x.val)
                .ToList();

            var refs = files
                .Where(x => x.lower.EndsWith(".dll"))
                .Select(x => x.val)
                .ToList();

            if (sources.Count == 0 && refs.Count == 0)
            {
                this.log.Warn("nothing to add. no files specified");
                return;
            }

            var config = this.droneService.LoadConfig(flags.ConfigFileName);

            this.droneService.AddFiles(config, sources, refs);
            this.droneService.SaveConfig(config);
        }
Ejemplo n.º 2
0
        public DroneEnv(DroneConfig config, DroneFlags flags)
        {
            if(config == null)
                throw new ArgumentNullException("config");

            if(flags == null)
                throw new ArgumentNullException("flags");

            this.Config = config;
            this.Flags = flags;
        }
Ejemplo n.º 3
0
        private void ApplyLogConfig(DroneFlags flags)
        {
            if (flags == null)
                throw new ArgumentNullException("flags");

            var rules = (from rule in LogManager.Configuration.LoggingRules
                         where rule.LoggerNamePattern == "drone" || rule.LoggerNamePattern == "drone.task.*"
                         select rule).ToList();

            foreach (var rule in rules)
            {
                var level = flags.LogLevel;

                if (rule.LoggerNamePattern == "drone" && level > LogLevel.Info)
                    level = LogLevel.Info;

                var effectiveLevels = logLevels.Where(l => l >= level).ToList();

                this.ApplyLogLevel(rule, effectiveLevels);
            }

            if (!flags.IsConsoleLogColorsEnabled)
                this.DisableConsoleLogColors(rules);

            var errorFileTarget = (from target in LogManager.Configuration.AllTargets
                                   where target.Name == "drone.error.file" && target is FileTarget
                                   select target as FileTarget).FirstOrDefault();

            if (errorFileTarget != null)
            {
                var configPath = Path.GetFullPath(flags.ConfigFileName);
                var configDir = Path.GetDirectoryName(configPath);
                errorFileTarget.FileName = Path.Combine(configDir, "drone.errors.txt");
            }

            LogManager.ReconfigExistingLoggers();
        }
Ejemplo n.º 4
0
 private void ShowHelpCommand(ParameterTokenSet tokens, DroneFlags flags)
 {
     this.log.Info("!help goes here");
 }
Ejemplo n.º 5
0
 private void SyncCommand(ParameterTokenSet tokens, DroneFlags flags)
 {
     throw new Exception("not implemented exception");
 }
Ejemplo n.º 6
0
 private void RunCommand(ParameterTokenSet tokens, DroneFlags flags)
 {
     var config = this.droneService.LoadConfig(flags.ConfigFileName);
     var env = new DroneEnv(config, flags);
     var taskNames = tokens.Where(x => !x.Value.StartsWith("-")).Select(x => x.Value);
     this.droneService.RunTasks(env, taskNames);
 }
Ejemplo n.º 7
0
        private void SetPropertyCommand(ParameterTokenSet tokens, DroneFlags flags)
        {
            var config = this.droneService.LoadConfig(flags.ConfigFileName);

            if (tokens.Count == 0)
            {
                this.log.Error("no key provided, must provide a key and value");
                return;
            }

            var key = tokens.Pop();

            if (key == null)
            {
                this.log.Error("no key provided. please provide a key");
                return;
            }

            var type = tokens.PopFlagValue("-t", "auto");

            var val = tokens.Pop();

            if (val == null)
            {
                this.log.Error("no value provided. please provide a value");
                return;
            }

            config.Props[key.Value] = (JToken)this.GetTokenJsonValue(val, type);

            this.droneService.SaveConfig(config);

            this.log.Info("key: {0}", key.Value);
            this.log.Info("value: {0}", config.Props[key.Value]);
        }
Ejemplo n.º 8
0
        private void ListCommand(ParameterTokenSet tokens, DroneFlags flags)
        {
            var config = this.droneService.LoadConfig(flags.ConfigFileName);
            var env = new DroneEnv(config, flags);

            // need to add pattern matching to the check
            var tasks = this.droneService.GetTasks(env).ToList();

            var searchPatternFlag = tokens.Pop();

            if(searchPatternFlag != null)
            {
                var searchPattern = searchPatternFlag.Value ?? string.Empty;
                tasks = tasks.Where(x => Regex.IsMatch(x.Name, searchPattern)).ToList();
            }

            var taskCounter = 0;

            foreach (var task in tasks)
            {
                this.log.Info("{0}─ {1}", this.GetTaskListPositionSymbol(taskCounter, tasks.Count - 1, false), task.Name);

                if (task.Dependencies.Count > 0)
                {
                    var depCounter = 0;

                    foreach (var dep in task.Dependencies)
                    {
                        this.log.Info("│  {0}─ {1}", this.GetTaskListPositionSymbol(depCounter, task.Dependencies.Count - 1, true), dep);
                        depCounter += 1;
                    }
                }

                taskCounter += 1;
            }
        }
Ejemplo n.º 9
0
        private void RemovePropertyCommand(ParameterTokenSet tokens, DroneFlags flags)
        {
            var config = this.droneService.LoadConfig(flags.ConfigFileName);
            var key = tokens.TryGetAt(0);

            if (key != null)
            {
                if (config.Props.Remove(key.Value))
                    this.log.Info("property '{0}' removed", key.Value);
            }

            this.droneService.SaveConfig(config);
        }
Ejemplo n.º 10
0
        private void InitCommand(ParameterTokenSet tokens, DroneFlags flags)
        {
            if (File.Exists(flags.ConfigFileName))
            {
                this.log.Warn("file '{0}' already exists", flags.ConfigFileName);
                return;
            }

            var config = new DroneConfig();
            config.SetConfigFilename(flags.ConfigFileName);

            this.droneService.InitDroneDir(config);

            this.droneService.SaveConfig(config);

            this.log.Info("created '{0}'", Path.GetFileName(config.DroneDirPath));
            this.log.Info("created '{0}'", Path.GetFileName(config.FilePath));
        }
Ejemplo n.º 11
0
        private void HandleCommand(string command, ParameterTokenSet tokens, DroneFlags flags)
        {
            if (string.IsNullOrWhiteSpace(command))
                throw new ArgumentException("command is empty or null", "command");

            if(flags == null)
                throw new ArgumentNullException("flags");

            var action = null as Action<ParameterTokenSet, DroneFlags>;

            switch (command.ToLower())
            {
                case "init":
                    action = this.InitCommand;
                    break;

                case "help":
                    action = this.ShowHelpCommand;
                    break;

                case "add":
                    action = this.AddCommand;
                    break;

                case "rm":
                    action = this.RemoveCommand;
                    break;

                case "r":
                    action = this.RunCommand;
                    break;

                case "sp":
                    action = this.SetPropertyCommand;
                    break;

                case "gp":
                    action = this.GetPropertyCommand;
                    break;

                case "rp":
                    action = this.RemovePropertyCommand;
                    break;

                case "ls":
                    action = this.ListCommand;
                    break;

                case "c":
                    action = this.CompileCommand;
                    break;

                case "sync":
                    action = this.SyncCommand;
                    break;
            }

            if (action == null)
            {
                throw UnknownCommandException.Get(command);
            }
            else
            {

                action(tokens, flags);
            }
        }
Ejemplo n.º 12
0
        private void GetPropertyCommand(ParameterTokenSet tokens, DroneFlags flags)
        {
            var config = this.droneService.LoadConfig(flags.ConfigFileName);

            var key = tokens.TryGetAt(0);

            if (key == null)
            {
                foreach (var prop in config.Props)
                {
                    this.log.Info("{0}: {1}", prop.Key, prop.Value);
                }
            }
            else
            {
                var token = null as JToken;
                if (!config.Props.TryGetValue(key.Value, out token))
                    return;

                this.log.Info("{0}: {1}", key.Value, token);
            }
        }
Ejemplo n.º 13
0
        private DroneFlags GetFlags(ParameterTokenSet tokens)
        {
            var configFilename = tokens.PopFlagValue("-f", DroneConfig.DroneFileName);

            if (Directory.Exists(configFilename))
            {
                this.log.Debug("config filename is a directory, setting config filename to dir + default name");
                configFilename = Path.Combine(configFilename, DroneConfig.DroneFileName);
            }

            var isDebugEnabled = tokens.PopFlag("-d");
            var isConsoleLogColorsEnabled = !tokens.PopFlag("-no-colors");
            var logLevel = DroneLogManager.GetLogLevelFromString(tokens.PopFlagValue("-l", "info"));

            var flags = new DroneFlags(
                configFilename,
                isDebugEnabled,
                isConsoleLogColorsEnabled,
                logLevel);

            return flags;
        }
Ejemplo n.º 14
0
 private void CompileCommand(ParameterTokenSet tokens, DroneFlags flags)
 {
     var config = this.droneService.LoadConfig(flags.ConfigFileName);
     var env = new DroneEnv(config, flags);
     this.droneService.CompileTasks(env, LogLevel.Info);
 }