private void btnAddAttachment_Click(object sender, EventArgs e) { try { bool isValid = CheckConditions(); if (isValid == true) { this.Cursor = Cursors.WaitCursor; string contentType = Utils.GetFileContentType(txtFile.Text); this.NewAttachment = new Attachment(_bugID, txtFile.Text, txtDescription.Text, contentType, txtComment.Text); System.IO.FileInfo fileInfo = new System.IO.FileInfo(txtFile.Text); this.NewAttachment.Size = fileInfo.Length; if (_postWhenAdding == true) { string errorMessage = string.Empty; // post attachment IBugBSI bugProvider = (IBugBSI)BLControllerFactory.GetRegisteredConcreteFactory(this.connectionId); bugProvider.PostAttachment(this.NewAttachment, out errorMessage); if (!String.IsNullOrEmpty(errorMessage)) { string strMessage = string.Format(Messages.ErrPostFile, txtFile.Text); MessageBox.Show(this, strMessage + Environment.NewLine + errorMessage, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); this.NewAttachment = null; } else { this.Close(); } } else { // no code here. this.Close(); } } } catch (Exception ex) { MyLogger.Write(ex, "btnAddAttachment_Click", LoggingCategory.Exception); this.NewAttachment = null; MessageBox.Show(this, ex.Message, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Cursor = Cursors.Default; } }
void bkgAddBug_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; try { worker.ReportProgress(0); // start thread. worker.ReportProgress(10); IBugBSI bugInterface = (IBugBSI)BLControllerFactory.GetRegisteredConcreteFactory(this.connectionId); worker.ReportProgress(60); //intermediate state string strResult = bugInterface.AddBug(addedBug); if (addedBug.Attachments.Count > 0) { // get bug ID Regex addBug = new Regex(@"(?<bug_number>[(0-9)]+) was added to the database", RegexOptions.IgnoreCase); Match match = addBug.Match(strResult); int bugNo = 0; if (match.Success == true) { bugNo = int.Parse(match.Groups["bug_number"].ToString()); } string strAtt = string.Empty; string errorMessage = string.Empty; // get version for current connection MyZillaSettingsDataSet _appSettings = MyZillaSettingsDataSet.GetInstance(); string version = _appSettings.GetConnectionById(this.connectionId).Version; int versionINT = int.Parse(version.Substring(0, version.IndexOf("."))); switch (versionINT) { case 2: foreach (Attachment att in addedBug.Attachments) { att.BugId = bugNo; bugInterface.PostAttachment(att, out errorMessage); if (!String.IsNullOrEmpty(errorMessage)) { strAtt = string.Format(Messages.ErrPostFile, att.FileName); strResult += Environment.NewLine + strAtt + " [" + errorMessage + "]"; } } break; case 3: break; } } e.Result = strResult; worker.ReportProgress(100); //completed } catch (Exception ex) { MyLogger.Write(ex, "bkgAddBug_DoWork", LoggingCategory.Exception); worker.ReportProgress(100); //completed throw; } }