コード例 #1
0
        static void Main(string[] args)
        {

            var optionSet = new RequiredValuesOptionSet();
            var pathToProjectFile = optionSet.AddRequiredVariable<string>("p", "Path to project file");
            var pathToFiles = optionSet.AddRequiredVariable<string>("i", "path for files, must end in trailing slash");
            var searchPattern = optionSet.AddRequiredVariable<string>("sp", "search pattern to use");
            var buildType = optionSet.AddVariable<string>("bt", "buildtype to use.  Values are EmbeddedResource, Content, Compile, and None");
            //var structureInVS = optionSet.AddVariable<string>("s", "structure inside of VS.  Must end with a backslash. eg: REPORTS\\");
            string structureInVS = "";

            var helper = new ConsoleManager(optionSet, "Include Files As Links");

            var canProceed = helper.PerformCanProceed(Console.Out, args);

            if (canProceed)
            {
                Console.WriteLine("Loading project file at {0}", pathToProjectFile.Value);
                var modifier = new ProjectModifierFacade(new Project(pathToProjectFile.Value));

                BuildAction compileAction;

                switch (buildType.Value.ToUpper())
                {
                    case "EMBEDDEDRESOURCE":
                        compileAction = BuildAction.EmbeddedResource;
                        break;
                    case "CONTENT":
                        compileAction = BuildAction.Content;
                        break;
                    case "NONE":
                        compileAction = BuildAction.None;
                        break;
                    case "COMPILE":
                        compileAction = BuildAction.Compile;
                        break;
                    default:
                        throw new NotImplementedException(String.Format("{0} is not supported.", buildType.Value));
                }


                Console.WriteLine("Searching for files");
                var myParams = EstablishLinkParams.BuildParamsForMatchingFiles(compileAction, pathToFiles.Value, searchPattern.Value, structureInVS).ToList();

                Console.WriteLine("{0} files found to link", myParams.Count);
                myParams.ForEach(modifier.EstablishLinkToFile);
                Console.WriteLine("Saving project file");
                modifier.Project.Save(pathToProjectFile.Value);
                Console.WriteLine("Complete");
            }
        }
コード例 #2
0
        public void Should_Respond_To_Help_Arg()
        {
            var optionSet = new RequiredValuesOptionSet();

            //Add a non-required variable because we want to verify the help-arg.
            var name = optionSet.AddVariable<string>("n", "");

            const string HelpPrototype = "?";
            const string Description = "TESTMODE";

            var cm = new ConsoleManager("Test", optionSet, HelpPrototype, Description);

            using (var writer = new StringWriter())
            {
                var parsed = cm.TryParseOrShowHelp(writer, new[] {HelpPrototype,});

                Assert.IsFalse(parsed);

                Assert.IsTrue(writer.ToString().Contains(Description));
            }
        }
コード例 #3
0
    private static void Main(string[] args)
    {
      // TODO this code is prone to invalid inputs... idc :bikini:

      var requiredValuesOptionSet = new RequiredValuesOptionSet();
      var repository = requiredValuesOptionSet.AddRequiredVariable<string>("repository",
                                                                           "Specifies the URI to the SVN repository");
      var trunk = requiredValuesOptionSet.AddRequiredVariable<string>("trunk",
                                                                      "Specifies the relative path to the trunk, which is diffed against the <branch> parameter (usually trunk)");
      var branch = requiredValuesOptionSet.AddRequiredVariable<string>("branch",
                                                                       "Specifies the relative path to the branch, whose initial revision is used as the offset for the change log");
      var redmineHost = requiredValuesOptionSet.AddRequiredVariable<string>("redmineHost",
                                                                            "Specifies the host, which serves the Redmine instance");
      var redmineApiKey = requiredValuesOptionSet.AddRequiredVariable<string>("redmineApiKey",
                                                                              "Specifies the api key that is used for communication with the Redmine instance");
      var ignoreBranchIssues = requiredValuesOptionSet.AddVariable<bool>("ignoreBranchIssues",
                                                                         "Specifies whether issues, comitted to the branch, should be ignored or not. Default is false");
      var consoleManager = new ConsoleManager("ChangeLog Generator",
                                              requiredValuesOptionSet);
      if (!consoleManager.TryParseOrShowHelp(Console.Out,
                                             args))
      {
        return;
      }

      Console.WriteLine("Getting the initial revision of {0}",
                        branch.Value);
      var initialLogItem = Program.GetInitialLogItem(repository,
                                                     branch);
      if (initialLogItem == null)
      {
        Console.WriteLine("Could not get the initial revision of {0}",
                          branch.Value);
        return;
      }

      long[] branchIssueIds;
      if (ignoreBranchIssues)
      {
        Console.WriteLine("Getting log for {0} since {1} ({2})",
                          branch.Value,
                          initialLogItem.Revision,
                          initialLogItem.Time);
        var branchLogItems = Program.GetLogSince(repository,
                                                 branch,
                                                 initialLogItem.Revision);
        branchIssueIds = branchLogItems.SelectMany(arg => arg.GetIssueIds())
                                       .Distinct()
                                       .ToArray();
      }
      else
      {
        branchIssueIds = new long[0];
      }

      var revision = initialLogItem.ChangedPaths.Max(arg => arg.CopyFromRevision);
      Console.WriteLine("Getting log for {0} since {1}",
                        trunk.Value,
                        revision);
      var logItems = Program.GetLogSince(repository,
                                         trunk,
                                         revision);

      var complexIssueIds = logItems.SelectMany(arg => arg.GetIssueIds()
                                                          .Except(branchIssueIds)
                                                          .Select(issueId => new
                                                                             {
                                                                               LogItem = arg,
                                                                               IssueId = issueId
                                                                             }))
                                    .OrderBy(arg => arg.IssueId)
                                    .GroupBy(arg => arg.IssueId)
                                    .ToDictionary(arg => arg.Key);

      Console.WriteLine("Getting the issues for {0} since {1} ({3}) from {2}",
                        trunk.Value,
                        revision,
                        redmineHost.Value,
                        initialLogItem.Time);
      var issues = Program.GetIssues(redmineHost,
                                     redmineApiKey,
                                     complexIssueIds.Keys);

      issues.ForEach(issue =>
                     {
                       Console.WriteLine("#{0}: {1} (assigned to: {2}, commits by: {3})",
                                         issue.Id,
                                         issue.Subject,
                                         issue.AssignedTo?.Name ?? "none",
                                         string.Join(", ",
                                                     complexIssueIds[issue.Id].Select(arg => arg.LogItem)
                                                                              .Select(arg => arg.Author)
                                                                              .Distinct()));
                     });
    }
