Esempio n. 1
0
 internal void ActivatePerfDownloadEvent(object sender, DownloadCompleteEventArgs eventArgs)
 {
     base.CheckDisposed();
     if (this.DownloadsCompleted != null)
     {
         this.DownloadsCompleted(sender, eventArgs);
     }
 }
Esempio n. 2
0
        // Token: 0x06000134 RID: 308 RVA: 0x00006C24 File Offset: 0x00004E24
        public IAsyncResult BeginCommand(ImapCommand command, bool processResponse, ImapConnectionContext imapConnectionContext, AsyncCallback callback, object callbackState)
        {
            base.CheckDisposed();
            byte[] array = command.ToBytes();
            this.currentResponse.Reset(command);
            this.currentCommand = command;
            AsyncResult <ImapConnectionContext, ImapResultData> asyncResult = new AsyncResult <ImapConnectionContext, ImapResultData>(this, imapConnectionContext, callback, callbackState);

            asyncResult.State.TimeSent = ExDateTime.MinValue;
            if (this.cancellationRequested)
            {
                asyncResult.SetCompletedSynchronously();
                this.HandleCancellation(asyncResult);
                return(asyncResult);
            }
            if (this.isNetworkConnectionShutdown)
            {
                asyncResult.SetCompletedSynchronously();
                ImapNetworkFacade.HandleError(ImapNetworkFacade.GetConnectionClosedException(), asyncResult);
                return(asyncResult);
            }
            this.totalBytesSent += (long)array.Length;
            if (this.totalBytesSent > this.connectionParameters.MaxBytesToTransfer)
            {
                asyncResult.SetCompletedSynchronously();
                ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesSentExceeded(), asyncResult);
                return(asyncResult);
            }
            if (processResponse && this.totalBytesReceived > this.connectionParameters.MaxBytesToTransfer)
            {
                asyncResult.State.Log.Debug("Not sending {0}, since we've exceeded our received-bytes threshold.", new object[]
                {
                    this.currentCommand.ToPiiCleanString()
                });
                asyncResult.SetCompletedSynchronously();
                ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesReceivedExceeded(), asyncResult);
                return(asyncResult);
            }
            asyncResult.State.Log.Info("IMAP Send command: [{0}]", new object[]
            {
                this.currentCommand.ToPiiCleanString()
            });
            DownloadCompleteEventArgs eventArgs = new DownloadCompleteEventArgs(0L, (long)array.Length);

            imapConnectionContext.ActivatePerfDownloadEvent(imapConnectionContext, eventArgs);
            if (processResponse)
            {
                asyncResult.PendingAsyncResult = this.networkConnection.BeginWrite(array, 0, array.Length, new AsyncCallback(this.OnEndWriteCommandOrLiteralBeginReadResponse), asyncResult);
            }
            else
            {
                asyncResult.PendingAsyncResult = this.networkConnection.BeginWrite(array, 0, array.Length, new AsyncCallback(this.OnEndSendCommandIgnoreResponse), asyncResult);
                asyncResult.SetCompletedSynchronously();
                this.currentResultData.Clear();
                asyncResult.ProcessCompleted(this.currentResultData);
            }
            return(asyncResult);
        }
