Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions Source/Applications/openPDC/openPDC/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
//
//******************************************************************************************************

using System;
using System.Security;
using System.Web.Http;
using System.Web.Http.Cors;
using System.Web.Http.ExceptionHandling;
using GSF.IO;
using GSF.Web;
using GSF.Web.Hosting;
Expand All @@ -36,9 +31,14 @@
using ModbusAdapters;
using Newtonsoft.Json;
using openPDC.Adapters;
using Owin;
using openPDC.Model;
using Owin;
using PhasorWebUI;
using System;
using System.Security;
using System.Web.Http;
using System.Web.Http.Cors;
using System.Web.Http.ExceptionHandling;

namespace openPDC
{
Expand All @@ -53,6 +53,11 @@ public override void Handle(ExceptionHandlerContext context)

public class Startup
{
/// <summary>
/// Gets the authentication options used for the hosted web server.
/// </summary>
public static AuthenticationOptions AuthenticationOptions { get; } = new AuthenticationOptions();

public void Configuration(IAppBuilder app)
{
// Add Content-Security Headers
Expand All @@ -77,15 +82,16 @@ public void Configuration(IAppBuilder app)
}
});

// Modify the JSON serializer to serialize dates as UTC - otherwise, timezone will not be appended
// to date strings and browsers will select whatever timezone suits them
// Modify the JSON serializer to serialize dates as UTC - otherwise, timezone will not
// be appended to date strings and browsers will select whatever timezone suits them
JsonSerializerSettings settings = JsonUtility.CreateDefaultSerializerSettings();
settings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
JsonSerializer serializer = JsonSerializer.Create(settings);
GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () => serializer);
AppModel model = Program.Host.Model;

// Load security hub into application domain before establishing SignalR hub configuration, initializing default status and exception handlers
// Load security hub into application domain before establishing SignalR hub
// configuration, initializing default status and exception handlers
try
{
using (new SecurityHub(
Expand Down Expand Up @@ -119,7 +125,7 @@ public void Configuration(IAppBuilder app)
Program.Host.LogException
))
{
WebExtensions.AddEmbeddedResourceAssembly(hub.GetType().Assembly);
WebExtensions.AddEmbeddedResourceAssembly(hub.GetType().Assembly);
}
}
catch (Exception ex)
Expand All @@ -145,9 +151,8 @@ public void Configuration(IAppBuilder app)
// Enable GSF role-based security authentication
app.UseAuthentication(AuthenticationOptions);

// Enable cross-domain scripting default policy - controllers can manually
// apply "EnableCors" attribute to class or an action to override default
// policy configured here
// Enable cross-domain scripting default policy - controllers can manually apply
// "EnableCors" attribute to class or an action to override default policy configured here
try
{
if (!string.IsNullOrWhiteSpace(model.Global.DefaultCorsOrigins))
Expand Down Expand Up @@ -180,6 +185,12 @@ public void Configuration(IAppBuilder app)
{
using (new GrafanaController()) { }

using (new DeviceController()) { }

using (new PhasorController()) { }

using (new DevicePhasorController()) { }

httpConfig.Routes.MapHttpRoute(
name: "CustomAPIs",
routeTemplate: "api/{controller}/{action}/{id}",
Expand Down Expand Up @@ -208,8 +219,8 @@ private void Load_ModbusAssembly()
{
try
{
// Wrap class reference in lambda function to force
// assembly load errors to occur within the try-catch
// Wrap class reference in lambda function to force assembly load errors to occur
// within the try-catch
new Action(() =>
{
// Make embedded resources of Modbus poller available to web server
Expand All @@ -224,12 +235,7 @@ private void Load_ModbusAssembly()
Program.Host.LogException(new InvalidOperationException($"Failed to load Modbus assembly: {ex.Message}", ex));
}
}

// Static Properties

/// <summary>
/// Gets the authentication options used for the hosted web server.
/// </summary>
public static AuthenticationOptions AuthenticationOptions { get; } = new AuthenticationOptions();
// Static Properties
}
}
}
14 changes: 14 additions & 0 deletions Source/Libraries/openPDC.Adapters/Constants/StringConstant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace openPDC.Adapters.Constants
{
internal static class StringConstant
{
#region [ Constants ]

internal const string Acronym = "Acronym";
internal const string DeviceID = "DeviceID";
internal const string SourceIndex = "SourceIndex";
internal const string SystemSettings = "systemSettings";

#endregion [ Constants ]
}
}
Loading