Ejemplo n.º 1
0
        /// <inheritdoc/>
        public void Write(IEnumerable <RankedTheorem> rankedTheorems)
        {
            // Check if we have begun
            if (!HasWritingBegun)
            {
                throw new RankedTheoremIOException("Writing hasn't begun yet.");
            }

            // Go through the theorems
            foreach (var rankedTheorem in rankedTheorems)
            {
                // If we haven written anything, write a colon to separate entries
                if (_firstEntryWritten)
                {
                    _writingStream.Write(",");
                }
                // Otherwise mark that we've written something (we're about to)
                else
                {
                    _firstEntryWritten = true;
                }

                // Serialize the theorem
                var theoremString = JsonConvert.SerializeObject(RankedTheoremIntermediate.Convert(rankedTheorem));

                // Write it
                _writingStream.Write(theoremString);
            }

            // Flush
            _writingStream.Flush();
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public IEnumerable <RankedTheorem> Read(string filePath)
        {
            // Prepare the reader of the file
            using JsonTextReader reader = new JsonTextReader(new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read)));

            // Read until the end
            while (reader.Read())
            {
                // If we have a token that starts an object...
                if (reader.TokenType == JsonToken.StartObject)
                {
                    // Load the object from the stream and convert it to our intermediate one
                    var intermediateObject = JObject.Load(reader).ToObject <RankedTheoremIntermediate>();

                    // Return its converted version to the real object
                    yield return(RankedTheoremIntermediate.Convert(intermediateObject));
                }
            }
        }