コード例 #4
0
        /// <summary>
        ///     Processes the arguments, utilising NDesk.Options.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>True if the command line was successfully processed</returns>
        private static bool ProcessArguments(string[] args)
        {
            try
            {
                bool retVal;

                // Create a commandline option set for processing command line options
                RequiredValuesOptionSet options = new RequiredValuesOptionSet();

                commandLine.SettingsFile        = options.AddRequiredVariable <string>("f|File", "Settings file to encrypt/decrypt");
                commandLine.Decrypt             = options.AddSwitch("d|Decrypt", "Indicates that settings are to be decrypted - default is to encrypt");
                commandLine.AffectedSettingsCsv =
                    options.AddVariable <string>("s|Settings", "Comma seperated list of individual settings to encrypt/decrypt");
                commandLine.AffectedSettingsFile = options.AddVariable <string>("sf|SettingsFile",
                                                                                "Filepath to the file containing line seperated settings to encrypt/decrypt");

                // Process the command line arguments
                ConsoleManager consoleOptionsManager = new ConsoleManager("Settings Encryptor", options);
                retVal = consoleOptionsManager.TryParseOrShowHelp(Console.Out, args);

                if (retVal)
                {
                    if (commandLine.AffectedSettingsCsv.Value != null)
                    {
                        settingsToEncrypt.AddRange(commandLine.AffectedSettingsCsv.Value.Split(','));
                    }
                    else if (commandLine.AffectedSettingsFile.Value == null)
                    {
                        throw new EncryptAppException(EncryptAppExceptionReason.NoSettingsSpecified);
                    }
                    else
                    {
                        if (!File.Exists(commandLine.AffectedSettingsFile))
                        {
                            throw new EncryptAppException(EncryptAppExceptionReason.SettingsInputFileNotFound,
                                                          commandLine.AffectedSettingsFile.Value);
                        }

                        // Read the list of settings from the settings file
                        string[] readSettings = File.ReadAllLines(commandLine.AffectedSettingsFile);

                        foreach (string readSetting in readSettings)
                        {
                            // Be quite forgiving about how the settings are listed.
                            settingsToEncrypt.AddRange(readSetting.Trim(' ', '"', '\'', ',').Split(','));
                        }
                    }
                }

                return(retVal);
            }
            catch (EncryptAppException)
            {
                throw;
            }
            catch (OptionException excep)
            {
                throw new EncryptAppException(EncryptAppExceptionReason.CommandLineOptionException, excep.Message);
            }
            catch (Exception excep)
            {
                throw new EncryptAppException(EncryptAppExceptionReason.UnknownException, nameof(ProcessArguments), excep.Message);
            }
        }
