/// <summary> /// Runs the synchronization attempt. /// Does not raise exceptions. /// </summary> public async Task <SyncResult> Synchronize(CancellationToken token, SyncPolicy policy = SyncPolicy.Default) { if (DateTime.UtcNow < NextUploadOpportunity && policy == SyncPolicy.Default) { Log.Debug("Can't sync: sync attempt too early, next upload scheduled after {0}", NextUploadOpportunity); return(new SyncResult(new InvalidOperationException("Sync attempt too early"))); } Settings.LastUploadAttempt = DateTime.UtcNow; if (!CheckSyncConditions(policy)) { return(new SyncResult(error: new InvalidOperationException("Sync conditions not met"))); } Log.Debug("Sync attempt started (policy {0})", policy); IsSyncing = true; StatusChanged.Raise(this); try { var ret = await SynchronizeInner(token, policy); Log.Debug("Sync process terminated normally"); Log.Event("Sync.terminate", new Dictionary <string, string>() { { "policy", policy.ToString() } }); if (ret.HasFailed) { UserLog.Add(UserLog.Icon.Error, LogStrings.FileUploadFailure, ret.Error.Message); SyncError.Raise(this, new SyncErrorEventArgs(ret.Error)); } else { if (ret.ChunksUploaded == 1) { UserLog.Add(LogStrings.FileUploadSummarySingular); } else { UserLog.Add(LogStrings.FileUploadSummaryPlural, ret.ChunksUploaded); } } return(ret); } catch (TaskCanceledException) { Log.Debug("Sync process was canceled"); return(new SyncResult(0, 0)); } catch (Exception ex) { Log.Error(ex, "Sync process failed with unforeseen error"); UserLog.Add(UserLog.Icon.Error, LogStrings.FileUploadFailure, ex.Message); return(new SyncResult(error: ex)); } finally { IsSyncing = false; StatusChanged.Raise(this); } }
protected void RaiseStatusChanged(string status, params object[] args) { StatusChanged.Raise(this, new StatusChangedEventArgs(string.Format(status, args))); }
protected void OnStatusChanged(StreamingStatus status) { StatusChanged.Raise(this, new StreamingStatusEventArgs { Status = status }); }
public TaskProgressMessage(ITask task) { _task = task; _task.ProgressChanged += (s, e) => this.ProgressChanged.Raise(this, e); _task.StatusChanged += (s, e) => StatusChanged.Raise(this, e); }
private void OnStatusChanged(SkypeStatus status) { _context.InvokeThreadSafe(() => StatusChanged.Raise(this, status)); }
private void SourceControlServiceStatusChanged(object sender, SourceControlEventArgs e) { StatusChanged.Raise(this, e); }
/// <summary> /// Handles processing of the underlying connection(s) and promoting data to the upper layer to be handled /// by the application. Should be called once per frame. /// </summary> public void Heartbeat() { const string debugMsgFormat = "Debug message from `{0}` on `{1}`: {2}"; NetIncomingMessage incMsg; while ((incMsg = _local.ReadMessage()) != null) { IIPSocket ipSocket; Debug.Assert( RemoteSocket == null || incMsg.SenderConnection == null || incMsg.SenderConnection.Tag == RemoteSocket, "Why did we get a message from a different connection?"); switch (incMsg.MessageType) { case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.VerboseDebugMessage: if (log.IsDebugEnabled) { var debugMsg = incMsg.ReadString(); log.DebugFormat(debugMsgFormat, incMsg.SenderConnection, this, debugMsg); } break; case NetIncomingMessageType.WarningMessage: if (log.IsWarnEnabled) { var debugMsg = incMsg.ReadString(); log.WarnFormat(debugMsgFormat, incMsg.SenderConnection, this, debugMsg); } break; case NetIncomingMessageType.ErrorMessage: if (log.IsErrorEnabled) { var debugMsg = incMsg.ReadString(); log.ErrorFormat(debugMsgFormat, incMsg.SenderConnection, this, debugMsg); } break; case NetIncomingMessageType.StatusChanged: var status = (NetConnectionStatus)incMsg.ReadByte(); ipSocket = (IIPSocket)incMsg.SenderConnection.Tag; var reason = incMsg.ReadString(); // Set the ClientDisconnected value based on the status switch (status) { case NetConnectionStatus.InitiatedConnect: case NetConnectionStatus.RespondedConnect: case NetConnectionStatus.Connected: case NetConnectionStatus.None: // Reset the status _clientDisconnected = false; break; case NetConnectionStatus.Disconnecting: // Disconnecting only is set when we are the ones disconnecting. However, we want to set _clientDisconnected // only when we didn't disconnect due to an error (like the connection couldn't be made in the first place). if (string.IsNullOrEmpty(reason)) { _clientDisconnected = true; } else { _clientDisconnected = false; } break; } // Handle parsing a custom disconnect message if (status == NetConnectionStatus.Disconnected) { reason = ParseCustomDisconnectMessage(reason); } // Don't let them set it to null if (reason == null) { reason = string.Empty; } if (log.IsDebugEnabled) { log.DebugFormat("Socket `{0}` status changed to `{1}`. Reason: {2}", ipSocket, status, reason); } OnReceiveStatusChanged(ipSocket, status, reason); if (StatusChanged != null) { StatusChanged.Raise(this, new ClientSocketManagerStatusChangedEventArgs(status, reason)); } break; case NetIncomingMessageType.Data: ipSocket = (IIPSocket)incMsg.SenderConnection.Tag; if (log.IsDebugEnabled) { log.DebugFormat("Received {0} bits from {1}.", incMsg.LengthBits, ipSocket); } // Copy the received data into a BitStream before passing it up _receiveBitStream.Reset(); _receiveBitStream.Write(incMsg); _receiveBitStream.PositionBits = 0; OnReceiveData(ipSocket, _receiveBitStream); break; default: break; } _local.Recycle(incMsg); } }
/// <summary> /// Raises the StatusChanged event</summary> /// <param name="e">Event args</param> protected virtual void OnStatusChanged(SourceControlEventArgs e) { StatusChanged.Raise(this, e); }
public void Status(string status) { StatusChanged.Raise(this, new StatusChangedEventArgs(status)); }