//******************************************************************************************************
// AdapterConnectionStringParameter.cs - Gbtc
//
// Copyright © 2012, 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:
// ----------------------------------------------------------------------------------------------------
// 06/09/2011 - Stephen C. Wills
// Generated original version of source code.
// 12/20/2012 - Starlynn Danyelle Gilliam
// Modified Header.
//
//******************************************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Media;
using GSF.TimeSeries.Adapters;
namespace GSF.TimeSeries.UI.ViewModels
{
///
/// View-model for a key-value pair in an adapter connection string.
/// This can also represent key-value pairs which aren't necessarily
/// in the connection string, but rather are defined by properties
/// in an adapter class. This view-model is used by the
/// .
///
public class AdapterConnectionStringParameter : ViewModelBase
{
#region [ Members ]
// Fields
private PropertyInfo m_info;
private string m_name;
private string m_description;
private object m_value;
private object m_defaultValue;
private bool m_isRequired;
#endregion
#region [ Properties ]
///
/// Gets or sets the of the
///
/// associated with this .
///
public PropertyInfo Info
{
get
{
return m_info;
}
set
{
m_info = value;
OnPropertyChanged("Info");
}
}
///
/// Gets or sets the name of the
/// which is either a key in the connection string or the name of a property in
/// the adapter class.
///
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
OnPropertyChanged("Name");
}
}
///
/// Gets or sets the description of the
/// obtained through the using reflection. A property annotated with
///
/// must also define a for this
/// to become populated.
///
public string Description
{
get
{
return m_description;
}
set
{
m_description = value;
OnPropertyChanged("Description");
}
}
///
/// Gets or sets the value of the as defined
/// by either the connection string or the of the parameter.
///
public object Value
{
get
{
return m_value ?? m_defaultValue;
}
set
{
m_value = value;
OnPropertyChanged("Value");
OnPropertyChanged("Color");
OnPropertyChanged("Boldness");
}
}
///
/// Gets or sets the default value of the
/// obtained through the using reflection. A property annotated with
/// must
/// also define a for this to
/// be populated.
///
public object DefaultValue
{
get
{
return m_defaultValue;
}
set
{
m_defaultValue = value;
OnPropertyChanged("DefaultValue");
}
}
///
/// Gets or sets a value that indicates whether this parameter is defined by a property
/// that is annotated with the .
///
public bool IsRequired
{
get
{
return m_isRequired;
}
set
{
m_isRequired = value;
OnPropertyChanged("IsRequired");
}
}
///
/// Gets or sets the color of the item in the
/// that the is modeling.
///
public Brush Color
{
get
{
bool red = m_isRequired && (m_value == null);
return red ? Brushes.Red : Brushes.Black;
}
}
///
/// Gets or sets the boldness of the item in the that the
/// is modeling.
///
public FontWeight Boldness
{
get
{
return (m_value == null) ? FontWeights.Normal : FontWeights.Bold;
}
}
///
/// Gets a list of enum types if this 's type is an enum.
/// If it is not an enum, this returns null.
///
public List EnumValues
{
get
{
if (!IsEnum)
return null;
return Enum.GetValues(m_info.PropertyType)
.Cast