Esempio n. 3
0
        void onCheckQuotaCompleted(object sender, DownloadCompleteEventArgs<int> e)
        {
            if (e.Result > 0)
                _service.GetBatchAsync(1000, RandomNumberService.MinValue, RandomNumberService.MaxValue);
            else
            {
                _isDownloading = false;

                if (e.Error == null)
                {
                    var han = QuotaExceeded;
                    if (han != null)
                        han(this, new EventArgs());
                }
            }
        }
        public void OnDownloadCompleted(object sender, DownloadCompleteEventArgs e)
        {
            if (!this.Dispatcher.CheckAccess())
            {
                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new DownloadCompleteEventHandler((s, e2) => {
                    OnDownloadCompleted(s, e2);
                }), sender, e);
                return;
            }

            BlockControls(false);

            webProvider.DownloadStarted   -= Proxy.OnDownloadStarted;
            webProvider.DownloadCompleted -= Proxy.OnDownloadCompleted;
            webProvider.StatusChanged     -= Proxy.OnStatusChanged;

            ProgressBlock.Visibility = Visibility.Collapsed;
            switch (e.Code)
            {
            case DMODownloadResultCode.OK:
            {
                CurrentGuild = MergeHelper.Merge(e.Guild);
                GuildInfoModel.LoadData(CurrentGuild);
                TDBlock_.SetGuild(CurrentGuild);
                break;
            }

            case DMODownloadResultCode.CANT_GET:
            {
                DialogManager.ShowErrorDialog(LanguageManager.Model.CantGetError);
                break;
            }

            case DMODownloadResultCode.NOT_FOUND:
            {
                DialogManager.ShowErrorDialog(LanguageManager.Model.GuildNotFoundError);
                break;
            }

            case DMODownloadResultCode.WEB_ACCESS_ERROR:
            {
                DialogManager.ShowErrorDialog(LanguageManager.Model.ConnectionError);
                break;
            }
            }
        }
Esempio n. 5
0
 // called on download complete of each package/file
 public void downloadCompleteCallback(Uri packageSource, DownloadCompleteEventArgs e)
 {
     m_packageDownloadCount--;
     // if download is complete set source to a package of our choice
     if (m_packageDownloadCount <= 0)
     {
         // ! note that for the demo's sake we are just setting the active xap to be the first xap on the list.
         //   you should probably modify this if you have more then one xap on the list !
         foreach (Uri source in m_packageSourceList.Keys)
         {
             if (source.ToString().EndsWith(".xap"))
             {
                 // this will unload the the loader from the page and cause the package source to become the active xap file on page
                 // ! this should be the last loader operation after that it will start the unload process !
                 XapUtil.setCurrentXapFile(source);
                 break;
             }
         }
     }
 }
Esempio n. 6
0
        public void OnDownloadCompleted(object sender, DownloadCompleteEventArgs e)
        {
            if (!this.Dispatcher.CheckAccess())
            {
                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new DownloadCompleteEventHandler((s, e2) => {
                    OnDownloadCompleted(s, e2);
                }), sender, e);
                return;
            }

            if (e.Code != DMODownloadResultCode.OK)
            {
                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => {
                    loader.Title = LanguageManager.Model.ErrorOccured + " [" + e.Code + "]";
                    switch (e.Code)
                    {
                    case DMODownloadResultCode.CANT_GET:
                        {
                            loader.Summary = LanguageManager.Model.CantGetError;
                            break;
                        }

                    case DMODownloadResultCode.NOT_FOUND:
                        {
                            loader.Summary = LanguageManager.Model.GuildNotFoundError;
                            break;
                        }

                    case DMODownloadResultCode.WEB_ACCESS_ERROR:
                        {
                            loader.Summary = LanguageManager.Model.ConnectionError;
                            break;
                        }
                    }
                    IsErrorOccured = true;
                }));
                return;
            }
            Guild = MergeHelper.Merge(e.Guild);
        }
Esempio n. 7
0
 // Token: 0x06000148 RID: 328 RVA: 0x0000786C File Offset: 0x00005A6C
 private void OnEndWriteLiteral(IAsyncResult asyncResult)
 {
     lock (this.syncRoot)
     {
         if (this.ShouldCancelCallback())
         {
             NetworkConnection networkConnection = this.ExtractNetworkConnectionFrom(asyncResult);
             object            obj2;
             networkConnection.EndWrite(asyncResult, out obj2);
         }
         else
         {
             base.CheckDisposed();
             AsyncResult <ImapConnectionContext, ImapResultData> asyncResult2 = (AsyncResult <ImapConnectionContext, ImapResultData>)asyncResult.AsyncState;
             object obj2;
             this.networkConnection.EndWrite(asyncResult, out obj2);
             if (obj2 != null)
             {
                 ImapNetworkFacade.HandleError(obj2, asyncResult2);
             }
             else if (this.cancellationRequested)
             {
                 this.HandleCancellation(asyncResult2);
             }
             else
             {
                 ExTraceGlobals.FaultInjectionTracer.TraceTest(3748015421U);
                 this.totalBytesSent += (long)ImapNetworkFacade.BytesCrLf.Length;
                 DownloadCompleteEventArgs eventArgs = new DownloadCompleteEventArgs(0L, (long)ImapNetworkFacade.BytesCrLf.Length);
                 asyncResult2.State.ActivatePerfDownloadEvent(asyncResult2.State, eventArgs);
                 asyncResult2.State.Log.Debug("Literal sent, sending CRLF to complete it.", new object[0]);
                 asyncResult2.PendingAsyncResult = this.networkConnection.BeginWrite(ImapNetworkFacade.BytesCrLf, 0, ImapNetworkFacade.BytesCrLf.Length, new AsyncCallback(this.OnEndWriteCommandOrLiteralBeginReadResponse), asyncResult2);
             }
         }
     }
 }
