Пример #1
0
        /// <summary>
        ///     Fills a library data provider by parsing every XML file in a given directory, the data provider is cleared of all
        ///     definitions first.
        /// </summary>
        /// <param name="path">The directory path.</param>
        /// <param name="loadOptions">
        ///     Optionally specifies what type's of library definitions will be loaded, defaults to
        ///     <see cref="LSLLibraryDataLoadOptions.All" />
        /// </param>
        /// <exception cref="System.ArgumentNullException">path</exception>
        /// <exception cref="System.ArgumentException">path</exception>
        /// <exception cref="LSLLibraryDataXmlSyntaxException">
        ///     If a syntax error was detected in an XML file (Attribute value did
        ///     not pass pattern validation.. etc..)
        /// </exception>
        /// <exception cref="DirectoryNotFoundException">
        ///     When the path in the 'path' parameter is invalid, such as being on an
        ///     unmapped drive.
        /// </exception>
        /// <exception cref="IOException">If an IOException occurs while reading a file.</exception>
        /// <exception cref="SecurityException">
        ///     The caller does not have the required permission.
        ///     <see cref="Directory.EnumerateFiles(string)" />.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        ///     The caller does not have the required permission.
        ///     <see cref="Directory.EnumerateFiles(string)" />.
        /// </exception>
        /// <exception cref="XmlException">If incorrect XML was encountered in the input stream of a file.</exception>
        /// <exception cref="PathTooLongException">
        ///     A path, file name, or combined exceed the system-defined maximum length. For
        ///     example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260
        ///     characters.
        /// </exception>
        public void FillFromXmlDirectory(string path,
                                         LSLLibraryDataLoadOptions loadOptions = LSLLibraryDataLoadOptions.All)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("Path cannot be whitespace.", "path");
            }

            ClearLibraryData();

            foreach (var file in Directory.EnumerateFiles(path, "*.xml"))
            {
                try
                {
                    AddFromXml(file, loadOptions);
                }
                catch (LSLLibraryDataXmlSyntaxException e)
                {
                    throw new LSLLibraryDataXmlSyntaxException(
                              string.Format("Error Parsing File '{0}': {1}", file, e.Message), e);
                }
            }
        }
Пример #2
0
        /// <summary>
        ///     Fills a library data provider from an XML reader object, the data provider is cleared of all definitions first.
        ///     Encoding is detected using the BOM (Byte Order Mark) of the file.
        /// </summary>
        /// <param name="filename">The XML file to read library data from.</param>
        /// <param name="loadOptions">
        ///     Optionally specifies what type's of library definitions will be loaded, defaults to
        ///     <see cref="LSLLibraryDataLoadOptions.All" />
        /// </param>
        /// <exception cref="ArgumentException">When the 'filename' parameter is whitespace.</exception>
        /// <exception cref="ArgumentNullException">When the 'filename' parameter is <c>null</c>.</exception>
        /// <exception cref="FileNotFoundException">When the file in the 'filename' parameter could not be found.</exception>
        /// <exception cref="DirectoryNotFoundException">
        ///     When the path in the 'filename' parameter is invalid, such as being on an
        ///     unmapped drive.
        /// </exception>
        /// <exception cref="IOException">
        ///     When the path in the 'filename' parameter includes an incorrect or invalid syntax for a
        ///     file name, directory name, or volume label.
        /// </exception>
        /// <exception cref="LSLLibraryDataXmlSyntaxException">
        ///     If a syntax error was detected in the XML (Attribute value did not
        ///     pass pattern validation.. etc..)
        /// </exception>
        /// <exception cref="XmlException">If incorrect XML was encountered in the input stream.</exception>
        public void FillFromXml(string filename, LSLLibraryDataLoadOptions loadOptions = LSLLibraryDataLoadOptions.All)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }

            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentException("Filename cannot be whitespace", "filename");
            }

            ClearLibraryData();


            var settings = new XmlReaderSettings()
            {
                IgnoreWhitespace = false,
                CloseInput       = true
            };

            using (var reader = XmlReader.Create(new StreamReader(filename, true), settings))
            {
                reader.ReadStartElement(RootElementName);

                _ReadXml(reader, loadOptions);

                reader.ReadEndElement();
            }
        }
