コード例 #1
0
 public GetPerforceChanges()
 {
     this.commandLineParser = new CommandLineParser();
     this.processWrapper    = new ProcessWrapper();
     this.changesParser     = new ChangesParser();
     this.cmdlet            = new CmdletAdapter(this);
 }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: Shell.cs プロジェクト: cmllr/redundancy-cli
 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);
 }
コード例 #4
0
        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;
        }
コード例 #5
0
 public void InjectDependencies(ICmdlet cmdlet, IProcessWrapper processWrapper, ICommandLineParser commandLineParser, ILogger logger)
 {
     this.cmdLet            = cmdlet;
     this.processWrapper    = processWrapper;
     this.commandLineParser = commandLineParser;
     this.logger            = logger;
 }
コード例 #6
0
 public StartProcessSync()
 {
     this.cmdLet            = new CmdletAdapter(this);
     this.processWrapper    = new ProcessWrapper();
     this.commandLineParser = new CommandLineParser();
     this.logger            = new RawConsoleLogger();
 }
コード例 #7
0
 public GetGitLog()
 {
     this.commandLineParser = new CommandLineParser();
     this.processWrapper    = new ProcessWrapper();
     this.gitLogParser      = new GitLogParser();
     this.cmdlet            = new CmdletAdapter(this);
 }
コード例 #8
0
 public void InjectDependencies(ICommandLineParser commandLineParser, IProcessWrapper processWrapper,
                                IGitLogParser gitLogParser, ICmdlet cmdlet)
 {
     this.commandLineParser = commandLineParser;
     this.processWrapper    = processWrapper;
     this.gitLogParser      = gitLogParser;
     this.cmdlet            = cmdlet;
 }
コード例 #9
0
 public void InjectDependencies(IDescribeParser describeParser, IProcessWrapper processWrapper, ICommandLineParser commandLineParser,
                                ICmdlet cmdlet)
 {
     this.processWrapper    = processWrapper;
     this.describeParser    = describeParser;
     this.commandLineParser = commandLineParser;
     this.cmdlet            = cmdlet;
 }
コード例 #10
0
 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}";
 }
コード例 #11
0
 public void InjectDependencies(ICommandLineParser commandLineParser, IProcessWrapper processWrapper,
                                IChangesParser changesParser, ICmdlet cmdlet)
 {
     this.commandLineParser = commandLineParser;
     this.processWrapper    = processWrapper;
     this.changesParser     = changesParser;
     this.cmdlet            = cmdlet;
 }
コード例 #12
0
 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();
 }
コード例 #13
0
 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);
         }
     }
 }
コード例 #14
0
 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);
         }
     }
 }
コード例 #15
0
ファイル: Shell.cs プロジェクト: cmllr/redundancy-cli
 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");
 }
コード例 #16
0
        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;
                }
            }
        }
コード例 #17
0
        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);
                }
            }
        }
コード例 #18
0
 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));
         }
     }
 }
コード例 #19
0
 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));
         }
     }
 }
コード例 #20
0
        /// <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;
                    }
                }
            });
        }
コード例 #21
0
 public NamespaceScanProgressReporter(ICmdlet cmdlet) : base(cmdlet, withProgressBar: true)
 {
 }
コード例 #22
0
 public static void WriteConfigurationData(Config config, ICmdlet cmdlet)
 {
     WriteConfigurationData(GetConfigurationDataFilePath(cmdlet), config, cmdlet);
 }
コード例 #23
0
 public static Config ReadConfigurationData(ICmdlet cmdlet)
 {
     return(ReadConfigurationData(GetConfigurationDataFilePath(cmdlet), cmdlet));
 }
コード例 #24
0
 public AsyncCmdlet(ICmdlet cmdlet)
 {
     Cmdlet = cmdlet;
 }
コード例 #25
0
 public PsObjectsOutputWriter(ICmdlet cmdlet)
 {
     this._cmdlet = cmdlet;
 }
コード例 #26
0
        public static string GetAzureConnectionString(ICmdlet cmdlet)
        {
            var config = ReadConfigurationData(cmdlet);

            return config.AzureConnectionString;
        }
コード例 #27
0
 public SystemCheckProgressReporter(ICmdlet cmdlet) : base(cmdlet, withProgressBar: true)
 {
 }
コード例 #28
0
 public static void WriteConfigurationData(Config config, ICmdlet cmdlet)
 {
     WriteConfigurationData(GetConfigurationDataFilePath(cmdlet), config, cmdlet);
 }
コード例 #29
0
 public NamespaceEstimationProgressReporter(ICmdlet cmdlet) : base(cmdlet, withProgressBar: false)
 {
 }
コード例 #30
0
        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);
        }
コード例 #31
0
        public static string GetAzureConnectionString(ICmdlet cmdlet)
        {
            var config = ReadConfigurationData(cmdlet);

            return(config.AzureConnectionString);
        }
コード例 #32
0
 public static Config ReadConfigurationData(ICmdlet cmdlet)
 {
     return ReadConfigurationData(GetConfigurationDataFilePath(cmdlet), cmdlet);
 }
コード例 #33
0
        /// <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);
        }
コード例 #34
0
        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();
        }