Esempio n. 8
0
 // Token: 0x06000147 RID: 327 RVA: 0x000075E4 File Offset: 0x000057E4
 private void OnReadAndDiscardLine(IAsyncResult asyncResult)
 {
     lock (this.syncRoot)
     {
         if (this.ShouldCancelCallback())
         {
             NetworkConnection networkConnection = this.ExtractNetworkConnectionFrom(asyncResult);
             byte[]            data;
             int    offset;
             int    num;
             object obj2;
             networkConnection.EndRead(asyncResult, out data, out offset, out num, out obj2);
         }
         else
         {
             base.CheckDisposed();
             AsyncResult <ImapConnectionContext, ImapResultData> asyncResult2 = (AsyncResult <ImapConnectionContext, ImapResultData>)asyncResult.AsyncState;
             ImapResponse imapResponse = this.currentResponse;
             byte[]       data;
             int          offset;
             int          num;
             object       obj2;
             this.networkConnection.EndRead(asyncResult, out data, out offset, out num, out obj2);
             if (obj2 != null)
             {
                 ImapNetworkFacade.HandleError(obj2, asyncResult2);
             }
             else if (this.cancellationRequested)
             {
                 this.HandleCancellation(asyncResult2);
             }
             else
             {
                 ExTraceGlobals.FaultInjectionTracer.TraceTest(4284886333U);
                 this.totalBytesReceived += (long)num;
                 DownloadCompleteEventArgs eventArgs = new DownloadCompleteEventArgs((long)num, 0L);
                 asyncResult2.State.ActivatePerfDownloadEvent(asyncResult2.State, eventArgs);
                 if (this.totalBytesReceived > this.connectionParameters.MaxBytesToTransfer)
                 {
                     ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesReceivedExceeded(), asyncResult2);
                 }
                 else
                 {
                     int num2 = imapResponse.AddData(data, offset, num);
                     int num3 = num - num2;
                     this.Log.Assert(num3 >= 0, "The unconsumed bytes must be non-negative.", new object[0]);
                     if (num3 > 0)
                     {
                         this.networkConnection.PutBackReceivedBytes(num3);
                     }
                     if (imapResponse.IsComplete)
                     {
                         this.currentResultData.Clear();
                         this.currentResultData.Status = imapResponse.Status;
                         if (asyncResult.CompletedSynchronously)
                         {
                             asyncResult2.SetCompletedSynchronously();
                         }
                         asyncResult2.State.Log.Assert(this.currentCommand == null, "this.currentCommand is expected to be null", new object[0]);
                         if (imapResponse.Status == ImapStatus.No || imapResponse.Status == ImapStatus.Bad || imapResponse.Status == ImapStatus.Bye)
                         {
                             this.LogFailureDetails("Connecting", imapResponse);
                             asyncResult2.ProcessCompleted(this.currentResultData);
                         }
                         else
                         {
                             asyncResult2.State.Log.Assert(imapResponse.ResponseLines != null && imapResponse.ResponseLines.Count > 0, "ResponseLines was null or had no content", new object[0]);
                             if (imapResponse.Status != ImapStatus.Ok)
                             {
                                 asyncResult2.ProcessCompleted(this.BuildAndLogUnknownCommandFailureException(asyncResult2.State, "Connecting"));
                             }
                             else
                             {
                                 asyncResult2.ProcessCompleted(this.currentResultData);
                             }
                         }
                     }
                     else
                     {
                         asyncResult2.PendingAsyncResult = this.BeginNetworkRead(asyncResult2, new AsyncCallback(this.OnReadAndDiscardLine));
                     }
                 }
             }
         }
     }
 }
