Beispiel #1
0
 void OnSmartWebClient_OpenReadCompleted(object sender, SwcOpenReadCompletedEventArgs ev)
 {
     if (SmartWebClient_OpenReadCompleted != null)
     {
         SmartWebClient_OpenReadCompleted(sender, ev);
     }
 }
Beispiel #2
0
        void On_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                throw new WebClientPlusException(WebClientPlusException.Messages.OpenReadCancelled);
            }
            if (e.Error != null)
            {
                throw new WebClientPlusException(WebClientPlusException.Messages.OpenReadInnerException, e.Error);
            }
            //
            // use the result
            //
            //AsyncCopy asyncStreamCopy = new AsyncCopy(e.Result);
            //Stream copied = asyncStreamCopy.Do();
            const int count = 1024;
            int       read  = 0;

            byte [] buffer = new byte[count];
            //Stream copied = new BufferedStream(e.Result, count);
            MemoryStream copied = new MemoryStream();

            try
            {
                // read position automatically advances
                while (e.Result.CanRead &&
                       (read = e.Result.Read(buffer, 0, count)) > 0)
                {
                    copied.Write(buffer, 0, read);
                    //offset += read;
                }
                if (e.Result != null)
                {
                    e.Result.Close();
                    e.Result.Dispose();
                }
            }
            catch { }
            //
            // fire local matching event
            //
            SwcOpenReadCompletedEventArgs swce = new SwcOpenReadCompletedEventArgs();

            swce.UsableStream = copied;
            OnSmartWebClient_OpenReadCompleted(sender, swce);
        }
 void On_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
 {
     if (e.Cancelled)
     throw new WebClientPlusException(WebClientPlusException.Messages.OpenReadCancelled);
       if (e.Error != null)
     throw new WebClientPlusException(WebClientPlusException.Messages.OpenReadInnerException, e.Error);
       //
       // use the result
       //
       //AsyncCopy asyncStreamCopy = new AsyncCopy(e.Result);
       //Stream copied = asyncStreamCopy.Do();
       const int count = 1024;
       int read = 0;
       byte [] buffer = new byte[count];
       //Stream copied = new BufferedStream(e.Result, count);
       MemoryStream copied = new MemoryStream();
       try
       {
     // read position automatically advances
     while (e.Result.CanRead &&
       (read = e.Result.Read(buffer, 0, count)) > 0)
     {
       copied.Write(buffer, 0, read);
       //offset += read;
     }
     if (e.Result != null)
     {
       e.Result.Close();
       e.Result.Dispose();
     }
       }
       catch { }
       //
       // fire local matching event
       //
       SwcOpenReadCompletedEventArgs swce = new SwcOpenReadCompletedEventArgs();
       swce.UsableStream = copied;
       OnSmartWebClient_OpenReadCompleted(sender, swce);
 }
 void OnSmartWebClient_OpenReadCompleted(object sender, SwcOpenReadCompletedEventArgs ev)
 {
     if (SmartWebClient_OpenReadCompleted != null)
       {
     SmartWebClient_OpenReadCompleted(sender, ev);
       }
 }