Ejemplo n.º 1
0
 public StartProcessSync()
 {
     this.cmdLet            = new CmdletAdapter(this);
     this.processWrapper    = new ProcessWrapper();
     this.commandLineParser = new CommandLineParser();
     this.logger            = new RawConsoleLogger();
 }
 protected override void Given()
 {
     processWrapper = Substitute.For<IProcessWrapper>();
     processWrapper.ProcessTreeCPUUsageId.Returns(info => {throw new InvalidOperationException("process is gone");});
     task = new OSExecuatableTask("fle", "flo", "name",
                         (s, s1, arg3) => processWrapper, periodLengthMs: 1000, quotaNrPeriods: 3);
 }
Ejemplo n.º 3
0
        public override IProcessWrapper CreateProcess(string fileName, string workingDirectory, string arguments)
        {
            var processWrapper = _processWrapper;

            _processWrapper = null;
            return(processWrapper);
        }
Ejemplo n.º 4
0
 public GetGitLog()
 {
     this.commandLineParser = new CommandLineParser();
     this.processWrapper    = new ProcessWrapper();
     this.gitLogParser      = new GitLogParser();
     this.cmdlet            = new CmdletAdapter(this);
 }
 protected override void Given()
 {
     processWrapper = Substitute.For<IProcessWrapper>();
     processWrapper.ProcessTreeCPUUsageId.Returns("");
     task = new OSExecuatableTask("fle", "flo", "name",
                         (s, s1, arg3) => processWrapper, periodLengthMs: 1000, quotaNrPeriods: 10);
 }
Ejemplo n.º 6
0
        public string Start <T>(string username) where T : IProcessWrapper
        {
            var x = typeof(T);

            Process           = Activator.CreateInstance <T>();
            Process.StartInfo = new ProcessStartInfo()
            {
                WorkingDirectory       = Properties.Settings.Default.SeleniumPath,
                Arguments              = CurrentArgs,
                FileName               = CurrentFileName,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true
            };
            Process.EnableRaisingEvents = true;

            if (username != null)
            {
                var cm = CredentialStore.GetCredential(username);
                Process.StartInfo.Domain   = cm.Username.Split('\\')[0];
                Process.StartInfo.UserName = cm.Username.Split('\\')[1];
                var pass = cm.Password;
                Console.WriteLine(pass);
                Process.StartInfo.Password = cm.SecurePassword;
            }

            Process.Start();
            Process.BeginOutputReadLine();
            Process.BeginErrorReadLine();

            var proc = new Process();

            return(Process.GetProcessUser());
        }
Ejemplo n.º 7
0
        private void CreateProccess(IProcessProxy processProxy, string binaryPath, string arguments)
        {
            var processStartInfo = new ProcessStartInfo
            {
                FileName               = binaryPath,
                Arguments              = arguments,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                CreateNoWindow         = true
            };

            try
            {
                this.process = processProxy.Start(processStartInfo);

                if (this.process != null)
                {
                    this.process.OutputDataReceived += this.ProcessOutputDataReceived;
                    this.process.BeginOutputReadLine();
                }
                else
                {
                    throw new NullReferenceException("IProcessProxy produced null object");
                }
            }
            catch (Exception ex)
            {
                throw new AggregateException(string.Format("Failed to run process '{0}' with arguments '{1}'", binaryPath, arguments), new[] { ex });
            }
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        public IEnumerable <IPAddress> GetRespondingMachines()
        {
            var arpScanResults = new List <IPAddress>();

            using (IProcessWrapper arpScanProcess = getArpScanProc())
            {
                arpScanProcess.Start();

                string procOut = "";
                while ((procOut = arpScanProcess.StandardOuput.ReadLine()) != null)
                {
                    string[] parts = procOut.Trim().Split(' ');

                    if (parts.Length < 2 || parts[parts.Length - 1] == "invalid")
                    {
                        continue;
                    } // end if

                    string    address = parts[0];
                    IPAddress ipAddress;
                    if (IPAddress.TryParse(address, out ipAddress))
                    {
                        arpScanResults.Add(ipAddress);
                    } // end if
                }     // end while

                arpScanProcess.WaitForExit();
            } // end using

            return(arpScanResults);
        } // end method
Ejemplo n.º 9
0
 public GetPerforceChanges()
 {
     this.commandLineParser = new CommandLineParser();
     this.processWrapper    = new ProcessWrapper();
     this.changesParser     = new ChangesParser();
     this.cmdlet            = new CmdletAdapter(this);
 }
Ejemplo n.º 10
0
 public void InjectDependencies(ICmdlet cmdlet, IProcessWrapper processWrapper, ICommandLineParser commandLineParser, ILogger logger)
 {
     this.cmdLet            = cmdlet;
     this.processWrapper    = processWrapper;
     this.commandLineParser = commandLineParser;
     this.logger            = logger;
 }
Ejemplo n.º 11
0
 public void InjectDependencies(IDescribeParser describeParser, IProcessWrapper processWrapper, ICommandLineParser commandLineParser,
                                ICmdlet cmdlet)
 {
     this.processWrapper    = processWrapper;
     this.describeParser    = describeParser;
     this.commandLineParser = commandLineParser;
     this.cmdlet            = cmdlet;
 }
Ejemplo n.º 12
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}";
 }
