Exemplo n.º 1
0
 public void Upload(ProgressChangedEventHandler progressChanged)
 {
     using (FileStream bzipFile = new FileStream(ReportBaseName + ".tbz",
     FileMode.Open, FileAccess.Read, FileShare.Read, 131072, FileOptions.DeleteOnClose))
        using (Stream logFile = Report.DebugLog)
        {
     MultipartFormDataBuilder builder = new MultipartFormDataBuilder();
     builder.AddPart(new FormField("action", "upload"));
     builder.AddPart(new FormFileField("crashReport", "Report.tbz", bzipFile));
     AddStackTraceToRequest(Report.StackTrace, builder);
     WebRequest reportRequest = HttpWebRequest.Create(BlackBoxServer);
     reportRequest.ContentType = "multipart/form-data; boundary=" + builder.Boundary;
     reportRequest.Method = "POST";
     reportRequest.Timeout = int.MaxValue;
     using (Stream formStream = builder.Stream)
     {
      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);
        progressChanged(this, new ProgressChangedEventArgs(
     (int)(formStream.Position * 100 / formStream.Length), 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(S._("The server encountered a problem " +
     "while processing the request: {0}", reader.ReadString()));
       }
       catch (XmlException)
       {
       }
      }
      throw new InvalidDataException(((HttpWebResponse)e.Response).StatusDescription);
     }
        }
 }
Exemplo n.º 2
0
      private static void AddStackTraceToRequest(IList<BlackBoxExceptionEntry> stackTrace,
 MultipartFormDataBuilder builder)
      {
          int exceptionIndex = 0;
             foreach (BlackBoxExceptionEntry exceptionStack in stackTrace)
             {
          foreach (string stackFrame in exceptionStack.StackTrace)
           builder.AddPart(new FormField(
            string.Format("stackTrace[{0}][]", exceptionIndex), stackFrame));
          builder.AddPart(new FormField(string.Format(
           "stackTrace[{0}][exception]", exceptionIndex), exceptionStack.ExceptionType));
          ++exceptionIndex;
             }
      }
Exemplo n.º 3
0
 public bool ReportIsNew()
 {
     MultipartFormDataBuilder builder = new MultipartFormDataBuilder();
        builder.AddPart(new FormField("action", "status"));
        AddStackTraceToRequest(Report.StackTrace, builder);
        WebRequest reportRequest = HttpWebRequest.Create(BlackBoxServer);
        reportRequest.ContentType = "multipart/form-data; boundary=" + builder.Boundary;
        reportRequest.Method = "POST";
        using (Stream formStream = builder.Stream)
        {
     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);
     }
        }
        try
        {
     HttpWebResponse response = reportRequest.GetResponse() as HttpWebResponse;
     using (Stream responseStream = response.GetResponseStream())
     {
      XmlReader reader = XmlReader.Create(responseStream);
      reader.ReadToFollowing("crashReport");
      string reportStatus = reader.GetAttribute("status");
      switch (reportStatus)
      {
       case "exists":
        Report.Submitted = true;
        return false;
       case "new":
        return true;
       default:
        throw new InvalidDataException(S._("Unknown crash report server response."));
      }
     }
        }
        catch (WebException e)
        {
     using (Stream responseStream = e.Response.GetResponseStream())
     {
      try
      {
       XmlReader reader = XmlReader.Create(responseStream);
       reader.ReadToFollowing("error");
       throw new InvalidDataException(S._("The server encountered a problem " +
        "while processing the request: {0}", reader.ReadString()));
      }
      catch (XmlException)
      {
      }
     }
     throw new InvalidDataException(((HttpWebResponse)e.Response).StatusDescription);
        }
 }