示例#1
0
        internal ChoIniNameValueNode(ChoIniDocument ownerDocument, string name, string value, char nameValueSeperator, ChoIniCommentNode inlineCommentNode)
            : base(ownerDocument)
        {
            ChoGuard.ArgumentNotNullOrEmpty(name, "Name");

            //Check for valid delimiter
            if (ownerDocument.NameValueSeperator != nameValueSeperator)
            {
                throw new ChoIniDocumentException(String.Format("Invalid NameValue Seperator [{0}] passed.", nameValueSeperator));
            }

            _nameValueSeperator = nameValueSeperator;
            _name = name.Trim();
            if (!ownerDocument.IgnoreValueWhiteSpaces)
            {
                _rawValue = value;
            }
            else
            {
                _rawValue = value != null?value.Trim() : null;
            }

            _inlineCommentNode = inlineCommentNode;
            NormalizeValue();
        }
示例#2
0
        internal ChoIniIncludeFileNode(ChoIniDocument ownerDocument, string filePath, ChoIniCommentNode inlineCommentNode, Stream stream = null)
            : base(ownerDocument)
        {
            ChoGuard.ArgumentNotNullOrEmpty(filePath, "Ini Include File Path");

            _filePath          = filePath;
            _inlineCommentNode = inlineCommentNode;

            ChoIniDocument iniDocument = OwnerDocument;

            while (true)
            {
                if (iniDocument == null)
                {
                    break;
                }

                if (_filePath == iniDocument.Path)
                {
                    throw new ChoIniDocumentException(String.Format("Can't include {0} document, it is already included in the include chain of documents.", _filePath));
                }

                iniDocument = iniDocument.ParentIniDocument;
            }

            _iniDocument = new ChoIniDocument(_filePath, ownerDocument);
        }
示例#3
0
        internal ChoIniSectionNode(ChoIniDocument ownerDocument, string name, ChoIniCommentNode inlineCommentNode)
            : base(ownerDocument)
        {
            ChoGuard.ArgumentNotNullOrEmpty(name, "Name");

            _name = name != null?name.Trim() : null;

            _inlineCommentNode = inlineCommentNode;
        }
示例#4
0
        private static ChoIniDocument OpenNLoadDocument(string filePath)
        {
            ChoIniDocument iniDocument = ChoIniDocument.Load(filePath);

            iniDocument.TextIgnored    += new EventHandler <ChoIniDocumentEventArgs>(iniDocument_IgnoredEntry);
            iniDocument.TextErrorFound += new EventHandler <ChoIniDocumentEventArgs>(iniDocument_ErrorFound);

            return(iniDocument);
        }
示例#5
0
        public ChoIniDocumentService(string name, ChoIniDocument iniDocument)
        {
            ChoGuard.ArgumentNotNull(name, "Name");
            ChoGuard.ArgumentNotNull(iniDocument, "IniDocument");

            _iniDocument      = iniDocument;
            _queuedMsgService = new ChoQueuedMsgService <string>(name, ChoStandardQueuedMsgObject <string> .QuitMsg, false, false,
                                                                 QueueMessageHandler);
            _timerService = new ChoTimerService <string>(String.Format("{0}_Timer", _iniDocument.GetHashCode()),
                                                         new ChoTimerService <string> .ChoTimerServiceCallback(OnTimerServiceCallback), null, 1000, 5000, false);
        }
示例#6
0
        private static ChoIniDocument LoadDocument(string filePath)
        {
            lock (_iniDocuments.SyncRoot)
            {
                if (!_iniDocuments.ContainsKey(filePath))
                {
                    _iniDocuments.Add(filePath, OpenNLoadDocument(filePath));
                }
                else if (_iniDocuments[filePath].IsDisposed)
                {
                    _iniDocuments[filePath] = ChoIniDocument.Load(filePath);
                }

                return(_iniDocuments[filePath]);
            }
        }
示例#7
0
        internal object GetData()
        {
            if (!IniFilePath.IsNullOrWhiteSpace() && File.Exists(IniFilePath))
            {
                using (ChoIniDocument iniDocument = ChoIniDocument.Load(IniFilePath))
                {
                    ChoIniSectionNode iniSectionNode = iniDocument.GetSection(IniSectionName);
                    if (iniSectionNode != null)
                    {
                        return(iniSectionNode.ToNameValueCollection());
                    }
                }
            }

            return(null);
        }
示例#8
0
        internal void SaveData(object data)
        {
            if (!(data is NameValueCollection))
            {
                throw new ChoConfigurationException("Data object is not NameValueCollection object.");
            }

            NameValueCollection nameValueCollection = data as NameValueCollection;

            if (!IniFilePath.IsNullOrWhiteSpace())
            {
                if (!File.Exists(IniFilePath))
                {
                    using (File.CreateText(IniFilePath))
                    { }
                }

                using (ChoIniDocument iniDocument = new ChoIniDocument(IniFilePath))
                {
                    ChoIniSectionNode sectionNode = iniDocument.GetSection(IniSectionName);
                    if (sectionNode == null)
                    {
                        sectionNode = iniDocument.AddSection(IniSectionName);
                    }

                    sectionNode.ClearNodes();
                    foreach (string key in nameValueCollection.AllKeys)
                    {
                        sectionNode.AddNameValueNode(key, nameValueCollection[key] == null ? String.Empty : nameValueCollection[key].ToString());
                    }

                    sectionNode.AppendNewLine();

                    iniDocument.Save();
                }
            }
        }
示例#9
0
 internal ChoIniNewLineNode(ChoIniDocument ownerDocument)
     : base(ownerDocument)
 {
 }
示例#10
0
 internal ChoIniSectionNode(ChoIniDocument ownerDocument, string name)
     : this(ownerDocument, name, null)
 {
 }
示例#11
0
 internal ChoIniNode(ChoIniDocument ownerDocument)
 {
     _ownerDocument = ownerDocument;
 }
示例#12
0
 internal ChoIniNameValueNode(ChoIniDocument ownerDocument, string name, string value, char nameValueSeperator)
     : this(ownerDocument, name, value, nameValueSeperator, null)
 {
 }
示例#13
0
 internal ChoIniCommentNode(ChoIniDocument ownerDocument, string commentLine, char commentChar)
     : base(ownerDocument)
 {
     Value       = commentLine;
     CommentChar = commentChar;
 }
示例#14
0
 internal ChoIniCommentNode(ChoIniDocument ownerDocument, string commentLine)
     : this(ownerDocument, commentLine, ownerDocument.FirstAvailableCommentChar)
 {
 }
示例#15
0
 internal ChoIniIncludeFileNode(ChoIniDocument ownerDocument, string filePath, string commentLine, Stream stream = null)
     : this(ownerDocument, filePath, String.IsNullOrEmpty(commentLine) ? null : new ChoIniCommentNode(ownerDocument, commentLine), stream)
 {
 }
示例#16
0
 internal ChoIniIncludeFileNode(ChoIniDocument ownerDocument, string filePath)
     : this(ownerDocument, filePath, (string)null)
 {
 }