/// <summary> /// Alters (add/edit/remove) a metadata item within a KStudioMetadata object /// </summary> /// <param name="metadata">The metadata object to alter</param> /// <param name="key">The key of the particular metadata item to alter</param> /// <param name="value">New value for the metadata object when adding/editing</param> private static void AlterMetadata(KStudioMetadata metadata, string key, object value) { if (metadata == null) { throw new InvalidOperationException(Strings.ErrorInvalidMetadataPair); } if (string.IsNullOrEmpty(key)) { throw new InvalidOperationException(Strings.ErrorNullMetadataKey); } metadata[key] = value; }
/// <summary> /// Returns all key/value pairs in a metadata object as a single string /// </summary> /// <param name="metadata">Collection of metadata items</param> /// <param name="type">Public or PersonallyIdentifiableInformation</param> /// <param name="streamName">Name of stream which metadata belongs to, empty if file-level metadata</param> /// <returns>A string which contains all key/value pairs in the metadata object</returns> private static string GetMetadataAsText(KStudioMetadata metadata, KStudioMetadataType type, string streamName) { if (metadata == null) { throw new ArgumentNullException("metadata"); } StringBuilder metadataString = new StringBuilder(); metadataString.Append(Environment.NewLine); if (string.IsNullOrEmpty(streamName)) { metadataString.Append(Strings.File); } else { metadataString.Append(streamName); } metadataString.Append(" "); if (type == KStudioMetadataType.Public) { metadataString.Append(string.Format(Strings.PublicMetadataHeader, metadata.Count)); } else { metadataString.Append(string.Format(Strings.PersonalMetadataHeader, metadata.Count)); } foreach (KeyValuePair <string, object> pair in metadata) { metadataString.Append(Environment.NewLine); metadataString.Append(" "); metadataString.Append(pair.Key); metadataString.Append(" = "); metadataString.Append(Metadata.ConvertMetadataValueToString(pair.Value)); } metadataString.Append(Environment.NewLine); return(metadataString.ToString()); }
/// <summary> /// Updates (add/edits) stream-level metadata in an event file /// </summary> /// <param name="client">KStudioClient to use for accessing the event file</param> /// <param name="fileName">Path to event file</param> /// <param name="streamName">Name of stream which should contain the metadata</param> /// <param name="type">Type of metadata to update (Public or Personal)</param> /// <param name="key">Key of metadata object to add/edit</param> /// <param name="value">Value of metadata object to add/edit</param> /// <returns>String which contains the updated contents of the target metadata object</returns> public static string UpdateStreamMetadata(KStudioClient client, string fileName, string streamName, KStudioMetadataType type, string key, object value) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName"); } if (string.IsNullOrEmpty(streamName)) { throw new ArgumentNullException("streamName"); } string metadataText = string.Empty; using (KStudioEventFile file = client.OpenEventFileForEdit(fileName)) { // find the stream in the file and alter its metadata Guid dataTypeId = StreamSupport.ConvertStreamStringToGuid(streamName); if (dataTypeId == KStudioEventStreamDataTypeIds.Null) { throw new InvalidOperationException(Strings.ErrorNullStream); } KStudioEventStream stream = file.EventStreams.FirstOrDefault(s => s.DataTypeId == dataTypeId); if (stream != null) { KStudioMetadata metadata = stream.GetMetadata(type); Metadata.AlterMetadata(metadata, key, value); metadataText = Metadata.GetMetadataAsText(metadata, type, stream.DataTypeName); } } return(metadataText); }
/// <summary> /// Updates (adds/edits) file-level metadata in an event file /// </summary> /// <param name="client">KStudioClient to use for accessing the event file</param> /// <param name="fileName">Path to event file</param> /// <param name="type">Type of metadata (Public or Personal)</param> /// <param name="key">Key of metadata object to add/edit</param> /// <param name="value">Value of metadata object to add/edit</param> /// <returns>String which contains the updated contents of the target metadata object</returns> public static string UpdateFileMetadata(KStudioClient client, string fileName, KStudioMetadataType type, string key, object value) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName"); } string metadataText = string.Empty; using (KStudioEventFile file = client.OpenEventFileForEdit(fileName)) { KStudioMetadata metadata = file.GetMetadata(type); Metadata.AlterMetadata(metadata, key, value); metadataText = Metadata.GetMetadataAsText(metadata, type, string.Empty); } return(metadataText); }
public WritableMetadataProxy(KStudioEventFile file, KStudioMetadata metadata) { DebugHelper.AssertUIThread(); if (metadata == null) { throw new ArgumentNullException("metadata"); } if (metadata.IsReadOnly) { throw new ArgumentOutOfRangeException("metadata"); } this.file = file as KStudioWritableEventFile; this.stream = null; this.metadata = metadata; this.metadata.CollectionChanged += Notify_CollectionChanged; lock (this.metadata) { LoadCollection(); } }
/// <summary> /// Initializes a new instance of the CompareStreamData class and sets all properties based on the StreamData provided /// </summary> /// <param name="leftStream">First StreamData object to use for comparison</param> /// <param name="rightStream">Second StreamData object to use for comparison</param> public CompareStreamData(StreamData leftStream, StreamData rightStream) { if (leftStream == null && rightStream == null) { throw new InvalidOperationException(Strings.ErrorNoStreams); } this.StreamName = Strings.Unknown; this.LeftPublicMetadataCount = 0; this.RightPublicMetadataCount = 0; this.LeftPersonalMetadataCount = 0; this.RightPersonalMetadataCount = 0; string dataTypeIdKey = Strings.DataTypeIdHeader; string semanticIdKey = Strings.SemanticIdHeader; string eventCountKey = Strings.EventCountHeader; string startTimeKey = Strings.StreamStartTimeHeader; string endTimeKey = Strings.StreamEndTimeHeader; string leftSemanticId = string.Empty; string rightSemanticId = string.Empty; string leftEventCount = string.Empty; string rightEventCount = string.Empty; string leftStartTime = string.Empty; string rightStartTime = string.Empty; string leftEndTime = string.Empty; string rightEndTime = string.Empty; string leftDataTypeId = string.Empty; string rightDataTypeId = string.Empty; KStudioMetadata leftPublicMetadata = null; KStudioMetadata rightPublicMetadata = null; KStudioMetadata leftPersonalMetadata = null; KStudioMetadata rightPersonalMetadata = null; if (leftStream != null) { this.StreamName = leftStream.EventStream.DataTypeName; leftSemanticId = leftStream.EventStream.SemanticId.ToString(); leftEventCount = leftStream.EventHeaders.Count.ToString(); leftStartTime = leftStream.StartTime.ToString(); leftEndTime = leftStream.EndTime.ToString(); leftDataTypeId = leftStream.EventStream.DataTypeId.ToString(); leftPublicMetadata = leftStream.PublicMetadata; leftPersonalMetadata = leftStream.PersonalMetadata; this.LeftPublicMetadataCount = leftStream.PublicMetadata.Count; this.LeftPersonalMetadataCount = leftStream.PersonalMetadata.Count; } if (rightStream != null) { if (leftStream == null) { this.StreamName = rightStream.EventStream.DataTypeName; } rightSemanticId = rightStream.EventStream.SemanticId.ToString(); rightEventCount = rightStream.EventHeaders.Count.ToString(); rightStartTime = rightStream.StartTime.ToString(); rightEndTime = rightStream.EndTime.ToString(); rightDataTypeId = rightStream.EventStream.DataTypeId.ToString(); rightPublicMetadata = rightStream.PublicMetadata; rightPersonalMetadata = rightStream.PersonalMetadata; this.RightPublicMetadataCount = rightStream.PublicMetadata.Count; this.RightPersonalMetadataCount = rightStream.PersonalMetadata.Count; } // compare stream metadata bool samePublicMetadata = true; bool samePersonalMetadata = true; this.PublicMetadata = CompareFileData.CompareMetadata(leftPublicMetadata, rightPublicMetadata, out samePublicMetadata); this.PersonalMetadata = CompareFileData.CompareMetadata(leftPersonalMetadata, rightPersonalMetadata, out samePersonalMetadata); if (this.LeftPublicMetadataCount == 0 && this.RightPublicMetadataCount == 0) { this.StreamPublicMetadataCompareText = string.Format(Strings.PublicMetadataHeader, Strings.None); } else { this.StreamPublicMetadataCompareText = string.Format(Strings.PublicMetadataHeader, samePublicMetadata ? Strings.Same : Strings.Different); } if (this.LeftPersonalMetadataCount == 0 && this.RightPersonalMetadataCount == 0) { this.StreamPersonalMetadataCompareText = string.Format(Strings.PersonalMetadataHeader, Strings.None); } else { this.StreamPersonalMetadataCompareText = string.Format(Strings.PersonalMetadataHeader, samePersonalMetadata ? Strings.Same : Strings.Different); } // compare stream details this.StreamDetails = new ObservableCollection <CompareData>(); this.StreamDetails.Add(new CompareData(dataTypeIdKey, leftDataTypeId, rightDataTypeId)); this.StreamDetails.Add(new CompareData(semanticIdKey, leftSemanticId, rightSemanticId)); this.StreamDetails.Add(new CompareData(eventCountKey, leftEventCount, rightEventCount)); this.StreamDetails.Add(new CompareData(startTimeKey, leftStartTime, rightStartTime)); this.StreamDetails.Add(new CompareData(endTimeKey, leftEndTime, rightEndTime)); bool sameDetails = this.StreamDetails.All(data => data.Same); this.StreamDetailsCompareText = string.Format(Strings.StreamDetailsHeader, sameDetails ? Strings.Same : Strings.Different); this.Same = (samePublicMetadata && samePersonalMetadata && sameDetails) ? true : false; }
/// <summary> /// Returns all key/value pairs in a metadata object as a single string /// </summary> /// <param name="metadata">Collection of metadata items</param> /// <param name="type">Public or PersonallyIdentifiableInformation</param> /// <param name="streamName">Name of stream which metadata belongs to, empty if file-level metadata</param> /// <returns>A string which contains all key/value pairs in the metadata object</returns> private static string GetMetadataAsText(KStudioMetadata metadata, KStudioMetadataType type, string streamName) { if (metadata == null) { throw new ArgumentNullException("metadata"); } StringBuilder metadataString = new StringBuilder(); metadataString.Append(Environment.NewLine); if (string.IsNullOrEmpty(streamName)) { metadataString.Append(Strings.File); } else { metadataString.Append(streamName); } metadataString.Append(" "); if (type == KStudioMetadataType.Public) { metadataString.Append(string.Format(Strings.PublicMetadataHeader, metadata.Count)); } else { metadataString.Append(string.Format(Strings.PersonalMetadataHeader, metadata.Count)); } foreach (KeyValuePair<string, object> pair in metadata) { metadataString.Append(Environment.NewLine); metadataString.Append(" "); metadataString.Append(pair.Key); metadataString.Append(" = "); metadataString.Append(Metadata.ConvertMetadataValueToString(pair.Value)); } metadataString.Append(Environment.NewLine); return metadataString.ToString(); }