Esempio n. 9
0
    void webBrowserEvents2_DownloadComplete()
    {
        var htmlDocument = _webBrowser2.Document as mshtml.HTMLDocument;

        var eventArgs = new DownloadCompleteEventArgs();
            eventArgs.Uri = _webBrowser2.LocationURL;
            eventArgs.PageTitle = htmlDocument.title;
                    
        DownloadComplete( this, eventArgs );
    }
Esempio n. 10
0
        /// <summary>
        /// Constructs SmilDocument and sets it as active from the SMIL file contents.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetSmilFileComplete(object sender, DownloadCompleteEventArgs e)
        {
            //Remove the event
            //This prevents a file from getting opened twice causing an exception when trying to read
            //the stream of the document since the file has already been opened and is currently stored
            //in memory.
            ((IFile)sender).OpenAsyncComplete -= GetSmilFileComplete;

            PhraseConstructionKit phraseConstruction = e.UserState as PhraseConstructionKit;

            XDocument smilXml;
            try
            {
                e.Result.Seek(0, SeekOrigin.Begin);
                smilXml = XDocument.Load(e.Result, LoadOptions.SetBaseUri);
            }
            catch(Exception ex)
            {
                Logger.Log("Stream length = " + e.Result.Length + "; Error: " + ex);
                throw;
            }

            SmilDocument currentSmilDocument = e.UserState as SmilDocument;

            //Load into SmilDocument object
            currentSmilDocument = new SmilDocument(phraseConstruction.SmilPath, smilXml);
            _activeSmilDocument = currentSmilDocument;

            //Bail out if this isn't the expected file or SMIL reference.
            if(phraseConstruction == null
                    || _currentRequestedFileUri != phraseConstruction.SmilPath
                    || _currentPhraseConstruction.SmilReferenceID != phraseConstruction.SmilReferenceID)
                return;

            GetPhraseAudio(phraseConstruction);
        }
		private void OnDownloadCompleted(object sender, DownloadCompleteEventArgs e)
		{
		}
 void file_OpenAsyncComplete(object sender, DownloadCompleteEventArgs e)
 {
     Assert.IsTrue(e.Result != null);
 }
