/// <summary>
        /// Sends this instance.
        /// </summary>
        /// <remarks>Documented by Dev02, 2009-07-15</remarks>
        private void Send()
        {
            TrayIconSetText(trayicon, Properties.Resources.ERROR_TRANSMIT_SENDING, showMessages);

            //begin with chunking and transfer
            ErrorReportService.ErrorReportService errorReportService = null;
            bool success = false;
            try
            {
                if (!SendingCanceled)
                {
                    //read out report data
                    byte[] buffer = File.ReadAllBytes(reportfile);
                    string filename = Path.GetFileName(reportfile);

                    ErrorReportHandler handler = new ErrorReportHandler(new FileInfo(reportfile));
                    string email = String.Empty, description = String.Empty, stacktrace = String.Empty;
                    try
                    {
                        email = handler.GetValue(Resources.ERRORREPORTPATH_USEREMAIL);
                        description = handler.GetValue(Resources.ERRORREPORTPATH_USERDESCRIPTION);
                    }
                    catch (Exception exp)
                    {
                        Trace.WriteLine("Reading user data from ErrorReport Exception: " + exp.ToString());
                    }
                    try
                    {
                        stacktrace = handler.GetValue(Resources.ERRORREPORTPATH_MESSAGE) + Environment.NewLine +
                            handler.GetValue(Resources.ERRORREPORTPATH_STACKTRACE);
                    }
                    catch (Exception exp)
                    {
                        Trace.WriteLine("Reading error data from ErrorReport Exception: " + exp.ToString());
                    }

                    //try to connect to webservice
                    errorReportService = new ErrorReportService.ErrorReportService();
                    errorReportService.Url = Properties.Settings.Default.MLifterErrorHandler_ErrorReportService_ErrorReportService;
                    errorReportService.CookieContainer = new System.Net.CookieContainer();

                    int chunksize = Settings.Default.Transfer_Chunksize;
                    int partcount = Convert.ToInt32(Math.Ceiling(buffer.Length * 1.0 / chunksize));
                    if (success = errorReportService.TransferStart(filename, buffer.Length, chunksize, email, description, stacktrace))
                    {
                        byte[] chunk = new byte[chunksize];
                        for (int partno = 0; partno < partcount; partno++)
                        {
                            if (SendingCanceled)
                            {
                                success = false;
                                break;
                            }

                            int length = partno == partcount - 1 ? buffer.Length % chunksize : chunksize;
                            Buffer.BlockCopy(buffer, partno * chunksize, chunk, 0, length);

                            if (!(success = errorReportService.TransferChunk(filename, chunk, partcount)))
                            {
                                break;
                            }
                            else
                            {
                                TrayIconSetText(trayicon, string.Format(Properties.Resources.ERROR_TRANSMIT_SENDSTAT, 1.0 * partno / partcount), false);
                                TrayIconPercent(trayicon, 1.0 * partno / partcount);
                            }
                        }
                        if (success)
                        {
                            success = errorReportService.TransferFinish(filename, partcount);
                        }
                    }
                }

                if (!success)
                {
                    TrayIconSetText(trayicon, Properties.Resources.ERROR_TRANSMIT_SERVERERROR, showMessages);
                }
            }
            catch
            {
                success = false;
                TrayIconSetText(trayicon, Properties.Resources.ERROR_TRANSMIT_ERROR, showMessages);
            }
            finally
            {
                if (errorReportService != null)
                    errorReportService.Abort();
            }

            SendingSuccess = success;

            if (!SendingSuccess && !SendingCanceled && showMessages) //in case an error message needs to be shown, delay the thread termination
            {
                //set the events to enable close form on click
                this.Invoke((MethodInvoker)delegate()
                {
                    if (!success && showMessages)
                        SetTrayIconClickCloseForm(trayicon);

                });

                //wait before closing the form anyway
                System.Threading.Thread.Sleep(10000);
            }

            this.Invoke((MethodInvoker)delegate()
            {
                if (this.IsHandleCreated && !this.IsDisposed)
                    this.Close();
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends this instance.
        /// </summary>
        /// <remarks>Documented by Dev02, 2009-07-15</remarks>
        private void Send()
        {
            TrayIconSetText(trayicon, Properties.Resources.ERROR_TRANSMIT_SENDING, showMessages);

            //begin with chunking and transfer
            ErrorReportService.ErrorReportService errorReportService = null;
            bool success = false;

            try
            {
                if (!SendingCanceled)
                {
                    //read out report data
                    byte[] buffer   = File.ReadAllBytes(reportfile);
                    string filename = Path.GetFileName(reportfile);

                    ErrorReportHandler handler = new ErrorReportHandler(new FileInfo(reportfile));
                    string             email = String.Empty, description = String.Empty, stacktrace = String.Empty;
                    try
                    {
                        email       = handler.GetValue(Resources.ERRORREPORTPATH_USEREMAIL);
                        description = handler.GetValue(Resources.ERRORREPORTPATH_USERDESCRIPTION);
                    }
                    catch (Exception exp)
                    {
                        Trace.WriteLine("Reading user data from ErrorReport Exception: " + exp.ToString());
                    }
                    try
                    {
                        stacktrace = handler.GetValue(Resources.ERRORREPORTPATH_MESSAGE) + Environment.NewLine +
                                     handler.GetValue(Resources.ERRORREPORTPATH_STACKTRACE);
                    }
                    catch (Exception exp)
                    {
                        Trace.WriteLine("Reading error data from ErrorReport Exception: " + exp.ToString());
                    }

                    //try to connect to webservice
                    errorReportService                 = new ErrorReportService.ErrorReportService();
                    errorReportService.Url             = Properties.Settings.Default.MLifterErrorHandler_ErrorReportService_ErrorReportService;
                    errorReportService.CookieContainer = new System.Net.CookieContainer();

                    int chunksize = Settings.Default.Transfer_Chunksize;
                    int partcount = Convert.ToInt32(Math.Ceiling(buffer.Length * 1.0 / chunksize));
                    if (success = errorReportService.TransferStart(filename, buffer.Length, chunksize, email, description, stacktrace))
                    {
                        byte[] chunk = new byte[chunksize];
                        for (int partno = 0; partno < partcount; partno++)
                        {
                            if (SendingCanceled)
                            {
                                success = false;
                                break;
                            }

                            int length = partno == partcount - 1 ? buffer.Length % chunksize : chunksize;
                            Buffer.BlockCopy(buffer, partno * chunksize, chunk, 0, length);

                            if (!(success = errorReportService.TransferChunk(filename, chunk, partcount)))
                            {
                                break;
                            }
                            else
                            {
                                TrayIconSetText(trayicon, string.Format(Properties.Resources.ERROR_TRANSMIT_SENDSTAT, 1.0 * partno / partcount), false);
                                TrayIconPercent(trayicon, 1.0 * partno / partcount);
                            }
                        }
                        if (success)
                        {
                            success = errorReportService.TransferFinish(filename, partcount);
                        }
                    }
                }

                if (!success)
                {
                    TrayIconSetText(trayicon, Properties.Resources.ERROR_TRANSMIT_SERVERERROR, showMessages);
                }
            }
            catch
            {
                success = false;
                TrayIconSetText(trayicon, Properties.Resources.ERROR_TRANSMIT_ERROR, showMessages);
            }
            finally
            {
                if (errorReportService != null)
                {
                    errorReportService.Abort();
                }
            }

            SendingSuccess = success;

            if (!SendingSuccess && !SendingCanceled && showMessages)             //in case an error message needs to be shown, delay the thread termination
            {
                //set the events to enable close form on click
                this.Invoke((MethodInvoker) delegate()
                {
                    if (!success && showMessages)
                    {
                        SetTrayIconClickCloseForm(trayicon);
                    }
                });

                //wait before closing the form anyway
                System.Threading.Thread.Sleep(10000);
            }

            this.Invoke((MethodInvoker) delegate()
            {
                if (this.IsHandleCreated && !this.IsDisposed)
                {
                    this.Close();
                }
            });
        }