public static void CopyImageMetadataToWholeBook(string folderPath, HtmlDom dom, Metadata metadata, IProgress progress) { progress.WriteStatus("Starting..."); //First update the images themselves int completed = 0; var imgElements = GetImagePaths(folderPath); foreach (string path in imgElements) { progress.ProgressIndicator.PercentCompleted = (int)(100.0 * (float)completed / imgElements.Count()); progress.WriteStatus("Copying to " + Path.GetFileName(path)); using (var image = PalasoImage.FromFile(path)) { image.Metadata = metadata; image.SaveUpdatedMetadataIfItMakesSense(); } ++completed; } //Now update the html attributes which echo some of it, and is used by javascript to overlay displays related to //whether the info is there or missing or whatever. foreach (XmlElement img in dom.SafeSelectNodes("//img")) { UpdateImgMetdataAttributesToMatchImage(folderPath, img, progress, metadata); } }
public void Setup() { _mediaFile = new Bitmap(10, 10); _tempFile = TempFile.WithExtension("png"); _mediaFile.Save(_tempFile.Path); _outgoing = Metadata.FromFile(_tempFile.Path); }
public void ChangeLicenseDetails_HasChanges_True() { var m = new Metadata(); m.License = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules.Derivatives); m.HasChanges = false; ((CreativeCommonsLicense) m.License).CommercialUseAllowed = false; Assert.IsTrue(m.HasChanges); }
public void ChangeLicenseObject_HasChanges_True() { var m = new Metadata(); m.License = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules.Derivatives); m.HasChanges = false; m.License = new NullLicense(); Assert.IsTrue(m.HasChanges); }
public void ShowFullDialog() { var m = new Metadata(); using (var dlg = new MetadataEditorDialog(m)) { dlg.ShowDialog(); } }
/// <summary> /// Create a MetadataAccess by reading an existing media file /// </summary> /// <param name="path"></param> /// <returns></returns> public static Metadata FromFile(string path) { var m = new Metadata(); m._path = path; LoadProperties(path, m); return m; }
public void DeepCopy() { var m = new Metadata(); m.License = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules. DerivativesWithShareAndShareAlike); Metadata copy = m.DeepCopy(); Assert.AreEqual(m.License.Url,copy.License.Url); }
public void ShowControl() { var m = new Metadata(); m.CopyrightNotice = "copyright me"; m.Creator = "you"; m.AttributionUrl = "http://google.com"; m.License = new CreativeCommonsLicense(true, false, CreativeCommonsLicense.DerivativeRules.DerivativesWithShareAndShareAlike); var c = new MetadataDisplayControl(); c.SetMetadata(m); var dlg = new Form(); c.Dock = DockStyle.Fill; dlg.Controls.Add(c); dlg.ShowDialog(); }
public void ShowControl_NoLicense() { var m = new Metadata(); m.CopyrightNotice = "copyright me"; m.Creator = "you"; m.AttributionUrl = "http://google.com"; m.License = new NullLicense(); var c = new MetadataEditorControl(); c.Metadata = m; var dlg = new Form(); dlg.Height = c.Height; dlg.Width = c.Width + 20; c.Dock = DockStyle.Fill; dlg.Controls.Add(c); dlg.ShowDialog(); }
public void ShowFullDialogTwiceToCheckRoundTripping() { var m = new Metadata(); m.License = CreativeCommonsLicense.FromToken("by"); m.License.RightsStatement = "some restrictions"; using (var dlg = new MetadataEditorDialog(m)) { dlg.ShowDialog(); m = dlg.Metadata; } using (var dlg = new MetadataEditorDialog(m)) { dlg.ShowDialog(); } }
public Metadata GetLicenseMetadata() { var data = new DataSet(); GatherDataItemsFromXElement(data, _dom.RawDom); var metadata = new Metadata(); NamedMutliLingualValue d; if (data.TextVariables.TryGetValue("copyright", out d)) { metadata.CopyrightNotice = WebUtility.HtmlDecode(d.TextAlternatives.GetFirstAlternative()); } string licenseUrl = ""; if (data.TextVariables.TryGetValue("licenseUrl", out d)) { licenseUrl = d.TextAlternatives.GetFirstAlternative(); } //Enhance: have a place for notes (amendments to license). It's already in the frontmatter, under "licenseNotes" if (licenseUrl == null || licenseUrl.Trim() == "") { //NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html. //custom licenses live in this field if (data.TextVariables.TryGetValue("licenseNotes", out d)) { string licenseNotes = d.TextAlternatives.GetFirstAlternative(); metadata.License = new CustomLicense {RightsStatement = licenseNotes}; } else { //how to detect a null license was chosen? We're using the fact that it has a description, but nothing else. if (data.TextVariables.TryGetValue("licenseDescription", out d)) { metadata.License = new NullLicense(); //"contact the copyright owner } else { //looks like the first time. Nudge them with a nice default metadata.License = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules.Derivatives); } } } else { metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl); } return metadata; }
public static void UpdateImgMetdataAttributesToMatchImage(string folderPath, XmlElement imgElement, IProgress progress, Metadata metadata) { //see also PageEditingModel.UpdateMetadataAttributesOnImage(), which does the same thing but on the browser dom var fileName = imgElement.GetOptionalStringAttribute("src", string.Empty).ToLower(); var end = fileName.IndexOf('?'); if (end > 0) { fileName = fileName.Substring(0, end); } if (fileName == "placeholder.png" || fileName == "license.png") return; if (string.IsNullOrEmpty(fileName)) { Logger.WriteEvent("Book.UpdateImgMetdataAttributesToMatchImage() Warning: img has no or empty src attribute"); //Debug.Fail(" (Debug only) img has no or empty src attribute"); return; // they have bigger problems, which aren't appropriate to deal with here. } if (metadata == null) { progress.WriteStatus("Reading metadata from " + fileName); var path = folderPath.CombineForPath(fileName); if (!File.Exists(path)) // they have bigger problems, which aren't appropriate to deal with here. { imgElement.RemoveAttribute("data-copyright"); imgElement.RemoveAttribute("data-creator"); imgElement.RemoveAttribute("data-license"); Logger.WriteEvent("Book.UpdateImgMetdataAttributesToMatchImage() Image " + path + " is missing"); Debug.Fail(" (Debug only) Image " + path + " is missing"); return; } using (var image = PalasoImage.FromFile(path)) { metadata = image.Metadata; } } progress.WriteStatus("Writing metadata to HTML for " + fileName); imgElement.SetAttribute("data-copyright", String.IsNullOrEmpty(metadata.CopyrightNotice) ? "" : metadata.CopyrightNotice); imgElement.SetAttribute("data-creator", String.IsNullOrEmpty(metadata.Creator) ? "" : metadata.Creator); imgElement.SetAttribute("data-license", metadata.License == null ? "" : metadata.License.ToString()); }
public void GetCopyrightYear_HasCopyrightAndSymbolAndComma_ReturnsCopyrightYear() { var m = new Metadata(); m.CopyrightNotice = "Copyright © 2012, SIL International"; Assert.AreEqual("2012", m.GetCopyrightYear()); }
/// <summary> /// Load the properties of the specified MetaData object from the specified ImageTag. /// tagMain may be a CombinedImageTag (when working with a real image file) or an XmpTag (when working with an XMP file). /// Most of the data is read simply from the XmpTag (which is the Xmp property of the combined tag, if it is not tagMain itself). /// But, we don't want to pass combinedTag.Xmp when working with a file, because some files may have CopyRightNotice or Creator /// stored (only) in some other tag; /// and we need to handle the case where we only have an XmpTag, because there appears to be no way to create a /// combinedTag that just has an XmpTag inside it (or indeed any way to create any combinedTag except as part of /// reading a real image file). /// </summary> private static void LoadProperties(ImageTag tagMain, Metadata m) { m.CopyrightNotice = tagMain.Copyright; m.Creator = tagMain.Creator; XmpTag xmpTag = tagMain as XmpTag; if (xmpTag == null) xmpTag = ((CombinedImageTag) tagMain).Xmp; var licenseProperties = new Dictionary<string, string>(); if (xmpTag != null) { m.CollectionUri = xmpTag.GetTextNode(kNsCollections, "CollectionURI"); m.CollectionName = xmpTag.GetTextNode( kNsCollections, "CollectionName"); m.AttributionUrl = xmpTag.GetTextNode(kNsCc, "attributionURL"); var licenseUrl = xmpTag.GetTextNode(kNsCc, "license"); if (!string.IsNullOrWhiteSpace(licenseUrl)) licenseProperties["license"] = licenseUrl; var rights = GetRights(xmpTag); if (rights != null) licenseProperties["rights (en)"] = rights; } m.License = LicenseInfo.FromXmp(licenseProperties); //NB: we're loosing non-ascii somewhere... the copyright symbol is just the most obvious if (!string.IsNullOrEmpty(m.CopyrightNotice)) { m.CopyrightNotice = m.CopyrightNotice.Replace("Copyright �", "Copyright ©"); } //clear out the change-setting we just caused, because as of right now, we are clean with respect to what is on disk, no need to save. m.HasChanges = false; }
/// <summary> /// For use on a hyperlink/button /// </summary> /// <returns></returns> public static string GetStoredExemplarSummaryString(FileCategory category) { try { var m = new Metadata(); m.LoadFromStoredExemplar(category); return string.Format("{0}/{1}/{2}", m.Creator, m.CopyrightNotice, m.License.ToString()); } catch (Exception) { return string.Empty; } }
public PalasoImage() { Metadata = new Metadata(); }
public void SetHasChangesFalse_AlsoClearsLicenseHasChanges() { var m = new Metadata(); m.License = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules.Derivatives); ((CreativeCommonsLicense)m.License).CommercialUseAllowed = false; Assert.IsTrue(m.HasChanges); m.HasChanges = false; Assert.IsFalse(m.License.HasChanges); Assert.IsFalse(m.HasChanges); }
public PalasoImage(Image image) { Image = image; FileName = null; Metadata = new Metadata(); }
public void LoadXmpFile_ValuesCopiedFromOtherFile() { var original = new Metadata(); var another = new Metadata(); original.Creator = "John"; original.License = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules.Derivatives); using(var f = TempFile.WithExtension("xmp")) { original.SaveXmpFile(f.Path); another.LoadXmpFile(f.Path); } Assert.AreEqual("John", another.Creator); Assert.AreEqual(original.License.Url, another.License.Url); }
public void GetCopyrightYear_SymbolButNoYear_ReturnsEmptyString() { var m = new Metadata(); m.CopyrightNotice = "© SIL International"; Assert.AreEqual("", m.GetCopyrightYear()); }
public void GetCopyrightYear_NoSymbolOrComma_ReturnsCopyrightYear() { var m = new Metadata(); m.CopyrightNotice = "2012 SIL International"; Assert.AreEqual("2012", m.GetCopyrightYear()); }
public void SetLicenseMetdata(Metadata metadata) { var data = new DataSet(); GatherDataItemsFromXElement(data, _dom.RawDom); string copyright = metadata.CopyrightNotice; data.UpdateLanguageString("copyright", copyright, "*", false); string description = metadata.License.GetDescription("en"); data.UpdateLanguageString("licenseDescription", description, "en", false); string licenseUrl = metadata.License.Url; data.UpdateLanguageString("licenseUrl", licenseUrl, "*", false); string licenseNotes = metadata.License.RightsStatement; data.UpdateLanguageString("licenseNotes", licenseNotes, "*", false); string licenseImageName = metadata.License.GetImage() == null ? "" : "license.png"; data.UpdateGenericLanguageString("licenseImage", licenseImageName, false); UpdateDomFromDataSet(data, "*", _dom.RawDom); //UpdateDomFromDataSet() is not able to remove items yet, so we do it explicity RemoveDataDivElementIfEmptyValue("licenseDescription", description); RemoveDataDivElementIfEmptyValue("licenseImage", licenseImageName); RemoveDataDivElementIfEmptyValue("licenseUrl", licenseUrl); RemoveDataDivElementIfEmptyValue("copyright", copyright); RemoveDataDivElementIfEmptyValue("licenseNotes", licenseNotes); }
/// <summary> /// NB: this is used in 2 places; one is loading from the image we are linked to, the other from a sample image we are copying metadata from /// </summary> /// <param name="path"></param> /// <param name="m"></param> private static void LoadProperties(string path, Metadata m) { var properties = GetImageProperites(path); foreach (var assignment in MetadataAssignments) { string propertyValue; if (properties.TryGetValue(assignment.ResultLabel.ToLower(), out propertyValue)) { assignment.AssignmentAction.Invoke(m, propertyValue); m.IsEmpty = false; } } m.License = LicenseInfo.FromXmp(properties); //NB: we're loosing non-ascii somewhere... the copyright symbol is just the most obvious if (!string.IsNullOrEmpty(m.CopyrightNotice)) { m.CopyrightNotice = m.CopyrightNotice.Replace("Copyright �", "Copyright ©"); } //clear out the change-setting we just caused, because as of right now, we are clean with respect to what is on disk, no need to save. m.HasChanges = false; }
public void GetCopyrightBy_Empty_ReturnsEmpty() { var m = new Metadata(); m.CopyrightNotice = ""; Assert.AreEqual("", m.GetCopyrightBy()); }
/// <summary> /// NB: this is used in 2 places; one is loading from the image we are linked to, the other from a sample image we are copying metadata from /// </summary> /// <param name="path"></param> /// <param name="m"></param> private static void LoadProperties(string path, Metadata m) { var file = TagLib.File.Create(path) as TagLib.Image.File; LoadProperties(file.ImageTag, m); }
public void GetCopyrightBy_HasCOPYRIGHTAndSymbolNoYear_ReturnsCopyrightHolder() { var m = new Metadata(); m.CopyrightNotice = "COPYRIGHT © SIL International"; Assert.AreEqual("SIL International", m.GetCopyrightBy()); }
public void CopyImageMetadataToWholeBook(Metadata metadata) { using (var dlg = new ProgressDialogForeground())//REVIEW: this foreground dialog has known problems in other contexts... it was used here because of its ability to handle exceptions well. TODO: make the background one handle exceptions well { dlg.ShowAndDoWork(progress => CurrentBook.CopyImageMetadataToWholeBookAndSave(metadata, progress)); } }
public void GetCopyrightBy_HasSymbolAndComma_ReturnsCopyrightHolder() { var m = new Metadata(); m.CopyrightNotice = "© 2012, SIL International"; Assert.AreEqual("SIL International", m.GetCopyrightBy()); }
private void SetupMetaDataControls(Metadata metaData) { //NB: there was a bug here where the display control refused to go to visible, if this was called before loading. Weird. So now, we have an OnLoad() to call it again. _invitationToMetadataPanel.Visible = (metaData == null || metaData.IsEmpty); _metadataDisplayControl.Visible = !_invitationToMetadataPanel.Visible; bool looksOfficial = !string.IsNullOrEmpty(metaData.CollectionUri); _editLink.Visible = metaData!=null && _metadataDisplayControl.Visible && !looksOfficial; if (_metadataDisplayControl.Visible) _metadataDisplayControl.SetMetadata(metaData); _copyExemplarMetadata.Visible = Metadata.HaveStoredExemplar(Metadata.FileCategory.Image); if (_invitationToMetadataPanel.Visible && _copyExemplarMetadata.Visible) { var s = LocalizationManager.GetString("Use {0}", "ImageToolbox.CopyExemplarMetadata", "Used to copy a previous metadata set to the current image. The {0} will be replaced with the name of the exemplar image."); _copyExemplarMetadata.Text = string.Format(s, Metadata.GetStoredExemplarSummaryString(Metadata.FileCategory.Image)); } }
public void GetCopyrightBy_NoSymbolOrYear_ReturnsCopyrightHolder() { var m = new Metadata(); m.CopyrightNotice = "SIL International"; Assert.AreEqual("SIL International", m.GetCopyrightBy()); }