Skip to content

Commit

Permalink
Merge pull request #551 from Sitecore/rc/1.9.0
Browse files Browse the repository at this point in the history
Rc/1.9.0
  • Loading branch information
AndreyFilchenkov authored Feb 3, 2021
2 parents cc4de25 + d3e7e9d commit 1b9dd04
Show file tree
Hide file tree
Showing 139 changed files with 5,627 additions and 550 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ src/SIM.Telemetry.Tests/bin/
src/SIM.SitecoreEnvironments/bin/
/.vs
src/SIM.Sitecore9Installer.Tests/bin/
src/SIM.ContainerInstaller/bin/
src/SIM.Products.Tests/bin/
18 changes: 2 additions & 16 deletions src/SIM.Adapters/WebServer/Website.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class Website

public long ID { get; }

private string name;

#endregion

#region Constructors
Expand Down Expand Up @@ -163,21 +161,9 @@ public virtual string Name
{
get
{
try
{
if (string.IsNullOrEmpty(name))
{
using (WebServerManager.WebServerContext context = WebServerManager.CreateContext())
{
name = GetName(context);
}
}
return name;
}
catch(Exception ex)
using (WebServerManager.WebServerContext context = WebServerManager.CreateContext())
{
Log.Error(ex, ex.Message);
return "Error";
return GetName(context);
}
}
}
Expand Down
181 changes: 180 additions & 1 deletion src/SIM.Base/ApplicationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ namespace SIM
using Sitecore.Diagnostics.Base;
using JetBrains.Annotations;
using SIM.Extensions;
using System.Timers;
using System.ServiceProcess;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;

#region



#endregion

Expand All @@ -29,6 +34,10 @@ public static class ApplicationManager
public const string AppDataRoot = @"%AppData%\Sitecore\Sitecore Instance Manager";
public const string DefaultConfigurations = "Configurations";
public const string DefaultPackages = "Packages";
public const string DockerDesktopPath = @"C:\Program Files\Docker\Docker\Docker Desktop.exe";
public const string DockerProcessName = "Docker Desktop";
public const string DockerServiceName = "docker";
public const string IisServiceName = "W3SVC";

#endregion

Expand Down Expand Up @@ -82,6 +91,18 @@ public static class ApplicationManager

public static string AppsFolder { get; }

public static bool IsIisRunning { get; set; }

public static bool IsDockerRunning { get; set; }

public static event PropertyChangedEventHandler IisStatusChanged;

public static event PropertyChangedEventHandler DockerStatusChanged;

private static readonly System.Timers.Timer Timer;

private const double TimerInterval = 10000;

#endregion

#region Constructors
Expand All @@ -108,6 +129,11 @@ static ApplicationManager()
AppLabel = GetLabel();
UnInstallParamsFolder = InitializeDataFolder("UnInstallParams");
TempFolder = InitializeDataFolder("Temp");
IsIisRunning = GetIisStatus();
IsDockerRunning = GetDockerStatus();
Timer = new System.Timers.Timer(TimerInterval);
Timer.Elapsed += Timer_Elapsed;
Timer.Enabled = true;
}

#endregion
Expand Down Expand Up @@ -224,6 +250,89 @@ public static void RaiseAttemptToClose(CancelEventArgs e)
EventHelper.RaiseEvent(AttemptToClose, typeof(ApplicationManager), e);
}

public static bool StartStopIis(bool start)
{
Timer.Stop();
try
{
using (ServiceController serviceController = new ServiceController(IisServiceName))
{
if (start)
{
serviceController.Start();
serviceController.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMilliseconds(TimerInterval));
}
else
{
serviceController.Stop();
serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(TimerInterval));
}
}

RunTimerElapsed(4000);
Timer.Start();
return true;
}
catch
{
Timer.Start();
return false;
}
}

