Ejemplo n.º 1
0
    public void RecognizeId(string path)
    {
        try
        {
            var text = Recognize(path);
            var res  = text.Split("\n").Where(x => x.Length > 25).TakeLast(2);

            var pData   = IdParser.Parse(res.ElementAt(0), res.ElementAt(1));
            var jsonStr = JsonConvert.SerializeObject(pData);

            var jsonPath = SaveToTemp(jsonStr);

            RecognitionFinished?.Invoke(jsonPath);
        }
        catch (ArgumentOutOfRangeException aOrE)
        {
            Console.WriteLine(aOrE.ToString());
            RecognitionFinished?.Invoke(null);
            throw new ArgumentException(ParseErrorMessage, aOrE);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
            RecognitionFinished?.Invoke(null);
            throw e;
        }
    }
Ejemplo n.º 2
0
        public void TestVALicense()
        {
            var file   = File.ReadAllText("VA License.txt");
            var idCard = IdParser.Parse(file);

            Assert.AreEqual("JUSTIN", idCard.FirstName);
            Assert.AreEqual("WILLIAM", idCard.MiddleName);
            Assert.AreEqual("MAURY", idCard.LastName);
            Assert.AreEqual(new DateTime(1958, 07, 15), idCard.DateOfBirth);

#if NET20
            Assert.AreEqual("VA", IdParser.GetAbbreviation(idCard.IssuerIdentificationNumber));
#else
            Assert.AreEqual("VA", idCard.IssuerIdentificationNumber.GetAbbreviation());
#endif
            Assert.AreEqual(new DateTime(2009, 08, 14), idCard.IssueDate);
            Assert.AreEqual(new DateTime(2017, 08, 14), idCard.ExpirationDate);
            Assert.AreEqual(Country.USA, idCard.Country);

            Assert.AreEqual("17 FIRST STREET", idCard.StreetLine1);
            Assert.AreEqual("STAUNTON", idCard.City);
            Assert.AreEqual("244010000", idCard.PostalCode);

            if (idCard is DriversLicense)
            {
                var license = (DriversLicense)idCard;

                Assert.AreEqual("158X9", license.Jurisdiction.RestrictionCodes);
            }
        }
Ejemplo n.º 3
0
        public void TestMA2016License()
        {
            var file   = File.ReadAllText("MA License 2016.txt");
            var idCard = IdParser.Parse(file, Validation.None);

            Assert.AreEqual("MORRIS", idCard.FirstName);
            Assert.AreEqual("T", idCard.MiddleName);
            Assert.AreEqual("SAMPLE", idCard.LastName);
            Assert.AreEqual(new DateTime(1971, 12, 31), idCard.DateOfBirth);

#if NET20
            Assert.AreEqual("MA", IdParser.GetAbbreviation(idCard.IssuerIdentificationNumber));
#else
            Assert.AreEqual("MA", idCard.IssuerIdentificationNumber.GetAbbreviation());
#endif
            Assert.AreEqual("S12345678", idCard.IdNumber);
            Assert.AreEqual(new DateTime(2016, 08, 09), idCard.IssueDate);
            Assert.AreEqual(Country.USA, idCard.Country);

            Assert.AreEqual("24 BEACON STREET", idCard.StreetLine1);
#if !NET20
            Assert.AreEqual("MA504", idCard.AdditionalJurisdictionElements.Single(e => e.Key == "ZMZ").Value);
#endif
            Assert.AreEqual("02133-0000", idCard.FormattedPostalCode);

            if (idCard is DriversLicense)
            {
                var license = (DriversLicense)idCard;

                Assert.AreEqual("D", license.Jurisdiction.VehicleClass);
                Assert.AreEqual("NONE", license.Jurisdiction.RestrictionCodes);
            }
        }
