private void BtnServerConfig_Click(object sender, EventArgs e) { using (var dlg = new ServerConfigDlg()) { try { dlg.ServerConfig = WcfProxy.GetConfig(); } catch (Exception ex) when( ex is EndpointNotFoundException || ex is CommunicationException) { _ = MessageBox.Show( "Unable to retrieve configuration from server.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dlg.ShowDialog() != DialogResult.OK) { return; } while (true) { try { WcfProxy.SetConfig(dlg.ServerConfig); return; } catch (Exception ex) when( ex is EndpointNotFoundException || ex is CommunicationException) { if (MessageBox.Show( $"Unable to send configuration to the server." + $"{Environment.NewLine}Do you want to try again?", "Connection Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No) { return; } } } } }
private void BtnResolveConflicts_Click(object sender, EventArgs e) { try { while (true) { var duplicate = WcfProxy.GetDuplicate(); if (duplicate == null) { return; } using (var dlg = new FileComparisonDlg()) { DialogResult result; dlg.LeftFile = duplicate.File1; dlg.RightFile = duplicate.File2; dlg.ServerSourcePath = duplicate.BasePath; dlg.Settings = Settings; result = dlg.ShowDialog(); if (result == DialogResult.Cancel) { WcfProxy.ResolveDuplicate( duplicate.DuplicateId, ResolveOperation.Cancel); return; } WcfProxy.ResolveDuplicate( duplicate.DuplicateId, dlg.ResolveOperation); } } } catch (Exception ex) when( ex is EndpointNotFoundException || ex is CommunicationException) { _ = MessageBox.Show( $"Unable to process duplicate.{Environment.NewLine}" + $"Connection to server failed.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async void RequestLogEntries(Guid logToken, int start, int count) { foreach (var index in Enumerable.Range(start, count)) { _ = LogEntries.TryAdd(index, new LogEntry { Status = LogEntryStatus.Requested, Message = "", }); } try { var logData = await Task.Factory.StartNew(() => WcfProxy.GetLogEntries(logToken, start, count)); if (start + count > DgvLog.RowCount) { return; } var logIndex = start; foreach (var logEntry in logData.LogEntries) { _ = LogEntries[logIndex++] = new LogEntry { Status = LogEntryStatus.Present, Message = logEntry, }; } foreach (var index in Enumerable.Range(start, count)) { DgvLog.UpdateCellValue(0, index); } } catch (Exception ex) when( ex is EndpointNotFoundException || ex is CommunicationException) { foreach (var index in Enumerable.Range(start, count)) { _ = LogEntries.TryRemove(index, out _); } } }
private void BtnDiscard_Click(object sender, EventArgs e) { var selection = MessageBox.Show( $"There are {DuplicateCount} duplicates to resolve." + $"{Environment.NewLine}Are you sure you want to discard them?", "Discard duplicates?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (selection == DialogResult.No) { return; } try { WcfProxy.DiscardDuplicates(); } catch (Exception ex) when( ex is EndpointNotFoundException || ex is CommunicationException) { } }
private void StatusTimerCallback(object param) { try { var status = WcfProxy.GetCurrentStatus(); this.InvokeIfRequired(() => { if (logToken != status.LogToken) { // Has to be in this order // Otherwise clearing the DGV causes cell value requests // in this thread before continuing here. // Which has a high chance of adding items in the // LogEntries list, which are subsequently cleared, // leaving empty cells in the DGV that won't be filled. DgvLog.RowCount = 0; LogEntries.Clear(); } logToken = status.LogToken; // If we are scrolled down, we auto scroll var prevRowCount = DgvLog.RowCount; DgvLog.RowCount = status.LogCount; if (DgvLog.GetLastDisplayedScrollingRowIndex(false) + 1 >= prevRowCount) { DgvLog.FirstDisplayedScrollingRowIndex = DgvLog.RowCount - 1; } UpdateOperation(status.Operation); DuplicateCount = status.DuplicateCount; LblDuplicateCount.Text = string.Format( StatusInfoDuplicateCount, DuplicateCount); BtnResolveDuplicates.Enabled = DuplicateCount > 0; BtnDiscardDuplicates.Enabled = DuplicateCount > 0; }); } catch (Exception ex) when( ex is EndpointNotFoundException || ex is CommunicationException || ex is TimeoutException) { Debug.Print("Status request failed with: " + ex.Message); this.InvokeIfRequired(() => { BtnResolveDuplicates.Enabled = false; UpdateOperation(new OperationInfo { Message = "Connecting...", ProgressStyle = ProgressStyle.Marquee, }); }); } finally { _ = StatusTimer.StartSingle(Settings.StatusRequestInterval); } }