Beispiel #1
0
        public static void StorytellerRun(this ICakeContext context, string projectPath,
                                          StorytellerSettings settings = null)
        {
            var runner = new StorytellerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Arguments);

            runner.RunCommand(projectPath, settings);
        }
        /// <summary>
        /// Builds arguments for Storyteller
        /// </summary>
        /// <param name="command">Storyteller Command (Open or Run)</param>
        /// <param name="projectPath">Storyteller project path</param>
        /// <param name="arguments">Arguments pass in by cake</param>
        /// <param name="settings"><see cref="StorytellerSettings"/> object</param>
        /// <returns></returns>
        public ProcessArgumentBuilder BuildArguments(StorytellerCommand command,
                                                     string projectPath,
                                                     ICakeArguments arguments,
                                                     StorytellerSettings settings = null)
        {
            var dict = new Dictionary <string, string>();

            if (settings != null)
            {
                //settings
                var props = typeof(StorytellerSettings).GetProperties();
                foreach (var prop in props)
                {
                    var attrs = prop.GetCustomAttributes(false);
                    foreach (var attr in attrs)
                    {
                        var stFlagAttr = attr as StorytellerFlag;
                        if (stFlagAttr != null)
                        {
                            var value = prop.GetValue(settings, null);
                            if (value != null)
                            {
                                dict.Add(stFlagAttr.Flag, value.ToString());
                            }
                        }
                    }
                }
            }

            //arguments
            if (arguments != null)
            {
                _stArguments.ForEach(arg =>
                {
                    if (arguments.HasArgument(arg))
                    {
                        dict[arg] = arguments.GetArgument(arg);
                    }
                });
            }

            var builder = new ProcessArgumentBuilder();

            builder.Append(command.ToString().ToLower());
            builder.Append(projectPath);
            foreach (var pair in dict)
            {
                if (pair.Value == "True" || string.IsNullOrEmpty(pair.Value))
                {
                    builder.Append("--" + pair.Key);
                }
                else
                {
                    builder.Append("--" + pair.Key + " " + pair.Value);
                }
            }
            return(builder);
        }