本文整理汇总了C#中ITransferProgress类的典型用法代码示例。如果您正苦于以下问题:C# ITransferProgress类的具体用法?C# ITransferProgress怎么用?C# ITransferProgress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITransferProgress类属于命名空间,在下文中一共展示了ITransferProgress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupUploadTransferProgress
public IDisposable SetupUploadTransferProgress(ITransferProgress transferProgress, TimeSpan timeout) {
var lastTime = Tools.Generic.GetCurrentUtcDateTime;
long lastBytes = 0;
UploadProgressChanged +=
(sender, args) => {
var bytes = args.BytesReceived;
var now = Tools.Generic.GetCurrentUtcDateTime;
transferProgress.FileSizeTransfered = bytes;
long? speed = null;
if (lastBytes != 0) {
var timeSpan = now - lastTime;
var bytesChange = bytes - lastBytes;
if (timeSpan.TotalMilliseconds > 0)
speed = (long) (bytesChange/(timeSpan.TotalMilliseconds/1000.0));
}
transferProgress.Update(speed, args.ProgressPercentage);
lastTime = now;
lastBytes = bytes;
};
UploadFileCompleted += (sender, args) => { transferProgress.Completed = true; };
var timer = new TimerWithElapsedCancellation(500, () => {
if (!transferProgress.Completed
&& Tools.Generic.LongerAgoThan(lastTime, timeout)) {
CancelAsync();
return false;
}
return !transferProgress.Completed;
});
return timer;
}
示例2: CheckZsyncLoop
public bool CheckZsyncLoop(Process process, string data, ITransferProgress progress) {
// By not resetting the loopdata/counts we set ourselves up for a situation where it's possible to detect loops that span multiple lines..
if (!ZsyncLoop.IsMatch(data))
return false;
if (progress.ZsyncLoopData == null) {
progress.ZsyncLoopData = data;
progress.ZsyncLoopCount = 0;
return false;
}
if (progress.ZsyncLoopData.Equals(data, StringComparison.OrdinalIgnoreCase)) {
var loopCount = ++progress.ZsyncLoopCount;
if (loopCount < 2)
return false;
if (!process.SafeHasExited())
process.TryKill();
return true;
}
progress.ZsyncLoopData = data;
progress.ZsyncLoopCount = 0;
return false;
}
示例3: Pull
public void Pull(ITransferProgress status, string remoteSub = null, string localSub = null) {
CreateSshFolder();
HandleRsyncResponse(_rsyncLauncher.RunAndProcess(
status,
JoinPathsIfNeeded(Remote, remoteSub),
JoinPathsIfNeeded(Local, localSub),
BuildOptions()));
}
示例4: TransferSpec
protected TransferSpec(Uri uri, IAbsoluteFilePath localFile, ITransferProgress progress) {
Contract.Requires<ArgumentNullException>(uri != null);
Contract.Requires<ArgumentNullException>(localFile != null);
Uri = uri;
LocalFile = localFile;
Progress = progress ?? new TransferProgress();
}
示例5: RunAndProcess
public ProcessExitResultWithOutput RunAndProcess(ITransferProgress progress, string source, string destination,
CancellationToken token,
RsyncOptions options = null) {
var processInfo = BuildProcessInfo(progress, source, destination, options);
processInfo.CancellationToken = token;
return ProcessExitResultWithOutput.FromProcessExitResult(_processManager.LaunchAndProcess(processInfo),
progress.Output);
}
示例6: RunAndProcessAsync
public async Task<ProcessExitResultWithOutput> RunAndProcessAsync(ITransferProgress progress, string source,
string destination,
RsyncOptions options = null) {
var processInfo = BuildProcessInfo(progress, source, destination, options);
return
ProcessExitResultWithOutput.FromProcessExitResult(
await _processManager.LaunchAndProcessAsync(processInfo).ConfigureAwait(false), progress.Output);
}
示例7: RunAndProcess
public ProcessExitResultWithOutput RunAndProcess(ITransferProgress progress, Uri url, string file) {
TryHandleOldFiles(file);
var processInfo = BuildProcessInfo(progress, url, file);
var r =
ProcessExitResultWithOutput.FromProcessExitResult(_processManager.LaunchAndProcess(processInfo),
progress.Output);
TryRemoveOldFiles(file);
return r;
}
示例8: ParseOutput
public override void ParseOutput(Process sender, string data, ITransferProgress progress) {
// 3.51M 43% 177.98kB/s 0:00:25
// sent 1.39K bytes received 1.01K bytes 1.60K bytes/sec
// total size is 114.55K speedup is 47.57
if (data == null)
return;
progress.UpdateOutput(data);
var matches = RSYNC_START.Matches(data);
if (matches.Count > 0) {
var match = matches[0];
var speed = match.Groups[2].Value.TryDouble();
var speedUnit = match.Groups[3].Value;
progress.Update(GetByteSize(speed, speedUnit), match.Groups[1].Value.TryDouble());
TimeSpan ts;
if (TimeSpan.TryParse(match.Groups[4].Value, out ts))
progress.Eta = ts;
return;
}
matches = RSYNC_END.Matches(data);
if (matches.Count > 0) {
var match = matches[0];
var sent = match.Groups[1].Value.TryDouble();
var sentUnit = match.Groups[2].Value;
var received = match.Groups[3].Value.TryDouble();
var receivedUnit = match.Groups[4].Value;
// Rsync final message omits B(yte) indication
progress.FileSizeTransfered = GetByteSize(sent, sentUnit + "b") +
GetByteSize(received, receivedUnit + "b");
progress.Completed = true;
return;
}
progress.Eta = null;
progress.Update(null, 0);
}
示例9: ParseOutput
public override void ParseOutput(Process sender, string data, ITransferProgress progress) {
// ###################- 97.3% 141.5 kBps 0:00 ETA
// used 0 local, fetched 894
if (data == null)
return;
progress.UpdateOutput(data);
if (!VerifyZsyncCompatible(data))
progress.ZsyncIncompatible = true;
if (CheckZsyncLoop(sender, data, progress))
return;
var matches = ZSYNC_START.Matches(data);
if (matches.Count > 0) {
var match = matches[0];
var speed = match.Groups[2].Value.TryDouble();
var speedUnit = match.Groups[3].Value;
progress.Update(GetByteSize(speed, speedUnit), match.Groups[1].Value.TryDouble());
var eta = match.Groups[4].Value;
if (tspan.IsMatch(eta))
eta = "0:" + eta;
TimeSpan ts;
if (TimeSpan.TryParse(eta, out ts))
progress.Eta = ts;
return;
}
matches = ZSYNC_END.Matches(data);
if (matches.Count > 0) {
var match = matches[0];
progress.FileSizeTransfered = match.Groups[2].Value.TryInt();
progress.Completed = true;
return;
}
progress.Eta = null;
progress.Update(null, 0);
}
示例10: GetStream
/// <summary>
/// Gets a substream of the specified body part.
/// </summary>
/// <remarks>
/// <para>Gets a substream of the specified message.</para>
/// <para>For more information about how to construct the <paramref name="section"/>,
/// see Section 6.4.5 of RFC3501.</para>
/// </remarks>
/// <returns>The stream.</returns>
/// <param name="uid">The UID of the message.</param>
/// <param name="section">The desired section of the message.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress reporting mechanism.</param>
/// <exception cref="System.ArgumentException">
/// <paramref name="uid"/> is invalid.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="section"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="ImapClient"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="ImapClient"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="ImapClient"/> is not authenticated.
/// </exception>
/// <exception cref="FolderNotOpenException">
/// The <see cref="ImapFolder"/> is not currently open.
/// </exception>
/// <exception cref="MessageNotFoundException">
/// The IMAP server did not return the requested message stream.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ImapProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="ImapCommandException">
/// The server replied with a NO or BAD response.
/// </exception>
public override Stream GetStream (UniqueId uid, string section, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
{
if (uid.Id == 0)
throw new ArgumentException ("The uid is invalid.", "uid");
if (section == null)
throw new ArgumentNullException ("section");
CheckState (true, false);
var command = string.Format ("UID FETCH {0} (BODY.PEEK[{1}])\r\n", uid.Id, section);
var ic = new ImapCommand (Engine, cancellationToken, this, command);
var ctx = new FetchStreamContext (progress);
Stream stream;
ic.RegisterUntaggedHandler ("FETCH", FetchStream);
ic.UserData = ctx;
Engine.QueueCommand (ic);
try {
Engine.Wait (ic);
ProcessResponseCodes (ic, null);
if (ic.Response != ImapCommandResponse.Ok)
throw ImapCommandException.Create ("FETCH", ic);
if (!ctx.Sections.TryGetValue (section, out stream))
throw new MessageNotFoundException ("The IMAP server did not return the requested stream.");
ctx.Sections.Remove (section);
} finally {
ctx.Dispose ();
}
return stream;
}
示例11: GetBodyPart
/// <summary>
/// Gets the specified body part.
/// </summary>
/// <remarks>
/// Gets the specified body part.
/// </remarks>
/// <returns>The body part.</returns>
/// <param name="index">The index of the message.</param>
/// <param name="partSpecifier">The body part specifier.</param>
/// <param name="headersOnly"><c>true</c> if only the headers should be downloaded; otherwise, <c>false</c>></param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress reporting mechanism.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="partSpecifier"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="index"/> is out of range.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="ImapClient"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="ImapClient"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="ImapClient"/> is not authenticated.
/// </exception>
/// <exception cref="FolderNotOpenException">
/// The <see cref="ImapFolder"/> is not currently open.
/// </exception>
/// <exception cref="MessageNotFoundException">
/// The IMAP server did not return the requested message.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ImapProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="ImapCommandException">
/// The server replied with a NO or BAD response.
/// </exception>
public MimeEntity GetBodyPart (int index, string partSpecifier, bool headersOnly, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
{
if (index < 0 || index >= Count)
throw new ArgumentOutOfRangeException ("index");
if (partSpecifier == null)
throw new ArgumentNullException ("partSpecifier");
CheckState (true, false);
string[] tags;
var command = string.Format ("FETCH {0} ({1})\r\n", index + 1, GetBodyPartQuery (partSpecifier, headersOnly, out tags));
var ic = new ImapCommand (Engine, cancellationToken, this, command);
var ctx = new FetchStreamContext (progress);
ChainedStream chained;
bool dispose = false;
Stream stream;
ic.RegisterUntaggedHandler ("FETCH", FetchStream);
ic.UserData = ctx;
Engine.QueueCommand (ic);
try {
Engine.Wait (ic);
ProcessResponseCodes (ic, null);
if (ic.Response != ImapCommandResponse.Ok)
throw ImapCommandException.Create ("FETCH", ic);
chained = new ChainedStream ();
foreach (var tag in tags) {
if (!ctx.Sections.TryGetValue (tag, out stream))
throw new MessageNotFoundException ("The IMAP server did not return the requested body part.");
if (!(stream is MemoryStream || stream is MemoryBlockStream))
dispose = true;
chained.Add (stream);
}
foreach (var tag in tags)
ctx.Sections.Remove (tag);
} finally {
ctx.Dispose ();
}
var entity = ParseEntity (chained, dispose, cancellationToken);
if (partSpecifier.Length == 0) {
for (int i = entity.Headers.Count; i > 0; i--) {
var header = entity.Headers[i - 1];
//.........这里部分代码省略.........
示例12: FetchStreamContext
public FetchStreamContext (ITransferProgress progress)
{
Progress = progress;
}
示例13: QueueMultiAppend
ImapCommand QueueMultiAppend (FormatOptions options, IList<MimeMessage> messages, IList<MessageFlags> flags, IList<DateTimeOffset> dates, CancellationToken cancellationToken, ITransferProgress progress)
{
var args = new List<object> ();
string format = "APPEND %F";
args.Add (this);
for (int i = 0; i < messages.Count; i++) {
if ((flags[i] & SettableFlags) != 0)
format += " " + ImapUtils.FormatFlagsList (flags[i], 0);
if (dates != null)
format += " \"" + ImapUtils.FormatInternalDate (dates[i]) + "\"";
format += " %L";
args.Add (messages[i]);
}
format += "\r\n";
var ic = new ImapCommand (Engine, cancellationToken, null, options, format, args.ToArray ());
ic.Progress = progress;
Engine.QueueCommand (ic);
return ic;
}
示例14: QueueAppend
ImapCommand QueueAppend (FormatOptions options, MimeMessage message, MessageFlags flags, DateTimeOffset? date, CancellationToken cancellationToken, ITransferProgress progress)
{
string format = "APPEND %F";
if ((flags & SettableFlags) != 0)
format += " " + ImapUtils.FormatFlagsList (flags, 0);
if (date.HasValue)
format += " \"" + ImapUtils.FormatInternalDate (date.Value) + "\"";
format += " %L\r\n";
var ic = new ImapCommand (Engine, cancellationToken, null, options, format, this, message);
ic.Progress = progress;
Engine.QueueCommand (ic);
return ic;
}
示例15: Append
/// <summary>
/// Appends the specified message to the folder.
/// </summary>
/// <remarks>
/// Appends the specified message to the folder and returns the UniqueId assigned to the message.
/// </remarks>
/// <returns>The UID of the appended message, if available; otherwise, <c>null</c>.</returns>
/// <param name="options">The formatting options.</param>
/// <param name="message">The message.</param>
/// <param name="flags">The message flags.</param>
/// <param name="date">The received date of the message.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress reporting mechanism.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="options"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="message"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="ImapClient"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="ImapClient"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="ImapClient"/> is not authenticated.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// Internationalized formatting was requested but has not been enabled.
/// </exception>
/// <exception cref="FolderNotFoundException">
/// The <see cref="ImapFolder"/> does not exist.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// Internationalized formatting was requested but is not supported by the server.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ImapProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="ImapCommandException">
/// The server replied with a NO or BAD response.
/// </exception>
public override UniqueId? Append (FormatOptions options, MimeMessage message, MessageFlags flags, DateTimeOffset date, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
{
if (options == null)
throw new ArgumentNullException ("options");
if (message == null)
throw new ArgumentNullException ("message");
CheckState (false, false);
if (options.International && (Engine.Capabilities & ImapCapabilities.UTF8Accept) == 0)
throw new NotSupportedException ("The IMAP server does not support the UTF8 extension.");
var format = options.Clone ();
format.NewLineFormat = NewLineFormat.Dos;
if ((Engine.Capabilities & ImapCapabilities.UTF8Only) == ImapCapabilities.UTF8Only)
format.International = true;
if (format.International && !Engine.UTF8Enabled)
throw new InvalidOperationException ("The UTF8 extension has not been enabled.");
var ic = QueueAppend (format, message, flags, date, cancellationToken, progress);
Engine.Wait (ic);
ProcessResponseCodes (ic, this);
if (ic.Response != ImapCommandResponse.Ok)
throw ImapCommandException.Create ("APPEND", ic);
var append = ic.RespCodes.OfType<AppendUidResponseCode> ().FirstOrDefault ();
if (append != null)
return append.UidSet[0];
return null;
}