Пример #1
0
        private static void CreateScript(string sqlpackage, DbConnectionStringBuilder connection, string dacpacFile, string profileFile, string outputFile)
        {
            const string argumentsMask = "/Action:Script /OverwriteFiles:True /Quiet:False /TargetConnectionString:\"{0}\" /SourceFile:{1} /Profile:{2} /OutputPath:{3}";
            var          arguments     = string.Format(argumentsMask, connection.ConnectionString, dacpacFile, profileFile, outputFile);

            ExternalProcessExecutor.Exec(sqlpackage, arguments);
        }
Пример #2
0
        private static void WaitForStop(Options options)
        {
            int exitCode = ExternalProcessExecutor.ExecAndGetExitCode(DefaultSettings.ServiceControl, options.GetArguments());

            if (exitCode == NotAcceptingCommandsExitCode)
            {
                Console.Error.WriteLine("Service is not accepting any commands right now, waiting before trying again");
                Thread.Sleep(TimeSpan.FromSeconds(5));
                WaitForStop(options);
            }
            else if (exitCode == 0)
            {
                Console.Error.WriteLine("Service is stopping, waiting before checking again");
                Thread.Sleep(TimeSpan.FromSeconds(5));
                WaitForStop(options);
            }
            else if (exitCode == NotStartedExitCode)
            {
                Console.WriteLine("Service successfully stopped");
            }
            else
            {
                ValidateExitCode(options, exitCode);
            }
        }
Пример #3
0
        private static void DeployScript(string sqlcmd, SqlConnectionStringBuilder connection, string scriptFile)
        {
            var arguments = SqlcmdArgumentsBuilder.Build(connection).RunScript(scriptFile);

            Console.WriteLine("Executing script {0}", scriptFile);
            ExternalProcessExecutor.Exec(sqlcmd, arguments);
        }
        public void ExternalProcessBrowser_With_ComException()
        {
            var mockedUrl = new Mock <Uri>("https://warewolf.io");

            mockedUrl.Setup(uri => uri.ToString()).Throws(new System.Runtime.InteropServices.COMException());
            var processExecutor = new ExternalProcessExecutor();

            processExecutor.OpenInBrowser(mockedUrl.Object);
        }
        public void ExternalProcessBrowser_With_ProcessTimout()
        {
            var mockedUrl = new Mock <Uri>("https://warewolf.io");

            mockedUrl.Setup(uri => uri.ToString()).Throws(new TimeoutException());
            var processExecutor = new ExternalProcessExecutor();

            processExecutor.OpenInBrowser(mockedUrl.Object);
        }
Пример #6
0
        private static void Run(Options options)
        {
            const string deployUrlMask = "https://{0}.scm.azurewebsites.net:443/msdeploy.axd?site={0}";
            const string argumentMask  = "-verb:sync -source:contentPath='{0}' -dest:contentPath='{1}',ComputerName='{4}',UserName='******',Password='******',AuthType='Basic'";
            var          deployUrl     = string.Format(deployUrlMask, options.Sitename);
            var          arguments     = string.Format(argumentMask, options.PackageDir, options.Sitename, options.Username, options.Password, deployUrl);

            Console.WriteLine("deploying to url {0} ({1})", deployUrl, options.Sitename);
            Console.WriteLine("from {0}", options.PackageDir);
            ExternalProcessExecutor.Exec(DefaultSettings.Msdeploy, arguments);
        }
Пример #7
0
 private static void Run(Options options)
 {
     if (options.Action == Options.ScAction.WaitStop)
     {
         WaitForStop(options);
     }
     else
     {
         int exitCode = ExternalProcessExecutor.ExecAndGetExitCode(DefaultSettings.ServiceControl, options.GetArguments());
         ValidateExitCode(options, exitCode);
     }
 }