Ejemplo n.º 13
0
 public void InjectDependencies(ICommandLineParser commandLineParser, IProcessWrapper processWrapper,
                                IChangesParser changesParser, ICmdlet cmdlet)
 {
     this.commandLineParser = commandLineParser;
     this.processWrapper    = processWrapper;
     this.changesParser     = changesParser;
     this.cmdlet            = cmdlet;
 }
Ejemplo n.º 14
0
 public void InjectDependencies(ICommandLineParser commandLineParser, IProcessWrapper processWrapper,
                                IGitLogParser gitLogParser, ICmdlet cmdlet)
 {
     this.commandLineParser = commandLineParser;
     this.processWrapper    = processWrapper;
     this.gitLogParser      = gitLogParser;
     this.cmdlet            = cmdlet;
 }
Ejemplo n.º 15
0
 public AudioNormalizerService(
     ISettingsManager settingsManager,
     IProcessWrapper processWrapper,
     IStorageWrapper storageWrapper)
 {
     _userSettings   = settingsManager.LoadSettings();
     _processWrapper = processWrapper;
     _storageWrapper = storageWrapper;
 }
Ejemplo n.º 16
0
 public ProcessRunner(
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISystemOperations systemOperations,
     IProcessWrapper processWrapper = null)
     : base(vmConfiguration, logger, systemOperations)
 {
     _processWrapper = processWrapper;
 }
