private void InsertTreeViewNode(EntryUpdateInfoViewModel entry, EntryUpdateInfoViewModel node, IList <string> pathStack) { if (pathStack.Count < 1) { throw new InvalidOperationException("Skipped something in the path stack"); } if (pathStack.Count == 1) { App.DispatcherInvoke(() => { node.ChildEntries.Add(entry); }); return; } EntryUpdateInfoViewModel childNode = node.ChildEntries.FirstOrDefault(e => e.Name == pathStack.First()); if (childNode == null) { // No root element for this entry childNode = new EntryUpdateInfoViewModel { Name = pathStack.First(), NoChange = true, IsDirectory = true }; App.DispatcherInvoke(() => { node.ChildEntries.Add(childNode); }); } pathStack.RemoveAt(0); this.InsertTreeViewNode(entry, childNode, pathStack); }
private void AddEntryUpdate(EntryUpdateInfoViewModel viewModel, IList <string> pathStack) { // Add the view model to the flat list App.DispatcherInvoke(() => { this.EntryUpdatesFlatList.Add(viewModel); }); EntryUpdateInfoViewModel rootNode = this.EntryUpdatesTreeList.First(); this.InsertTreeViewNode(viewModel, rootNode, pathStack); }
/// <summary> /// During an active sync job, this methods is invoked on progress changed (aka when a change is detected). /// </summary> /// <param name="sender">The sender</param> /// <param name="syncJobProgressInfo">The progressInfo object</param> private void SyncJobOnProgressChanged(object sender, SyncJobProgressInfo syncJobProgressInfo) { App.Current.Dispatcher.Invoke(() => { if (syncJobProgressInfo.Message != null) { this.SyncProgressCurrentText = syncJobProgressInfo.Message; } if (double.IsInfinity(syncJobProgressInfo.ProgressValue)) { } else { this.ShowDiscreteProgress = true; this.ProgressValue = syncJobProgressInfo.ProgressValue; this.SyncProgressCurrentText = syncJobProgressInfo.ProgressValue.ToString("P0") + " complete"; this.BytesCompleted = syncJobProgressInfo.BytesCompleted; this.BytesRemaining = syncJobProgressInfo.BytesTotal - syncJobProgressInfo.BytesCompleted; this.FilesCompleted = syncJobProgressInfo.FilesCompleted; this.FilesRemaining = syncJobProgressInfo.FilesTotal - syncJobProgressInfo.FilesCompleted; this.TimeElapsed = DateTime.Now.Subtract(this.StartTime); if (DateTime.Now.Subtract(this.lastSyncProgressUpdate).TotalSeconds > 1) { this.lastSyncProgressUpdate = DateTime.Now; if (syncJobProgressInfo.BytesPerSecond > 0) { var secondsRemaining = this.BytesRemaining / syncJobProgressInfo.BytesPerSecond; this.TimeRemaining = TimeSpan.FromSeconds( Math.Round(secondsRemaining / 5.0) * 5); } else { this.TimeRemaining = TimeSpan.Zero; } this.Throughput = FileSizeConverter.Convert(syncJobProgressInfo.BytesPerSecond, 2) + " per second"; } } if (!this.EntryUpdatesTreeList.Any() && syncJobProgressInfo.UpdateInfo != null) { SyncEntry rootEntry = syncJobProgressInfo.UpdateInfo.OriginatingAdapter.GetRootSyncEntry(); var rootNode = new EntryUpdateInfoViewModel { Name = rootEntry.Name, IsDirectory = true }; this.EntryUpdatesTreeList.Add(rootNode); } if (syncJobProgressInfo.UpdateInfo != null) { IList <string> pathStack = syncJobProgressInfo.UpdateInfo.RelativePath.Split('\\').ToList(); this.CalculateChangeMetrics(syncJobProgressInfo.UpdateInfo); this.AddEntryUpdate( new EntryUpdateInfoViewModel( syncJobProgressInfo.UpdateInfo, this.SyncRelationship, -1), pathStack); } }); }