Пример #1
0
        public ServerPresetsManager()
        {
            SavedDrivers = new ChangeableObservableCollection <ServerSavedDriver>(ServerSavedDriver.Load(DriversFilename));
            SavedDrivers.CollectionChanged   += OnSavedDriversCollectionChanged;
            SavedDrivers.ItemPropertyChanged += OnSavedDriversItemPropertyChanged;

            var directory = Path.GetDirectoryName(DriversFilename);

            if (directory != null)
            {
                Directory.CreateDirectory(directory);

                _directoryWatcher = new FileSystemWatcher {
                    Path                  = directory,
                    NotifyFilter          = NotifyFilters.LastWrite | NotifyFilters.FileName,
                    Filter                = Path.GetFileName(DriversFilename),
                    EnableRaisingEvents   = true,
                    IncludeSubdirectories = false
                };

                _directoryWatcher.Created += OnDirectoryWatcher;
                _directoryWatcher.Renamed += OnDirectoryWatcher;
                _directoryWatcher.Changed += OnDirectoryWatcher;
                _directoryWatcher.Deleted += OnDirectoryWatcher;
            }
        }
Пример #2
0
        private async void OnDirectoryWatcher(object sender, FileSystemEventArgs e)
        {
            if (_updating || _saving)
            {
                return;
            }
            _updating = true;

            try {
                await Task.Delay(300);

                if (_updating)
                {
                    ActionExtension.InvokeInMainThread(() => {
                        SavedDrivers.ReplaceIfDifferBy(ServerSavedDriver.Load(DriversFilename));
                    });
                    await Task.Delay(200);
                }
            } finally {
                _updating = false;
            }
        }
Пример #3
0
 private bool Equals(ServerSavedDriver other)
 {
     return(string.Equals(Guid, other.Guid) && string.Equals(DriverName, other.DriverName) && string.Equals(TeamName, other.TeamName) &&
            Skins.SequenceEqual(other.Skins));
 }