Exemple #1
0
        private void DeleteResource(string emIri, string seIri)
        {
            sc = new SWORDClient(seIri, profile.GetUsername(), profile.GetPassword(), profile.GetOnBehalfOf());
            sc.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressHandler);
            sc.UploadDataCompleted   += new UploadDataCompletedEventHandler(UploadDataCompleted);

            try
            {
                sc.UploadDataAsync(new Uri(emIri), "DELETE", new byte[0]);
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    HttpStatusCode code = ((HttpWebResponse)ex.Response).StatusCode;
                    switch (code)
                    {
                    case HttpStatusCode.InternalServerError:
                        // All good.. DSpace does this for anything with " in it right now
                        break;

                    default:
                        MessageBox.Show("Error deleting deposit, please check your login details and profile configuration.\nReason: " + code.ToString(), "Error deleting deposit", 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;
                }
            }
        }
Exemple #2
0
        private void UploadFile(string file, string emIri, string seIri, string packaging, string contentType)
        {
            sc = new SWORDClient(emIri, profile.GetUsername(), profile.GetPassword(), profile.GetOnBehalfOf());
            sc.UploadProgressChanged         += new UploadProgressChangedEventHandler(UploadProgressHandler);
            sc.UploadFileCompleted           += new UploadFileCompletedEventHandler(UploadFileCompleted);
            sc.Headers["Content-Disposition"] = "attachment; filename=" + filename + "; charset=utf-8";
            //sc.Headers["Content-Type"] = contentType;
            sc.Headers["X-Packaging"]       = packaging;
            sc.Headers["Metadata-Relevant"] = "false";

            try
            {
                sc.UploadFileAsync(new Uri(emIri), "PUT", file, seIri);
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    HttpStatusCode code = ((HttpWebResponse)ex.Response).StatusCode;
                    switch (code)
                    {
                    case HttpStatusCode.InternalServerError:
                        // All good.. DSpace does this for anything with " in it right now
                        break;

                    default:
                        MessageBox.Show("Error uploading file, please check your login details, profile configuration and deposit status.\nReason: " + code.ToString(), "Error uploading file", 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;
                }
            }
        }
Exemple #3
0
        public frmMain(string file, Profile profile, string action, string endpoint, int depositId)
        {
            InitializeComponent();
            this.profile = profile;

            this.action    = action;
            this.endpoint  = endpoint;
            this.depositId = depositId;


            loadFile(file);

            if (profile.GetUsername() == null || "".Equals(profile.GetUsername()))
            {
                try
                {
                    this.username = WindowsIdentity.GetCurrent().Name.Split('\\')[1];
                }
                catch (Exception le)
                {
                    MessageBox.Show("Could not get username.\nReason: " + le.Message, "Error getting Windows credentials", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
            }
            else
            {
                this.username = profile.GetUsername();
            }

            sc = new SWORDClient(profile.GetServiceDocumentUri(), profile.GetUsername(), profile.GetPassword(), profile.GetOnBehalfOf());
            List <string> mimes = getAcceptableMimes();

            populateMimes(mimes);

            drawForm();
        }
Exemple #4
0
        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;
                }
            }
        }