internal IptcValue(IptcTag tag, string value, bool strict) { this.Strict = strict; this.Tag = tag; this.encoding = Encoding.UTF8; this.Value = value; }
public void TestReadingExifTag() { const IptcTag expected = IptcTag.Source; IptcTag actual = JsonSerializer.Deserialize <IptcTag>("\"Source\"", Options); Assert.Equal(expected, actual); }
private static void TestValue(IIptcProfile profile, IptcTag tag, string expectedValue) { var value = profile.GetValue(tag); Assert.NotNull(value); Assert.Equal(expectedValue, value.Value); }
private static void TestValue(IptcProfile profile, IptcTag tag, string expectedValue) { IptcValue value = profile.GetValue(tag); Assert.IsNotNull(value); Assert.AreEqual(expectedValue, value.Value); }
internal IptcValue(IptcTag tag, byte[] value) { Throw.IfNull(nameof(value), value); Tag = tag; _data = value; _encoding = Encoding.UTF8; }
internal IptcValue(IptcTag tag, byte[] value) { Throw.IfNull("value", value); Tag = tag; _Data = value; _Encoding = Encoding.UTF8; }
internal IptcValue(IptcTag tag, byte[] value, bool strict) { Guard.NotNull(value, nameof(value)); this.Strict = strict; this.Tag = tag; this.data = value; this.encoding = Encoding.UTF8; }
/// <summary> /// Returns all values with the specified tag. /// </summary> /// <param name="tag">The tag of the iptc value.</param> /// <returns>The values found with the specified tag.</returns> public IEnumerable <IIptcValue> GetAllValues(IptcTag tag) { foreach (var iptcValue in Values) { if (iptcValue.Tag == tag) { yield return(iptcValue); } } }
public void SetValue(IptcTag tag, Encoding encoding, String value) { try { _Instance.CallMethod("SetValue", new Type[] { Types.IptcTag, typeof(Encoding), typeof(String) }, tag, encoding, value); } catch (Exception ex) { throw ExceptionHelper.Create(ex); } }
public void ShouldFormatTheDate(IptcTag tag) { var profile = new IptcProfile(); var datetime = new DateTimeOffset(new DateTime(1994, 3, 17)); profile.SetValue(tag, datetime); var actual = profile.GetValue(tag); Assert.Equal("19940317", actual.Value); }
public void ShouldFormatTheTime(IptcTag tag) { var profile = new IptcProfile(); var dateTimeUtc = new DateTime(1994, 3, 17, 14, 15, 16, DateTimeKind.Utc); var dateTimeOffset = new DateTimeOffset(dateTimeUtc).ToOffset(TimeSpan.FromHours(2)); profile.SetValue(tag, dateTimeOffset); var actual = profile.GetAllValues(tag).First(); Assert.Equal("161516+0200", actual.Value); }
/// <summary> /// Returns the value with the specified tag. /// </summary> /// <param name="tag">The tag of the iptc value.</param> /// <returns>The value with the specified tag.</returns> public IIptcValue GetValue(IptcTag tag) { foreach (var iptcValue in Values) { if (iptcValue.Tag == tag) { return(iptcValue); } } return(null); }
/// <summary> /// Maximum length of the IPTC value with the given tag according to the specification. /// </summary> /// <param name="tag">The tag to check the max length for.</param> /// <returns>The maximum length.</returns> public static int MaxLength(this IptcTag tag) { return(tag switch { IptcTag.RecordVersion => 2, IptcTag.ObjectType => 67, IptcTag.ObjectAttribute => 68, IptcTag.Name => 64, IptcTag.EditStatus => 64, IptcTag.EditorialUpdate => 2, IptcTag.Urgency => 1, IptcTag.SubjectReference => 236, IptcTag.Category => 3, IptcTag.SupplementalCategories => 32, IptcTag.FixtureIdentifier => 32, IptcTag.Keywords => 64, IptcTag.LocationCode => 3, IptcTag.LocationName => 64, IptcTag.ReleaseDate => 8, IptcTag.ReleaseTime => 11, IptcTag.ExpirationDate => 8, IptcTag.ExpirationTime => 11, IptcTag.SpecialInstructions => 256, IptcTag.ActionAdvised => 2, IptcTag.ReferenceService => 10, IptcTag.ReferenceDate => 8, IptcTag.ReferenceNumber => 8, IptcTag.CreatedDate => 8, IptcTag.CreatedTime => 11, IptcTag.DigitalCreationDate => 8, IptcTag.DigitalCreationTime => 11, IptcTag.OriginatingProgram => 32, IptcTag.ProgramVersion => 10, IptcTag.ObjectCycle => 1, IptcTag.Byline => 32, IptcTag.BylineTitle => 32, IptcTag.City => 32, IptcTag.SubLocation => 32, IptcTag.ProvinceState => 32, IptcTag.CountryCode => 3, IptcTag.Country => 64, IptcTag.OriginalTransmissionReference => 32, IptcTag.Headline => 256, IptcTag.Credit => 32, IptcTag.Source => 32, IptcTag.CopyrightNotice => 128, IptcTag.Contact => 128, IptcTag.Caption => 2000, IptcTag.CaptionWriter => 32, IptcTag.ImageType => 2, IptcTag.ImageOrientation => 1, _ => 256 });
public Boolean RemoveValue(IptcTag tag) { object result; try { result = _Instance.CallMethod("RemoveValue", new Type[] {Types.IptcTag}, tag); } catch (Exception ex) { throw ExceptionHelper.Create(ex); } return (Boolean)result; }
public IptcValue GetValue(IptcTag tag) { object result; try { result = _Instance.CallMethod("GetValue", new Type[] {Types.IptcTag}, tag); } catch (Exception ex) { throw ExceptionHelper.Create(ex); } return (result == null ? null : new IptcValue(result)); }
public void ShoulNotdAllowDuplicateValuesForValuesThatCannotBeRepated(IptcTag tag) { var profile = new IptcProfile(); var expectedValue = "another one"; profile.SetValue(tag, "test"); profile.SetValue(tag, expectedValue); var values = profile.Values.ToList(); Assert.Single(values); Assert.Contains(new IptcValue(tag, Encoding.UTF8.GetBytes(expectedValue)), values); }
public void IptcProfile_SetDateValue_Works(IptcTag tag) { // arrange var profile = new IptcProfile(); var datetime = new DateTimeOffset(new DateTime(1994, 3, 17)); // act profile.SetDateTimeValue(tag, datetime); // assert IptcValue actual = profile.GetValues(tag).First(); Assert.Equal("19940317", actual.Value); }
public static bool IsTime(IptcTag tag) { switch (tag) { case IptcTag.CreatedTime: case IptcTag.DigitalCreationTime: case IptcTag.ExpirationTime: case IptcTag.ReleaseTime: return(true); default: return(false); } }
/// <summary> /// Makes sure the datetime is formatted according to the iptc specification. /// <example> /// A date will be formatted as CCYYMMDD, e.g. "19890317" for 17 March 1989. /// A time value will be formatted as HHMMSS±HHMM, e.g. "090000+0200" for 9 o'clock Berlin time, /// two hours ahead of UTC. /// </example> /// </summary> /// <param name="tag">The tag of the iptc value.</param> /// <param name="dateTimeOffset">The datetime.</param> public void SetDateTimeValue(IptcTag tag, DateTimeOffset dateTimeOffset) { if (!tag.IsDate() && !tag.IsTime()) { throw new ArgumentException("iptc tag is not a time or date type"); } var formattedDate = tag.IsDate() ? dateTimeOffset.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture) : dateTimeOffset.ToString("HHmmsszzzz", System.Globalization.CultureInfo.InvariantCulture) .Replace(":", string.Empty); this.SetValue(tag, Encoding.UTF8, formattedDate); }
/// <summary> /// Returns all values with the specified tag. /// </summary> /// <param name="tag">The tag of the iptc value.</param> /// <returns>The values found with the specified tag.</returns> public List <IIptcValue> GetAllValues(IptcTag tag) { var iptcValues = new List <IIptcValue>(); foreach (IptcValue iptcValue in Values) { if (iptcValue.Tag == tag) { iptcValues.Add(iptcValue); } } return(iptcValues); }
public Boolean RemoveValue(IptcTag tag) { object result; try { result = _Instance.CallMethod("RemoveValue", new Type[] { Types.IptcTag }, tag); } catch (Exception ex) { throw ExceptionHelper.Create(ex); } return((Boolean)result); }
public IptcValue GetValue(IptcTag tag) { object result; try { result = _Instance.CallMethod("GetValue", new Type[] { Types.IptcTag }, tag); } catch (Exception ex) { throw ExceptionHelper.Create(ex); } return(result == null ? null : new IptcValue(result)); }
public void ShouldAllowDuplicateValuesForValuesThatCanBeRepated(IptcTag tag) { var profile = new IptcProfile(); var expectedValue1 = "test"; var expectedValue2 = "another one"; profile.SetValue(tag, expectedValue1); profile.SetValue(tag, expectedValue2); var values = profile.Values.ToList(); Assert.Equal(2, values.Count); Assert.Contains(new IptcValue(tag, Encoding.UTF8.GetBytes(expectedValue1)), values); Assert.Contains(new IptcValue(tag, Encoding.UTF8.GetBytes(expectedValue2)), values); }
public void IptcProfile_SetValue_WithStrictOption_Works(IptcTag tag) { // arrange var profile = new IptcProfile(); var value = new string('s', tag.MaxLength() + 1); var expectedLength = tag.MaxLength(); // act profile.SetValue(tag, value); // assert IptcValue actual = profile.GetValues(tag).First(); Assert.Equal(expectedLength, actual.Value.Length); }
public static bool IsDate(IptcTag tag) { switch (tag) { case IptcTag.CreatedDate: case IptcTag.DigitalCreationDate: case IptcTag.ExpirationDate: case IptcTag.ReferenceDate: case IptcTag.ReleaseDate: return(true); default: return(false); } }
/// <summary> /// Removes the value with the specified tag. /// </summary> /// <param name="tag">The tag of the iptc value.</param> /// <returns>True when the value was fount and removed.</returns> public bool RemoveValue(IptcTag tag) { Initialize(); for (int i = 0; i < _values.Count; i++) { if (_values[i].Tag == tag) { _values.RemoveAt(i); return(true); } } return(false); }
/// <summary> /// Makes sure the datetime is formatted according to the iptc specification. /// <example> /// A date will be formatted as CCYYMMDD, e.g. "19890317" for 17 March 1989. /// A time value will be formatted as HHMMSS±HHMM, e.g. "090000+0200" for 9 o'clock Berlin time, /// two hours ahead of UTC. /// </example> /// </summary> /// <param name="tag">The tag of the iptc value.</param> /// <param name="dateTimeOffset">The datetime.</param> public void SetValue(IptcTag tag, DateTimeOffset dateTimeOffset) { var isDate = tag.IsDate(); if (!isDate && !tag.IsTime()) { throw new ArgumentException("iptc tag is not a time or date type", nameof(tag)); } var formattedDate = isDate ? dateTimeOffset.ToString("yyyyMMdd", CultureInfo.InvariantCulture) : dateTimeOffset.ToString("HHmmsszzzz", CultureInfo.InvariantCulture).Replace(":", string.Empty); SetValue(tag, Encoding.UTF8, formattedDate); }
public void IptcProfile_SetTimeValue_Works(IptcTag tag) { // arrange var profile = new IptcProfile(); var dateTimeUtc = new DateTime(1994, 3, 17, 14, 15, 16, DateTimeKind.Utc); DateTimeOffset dateTimeOffset = new DateTimeOffset(dateTimeUtc).ToOffset(TimeSpan.FromHours(2)); // act profile.SetDateTimeValue(tag, dateTimeOffset); // assert IptcValue actual = profile.GetValues(tag).First(); Assert.Equal("161516+0200", actual.Value); }
/// <summary> /// Sets the value of the specified tag. /// </summary> /// <param name="tag">The tag of the iptc value.</param> /// <param name="encoding">The encoding to use when storing the bytes.</param> /// <param name="value">The value.</param> public void SetValue(IptcTag tag, Encoding encoding, string value) { Throw.IfNull(nameof(encoding), encoding); foreach (IptcValue iptcValue in Values) { if (iptcValue.Tag == tag) { iptcValue.Encoding = encoding; iptcValue.Value = value; return; } } _values.Add(new IptcValue(tag, encoding, value)); }
/// <summary> /// Removes values with the specified tag and value. /// </summary> /// <param name="tag">The tag of the iptc value to remove.</param> /// <param name="value">The value of the iptc item to remove.</param> /// <returns>True when the value was found and removed.</returns> public bool RemoveValue(IptcTag tag, string value) { this.Initialize(); bool removed = false; for (int i = this.values.Count - 1; i >= 0; i--) { if (this.values[i].Tag == tag && this.values[i].Value.Equals(value)) { this.values.RemoveAt(i); removed = true; } } return(removed); }
/// <summary> /// Removes all values with the specified tag. /// </summary> /// <param name="tag">The tag of the iptc value to remove.</param> /// <returns>True when the value was found and removed.</returns> public bool RemoveValue(IptcTag tag) { Initialize(); bool removed = false; for (int i = _values.Count - 1; i >= 0; i--) { if (_values[i].Tag == tag) { _values.RemoveAt(i); removed = true; } } return(removed); }
/// <summary> /// Removes values with the specified tag and value. /// </summary> /// <param name="tag">The tag of the iptc value to remove.</param> /// <param name="value">The value of the iptc item to remove.</param> /// <returns>True when the value was found and removed.</returns> public bool RemoveValue(IptcTag tag, string value) { Initialize(); bool removed = false; for (int i = _values.Count - 1; i >= 0; i--) { if (_values[i].Tag == tag && _values[i].Value.Equals(value, StringComparison.Ordinal)) { _values.RemoveAt(i); removed = true; } } return(removed); }
public void SetValue(IptcTag tag, Encoding encoding, String value) { try { _Instance.CallMethod("SetValue", new Type[] {Types.IptcTag, typeof(Encoding), typeof(String)}, tag, encoding, value); } catch (Exception ex) { throw ExceptionHelper.Create(ex); } }
///<summary> /// Sets the value of the specified tag. ///</summary> ///<param name="tag">The tag of the iptc value.</param> ///<param name="value">The value.</param> public void SetValue(IptcTag tag, string value) { SetValue(tag, Encoding.Default, value); }
private static void TestValue(IptcProfile profile, IptcTag tag, string expectedValue) { IptcValue value = profile.GetValue(tag); Assert.IsNotNull(value); Assert.AreEqual(expectedValue, value.Value); }
/// <summary> /// Sets the value of the specified tag. /// </summary> /// <param name="tag">The tag of the iptc value.</param> /// <param name="value">The value.</param> public void SetValue(IptcTag tag, string value) { SetValue(tag, Encoding.UTF8, value); }
///<summary> /// Returns the value with the specified tag. ///</summary> ///<param name="tag">The tag of the iptc value.</param> public IptcValue GetValue(IptcTag tag) { foreach (IptcValue iptcValue in Values) { if (iptcValue.Tag == tag) return iptcValue; } return null; }
///<summary> /// Sets the value of the specified tag. ///</summary> ///<param name="tag">The tag of the iptc value.</param> ///<param name="encoding">The encoding to use when storing the bytes.</param> ///<param name="value">The value.</param> public void SetValue(IptcTag tag, Encoding encoding, string value) { Throw.IfNull("encoding", encoding); foreach (IptcValue iptcValue in Values) { if (iptcValue.Tag == tag) { iptcValue.Encoding = encoding; iptcValue.Value = value; return; } } _Values.Add(new IptcValue(tag, encoding, value)); }
///<summary> /// Removes the value with the specified tag. ///</summary> ///<param name="tag">The tag of the iptc value.</param> public bool RemoveValue(IptcTag tag) { Initialize(); for (int i = 0; i < _Values.Count; i++) { if (_Values[i].Tag == tag) { _Values.RemoveAt(i); return true; } } return false; }