Пример #1
0
        public void DotnetPublish(string sampleName)
        {
            var framework   = "CoreCLR";
            var testName    = $"{sampleName}.{framework}.{nameof(DotnetPublish)}";
            var testProject = _sampleManager.GetRestoredSample(sampleName);

            Assert.True(testProject != null, "Failed to set up test project.");

            var testOutput = Path.Combine(PathHelper.GetNewTempFolder(), testName);

            Directory.CreateDirectory(testOutput);

            using (Collector.StartCollection())
            {
                DotnetHelper.GetDefaultInstance().Publish(
                    workingDir: testProject,
                    outputDir: testOutput);
            }

            try
            {
                Directory.Delete(testOutput, recursive: true);
            }
            catch (IOException)
            {
                // Ignore problems deleting the publish target directory.
            }
        }
Пример #2
0
        private MailsSendedReport SendMail(IEnumerable <IAdherent> users, MailMessage mailMessage)
        {
            var activeAdherentStolon = GetActiveAdherentStolon();
            MailsSendedReport report = new MailsSendedReport();

            foreach (Adherent user in users)
            {
                if (!String.IsNullOrWhiteSpace(user.Email))
                {
                    try
                    {
                        AuthMessageSender.SendEmail(activeAdherentStolon.Stolon.Label,
                                                    user.Email,
                                                    user.Name,
                                                    mailMessage.Title,
                                                    mailMessage.Message);
                        report.MailsSended++;
                    }
                    catch (Exception ex)
                    {
                        DotnetHelper.GetLogger <MailsController>().LogError(ex.ToString());
                        report.MailsNotSended++;
                    }
                }
            }
            return(report);
        }
Пример #3
0
        /// <summary>
        /// MAIL KIT
        /// Info : http://dotnetthoughts.net/how-to-send-emails-from-aspnet-core/
        /// </summary>
        public static void SendEmail(string senderLabel, string email, string name, string subject, string message, byte[] attachment = null, string attachmentName = "Facture")
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                name = email;
            }
            var mimeMessage = new MimeMessage();

            mimeMessage.From.Add(new MailboxAddress(senderLabel, Configurations.Application.MailAddress));
            mimeMessage.To.Add(new MailboxAddress(name, email));
            mimeMessage.Subject = subject;
            var bodyBuilder = new BodyBuilder();

            if (attachment != null)
            {
                bodyBuilder.Attachments.Add(attachmentName, attachment);
            }
            bodyBuilder.HtmlBody = message;
            mimeMessage.Body     = bodyBuilder.ToMessageBody();
            try
            {
                using (var client = new SmtpClient())
                {
                    if (Configurations.Environment.EnvironmentName == "Debug" || Configurations.Environment.EnvironmentName == "Development")
                    {
                        client.Connect(Configurations.DebugMailSmtp, Configurations.DebugMailPort, false);
                        client.AuthenticationMechanisms.Remove("XOAUTH2");
                        // Note: since we don't have an OAuth2 token, disable
                        // the XOAUTH2 authentication mechanism.
                        if (Configurations.DebugMailUser != null && Configurations.DebugMailPassword != null)
                        {
                            client.Authenticate(Configurations.DebugMailUser, Configurations.DebugMailPassword);
                        }
                    }
                    else
                    {
                        client.Connect(Configurations.Application.MailSmtp, Configurations.Application.MailPort, false);
                        client.AuthenticationMechanisms.Remove("XOAUTH2");
                        // Note: since we don't have an OAuth2 token, disable
                        // the XOAUTH2 authentication mechanism.
                        client.Authenticate(Configurations.Application.MailAddress, Configurations.Application.MailPassword);
                    }
                    client.Send(mimeMessage);
                    client.Disconnect(true);
                }
            }
            catch (Exception except)
            {
                DotnetHelper.GetLogger <String>().LogError("Error on sending mail : " + except.Message);
            }
        }
