Skip to content

Commit

Permalink
Quality improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MajMcCloud committed Nov 24, 2021
1 parent f7f6e06 commit c228073
Show file tree
Hide file tree
Showing 17 changed files with 353 additions and 142 deletions.
4 changes: 2 additions & 2 deletions ServiceManager.Base/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.16")]
[assembly: AssemblyFileVersion("1.0.1.16")]
71 changes: 48 additions & 23 deletions ServiceManager.Base/ServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,37 @@ public void Start()

Connection.Server.Manager = this;

PrepareServices(cfg);

Thread th = new Thread(new ThreadStart(() =>
{
Thread.Sleep(cfg.RuntimeSettings.Startup_Delay * 1000);
StartServices(cfg);
}));

th.Start();

}

private void PrepareServices(ServiceConfig cfg)
{
foreach (var c in cfg.ServiceList)
{
PrepareService(c);
}
}

private void StartServices(ServiceConfig cfg)
{
foreach (var c in cfg.ServiceList)
{
//Don't start
if (!c.Enabled)
continue;

StartService(c);
}

}

/// <summary>
Expand Down Expand Up @@ -312,31 +332,35 @@ private void Proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
if (e.Data == null)
return;

//Save to harddrive
if (sa.LastSaved.Date != DateTime.Today)
var service = this.Config.ServiceList.FirstOrDefault(a => a.ID == sa.ServiceID);
if (service.LogConsoleOutput)
{
var service = this.Config.ServiceList.FirstOrDefault(a => a.ID == sa.ServiceID);
if (service.LogConsoleOutput && SaveToLogs(service, sa.Output))
//Save to harddrive
if (sa.LastSaved.Date != DateTime.Today)
{
sa.Output = "";
sa.LastSaved = DateTime.Now;
}
else if (service.ResetConsoleOutputDaily)
{
sa.Output = "";
sa.LastSaved = DateTime.Now;

if (service.LogConsoleOutputToDisk && SaveToDisk(service, sa.Output))
{
sa.Output = "";
sa.LastSaved = DateTime.Now;
}
else if (service.ResetConsoleOutputDaily)
{
sa.Output = "";
sa.LastSaved = DateTime.Now;
}
}
}

sa.Output += e.Data + "\r\n";
sa.Output += e.Data + "\r\n";
}

if (Connection.ServerChannel == null || Connection.Failed)
return;


