Esempio n. 1
0
        public static bool Execute(FileDescriptor file)
        {
            using (FileStream fs = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
                do
                {
                    fs.SkipUtf8(" \t\r\n");
                    if (fs.PeekUtf8() != "{" || !ParseJson(fs))
                    {
                        long streamPos = fs.Position;
                        long length    = fs.FindAnyUtf8(Environment.NewLine);

                        if (length == 0)
                        {
                            return(false);
                        }

                        fs.Position = streamPos;
                        bool exitState; if (!ParseLine(fs.Read(length), out exitState))
                        {
                            return(false);
                        }

                        if (exitState)
                        {
                            return(true);
                        }
                    }
                }while (!fs.Eof());
            return(true);
        }
        /// <summary>
        /// Loads a package info from this file's content if possible
        /// </summary>
        /// <param name="logger">A logging interface to write parser errors to</param>
        /// <param name="result">The resulting package info if processing succeeded</param>
        /// <returns>True if the file has successfully been processed, false otherwise</returns>
        public static bool GetPackage(this FileDescriptor file, ILogSystem logger, out PackageMeta result)
        {
            try
            {
                JsonDocument document = new JsonDocument();
                using (Stream fs = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
                    if (document.Load(fs))
                    {
                        result = new PackageMeta();
                        PropertyMapper.Assign(result, document, true, true);

                        return(true);
                    }
                    else if (logger != null)
                    {
                        foreach (string error in document.Errors)
                        {
                            logger.Error(error);
                        }
                    }
            }
            catch (Exception er)
            {
                if (logger != null)
                {
                    logger.Error(er.Message);
                }
            }
            result = null;
            return(false);
        }