public static void Run(this IToolHost toolHost, string sourceFilePath) { HostConfiguration hostConfiguration; if ((object)toolHost == null) { throw new ArgumentNullException(nameof(toolHost)); } sourceFilePath = Path.GetFullPath(sourceFilePath); hostConfiguration = FromJsonFile <HostConfiguration>(sourceFilePath); toolHost.Configuration = hostConfiguration; toolHost.Create(); toolHost.Run(); }
public static async Task RunAsync(this IToolHost toolHost, string sourceFilePath, CancellationToken cancellationToken) { HostConfiguration hostConfiguration; if ((object)toolHost == null) { throw new ArgumentNullException(nameof(toolHost)); } sourceFilePath = Path.GetFullPath(sourceFilePath); hostConfiguration = FromJsonFile <HostConfiguration>(sourceFilePath); toolHost.Configuration = hostConfiguration; await toolHost.CreateAsync(cancellationToken); await toolHost.RunAsync(cancellationToken); }
protected override int OnStartup(string[] args, IDictionary <string, IList <object> > arguments) { Dictionary <string, object> argz; string sourceFilePath; IDictionary <string, IList <string> > properties; IList <object> argumentValues; IList <string> propertyValues; bool hasProperties; if ((object)args == null) { throw new ArgumentNullException(nameof(args)); } if ((object)arguments == null) { throw new ArgumentNullException(nameof(arguments)); } // required properties = new Dictionary <string, IList <string> >(); sourceFilePath = (string)arguments[CMDLN_TOKEN_SOURCEFILE].Single(); hasProperties = arguments.TryGetValue(CMDLN_TOKEN_PROPERTY, out argumentValues); argz = new Dictionary <string, object>(); argz.Add(CMDLN_TOKEN_SOURCEFILE, sourceFilePath); argz.Add(CMDLN_TOKEN_PROPERTY, hasProperties ? (object)argumentValues : null); if (hasProperties) { if ((object)argumentValues != null) { foreach (string argumentValue in argumentValues) { string key, value; if (!this.TryParseCommandLineArgumentProperty(argumentValue, out key, out value)) { continue; } if (!properties.ContainsKey(key)) { properties.Add(key, propertyValues = new List <string>()); } else { propertyValues = properties[key]; } // duplicate values are ignored if (propertyValues.Contains(value)) { continue; } propertyValues.Add(value); } } } using (IToolHost toolHost = AssemblyDomain.Default.DependencyManager.ResolveDependency <IToolHost>(string.Empty, true)) { toolHost.Run(sourceFilePath); } return(0); }