Пример #8
0
        private static void ValidateExitCode(Options options, int exitCode)
        {
            string reason = GetExitReason(options, exitCode);

            if (string.IsNullOrEmpty(reason))
            {
                ExternalProcessExecutor.ValidateExitWithZero(exitCode);
            }
            else
            {
                Console.Error.WriteLine("SC reported failure, but exiting with success ({0})", reason);
            }
        }
        public void ExternalProcessExecutor_Start_OpenInBrowser_VerifyCalls_ToBeOnce_ExpectTrue()
        {
            //---------------------Arrange-------------------------
            var mockProcessWrapper = new Mock <IProcessFactory>();

            var uri = new Uri("https://testwarewolf.io");

            var externalProcessExecutor = new ExternalProcessExecutor(mockProcessWrapper.Object);

            //---------------------Act-----------------------------
            externalProcessExecutor.OpenInBrowser(uri);
            //---------------------Assert--------------------------
            mockProcessWrapper.Verify(o => o.Start(uri.ToString()), Times.Once);
        }
Пример #10
0
        public static void SendErrorOpenInBrowser(IEnumerable <string> exceptionList, string description, string url)
        {
            ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => true;
            const string PayloadFormat  = "\"header\":{0},\"description\":{1},\"type\":3,\"category\":27";
            var          headerVal      = JsonConvert.SerializeObject(string.Join(Environment.NewLine, exceptionList));
            var          serDescription = JsonConvert.SerializeObject(description);
            var          postData       = "{" + string.Format(PayloadFormat, headerVal, serDescription) + "}";

            //make sure to use TLS 1.2 first before trying other version
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            var request = (HttpWebRequest)WebRequest.Create(url);

            request.KeepAlive       = false;
            request.ProtocolVersion = HttpVersion.Version10;
            request.ServicePoint.ConnectionLimit = 1;
            request.Method = "POST";
            var byteArray = Encoding.UTF8.GetBytes(postData);

            request.ContentType   = "text/plain";
            request.ContentLength = byteArray.Length;
            request.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
            var dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            var response = request.GetResponse();

            dataStream = response.GetResponseStream();
            if (dataStream != null)
            {
                var reader             = new StreamReader(dataStream);
                var responseFromServer = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
                response.Close();
                if (JsonConvert.DeserializeObject(responseFromServer) is JObject responseObj)
                {
                    var urlToOpen = ((dynamic)responseObj).data.url;

                    var urlValue = urlToOpen.ToString();
                    if (!string.IsNullOrEmpty(urlValue))
                    {
                        var executor = new ExternalProcessExecutor();
                        executor.OpenInBrowser(new Uri(urlValue));
                    }
                }
            }
        }
        public void ExternalProcessExecutor_Start_Catch_COMException_VerifyAll_ExpectTrue()
        {
            //---------------------Arrange-------------------------
            var mockProcessWrapper = new Mock <IProcessFactory>();

            var uri = new Uri("https://testwarewolf.io");

            mockProcessWrapper.Setup(o => o.Start(uri.ToString())).Throws <COMException>();

            var externalProcessExecutor = new ExternalProcessExecutor(mockProcessWrapper.Object);

            //---------------------Act-----------------------------
            externalProcessExecutor.OpenInBrowser(uri);
            //---------------------Assert--------------------------
            mockProcessWrapper.VerifyAll();
        }
        public void ExternalProcessExecutor_Start_ProcessStartInfo_VerifyCalls_ToBeOnce_ExpectTrue()
        {
            //---------------------Arrange-------------------------
            var mockProcessWrapper = new Mock <IProcessFactory>();
            var mockProcess        = new Mock <IProcess>();

            var processStartInfo = new ProcessStartInfo();

            mockProcessWrapper.Setup(o => o.Start(It.IsAny <ProcessStartInfo>())).Returns(mockProcess.Object);

            var externalProcessExecutor = new ExternalProcessExecutor(mockProcessWrapper.Object);

            //---------------------Act-----------------------------
            externalProcessExecutor.Start(processStartInfo);
            //---------------------Assert--------------------------
            mockProcessWrapper.Verify(o => o.Start(It.IsAny <ProcessStartInfo>()), Times.Once);
        }