Ejemplo n.º 1
0
      private static void AddStackTraceToRequest(IList<BlackBoxExceptionEntry> stackTrace,
 PostDataBuilder builder)
      {
          int exceptionIndex = 0;
             foreach (BlackBoxExceptionEntry exceptionStack in stackTrace)
             {
          foreach (string stackFrame in exceptionStack.StackTrace)
           builder.AddPart(new PostDataField(
            string.Format("stackTrace[{0}][]", exceptionIndex), stackFrame));
          builder.AddPart(new PostDataField(string.Format(
           "stackTrace[{0}][exception]", exceptionIndex), exceptionStack.ExceptionType));
          ++exceptionIndex;
             }
      }
Ejemplo n.º 2
0
 public void Submit(ProgressChangedEventHandler progressChanged)
 {
     SteppedProgressManager overallProgress = new SteppedProgressManager();
        Compress(overallProgress, progressChanged);
        using (FileStream bzipFile = new FileStream(ReportBaseName + ".tbz",
     FileMode.Open, FileAccess.Read, FileShare.Read, 131072, FileOptions.DeleteOnClose))
        using (Stream logFile = Report.DebugLog)
        {
     PostDataBuilder builder = new PostDataBuilder();
     builder.AddPart(new PostDataField("action", "upload"));
     builder.AddPart(new PostDataFileField("crashReport", "Report.tbz", bzipFile));
     AddStackTraceToRequest(Report.StackTrace, builder);
     WebRequest reportRequest = HttpWebRequest.Create(BlackBoxServer);
     reportRequest.ContentType = builder.ContentType;
     reportRequest.Method = "POST";
     reportRequest.Timeout = int.MaxValue;
     using (Stream formStream = builder.Stream)
     {
      ProgressManager progress = new ProgressManager();
      overallProgress.Steps.Add(new SteppedProgressManagerStep(
       progress, 0.5f, "Uploading"));
      reportRequest.ContentLength = formStream.Length;
      using (Stream requestStream = reportRequest.GetRequestStream())
      {
       int lastRead = 0;
       byte[] buffer = new byte[32768];
       while ((lastRead = formStream.Read(buffer, 0, buffer.Length)) != 0)
       {
        requestStream.Write(buffer, 0, lastRead);
        progress.Completed = formStream.Position;
        progress.Total = formStream.Length;
        progressChanged(this, new ProgressChangedEventArgs(overallProgress, null));
       }
      }
     }
     try
     {
      reportRequest.GetResponse();
      Report.Submitted = true;
     }
     catch (WebException e)
     {
      using (Stream responseStream = e.Response.GetResponseStream())
      {
       try
       {
        XmlReader reader = XmlReader.Create(responseStream);
        reader.ReadToFollowing("error");
        throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture,
     "The server encountered a problem while processing the request: {0}",
     reader.ReadString()));
       }
       catch (XmlException)
       {
       }
      }
      throw new InvalidDataException(((HttpWebResponse)e.Response).StatusDescription);
     }
        }
 }