Ejemplo n.º 4
0
        public void TestCTLicense()
        {
            var file   = File.ReadAllText("CT License.txt");
            var idCard = IdParser.Parse(file, Validation.None);

            Assert.AreEqual("ADULT", idCard.FirstName);
            Assert.AreEqual("A", idCard.MiddleName);
            Assert.AreEqual("CTLIC", idCard.LastName);
            Assert.AreEqual(new DateTime(1961, 01, 01), idCard.DateOfBirth);

            Assert.AreEqual(new Height(Version.Aamva2013, "066 in"), idCard.Height);
            Assert.AreEqual("BLU", idCard.EyeColor);
            Assert.IsTrue(idCard.IsOrganDonor);

            Assert.AreEqual("60 STATE ST", idCard.StreetLine1);
            Assert.AreEqual("WETHERSFIELD", idCard.City);
            Assert.AreEqual("061091896", idCard.PostalCode);

#if NET20
            Assert.AreEqual("CT", IdParser.GetAbbreviation(idCard.IssuerIdentificationNumber));
#else
            Assert.AreEqual("CT", idCard.IssuerIdentificationNumber.GetAbbreviation());
#endif
            Assert.AreEqual("990000001", idCard.IdNumber);
            Assert.AreEqual(new DateTime(2015, 01, 01), idCard.ExpirationDate);
            Assert.AreEqual(Country.USA, idCard.Country);

            if (idCard is DriversLicense)
            {
                var license = (DriversLicense)idCard;

                Assert.AreEqual("D", license.Jurisdiction.VehicleClass);
                Assert.AreEqual("B", license.Jurisdiction.RestrictionCodes);
            }
        }
Ejemplo n.º 5
0
        public void TestGALicense()
        {
            var file   = File.ReadAllText("GA License.txt");
            var idCard = IdParser.Parse(file);

            Assert.AreEqual("JANICE", idCard.FirstName);
            Assert.IsNull(idCard.MiddleName);
            Assert.AreEqual("SAMPLE", idCard.LastName);
            Assert.AreEqual("PH.D.", idCard.NameSuffix);
            Assert.AreEqual(new DateTime(1957, 07, 01), idCard.DateOfBirth);

            Assert.AreEqual("123 NORTH STATE ST.", idCard.StreetLine1);
            Assert.AreEqual("ANYTOWN", idCard.City);
            Assert.AreEqual("303340000", idCard.PostalCode);

#if NET20
            Assert.AreEqual("Georgia", IdParser.GetDescription(idCard.IssuerIdentificationNumber));
            Assert.AreEqual("GA", IdParser.GetAbbreviation(idCard.IssuerIdentificationNumber));
#else
            Assert.AreEqual("Georgia", idCard.IssuerIdentificationNumber.GetDescription());
            Assert.AreEqual("GA", idCard.IssuerIdentificationNumber.GetAbbreviation());
#endif
            Assert.AreEqual(new DateTime(2006, 07, 01), idCard.IssueDate);
            Assert.AreEqual(Country.USA, idCard.Country);

            if (idCard is DriversLicense)
            {
                var license = (DriversLicense)idCard;

                Assert.AreEqual("NONE", license.Jurisdiction.RestrictionCodes);
                Assert.AreEqual("C", license.Jurisdiction.VehicleClass);
                Assert.AreEqual("P", license.Jurisdiction.EndorsementCodes);
            }
        }
Ejemplo n.º 6
0
 public async Task <Standart> GetById(string id)
 {
     return(await ExecuteAndHandleException <Standart> .Execute(async() =>
     {
         var internalId = IdParser.GetInternalId(id);
         return await _context.Standarts.Find(x => x.InternalId == internalId).FirstOrDefaultAsync();
     }
                                                                ));
 }
Ejemplo n.º 7
0
        public void TestNonStandardDataElementSeparator()
        {
            var file   = File.ReadAllText("MA License Piped.txt");
            var idCard = IdParser.Parse(file, Validation.None);

            Assert.AreEqual("S65807412", idCard.IdNumber);
            Assert.AreEqual("123 MAIN STREET", idCard.StreetLine1);
            Assert.AreEqual(Country.USA, idCard.Country);
            Assert.IsInstanceOfType(idCard, typeof(DriversLicense));
        }
