|
|
|
@ -7,14 +7,29 @@ using System.Text; |
|
|
|
|
|
|
|
|
|
namespace rabi_splitter_WPF |
|
|
|
|
{ |
|
|
|
|
public class ExportableVariable |
|
|
|
|
public class ExportableVariable<T> : ExportableVariable |
|
|
|
|
{ |
|
|
|
|
private readonly Func<T> tracker; |
|
|
|
|
|
|
|
|
|
public ExportableVariable(string displayName, Func<T> tracker) : base(displayName) |
|
|
|
|
{ |
|
|
|
|
this.tracker = tracker; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal override VariableTracker GetTracker() |
|
|
|
|
{ |
|
|
|
|
return new VariableTracker<T>(tracker); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public abstract class ExportableVariable |
|
|
|
|
{ |
|
|
|
|
// Do not make these properties public. |
|
|
|
|
private static int nextAvailableId = 0; |
|
|
|
|
private readonly int _id; |
|
|
|
|
private readonly string _displayName; |
|
|
|
|
|
|
|
|
|
private ExportableVariable(string displayName) |
|
|
|
|
protected ExportableVariable(string displayName) |
|
|
|
|
{ |
|
|
|
|
_id = nextAvailableId++; |
|
|
|
|
_displayName = displayName; |
|
|
|
@ -30,11 +45,13 @@ namespace rabi_splitter_WPF |
|
|
|
|
get { return _displayName; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal abstract VariableTracker GetTracker(); |
|
|
|
|
|
|
|
|
|
public static List<ExportableVariable> GetAll() |
|
|
|
|
{ |
|
|
|
|
return new List<ExportableVariable>() |
|
|
|
|
{ |
|
|
|
|
new ExportableVariable("TestVariable") |
|
|
|
|
new ExportableVariable<int>("TestVariable", () => 1) |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -53,14 +70,96 @@ namespace rabi_splitter_WPF |
|
|
|
|
#endregion |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class VariableTracker<T> : VariableTracker |
|
|
|
|
{ |
|
|
|
|
private readonly Func<T> tracker; |
|
|
|
|
private T currentValue; |
|
|
|
|
|
|
|
|
|
public VariableTracker(Func<T> tracker) |
|
|
|
|
{ |
|
|
|
|
this.tracker = tracker; |
|
|
|
|
forceUpdate = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override bool CheckForUpdate() |
|
|
|
|
{ |
|
|
|
|
T newValue = tracker(); |
|
|
|
|
if (forceUpdate || !newValue.Equals(currentValue)) |
|
|
|
|
{ |
|
|
|
|
currentValue = newValue; |
|
|
|
|
forceUpdate = false; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override object GetValue() |
|
|
|
|
{ |
|
|
|
|
return currentValue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public abstract class VariableTracker |
|
|
|
|
{ |
|
|
|
|
protected bool forceUpdate; |
|
|
|
|
|
|
|
|
|
public void FormatChanged() |
|
|
|
|
{ |
|
|
|
|
forceUpdate = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public abstract bool CheckForUpdate(); |
|
|
|
|
public abstract object GetValue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class VariableExportSetting : INotifyPropertyChanged |
|
|
|
|
{ |
|
|
|
|
private ExportableVariable _selectedVariable; |
|
|
|
|
private VariableTracker _variableTracker; |
|
|
|
|
private string _outputFileName; |
|
|
|
|
private string _outputFormat; |
|
|
|
|
private string _formatPreview; |
|
|
|
|
private bool _isExporting; |
|
|
|
|
private bool _isPreviewingFormat; |
|
|
|
|
|
|
|
|
|
public VariableExportSetting() |
|
|
|
|
{ |
|
|
|
|
// Default values |
|
|
|
|
_selectedVariable = null; |
|
|
|
|
_outputFileName = ""; |
|
|
|
|
_outputFormat = ""; |
|
|
|
|
_isExporting = false; |
|
|
|
|
_isPreviewingFormat = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region Logic |
|
|
|
|
private string FormatOutput() |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
return string.Format(_outputFormat, _variableTracker.GetValue()); |
|
|
|
|
} |
|
|
|
|
catch (FormatException e) |
|
|
|
|
{ |
|
|
|
|
return e.Message; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal void OutputUpdate() |
|
|
|
|
{ |
|
|
|
|
if (_variableTracker == null) return; |
|
|
|
|
var formattedOutput = FormatOutput(); |
|
|
|
|
FormatPreview = formattedOutput; |
|
|
|
|
// TODO: Write to file |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal bool CheckForUpdate() |
|
|
|
|
{ |
|
|
|
|
if (_variableTracker == null) return false; |
|
|
|
|
return _variableTracker.CheckForUpdate(); |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region Dictionaries |
|
|
|
|
private static Dictionary<ExportableVariable, string> _variableCaptions; |
|
|
|
|
|
|
|
|
@ -83,16 +182,6 @@ namespace rabi_splitter_WPF |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
public VariableExportSetting() |
|
|
|
|
{ |
|
|
|
|
// Default values |
|
|
|
|
_selectedVariable = null; |
|
|
|
|
_outputFileName = ""; |
|
|
|
|
_outputFormat = ""; |
|
|
|
|
_isExporting = false; |
|
|
|
|
_isPreviewingFormat = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region Parameters |
|
|
|
|
|
|
|
|
|
public ExportableVariable SelectedVariable |
|
|
|
@ -102,6 +191,7 @@ namespace rabi_splitter_WPF |
|
|
|
|
{ |
|
|
|
|
if (value.Equals(_selectedVariable)) return; |
|
|
|
|
_selectedVariable = value; |
|
|
|
|
_variableTracker = _selectedVariable.GetTracker(); |
|
|
|
|
OnPropertyChanged(nameof(SelectedVariable)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -124,10 +214,22 @@ namespace rabi_splitter_WPF |
|
|
|
|
{ |
|
|
|
|
if (value.Equals(_outputFormat)) return; |
|
|
|
|
_outputFormat = value; |
|
|
|
|
if (_variableTracker != null) _variableTracker.FormatChanged(); |
|
|
|
|
OnPropertyChanged(nameof(OutputFormat)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public string FormatPreview |
|
|
|
|
{ |
|
|
|
|
get { return _formatPreview; } |
|
|
|
|
private set |
|
|
|
|
{ |
|
|
|
|
if (value.Equals(_formatPreview)) return; |
|
|
|
|
_formatPreview = value; |
|
|
|
|
OnPropertyChanged(nameof(FormatPreview)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool IsPreviewingFormat |
|
|
|
|
{ |
|
|
|
|
get { return _isPreviewingFormat; } |
|
|
|
@ -149,10 +251,10 @@ namespace rabi_splitter_WPF |
|
|
|
|
OnPropertyChanged(nameof(IsExporting)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
// Note: DO NOT OVERRIDE Equals and GetHashCode. We compare by reference equality. |
|
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged; |
|
|
|
|
|
|
|
|
|
[NotifyPropertyChangedInvocator] |
|
|
|
@ -160,6 +262,5 @@ namespace rabi_splitter_WPF |
|
|
|
|
{ |
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|