public GetPerforceChanges() { this.commandLineParser = new CommandLineParser(); this.processWrapper = new ProcessWrapper(); this.changesParser = new ChangesParser(); this.cmdlet = new CmdletAdapter(this); }
public static string GetConfigurationDataFilePath(ICmdlet cmdlet) { var f = Environment.GetEnvironmentVariable("APPDATA"); if (f == null) { throw new MissingEnvironmentVariableException("APPDATA"); } f = Path.Combine(f, "AzurePowerShellTools"); if (!Directory.Exists(f)) { Logger.WriteVerbose(cmdlet, "Data directory '{0}' not found; creating.", f); Directory.CreateDirectory(f); } f = Path.Combine(f, "config.json"); if (!File.Exists(f)) { Logger.WriteVerbose(cmdlet, "Data file '{0}' not found; creating.", f); WriteConfigurationData(f, new Config(), cmdlet); } return(f); }
private bool Processing(string arguments) { foreach (KeyValuePair <string, string> kvp in commands) { if (new Regex(kvp.Key, RegexOptions.IgnoreCase).IsMatch(arguments)) { try { Type t = Type.GetType(kvp.Value); ICmdlet x = (ICmdlet)Activator.CreateInstance(t, new object[] { this }); return(x.run(arguments) == 0); } catch (Exception ex) { Console.WriteLine("Got an Error: {0}", ex.Message); if (ex.GetType() == typeof(NullReferenceException)) { Console.WriteLine("Did you authentificate?"); } return(false); } } } Console.WriteLine("{0}: Command not found", arguments); return(false); }
public static string GetConfigurationDataFilePath(ICmdlet cmdlet) { var f = Environment.GetEnvironmentVariable("APPDATA"); if (f == null) throw new MissingEnvironmentVariableException("APPDATA"); f = Path.Combine(f, "AzurePowerShellTools"); if (!Directory.Exists(f)) { Logger.WriteVerbose(cmdlet, "Data directory '{0}' not found; creating.", f); Directory.CreateDirectory(f); } f = Path.Combine(f, "config.json"); if (!File.Exists(f)) { Logger.WriteVerbose(cmdlet, "Data file '{0}' not found; creating.", f); WriteConfigurationData(f, new Config(), cmdlet); } return f; }
public void InjectDependencies(ICmdlet cmdlet, IProcessWrapper processWrapper, ICommandLineParser commandLineParser, ILogger logger) { this.cmdLet = cmdlet; this.processWrapper = processWrapper; this.commandLineParser = commandLineParser; this.logger = logger; }
public StartProcessSync() { this.cmdLet = new CmdletAdapter(this); this.processWrapper = new ProcessWrapper(); this.commandLineParser = new CommandLineParser(); this.logger = new RawConsoleLogger(); }
public GetGitLog() { this.commandLineParser = new CommandLineParser(); this.processWrapper = new ProcessWrapper(); this.gitLogParser = new GitLogParser(); this.cmdlet = new CmdletAdapter(this); }
public void InjectDependencies(ICommandLineParser commandLineParser, IProcessWrapper processWrapper, IGitLogParser gitLogParser, ICmdlet cmdlet) { this.commandLineParser = commandLineParser; this.processWrapper = processWrapper; this.gitLogParser = gitLogParser; this.cmdlet = cmdlet; }
public void InjectDependencies(IDescribeParser describeParser, IProcessWrapper processWrapper, ICommandLineParser commandLineParser, ICmdlet cmdlet) { this.processWrapper = processWrapper; this.describeParser = describeParser; this.commandLineParser = commandLineParser; this.cmdlet = cmdlet; }
public GetPerforceChangeset() { this.processWrapper = new ProcessWrapper(); this.describeParser = new DescribeParser(); this.commandLineParser = new CommandLineParser(); this.cmdlet = new CmdletAdapter(this); this.DescribeCommand = "p4 describe -ds {0}"; }
public void InjectDependencies(ICommandLineParser commandLineParser, IProcessWrapper processWrapper, IChangesParser changesParser, ICmdlet cmdlet) { this.commandLineParser = commandLineParser; this.processWrapper = processWrapper; this.changesParser = changesParser; this.cmdlet = cmdlet; }
public ProgressReporter(ICmdlet cmdlet, bool withProgressBar) { this._steps = 0; this._completedSteps = 0; this._lastCompletePercentage = 0; this._cmdlet = cmdlet; this._withProgressBar = withProgressBar; this._timer = Stopwatch.StartNew(); }
private static void WriteConfigurationData(string pathToFile, Config config, ICmdlet cmdlet) { using (var fs = File.Open(pathToFile, FileMode.Create)) { using (var sw = new StreamWriter(fs)) { var json = JsonConvert.SerializeObject(config); sw.Write(json); } } }
public void Help() { foreach (KeyValuePair <string, string> kvp in commands) { Console.Write("{0} - ", kvp.Key); Type t = Type.GetType(kvp.Value); ICmdlet x = (ICmdlet)Activator.CreateInstance(t, new object[] { this }); x.PrintHelp(); } Console.WriteLine("help - Print out this text"); }
private static Config ReadConfigurationData(string pathToFile, ICmdlet cmdlet) { using (var fs = File.Open(pathToFile, FileMode.Open)) { using (var sr = new StreamReader(fs)) { var json = sr.ReadToEnd(); var config = JsonConvert.DeserializeObject<Config>(json); return config; } } }
private static Config ReadConfigurationData(string pathToFile, ICmdlet cmdlet) { using (var fs = File.Open(pathToFile, FileMode.Open)) { using (var sr = new StreamReader(fs)) { var json = sr.ReadToEnd(); var config = JsonConvert.DeserializeObject <Config>(json); return(config); } } }
public static void WriteVerbose(ICmdlet cmdlet, string message, params object[] args) { if (cmdlet != null) { if (args.Length == 0) { cmdlet.WriteVerbose(message); } else { cmdlet.WriteVerbose(string.Format(message, args)); } } }
/// <summary> /// Note: the function must be called in the main PowerShell thread. /// </summary> /// <param name="cmdlet"></param> /// <param name="createAndStartTask"></param> public static void CmdletStartAndWait( this ICmdlet cmdlet, Func <IAsyncCmdlet, Task> createAndStartTask) { var asyncCmdlet = new AsyncCmdlet(cmdlet); string previousX = null; string previousOperation = null; asyncCmdlet.Scheduler.Wait( createAndStartTask(asyncCmdlet), () => { if (asyncCmdlet.TaskProgressList.Any()) { var progress = 0.0; var activeTasks = new List <string>(); foreach (var taskProgress in asyncCmdlet.TaskProgressList) { if (!taskProgress.IsDone) { var config = taskProgress.Config; activeTasks.Add(config.GetFullName()); } progress += taskProgress.GetProgress(); } var percent = (int)(progress * 100.0); var r = new[] { "|", "/", "-", "\\" }; var x = r[DateTime.Now.Second % 4]; var operation = activeTasks.Count > 0 ? "Creating " + string.Join(", ", activeTasks) + "." : null; // write progress only if it's changed. if (x != previousX || operation != previousOperation) { asyncCmdlet.Cmdlet.WriteProgress( activity: "Creating Azure resources", statusDescription: percent + "% " + x, currentOperation: operation, percentComplete: percent); previousX = x; previousOperation = operation; } } }); }
public NamespaceScanProgressReporter(ICmdlet cmdlet) : base(cmdlet, withProgressBar: true) { }
public static void WriteConfigurationData(Config config, ICmdlet cmdlet) { WriteConfigurationData(GetConfigurationDataFilePath(cmdlet), config, cmdlet); }
public static Config ReadConfigurationData(ICmdlet cmdlet) { return(ReadConfigurationData(GetConfigurationDataFilePath(cmdlet), cmdlet)); }
public AsyncCmdlet(ICmdlet cmdlet) { Cmdlet = cmdlet; }
public PsObjectsOutputWriter(ICmdlet cmdlet) { this._cmdlet = cmdlet; }
public static string GetAzureConnectionString(ICmdlet cmdlet) { var config = ReadConfigurationData(cmdlet); return config.AzureConnectionString; }
public SystemCheckProgressReporter(ICmdlet cmdlet) : base(cmdlet, withProgressBar: true) { }
public NamespaceEstimationProgressReporter(ICmdlet cmdlet) : base(cmdlet, withProgressBar: false) { }
private INamespaceInfo StorageEval(IList <INamespaceValidation> validations, IProgressReporter progressReporter, ICmdlet cmdlet, TextSummaryOutputWriter summaryWriter, PsObjectsOutputWriter psObjectsWriter) { IDirectoryInfo root = new AfsDirectoryInfo(this.Path); var outputWriters = new List <IOutputWriter> { psObjectsWriter, summaryWriter }; NamespaceValidationsProcessor validationsProcessor = new NamespaceValidationsProcessor(validations, outputWriters, progressReporter); List <INamespaceEnumeratorListener> namespaceEnumeratorListeners = new List <INamespaceEnumeratorListener> { validationsProcessor, }; NamespaceEnumerator namespaceEnumerator = new NamespaceEnumerator(namespaceEnumeratorListeners); var namespaceInfo = namespaceEnumerator.Run(root); return(namespaceInfo); }
public static string GetAzureConnectionString(ICmdlet cmdlet) { var config = ReadConfigurationData(cmdlet); return(config.AzureConnectionString); }
public static Config ReadConfigurationData(ICmdlet cmdlet) { return ReadConfigurationData(GetConfigurationDataFilePath(cmdlet), cmdlet); }
/// <summary> /// Storages the eval. /// </summary> /// <param name="validations">The validations.</param> /// <param name="progressReporter">The progress reporter.</param> /// <param name="cmdlet">The cmdlet.</param> /// <param name="outputWriters">The output writers.</param> /// <returns>INamespaceInfo.</returns> private INamespaceInfo StorageEval(IList <INamespaceValidation> validations, IProgressReporter progressReporter, ICmdlet cmdlet, IList <IOutputWriter> outputWriters) { IDirectoryInfo root = new AfsDirectoryInfo(Path); NamespaceValidationsProcessor validationsProcessor = new NamespaceValidationsProcessor(validations, outputWriters, progressReporter); List <INamespaceEnumeratorListener> namespaceEnumeratorListeners = new List <INamespaceEnumeratorListener> { validationsProcessor, }; NamespaceEnumerator namespaceEnumerator = new NamespaceEnumerator(namespaceEnumeratorListeners); var namespaceInfo = namespaceEnumerator.Run(root); return(namespaceInfo); }
private void PerformSystemChecks(IList <ISystemValidation> validations, IProgressReporter progressReporter, ICmdlet cmdlet, TextSummaryOutputWriter summaryWriter, PsObjectsOutputWriter psObjectsWriter) { PowerShellCommandRunner commandRunner = null; try { commandRunner = new PowerShellCommandRunner(this.ComputerNameValue.Value, this.Credential); } catch { this.WriteWarning( $"Establishing management service connection with host '{this.ComputerNameValue.Value}' as {this.UserName} didn't work." + Environment.NewLine + $"Ensure {this.UserName} has administrative rights and that the process is running with administrative permissions." + Environment.NewLine + $"You can also use -SkipSystemChecks switch to skip system requirements checks."); throw; } var outputWriters = new List <IOutputWriter> { summaryWriter, psObjectsWriter }; SystemValidationsProcessor systemChecksProcessor = new SystemValidationsProcessor(commandRunner, validations, outputWriters, progressReporter); systemChecksProcessor.Run(); }