924 lines · 38.3 KB · C#
RawDownload
//******************************************************************************************************//  Subscriber.cs - Gbtc////  Copyright © 2010, 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://www.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://  ----------------------------------------------------------------------------------------------------//  05/10/2011 - Magdiel Lorenzo//       Generated original version of source code.// 05/13/2011 - Aniket Salver//       Modified the way Guid is retrieved from the Data Base.// 05/20/2011 - Mehulbhai P Thakkar//       Added methods to retrieve, add and remove measurements and measurement groups.////****************************************************************************************************** using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.ComponentModel.DataAnnotations;using System.Data;using System.Net.Security;using System.Security.Cryptography.X509Certificates;using GSF.ComponentModel.DataAnnotations;using GSF.Data;using GSF.TimeSeries.UI;using GSF.TimeSeries.UI.DataModels; namespace GSF.TimeSeries.Transport.UI.DataModels{    /// <summary>    /// Represents a record of <see cref="Subscriber"/> information as defined in the database.    /// </summary>    public class Subscriber : DataModelBase    {        #region [ Members ]         // Fields        private Guid m_nodeID;        private Guid m_id;        private string m_acronym;        private string m_name;        private string m_sharedSecret;        private string m_authKey;        private string m_validIPAddresses;        private string m_remoteCertificateFile;        private bool m_remoteCertificateIsSelfSigned;        private SslPolicyErrors? m_validPolicyErrors;        private X509ChainStatusFlags? m_validChainFlags;        private bool m_enabled;        private DateTime m_createdOn;        private string m_createdBy;        private DateTime m_updatedOn;        private string m_updatedBy;         // Fields below are used only for Subscriber Measurements screen.        private Dictionary<int, string> m_allowedMeasurementGroups;        private Dictionary<int, string> m_deniedMeasurementGroups;        private Dictionary<int, string> m_availableMeasurementGroups;         // Fields below are used only for Subscriber Status screen.        private string m_statusColor;        private string m_version;        private string m_accessControlFilter;         #endregion         #region [ Properties ]         /// <summary>        /// Gets or sets <see cref="Subscriber"/>'s status color.        /// </summary>        public string StatusColor        {            get            {                return m_statusColor;            }            set            {                m_statusColor = value;                OnPropertyChanged("StatusColor");            }        }         /// <summary>        /// Gets or sets version information for <see cref="Subscriber"/>.        /// </summary>        public string Version        {            get            {                return m_version;            }            set            {                m_version = value;                OnPropertyChanged("Version");            }        }         /// <summary>        /// Gets or sets <see cref="Subscriber"/>'s allowed measurement groups.        /// </summary>        // Field is populated by many to many database relationship with measurementgroup table, so no validation applied.        public Dictionary<int, string> AllowedMeasurementGroups        {            get            {                return m_allowedMeasurementGroups;            }            set            {                m_allowedMeasurementGroups = value;                OnPropertyChanged("AllowedMeasurementGroups");            }        }         /// <summary>        /// Gets or sets <see cref="Subscriber"/>'s denied measurement groups.        /// </summary>        // Field is populated by many to many database relationship with measurementgroup table, so no validation applied.        public Dictionary<int, string> DeniedMeasurementGroups        {            get            {                return m_deniedMeasurementGroups;            }            set            {                m_deniedMeasurementGroups = value;                OnPropertyChanged("DeniedMeasurementGroups");            }        }         /// <summary>        /// Gets or sets <see cref="Subscriber"/>'s available measurement groups.        /// </summary>        // Field is populated by many to many database relationship with measurementgroup table, so no validation applied.        public Dictionary<int, string> AvailableMeasurementGroups        {            get            {                return m_availableMeasurementGroups;            }            set            {                m_availableMeasurementGroups = value;                OnPropertyChanged("AvailableMeasurementGroups");            }        }         /// <summary>        /// Gets or sets the current <see cref="Subscriber"/>'s node ID.        /// </summary>        [Required(ErrorMessage = "The Subscriber node ID is required, please provide value.")]        public Guid NodeID        {            get            {                return m_nodeID;            }            set            {                m_nodeID = value;                OnPropertyChanged("NodeID");            }        }         /// <summary>        /// Gets or sets the current <see cref="Subscriber"/>'s ID.        /// </summary>        public Guid ID        {            get            {                return m_id;            }            set            {                m_id = value;            }        }         /// <summary>        /// Gets or sets the current <see cref="Subscriber"/>'s acronym.        /// </summary>        [Required(ErrorMessage = "The Subscriber acronym is a required field, please provide a value.")]        [StringLength(200, ErrorMessage = "The subscriber acronym cannot exceed 200 characters.")]        [AcronymValidation]        public string Acronym        {            get            {                return m_acronym;            }            set            {                m_acronym = value;                OnPropertyChanged("Acronym");            }        }         /// <summary>        /// Gets or sets the current <see cref="Subscriber"/> name.        /// </summary>        [StringLength(200, ErrorMessage = "The subscriber name cannot exceed 200 characters.")]        public string Name        {            get            {                return m_name;            }            set            {                m_name = value;                OnPropertyChanged("Name");            }        }         /// <summary>        /// Gets or sets the current <see cref="Subscriber"/>'s shared secret.        /// </summary>        public string SharedSecret        {            get            {                return m_sharedSecret;            }            set            {                m_sharedSecret = value;                OnPropertyChanged("SharedSecret");            }        }         /// <summary>        /// Gets or sets the authorization key for the current <see cref="Subscriber"/>.        /// </summary>        public string AuthKey        {            get            {                return m_authKey;            }            set            {                m_authKey = value;                OnPropertyChanged("AuthKey");            }        }         /// <summary>        /// Gets or sets the valid IP addresses of the current <see cref="Subscriber"/>.        /// </summary>        public string ValidIPAddresses        {            get            {                return m_validIPAddresses;            }            set            {                m_validIPAddresses = value;                OnPropertyChanged("ValidIPAddresses");            }        }         /// <summary>        /// Gets or sets the path to the certificate file used to        /// validate the identity of the <see cref="Subscriber"/>.        /// </summary>        public string RemoteCertificateFile        {            get            {                return m_remoteCertificateFile;            }            set            {                m_remoteCertificateFile = value;                OnPropertyChanged("RemoteCertificateFile");            }        }         /// <summary>        /// Gets or sets the flag that indicates whether the remote certificate is self-signed.        /// </summary>        public bool RemoteCertificateIsSelfSigned        {            get            {                return m_remoteCertificateIsSelfSigned;            }            set            {                m_remoteCertificateIsSelfSigned = value;            }        }         /// <summary>        /// Gets or sets the policy errors which can be ignored        /// when validating <see cref="Subscriber"/> identity.        /// </summary>        public SslPolicyErrors? ValidPolicyErrors        {            get            {                return m_validPolicyErrors;            }            set            {                m_validPolicyErrors = value;                OnPropertyChanged("ValidPolicyErrors");            }        }         /// <summary>        /// Gets or sets the chain flags which can be ignored        /// when validating <see cref="Subscriber"/> identity.        /// </summary>        public X509ChainStatusFlags? ValidChainFlags        {            get            {                return m_validChainFlags;            }            set            {                m_validChainFlags = value;                OnPropertyChanged("ValidChainFlags");            }        }         /// <summary>        /// Gets or sets the filter used to determine which signals        /// this <see cref="Subscriber"/> is allowed to subscribe to.        /// </summary>        public string AccessControlFilter        {            get            {                return m_accessControlFilter;            }            set            {                m_accessControlFilter = value;                OnPropertyChanged("AccessControlFilter");            }        }         /// <summary>        /// Gets or sets whether the current <see cref="Subscriber"/> is enabled.        /// </summary>        public bool Enabled        {            get            {                return m_enabled;            }            set            {                m_enabled = value;                OnPropertyChanged("Enabled");            }        }         /// <summary>        /// Gets or sets when the current <see cref="Subscriber"/> was created.        /// </summary>        // Field is populated by trigger and has no screen interaction, so no validation attributes are applied.        public DateTime CreatedOn        {            get            {                return m_createdOn;            }            set            {                m_createdOn = value;            }        }         /// <summary>        /// Gets or sets who the current <see cref="Subscriber"/> was created by.        /// </summary>        // Field is populated by trigger and has no screen interaction, so no validation attributes are applied.        public string CreatedBy        {            get            {                return m_createdBy;            }            set            {                m_createdBy = value;            }        }         /// <summary>        /// Gets or sets when the current <see cref="Subscriber"/> was updated last.        /// </summary>        // Field is populated by trigger and has no screen interaction, so no validation attributes are applied.        public DateTime UpdatedOn        {            get            {                return m_updatedOn;            }            set            {                m_updatedOn = value;            }        }         /// <summary>        /// Gets or sets who the current <see cref="Subscriber"/> was updated by.        /// </summary>        // Field is populated by trigger and has no screen interaction, so no validation attributes are applied.        public string UpdatedBy        {            get            {                return m_updatedBy;            }            set            {                m_updatedBy = value;            }        }         #endregion         #region [ Static ]         /// <summary>        /// Loads <see cref="Node"/> information as an <see cref="ObservableCollection{T}"/> style list.        /// </summary>        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>                /// <returns>Collection of <see cref="Subscriber"/>.</returns>        public static ObservableCollection<Subscriber> Load(AdoDataConnection database)        {            ObservableCollection<Subscriber> subscriberList;            DataTable subscriberTable;            bool createdConnection = false;            string query;             SslPolicyErrors validPolicyErrors;            X509ChainStatusFlags validChainFlags;             try            {                createdConnection = CreateConnection(ref database);                subscriberList = new ObservableCollection<Subscriber>();                 query = database.ParameterizedQueryString("SELECT ID, NodeID, Acronym, Name, SharedSecret, AuthKey, ValidIPAddresses, RemoteCertificateFile," +                    " ValidPolicyErrors, ValidChainFlags, AccessControlFilter, Enabled FROM Subscriber WHERE NodeID = {0} ORDER BY Name", "nodeID");                 subscriberTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout, database.CurrentNodeID());                 foreach (DataRow row in subscriberTable.Rows)                {                    subscriberList.Add(new Subscriber()                    {                        ID = database.Guid(row, "ID"),                        NodeID = database.Guid(row, "NodeID"),                        Acronym = row.Field<string>("Acronym"),                        Name = row.Field<string>("Name"),                        SharedSecret = row.Field<string>("SharedSecret"),                        AuthKey = row.Field<string>("AuthKey"),                        ValidIPAddresses = row.Field<string>("ValidIPAddresses"),                        RemoteCertificateFile = row.Field<string>("RemoteCertificateFile"),                        ValidPolicyErrors = Enum.TryParse(row.Field<string>("ValidPolicyErrors"), out validPolicyErrors) ? validPolicyErrors : (SslPolicyErrors?)null,                        ValidChainFlags = Enum.TryParse(row.Field<string>("ValidChainFlags"), out validChainFlags) ? validChainFlags : (X509ChainStatusFlags?)null,                        AccessControlFilter = row.Field<string>("AccessControlFilter"),                        Enabled = Convert.ToBoolean(row.Field<object>("Enabled")),                        AllowedMeasurementGroups = GetAllowedMeasurementGroups(database, database.Guid(row, "ID")),                        DeniedMeasurementGroups = GetDeniedMeasurementGroups(database, database.Guid(row, "ID")),                        AvailableMeasurementGroups = GetAvailableMeasurementGroups(database, database.Guid(row, "ID")),                        StatusColor = "gray",                        Version = ""                    });                }                 return subscriberList;            }            finally            {                if (createdConnection && database != null)

Lines 1–500 of 924.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t