Пример #3
0
        /// <summary>
        ///     Fills a library data provider from an XML reader object, the data provider is cleared of all definitions first.
        /// </summary>
        /// <param name="data">The XML reader to read from.</param>
        /// <param name="loadOptions">
        ///     Optionally specifies what type's of library definitions will be loaded, defaults to
        ///     <see cref="LSLLibraryDataLoadOptions.All" />
        /// </param>
        /// <exception cref="ArgumentNullException">When the 'data' parameter is <c>null</c>.</exception>
        /// <exception cref="LSLLibraryDataXmlSyntaxException">
        ///     If a syntax error was detected in the XML (Attribute value did not
        ///     pass pattern validation.. etc..)
        /// </exception>
        /// <exception cref="XmlException">If incorrect XML was encountered in the input stream.</exception>
        public void FillFromXml(XmlReader data, LSLLibraryDataLoadOptions loadOptions = LSLLibraryDataLoadOptions.All)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            ClearLibraryData();

            _ReadXml(data, loadOptions);

            data.ReadEndElement();
        }
Пример #4
0
        /// <summary>
        ///     Adds additional library data provider from an XML reader object, the data provider is not cleared first.
        /// </summary>
        /// <param name="data">The XML reader to read from.</param>
        /// <param name="loadOptions">
        ///     Optionally specifies what type's of library definitions will be loaded, defaults to
        ///     <see cref="LSLLibraryDataLoadOptions.All" />
        /// </param>
        /// <exception cref="ArgumentNullException">When the 'data' parameter is <c>null</c>.</exception>
        /// <exception cref="LSLLibraryDataXmlSyntaxException">
        ///     If a syntax error was detected in the XML (Attribute value did not
        ///     pass pattern validation.. etc..)
        /// </exception>
        /// <exception cref="XmlException">If incorrect XML was encountered in the input stream.</exception>
        public void AddFromXml(XmlReader data, LSLLibraryDataLoadOptions loadOptions = LSLLibraryDataLoadOptions.All)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            data.ReadStartElement(RootElementName);

            _ReadXml(data, loadOptions);

            data.ReadEndElement();
        }
Пример #5
0
        public LSLEmbeddedLibraryDataProvider(IEnumerable <string> activeSubsets, bool liveFiltering,
                                              LSLLibraryDataLoadOptions loadOptions = LSLLibraryDataLoadOptions.All) : base(activeSubsets, liveFiltering)
        {
            using (var libraryData = GetDefaultLibraryDataStream())
            {
                if (libraryData == null)
                {
                    throw new InvalidOperationException(
                              "Could not locate manifest resource LibLSLCC.LibraryData.default.xml");
                }

                // ReSharper disable once ExceptionNotDocumented
                using (var reader = XmlReader.Create(libraryData))
                {
                    // ReSharper disable once ExceptionNotDocumented
                    FillFromXml(reader, loadOptions);
                }
            }
        }
Пример #6
0
 /// <summary>
 ///     Constructs an <see cref="LSLEmbeddedLibraryDataProvider"/> using the library data embedded in LibLSLCC's assembly.
 /// </summary>
 /// <param name="liveFiltering">
 ///     If this is set to true, all subsets will be loaded into memory. And when you change the active subsets query
 ///     results will change.  Otherwise if this is false, only subsets present upon construction will be loaded.
 /// </param>
 /// <param name="libraryBaseData">The base library data to use.</param>
 /// <param name="dataAdditions">Addititional library data to import (flags).</param>
 /// <param name="loadOptions">
 ///     Optionally specifies what type's of library definitions will be loaded, defaults to
 ///     <see cref="LSLLibraryDataLoadOptions.All" />
 /// </param>
 /// <exception cref="InvalidOperationException">
 ///     If the embedded library data could not be loaded from the assembly
 ///     manifest.
 /// </exception>
 public LSLEmbeddedLibraryDataProvider(LSLLibraryBaseData libraryBaseData,
                                       LSLLibraryDataAdditions dataAdditions, bool liveFiltering,
                                       LSLLibraryDataLoadOptions loadOptions = LSLLibraryDataLoadOptions.All)
     : this(GetSubsets(libraryBaseData, dataAdditions), liveFiltering, loadOptions)
 {
 }
