public void Apply(SnapshotItem item) { Execute.BeginOnThreadPool(() => { var snapshotDirectoryName = item.Name; var snapshotDirectoryFullName = Path.Combine(Constants.SnapshotsDirectoryName, snapshotDirectoryName); var stateFullFileName = Path.Combine(snapshotDirectoryFullName, Telegram.Api.Constants.StateFileName); try { _updateService.LoadStateSnapshot(snapshotDirectoryFullName); _cacheService.LoadSnapshot(snapshotDirectoryFullName); var currentState = _updateService.GetState(); State = currentState; NotifyOfPropertyChange(() => State); Difference = TLUtils.OpenObjectFromMTProtoFile <TLVector <TLDifferenceBase> >(new object(), Telegram.Api.Constants.DifferenceFileName); NotifyOfPropertyChange(() => Difference); _eventAggregator.Publish(new UpdateCompletedEventArgs()); Execute.ShowDebugMessage("Snapshot has been successfully applied"); } catch (Exception ex) { } }); }
public SnapshotsViewModel(ICacheService cacheService, IUpdatesService updateService, ITelegramEventAggregator eventAggregator) { Items = new ObservableCollection <SnapshotItem>(); _cacheService = cacheService; _updateService = updateService; _eventAggregator = eventAggregator; Execute.BeginOnThreadPool(() => { try { var currentState = _updateService.GetState(); State = currentState; NotifyOfPropertyChange(() => State); var tempDifference = TLUtils.OpenObjectFromMTProtoFile <TLVector <TLDifferenceBase> >(new object(), Telegram.Api.Constants.DifferenceFileName); Difference = tempDifference; NotifyOfPropertyChange(() => Difference); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (store.DirectoryExists(Constants.SnapshotsDirectoryName)) { foreach (var directory in store.GetDirectoryNames(Constants.SnapshotsDirectoryName + "/*")) { var item = new SnapshotItem { Name = directory }; var stateFullFileName = Path.Combine(Path.Combine(Constants.SnapshotsDirectoryName, directory), Telegram.Api.Constants.StateFileName); if (store.FileExists(stateFullFileName)) { var state = TLUtils.OpenObjectFromMTProtoFile <TLState>(new object(), stateFullFileName); item.State = state; } var differenceFullFileName = Path.Combine(Path.Combine(Constants.SnapshotsDirectoryName, directory), Telegram.Api.Constants.DifferenceFileName); if (store.FileExists(differenceFullFileName)) { long length; var difference = TLUtils.OpenObjectFromMTProtoFile <TLVector <TLDifferenceBase> >(new object(), differenceFullFileName, out length); item.Difference = difference; item.DifferenceLength = length; } Execute.BeginOnUIThread(() => Items.Add(item)); } } } } catch (Exception ex) { } }); }