コード例 #5
0
        public static void Main(string[] args)
        {
            SetupNLog();

            var options = new RequiredValuesOptionSet();

            // Required
            var templateBaseFolderArg = options.AddRequiredVariable<string>("tbase", "{TemplateBaseFolder} which contains .cshtml Razor templates");
            var razorFilenameArg = options.AddRequiredVariable<string>("f", "{RazorFile} to parse & execute");
            var outputFilenameArg = options.AddRequiredVariable<string>("o", "{OutputFilename}");

            // Optional
            var modelKeyValuePairArgs = options.AddVariableMatrix<object>("m", "{Model} key/value pairs");
            var namespaceArgs = options.AddVariableList<string>("n", "{Namespaces} to automatically include");
            var outputBaseFolderArg = options.AddVariable<string>("obase", "{OutputBaseFolder}");
            var assemblyFileArgs = options.AddVariableList<string>("assemblyFile", "{Assembly} path to load");
            var assemblyFolderArgs = options.AddVariableList<string>("assemblyFolder", "{AssemblyFolder} to load assemblies from");
            var assemblyFolderIgnorePatternArgs = options.AddVariableList<string>("ignoreAssemblyPattern", "{RegexIgnorePattern} to ignore certain assemblies within Assembly Folders. Helpful to prevent an assembly from attempting to load multiple times.");
            var suspendRootOutput = options.AddVariable<bool>("suspendRootOutput", "Silence primary root template's output. Child templates are still outputed.");
            var rootExistingFileBehavior = options.AddVariable<int>("rootOverwriteBehavior", "ExistingFileBehavior of primary root template. 0 = ThrowException, 1 = NeverOverwrite, 3 = AlwaysOverwrite");

            var consoleManager = new ConsoleManager(options, "gcRazorConsole", "?", new string[] {
                "",
                "gcRazorConsole: 'Console-Based Razor Template Execution'",
                "",
                "Specify the Razor file to parse & execute, as well as key/value pairs to be used for @Model calls. For instance: Console parameter m:Name=Greg would transform razor @Model.Name into Greg",
                "Please find out more information at http://www.geniuscode.net", 
                ""});

            // VisualStudio-Aware Exceptions (for cast exceptions)
            consoleManager.MakeOptionExceptionsVisualStudioAware();

            var argErrors = new StringWriter();

            // Apply Arguments

            bool canProceed = consoleManager.PerformCanProceed(argErrors, args);

            if (canProceed)
            {
                logger.Info(string.Format("templateBaseFolder = {0}", templateBaseFolderArg.Value));
                logger.Info(string.Format("razorFilename = {0}", razorFilenameArg.Value));
                logger.Info(string.Format("outputFilename = {0}", outputFilenameArg.Value));
                logger.Info(string.Format("outputBaseFolder = {0}", outputBaseFolderArg.Value));
                logger.Info(string.Format("assemblyFiles = {0}", assemblyFileArgs.Values.Select(file => file + "; ")));
                logger.Info(string.Format("assemblyFolders = {0}", assemblyFolderArgs.Values.Select(folder => folder + "; ")));
                logger.Info(string.Format("assemblyFolderIgnorePatterns = {0}", assemblyFolderIgnorePatternArgs.Values.Select(pattern => pattern + "; ")));

                // Remove quotes from folder paths
                var templateBaseFolder = RemoveSurroundingQuotes(templateBaseFolderArg.Value);
                var razorFilename = RemoveSurroundingQuotes(razorFilenameArg.Value);
                var outputFilename = RemoveSurroundingQuotes(outputFilenameArg.Value);
                var outputBaseFolder = RemoveSurroundingQuotes(outputBaseFolderArg.Value);

                var assemblyFiles = assemblyFileArgs.Values.Select(file => RemoveSurroundingQuotes(file));
                var assemblyFolders = assemblyFolderArgs.Values.Select(folder => RemoveSurroundingQuotes(folder));
                var assemblyFolderIgnorePatterns = assemblyFolderIgnorePatternArgs.Values.Select(pattern => new Regex(pattern));

                // Template & Output Base Folders
                var razorArgs = new RazorExecuteArgs(templateBaseFolder, outputBaseFolder);

                // Additional Namespaces
                razorArgs.namespaces.AddRange(namespaceArgs.Values);

                // Additional Assemblies
                RazorExtensions.ApplyAssembliesToRazorArgs(razorArgs, assemblyFiles, assemblyFolders, assemblyFolderIgnorePatterns);

                // Additional Options
                razorArgs.SuspendRootOutput = suspendRootOutput.Value;
                razorArgs.RootExistingFileBehavior = (ExistingFileBehavior)rootExistingFileBehavior.Value;

                // Execute Razor
                RazorExtensions.ExecuteRazorDynamicModel(razorArgs, razorFilename, modelKeyValuePairArgs.Matrix, outputFilename);
            }
            else
            {
                // Arguments Failed
                // Build VisualStudio-Aware Exception
                var errorString = ConsoleHelper.CreateVisualStudioErrorString("gcRazorConsole", "-100", string.Format("Invalid command-line arguments. {0}",argErrors.ToString()));

                logger.Error(errorString);

                Console.Write(errorString);
            }

        }