Ejemplo n.º 8
0
        public FutureLocation(Uri location)
        {
            if (!location.TryGetValueFromQueryString("id", out var value))
            {
                throw new FormatException($"Location format invalid: {location}");
            }

            var parsedId = IdParser.Parse(value);

            Id = parsedId.ToGuid();

            Address = new Uri(location.GetLeftPart(UriPartial.Path));
        }
Ejemplo n.º 9
0
        private void ParseScanData(string input)
        {
            SetStatus(Level.Info, "Parsing ID");
            var id = IdParser.Parse(input, Validation.None);

            if (id is DriversLicense)
            {
                lblIdType.Text = "Drivers License";
            }
            else
            {
                lblIdType.Text = "Identification Card";
            }

            txtParsedId.Text = JsonConvert.SerializeObject(id, Formatting.Indented);
        }
Ejemplo n.º 10
0
        public void RoomIdTooLongTest()
        {
            Exception expectedException = null;

            try
            {
                string worldid;
                IdParser.TryParse("http://domain.com/PWthisroomnameiswaytoolongtoprocessefficientlyomgz12", out worldid);
            }
            catch (Exception ex)
            {
                expectedException = ex;
            }

            Assert.IsNull(expectedException);
        }
Ejemplo n.º 11
0
        public void TestMA2009License()
        {
            var file   = File.ReadAllText("MA License 2009.txt");
            var idCard = IdParser.Parse(file, Validation.None);

            Assert.AreEqual("ROBERT", idCard.FirstName);
            Assert.AreEqual("LOWNEY", idCard.MiddleName);
            Assert.AreEqual("SMITH", idCard.LastName);
#if NET20
            Assert.AreEqual("MA", IdParser.GetAbbreviation(idCard.IssuerIdentificationNumber));
#else
            Assert.AreEqual("MA", idCard.IssuerIdentificationNumber.GetAbbreviation());
#endif
            Assert.AreEqual(new DateTime(2016, 06, 29), idCard.IssueDate);
            Assert.AreEqual(new DateTime(1977, 07, 07), idCard.DateOfBirth);
            Assert.AreEqual(Country.USA, idCard.Country);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Logs in and connects to the specified room.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="password">The password.</param>
        /// <param name="worldId">The room id of the world to join</param>
        /// <param name="CreateRoom">if set to <c>true</c> secure API requests will be used.</param>
        /// <returns>
        /// Connection.
        /// </returns>
        public Connection LogOn(string email, string password, string inWorldId, bool createRoom = true)
        {
            var client = base.LogOn(GameId, email, password);

            string worldId;

            // Parse the world id (if it exists in another format)

            if (!IdParser.TryParse(inWorldId, out worldId))
            {
                throw new FormatException("The world id is invalid.");
            }

            if (createRoom)
            {
                string roomPrefix;

                switch (worldId.Substring(2))
                {
                case "BW":
                    roomPrefix = "Beta";
                    break;

                case "PW":
                    roomPrefix = "Everybodyedits";
                    break;

                default:
                    throw new FormatException("World ID must start with PW or BW when creating a new room.");
                }

                var serverVersion = client.BigDB.Load("config", "config")["version"];
                return(client.Multiplayer.CreateJoinRoom(
                           worldId,
                           roomPrefix + serverVersion,
                           true,
                           null,
                           null));
            }

            return(client.Multiplayer.JoinRoom(worldId, null));
        }
Ejemplo n.º 13
0
        public void TestNYLicense()
        {
            var file    = File.ReadAllText("NY License.txt");
            var license = IdParser.Parse(file);

            Assert.AreEqual("M", license.FirstName);
            Assert.AreEqual("Motorist", license.MiddleName);
            Assert.AreEqual("Michael", license.LastName);
            Assert.AreEqual(new DateTime(2013, 08, 31), license.DateOfBirth);

#if NET20
            Assert.AreEqual("New York", IdParser.GetDescription(license.IssuerIdentificationNumber));
            Assert.AreEqual("NY", IdParser.GetAbbreviation(license.IssuerIdentificationNumber));
#else
            Assert.AreEqual("New York", license.IssuerIdentificationNumber.GetDescription());
            Assert.AreEqual("NY", license.IssuerIdentificationNumber.GetAbbreviation());
#endif
            Assert.AreEqual(new DateTime(2013, 08, 31), license.IssueDate);
            Assert.AreEqual(new DateTime(2013, 08, 31), license.ExpirationDate);
            Assert.AreEqual(Country.USA, license.Country);

            Assert.AreEqual("2345 ANYWHERE STREET", license.StreetLine1);
            Assert.AreEqual("YOUR CITY", license.City);
        }
Ejemplo n.º 14
0
        public NotesQuery(NotesRepository notes, AuthorsRepository authors)
        {
            FieldAsync <NonNullGraphType <ListGraphType <NonNullGraphType <NoteGraphType> > > >(
                name: "notes",
                description: "Returns all existing notes.",
                resolve: async ctx => await notes.GetAll(ctx.CancellationToken));

            FieldAsync <NoteGraphType>(
                name: "noteById",
                description: "Returns the note identified by the given id, if present.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >()
            {
                Name        = "id",
                Description = "The id of the note you are looking for."
            }),
                resolve: async ctx =>
            {
                var prefixedId = ctx.GetRequiredArgument <string>("id");
                var id         = IdParser.ParsePrefixedId(prefixedId, NoteGraphType.IdPrefix);
                return(await notes.GetById(id, ctx.CancellationToken));
            });

            FieldAsync <NonNullGraphType <ListGraphType <NonNullGraphType <NoteGraphType> > > >(
                name: "notesByTitle",
                description: "Returns all notes whose titles start with the given prefix.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> >()
            {
                Name        = "title",
                Description = "A prefix of the title of the notes you are looking for."
            }),
                resolve: async ctx =>
            {
                var titlePrefix = ctx.GetRequiredArgument <string>("title");
                return(await notes.GetByTitle(titlePrefix, ctx.CancellationToken));
            });

            FieldAsync <NonNullGraphType <ListGraphType <NonNullGraphType <NoteGraphType> > > >(
                name: "notesByAuthor",
                description: "Returns all notes manipulated by the given author.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >()
            {
                Name        = "authorId",
                Description = "The id of the author whose notes you are looking for."
            }),
                resolve: async ctx =>
            {
                var prefixedId = ctx.GetRequiredArgument <string>("authorId");
                var authorId   = IdParser.ParsePrefixedId(prefixedId, AuthorGraphType.IdPrefix);
                var author     = await authors.GetById(authorId, ctx.CancellationToken);

                if (!author.HasValue)
                {
                    return(Errors.InvalidArgumentException <object>("authorId", "Author could not be found"));
                }

                return(notes.GetByAuthor(author.Value, ctx.CancellationToken));
            });

            FieldAsync <NonNullGraphType <ListGraphType <NonNullGraphType <NoteGraphType> > > >(
                name: "notesForKeyword",
                description: "Returns all notes with the given keyword.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <KeywordGraphType> >()
            {
                Name        = "keyword",
                Description = "The keyword of the notes your are looking for."
            }),
                resolve: async ctx =>
            {
                var keyword = ctx.GetRequiredArgument <Keyword>("keyword");
                return(await notes.GetByKeyword(keyword, ctx.CancellationToken));
            });

            FieldAsync <NonNullGraphType <ListGraphType <NonNullGraphType <AuthorGraphType> > > >(
                name: "authors",
                description: "Returns all existing authors.",
                resolve: async ctx => await authors.GetAll(ctx.CancellationToken));

            FieldAsync <AuthorGraphType>(
                name: "authorById",
                description: "Returns the author identified by the given id, if present.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >()
            {
                Name        = "id",
                Description = "The id of the author you are looking for."
            }),
                resolve: async ctx =>
            {
                var prefixedId = ctx.GetRequiredArgument <string>("id");
                var id         = IdParser.ParsePrefixedId(prefixedId, AuthorGraphType.IdPrefix);
                return(await authors.GetById(id, ctx.CancellationToken));
            });
        }
