Esempio n. 1
0
        /// <summary>
        /// Parses the given file contents into blocks asynchronously.
        /// Each MoveNext() call on the returned IEnumerator will parse one line.
        /// </summary>
        static public TPackage ParseAsync <TBlock, TPackage>(string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache, out IEnumerator outLoader)
            where TBlock : class, IDataBlock
            where TPackage : class, IDataBlockPackage <TBlock>
        {
            if (inFile.IsEmpty)
            {
                outLoader = null;
                return(null);
            }

            if (inRules == null)
            {
                throw new ArgumentNullException("inRules");
            }
            if (inGenerator == null)
            {
                throw new ArgumentNullException("inGenerator");
            }

            string   fileName = string.IsNullOrEmpty(inFileName) ? NullFilename : inFileName;
            TPackage package  = inGenerator.CreatePackage(fileName);

            outLoader = InternalBlockParser <TBlock, TPackage> .ParseFile(fileName, inFile, package, inRules, inGenerator, inCache);

            return(package);
        }
Esempio n. 2
0
        /// <summary>
        /// Parses the given file contents into blocks asynchronously
        /// and merges into the given package.
        /// Each MoveNext() call on the returned IEnumerator will parse one line.
        /// </summary>
        static public IEnumerator ParseAsync <TBlock, TPackage>(ref TPackage ioPackage, string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null)
            where TBlock : class, IDataBlock
            where TPackage : class, IDataBlockPackage <TBlock>
        {
            if (inFile.IsEmpty)
            {
                return(null);
            }

            if (inRules == null)
            {
                throw new ArgumentNullException("inRules");
            }
            if (inGenerator == null)
            {
                throw new ArgumentNullException("inGenerator");
            }

            string fileName = string.IsNullOrEmpty(inFileName) ? NullFilename : inFileName;

            if (ioPackage == null)
            {
                ioPackage = inGenerator.CreatePackage(fileName);
            }
            return(InternalBlockParser <TBlock, TPackage> .ParseFile(fileName, inFile, ioPackage, inRules, inGenerator, inCache));
        }