예제 #1
0
        public void SaveMetadataProperties()
        {
            try
            {
                OleDocumentProperties documentProperties = new OleDocumentProperties();
                documentProperties.Open(this.FilePath, false, dsoFileOpenOptions.dsoOptionDefault);

                var FileCustomPropertyCollection = documentProperties.CustomProperties.Cast <CustomProperty>()
                                                   .Where(property => property.Name.Contains("SoundboardSample")).ToDictionary(x => x.Name, x => x);

                // File Unique Id
                if (FileCustomPropertyCollection.ContainsKey("SoundboardSample_FileUniqueIdentifier"))
                {
                    FileCustomPropertyCollection["SoundboardSample_FileUniqueIdentifier"].set_Value(FileUniqueId.ToString());
                }
                else
                {
                    documentProperties.CustomProperties.Add("SoundboardSample_FileUniqueIdentifier", FileUniqueId.ToString());
                }

                // Hotkey
                if (FileCustomPropertyCollection.ContainsKey("SoundboardSample_Hotkey"))
                {
                    FileCustomPropertyCollection["SoundboardSample_Hotkey"].set_Value((int)Hotkey);
                }
                else
                {
                    documentProperties.CustomProperties.Add("SoundboardSample_Hotkey", (int)Hotkey);
                }

                // Volume
                if (FileCustomPropertyCollection.ContainsKey("SoundboardSample_Volume"))
                {
                    FileCustomPropertyCollection["SoundboardSample_Volume"].set_Value(Volume.ToString());
                }
                else
                {
                    documentProperties.CustomProperties.Add("SoundboardSample_Volume", Volume.ToString());
                }

                documentProperties.Save();
                documentProperties.Close();
            }
            catch (Exception ex)
            {
                ApplicationLogger.Log(ex.Message, ex.StackTrace);
            }
        }
예제 #2
0
        private void InitializePropertiesFromMetaData()
        {
            try
            {
                // Pull custom metadata properties from the file. Generate them if this is a new file and none are found
                OleDocumentProperties documentProperties = new OleDocumentProperties();
                documentProperties.Open(this.FilePath, false, dsoFileOpenOptions.dsoOptionDefault);

                var FileCustomPropertyCollection = documentProperties.CustomProperties.Cast <CustomProperty>()
                                                   .Where(property => property.Name.Contains("SoundboardSample")).ToDictionary(x => x.Name, x => x);

                if (!FileCustomPropertyCollection.Any())
                {
                    FileUniqueId = Guid.NewGuid();

                    documentProperties.CustomProperties.Add("SoundboardSample_FileUniqueIdentifier", FileUniqueId.ToString());

                    Hotkey = Key.None;
                    documentProperties.CustomProperties.Add("SoundboardSample_Hotkey", Hotkey.ToString());
                    documentProperties.CustomProperties.Add("SoundboardSample_Volume", Volume.ToString());

                    documentProperties.Save();
                }
                else
                {
                    FileUniqueId = Guid.Parse((string)FileCustomPropertyCollection["SoundboardSample_FileUniqueIdentifier"].get_Value());
                    Volume       = Convert.ToInt32(FileCustomPropertyCollection["SoundboardSample_Volume"].get_Value());

                    var hotkeyValue = FileCustomPropertyCollection["SoundboardSample_Hotkey"].get_Value();
                    Hotkey = hotkeyValue == null ? Key.None : (Key)hotkeyValue;
                }

                documentProperties.Close();
            }
            catch (Exception ex)
            {
                ApplicationLogger.Log(ex.Message, ex.StackTrace);
            }
        }