Ejemplo n.º 1
0
        public static void PrintArgument(List <string> lines, ICommandLineArgument arg, string indent)
        {
            lines.Add(indent + "--" + arg.Name + " (" + arg.Typename + "): " + arg.ShortDescription);

            if (arg.Deprecated)
            {
                lines.Add(indent + "  " + Strings.CommandLineArgument.DeprecationMarker + ": " + arg.DeprecationMessage);
            }

            lines.Add(indent + "  " + arg.LongDescription);
            if (arg.Aliases != null && arg.Aliases.Length > 0)
            {
                lines.Add(indent + "  * " + Strings.CommandLineArgument.AliasesHeader + ": --" + string.Join(", --", arg.Aliases));
            }

            if (arg.ValidValues != null && arg.ValidValues.Length > 0)
            {
                lines.Add(indent + "  * " + Strings.CommandLineArgument.ValuesHeader + ": " + string.Join(", ", arg.ValidValues));
            }

            if (!string.IsNullOrEmpty(arg.DefaultValue))
            {
                lines.Add(indent + "  * " + Strings.CommandLineArgument.DefaultValueHeader + ": " + arg.DefaultValue);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a collection of values starting at <paramref name="argument"/>, and ending at the next value that begins
        /// with the first character of <paramref name="argument"/>.
        /// </summary>
        /// <param name="argument">The argument to search for.</param>
        /// <param name="comparer">The comparer to use when determining if a match was found.</param>
        /// <param name="argumentsToParse">
        /// The collection to search.
        /// Specifying null will default to <see cref="CommandLine.Arguments"/>.
        /// </param>
        /// <returns>
        /// Returns all child <see cref="ICommandLineArgument.Command"/> and parameters based upon the
        /// <see cref="ICommandLineSpecification"/> if <paramref name="argument"/> is found.
        /// Returns an empty collection if <paramref name="argument"/> is not found.
        /// </returns>
        /// <remarks>
        /// This method searches <paramref name="argumentsToParse"/> for a value that matches <paramref name="argument"/>
        /// using the <see cref="Comparer"/> value.
        /// Once found, that value and all proceeding values are returned until a value whose first character matches that
        /// of the <paramref name="argument"/>'s delimiter.
        ///
        /// If <paramref name="argumentsToParse"/> is null, <see cref="Arguments"/> is used.
        ///
        /// If no matches to <paramref name="argument"/> are found, an empty collection is returned.
        /// </remarks>
        public static IEnumerable <string> GetSegment(this ICommandLineArgument argument, StringComparison?comparer = null, IEnumerable <string> argumentsToParse = null)
        {
            var  workingSegment  = argumentsToParse ?? Arguments;
            var  workingComparer = comparer ?? Comparer;
            bool didFindFirst    = false;

            if (workingSegment.Any(str => argument.Command.Equals(str, workingComparer)))
            {
                foreach (var arg in workingSegment)
                {
                    if (!didFindFirst)
                    {
                        if (argument.Command.Equals(arg, workingComparer))
                        {
                            yield return(arg);

                            didFindFirst = true;
                        }
                    }
                    else
                    {
                        if (arg.StartsWith(argument.Specification.Delimiter))
                        {
                            break;
                        }
                        else
                        {
                            yield return(arg);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 UsesName(
     ICommandLineArgument arg,
     string[] splitArgs)
 {
     var uses = ((splitArgs[0].StartsWith("--") && splitArgs[0].EndsWith(arg.LongName)) ||
         ((arg.ShortName != null) && (splitArgs[0].StartsWith("-") && splitArgs[0].EndsWith(arg.ShortName))));
     return uses;
 }
Ejemplo n.º 4
0
        UsesName(
            ICommandLineArgument arg,
            string[] splitArgs)
        {
            var uses = ((splitArgs[0].StartsWith("--") && splitArgs[0].EndsWith(arg.LongName)) ||
                        ((arg.ShortName != null) && (splitArgs[0].StartsWith("-") && splitArgs[0].EndsWith(arg.ShortName))));

            return(uses);
        }
    public override void Run(ICommandLineArgument[] args) {

      core = new HeuristicLab.Clients.Hive.SlaveCore.Core();
      Thread coreThread = new Thread(core.Start);
      coreThread.IsBackground = true;
      coreThread.Start();

      MainWindow window = new MainWindow();
      window.Content = new SlaveItem();
      Application.ApplicationExit += new System.EventHandler(Application_ApplicationExit);
      Application.Run(window);
    }
Ejemplo n.º 6
0
    public override void Run(ICommandLineArgument[] args) {
      HeuristicLab.MainForm.WindowsForms.MainForm mainForm = null;

      if (Settings.Default.MainFormType == OptimizerMainFormTypes.DockingMainForm) {
        mainForm = new OptimizerDockingMainForm(typeof(IOptimizerUserInterfaceItemProvider));
      } else if (Settings.Default.MainFormType == OptimizerMainFormTypes.MultipleDocumentMainForm) {
        mainForm = new OptimizerMultipleDocumentMainForm(typeof(IOptimizerUserInterfaceItemProvider));
      } else if (Settings.Default.MainFormType == OptimizerMainFormTypes.SingleDocumentMainForm) {
        mainForm = new OptimizerSingleDocumentMainForm(typeof(IOptimizerUserInterfaceItemProvider));
      }

      if (mainForm != null) {
        if (CheckSavedMainFormSettings()) {
          mainForm.Location = Settings.Default.MainFormLocation;
          mainForm.Size = Settings.Default.MainFormSize;
          mainForm.WindowState = Settings.Default.MainFormWindowState;
        }

        mainForm.FormClosing += (sender, eventArgs) => {
          if (mainForm.WindowState != FormWindowState.Minimized)
            Settings.Default.MainFormWindowState = mainForm.WindowState;
          if (mainForm.WindowState != FormWindowState.Normal) {
            Settings.Default.MainFormLocation = mainForm.RestoreBounds.Location;
            Settings.Default.MainFormSize = mainForm.RestoreBounds.Size;
          } else if (mainForm.WindowState == FormWindowState.Normal) {
            Settings.Default.MainFormLocation = mainForm.Location;
            Settings.Default.MainFormSize = mainForm.Size;
          }
        };


        ClientInformation.InitializeAsync();
        UserInformation.InitializeAsync();

        mainForm.ShowContentInViewHost = true;
        var filesToOpen = args.OfType<OpenArgument>().Select(x => x.Value);
        mainForm.Load += (sender, eventArgs) => FileManager.OpenFiles(filesToOpen);
        Application.Run(mainForm);
      } else {
        MessageBox.Show("Error loading setting for the MainForm Type. Please check your configuration file!", "HeuristicLab", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
    }
        public void AddArgument(ICommandLineArgument argument)
        {
            // Ensure the argument already has a parser registered.
            if (!argumentTypeParsers.ContainsKey(argument.ArgumentType))
            {
                throw new ArgumentException($"ArgumentParser for type {argument.ArgumentType} is not registered.", nameof(argument));
            }

            // Ensure the argument isn't already registered.
            if (arguments.ContainsKey(argument.Name))
            {
                throw new ArgumentException($"Argument {argument.Name} is already registered.", nameof(argument));
            }

            arguments[argument.Name] = argument;
            if (argument.IsRequired)
            {
                requiredArguments.Add(argument.Name);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Runs the application.
 /// </summary>
 public abstract void Run(ICommandLineArgument[] args);
 /// <summary>
 /// Creates new instance of <see cref="CommandLineGrouping"/>.
 /// <para>
 /// *See remarks for further details and correct implementation.
 /// </para>
 /// </summary>
 /// <param name="parentCallChain">The parent call-chain.</param>
 /// <param name="children">The associated children in relation to <paramref name="parentCallChain"/>.</param>
 /// <param name="description">A description of what this grouping represents or does within the scope of the application.</param>
 /// <exception cref="System.ArgumentNullException">
 /// Throws when <paramref name="parentCallChain"/> is null or contains not elements.
 /// </exception>
 /// <remarks>
 /// The <see cref="ICommandLineGrouping.ParentCallChain"/> property represents the full parent hierarchy chain.
 ///
 /// The <see cref="ICommandLineGrouping.Children"/> property represents associated child pairings.
 /// It is important to note this property is not an "all inclusive" listing", but rather an individual grouping.
 /// This means that if you have one "main argument", which has three "child arguments", then specifying a grouping
 /// with "main" and "childOne" would transpose to the command line as "$ main childOne".
 ///
 /// If you wanted to specify a grouping that states "main" must run with "childOne" and "childTwo", but leave "childThree" as optional,
 /// then you would create two groupings; one with "childOne" and "childTwo"; the other, with "childOne", "childTwo", and "childThree".
 /// </remarks>
 public CommandLineGrouping(ICommandLineArgument parentCallChain, ICommandLineArgument[] children, string description = null) : base(parentCallChain, children, description)
 {
 }
Ejemplo n.º 10
0
        public static void PrintArgument(List<string> lines, ICommandLineArgument arg, string indent)
        {
            lines.Add(indent + "--" + arg.Name + " (" + arg.Typename + "): " + arg.ShortDescription);

            if (arg.Deprecated)
                lines.Add(indent + "  " + Strings.CommandLineArgument.DeprecationMarker + ": " + arg.DeprecationMessage);

            lines.Add(indent + "  " + arg.LongDescription);
            if (arg.Aliases != null && arg.Aliases.Length > 0)
                lines.Add(indent + "  * " + Strings.CommandLineArgument.AliasesHeader + ": --" + string.Join(", --", arg.Aliases));

            if (arg.ValidValues != null && arg.ValidValues.Length > 0)
                lines.Add(indent + "  * " + Strings.CommandLineArgument.ValuesHeader + ": " + string.Join(", ", arg.ValidValues));

            if (!string.IsNullOrEmpty(arg.DefaultValue))
                lines.Add(indent + "  * " + Strings.CommandLineArgument.DefaultValueHeader + ": " + arg.DefaultValue);
        }
Ejemplo n.º 11
0
 private void StartApplication(ApplicationDescription app, ICommandLineArgument[] args) {
   splashScreen.Show("Loading " + app.Name);
   Thread t = new Thread(delegate() {
     bool stopped = false;
     do {
       try {
         if (!abortRequested) {
           pluginManager.Run(app, args);
         }
         stopped = true;
       }
       catch (Exception ex) {
         stopped = false;
         ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
         Thread.Sleep(5000); // sleep 5 seconds before autorestart
       }
     } while (!abortRequested && !stopped && app.AutoRestart);
   });
   t.SetApartmentState(ApartmentState.STA); // needed for the AdvancedOptimizationFrontent
   t.Start();
 }
Ejemplo n.º 12
0
 internal static CommandLineArgument ToCommandLineArgument(this ICommandLineArgument commandLineArgument)
 {
     return((CommandLineArgument)commandLineArgument);
 }
Ejemplo n.º 13
0
 public static void PrintArgument(List<string> lines, ICommandLineArgument arg)
 {
     PrintArgument(lines, arg, " ");
 }
Ejemplo n.º 14
0
    /// <summary>
    /// Starts an application in a separate AppDomain.
    /// Loads all enabled plugins and starts the application via an ApplicationManager instance activated in the new AppDomain.
    /// </summary>
    /// <param name="appInfo">application to run</param>
    public void Run(ApplicationDescription appInfo, ICommandLineArgument[] args) {
      if (!initialized) throw new InvalidOperationException("PluginManager is not initialized. DiscoverAndCheckPlugins() must be called before Run()");
      // create a separate AppDomain for the application
      // initialize the static ApplicationManager in the AppDomain
      // and remotely tell it to start the application

      OnApplicationStarting(new PluginInfrastructureEventArgs(appInfo));
      AppDomain applicationDomain = null;
      try {
        AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
        setup.PrivateBinPath = pluginDir;
        applicationDomain = AppDomain.CreateDomain(AppDomain.CurrentDomain.FriendlyName, null, setup);
        Type applicationManagerType = typeof(DefaultApplicationManager);
        DefaultApplicationManager applicationManager =
          (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null);
        applicationManager.PluginLoaded += applicationManager_PluginLoaded;
        applicationManager.PluginUnloaded += applicationManager_PluginUnloaded;
        applicationManager.PrepareApplicationDomain(applications, plugins);
        OnApplicationStarted(new PluginInfrastructureEventArgs(appInfo));
        applicationManager.Run(appInfo, args);
      }
      finally {
        // make sure domain is unloaded in all cases
        AppDomain.Unload(applicationDomain);
      }
    }
Ejemplo n.º 15
0
 public static void PrintArgument(List <string> lines, ICommandLineArgument arg)
 {
     PrintArgument(lines, arg, " ");
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Creates new instance of <see cref="CommandLineGroupingBase"/>.
 /// <para>
 /// *See remarks for further details and correct implementation.
 /// </para>
 /// </summary>
 /// <param name="parentCallChain">The parent call-chain.</param>
 /// <param name="children">The associated children in relation to <paramref name="parentCallChain"/>.</param>
 /// <param name="description">A description of what this grouping represents or does within the scope of the application.</param>
 /// <exception cref="System.ArgumentNullException">
 /// Throws when <paramref name="parentCallChain"/> is null or contains not elements.
 /// </exception>
 /// <remarks>
 /// The <see cref="ICommandLineGrouping.ParentCallChain"/> property represents the full parent hierarchy chain.
 ///
 /// The <see cref="ICommandLineGrouping.Children"/> property represents associated child pairings.
 /// It is important to note this property is not an "all inclusive" listing", but rather an individual grouping.
 /// This means that if you have one "main argument", which has three "child arguments", then specifying a grouping
 /// with "main" and "childOne" would transpose to the command line as "$ main childOne".
 ///
 /// If you wanted to specify a grouping that states "main" must run with "childOne" and "childTwo", but leave "childThree" as optional,
 /// then you would create two groupings; one with "childOne" and "childTwo"; the other, with "childOne", "childTwo", and "childThree".
 /// </remarks>
 protected CommandLineGroupingBase(ICommandLineArgument parentCallChain, ICommandLineArgument[] children, string description = null)
     : this(new ICommandLineArgument[] { parentCallChain }, children, description)
 {
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Determines if the specified argument is present.
        /// </summary>
        /// <param name="rootArgument">The <see cref="ICommandLineArgument"/> to check.</param>
        /// <param name="options">The flags which dictate what determines an argument as found.</param>
        /// <param name="comparer">The comparer to use when determining if a match was found.</param>
        /// <param name="argumentsToParse">
        /// The collection to search.
        /// Specifying null will default to <see cref="Arguments"/>.
        /// </param>
        /// <returns>
        /// Returns true if the apecified argument was found using the supplied flags; otherwise, returns false.
        /// </returns>
        /// <exception cref="System.ArgumentException">
        /// Throws when an invalid flag combination is given.
        /// </exception>
        public static bool Found(this ICommandLineArgument rootArgument, CmdLineSearchOptions options, StringComparison?comparer = null, IEnumerable <string> argumentsToParse = null)
        {
            if (options.HasFlag(CmdLineSearchOptions.WithChildren | CmdLineSearchOptions.WithoutChildren))
            {
                throw new ArgumentException($"Invalid flag combination. {options}", nameof(options));
            }

            if (options.HasFlag(CmdLineSearchOptions.WithSiblings | CmdLineSearchOptions.WithoutSiblings))
            {
                throw new ArgumentException($"Invalid flag combination. {options}", nameof(options));
            }

            if (options.HasFlag(CmdLineSearchOptions.WithParams | CmdLineSearchOptions.WithoutParams))
            {
                throw new ArgumentException($"Invalid flag combination. {options}", nameof(options));
            }

            var segment = rootArgument.GetSegment(comparer, argumentsToParse);

            if (options == CmdLineSearchOptions.None)
            {
                return(segment.Any());
            }

            if (!segment.Any())
            {
                return(false);
            }

            if (options == CmdLineSearchOptions.WithChildren)
            {
                return(segment.Count() > 1);
            }

            if (options == CmdLineSearchOptions.WithoutChildren)
            {
                return(segment.Count() == 1);
            }

            if (options == CmdLineSearchOptions.WithParams)
            {
                return(segment.Any() && rootArgument.GetParams().Any());
            }

            if (options == CmdLineSearchOptions.WithoutParams)
            {
                return(segment.Any() && !rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithChildren | CmdLineSearchOptions.WithParams))
            {
                return(segment.Count() > 1 && rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithChildren | CmdLineSearchOptions.WithoutParams))
            {
                return(segment.Count() > 1 && !rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithoutChildren | CmdLineSearchOptions.WithParams))
            {
                return(segment.Count() == 1 && rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithoutChildren | CmdLineSearchOptions.WithoutParams))
            {
                return(segment.Count() == 1 && !rootArgument.GetParams().Any());
            }

            var hasSiblings = (argumentsToParse ?? Arguments).Any(str =>
                                                                  str.StartsWith(rootArgument.Specification.Delimiter) && !rootArgument.Command.Equals(str, (comparer ?? Comparer)));

            if (options == CmdLineSearchOptions.WithSiblings)
            {
                return(segment.Any() && hasSiblings);
            }

            if (options == CmdLineSearchOptions.WithoutSiblings)
            {
                return(segment.Any() && !hasSiblings);
            }

            if (options == (CmdLineSearchOptions.WithoutChildren | CmdLineSearchOptions.WithoutSiblings))
            {
                return(segment.Count() == 1 && !hasSiblings);
            }

            if (options == (CmdLineSearchOptions.WithChildren | CmdLineSearchOptions.WithoutSiblings))
            {
                return(segment.Count() > 1 && !hasSiblings);
            }

            if (options == (CmdLineSearchOptions.WithoutChildren | CmdLineSearchOptions.WithSiblings))
            {
                return(segment.Count() == 1 && hasSiblings);
            }

            if (options == (CmdLineSearchOptions.WithChildren | CmdLineSearchOptions.WithSiblings))
            {
                return(segment.Count() > 1 && hasSiblings);
            }

            if (options == (CmdLineSearchOptions.WithoutChildren | CmdLineSearchOptions.WithoutSiblings | CmdLineSearchOptions.WithoutParams))
            {
                return(segment.Count() == 1 && !hasSiblings && !rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithChildren | CmdLineSearchOptions.WithoutSiblings | CmdLineSearchOptions.WithoutParams))
            {
                return(segment.Count() > 1 && !hasSiblings && !rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithoutChildren | CmdLineSearchOptions.WithSiblings | CmdLineSearchOptions.WithoutParams))
            {
                return(segment.Count() == 1 && hasSiblings && !rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithChildren | CmdLineSearchOptions.WithSiblings | CmdLineSearchOptions.WithoutParams))
            {
                return(segment.Count() > 1 && hasSiblings && !rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithoutChildren | CmdLineSearchOptions.WithoutSiblings | CmdLineSearchOptions.WithParams))
            {
                return(segment.Count() == 1 && !hasSiblings && rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithChildren | CmdLineSearchOptions.WithoutSiblings | CmdLineSearchOptions.WithParams))
            {
                return(segment.Count() > 1 && !hasSiblings && rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithoutChildren | CmdLineSearchOptions.WithSiblings | CmdLineSearchOptions.WithParams))
            {
                return(segment.Count() == 1 && hasSiblings && rootArgument.GetParams().Any());
            }

            if (options == (CmdLineSearchOptions.WithChildren | CmdLineSearchOptions.WithSiblings | CmdLineSearchOptions.WithParams))
            {
                return(segment.Count() > 1 && hasSiblings && rootArgument.GetParams().Any());
            }

            throw new ArgumentException("Could not find a search match pattern using the supplied search options.", nameof(options));
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Returns all parameters associated with the specified <see cref="ICommandLineArgument"/>.
 /// </summary>
 /// <param name="argument">The argument to retrieve the parameters of.</param>
 /// <param name="comparer">The comparer to use when determining if a match was found.</param>
 /// <param name="argumentsToParse">
 /// The collection to search.
 /// Specifying null will default to <see cref="Arguments"/>.
 /// </param>
 /// <returns>
 /// Searches <paramref name="argumentsToParse"/> for <paramref name="argument"/>.
 /// Once found, proceeding values are returned until a value begins with a known <see cref="ICommandLineSpecification.Delimiter"/>.
 ///
 /// If <paramref name="argument"/> is not found, or no parameters are found, an empty collection is returned.
 /// </returns>
 public static IEnumerable <string> GetParams(this ICommandLineArgument argument, StringComparison?comparer = null, IEnumerable <string> argumentsToParse = null)
 => argument.GetSegment(comparer, argumentsToParse ?? Arguments)
 .Skip(1)
 .TakeWhile(arg => !CommandLineSetManager.KnownSpecifications.Any(ks => arg.StartsWith(ks.Delimiter)));