//******************************************************************************************************
// 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
{
///
/// Represents a record of information as defined in the database.
///
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 m_allowedMeasurementGroups;
private Dictionary m_deniedMeasurementGroups;
private Dictionary 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 ]
///
/// Gets or sets 's status color.
///
public string StatusColor
{
get
{
return m_statusColor;
}
set
{
m_statusColor = value;
OnPropertyChanged("StatusColor");
}
}
///
/// Gets or sets version information for .
///
public string Version
{
get
{
return m_version;
}
set
{
m_version = value;
OnPropertyChanged("Version");
}
}
///
/// Gets or sets 's allowed measurement groups.
///
// Field is populated by many to many database relationship with measurementgroup table, so no validation applied.
public Dictionary AllowedMeasurementGroups
{
get
{
return m_allowedMeasurementGroups;
}
set
{
m_allowedMeasurementGroups = value;
OnPropertyChanged("AllowedMeasurementGroups");
}
}
///
/// Gets or sets 's denied measurement groups.
///
// Field is populated by many to many database relationship with measurementgroup table, so no validation applied.
public Dictionary DeniedMeasurementGroups
{
get
{
return m_deniedMeasurementGroups;
}
set
{
m_deniedMeasurementGroups = value;
OnPropertyChanged("DeniedMeasurementGroups");
}
}
///
/// Gets or sets 's available measurement groups.
///
// Field is populated by many to many database relationship with measurementgroup table, so no validation applied.
public Dictionary AvailableMeasurementGroups
{
get
{
return m_availableMeasurementGroups;
}
set
{
m_availableMeasurementGroups = value;
OnPropertyChanged("AvailableMeasurementGroups");
}
}
///
/// Gets or sets the current 's node ID.
///
[Required(ErrorMessage = "The Subscriber node ID is required, please provide value.")]
public Guid NodeID
{
get
{
return m_nodeID;
}
set
{
m_nodeID = value;
OnPropertyChanged("NodeID");
}
}
///
/// Gets or sets the current 's ID.
///
public Guid ID
{
get
{
return m_id;
}
set
{
m_id = value;
}
}
///
/// Gets or sets the current 's acronym.
///
[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");
}
}
///
/// Gets or sets the current name.
///
[StringLength(200, ErrorMessage = "The subscriber name cannot exceed 200 characters.")]
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
OnPropertyChanged("Name");
}
}
///
/// Gets or sets the current 's shared secret.
///
public string SharedSecret
{
get
{
return m_sharedSecret;
}
set
{
m_sharedSecret = value;
OnPropertyChanged("SharedSecret");
}
}
///
/// Gets or sets the authorization key for the current .
///
public string AuthKey
{
get
{
return m_authKey;
}
set
{
m_authKey = value;
OnPropertyChanged("AuthKey");
}
}
///
/// Gets or sets the valid IP addresses of the current .
///
public string ValidIPAddresses
{
get
{
return m_validIPAddresses;
}
set
{
m_validIPAddresses = value;
OnPropertyChanged("ValidIPAddresses");
}
}
///
/// Gets or sets the path to the certificate file used to
/// validate the identity of the .
///
public string RemoteCertificateFile
{
get
{
return m_remoteCertificateFile;
}
set
{
m_remoteCertificateFile = value;
OnPropertyChanged("RemoteCertificateFile");
}
}
///
/// Gets or sets the flag that indicates whether the remote certificate is self-signed.
///
public bool RemoteCertificateIsSelfSigned
{
get
{
return m_remoteCertificateIsSelfSigned;
}
set
{
m_remoteCertificateIsSelfSigned = value;
}
}
///
/// Gets or sets the policy errors which can be ignored
/// when validating identity.
///
public SslPolicyErrors? ValidPolicyErrors
{
get
{
return m_validPolicyErrors;
}
set
{
m_validPolicyErrors = value;
OnPropertyChanged("ValidPolicyErrors");
}
}
///
/// Gets or sets the chain flags which can be ignored
/// when validating identity.
///
public X509ChainStatusFlags? ValidChainFlags
{
get
{
return m_validChainFlags;
}
set
{
m_validChainFlags = value;
OnPropertyChanged("ValidChainFlags");
}
}
///
/// Gets or sets the filter used to determine which signals
/// this is allowed to subscribe to.
///
public string AccessControlFilter
{
get
{
return m_accessControlFilter;
}
set
{
m_accessControlFilter = value;
OnPropertyChanged("AccessControlFilter");
}
}
///
/// Gets or sets whether the current is enabled.
///
public bool Enabled
{
get
{
return m_enabled;
}
set
{
m_enabled = value;
OnPropertyChanged("Enabled");
}
}
///
/// Gets or sets when the current was created.
///
// 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;
}
}
///
/// Gets or sets who the current was created by.
///
// 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;
}
}
///
/// Gets or sets when the current was updated last.
///
// 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;
}
}
///
/// Gets or sets who the current was updated by.
///
// 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 ]
///
/// Loads information as an style list.
///
/// to connection to database.
/// Collection of .
public static ObservableCollection Load(AdoDataConnection database)
{
ObservableCollection subscriberList;
DataTable subscriberTable;
bool createdConnection = false;
string query;
SslPolicyErrors validPolicyErrors;
X509ChainStatusFlags validChainFlags;
try
{
createdConnection = CreateConnection(ref database);
subscriberList = new ObservableCollection();
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("Acronym"),
Name = row.Field("Name"),
SharedSecret = row.Field("SharedSecret"),
AuthKey = row.Field("AuthKey"),
ValidIPAddresses = row.Field("ValidIPAddresses"),
RemoteCertificateFile = row.Field("RemoteCertificateFile"),
ValidPolicyErrors = Enum.TryParse(row.Field("ValidPolicyErrors"), out validPolicyErrors) ? validPolicyErrors : (SslPolicyErrors?)null,
ValidChainFlags = Enum.TryParse(row.Field("ValidChainFlags"), out validChainFlags) ? validChainFlags : (X509ChainStatusFlags?)null,
AccessControlFilter = row.Field("AccessControlFilter"),
Enabled = Convert.ToBoolean(row.Field