Example #1
0
 public IActionResult InitializeTapes()
 {
     // We do not initialize unless database is empty for safety reasons
     if (_tapeService.GetAllTapes().Count > 0)
     {
         return(BadRequest(new ExceptionModel {
             StatusCode = (int)HttpStatusCode.BadRequest,
             Message = "Tapes have already initialized in some form"
         }));
     }
     // Otherwise add tapes from initialization file
     using (StreamReader r = StreamReaderFactory.GetStreamReader("./Resources/tapes.json")) {
         string  json      = r.ReadToEnd();
         dynamic tapesJSON = JsonConvert.DeserializeObject(json);
         foreach (var tapeJSON in tapesJSON)
         {
             // Generate input model from json tape
             TapeInputModel tape = SeedingUtils.ConvertJSONToTapeInputModel(tapeJSON);
             // Check if tape input model is valid
             if (!ModelState.IsValid)
             {
                 IEnumerable <string> errorList = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage);
                 throw new InputFormatException("Video tape in initialization file improperly formatted.", errorList);
             }
             // Create new tape if input model was valid
             Console.WriteLine($"adding tape {tapeJSON.id} of {tapesJSON.Count}");
             _tapeService.CreateTape(tape);
         }
     }
     return(NoContent());
 }
Example #2
0
        public void EmptyFile()
        {
            var streamReader = StreamReaderFactory.Create("../../Resources/IO/Empty.txt");
            var cs           = new CharStream(streamReader);

            Assert.IsTrue(cs.EndOfStream());
        }
        public TextDeserializer(StreamReaderFactory streamReaderFactory) : base(streamReaderFactory)
        {
            this._mNodeBuilder = new NodeBuilder();

            this._mTokenizer = new Tokenizer();

            this._mStateStack = new Stack <State>();
        }
Example #4
0
        public void ValidFTLPartialBodyTest()
        {
            var streamReader = StreamReaderFactory.Create("../../Resources/Parsers/example.ftl");
            var ctx          = new Context(Context.ASTTypes.Partial);
            var parser       = new Parser();

            Assert.IsNotNull(parser.Parse(streamReader, ctx));
        }
Example #5
0
        public IActionResult InitializeUsersAndBorrows()
        {
            // We do not initialize unless database is empty for safety reasons
            if (_userService.GetAllUsers().Count > 0)
            {
                return(BadRequest(new ExceptionModel {
                    StatusCode = (int)HttpStatusCode.BadRequest,
                    Message = "Users have already been initialized in some form"
                }));
            }
            // We do not initialize users unless tapes have been initialized due to borrow records
            if (_tapeService.GetAllTapes().Count == 0)
            {
                return(BadRequest(new ExceptionModel {
                    StatusCode = (int)HttpStatusCode.BadRequest,
                    Message = "Tapes need to be initialized before users. Call [POST] /tapes/initialize before."
                }));
            }
            // Otherwise add users from initialization file
            using (StreamReader r = StreamReaderFactory.GetStreamReader("../Resources/usersAndBorrows.json")) {
                string  json      = r.ReadToEnd();
                dynamic usersJSON = JsonConvert.DeserializeObject(json);
                foreach (var userJSON in usersJSON)
                {
                    // Generate input model from json for user
                    UserInputModel user = SeedingUtils.ConvertJsonToUserInputModel(userJSON);
                    // Check if tape input model is valid
                    if (!ModelState.IsValid)
                    {
                        IEnumerable <string> errorList = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage);
                        throw new InputFormatException("User in initialization file improperly formatted.", errorList);
                    }
                    // Create new user if input model was valid
                    Console.WriteLine($"adding user and user records for user {userJSON.id} of {usersJSON.Count}");
                    int userId = _userService.CreateUser(user);

                    SeedingUtils.CreateTapesForUser(userJSON, _tapeService);
                }
            }
            return(NoContent());
        }
 public RoadConditionRepository(StreamReaderFactory streamReaderFactory)
 {
     _streamReaderFactory = streamReaderFactory;
 }
 public RoadConditionRepository(StreamReaderFactory streamReaderFactory)
 {
     _streamReaderFactory = streamReaderFactory;
 }
 /// <summary>
 /// Constructs a new <see cref="SQLFileDataMigration" />.
 /// </summary>
 /// <param name="streamReaderFactory">The factory for an UTF-8 encoded <see cref="StreamReader" /> with the SQL script</param>
 /// <param name="closeStream">true for closing the stream after reading</param>
 public SQLFileDataMigration(StreamReaderFactory streamReaderFactory, bool closeStream)
     : base()
 {
     m_streamReaderFactory = streamReaderFactory;
     m_closeStream         = closeStream;
 }
 public TravelTimeRepository(StreamReaderFactory streamReaderFactory)
 {
     _streamReaderFactory = streamReaderFactory;
 }
 public AdjacenciesDeserializer(StreamReaderFactory streamReaderFactory) : base(streamReaderFactory)
 {
 }
