@******************************************************************************************************* // AddSynchrophasorDevice.cshtml - Gbtc // // Copyright © 2019, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this // file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 02/18/2019 - J. Ritchie Carroll // Generated original version of source code. // //****************************************************************************************************** // To use in ASP.NET project, include a AddSynchrophasorDevice.cshtml view with the following: // // @using GSF.Web // @section StyleSheets{@Html.Raw(ViewBag.StyleSheetsSection?.ToString())} // @Html.RenderResource("PhasorWebUI.Views.AddSynchrophasorDevice.cshtml") // @section Scripts{@Html.Raw(ViewBag.ScriptsSection?.ToString())} // //****************************************************************************************************** // To use in self-hosted web project, include a AddSynchrophasorDevice.cshtml view with the following: // // @using GSF.Web.Model // @using .Model // @inherits ExtendedTemplateBase // @section StyleSheets{@Html.Raw(ViewBag.StyleSheetsSection.ToString())} // @{Layout = "Layout.cshtml";} // @Html.RenderResource("PhasorWebUI.AddSynchrophasorDevice.cshtml") // @section Scripts{@Html.Raw(ViewBag.ScriptsSection.ToString())} //*****************************************************************************************************@ @* ReSharper disable UnknownCssClass *@ @* ReSharper disable Html.PathError *@ @* ReSharper disable InlineOutVariableDeclaration *@ @* ReSharper disable ArrangeAccessorOwnerBody *@ @using System @using System.Collections.Generic @using System.ComponentModel @using System.Net.Http @using System.Text.RegularExpressions @using System.Threading @using GSF.ComponentModel @using GSF.ComponentModel.DataAnnotations @using GSF.Identity @using GSF.Security @using GSF.Web @using GSF.Web.Model @using GSF.Web.Shared @inherits ExtendedTemplateBase @{ // Layout will depend on rendering environment, so do not specify one ViewBag.HidePageTitle = true; ViewBag.Title = "New Device Commissioning Wizard"; HttpRequestMessage request = ViewBag.Request; Dictionary parameters = request.QueryParameters(); string parameter; int deviceID; if (!parameters.TryGetValue("DeviceID", out parameter) || !int.TryParse(parameter, out deviceID)) { deviceID = 0; } bool userIsEditor = UserIsEditor(); } @section StyleSheets { } @functions { private static Dictionary s_appModelGlobal; private static Guid s_nodeID; private static string s_companyAcronym; private static double s_defaultCalculationLagTime; private static double s_defaultCalculationLeadTime; private static int s_nominalFrequency; private static string s_systemName; // Quasi-Static Properties private Dictionary AppModelGlobal { get { if (s_appModelGlobal != null) return s_appModelGlobal; s_appModelGlobal = new Dictionary(); ExpressionEvaluator.ValueType global = ValueExpressionParser.DefaultTypeRegistry["Global"] as ExpressionEvaluator.ValueType; if (global == null) return s_appModelGlobal; foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(global.Value)) { s_appModelGlobal.Add(propertyDescriptor.Name, propertyDescriptor.GetValue(global.Value)); } return s_appModelGlobal; } } private Guid NodeID { get { return s_nodeID != default(Guid) ? s_nodeID : s_nodeID = (Guid)AppModelGlobal["NodeID"]; } } private string CompanyAcronym { get { return !string.IsNullOrWhiteSpace(s_companyAcronym) ? s_companyAcronym : s_companyAcronym = (string)AppModelGlobal["CompanyAcronym"]; } } private double DefaultCalculationLagTime { get { return s_defaultCalculationLagTime != default(double) ? s_defaultCalculationLagTime : s_defaultCalculationLagTime = (double)AppModelGlobal["DefaultCalculationLagTime"]; } } private double DefaultCalculationLeadTime { get { return s_defaultCalculationLeadTime != default(double) ? s_defaultCalculationLeadTime : s_defaultCalculationLeadTime = (double)AppModelGlobal["DefaultCalculationLeadTime"]; } } private int NominalFrequency { get { return s_nominalFrequency != default(int) ? s_nominalFrequency : s_nominalFrequency = (int)AppModelGlobal["NominalFrequency"]; } } private string SystemName { get { if (s_systemName == default(string)) { object value; if (AppModelGlobal.TryGetValue("SystemName", out value)) { s_systemName = (string)value; if (s_systemName != null) s_systemName = Regex.Replace(s_systemName.Trim().ToUpperInvariant(), @"[^A-Z0-9\-!_\.@#\$]+", "_", RegexOptions.Compiled); if (!string.IsNullOrWhiteSpace(s_systemName)) s_systemName = s_systemName + "!"; } if (s_systemName == null) s_systemName = ""; } return s_systemName; } } private string GetCurrentUserID() { if (Thread.CurrentPrincipal.Identity == null) return UserInfo.CurrentUserID; return Thread.CurrentPrincipal.Identity.Name; } // This function simply limits access to UI elements that the user does not have access to, server-side // functions will further validate user rights even if UI restriction was somehow bypassed private bool UserIsEditor() { SecurityPrincipal securityPrincipal = ViewBag.SecurityPrincipal as SecurityPrincipal; if (securityPrincipal == null) return false; return securityPrincipal.IsInRole("Administrator") || securityPrincipal.IsInRole("Editor"); } } @section Scripts { }

@ViewBag.Title Instance: 

@* Connection Settings and Status Panel *@
     

@if (userIsEditor) {
} else {
User "@GetCurrentUserID()" does not have rights to add or modify device data.
}
@**@
@if (userIsEditor) {
}
Loading  
@* JSON Serialized Configuration Display Panel *@

    
@* TCP Connection String Builder *@ @* UDP Connection String Builder *@ @* Serial Connection String Builder *@ @* Device Name String Builder *@ @{ ViewBag.StyleSheetsSection = RenderSection("StyleSheets").ToString(); ViewBag.ScriptsSection = RenderSection("Scripts").ToString(); }