StockSharp

Форк
0
/
ExchangeBoard.cs 
268 строк · 6.9 Кб
1
#region S# License
2
/******************************************************************************************
3
NOTICE!!!  This program and source code is owned and licensed by
4
StockSharp, LLC, www.stocksharp.com
5
Viewing or use of this code requires your acceptance of the license
6
agreement found at https://github.com/StockSharp/StockSharp/blob/master/LICENSE
7
Removal of this comment is a violation of the license agreement.
8

9
Project: StockSharp.BusinessEntities.BusinessEntities
10
File: ExchangeBoard.cs
11
Created: 2015, 11, 11, 2:32 PM
12

13
Copyright 2010 by StockSharp, LLC
14
*******************************************************************************************/
15
#endregion S# License
16
namespace StockSharp.BusinessEntities
17
{
18
	using System;
19
	using System.ComponentModel;
20
	using System.ComponentModel.DataAnnotations;
21
	using System.Runtime.Serialization;
22
	using System.Xml;
23
	using System.Xml.Serialization;
24
	using System.Runtime.CompilerServices;
25

26
	using Ecng.Common;
27
	using Ecng.Serialization;
28

29
	using StockSharp.Messages;
30
	using StockSharp.Localization;
31

32
	/// <summary>
33
	/// Information about electronic board.
34
	/// </summary>
35
	[Serializable]
36
	[DataContract]
37
	public partial class ExchangeBoard : Equatable<ExchangeBoard>, IPersistable, INotifyPropertyChanged
38
	{
39
		/// <summary>
40
		/// Initializes a new instance of the <see cref="ExchangeBoard"/>.
41
		/// </summary>
42
		public ExchangeBoard()
43
		{
44
		}
45

46
		private string _code = string.Empty;
47

48
		/// <summary>
49
		/// Board code.
50
		/// </summary>
51
		[DataMember]
52
		[Display(
53
			ResourceType = typeof(LocalizedStrings),
54
			Name = LocalizedStrings.CodeKey,
55
			Description = LocalizedStrings.BoardCodeKey + LocalizedStrings.Dot,
56
			GroupName = LocalizedStrings.GeneralKey
57
		)]
58
		public string Code
59
		{
60
			get => _code;
61
			set
62
			{
63
				if (Code == value)
64
					return;
65

66
				_code = value ?? throw new ArgumentNullException(nameof(value));
67
				Notify();
68
			}
69
		}
70

71
		private TimeSpan _expiryTime;
72

73
		/// <summary>
74
		/// Securities expiration times.
75
		/// </summary>
76
		//[TimeSpan]
77
		[DataMember]
78
		[Display(
79
			ResourceType = typeof(LocalizedStrings),
80
			Name = LocalizedStrings.ExpiryDateKey,
81
			Description = LocalizedStrings.SecExpirationTimeKey,
82
			GroupName = LocalizedStrings.GeneralKey
83
		)]
84
		[XmlIgnore]
85
		public TimeSpan ExpiryTime
86
		{
87
			get => _expiryTime;
88
			set
89
			{
90
				if (ExpiryTime == value)
91
					return;
92

93
				_expiryTime = value;
94
				Notify();
95
			}
96
		}
97

98
		/// <summary>
99
		/// Reserved.
100
		/// </summary>
101
		[Browsable(false)]
102
		[XmlElement(DataType = "duration", ElementName = nameof(ExpiryTime))]
103
		public string ExpiryTimeStr
104
		{
105
			// XmlSerializer does not support TimeSpan, so use this property for
106
			// serialization instead.
107
			get => XmlConvert.ToString(ExpiryTime);
108
			set => ExpiryTime = value.IsEmpty() ? TimeSpan.Zero : XmlConvert.ToTimeSpan(value);
109
		}
110

111
		/// <summary>
112
		/// Exchange, where board is situated.
113
		/// </summary>
114
		[DataMember]
115
		[Display(
116
			ResourceType = typeof(LocalizedStrings),
117
			Name = LocalizedStrings.ExchangeInfoKey,
118
			Description = LocalizedStrings.BoardExchangeKey,
119
			GroupName = LocalizedStrings.GeneralKey
120
		)]
121
		public Exchange Exchange { get; set; }
122

123
		private WorkingTime _workingTime = new() { IsEnabled = true };
124

125
		/// <summary>
126
		/// Board working hours.
127
		/// </summary>
128
		[DataMember]
129
		[Display(
130
			ResourceType = typeof(LocalizedStrings),
131
			Name = LocalizedStrings.WorkingTimeKey,
132
			Description = LocalizedStrings.WorkingHoursKey,
133
			GroupName = LocalizedStrings.GeneralKey
134
		)]
135
		public WorkingTime WorkingTime
136
		{
137
			get => _workingTime;
138
			set
139
			{
140
				if (WorkingTime == value)
141
					return;
142

143
				_workingTime = value ?? throw new ArgumentNullException(nameof(value));
144
				Notify();
145
			}
146
		}
147

148
		[field: NonSerialized]
149
		private TimeZoneInfo _timeZone = TimeZoneInfo.Utc;
150

151
		/// <summary>
152
		/// Information about the time zone where the exchange is located.
153
		/// </summary>
154
		[XmlIgnore]
155
		//[DataMember]
156
		public TimeZoneInfo TimeZone
157
		{
158
			get => _timeZone;
159
			set
160
			{
161
				if (TimeZone == value)
162
					return;
163

164
				_timeZone = value ?? throw new ArgumentNullException(nameof(value));
165
				Notify();
166
			}
167
		}
168

169
		/// <summary>
170
		/// Reserved.
171
		/// </summary>
172
		[Browsable(false)]
173
		[DataMember]
174
		public string TimeZoneStr
175
		{
176
			get => TimeZone.To<string>();
177
			set => TimeZone = value.To<TimeZoneInfo>();
178
		}
179

180
		[field: NonSerialized]
181
		private PropertyChangedEventHandler _propertyChanged;
182

183
		event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
184
		{
185
			add => _propertyChanged += value;
186
			remove => _propertyChanged -= value;
187
		}
188

189
		private void Notify([CallerMemberName]string propertyName = null)
190
		{
191
			_propertyChanged?.Invoke(this, propertyName);
192
		}
193

194
		/// <inheritdoc />
195
		public override string ToString()
196
		{
197
			return "{0} ({1})".Put(Code, Exchange);
198
		}
199

200
		/// <summary>
201
		/// Compare <see cref="ExchangeBoard"/> on the equivalence.
202
		/// </summary>
203
		/// <param name="other">Another value with which to compare.</param>
204
		/// <returns><see langword="true" />, if the specified object is equal to the current object, otherwise, <see langword="false" />.</returns>
205
		protected override bool OnEquals(ExchangeBoard other)
206
		{
207
			return Code == other.Code && Exchange == other.Exchange;
208
		}
209

210
		private int _hashCode;
211

212
		/// <summary>
213
		/// Get the hash code of the object <see cref="ExchangeBoard"/>.
214
		/// </summary>
215
		/// <returns>A hash code.</returns>
216
		public override int GetHashCode()
217
		{
218
			if (_hashCode == 0)
219
				_hashCode = Code.GetHashCode() ^ (Exchange == null ? 0 : Exchange.GetHashCode());
220

221
			return _hashCode;
222
		}
223

224
		/// <summary>
225
		/// Create a copy of <see cref="ExchangeBoard"/>.
226
		/// </summary>
227
		/// <returns>Copy.</returns>
228
		public override ExchangeBoard Clone()
229
		{
230
			return new ExchangeBoard
231
			{
232
				Exchange = Exchange,
233
				Code = Code,
234
				ExpiryTime = ExpiryTime,
235
				WorkingTime = WorkingTime.Clone(),
236
				TimeZone = TimeZone,
237
			};
238
		}
239

240
		/// <summary>
241
		/// Load settings.
242
		/// </summary>
243
		/// <param name="storage">Settings storage.</param>
244
		public void Load(SettingsStorage storage)
245
		{
246
			Exchange = storage.GetValue<SettingsStorage>(nameof(Exchange))?.Load<Exchange>();
247
			Code = storage.GetValue<string>(nameof(Code));
248
			ExpiryTime = storage.GetValue<TimeSpan>(nameof(ExpiryTime));
249
			WorkingTime = storage.GetValue<SettingsStorage>(nameof(WorkingTime)).Load<WorkingTime>();
250
			TimeZone = storage.GetValue(nameof(TimeZone), TimeZone);
251
		}
252

253
		/// <summary>
254
		/// Save settings.
255
		/// </summary>
256
		/// <param name="storage">Settings storage.</param>
257
		public void Save(SettingsStorage storage)
258
		{
259
			storage.SetValue(nameof(Exchange), Exchange?.Save());
260
			storage.SetValue(nameof(Code), Code);
261
			//storage.SetValue(nameof(IsSupportMarketOrders), IsSupportMarketOrders);
262
			//storage.SetValue(nameof(IsSupportAtomicReRegister), IsSupportAtomicReRegister);
263
			storage.SetValue(nameof(ExpiryTime), ExpiryTime);
264
			storage.SetValue(nameof(WorkingTime), WorkingTime.Save());
265
			storage.SetValue(nameof(TimeZone), TimeZone);
266
		}
267
	}
268
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.