Example #11
0
 public LocalisationDeserializer(StreamReaderFactory streamReaderFactory) : base(streamReaderFactory)
 {
 }
Example #12
0
        public void CharStreamFile()
        {
            var streamReader = StreamReaderFactory.Create("../../Resources/IO/CharStream.txt");
            var cs           = new CharStream(streamReader);

            Assert.AreEqual('H', cs.PeekNext());
            Assert.AreEqual("Hello, World!", cs.ReadLine());
            Assert.AreEqual("你好,世界!", cs.ReadLine());
            Assert.IsEmpty(cs.ReadLine());
            Assert.AreEqual("Chào thế giới!", cs.ReadLine());
            Assert.IsEmpty(cs.ReadLine());
            Assert.IsEmpty(cs.ReadLine());

            Assert.AreEqual("foo", cs.ReadWhile((c) => Char.IsLetter((char)c)));
            Assert.AreEqual("123", cs.ReadWhile((c) => Char.IsDigit((char)c)));
            cs.SkipCharacter(' ');
            Assert.AreEqual('b', cs.PeekNext());
            cs.SkipNext();             // b
            Assert.AreEqual('a', cs.PeekNext());
            cs.SkipCharacter('a');
            Assert.AreEqual('r', cs.ReadNext());
            cs.SkipNext();             // \n

            Assert.AreEqual("こんにちは世界!", cs.ReadLine());

            // read 1 line
            Assert.AreEqual(1, cs.SkipWhile(CharStream.IsNL));

            // Read mix between ASCII (dsl) and unicode (locale)
            cs.SkipCharacter('<');
            Assert.AreEqual("hello", cs.ReadWhile(char.IsLetter));
            cs.SkipString(" \"");
            Assert.AreEqual("你好", cs.ReadWhile((c) => c != '"'));
            Assert.AreEqual("\">", cs.ReadLine());

            // empty seperator line
            Assert.IsEmpty(cs.ReadLine());

            // making sure we're still correct
            Assert.AreEqual('0', cs.PeekNext());
            Assert.AreEqual('0', cs.PeekNext());

            int pos = 0;

            while (char.IsDigit(cs.PeekNext()))
            {
                cs.SkipCharacter((pos++).ToString()[0]);
                if (cs.PeekNext() != ',')
                {
                    break;                     // early exit
                }
                cs.SkipCharacter(',');
            }
            Assert.AreEqual('a', cs.PeekNext());
            cs.SkipBlock(2);             // a,
            while (char.IsDigit(cs.PeekNext()))
            {
                cs.SkipCharacter((pos++).ToString()[0]);
                if (cs.PeekNext() != ',')
                {
                    break;                     // early exit
                }
                cs.SkipCharacter(',');
            }
            Assert.IsEmpty(cs.ReadLine());
            Assert.IsEmpty(cs.ReadLine());

            cs.SkipString("[[");
            Assert.AreEqual("end", cs.ReadBlock(3));
            cs.SkipString("]]");
            Assert.IsEmpty(cs.ReadLine());

            Assert.AreEqual("\nor is it?\n", cs.ReadUntilEnd());

            Assert.IsTrue(cs.EndOfStream());
        }
 public Deserializer(StreamReaderFactory streamReaderFactory)
 {
     this._mStream = streamReaderFactory.GetStream();
 }
 public TravelTimeRepository(StreamReaderFactory streamReaderFactory)
 {
     _streamReaderFactory = streamReaderFactory;
 }
Example #15
0
 public DefinitionDeserializer(StreamReaderFactory streamReaderFactory) : base(streamReaderFactory)
 {
 }