Пример #7
0
 /// <summary>
 ///     Constructs an <see cref="LSLEmbeddedLibraryDataProvider"/> using the library data embedded in LibLSLCC's assembly.
 ///     <see cref="LSLLibraryDataProvider.LiveFiltering"/> will be enabled by default.
 /// </summary>
 /// <param name="activeSubsets">The library subsets to utilize.</param>
 /// <param name="loadOptions">
 ///     Optionally specifies what type's of library definitions will be loaded, defaults to
 ///     <see cref="LSLLibraryDataLoadOptions.All" />
 /// </param>
 /// <exception cref="InvalidOperationException">
 ///     If the embedded library data could not be loaded from the assembly
 ///     manifest.
 /// </exception>
 public LSLEmbeddedLibraryDataProvider(IEnumerable <string> activeSubsets, LSLLibraryDataLoadOptions loadOptions = LSLLibraryDataLoadOptions.All) :
     this(activeSubsets, true, loadOptions)
 {
 }
Пример #8
0
        /// <exception cref="LSLLibraryDataXmlSyntaxException">
        ///     If a syntax error was detected in the XML (Attribute value did not
        ///     pass pattern validation.. etc..)
        /// </exception>
        private void _ReadXml(XmlReader reader, LSLLibraryDataLoadOptions loadOptions = LSLLibraryDataLoadOptions.All)
        {
            var lineInfo = (IXmlLineInfo)reader;

            try
            {
                var serializer = new LSLLibraryDataXmlSerializer();


                serializer.ReadLibrarySubsetDescription += (sender, e) =>
                {
                    lineInfo = serializer.CurrentLineInfo;
                    AddSubsetDescription(e.SubsetDescription);
                };

                if ((loadOptions & LSLLibraryDataLoadOptions.Functions) == LSLLibraryDataLoadOptions.Functions)
                {
                    serializer.ReadLibraryFunctionDefinition += (sender, e) =>
                    {
                        lineInfo = serializer.CurrentLineInfo;
                        DefineFunction(e.FunctionSignature);
                    };
                }

                if ((loadOptions & LSLLibraryDataLoadOptions.Events) == LSLLibraryDataLoadOptions.Events)
                {
                    serializer.ReadLibraryEventHandlerDefinition += (sender, e) =>
                    {
                        lineInfo = serializer.CurrentLineInfo;
                        DefineEventHandler(e.EventSignature);
                    };
                }

                if ((loadOptions & LSLLibraryDataLoadOptions.Constants) == LSLLibraryDataLoadOptions.Constants)
                {
                    serializer.ReadLibraryConstantDefinition += (sender, e) =>
                    {
                        lineInfo = serializer.CurrentLineInfo;
                        DefineConstant(e.Signature);
                    };
                }

                serializer.Parse(reader);
            }
            //LSLLibraryDataXmlSerializer.Parse() handles XmlSyntaxExceptions by throwing an LSLLibraryDataXmlSyntaxException.
            catch (LSLMissingSubsetDescriptionException e)
            {
                //thrown by AddSubsetDescription
                throw new LSLLibraryDataXmlSyntaxException(lineInfo.LineNumber, e.Message, e);
            }
            catch (LSLDuplicateSubsetDescriptionException e)
            {
                //thrown by DefineFunction, DefineEventHandler and DefineConstant
                throw new LSLLibraryDataXmlSyntaxException(lineInfo.LineNumber, e.Message, e);
            }
            catch (LSLDuplicateSignatureException e)
            {
                //thrown by DefineFunction, DefineEventHandler and DefineConstant
                throw new LSLLibraryDataXmlSyntaxException(lineInfo.LineNumber, e.Message, e);
            }
        }