Пример #4
0
        public void Development_Startup(string sampleName)
        {
            var framework = Microsoft.Extensions.Internal.RuntimeEnvironment.RuntimeType;
            var testName = $"{sampleName}.{framework}.{nameof(Development_Startup)}";
            var logger = LogUtility.LoggerFactory.CreateLogger(testName);

            var testProject = _sampleManager.GetRestoredSample(sampleName);
            Assert.True(testProject != null, $"Fail to set up test project.");
            logger.LogInformation($"Test project is set up at {testProject}");

            var testAppStartInfo = DotnetHelper.GetDefaultInstance().BuildStartInfo(testProject, "run");

            RunStartup(5000, logger, testAppStartInfo);
        }
Пример #5
0
        public void Development_Update_Startup(string sampleName)
        {
            var framework = Microsoft.Extensions.Internal.RuntimeEnvironment.RuntimeType;
            var testName  = $"{sampleName}.{framework}.{nameof(Development_Startup)}";
            var logger    = LogUtility.LoggerFactory.CreateLogger(testName);

            var testProject = _sampleManager.GetRestoredSample(sampleName);

            Assert.True(testProject != null, $"Fail to set up test project.");
            logger.LogInformation($"Test project is set up at {testProject}");

            var testAppStartInfo = DotnetHelper.GetDefaultInstance().BuildStartInfo(testProject, "run");
            var process          = Process.Start(testAppStartInfo);

            Thread.Sleep(5000);
            process.KillTree();
            logger.LogInformation("Run server before updating");

            // update source code
            var lines = File.ReadLines(Path.Combine(testProject, "Startup.cs")).ToArray();

            for (var i = 0; i < lines.Length; ++i)
            {
                if (lines[i].Trim().StartsWith("private const string FixedResponse = "))
                {
                    lines[i] = $"private const string FixedResponse = \"{Guid.NewGuid()}\";";
                }
            }

            var retry = 0;

            while (retry < 3)
            {
                try
                {
                    File.WriteAllLines(Path.Combine(testProject, "Startup.cs"), lines);
                    break;
                }
                catch (IOException)
                {
                    ++retry;
                }
            }
            Assert.True(retry <= 3, "Failed to write the source code for 3 times.");
            logger.LogInformation("Update source code");

            RunStartup(5000, logger, testAppStartInfo);
        }
Пример #6
0
 private static void GetCurrentStolonsModes()
 {
     using (var scope = DotnetHelper.GetNewScope())
     {
         using (ApplicationDbContext dbContext = DotnetHelper.getDbContext(scope))
         {
             foreach (Stolon stolon in dbContext.Stolons.AsNoTracking().ToList())
             {
                 if (!lastModes.Keys.Contains(stolon.Id))
                 {
                     lastModes.Add(stolon.Id, stolon.GetMode());
                 }
             }
         }
     }
 }
Пример #7
0
 private ProcessStartInfo GetStartInfo(string testProject, string sampleName)
 {
     string processPath = Path.Combine(testProject, $"{sampleName}.exe");
     string processArguments = string.Empty;
     if (!File.Exists(processPath))
     {
         processPath = DotnetHelper.GetDefaultInstance().GetDotnetExecutable();
         processArguments = "\"" + Path.Combine(testProject, $"{sampleName}.dll") + "\"";
     }
     return new ProcessStartInfo(processPath)
     {
         UseShellExecute = false,
         RedirectStandardInput = false,
         RedirectStandardOutput = false,
         RedirectStandardError = false,
         Arguments = processArguments
     };
 }
Пример #8
0
        public void DotnetPublish(string sampleName)
        {
            var framework   = Microsoft.Extensions.Internal.RuntimeEnvironment.RuntimeType;
            var testName    = $"{sampleName}.{framework}.{nameof(DotnetPublish)}";
            var testProject = _sampleManager.GetRestoredSample(sampleName);

            Assert.True(testProject != null, $"Fail to set up test project.");

            var testOutput = Path.Combine(PathHelper.GetNewTempFolder(), testName);

            Directory.CreateDirectory(testOutput);

            using (Collector.StartCollection())
            {
                DotnetHelper.GetDefaultInstance().Publish(
                    workingDir: testProject,
                    outputDir: testOutput);
            }
        }
