Commit 377b3c2c authored by Greg Pettyjohn's avatar Greg Pettyjohn
Browse files

Added finishing touches to the code. Getting it ready for a pull request

parent a49bab94
Loading
Loading
Loading
Loading
+105 −0
Original line number Diff line number Diff line
//----------------------------------------------------------------------------------------------
// <copyright file="BooleanConverter.cs" company="Microsoft Corporation">
//     Licensed under the MIT License. See LICENSE.TXT in the project root license information.
// </copyright>
//----------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace SampleDeviceCollection
{
    //-------------------------------------------------------------------
    //  Boolean Converter
    //-------------------------------------------------------------------
    #region Boolean Converter
    /// <summary>
    ///     Template allows for easy creation of a value converter for bools
    /// </summary>
    /// <typeparam name="T">Type to convert back and forth to boolean</typeparam>
    /// <remarks>
    ///     See BooleanToVisibilityConverter and BooleanToBrushConverter (below) and usage in Generic.xaml
    /// </remarks>
    public class BooleanConverter<T> : IValueConverter
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="BooleanConverter{T}" /> class.
        /// </summary>
        /// <param name="trueValue">The value of type T that represents true</param>
        /// <param name="falseValue">The value of type T that represents false</param>
        public BooleanConverter(T trueValue, T falseValue)
        {
            this.True = trueValue;
            this.False = falseValue;
        }

        /// <summary>
        /// Gets or sets the value that represents true
        /// </summary>
        public T True { get; set; }

        /// <summary>
        /// Gets or sets the value that represetns false
        /// </summary>
        public T False { get; set; }

        /// <summary>
        /// Convert an object of type T to boolean
        /// </summary>
        /// <param name="value">Object of type T to convert</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>Object of boolean value</returns>
        public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value is bool && ((bool)value) ? this.True : this.False;
        }

        /// <summary>
        /// Convert a boolean value to an object of type T
        /// </summary>
        /// <param name="value">The boolean value to convert</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>Object of type T</returns>
        public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value is T && EqualityComparer<T>.Default.Equals((T)value, this.True);
        }
    }

    /// <summary>
    /// Converter between a boolean and visibility value
    /// </summary>
    [type: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Small classes are all instances of the same generic and are better organized in a single file.")]
    public sealed class BooleanToVisibilityConverter : BooleanConverter<Visibility>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="BooleanToVisibilityConverter" /> class.
        /// </summary>
        public BooleanToVisibilityConverter() :
            base(Visibility.Visible, Visibility.Hidden)
        {
        }
    }

    /// <summary>
    /// Converter between a boolean and either "http" or "https"
    /// </summary>
    [type: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Small classes are all instances of the same generic and are better organized in a single file.")]
    public sealed class BooleanToHttpsConverter : BooleanConverter<string>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="BooleanToHttpsConverter" /> class.
        /// </summary>
        public BooleanToHttpsConverter() :
            base("https", "http")
        {
        }
    }
    #endregion // Boolean Converter
}
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@
                                        <TextBlock Margin="0,0,4,0" Text="Device Name:" />
                                        <TextBlock Text="{Binding DeviceName}"/>
                                        <TextBlock Margin="50,0,4,0" Text="Cannonical Device Address:" />
                                        <TextBlock Text="{Binding CannonicalIpAddress}"/>
                                        <TextBlock Text="{Binding Address}"/>
                                        <Button
                                            DockPanel.Dock="Right"
                                            Height="16" Width="16"
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@
      <SubType>Designer</SubType>
    </ApplicationDefinition>
    <Compile Include="Controls\AutoScrollTextBox.cs" />
    <Compile Include="BooleanConverter.cs" />
    <Compile Include="ViewModels\CommandSequence.cs" />
    <Compile Include="ViewModels\DiagnosticSinks.cs" />
    <Compile Include="ViewModels\ObservableCommandQueue.cs" />
+5 −0
Original line number Diff line number Diff line
@@ -7,6 +7,11 @@
            <BooleanProperty Name="Enabled">False</BooleanProperty>
          </RuleSettings>
        </Rule>
        <Rule Name="EnumerationItemsMustBeDocumented">
          <RuleSettings>
            <BooleanProperty Name="Enabled">False</BooleanProperty>
          </RuleSettings>
        </Rule>
      </Rules>
      <AnalyzerSettings />
    </Analyzer>
+5 −5
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ namespace SampleDeviceCollection
        /// <summary>
        /// Initializes a new instance of the <see cref="DevicePortalCommandModel" /> class.
        /// </summary>
        /// <param name="portal">DevicePortal object enscapsulated by this</param>
        /// <param name="connection">IDevicePortalConnection object used for connecting</param>
        /// <param name="diags">Diagnostic sink for reporting</param>
        public DevicePortalCommandModel(IDevicePortalConnection connection, IDiagnosticSink diags)
        {
@@ -47,12 +47,12 @@ namespace SampleDeviceCollection
        //-------------------------------------------------------------------
        #region Class Members
        /// <summary>
        ///  The DevicePortal object encapsulated by this class
        ///  Gets or sets the DevicePortal object encapsulated by this class
        /// </summary>
        public DevicePortal Portal { get; protected set; }

        /// <summary>
        /// The IDevicePortalConnection object encapsulated by this class
        /// Gets or sets the IDevicePortalConnection object encapsulated by this class
        /// </summary>
        public IDevicePortalConnection Connection { get; protected set; }
        #endregion // Class Members
@@ -93,7 +93,7 @@ namespace SampleDeviceCollection
        {
            get
            {
                return this.Portal == null ? "<unknown>" : this.Portal.Address;
                return this.Portal == null ? "<unknown>" : this.Portal.Address.Split(':')[0];
            }
        }
        #endregion // Address
@@ -165,7 +165,7 @@ namespace SampleDeviceCollection
        /// <summary>
        /// Clears the shared command queue
        /// </summary>
        protected void ClearCommandQueue()
        public void ClearCommandQueue()
        {
            this.commandQueue.Clear();
        }
Loading