// // DocumentInfo.cs // // Author: Kees van Spelde // // Copyright (c) 2013-2018 Magic-Sessions. (www.magic-sessions.com) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // using System; using System.Collections; using System.Collections.Specialized; using System.Globalization; namespace MsgReader.Rtf { /// /// Document information /// internal class DocumentInfo { #region Fields private readonly StringDictionary _infoStringDictionary = new StringDictionary(); private DateTime _backupTime = DateTime.Now; private DateTime _creationTime = DateTime.Now; private DateTime _printTime = DateTime.Now; private DateTime _revisionTime = DateTime.Now; #endregion #region Properties /// /// Document title /// public string Title { get { return _infoStringDictionary["title"]; } set { _infoStringDictionary["title"] = value; } } /// /// Document subject /// public string Subject { get { return _infoStringDictionary["subject"]; } set { _infoStringDictionary["subject"] = value; } } /// /// Document author /// public string Author { get { return _infoStringDictionary["author"]; } set { _infoStringDictionary["author"] = value; } } /// /// Document manager /// public string Manager { get { return _infoStringDictionary["manager"]; } set { _infoStringDictionary["manager"] = value; } } /// /// Document company /// public string Company { get { return _infoStringDictionary["company"]; } set { _infoStringDictionary["company"] = value; } } /// /// Document operator /// public string Operator { get { return _infoStringDictionary["operator"]; } set { _infoStringDictionary["operator"] = value; } } /// /// Document category /// public string Category { get { return _infoStringDictionary["category"]; } set { _infoStringDictionary["categroy"] = value; } } /// /// Document keywords /// public string Keywords { get { return _infoStringDictionary["keywords"]; } set { _infoStringDictionary["keywords"] = value; } } /// /// Document comment /// public string Comment { get { return _infoStringDictionary["comment"]; } set { _infoStringDictionary["comment"] = value; } } /// /// Document doccomm /// public string Doccomm { get { return _infoStringDictionary["doccomm"]; } set { _infoStringDictionary["doccomm"] = value; } } /// /// Document base /// public string HLinkbase { get { return _infoStringDictionary["hlinkbase"]; } set { _infoStringDictionary["hlinkbase"] = value; } } /// /// Total edit minutes /// public int EditMinutes { get { if (_infoStringDictionary.ContainsKey("edmins")) { var v = Convert.ToString(_infoStringDictionary["edmins"]); int result; if (int.TryParse(v, out result)) return result; } return 0; } set { _infoStringDictionary["edmins"] = value.ToString(CultureInfo.InvariantCulture); } } /// /// Document version /// public string Version { get { return _infoStringDictionary["vern"]; } set { _infoStringDictionary["vern"] = value; } } /// /// Document number of pages /// public string NumberOfPages { get { return _infoStringDictionary["nofpages"]; } set { _infoStringDictionary["nofpages"] = value; } } /// /// Document number of words /// public string NumberOfWords { get { return _infoStringDictionary["nofwords"]; } set { _infoStringDictionary["nofwords"] = value; } } /// /// Document number of characters , include whitespace /// public string NumberOfCharaktersWithWhiteSpace { get { return _infoStringDictionary["nofchars"]; } set { _infoStringDictionary["nofchars"] = value; } } /// /// Document number of characters , exclude white space /// public string NumberOfCharaktersWithoutWhiteSpace { get { return _infoStringDictionary["nofcharsws"]; } set { _infoStringDictionary["nofcharsws"] = value; } } /// /// Document inner id /// public string Id { get { return _infoStringDictionary["id"]; } set { _infoStringDictionary["id"] = value; } } /// /// Document Creation time /// public DateTime CreationTime { get { return _creationTime; } set { _creationTime = value; } } /// /// Document modified time /// public DateTime RevisionTime { get { return _revisionTime; } set { _revisionTime = value; } } /// /// Document last print time /// public DateTime PrintTime { get { return _printTime; } set { _printTime = value; } } /// /// Document last backup time /// public DateTime BackupTime { get { return _backupTime; } set { _backupTime = value; } } #endregion #region StringItems internal string[] StringItems { get { var list = new ArrayList(); foreach (string key in _infoStringDictionary.Keys) { list.Add(key + "=" + _infoStringDictionary[key]); } list.Add("Creatim=" + CreationTime.ToString("yyyy-MM-dd HH:mm:ss")); list.Add("Revtim=" + RevisionTime.ToString("yyyy-MM-dd HH:mm:ss")); list.Add("Printim=" + PrintTime.ToString("yyyy-MM-dd HH:mm:ss")); list.Add("Buptim=" + BackupTime.ToString("yyyy-MM-dd HH:mm:ss")); return (string[]) list.ToArray(typeof (string)); } } #endregion #region GetInfo /// /// get information specify name /// /// name /// value public string GetInfo(string strName) { return _infoStringDictionary[strName]; } #endregion #region SetInfo /// /// set information specify name /// /// name /// value public void SetInfo(string strName, string strValue) { _infoStringDictionary[strName] = strValue; } #endregion #region Clear public void Clear() { _infoStringDictionary.Clear(); _creationTime = DateTime.Now; _revisionTime = DateTime.Now; _printTime = DateTime.Now; _backupTime = DateTime.Now; } #endregion #region Write public void Write(Writer writer) { writer.WriteStartGroup(); writer.WriteKeyword("info"); foreach (string strKey in _infoStringDictionary.Keys) { writer.WriteStartGroup(); if (strKey == "edmins" || strKey == "vern" || strKey == "nofpages" || strKey == "nofwords" || strKey == "nofchars" || strKey == "nofcharsws" || strKey == "id") { writer.WriteKeyword(strKey + _infoStringDictionary[strKey]); } else { writer.WriteKeyword(strKey); writer.WriteText(_infoStringDictionary[strKey]); } writer.WriteEndGroup(); } writer.WriteStartGroup(); WriteTime(writer, "creatim", _creationTime); WriteTime(writer, "revtim", _revisionTime); WriteTime(writer, "printim", _printTime); WriteTime(writer, "buptim", _backupTime); writer.WriteEndGroup(); } #endregion #region WriteTime private void WriteTime(Writer writer, string name, DateTime value) { writer.WriteStartGroup(); writer.WriteKeyword(name); writer.WriteKeyword("yr" + value.Year); writer.WriteKeyword("mo" + value.Month); writer.WriteKeyword("dy" + value.Day); writer.WriteKeyword("hr" + value.Hour); writer.WriteKeyword("min" + value.Minute); writer.WriteKeyword("sec" + value.Second); writer.WriteEndGroup(); } #endregion } }