Пример #9
0
        public static void ManageBills()
        {
            Logger = DotnetHelper.GetLogger <String>();
            GetCurrentStolonsModes();
            while (shouldRun)
            {
                using (var scope = DotnetHelper.GetNewScope())
                {
                    using (ApplicationDbContext dbContext = DotnetHelper.getDbContext(scope))
                    {
                        foreach (Stolon stolon in dbContext.Stolons.AsNoTracking().ToList())
                        {
                            //For new Stolon
                            if (!lastModes.Keys.Contains(stolon.Id))
                            {
                                lastModes.Add(stolon.Id, stolon.GetMode());
                            }

                            Stolon.Modes currentMode = stolon.GetMode();
                            if (lastModes[stolon.Id] == Stolon.Modes.Order && currentMode == Stolon.Modes.DeliveryAndStockUpdate)
                            {
#if (DEBUG)
                                DebugRemoveBills(dbContext);
#endif
                                TriggerDeliveryAndStockUpdateMode(stolon, dbContext);
                            }
                            else if (lastModes[stolon.Id] == Stolon.Modes.DeliveryAndStockUpdate && currentMode == Stolon.Modes.Order)
                            {
                                TriggerOrderMode(stolon, dbContext);
                            }
                            lastModes[stolon.Id] = currentMode;
                        }
                    }
                }
                Thread.Sleep(5000);
            }
        }
Пример #10
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            //Register webhost in Stolons configs
            Configurations.WebHost = host;

            Thread billManager = new Thread(() => BillGenerator.ManageBills());

            billManager.Start();

            var logger = DotnetHelper.GetLogger <Program>();

            using (var scope = DotnetHelper.GetNewScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    Startup.SeedDatabase(services);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            try
            {
                host.Run();
            }
            catch (Exception e)
            {
                logger.LogError("Server is dead, catched exception. Bye cruel world");
                throw e;
            }
        }
Пример #11
0
        private void DeployTestSite(string sampleName, string framework)
        {
            var runner = new CommandLineRunner()
            {
                Timeout = TimeSpan.FromMinutes(5)
            };

            _testsitesource = Path.GetTempFileName();
            File.Delete(_testsitesource);
            Directory.CreateDirectory(_testsitesource);

            var sourcePath = PathHelper.GetTestAppFolder(sampleName);

            Assert.NotNull(sourcePath);

            runner.Execute($"git clean -xdff .", sourcePath);
            Assert.NotEqual(-1, runner.Execute($"robocopy {sourcePath} {_testsitesource} /E /S /XD node_modules")); // robcopy doesn't return 0
            File.WriteAllText(Path.Combine(_testsitesource, "global.json"), DotnetHelper.GetDefaultInstance().BuildGlobalJson());
            File.Copy(PathHelper.GetNuGetConfig(), Path.Combine(_testsitesource, "NuGet.config"));

            _log.LogInformation($"Testsite sources are copied to {_testsitesource}.");

            CreateTestSite();

            Assert.Equal(0, runner.Execute("git add -A .", _testsitesource));
            Assert.Equal(0, runner.Execute("git commit -m \"init\"", _testsitesource));

            var giturl = $"https://{_username}:{_password}@{_testsitename}.scm.azurewebsites.net:443/{_testsitename}.git";

            Assert.Equal(0, runner.Execute($"git remote set-url azure {giturl}", _testsitesource));

            _log.LogInformation("Git repository is set up at testsite source folder");

            runner.Timeout = TimeSpan.FromMinutes(15);
            Assert.Equal(0, runner.Execute($"git push azure master", _testsitesource));
        }
Пример #12
0
 public static void OnShutdown()
 {
     DotnetHelper.GetLogger <Startup>().LogWarning("Server is shutting down");
     BillGenerator.StopThread();
 }