123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using System;
- using System.Runtime.Serialization;
- namespace WingCloudServer.GeneralDocTools.Model.Parameters
- {
- /// <summary>
- /// Range parameter base type
- /// </summary>
- /// <typeparam name="T">Type of T</typeparam>
- [DataContract]
- public abstract class RangeParameterBase<T> : IParameter where T : struct
- {
- private T _value;
- private T _initialValue;
- /// <summary>
- /// The value saved in setting file.Some times the value will be set but not saved to setting file.
- /// </summary>
- public T SavedValue { get; protected set; }
- /// <summary>
- /// value changed event
- /// </summary>
- public event EventHandler ValueChanged;
- /// <summary>
- /// Min value
- /// </summary>
- [DataMember]
- public T MinValue { get; set; }
- /// <summary>
- /// Max value
- /// </summary>
- [DataMember]
- public T MaxValue { get; set; }
- public T InitialValue => _initialValue;
- /// <summary>
- /// parameter value
- /// </summary>
- [DataMember]
- public T Value
- {
- get
- {
- return _value;
- }
- set
- {
- if (!Equals(_value, value))
- {
- _value = value;
- OnValueChanged();
- }
- }
- }
- /// <summary>
- /// parameter name
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// parameter section
- /// </summary>
- public string Section { get; set; }
- /// <summary>
- /// parameter value changed state
- /// </summary>
- public bool IsChanged => !Equals(_initialValue, Value);
- /// <summary>
- /// notify value changed
- /// </summary>
- private void OnValueChanged()
- {
- ValueChanged?.Invoke(this, EventArgs.Empty);
- }
- /// <summary>
- /// change initial value
- /// </summary>
- public void ChangeInitialValue()
- {
- _initialValue = Value;
- SavedValue = Value;
- }
- public void ChangeSavedValue()
- {
- SavedValue = Value;
- }
- /// <summary>
- /// Set user value.
- /// </summary>
- /// <param name="value">user value.</param>
- public abstract void ChangeParameterValue(object value);
- }
- /// <summary>
- /// Range long parameter.
- /// </summary>
- [DataContract]
- public class RangeLongParameter : RangeParameterBase<long>
- {
- public override void ChangeParameterValue(object value)
- {
- var longParameter = value as LongParameter;
- if (longParameter != null)
- {
- Value = longParameter.Value;
- SavedValue = Value;
- }
- }
- }
- /// <summary>
- /// Range int parameter.
- /// </summary>
- [DataContract]
- public class RangeIntParameter : RangeParameterBase<int>
- {
- public override void ChangeParameterValue(object value)
- {
- var intParameter = value as IntParameter;
- if (intParameter != null)
- {
- Value = intParameter.Value;
- SavedValue = Value;
- }
- }
- }
- }
|