Пример #1
0
        /// <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());
        }
Пример #2
0
        /// <summary>
        /// Edits file or stream-level metadata
        /// </summary>
        /// <param name="filePath">Path of file which contains metadata to edit</param>
        /// <param name="key">Key of metadata item to alter</param>
        /// <param name="value">New value to set for the metadata item</param>
        /// <param name="streamName">String which represents the stream to alter metadata for</param>
        /// <param name="updatePersonalMetadata">Value which indicates if personal metadata should be altered (default is public)</param>
        /// <param name="updateStreamMetadata">Value which indicates if stream metadata should be altered (default is file)</param>
        /// <returns>String containing updated contents of the target metadata object</returns>
        private string EditMetadata(string filePath, string key, object value, string streamName, bool updatePersonalMetadata, bool updateStreamMetadata)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            string metadataText = string.Empty;

            using (KStudioClient client = KStudio.CreateClient())
            {
                if (filePath.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant()))
                {
                    client.ConnectToService();
                }

                KStudioMetadataType type = KStudioMetadataType.Public;
                if (updatePersonalMetadata)
                {
                    type = KStudioMetadataType.PersonallyIdentifiableInformation;
                }

                if (updateStreamMetadata)
                {
                    metadataText = Metadata.UpdateStreamMetadata(client, filePath, streamName, type, key, value);
                }
                else
                {
                    metadataText = Metadata.UpdateFileMetadata(client, filePath, type, key, value);
                }
            }

            return(metadataText);
        }
Пример #3
0
        /// <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;
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        /// <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();
        }
Пример #7
0
        /// <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;
        }