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); } }
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); } }