Esempio n. 13
0
        private void ncxFile_OpenAsyncComplete(object sender, DownloadCompleteEventArgs e)
        {
            //Remove the event
            //This prevents a file from getting opened twice causing an exception when trying to read
            //the stream of the document since the file has already been opened and is currently stored
            //in memory.
            ((IFile)sender).OpenAsyncComplete -= ncxFile_OpenAsyncComplete;

            XDocument xml;
            try
            {
                xml = XDocument.Load(e.Result);
            }
            catch (Exception ex)
            {
                Logger.Log("Stream length = " + e.Result.Length + "; Error: " + ex.ToString());
                throw;
            }
            _book.TableOfContents = new TableOfContents(xml);
            _book.PageList = new PageList(xml);

            // This is the last asynchronous operation - we can tell listeners (our view) that
            // the book has been created now.
            if (BookCreated != null)
            {
                BookCreated(this, new BookCreateEventArgs(_book));
            }
        }
        /// <summary>
        /// This method is called when a book opf file has been asynchronously opened. Then we can begin to create a Package for
        /// the loaded book.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The EventArgs containing the book opf and the parent directory path.</param>
        private void file_OpenAsyncComplete(object sender, DownloadCompleteEventArgs e)
        {
            //Remove the event
            //This prevents a file from getting opened twice causing an exception when trying to read
            //the stream of the document since the file has already been opened and is currently stored
            //in memory.
            ((IFile)sender).OpenAsyncComplete -= file_OpenAsyncComplete;

            // TODO: Proper regex or other types of path handling to get the parent directory
            // Cheat, currently just grab the url given in the query string till the last '/' and use that
            // as the parent directory
            string opfParentDirectory = e.UserState.ToString().Substring(0, e.UserState.ToString().LastIndexOf('/'));

            IPackage package = new Package300(e.Result);
            package.BookFolder = opfParentDirectory;
            SetCurrentBook(package);
        }
        public void OpenAsync(string userState)
        {
            // Not really implemented asynchronously at the moment. We wanted to have this to make
            // opening files from web servers the same process as reading local/inmemory files. Web
            // resources can only accessed asynchronously (via WebClient)
            Exception error = null;
            Stream stream = null;

            try
            {
            stream = Open(FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            catch (Exception e)
            {
            error = e;
            }

            // Raise event if anyone is listening
            if (OpenAsyncComplete != null)
            {
            DownloadCompleteEventArgs eventArgs = new DownloadCompleteEventArgs(stream, error, false, userState);
            OpenAsyncComplete(this, eventArgs);
            }
        }
Esempio n. 16
0
 protected void onComplete(DownloadCompleteEventArgs e)
 {
     DownloadCompleteEventHandler handler = DownloadEvent;
     if (handler != null)
     {
         handler(this, e);
     }
 }
Esempio n. 17
0
        public void start(string url, string localDir, string fileName)
        {
            Console.Out.WriteLine("start download.");
            this.url = url;
            this.localDir = localDir;
            this.fileName = fileName;

            //If file exists, get the pointer of the stream
            if(File.Exists(localDir))
            {
                fs = File.OpenWrite(localDir);
                startPos = fs.Length;
                fs.Seek(startPos,SeekOrigin.Current);

            }else{

                fs = new FileStream(localDir, FileMode.Create);
                startPos = 0;

            }

            try
            {
                request = (HttpWebRequest)HttpWebRequest.Create(url);

                //if there is an existing file, add range parameters to the request
                if (startPos > 0)
                {
                    request.AddRange((int)startPos);
                }

                responeStream = request.GetResponse().GetResponseStream();

                byte[] nBytes = new byte[512];
                int nReadSize = 0;
                nReadSize = responeStream.Read(nBytes, 0, 512);
                while (nReadSize > 0)
                {
                    fs.Write(nBytes, 0, nReadSize);
                    nReadSize = responeStream.Read(nBytes, 0, 512);
                    Console.Out.WriteLine(nReadSize.ToString());
                }

                fs.Close();
                responeStream.Close();
                DownloadCompleteEventArgs e = new DownloadCompleteEventArgs(fileName);
                onComplete(e);
            }
            catch (Exception ex)
            {
                fs.Close();
                if(responeStream!=null)
                    responeStream.Close();
                Console.Out.WriteLine("Exception");

                if (reConnectTimer == null)
                    reConnectTimer = new Timer();

                reConnectTimer.Interval = 3000;
                reConnectTimer.Elapsed += reConnectTimer_Elapsed;
                reConnectTimer.Start();
            }
        }
Esempio n. 18
0
 void downloader_DownloadComplete(object sender, DownloadCompleteEventArgs e)
 {
     if (OpenAsyncComplete != null)
     {
         OpenAsyncComplete(this, e);
     }
 }
Esempio n. 19
0
 // Token: 0x0600014A RID: 330 RVA: 0x00007AA4 File Offset: 0x00005CA4
 private void OnReadMoreResponse(IAsyncResult asyncResult)
 {
     lock (this.syncRoot)
     {
         if (this.ShouldCancelCallback())
         {
             NetworkConnection networkConnection = this.ExtractNetworkConnectionFrom(asyncResult);
             byte[]            data;
             int    offset;
             int    num;
             object obj2;
             networkConnection.EndRead(asyncResult, out data, out offset, out num, out obj2);
         }
         else
         {
             base.CheckDisposed();
             AsyncResult <ImapConnectionContext, ImapResultData> asyncResult2 = (AsyncResult <ImapConnectionContext, ImapResultData>)asyncResult.AsyncState;
             ImapResponse imapResponse = this.currentResponse;
             byte[]       data;
             int          offset;
             int          num;
             object       obj2;
             this.networkConnection.EndRead(asyncResult, out data, out offset, out num, out obj2);
             if (obj2 != null)
             {
                 ImapNetworkFacade.HandleError(obj2, asyncResult2);
             }
             else if (this.cancellationRequested)
             {
                 this.HandleCancellation(asyncResult2);
             }
             else
             {
                 ExTraceGlobals.FaultInjectionTracer.TraceTest(2674273597U);
                 this.totalBytesReceived += (long)num;
                 DownloadCompleteEventArgs eventArgs = new DownloadCompleteEventArgs((long)num, 0L);
                 asyncResult2.State.ActivatePerfDownloadEvent(asyncResult2.State, eventArgs);
                 if (this.totalBytesReceived > this.connectionParameters.MaxBytesToTransfer)
                 {
                     ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesReceivedExceeded(), asyncResult2);
                 }
                 else
                 {
                     int num2 = imapResponse.AddData(data, offset, num);
                     int num3 = num - num2;
                     this.Log.Assert(num3 >= 0, "The unconsumed bytes must be non-negative.", new object[0]);
                     if (num3 > 0)
                     {
                         this.networkConnection.PutBackReceivedBytes(num3);
                     }
                     if (imapResponse.IsComplete)
                     {
                         ImapNetworkFacade.CountCommand(asyncResult2, true);
                         asyncResult2.State.Log.Debug("Command complete: [{0}].  Status = {1}", new object[]
                         {
                             this.currentCommand.ToPiiCleanString(),
                             imapResponse.Status
                         });
                         this.currentResultData.Status = imapResponse.Status;
                         if (asyncResult.CompletedSynchronously)
                         {
                             asyncResult2.SetCompletedSynchronously();
                         }
                         if (imapResponse.Status == ImapStatus.No || imapResponse.Status == ImapStatus.Bad || imapResponse.Status == ImapStatus.Bye)
                         {
                             this.LogFailureDetails(this.currentCommand, imapResponse);
                             asyncResult2.ProcessCompleted(this.currentResultData);
                         }
                         else if (imapResponse.Status != ImapStatus.Ok)
                         {
                             this.LogFailureDetails(this.currentCommand, imapResponse);
                             asyncResult2.ProcessCompleted(this.BuildAndLogUnknownCommandFailureException(asyncResult2.State));
                         }
                         else
                         {
                             if (!imapResponse.TryParseIntoResult(this.currentCommand, ref this.currentResultData))
                             {
                                 if (this.currentResultData.FailureException == null)
                                 {
                                     if (this.currentResultData.MessageStream != null)
                                     {
                                         this.totalMessagesReceived += 1UL;
                                     }
                                     asyncResult2.ProcessCompleted(this.currentResultData, this.BuildAndLogUnknownParseFailureException(asyncResult2.State));
                                     return;
                                 }
                                 ImapUtilities.LogExceptionDetails(asyncResult2.State.Log, this.currentCommand, this.currentResultData.FailureException);
                                 this.LogFailureDetails(this.currentCommand, this.currentResponse);
                             }
                             else
                             {
                                 asyncResult2.State.Log.Debug("Parsed server response succesfully.", new object[0]);
                             }
                             asyncResult2.ProcessCompleted(this.currentResultData);
                         }
                     }
                     else if (imapResponse.IsWaitingForLiteral)
                     {
                         Exception ex = null;
                         Stream    commandParameterStream = this.currentCommand.GetCommandParameterStream(this.serverParameters.Server, imapResponse.GetLastResponseLine(), out ex);
                         if (ex != null)
                         {
                             if (commandParameterStream != null)
                             {
                                 commandParameterStream.Close();
                             }
                             ImapNetworkFacade.CountCommand(asyncResult2, false);
                             asyncResult2.ProcessCompleted(ex);
                         }
                         else if (commandParameterStream == null)
                         {
                             ImapNetworkFacade.CountCommand(asyncResult2, false);
                             asyncResult2.ProcessCompleted(this.BuildAndLogUnexpectedLiteralRequestException(asyncResult2.State));
                         }
                         else
                         {
                             this.totalBytesSent += commandParameterStream.Length;
                             if (this.totalBytesSent > this.connectionParameters.MaxBytesToTransfer)
                             {
                                 ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesSentExceeded(), asyncResult2);
                             }
                             else
                             {
                                 eventArgs = new DownloadCompleteEventArgs(0L, commandParameterStream.Length);
                                 asyncResult2.State.ActivatePerfDownloadEvent(asyncResult2.State, eventArgs);
                                 asyncResult2.State.Log.Debug("Begin writing literal stream.", new object[0]);
                                 asyncResult2.PendingAsyncResult = this.networkConnection.BeginWrite(commandParameterStream, new AsyncCallback(this.OnEndWriteLiteral), asyncResult2);
                             }
                         }
                     }
                     else if (imapResponse.TotalLiteralBytesExpected > 0 && this.totalBytesReceived + (long)imapResponse.LiteralBytesRemaining > this.connectionParameters.MaxBytesToTransfer)
                     {
                         this.totalBytesReceived += (long)imapResponse.LiteralBytesRemaining;
                         ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesReceivedExceeded(), asyncResult2);
                     }
                     else
                     {
                         asyncResult2.PendingAsyncResult = this.BeginNetworkRead(asyncResult2, new AsyncCallback(this.OnReadMoreResponse));
                     }
                 }
             }
         }
     }
 }
