diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-01 16:42:04 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-01 16:42:04 +0200 |
| commit | f01b4d59ea6456fd7e46b447162835de387757bb (patch) | |
| tree | 5d7030128900acc65b3530b7f8e82d7bd354adf2 /Software/Visual_Studio/Utilities/Tango.Synchronization.UI/ViewModels/MainViewVM.cs | |
| parent | 7a347e757764f69d2768bbfa1265fe771b73703b (diff) | |
| download | Tango-f01b4d59ea6456fd7e46b447162835de387757bb.tar.gz Tango-f01b4d59ea6456fd7e46b447162835de387757bb.zip | |
Removed Utilities:
Synchronization.UI.
MobileEM.
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.Synchronization.UI/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/Utilities/Tango.Synchronization.UI/ViewModels/MainViewVM.cs | 306 |
1 files changed, 0 insertions, 306 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.Synchronization.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/Utilities/Tango.Synchronization.UI/ViewModels/MainViewVM.cs deleted file mode 100644 index 32573b2ec..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Synchronization.UI/ViewModels/MainViewVM.cs +++ /dev/null @@ -1,306 +0,0 @@ -using Microsoft.Win32; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows; -using Tango.Core; -using Tango.Core.Commands; -using Tango.Logging; -using Tango.Synchronization.Local; - -namespace Tango.Synchronization.UI.ViewModels -{ - public class MainViewVM : ExtendedObject - { - private String _masterDBFile; - private String _slaveDBFile; - private LocalDBComparer _comparer; - private LogManager LogManager = LogManager.Default; - - #region Properties - - private bool _isBusy; - /// <summary> - /// Gets or sets a value indicating whether an operation is in progress. - /// </summary> - public bool IsBusy - { - get { return _isBusy; } - set { _isBusy = value; RaisePropertyChanged(nameof(IsBusy)); } - } - - private String _status; - /// <summary> - /// Gets or sets the current operation status. - /// </summary> - public String Status - { - get { return _status; } - set { _status = value; RaisePropertyChanged(nameof(Status)); } - } - - private String _log; - /// <summary> - /// Gets or sets the current application log text. - /// </summary> - public String Log - { - get { return _log; } - set { _log = value; RaisePropertyChanged(nameof(Log)); } - } - - private ObservableCollection<Diff> _differences; - /// <summary> - /// Gets or sets the differences. - /// </summary> - public ObservableCollection<Diff> Differences - { - get { return _differences; } - set { _differences = value; RaisePropertyChanged(nameof(Differences)); } - } - - private Diff _selectedDifference; - /// <summary> - /// Gets or sets the selected difference. - /// </summary> - public Diff SelectedDifference - { - get { return _selectedDifference; } - set { _selectedDifference = value; RaisePropertyChanged(nameof(SelectedDifference)); InvalidateRelayCommands(); } - } - - private String _masterDBName; - /// <summary> - /// Gets or sets the name of the master database. - /// </summary> - public String MasterDBName - { - get { return _masterDBName; } - set { _masterDBName = value; RaisePropertyChanged(nameof(MasterDBName)); } - } - - private String _slaveDBName; - /// <summary> - /// Gets or sets the name of the slave database. - /// </summary> - public String SlaveDBName - { - get { return _slaveDBName; } - set { _slaveDBName = value; RaisePropertyChanged(nameof(SlaveDBName)); } - } - - #endregion - - #region Commands - - /// <summary> - /// Gets or sets the browse master database command. - /// </summary> - public RelayCommand BrowseMasterDBCommand { get; set; } - - /// <summary> - /// Gets or sets the browse slave database command. - /// </summary> - public RelayCommand BrowseSlaveDBCommand { get; set; } - - /// <summary> - /// Gets or sets the compare command. - /// </summary> - public RelayCommand CompareCommand { get; set; } - - /// <summary> - /// Gets or sets the commit command. - /// </summary> - public RelayCommand CommitCommand { get; set; } - - /// <summary> - /// Gets or sets the commit all command. - /// </summary> - public RelayCommand CommitAllCommand { get; set; } - - #endregion - - #region Constructors - - /// <summary> - /// Initializes a new instance of the <see cref="MainViewVM"/> class. - /// </summary> - public MainViewVM() - { - SimpleStringLogger logger = new SimpleStringLogger(LogCategory.Critical, LogCategory.Error, LogCategory.Info, LogCategory.Warning); - logger.LogReceived += (sender,log) => - { - Log += log.ToString() + Environment.NewLine; - }; - - LogManager.RegisterLogger(logger); - - LogManager.Log("DB Synchronizer Started!"); - - Differences = new ObservableCollection<Diff>(); - - BrowseMasterDBCommand = new RelayCommand(BrowseMasterDB); - BrowseSlaveDBCommand = new RelayCommand(BrowseSlaveDB); - CompareCommand = new RelayCommand(Compare, (x) => _masterDBFile != null && _slaveDBFile != null); - CommitCommand = new RelayCommand(Commit, (x) => SelectedDifference != null); - CommitAllCommand = new RelayCommand(CommitAll, (x) => Differences.Count > 0); - - Task.Factory.StartNew(() => - { - OpenStatus("Loading components, please wait..."); - Thread.Sleep(1000); - CloseStatus(); - }); - } - - #endregion - - #region Private Methods - - private void Compare() - { - _comparer = new LocalDBComparer(new SQLiteDataBase(_masterDBFile), new SQLiteDataBase(_slaveDBFile)); - - OpenStatus("Comparing DataBase..."); - - Task.Factory.StartNew(() => - { - try - { - Thread.Sleep(1500); - var diffs = _comparer.Compare(); - Differences = new ObservableCollection<Diff>(diffs); - } - catch (Exception ex) - { - ShowError(ex.Message); - } - finally - { - SelectedDifference = null; - InvalidateRelayCommands(); - CloseStatus(); - } - }); - } - - private void Commit() - { - OpenStatus("Committing difference..."); - - Task.Factory.StartNew(() => - { - try - { - Thread.Sleep(1500); - SelectedDifference.Commit(); - - InvokeUINow(() => Differences.Remove(SelectedDifference)); - } - catch (Exception ex) - { - ShowError(ex.Message); - } - finally - { - SelectedDifference = null; - InvalidateRelayCommands(); - CloseStatus(); - } - }); - } - - private void CommitAll() - { - OpenStatus("Committing all differences..."); - - Task.Factory.StartNew(() => - { - try - { - Thread.Sleep(1500); - - for (int i = 0; i < Differences.Count; i++) - { - var diff = Differences[i]; - OpenStatus("Committing difference " + (Differences.IndexOf(diff) + 1) + "..."); - diff.Commit(); - InvokeUINow(() => Differences.Remove(diff)); - i--; - } - } - catch (Exception ex) - { - ShowError(ex.Message); - } - finally - { - SelectedDifference = null; - InvalidateRelayCommands(); - CloseStatus(); - } - }); - } - - private void BrowseSlaveDB() - { - String file = BrowseForFilePath(); - if (file != null) - { - _slaveDBFile = file; - SlaveDBName = Path.GetFileName(file); - InvalidateRelayCommands(); - } - } - - private void BrowseMasterDB() - { - String file = BrowseForFilePath(); - if (file != null) - { - _masterDBFile = file; - MasterDBName = Path.GetFileName(file); - InvalidateRelayCommands(); - } - } - - private String BrowseForFilePath() - { - OpenFileDialog dlg = new OpenFileDialog(); - dlg.Title = "Select SQLite DataBase File"; - dlg.Filter = "SQLite DataBase|*.db"; - if (dlg.ShowDialog().Value) - { - return dlg.FileName; - } - return null; - } - - private void OpenStatus(String status) - { - IsBusy = true; - Status = status; - } - - private void CloseStatus() - { - IsBusy = false; - } - - private void ShowError(String message) - { - MessageBox.Show(message, "Tango", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly); - } - - private void ShowInfo(String message) - { - MessageBox.Show(message, "Tango", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly); - } - #endregion - } -} |