Ejemplo n.º 17
0
 public async Task TypicalRun_FactoryResultIsRunAndReturned(
     int ret,
     [Frozen] ProcessStartInfo startInfo,
     IProcessWrapper process,
     CancellationToken cancel,
     ProcessRunner sut)
 {
     process.Run().Returns(Task.FromResult(ret));
     sut.Factory.Create(default !).ReturnsForAnyArgs(process);
Ejemplo n.º 18
0
        public void Init()
        {
            _process = A.Fake<IProcessWrapper>();
            _processManager = A.Fake<IProcessManager>();
            A.CallTo(() => _processManager.GetProcess(Executable, Parameters)).Returns(_process);
            A.CallTo(() => _process.Start()).Invokes(x => InitStartInternalUpdates()).Returns(true);

            _command = new Command(_processManager, Name, Executable, Parameters, KillChildren);
        }
Ejemplo n.º 19
0
        public GitCodeChurnProcessor(ICommandLineParser commandLineParser, IProcessWrapper processWrapper, IGitLogParser gitLogParser, IOutputProcessor outputProcessor, IBugDatabaseProcessor bugDatabaseProcessor, ILogger logger, GitExtractCommandLineArgs commandLineArgs) : this(commandLineParser, processWrapper, gitLogParser, outputProcessor, bugDatabaseProcessor, logger, commandLineArgs.OutputFile, commandLineArgs.OutputType, commandLineArgs.BugRegexes, commandLineArgs.BugDatabaseDLL, commandLineArgs.BugDatabaseOutputFile, commandLineArgs.BugDatabaseDllArgs, commandLineArgs.GitLogCommand)
        {
            if (string.IsNullOrWhiteSpace(bugDatabaseDLL) == false && string.IsNullOrWhiteSpace(bugDatabaseOutputFile))
            {
                throw new Exception("Dll specified without known output file");
            }

            this.bugDatabaseOutputFile = commandLineArgs.BugDatabaseOutputFile;
            this.bugDatabaseOutputType = commandLineArgs.BugDatabaseOutputType;
        }
        public PerforceCodeChurnProcessor(IProcessWrapper processWrapper, IChangesParser changesParser, IDescribeParser describeParser, ICommandLineParser commandLineParser, IBugDatabaseProcessor bugDatabaseProcessor, ILogger logger, IStopWatch stopWatch, IOutputProcessor outputProcessor, P4ExtractCommandLineArgs args) : this(processWrapper, changesParser, describeParser, commandLineParser, bugDatabaseProcessor, logger, stopWatch, outputProcessor, args.OutputFile, args.OutputType, args.BugDatabaseDLL, args.BugDatabaseOutputFile, args.BugDatabaseDllArgs, args.P4ChangesCommandLine, args.P4DescribeCommandLine, args.BugRegexes)
        {
            if (string.IsNullOrWhiteSpace(bugDatabaseDLL) == false && string.IsNullOrWhiteSpace(bugDatabaseOutputFile))
            {
                throw new Exception("Dll specified without known output file");
            }

            this.bugDatabaseOutputFile = args.BugDatabaseOutputFile;
            this.bugDatabaseOutputType = args.BugDatabaseOutputType;
        }
Ejemplo n.º 21
0
 public WslWrapperService(
     [NotNull] IChain <IProcessWrapper> processChain,
     [NotNull] IChain <IEnvironment> envChain,
     [NotNull] IVirtualEnvironment virtualEnvironment,
     [NotNull, Tag(WslScriptWrapper)] IProcessWrapper wslProcessWrapper)
 {
     _processChain       = processChain ?? throw new ArgumentNullException(nameof(processChain));
     _envChain           = envChain ?? throw new ArgumentNullException(nameof(envChain));
     _virtualEnvironment = virtualEnvironment ?? throw new ArgumentNullException(nameof(virtualEnvironment));
     _wslProcessWrapper  = wslProcessWrapper;
 }
Ejemplo n.º 22
0
 public ProcessRunner(
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISystemOperations systemOperations,
     IProcessWrapper processWrapper = null)
 {
     _logger           = logger;
     _vmConfiguration  = vmConfiguration;
     _systemOperations = systemOperations;
     _processWrapper   = processWrapper;
 }
Ejemplo n.º 23
0
 public void KillProcess(IProcessWrapper process, bool killChildren)
 {
     if (killChildren)
     {
         KillChildren((uint)process.Id);
     }
     else
     {
         process.Kill();
     }
 }
Ejemplo n.º 24
0
        public void ProcessWrapperFactory_GetNewProcessWrapper_Returns_New_Instance_Of_ProcessWrapper()
        {
            // Arrange
            var sut = new ProcessWrapperFactory();

            // Act
            IProcessWrapper processWrapper = sut.GetNewProcessWrapper();

            // Assert
            Assert.IsNotNull(processWrapper);
            Assert.IsInstanceOfType(processWrapper, typeof(ProcessWrapper));
        }
        void GivenTheAppWasRunWithNoArguments()
        {
            _installedVersion = new Version(1, 0);
            _builder          = new AppUpdaterBuilder(TestConstants.AppPackageId)
                                .SetupWithTestValues(_installedVersion);

            _commandLineWrapper = _builder.GetSubsituteCommandLineWrapper();
            _processWrapper     = _builder.GetSubsituteProcessWrapper();

            _commandLineWrapper.Full.Returns(@"\.myapp.exe");
            _commandLineWrapper.Arguments.Returns(new[] { @"\.myapp.exe" });
        }
        void GivenTheAppWasRunWithArgumentsThatDoNotContainSpaces()
        {
            _installedVersion = new Version(1, 0);
            _builder = new AppUpdaterBuilder(TestConstants.AppPackageId)
                .SetupWithTestValues(_installedVersion);

            _commandLineWrapper = _builder.GetSubsituteCommandLineWrapper();
            _processWrapper = _builder.GetSubsituteProcessWrapper();

            _commandLineWrapper.Full.Returns(@".\myapp.exe -v1 -updatemode autoupdate");
            _commandLineWrapper.Arguments.Returns(new[] { @".\myapp.exe", "-v1", "-updatemode", "autoupdate" });
        }
Ejemplo n.º 27
0
        void GivenTheAppWasRunWithArgumentsThatDoNotContainSpaces()
        {
            _installedVersion = new Version(1, 0);
            _builder          = new AppUpdaterBuilder(TestConstants.AppPackageId)
                                .SetupWithTestValues(_installedVersion);

            _commandLineWrapper = _builder.GetSubsituteCommandLineWrapper();
            _processWrapper     = _builder.GetSubsituteProcessWrapper();

            _commandLineWrapper.Full.Returns(@".\myapp.exe -v1 -updatemode autoupdate");
            _commandLineWrapper.Arguments.Returns(new[] { @".\myapp.exe", "-v1", "-updatemode", "autoupdate" });
        }
Ejemplo n.º 28
0
        public ServerLogic(IOptionsSnapshot <ServerOptions> serverOptions, IProcessWrapper processLogic, IIPWrapper ipLogic, ILogger <ServerLogic> logger)
        {
            if (serverOptions.Value.Servers == null)
            {
                throw new Exception("server config is null!");
            }
            _servers = serverOptions.Value.Servers;

            _processLogic = processLogic;
            _ipLogic      = ipLogic;
            _logger       = logger;
        }
Ejemplo n.º 29
0
        public AppUpdater(NuGetConfig nugetConfig, IAppVersionProvider appVersionProvider, IExtendedFileSystem fileSystem, ICommandLineWrapper commandLineWrapper, IProcessWrapper processWrapper)
        {
            _appVersionProvider       = appVersionProvider;
            _fileSystem               = fileSystem;
            _commandLineWrapper       = commandLineWrapper;
            _processWrapper           = processWrapper;
            _packageSource            = nugetConfig.PackageSource;
            _appPackageId             = nugetConfig.AppPackageId;
            _packageRepositoryFactory = nugetConfig.RepositoryFactory;

            _oldVersionDir = Path.Combine(_fileSystem.AppDirectory, ".old");
        }
Ejemplo n.º 30
0
        void GivenTheAppWasRunWithAPathThatContainsSpacesAndArgumentsThatDoContainSpaces()
        {
            _installedVersion = new SemanticVersion(new Version(1, 0));
            _builder          = new AppUpdaterBuilder(TestConstants.AppPackageId)
                                .SetupWithTestValues(_installedVersion);

            _commandLineWrapper = _builder.GetSubsituteCommandLineWrapper();
            _processWrapper     = _builder.GetSubsituteProcessWrapper();

            _commandLineWrapper.Full.Returns("\"C:\\Program Files\\myapp.exe\" -v1 -updatemode \"auto update\"");
            _commandLineWrapper.Arguments.Returns(new[] { "C:\\Program Files\\myapp.exe", "-v1", "-updatemode", "auto update" });
        }
        void GivenTheAppWasRunWithNoArguments()
        {
            _installedVersion = new Version(1, 0);
            _builder = new AppUpdaterBuilder(TestConstants.AppPackageId)
                .SetupWithTestValues(_installedVersion);

            _commandLineWrapper = _builder.GetSubsituteCommandLineWrapper();
            _processWrapper = _builder.GetSubsituteProcessWrapper();

            _commandLineWrapper.Full.Returns(@"\.myapp.exe");
            _commandLineWrapper.Arguments.Returns(new[] { @"\.myapp.exe" });
        }
        void GivenTheAppWasRunWithAPathThatContainsSpacesAndArgumentsThatDoContainSpaces()
        {
            _installedVersion = new Version(1, 0);
            _builder = new AppUpdaterBuilder(TestConstants.AppPackageId)
                .SetupWithTestValues(_installedVersion);

            _commandLineWrapper = _builder.GetSubsituteCommandLineWrapper();
            _processWrapper = _builder.GetSubsituteProcessWrapper();

            _commandLineWrapper.Full.Returns("\"C:\\Program Files\\myapp.exe\" -v1 -updatemode \"auto update\"");
            _commandLineWrapper.Arguments.Returns(new[] { "C:\\Program Files\\myapp.exe", "-v1", "-updatemode", "auto update" });
        }
Ejemplo n.º 33
0
        public AppUpdater(NuGetConfig nugetConfig, IAppVersionProvider appVersionProvider, IExtendedFileSystem fileSystem, ICommandLineWrapper commandLineWrapper, IProcessWrapper processWrapper)
        {
            _appVersionProvider = appVersionProvider;
            _fileSystem = fileSystem;
            _commandLineWrapper = commandLineWrapper;
            _processWrapper = processWrapper;
            _packageSource = nugetConfig.PackageSource;
            _appPackageId = nugetConfig.AppPackageId;
            _packageRepositoryFactory = nugetConfig.RepositoryFactory;

            _oldVersionDir = Path.Combine(_fileSystem.AppDirectory, ".old");
        }
Ejemplo n.º 34
0
        private void HandleTimeout(IProcessWrapper process)
        {
            Defaults.Logger.WriteDebugMessage("TIMEOUT!");
            process.Kill();
            Thread.Sleep(1000); //wait one second so that the process has time to exit

            if (OnError == OnError.Fail)
            {
                //exit code should only be set if we want the application to fail on error
                BuildFile.SetErrorState(); //set our ExitCode to non-zero so consumers know we errored
            }
        }
Ejemplo n.º 35
0
        public void ProcessWrapperFactory_GetNewProcessWrapper_Returns_Unique_Instance_Of_ProcessWrapper()
        {
            // Arrange
            var sut = new ProcessWrapperFactory();

            // Act
            IProcessWrapper processWrapper1 = sut.GetNewProcessWrapper();
            IProcessWrapper processWrapper2 = sut.GetNewProcessWrapper();

            // Assert
            Assert.IsNotNull(processWrapper1);
            Assert.IsNotNull(processWrapper2);
            Assert.AreNotSame(processWrapper1, processWrapper2);
        }
Ejemplo n.º 36
0
        public void ArpScanner_GetRespondingMachines_Starts_ArpScan_Process()
        {
            // Arrange
            IProcessWrapper mockProcessWrapper = GetMockProcessWrapper(new string[] { null });

            _processWrapperFactory.Stub(x => x.GetNewProcessWrapper()).Return(mockProcessWrapper);
            var sut = new ArpScanner(_processWrapperFactory);

            // Act
            sut.GetRespondingMachines();

            // Assert
            mockProcessWrapper.AssertWasCalled(x => x.Start(), options => options.Repeat.Once());
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Test runner - Test that GetRespondingMachines continues if ReadLine content is invalid.
        /// </summary>
        /// <param name="content">ReadLine content.</param>
        private void GetRespondingMachinesShouldContinueIfReadLineContentInvalid_TestRunner(string content)
        {
            // Arrange
            IProcessWrapper mockProcessWrapper = GetMockProcessWrapper(new string[] { content, null });

            _processWrapperFactory.Stub(x => x.GetNewProcessWrapper()).Return(mockProcessWrapper);
            var sut = new ArpScanner(_processWrapperFactory);

            // Act
            IEnumerable <IPAddress> scanResults = sut.GetRespondingMachines();

            // Assert
            Assert.IsFalse(scanResults.Any());
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Get a mocked process wrapper which will return the provided string when ReadLine is called on it.
        /// </summary>
        /// <param name="readLineContents">Read line content values.</param>
        /// <returns>Mocked process wrapper.</returns>
        private static IProcessWrapper GetMockProcessWrapper(string[] readLineContents)
        {
            IStreamReaderWrapper streamReaderWrapper = MockRepository.GenerateMock <IStreamReaderWrapper>();

            foreach (string content in readLineContents)
            {
                streamReaderWrapper.Stub(x => x.ReadLine()).Return(content).Repeat.Once();
            }

            IProcessWrapper mockProcessWrapper = MockRepository.GenerateMock <IProcessWrapper>();

            mockProcessWrapper.Stub(x => x.StandardOuput).Return(streamReaderWrapper);

            return(mockProcessWrapper);
        }
Ejemplo n.º 39
0
 public ProcessStream(IProcessWrapper process, StreamReader streamReader)
 {
     StreamReader = streamReader;
     this.process = process;
 }
Ejemplo n.º 40
0
        /// <summary>
        /// Kill the process and remove it from memory
        /// </summary>
        private void Clean()
        {
            if (_process == null) return;

            try
            {
                _process.Exited -= ProcessExited;
                if (_process.IsStarted)
                {
                    _manager.KillProcess(_process, _killChildren);
                }
                _process.Dispose();
                _process = null;

            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Command {0} can't be killed: {1}", _name, ex.Message), ex);
            }
        }
Ejemplo n.º 41
0
        public void Start()
        {
            if (Disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if (_process != null)
            {
                Clean();
            }

            _process = _manager.GetProcess(_executable, _parameters);
            _process.Exited += ProcessExited;
            try
            {
                _process.Start();
                Log.Debug("Started !");
            }
            catch (Exception e)
            {
                if (_process != null)
                {
                    _process.Dispose();
                    _process = null;
                }
                Log.Error(string.Format("Unable to start command {0}: {1}", this, e.Message), e);
            }
        }
Ejemplo n.º 42
0
 /// <summary>
 /// Control how the <see cref="AppUpdater"/> will launch the new process when using the
 /// LaunchInstalledUpdater feature.
 /// </summary>
 public AppUpdaterBuilder RelaunchAppWith(IProcessWrapper processWrapper)
 {
     _processWrapper = processWrapper;
     return this;
 }