var t = new Task(() =>
{
if (DateTime.Now.Subtract(sa.LastPing).TotalSeconds > 5)
if (DateTime.Now.Subtract(sa.LastPing).TotalSeconds > 10)
{
Connection?.Try(a => a.ActivityPing(sa.ServiceID));
sa.LastPing = DateTime.Now;
Expand All @@ -353,7 +377,7 @@ private void Proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
t.Start();
}

public bool SaveToLogs(ServiceItem service, String content)
public bool SaveToDisk(ServiceItem service, String content)
{

var path = AppContext.BaseDirectory + "\\logs\\" + service.ID.ToString() + "\\";
Expand Down Expand Up @@ -388,13 +412,14 @@ private void Process_Exited(ServiceItem service, Process proc)

sa.Status = ServiceAnalytics.eStatus.offline;



//Save to harddrive
if (service.LogConsoleOutput && SaveToLogs(service, sa.Output))
if (service.LogConsoleOutput)
{
sa.Output = "";
sa.LastSaved = DateTime.Now;
//Save to harddrive
if (service.LogConsoleOutputToDisk && SaveToDisk(service, sa.Output))
{
sa.Output = "";
sa.LastSaved = DateTime.Now;
}
}

//if (LiveLogs.Contains(sa.ServiceID))
Expand Down Expand Up @@ -486,7 +511,7 @@ public void Stop()
//Save to harddrive
if (sa.LastSaved.Date != DateTime.Today)
{
if (service.LogConsoleOutput && SaveToLogs(service, sa.Output))
if (service.LogConsoleOutput && SaveToDisk(service, sa.Output))
{
sa.Output = "";
sa.LastSaved = DateTime.Now;
Expand Down
15 changes: 14 additions & 1 deletion ServiceManager.Base/data/ServiceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,21 @@ public class ServiceItem

public int Shutdown_ENTER_Timeout { get; set; }

public bool LogConsoleOutput { get; set; }
/// <summary>
/// Logs console output to memory
/// </summary>
public bool LogConsoleOutput { get; set; } = true;


/// <summary>
/// Logs console output to disk
/// </summary>
public bool LogConsoleOutputToDisk { get; set; }


/// <summary>
/// Clears up daily log cache from memory
/// </summary>
public bool ResetConsoleOutputDaily { get; set; } = true;

public ServiceItem()
Expand Down
6 changes: 6 additions & 0 deletions ServiceManager.Base/data/settings/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ public enum eMode

public int TCPPort { get; set; }

/// <summary>
/// Delay of service startup in seconds.
/// </summary>
public int Startup_Delay { get; set; }

public Runtime()
{
this.Mode = eMode.NetPipes;
this.TCPPort = 50000;
this.Startup_Delay = 0;
}

}
Expand Down
33 changes: 29 additions & 4 deletions ServiceManager.Base/wcf/ManagerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public interface IManagerService
[OperationContract(IsOneWay = true)]
void ToggleAutoRestart(Guid serviceId);

[OperationContract]
void Ping();

}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, AutomaticSessionShutdown = false, ConcurrencyMode = ConcurrencyMode.Multiple, IncludeExceptionDetailInFaults = true, UseSynchronizationContext = false)]
Expand Down Expand Up @@ -167,12 +170,27 @@ public GetServiceLogsResponse GetServiceLogs(Guid serviceId)
var service = Manager.Config.ServiceList.FirstOrDefault(a => a.ID == serviceId);
var analytics = Manager.Analytics.Services.FirstOrDefault(a => a.ServiceID == serviceId);

GetServiceLogsResponse logs = new GetServiceLogsResponse();
if(service.LogConsoleOutput)
{
GetServiceLogsResponse logs = new GetServiceLogsResponse();

logs.Logs = analytics.Output;
logs.Errors = analytics.Error;

return logs;
}
else
{
GetServiceLogsResponse logs = new GetServiceLogsResponse();

logs.Logs = "SYSTEM: Output history logging is currently disabled.\r\n";
logs.Errors = "SYSTEM: Error history logging is currently disabled.\r\n";

return logs;
}


logs.Logs = analytics.Output;
logs.Errors = analytics.Error;

return logs;
}

public void BeginLiveLogs(Guid serviceId)
Expand Down Expand Up @@ -231,5 +249,12 @@ public void ToggleAutoRestart(Guid serviceId)

}

/// <summary>
/// Just a Ping
/// </summary>
public void Ping()
{

}
}
}
4 changes: 2 additions & 2 deletions ServiceManager.Service/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.15")]
[assembly: AssemblyFileVersion("1.0.1.15")]
7 changes: 6 additions & 1 deletion ServiceManager.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceManager.UI", "ServiceManagerUI\ServiceManager.UI.csproj", "{E1921317-2E79-4715-AF44-483B610CF7B7}"
EndProject
Expand All @@ -21,6 +21,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceManager.Service", "S
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceManager.Base", "ServiceManager.Base\ServiceManager.Base.csproj", "{F7E25E80-2DDF-4928-A4FA-0F235D353A16}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E066821D-EF17-4AC7-AE20-A4F74FBE985B}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
4 changes: 2 additions & 2 deletions ServiceManagerUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.0.1.23")]
[assembly: AssemblyFileVersion("2.0.1.23")]
2 changes: 1 addition & 1 deletion ServiceManagerUI/ServiceManager.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
<SignManifests>false</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand Down
7 changes: 3 additions & 4 deletions ServiceManagerUI/forms/frmLogs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c228073

Please sign in to comment.