/// <summary> /// Resumes all threads after stopping /// <exception cref="AltoMultiThreadDownloader.Exceptions.RemoteFilePropertiesChangedException">Thrown when download informations changed, in case of expired url or changed authentication data</exception> /// </summary> public void Resume() { var currentInfo = GetCurrentInformations(); if (currentInfo == null || !currentInfo.Equals(this.Info)) { ErrorOccured.Raise(this, new ErrorEventArgs( new RemoteFilePropertiesChangedException(this.Info, currentInfo)), aop); return; } speedBytesOffset = TotalBytesReceived; FlagStop = false; stp.Reset(); stp.Start(); createNewThreadIfRequired(); Resumed.Raise(this, EventArgs.Empty, aop); }
/// <summary> /// Invoked when an StreamManagementStanza stanza is being received. /// </summary> /// <param name="stanza">The stanza which is being received.</param> /// <returns>true to intercept the stanza or false to pass the stanza /// on to the next handler.</returns> public bool Input(StreamManagementStanza stanza) { if (stanza.Data.NamespaceURI == "urn:xmpp:sm:3") { // We need to manage: // "enabled": in response to "enable" // "a": read answer from a previous request (at each ping) // "r": request asked by the sver // "resumed": in response to "resume" // "failed": in case of pb switch (stanza.Data.LocalName) { case "failed": im.StreamManagementResumeId = ""; Failed.Raise(this, null); // /!\ This event must be ALWAYS raised before RaiseConnectionStatus !!! im.RaiseConnectionStatus(false); break; case "resumed": // in response to "resume" Resumed.Raise(this, null); // /!\ This event must be ALWAYS raised before RaiseConnectionStatus !!! im.RaiseConnectionStatus(true); break; case "enabled": // in response to "enable" // Check if the server accepts resume string resume = stanza.Data.GetAttribute("resume"); Boolean resumeHandled = (resume == "true") || (resume == "1"); // Get Id used for resume purpose String resumeId = stanza.Data.GetAttribute("id"); // Has the server accepted Stream management ? im.StreamManagementEnabled = resumeHandled && !String.IsNullOrEmpty(resumeId); // Get max delay for the resume String maxDelay = stanza.Data.GetAttribute("max"); int delay; if (!int.TryParse(maxDelay, out delay)) { delay = 86400; } // Store id and delay im.StreamManagementResumeId = resumeId; im.StreamManagementResumeDelay = delay; log.LogDebug("[Input] - StreamManagementEnabled:[{0}] - ResumeStreamManagementId:[{1}] - ResumeStreamManagementDelay:[{2}]", im.StreamManagementEnabled, im.StreamManagementResumeId, im.StreamManagementResumeDelay); break; case "a": // read answer for a request // Store last handled stanzas String h = stanza.Data.GetAttribute("h"); if (!uint.TryParse(h, out stanzasReceivedHandled)) { stanzasReceivedHandled = 0; } im.StreamManagementLastStanzaReceivedAndHandledByServer = stanzasReceivedHandled; im.StreamManagementLastStanzaDateReceivedAndHandledByServer = DateTime.UtcNow; //log.LogDebug("[Input] - StreamManagementLastStanzaReceivedAndHandledByClient:[{0}]", im.StreamManagementLastStanzaReceivedAndHandledByClient); break; case "r": // answer to the request im.StreamManagementLastStanzaReceivedAndHandledByClient = im.StreamManagementLastStanzaReceivedByClient; SendkAcknowledgement(im.StreamManagementLastStanzaReceivedAndHandledByClient); break; } return(true); } return(false); }