private void DocMetadataHandlerWriter(string metadata) { OleDocumentProperties File = new OleDocumentProperties(); File.Open(FilePath, false, dsoFileOpenOptions.dsoOptionDefault); string propertyName = "Copyright"; object propertyValue = metadata; bool hasPropertyFlag = false; foreach (CustomProperty property in File.CustomProperties) { if (property.Name == propertyName) { hasPropertyFlag = true; property.set_Value(propertyValue); break; } } if (!hasPropertyFlag) { File.CustomProperties.Add(propertyName, ref propertyValue); } File.Save(); File.Close(true); //return File; }
public static void ExportScript(string filePath, List <Script> scripts) { var scriptLines = new List <string>(); var file = File.Create(filePath); file.Close(); //write reload script //File.WriteAllText(filePath,PluginResources.reload); //var reloadScriptLines = File.ReadAllLines(filePath).ToList(); //scriptLines.AddRange(reloadScriptLines); foreach (var script in scripts) { var scriptLinesContent = CreateScriptLinesContent(script); scriptLines.AddRange(scriptLinesContent); } File.WriteAllLines(filePath, scriptLines, Encoding.UTF8); //set custom property var fileProperties = new OleDocumentProperties(); fileProperties.Open(filePath); object customProperty = "GeneratedByAhkPlugin"; fileProperties.CustomProperties.Add("SdlCommunity", ref customProperty); fileProperties.Close(true); }
public static bool IsGeneratedByAhkPlugin(string filePath) { var fileProperties = new OleDocumentProperties(); fileProperties.Open(filePath); foreach (CustomProperty property in fileProperties.CustomProperties) { if (property.Name == "SdlCommunity") { return(true); } } return(false); }
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); } }
//получение свойств файла - проверка был ли файл создан с плагином или без public static string GetFileProperty(string fileName) { OleDocumentProperties loadedFile = new OleDocumentProperties(); loadedFile.Open(fileName, false, dsoFileOpenOptions.dsoOptionDefault); foreach (CustomProperty property in loadedFile.CustomProperties) { if (property.Name == "MyPlugin") { string pluginname = property.get_Value(); loadedFile.Close(true); return(pluginname); } } return(null); }
//установка свойств файла public static void SetFileProperty(string filename, string pluginname) { OleDocumentProperties fileWithPlugin = new OleDocumentProperties(); fileWithPlugin.Open(filename, false, dsoFileOpenOptions.dsoOptionDefault); object Value = pluginname; foreach (CustomProperty property in fileWithPlugin.CustomProperties) { if (property.Name == "MyPlugin") { property.set_Value(Value); fileWithPlugin.Close(true); return; } } fileWithPlugin.CustomProperties.Add("MyPlugin", ref Value); fileWithPlugin.Save(); fileWithPlugin.Close(true); }
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); } }
private string DocMetadataHandlerReader() { OleDocumentProperties File = new OleDocumentProperties(); File.Open(FilePath, false, dsoFileOpenOptions.dsoOptionDefault); CustomProperties customProperties = File.CustomProperties; object index = "Copyright"; Metadata = ""; foreach (CustomProperty property in File.CustomProperties) { if (property.Name == index.ToString()) { Metadata = customProperties[index].get_Value(); break; } } return(Metadata); }
private string ConseguirIdArchivoLocal() { try { string idAlfrescoArchivo = ""; List <string> extOfficeDocs = new List <string> { ".docx", ".docm", ".dotx", ".dotm", ".docb", ".xlsx", ".xlsm", ".xltx", ".xltm", ".pptx", "pptm", ".potx", "potm", ".ppam", ".ppsm", ".sldx", ".sldm" }; if (extOfficeDocs.Contains(Path.GetExtension(PathLocal))) { idAlfrescoArchivo = GetCustomProperty(PathLocal, "IdAlfresco", Path.GetExtension(PathLocal)) ?? ""; } else { OleDocumentProperties archivo = new OleDocumentProperties(); archivo.Open(PathLocal); if ((!(archivo.CustomProperties.Count == 0))) { foreach (CustomProperty property in archivo.CustomProperties) { if (property.Name == "IdAlfresco") { idAlfrescoArchivo = property.get_Value(); } } } archivo.Close(true); } return(idAlfrescoArchivo); } catch (System.Runtime.InteropServices.COMException) { } return(""); }
private void AddFile(string path) { if (!System.IO.File.Exists(path)) { Utils.ShowErrorMessage("ファイルが見つかりません。\r\n" + "ファイル=" + path); return; } FileDataSet.FilePropertiesRow row = fileDataSet.FileProperties.NewRow() as FileDataSet.FilePropertiesRow; FileInfo fileInfo = new FileInfo(path); row.Name = fileInfo.FullName; row.Size = fileInfo.Length; //row.CreationTime = fileInfo.CreationTime; row.LastWriteTime = fileInfo.LastWriteTime; OleDocumentProperties props = null; try { // 書き込み用で開くけど、ここでは何もしない // 後続処理で、書き込み出来ることを前提とするため props = new OleDocumentProperties(); props.Open(fileInfo.FullName, false, dsoFileOpenOptions.dsoOptionDefault); SummaryProperties summaryProps = props.SummaryProperties; row.SummaryPropsFlag = true; row.SummaryPropsAuthor = summaryProps.Author; row.SummaryPropsCategory = summaryProps.Category; row.SummaryPropsComments = summaryProps.Comments; row.SummaryPropsCompany = summaryProps.Company; row.SummaryPropsKeywords = summaryProps.Keywords; row.SummaryPropsLastSavedBy = summaryProps.LastSavedBy; row.SummaryPropsManager = summaryProps.Manager; row.SummaryPropsRevisionNumber = summaryProps.RevisionNumber; row.SummaryPropsSubject = summaryProps.Subject; row.SummaryPropsTemplate = summaryProps.Template; row.SummaryPropsTitle = summaryProps.Title; row.SummaryPropsVersion = summaryProps.Version; } catch (Exception e) { row.SummaryPropsFlag = false; row.SummaryPropsAuthor = "(取得不可)"; row.SummaryPropsCategory = "(取得不可)"; row.SummaryPropsComments = "(取得不可)"; row.SummaryPropsCompany = "(取得不可)"; row.SummaryPropsKeywords = "(取得不可)"; row.SummaryPropsLastSavedBy = "(取得不可)"; row.SummaryPropsManager = "(取得不可)"; row.SummaryPropsRevisionNumber = "(取得不可)"; row.SummaryPropsSubject = "(取得不可)"; row.SummaryPropsTemplate = "(取得不可)"; row.SummaryPropsTitle = "(取得不可)"; row.SummaryPropsVersion = "(取得不可)"; } finally { if (props != null) { props.Close(false); } } AddFilePropertiesRow(row); // 変更を確定する // グリッドにレコード追加後でないと例外発生する row.AcceptChanges(); }
private void UpdateFileProperties(FileDataSet.FilePropertiesRow row) { FileInfo fileInfo = new FileInfo(row.Name); if (row.SummaryPropsFlag) { OleDocumentProperties props = null; try { props = new OleDocumentProperties(); props.Open(fileInfo.FullName, false, dsoFileOpenOptions.dsoOptionDefault); SummaryProperties summaryProps = props.SummaryProperties; summaryProps.Author = row.SummaryPropsAuthor; summaryProps.Category = row.SummaryPropsCategory; summaryProps.Comments = row.SummaryPropsComments; summaryProps.Company = row.SummaryPropsCompany; summaryProps.Keywords = row.SummaryPropsKeywords; summaryProps.LastSavedBy = row.SummaryPropsLastSavedBy; summaryProps.Manager = row.SummaryPropsManager; //summaryProps.RevisionNumber = row.SummaryPropsRevisionNumber; summaryProps.Subject = row.SummaryPropsSubject; //summaryProps.Template = row.SummaryPropsTemplate; summaryProps.Title = row.SummaryPropsTitle; //summaryProps.Version = row.SummaryPropsVersion; props.Save(); } catch (Exception e) { Utils.ShowErrorMessage("プロパティの変更に失敗しました。\r\n" + "ファイル=" + row.Name + "\r\n" + "エラー詳細=" + e.Message); return; } finally { if (props != null) { props.Close(false); } } } // 変更を確定する row.AcceptChanges(); }
public override async Task <MetadataResponse> Get(HttpContent content) { try { IDictionary <string, string> metadata = new Dictionary <string, string>(); string fileName = tmpDir + @"\" + Guid.NewGuid() + ".doc"; if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } using (var fs = new FileStream(fileName, FileMode.CreateNew)) await content.CopyToAsync(fs); OleDocumentProperties odp = new OleDocumentProperties(); odp.Open(fileName, true); var summaryProps = odp.SummaryProperties; /* * Builtin Document Properties: * * ApplicationName Manager * Author MultimediaClipCount * ByteCount NoteCount * Category PageCount * CharacterCount ParagraphCount * CharacterCountWithSpaces PresentationFormat * Comments RevisionNumber * Company SharedDocument * DateCreated SlideCount * DateLastPrinted Subject * DateLastSaved Template * DigitalSignature Thumbnail * DocumentSecurity Title * HiddenSlideCount TotalEditTime * Keywords Version * LastSavedBy WordCount * LineCount */ /* Only main of them have been implemented */ if (summaryProps != null) { if (metaNames.Contains("Author", StringComparer.OrdinalIgnoreCase)) { metadata["Author"] = summaryProps.Author; } if (metaNames.Contains("Category", StringComparer.OrdinalIgnoreCase)) { metadata["Category"] = summaryProps.Category; } if (metaNames.Contains("DateCreated", StringComparer.OrdinalIgnoreCase)) { metadata["DateCreated"] = ((DateTime)summaryProps.DateCreated).ToString(ISO_DATE_FORMAT); } if (metaNames.Contains("Keywords", StringComparer.OrdinalIgnoreCase)) { metadata["Keywords"] = summaryProps.Keywords; } if (metaNames.Contains("DateLastSaved", StringComparer.OrdinalIgnoreCase)) { metadata["DateLastSaved"] = ((DateTime)summaryProps.DateLastSaved).ToString(ISO_DATE_FORMAT); } if (metaNames.Contains("LastSavedBy", StringComparer.OrdinalIgnoreCase)) { metadata["LastSavedBy"] = summaryProps.LastSavedBy; } if (metaNames.Contains("Subject", StringComparer.OrdinalIgnoreCase)) { metadata["Subject"] = summaryProps.Subject; } if (metaNames.Contains("Title", StringComparer.OrdinalIgnoreCase)) { metadata["Title"] = summaryProps.Title; } if (metaNames.Contains("Version", StringComparer.OrdinalIgnoreCase)) { metadata["Version"] = summaryProps.Version; } } foreach (CustomProperty p in odp.CustomProperties) { if (metaNames.Contains(p.Name, StringComparer.OrdinalIgnoreCase)) { dynamic value = p.get_Value(); if (value is DateTime) { metadata[p.Name] = ((DateTime)value).ToString(ISO_DATE_FORMAT); } else { metadata[p.Name] = value.ToString(); } } } return(new MetadataResponse() { Url = resource.Url, StatusCode = HttpStatusCode.OK, Metadata = metadata, ErrorMessage = null }); } catch (Exception e) { return(new MetadataResponse() { Url = resource.Url, StatusCode = HttpStatusCode.BadRequest, Metadata = null, ErrorMessage = e.Message }); } }
private void WriteFileInfo(StreamWriter sw, FileInfo fileInfo) { OutLineBuilder line = new OutLineBuilder(); line.AddColumn(fileInfo.FullName); line.AddColumn(fileInfo.Length); line.AddColumn(fileInfo.LastWriteTime); OleDocumentProperties props = null; try { props = new OleDocumentProperties(); props.Open(fileInfo.FullName, true, dsoFileOpenOptions.dsoOptionDefault); SummaryProperties summaryProps = props.SummaryProperties; line.AddColumn(summaryProps.Title); line.AddColumn(summaryProps.Subject); line.AddColumn(summaryProps.Category); line.AddColumn(summaryProps.Keywords); line.AddColumn(summaryProps.Comments); line.AddColumn(summaryProps.Author); line.AddColumn(summaryProps.LastSavedBy); line.AddColumn(summaryProps.RevisionNumber); line.AddColumn(summaryProps.Company); line.AddColumn(summaryProps.Version); line.AddColumn(summaryProps.Manager); line.AddColumn(summaryProps.Template); } catch (Exception e) { line.AddColumn(e.Message); } finally { if (props != null) { props.Close(false); } } sw.WriteLine(line.ToString()); }