generated from gemstone/gemtem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConnectionParameters.cs
180 lines (160 loc) · 7.94 KB
/
ConnectionParameters.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//******************************************************************************************************
// ConnectionParameters.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:
// ----------------------------------------------------------------------------------------------------
// 02/26/2007 - J. Ritchie Carroll
// Generated original version of source code.
// 09/15/2009 - Stephen C. Wills
// Added new header and license agreement.
// 05/19/2011 - Ritchie
// Added DST file support.
// 12/17/2012 - Starlynn Danyelle Gilliam
// Modified Header.
//
//******************************************************************************************************
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization;
namespace Gemstone.PhasorProtocols.BPAPDCstream
{
// TODO: Determine how to support UI editors like these
///// <summary>
///// INI file name browser used with BPA PDCstream <see cref="ConnectionParameters"/>.
///// </summary>
//public class IniFileNameEditor : FileNameEditor
//{
// /// <summary>
// /// Initializes the open file dialog when it is created.
// /// </summary>
// /// <param name="openFileDialog">The <see cref="OpenFileDialog"/> to use to select a file name.</param>
// protected override void InitializeDialog(OpenFileDialog openFileDialog)
// {
// base.InitializeDialog(openFileDialog);
// // We override this function to customize file dialog...
// openFileDialog.Title = "Load BPA PDCstream INI Configuration File";
// openFileDialog.Filter = "INI Files (*.ini)|*.ini|All Files (*.*)|*.*";
// }
//}
/// <summary>
/// Represents the extra connection parameters required for a connection to a BPA PDCstream.
/// </summary>
/// <remarks>
/// This class is designed to be exposed by a "PropertyGrid" so a UI can request protocol specific connection parameters.
/// As a result the <see cref="CategoryAttribute"/> and <see cref="DescriptionAttribute"/> elements should be defined for
/// each of the exposed properties.
/// </remarks>
[Serializable]
public class ConnectionParameters : ConnectionParametersBase
{
#region [ Members ]
// Fields
private string? m_configurationFileName;
private bool m_refreshConfigurationFileOnChange;
private bool m_parseWordCountFromByte;
private bool m_usePhasorDataFileFormat;
#endregion
#region [ Constructors ]
/// <summary>
/// Creates a new <see cref="ConnectionParameters"/>.
/// </summary>
public ConnectionParameters()
{
m_refreshConfigurationFileOnChange = false;
}
/// <summary>
/// Creates a new <see cref="ConnectionParameters"/> from serialization parameters.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> with populated with data.</param>
/// <param name="context">The source <see cref="StreamingContext"/> for this deserialization.</param>
protected ConnectionParameters(SerializationInfo info, StreamingContext context)
{
// Deserialize connection parameters
m_configurationFileName = info.GetOrDefault("configurationFileName", (string?)null);
m_refreshConfigurationFileOnChange = info.GetOrDefault("refreshConfigurationFileOnChange", false);
m_parseWordCountFromByte = info.GetOrDefault("parseWordCountFromByte", false);
m_usePhasorDataFileFormat = info.GetOrDefault("usePhasorDataFileFormat", false);
}
#endregion
#region [ Properties ]
/// <summary>
/// Gets or sets required external BPA PDCstream INI based configuration file.
/// </summary>
[Category("Required Connection Parameters")]
[Description("Defines required external BPA PDCstream INI based configuration file.")]
//[Editor(typeof(IniFileNameEditor), typeof(UITypeEditor))]
public string? ConfigurationFileName
{
get => m_configurationFileName;
set => m_configurationFileName = value;
}
/// <summary>
/// Gets or sets flag that interprets word count in packet header from a byte instead of a word.
/// </summary>
[Category("Required Connection Parameters")]
[Description("Set to True to interpret word count in packet header from a byte instead of a word - if the sync byte (0xAA) is at position one, then the word count would be interpreted from byte four. Some older BPA PDC stream implementations have a 0x01 in byte three where there should be a 0x00 and this throws off the frame length, setting this property to True will correctly interpret the word count.")]
[DefaultValue(false)]
public bool ParseWordCountFromByte
{
get => m_parseWordCountFromByte;
set => m_parseWordCountFromByte = value;
}
/// <summary>
/// Gets or sets flag that determines if configuration file is automatically reloaded when it has changed on disk.
/// </summary>
[Category("Optional Connection Parameters")]
[Description("Set to True to automatically reload configuration file when it has changed on disk.")]
[DefaultValue(true)]
public bool RefreshConfigurationFileOnChange
{
get => m_refreshConfigurationFileOnChange;
set => m_refreshConfigurationFileOnChange = value;
}
/// <summary>
/// Gets or sets flag that determines if source data is in the Phasor Data File Format (i.e., a DST file).
/// </summary>
[Category("Optional Connection Parameters")]
[Description("Set to True to use the Phasor Data File Format (i.e., use a DST file).")]
[DefaultValue(false)]
public bool UsePhasorDataFileFormat
{
get => m_usePhasorDataFileFormat;
set => m_usePhasorDataFileFormat = value;
}
/// <summary>
/// Determines if selected BPA PDCstream configuration file exists.
/// </summary>
[Browsable(false)]
public override bool ValuesAreValid => File.Exists(m_configurationFileName);
#endregion
#region [ Methods ]
/// <summary>
/// Populates a <see cref="SerializationInfo"/> with the data needed to serialize the target object.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> to populate with data.</param>
/// <param name="context">The destination <see cref="StreamingContext"/> for this serialization.</param>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
// Serialize connection parameters
info.AddValue("configurationFileName", m_configurationFileName);
info.AddValue("refreshConfigurationFileOnChange", m_refreshConfigurationFileOnChange);
info.AddValue("parseWordCountFromByte", m_parseWordCountFromByte);
info.AddValue("usePhasorDataFileFormat", m_usePhasorDataFileFormat);
}
#endregion
}
}