public static bool StartStopDocker(bool start)
{
Timer.Stop();
try
{
if (start)
{
if (File.Exists(DockerDesktopPath))
{
Process process = Process.Start(DockerDesktopPath);
if (process != null)
{
RunTimerElapsed(10000);
Timer.Start();
return true;
}
}
}
else
{
ServiceController serviceController = GetDockerService();

if (serviceController != null)
{
serviceController.Stop();

foreach (Process process in Process.GetProcessesByName(DockerProcessName))
{
process.Kill();
}

RunTimerElapsed(4000);
Timer.Start();
return true;
}
}

Timer.Start();
return false;
}
catch
{
Timer.Start();
return false;
}
}

private static void RunTimerElapsed(int timeout)
{
Thread.Sleep(timeout);
Timer_Elapsed(null, null);
}

#endregion

#region Private methods
Expand Down Expand Up @@ -282,6 +391,76 @@ private static string GetVersion()
return version != null ? version.Version : string.Empty;
}

private static void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
bool iisStatus = GetIisStatus();
if (IsIisRunning != iisStatus)
{
IsIisRunning = iisStatus;
OnIisStatusChanged();
}

bool dockerStatus = GetDockerStatus();
if (IsDockerRunning != dockerStatus)
{
IsDockerRunning = dockerStatus;
OnDockerStatusChanged();
}
}

private static bool GetIisStatus()
{
try
{
using (ServiceController serviceController = new ServiceController(IisServiceName))
{
if (serviceController.Status.Equals(ServiceControllerStatus.Running))
{
return true;
}
return false;
}
}
catch
{
return false;
}
}

private static bool GetDockerStatus()
{
try
{
ServiceController serviceController = GetDockerService();

if (serviceController != null && serviceController.Status.Equals(ServiceControllerStatus.Running))
{
return true;
}

return false;
}
catch
{
return false;
}
}

private static ServiceController GetDockerService()
{
return ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == DockerServiceName);
}

private static void OnIisStatusChanged([CallerMemberName] string name = null)
{
IisStatusChanged?.Invoke(null, new PropertyChangedEventArgs(name));
}

private static void OnDockerStatusChanged([CallerMemberName] string name = null)
{
DockerStatusChanged?.Invoke(null, new PropertyChangedEventArgs(name));
}

#endregion

#region Methods
Expand Down
17 changes: 17 additions & 0 deletions src/SIM.Base/Loggers/EmptyLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace SIM.Loggers
{
public class EmptyLogger : ILogger
{
public void Info(string message, bool includeSeverityLevel = true)
{
}

public void Warn(string message, bool includeSeverityLevel = true)
{
}

public void Error(string message, bool includeSeverityLevel = true)
{
}
}
}
11 changes: 11 additions & 0 deletions src/SIM.Base/Loggers/ILogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace SIM.Loggers
{
public interface ILogger
{
void Info(string message, bool includeSeverityLevel = true);

void Warn(string message, bool includeSeverityLevel = true);

void Error(string message, bool includeSeverityLevel = true);
}
}
38 changes: 38 additions & 0 deletions src/SIM.Base/Loggers/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Sitecore.Diagnostics.Base;

namespace SIM.Loggers
{
public class Logger : ILogger
{
internal Action<string> _WriteLogMessage;

public Logger(Action<string> writeLogMessage)
{
Assert.ArgumentNotNull(writeLogMessage);
this._WriteLogMessage = writeLogMessage;
}

public void Info(string message, bool includeSeverityLevel = true)
{
DoWriteMessage(message, includeSeverityLevel, "INFO");
}

public void Warn(string message, bool includeSeverityLevel = true)
{
DoWriteMessage(message, includeSeverityLevel, "WARN");
}

public void Error(string message, bool includeSeverityLevel = true)
{
DoWriteMessage(message, includeSeverityLevel, "ERROR");
}

private void DoWriteMessage(string message, bool includeSeverityLevel = true, string severity = "")
{
string time = DateTime.Now.ToString("HH:mm:ss");
string text = includeSeverityLevel ? $"[{time}] {severity}: {message}" : $"[{time}] {message}";
this._WriteLogMessage(text);
}
}
}
46 changes: 0 additions & 46 deletions src/SIM.Base/RangeObservableCollection.cs

This file was deleted.

Loading

0 comments on commit 1b9dd04

Please sign in to comment.