private void btnUpload_Click(object sender, EventArgs e) { //toolStripStatusLabel.Text = "Preparing deposit..."; //toolStripProgressBar.Value = 0; if (profile.GetUsername() == null || "".Equals(profile.GetUsername()) || profile.GetPassword() == null || "".Equals(profile.GetPassword())) { frmLogin loginDialog = new frmLogin(); loginDialog.Focus(); loginDialog.TopMost = true; if(profile.GetUsername() != null && !"".Equals(profile.GetUsername())) { loginDialog.SetUsername(profile.GetUsername()); } if ( loginDialog.ShowDialog() == DialogResult.OK) { profile.SetUsername(loginDialog.GetUsername()); profile.SetPassword(loginDialog.GetPassword()); username = profile.GetUsername(); //client = new SwordClientHandler(profile.GetUsername(), profile.GetPassword(), profile.GetDepositUri()); } } string emIri = null; string seIri = null; string stateIri = null; if (action.Equals("create")) { sc = new SWORDClient(profile.GetDepositUri(), profile.GetUsername(), profile.GetPassword(), profile.GetOnBehalfOf()); XmlDocument receipt = new XmlDocument(); try { receipt = sc.PostAtom(getAtomEntry()); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { HttpStatusCode code = ((HttpWebResponse)ex.Response).StatusCode; switch (code) { case HttpStatusCode.InternalServerError: MessageBox.Show("The server responded with an Internal Server Error (500). Please contact your repository system administrator and check your profile configuration", "Error creating deposit entry", MessageBoxButtons.OK, MessageBoxIcon.Error); return; default: MessageBox.Show("Error creating deposit, please check your login details and profile configuration.\nReason: " + code.ToString(), "Error creating deposit entry", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else if (ex.Status == WebExceptionStatus.NameResolutionFailure) { // handle name resolution failure MessageBox.Show("Could not resolve remote server's hostname. Please check your profile configuration and network connectivity.", "Error resolving remote server", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } //MessageBox.Show("RESPONSE\n" + receipt); foreach (XmlNode link in receipt.GetElementsByTagName("link")) { switch (link.Attributes["rel"].Value) { case "statement": stateIri = link.Attributes["href"].Value; break; case "edit": seIri = link.Attributes["href"].Value; break; case "edit-media": emIri = link.Attributes["href"].Value; break; case "add": break; default: break; } } } else { emIri = endpoint; seIri = Deposit.loadDeposits(Program.userDataPath)[depositId].GetSeIri(); } // Did we successfully retrieve an EM-IRI / SE-IRI? if (emIri != null && !"".Equals(emIri)) { string contentType = filemime; if(cmbMime.Text != null && !"".Equals(cmbMime.Text)) contentType = cmbMime.Text; switch (action) { case "create": UploadFile(file, emIri, seIri, profile.GetPackaging(), contentType); saveDepositInfo(emIri, seIri, stateIri, filename); break; case "delete": DeleteResource(endpoint, seIri); saveDepositInfo(emIri, seIri, stateIri, filename); break; case "update": UploadFile(file, emIri, seIri, profile.GetPackaging(), contentType); saveDepositInfo(emIri, seIri, stateIri, filename); break; case "complete": sc.CompleteDeposit(seIri, DepositCompleted, UploadDataProgressHandler); saveDepositInfo(emIri, seIri, stateIri, filename); break; default: break; } } }