Skip to content

Commit

Permalink
#50
Browse files Browse the repository at this point in the history
* refactor + connected all new code
  • Loading branch information
mrksoftware committed Mar 22, 2020
1 parent d15ad9b commit 5c0cdff
Show file tree
Hide file tree
Showing 75 changed files with 865 additions and 922 deletions.
10 changes: 4 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ ClientBin/
*.publishsettings
orleans.codegen.cs

# Including strong name files can present a security risk
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk

Expand Down Expand Up @@ -317,7 +317,7 @@ __pycache__/
# OpenCover UI analysis results
OpenCover/

# Azure Stream Analytics local run output
# Azure Stream Analytics local run output
ASALocalRun/

# MSBuild Binary and Structured Log
Expand All @@ -326,10 +326,8 @@ ASALocalRun/
# NVidia Nsight GPU debugger configuration file
*.nvuser

# MFractors (Xamarin productivity tool) working folder
# MFractors (Xamarin productivity tool) working folder
.mfractor/
Elfo.Wardein.Core/Assets/WardeinConfig.json
Elfo.Wardein.Core/Assets/MailConfig.json
Elfo.Wardein.Integrations.Tests/appsettings.json
/Elfo.Wardein.Integrations/appsettings.json
/Elfo.Wardein.Core.Tests/appsettings.json
*/appsettings.json
2 changes: 1 addition & 1 deletion Elfo.Wardein.APIs/Abstractions/IAmRouteImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class IAmRouteImplementation
{
public IAmRouteImplementation(bool blockActionIfInMaintenanceMode)
{
if (blockActionIfInMaintenanceMode && ServicesContainer.WardeinConfigurationManager(Const.WARDEIN_CONFIG_PATH).IsInMaintenanceMode)
if (blockActionIfInMaintenanceMode && ServicesContainer.WardeinConfigurationManager().IsInMaintenanceMode)
{
throw new InvalidOperationException("Wardein is in maintenance mode. Please try again later");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public ConfigsImplementation() : base(blockActionIfInMaintenanceMode: false) { }

public async Task Invalidate(HttpContext context)
{
ServicesContainer.MailConfigurationManager(Const.MAIL_CONFIG_PATH).InvalidateCache();
ServicesContainer.WardeinConfigurationManager(Const.WARDEIN_CONFIG_PATH).InvalidateCache();
ServicesContainer.MailConfigurationManager().InvalidateCache();
ServicesContainer.WardeinConfigurationManager().InvalidateCache();
await new PollingImplementation().Restart(context);
await context.Response.WriteAsync($"Cached configs invalidated");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ public Task StartMaintenanceMode(HttpContext context)
if (!double.TryParse(context.GetRouteData().Values["durationInSeconds"]?.ToString(), out double durationInSecond))
durationInSecond = TimeSpan.FromMinutes(5).TotalSeconds; // Default value

ServicesContainer.WardeinConfigurationManager(Const.WARDEIN_CONFIG_PATH).StartMaintenanceMode(durationInSecond);
ServicesContainer.WardeinConfigurationManager().StartMaintenanceMode(durationInSecond);
return context.Response.WriteAsync($"Maintenance Mode Started");
}

public Task StopMaintenanceMode(HttpContext context)
{
ServicesContainer.WardeinConfigurationManager(Const.WARDEIN_CONFIG_PATH).StopMaintenaceMode();
ServicesContainer.WardeinConfigurationManager().StopMaintenaceMode();
return context.Response.WriteAsync($"Maintenance Mode Stopped");
}

public Task GetMaintenanceModeStatus(HttpContext context)
{
var result = "Wardein is not in maintenance mode";
if (ServicesContainer.WardeinConfigurationManager(Const.WARDEIN_CONFIG_PATH).IsInMaintenanceMode)
if (ServicesContainer.WardeinConfigurationManager().IsInMaintenanceMode)
result = "Wardein is in maintenance mode";
return context.Response.WriteAsync(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public Task StopService(HttpContext context)
return context.Response.WriteAsync($"Service {serviceName} stopped");
}

public Task GetServiceStatus(HttpContext context)
public async Task<string> GetServiceStatus(HttpContext context)
{
string serviceName = context.GetRouteValue("name").ToString();

var status = GetServiceStatus(serviceName);
return context.Response.WriteAsync(status);
var status = await GetServiceStatus(serviceName);
return status; // TODO: print on webpage
}

public Task StartService(HttpContext context)
Expand Down Expand Up @@ -72,12 +72,12 @@ public Task StopPool(HttpContext context)
return context.Response.WriteAsync($"ApplicationPool {applicationPoolName} stopped");
}

public Task GetPoolStatus(HttpContext context)
public async Task<string> GetPoolStatus(HttpContext context)
{
string applicationPoolName = context.GetRouteValue("name").ToString();

var status = GetIISPoolStatus(applicationPoolName);
return context.Response.WriteAsync(status);
var status = await GetIISPoolStatus(applicationPoolName);
return status; // TODO: print in webpage
}

#endregion
Expand All @@ -98,14 +98,14 @@ public Task RestartServiceAndPool(HttpContext context)

#region Local Functions

void RestartService(string serviceName) => new WindowsServiceManager(serviceName).Restart();
void StopService(string serviceName) => new WindowsServiceManager(serviceName).Stop();
void StartService(string serviceName) => new WindowsServiceManager(serviceName).Start();
string GetServiceStatus(string serviceName) => new WindowsServiceManager(serviceName).GetStatus();
void RefreshIISPool(string iisPoolName) => new IISPoolManager(iisPoolName).Restart();
void StopIISPool(string issPoolName) => new IISPoolManager(issPoolName).Stop();
string GetIISPoolStatus(string iisPoolName) => new IISPoolManager(iisPoolName).GetStatus();
void StartIISPool(string iisPoolName) => new IISPoolManager(iisPoolName).Start();
async Task RestartService(string serviceName) => await new WindowsServiceManager(serviceName).Restart();
async Task StopService(string serviceName) => await new WindowsServiceManager(serviceName).Stop();
async Task StartService(string serviceName) => await new WindowsServiceManager(serviceName).Start();
async Task<string> GetServiceStatus(string serviceName) => await new WindowsServiceManager(serviceName).GetStatus();
async Task RefreshIISPool(string iisPoolName) => await new IISPoolManager(iisPoolName).Restart();
async Task StopIISPool(string issPoolName) => await new IISPoolManager(issPoolName).Stop();
async Task<string> GetIISPoolStatus(string iisPoolName) => await new IISPoolManager(iisPoolName).GetStatus();
async Task StartIISPool(string iisPoolName) => await new IISPoolManager(iisPoolName).Start();

#endregion
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace Elfo.Firmenich.Wardein.Abstractions.Configuration.Models
namespace Elfo.Wardein.Abstractions.Configuration.Models
{
public enum ServiceManagerType
{
Expand Down
17 changes: 13 additions & 4 deletions Elfo.Wardein.Abstractions/Configuration/Models/WardeinConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Elfo.Firmenich.Wardein.Abstractions.Configuration.Models;
using Elfo.Wardein.Abstractions.Configuration.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,9 @@ public class WardeinConfig
[JsonProperty(PropertyName = "timeSpanFromSeconds")]
public double TimeSpanFromSeconds { get; set; }

[JsonProperty(PropertyName = "connectionString")]
public string ConnectionString { get; set; }

[JsonProperty(PropertyName = "sendRepeatedNotificationAfterSeconds")]
public double SendRepeatedNotificationAfterSeconds { get; set; } = 3600; // Default values

Expand All @@ -28,13 +31,19 @@ public class WardeinConfig
MaintenanceModeStartDateInUTC = DateTime.UtcNow
}; // Default values

[JsonProperty(PropertyName = "heartbeat")]
public HeartbeatConfigurationModel Heartbeat { get; set; } = new HeartbeatConfigurationModel();

[JsonProperty(PropertyName = "services")]
public IEnumerable<GenericServiceModel> Services { get; set; }
public IEnumerable<GenericServiceConfigurationModel> Services { get; set; }

[JsonProperty(PropertyName = "iisPools")]
public IEnumerable<GenericServiceModel> IISPools { get; set; }
public IEnumerable<GenericServiceConfigurationModel> IISPools { get; set; }

[JsonProperty(PropertyName = "urls")]
public IEnumerable<WebWatcherUrlModel> Urls { get; set; }
public IEnumerable<WebWatcherConfigurationModel> Urls { get; set; }

[JsonProperty(PropertyName = "cleanUps")]
public IEnumerable<FileSystemConfigurationModel> CleanUps { get; set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Elfo.Wardein.Abstractions.Configuration.Models
{
public interface IAmBaseConfigurationModel
{
[JsonProperty(PropertyName = "isInMaintenanceMode")]
bool IsInMaintenanceMode { get; }
[JsonProperty(PropertyName = "timeSpanFromSeconds")]
double TimeSpanFromSeconds { get; }
[JsonProperty(PropertyName = "watcherConfigurationId")]
public int WatcherConfigurationId { get; }
[JsonProperty(PropertyName = "applicationId")]
public int ApplicationId { get; }
[JsonProperty(PropertyName = "applicationHostname")]
public string ApplicationHostname { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Elfo.Wardein.Abstractions.Configuration.Models
{
public interface IAmConfigurationModelWithResolution : IAmBaseConfigurationModel
{
[JsonProperty(PropertyName = "notificationtype")]
public NotificationType NotificationType { get; set; }

[JsonProperty(PropertyName = "recipientAddresses")]
public string RecipientAddresses { get; set; }

[JsonProperty(PropertyName = "failureMessage")]
public string FailureMessage { get; set; }

[JsonProperty(PropertyName = "restoredMessage")]
public string RestoredMessage { get; set; }

[JsonProperty(PropertyName = "maxRetryCount")]
public int MaxRetryCount { get; set; }

[JsonProperty(PropertyName = "sendReminderEmailAfterRetryCount")]
public int SendReminderEmailAfterRetryCount { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Elfo.Wardein.Abstractions.Configuration.Models
{
public class FileSystemConfigurationModel : IAmBaseConfigurationModel
{
/// <summary>
/// Property defines if watcher has to be running in maintainance mode
/// Default value false
/// </summary>
[JsonProperty(PropertyName = "isInMaintenanceMode")]
public bool IsInMaintenanceMode { get; set; } = false;

/// <summary>
/// Property that defines frequency of watcher polling
/// Default value 10 seconds
/// </summary>
[JsonProperty(PropertyName = "timeSpanFromSeconds")]
public double TimeSpanFromSeconds { get; set; } = 300;

/// <summary>
/// List of folder configurations that has to be monitored and cleaned by criteria
/// </summary>
[JsonProperty(PropertyName = "cleanUps")]
public IEnumerable<FileSystemCleanUpConfig> CleanUps { get; set; } = new List<FileSystemCleanUpConfig>();

public int WatcherConfigurationId { get; set; }

public int ApplicationId { get; set; }

public string ApplicationHostname => HostHelper.GetName();
}

public class FileSystemCleanUpConfig
{
[JsonProperty(PropertyName = "filePath")]
public string FilePath { get; set; }

[JsonProperty(PropertyName = "timeSpanFromSeconds")]
public double TimeSpanFromSeconds { get; set; } = 10; // Default values

[JsonProperty(PropertyName = "cleanUpOptions")]
public FileSystemCleanUpOptions CleanUpOptions { get; set; } = new FileSystemCleanUpOptions();
}

public class FileSystemCleanUpOptions
{
[JsonProperty(PropertyName = "thresholdInSeconds")]
public int ThresholdInSeconds { get; set; }

[JsonProperty(PropertyName = "thresholdInDays")]
public int ThresholdInDays { get; set; }

[JsonProperty(PropertyName = "displayOnly")]
public bool DisplayOnly { get; set; } = false;

[JsonProperty(PropertyName = "useRecycleBin")]
public bool UseRecycleBin { get; set; } = false;

[JsonProperty(PropertyName = "removeEmptyFolders")]
public bool RemoveEmptyFolders { get; set; } = false;

[JsonProperty(PropertyName = "recursive")]
public bool Recursive { get; set; } = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Elfo.Wardein.Abstractions.Configuration.Models
{
public class GenericServiceConfigurationModel : IAmConfigurationModelWithResolution
{
[JsonProperty(PropertyName = "serviceName")]
public string ServiceName { get; set; }
[JsonProperty(PropertyName = "serviceManagerType")]
public ServiceManagerType ServiceManagerType { get; set; }
public bool IsInMaintenanceMode { get; set; }
public double TimeSpanFromSeconds { get; set; } = 60;
public int WatcherConfigurationId { get; set; }
public int ApplicationId { get; set; }
public string ApplicationHostname => HostHelper.GetName();
public string RecipientAddresses { get; set; }
public string FailureMessage { get; set; }
public int SendReminderEmailAfterRetryCount { get; set; } = 120;
public NotificationType NotificationType { get; set; } = NotificationType.Mail;
public string RestoredMessage { get; set; }
public int MaxRetryCount { get; set; } = 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;

namespace Elfo.Wardein.Abstractions.Configuration.Models
{
public class HeartbeatConfigurationModel : IAmBaseConfigurationModel
{
public string ApplicationHostname => HostHelper.GetName();

public bool IsInMaintenanceMode => false;

public double TimeSpanFromSeconds => 60;

public int WatcherConfigurationId { get; set; }

public int ApplicationId { get; set; }
}
}
Loading

0 comments on commit 5c0cdff

Please sign in to comment.