Exemplo n.º 1
0
        public void HandleSelection(ItemSelection selection)
        {
            string tempfile = Path.Combine(Path.GetTempPath(), selection.AttachmentFilename);
            int    i        = 2;

            while (File.Exists(tempfile))
            {
                tempfile = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(tempfile) + i + Path.GetExtension(tempfile));
                i++;
            }

            SaveURLToDisk(new Uri(selection.ItemURL + "?attachment.uuid=" + selection.AttachmentUuid), tempfile);

            //open it up in associated application
            DocumentWrapper doc = Integ.Open(tempfile);

            //save metadata if necessary
            DocumentMetadata meta = doc.Metadata;

            if (meta.ItemName == null)
            {
                meta.ItemName = selection.ItemName;
            }
            if (meta.ItemUuid == null)
            {
                meta.ItemUuid = selection.ItemUuid;
            }
            if (meta.Keywords == null)
            {
                meta.Keywords = selection.Keywords;
            }
            if (meta.AttachmentFilename == null)
            {
                meta.AttachmentFilename = selection.AttachmentFilename;
            }
            meta.OwnerId = Soap.LoggedInUser;
            Integ.AssociateMetadata(doc, meta);
        }
Exemplo n.º 2
0
        public void EquellaUpdate_DoUpdate(IRibbonControl button)
        {
            try
            {
                if (!EnsureLogin())
                {
                    return;
                }
            }
            catch (NoProfileException)
            {
                return;
            }
            catch (WebException)
            {
                Utils.Alert(String.Format(BAD_URL_MESSAGE, InstitutionURL));
                return;
            }

            try
            {
                DocumentWrapper  doc  = Integ.CurrentDocument;
                DocumentMetadata meta = doc.Metadata;

                string ownerId       = meta.OwnerId;
                string currentUserId = Soap.LoggedInUser;
                if (currentUserId != ownerId)
                {
                    //make a new item regardless.  this document was owned by someone else
                    Utils.Alert("You are not the owner of this document.  A new scrapbook resource will be created instead.");
                    EquellaCreate_DoCreate(null);
                    return;
                }

                string itemUuid = meta.ItemUuid;
                if (!Soap.ScrapbookItemExists(itemUuid))
                {
                    Utils.Alert("The scrapbook resource associated with this document could not be found.  A new scrapbook resource will be created instead.");
                    EquellaCreate_DoCreate(null);
                    return;
                }

                string docFullPath        = doc.FileName;
                string keywords           = meta.Keywords ?? "";
                string attachmentFilename = meta.AttachmentFilename ?? Path.GetFileName(docFullPath);
                string itemName           = meta.ItemName ?? attachmentFilename;
                string documentUuid       = meta.DocumentUuid;


                if (AskDetails(ref itemName, ref keywords, ref attachmentFilename))
                {
                    //Save the document with updated metadata
                    Integ.AssociateMetadata(doc, new DocumentMetadata {
                        ItemUuid = itemUuid, ItemName = itemName, Keywords = keywords, AttachmentFilename = attachmentFilename, DocumentUuid = documentUuid
                    });
                    doc = Integ.Save(doc, Path.Combine(Path.GetTempPath(), attachmentFilename));

                    byte[] bytes = Integ.ReadFile(doc);
                    Soap.UpdateScrapbookItem(itemUuid, itemName, keywords, attachmentFilename, bytes);

                    Utils.Alert("A scrapbook resource has been updated in EQUELLA");
                }
            }
            catch (Exception e)
            {
                Utils.ShowError(e);
            }
        }
Exemplo n.º 3
0
        public void EquellaCreate_DoCreate(IRibbonControl button)
        {
            try
            {
                if (!EnsureLogin())
                {
                    return;
                }
            }
            catch (NoProfileException)
            {
                return;
            }
            catch (WebException)
            {
                Utils.Alert(String.Format(BAD_URL_MESSAGE, InstitutionURL));
                return;
            }

            try
            {
                DocumentWrapper  doc  = Integ.CurrentDocument;
                DocumentMetadata meta = doc.Metadata;

                string itemName           = meta.ItemName;
                string keywords           = meta.Keywords ?? "";
                string attachmentFilename = meta.AttachmentFilename;
                string documentUuid       = System.Guid.NewGuid().ToString();
                string ownerId            = Soap.LoggedInUser;

                string docFullPath = null;
                if (!doc.New)
                {
                    docFullPath = doc.FileName;
                    if (attachmentFilename == null)
                    {
                        attachmentFilename = Path.GetFileName(docFullPath);
                    }
                }
                else
                {
                    attachmentFilename = Integ.DefaultDocumentName;
                    docFullPath        = Path.Combine(Path.GetTempPath(), attachmentFilename);
                }
                if (itemName == null)
                {
                    itemName = attachmentFilename;
                }

                if (AskDetails(ref itemName, ref keywords, ref attachmentFilename))
                {
                    //unfortunately it's a two step process.... we need the itemUuid from the new item, but we need to also store
                    //it in the document.

                    //saves a placeholder attachment with a single byte in it.  better than uploading twice
                    XElement item     = Soap.NewScrapbookItem("TemporaryResource", keywords, attachmentFilename, new byte[] { 0 });
                    XElement itemPart = item.Element("item");
                    string   itemUuid = (string)itemPart.Attribute("id");

                    //Re-save the document with updated metadata
                    Integ.AssociateMetadata(doc, new DocumentMetadata {
                        ItemUuid = itemUuid, ItemName = itemName,
                        Keywords = keywords, AttachmentFilename = attachmentFilename, DocumentUuid = documentUuid,
                        OwnerId  = ownerId
                    });
                    doc = Integ.Save(doc, Path.Combine(Path.GetTempPath(), attachmentFilename));

                    byte[] bytes = Integ.ReadFile(doc);
                    Soap.UpdateScrapbookItem(itemUuid, itemName, keywords, attachmentFilename, bytes);

                    Utils.Alert("A new scrapbook resource titled \"" + itemName + "\" has been created in EQUELLA");
                }
            }
            catch (Exception e)
            {
                Utils.ShowError(e);
            }
        }