Esempio n. 20
0
        /// <summary>
        /// Asynchronously load the Xml for the book, then begin loading the book table of contents/navigation points
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dtBookFile_OpenAsyncComplete(object sender, DownloadCompleteEventArgs e)
        {
            //Remove the event
            //This prevents a file from getting opened twice causing an exception when trying to read
            //the stream of the document since the file has already been opened and is currently stored
            //in memory.
            ((IFile)sender).OpenAsyncComplete -= dtBookFile_OpenAsyncComplete;

            if (e.Error == null)
            {
                IPackage package = e.UserState as IPackage;

                if (package != null)
                {
                    // TODO: Make member variable for _book
                    _book.Xml = XDocument.Load(e.Result);
                    //If the Book Folder for the package has been defined (for example with server books), then use the folder
                    //otherwise, call GetBookFolder to try and find the book folder
                    if (package.BookFolder != null)
                    {
                        _book.FolderPath = FileSystem.GetDirectory(package.BookFolder);
                    }
                    else
                    {
                        _book.FolderPath = FileSystem.GetDirectory(GetBookFolder(package.BookId).FullName);
                    }

                    _book.IsBrowseable = FileSystem.IsBrowsable;

                    // If the FileSystem is browsable we may need to convert the image src paths
                    if (FileSystem.IsBrowsable)
                    {
                        ConvertImagePaths();
                    }

                    GetTableOfContentsAsync(e.UserState as IPackage);
                }
            }

            // TODO: What to do if there is an error?
        }