Ejemplo n.º 15
0
 public void removeItem([FromBody] IdParser idParser)
 {
     context.removeItemById(idParser.id);
 }
Ejemplo n.º 16
0
        public NotesMutation(NotesRepository notes, AuthorsRepository authors)
        {
            FieldAsync <NonNullGraphType <NoteGraphType> >(
                name: "addNote",
                description: "Add a new note.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <NoteInputType> >()
            {
                Name        = "note",
                Description = "The new note to be added."
            }),
                resolve: async ctx =>
            {
                var userName = ctx.RequireUserName();
                var creator  = await authors.GetByUserName(userName, ctx.CancellationToken);

                if (!creator.HasValue)
                {
                    return(Errors.InvalidUsernameError <object>());
                }

                var newNote = ctx.GetRequiredArgument <NotesRepository.NoteInput>("note");

                return(await notes.AddNote(newNote, creator.Value, ctx.CancellationToken));
            });

            FieldAsync <NoteGraphType>(
                name: "addKeyword",
                description: "Add a new keyword to an existing note with the given id.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >()
            {
                Name        = "noteId",
                Description = "The id of the note the keyword should be added to."
            },
                    new QueryArgument <NonNullGraphType <KeywordGraphType> >()
            {
                Name        = "keyword",
                Description = "The keyword to add to the note."
            }),
                resolve: async ctx =>
            {
                var prefixedId = ctx.GetRequiredArgument <string>("noteId");
                var id         = IdParser.ParsePrefixedId(prefixedId, NoteGraphType.IdPrefix);

                var keyword = ctx.GetRequiredArgument <Keyword>("keyword");

                var userName = ctx.RequireUserName();
                var editor   = await authors.GetByUserName(userName, ctx.CancellationToken);

                if (!editor.HasValue)
                {
                    return(Errors.InvalidUsernameError <object>());
                }

                var found = await notes.AddKeywordToNote(id, keyword, editor.Value, ctx.CancellationToken);

                if (!found)
                {
                    return(Errors.NotFound <object>("Note", prefixedId));
                }

                return(await notes.GetById(id, ctx.CancellationToken));
            });

            FieldAsync <BooleanGraphType>(
                name: "deleteNote",
                description: "Deletes the note with the given id, if present.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >()
            {
                Name        = "noteId",
                Description = "The id of the note that should be deleted."
            }),
                resolve: async ctx =>
            {
                var prefixedId = ctx.GetRequiredArgument <string>("noteId");
                var id         = IdParser.ParsePrefixedId(prefixedId, NoteGraphType.IdPrefix);

                var found = await notes.Remove(id, ctx.CancellationToken);

                if (!found)
                {
                    return(Errors.NotFound <bool>("Note", prefixedId));
                }

                return(true);
            });

            FieldAsync <NonNullGraphType <AuthorGraphType> >(
                name: "signup",
                description: "Create a new author.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <AuthorInputType> >()
            {
                Name        = "author",
                Description = "The new author to be added."
            }),
                resolve: async ctx =>
            {
                var newAuthor = ctx.GetRequiredArgument <AuthorsRepository.AuthorInput>("author");
                return(await authors.AddAuthor(newAuthor, ctx.CancellationToken));
            });
        }
Ejemplo n.º 17
0
 public Item getItemById([FromBody] IdParser idParser) => context.getItemById(idParser.id);