示例#1
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);
            }
        }