Esempio n. 21
0
 /// <summary>
 /// Executed when the current file has finished downloading
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void DownloadComplete(object sender, DownloadCompleteEventArgs e)
 {
     if (OpenAsyncComplete != null)
     {
         OpenAsyncComplete(this, new DownloadCompleteEventArgs(e.Result, e.Error, e.Cancelled, _userState));
     }
 }
Esempio n. 22
0
 protected virtual void RaiseFileDownloadedEvent(DownloadCompleteEventArgs eventArgs)
 {
     FileDownloaded?.Invoke(this, eventArgs);
 }
Esempio n. 23
0
 public void OnDownloadCompleted(object sender, DownloadCompleteEventArgs e)
 {
     Object.OnDownloadCompleted(sender, e);
 }
Esempio n. 24
0
 private void file_OpenAsyncComplete(object sender, DownloadCompleteEventArgs e)
 {
     // e.UserState should store the url of the requested resource. This can then be used
     // to set the appropriate source
     BitmapImage tempImage = new BitmapImage();
     tempImage.SetSource(e.Result);
 }
 void ISilverlightLoader.downloadCompleteCallback(Uri packageSource, DownloadCompleteEventArgs eventArgs)
 {
     XapUtil.setCurrentXapFile(packageSource);
 }
Esempio n. 26
0
        private void downloader_DownloadComplete(object sender, DownloadCompleteEventArgs e)
        {
            _downloader.DownloadComplete -= downloader_DownloadComplete;

            //get the filename from the path, will just have a flat memory structure?
            //TODO better/more secure filename extraction? escaping of characters
            string filename = FileSystem.CombinePath(CacheDirectory, FullName.Substring(FullName.LastIndexOf('/') + 1));

            //if the file doesn't already exist in the cache
            if (!FileSystem.InMemoryCache.FileExists(filename))
            {
                e.Result.Position = 0;

                //we have the file now, so store it in the webfilesystem memory cache
                Stream cacheStream = FileSystem.InMemoryCache.CreateFile(filename);
                FileHelpers.CopyStream(cacheStream, e.Result);
            }

            //remove the completed download from the filesystem dictionary of downloads in progress
            FileSystem.SetCachingInProgress(FullName, null);

            //notify the last download request for this file that they can continue execution
            if (NotifyLatestDownloadRequest != null)
            {
                NotifyLatestDownloadRequest(sender, e);
            }
        }
Esempio n. 27
0
        void onGetBatchCompleted(object sender, DownloadCompleteEventArgs<IEnumerable<int>> e)
        {
            var raiseEvent = _cache.Count == 0;
            foreach (var item in e.Result)
                _cache.Enqueue(item);

            _isDownloading = false;

            if (raiseEvent)
            {
                var han = Ready;
                if (han != null)
                    han(this, new EventArgs());
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Constructs the audio clip for the current phrase to be played by the player,
        /// when it is finished the phrase is delegated to the playerpresenter for playback.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetPhraseAudioComplete(object sender, DownloadCompleteEventArgs e)
        {
            //Remove the event
            //This prevents a file from getting opened twice causing an exception when trying to read
            //the stream of the document since the file has already been opened and is currently stored
            //in memory.
            ( (IFile)sender ).OpenAsyncComplete -= GetPhraseAudioComplete;

            PhraseConstructionKit phraseConstruction = e.UserState as PhraseConstructionKit;

            //Bail out if this isn't the expected file or SMIL reference.
            if(phraseConstruction == null
                    || _currentRequestedFileUri != phraseConstruction.AudioFilePath
                    || _currentPhraseConstruction.SmilReferenceID != phraseConstruction.SmilReferenceID )
                return;

            XElement audioElement = phraseConstruction.AudioElement;
            string audioClipStart = audioElement.Attribute("clipBegin").Value;
            string audioClipEnd = audioElement.Attribute("clipEnd").Value;

            Logger.Log("CompletedAsync Audio File {0}", audioElement.Attribute("src").Value);

            Phrase currentPhrase = phraseConstruction.ConstructedPhrase;
            currentPhrase.Audio = new Audio
            {
                SourceStream = e.Result,
                ClipStart = ValueConversionHelper.GetConvertedTimeSpan(audioClipStart),
                ClipEnd = ValueConversionHelper.GetConvertedTimeSpan(audioClipEnd)
            };

            if(PresentPhrase != null)
            {
                PresentPhrase(currentPhrase, _canResumePhrase);
            }
        }
Esempio n. 29
0
        public void OpenAsync(object userState)
        {
            Exception error = null;
            Stream stream = null;

            // This is actually a synchronous call at the moment.
            try
            {
                stream = Open(FileMode.Open);
            }
            catch (Exception e)
            {
                error = e;
            }

            // Raise event if anyone is listening
            if (OpenAsyncComplete != null)
            {
                DownloadCompleteEventArgs eventArgs = new DownloadCompleteEventArgs(stream, error, false, userState);
                OpenAsyncComplete(this, eventArgs);
            }
        }