Example #1
0
        public static void getXML()
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(VoterRecordsRequest));


            VoterRecordsRequest recordsRequest = new VoterRecordsRequest();
            Voter voter = new Voter();
            Name  name  = new Name()
            {
                FirstName = "John",
                LastName  = "Smith",
                FullName  = "John S. Smith"
            };

            name.MiddleName            = new string[1];
            name.MiddleName[0]         = "S";
            voter.Name                 = name;
            voter.DateOfBirthSpecified = true;
            voter.DateOfBirth          = Convert.ToDateTime("01/01/1999");

            VoterId voterId = new VoterId();

            voterId.DateOfIssuanceSpecified = true;
            voterId.DateOfIssuance          = Convert.ToDateTime("01/01/2015");
            voterId.StringValue             = "Z666776677";
            VoterIdType type = VoterIdType.driverslicense;

            voterId.Type = type;
            VoterId voterid2 = new VoterId();

            voterid2.StringValue = "1234";
            VoterIdType type2 = VoterIdType.ssn4;

            voterid2.Type = type2;
            voter.VoterId = new VoterId[2];

            voter.VoterId[0] = voterId;
            voter.VoterId[1] = voterid2;


            //voter.ResidenceAddress.NumberedThoroughfareAddress_type.CompleteAddressNumber = "4868";
            //voter.ResidenceAddress.NumberedThoroughfareAddress_type.CompleteStreetName = "Bonnie Brae Rd";
            //voter.ResidenceAddress.NumberedThoroughfareAddress_type.CompleteSubaddress = "Richmond, VA 23234";


            recordsRequest.Type    = new VoterRequestType[1];
            recordsRequest.Type[0] = VoterRequestType.lookup;

            recordsRequest.Issuer        = "Third-Party Issuer";
            recordsRequest.RequestMethod = RequestMethod.other;

            recordsRequest.Subject       = voter;
            recordsRequest.GeneratedDate = DateTime.Now;

            TextWriter write = new StreamWriter("C:\\dev\\vriout.xml");

            xmlSerializer.Serialize(write, recordsRequest);
        }
        public static XmlDocument responseRecord(VoterRecordsRequest lookuprecord)
        {
            XmlDocument             response = new XmlDocument();
            XmlSerializerNamespaces ns       = new XmlSerializerNamespaces();

            ns.Add("addr", "http://www.fgdc.gov/schemas/address/addr");
            ns.Add("addr_type", "http://www.fgdc.gov/schemas/address/addr_type");
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(VoterRecordsResponse));


            VoterRecordResults records = new VoterRecordResults();

            records.TransactionId = lookuprecord.TransactionId;
            VoterRecord vr = new VoterRecord();

            vr.Voter = new Voter();
            vr.Voter.DateOfBirthSpecified = true;
            vr.Voter.DateOfBirth          = Convert.ToDateTime(lookuprecord.Subject.DateOfBirth);
            Name votername = new Name()
            {
                FirstName = lookuprecord.Subject.Name.FirstName,
                LastName  = lookuprecord.Subject.Name.LastName,
                FullName  = lookuprecord.Subject.Name.FullName
            };

            vr.Voter.Name             = votername;
            vr.Voter.ResidenceAddress = voterAddress(lookuprecord.Subject);
            vr.Voter.MailingAddress   = mailingAddress(lookuprecord.Subject);
            Party p = new Party();

            p.Name         = "Not-specified";
            vr.Voter.Party = p;
            VoterId vid = new VoterId();

            vid.Type        = VoterIdType.statevoterregistrationid;
            vid.StringValue = "99998888991";

            vr.Voter.VoterId    = new VoterId[1];
            vr.Voter.VoterId[0] = vid;

            vr.District    = new ReportingUnit[1];
            vr.District[0] = ru("congressional", "7");
            vr.Locality    = new ReportingUnit[2];

            vr.Locality[0] = ru("county", "Richmond City");
            vr.Locality[1] = ru("precinct", "111 - One Hundred Eleven");

            records.VoterRecord = new VoterRecord[1];

            records.VoterRecord[0] = vr;

            VoterRecordsResponse vrresp = records;

            vrresp.TransactionId = "vri-resp" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "").Replace("AM", "").Replace("PM", "");

            TextWriter write = new StreamWriter("C:\\dev\\nvraresponse.xml");

            xmlSerializer.Serialize(write, vrresp, ns);

            //Simple acknowledgement example
            RequestAcknowledgement ack     = new RequestAcknowledgement();
            VoterRecordsResponse   vrresp2 = ack;

            vrresp2.TransactionId = "vri-validation" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "").Replace("AM", "").Replace("PM", "");

            TextWriter write2 = new StreamWriter("C:\\dev\\vriack.xml");

            xmlSerializer.Serialize(write2, vrresp2, ns);

            //Rejection request
            RequestRejection rejection = new RequestRejection();
            Error            e         = new Error();

            e.OtherError       = "There was an error in processing this request";
            rejection.Error    = new Error[1];
            rejection.Error[0] = e;
            VoterRecordsResponse resperr = rejection;

            resperr.TransactionId = "vri-validation" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "").Replace("AM", "").Replace("PM", "");

            TextWriter writeerr = new StreamWriter("C:\\dev\\vrierr.xml");

            xmlSerializer.Serialize(writeerr, resperr, ns);



            return(response);
        }
        public static XmlDocument lookup(string json)
        {
            XmlDocument             output      = null;
            JObject                 voterlookup = JObject.Parse(json);
            string                  firstname   = (string)voterlookup["VoterRequest"]["Subject"]["FirstName"];
            XmlSerializerNamespaces ns          = new XmlSerializerNamespaces();

            ns.Add("addr", "http://www.fgdc.gov/schemas/address/addr");
            ns.Add("addr_type", "http://www.fgdc.gov/schemas/address/addr_type");

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(VoterRecordsRequest));

            VoterRecordsRequest recordsRequest = new VoterRecordsRequest();
            Voter voter = new Voter();
            Name  name  = new Name()
            {
                FirstName = (string)voterlookup["VoterRequest"]["Subject"]["FirstName"],
                LastName  = (string)voterlookup["VoterRequest"]["Subject"]["LastName"],
                FullName  = (string)voterlookup["VoterRequest"]["Subject"]["FullName"],
            };

            name.MiddleName            = new string[1];
            name.MiddleName[0]         = (string)voterlookup["VoterRequest"]["Subject"]["MiddleName"];
            voter.Name                 = name;
            voter.DateOfBirthSpecified = true;
            voter.DateOfBirth          = Convert.ToDateTime((string)voterlookup["VoterRequest"]["Subject"]["DateOfBirth"]);

            int ids = voterlookup["VoterRequest"]["Subject"]["VoterId"].Count();

            voter.VoterId = new VoterId[ids];
            for (int i = 0; i < ids; i++)
            {
                VoterId vid = new VoterId();
                if (voterlookup["VoterRequest"]["Subject"]["VoterId"][i]["DateOfIssuance"] != null)
                {
                    vid.DateOfIssuanceSpecified = true;
                    vid.DateOfIssuance          = Convert.ToDateTime((string)voterlookup["VoterRequest"]["Subject"]["VoterId"][i]["DateOfIssuance"]);
                }
                vid.StringValue  = (string)voterlookup["VoterRequest"]["Subject"]["VoterId"][i]["StringValue"];
                vid.Type         = getVoterType((string)voterlookup["VoterRequest"]["Subject"]["VoterId"][i]["type"]);
                voter.VoterId[i] = vid;
            }

            voter.ResidenceAddress = voterAddress(voter);

            recordsRequest.Type    = new VoterRequestType[1];
            recordsRequest.Type[0] = VoterRequestType.lookup;

            recordsRequest.Issuer        = "NVRA Agency";
            recordsRequest.RequestMethod = RequestMethod.motorvehicleoffice;

            recordsRequest.Subject       = voter;
            recordsRequest.GeneratedDate = DateTime.Now;
            recordsRequest.TransactionId = "vri-request" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "").Replace("AM", "").Replace("PM", "");

            TextWriter write = new StreamWriter("C:\\dev\\nvraout.xml");

            xmlSerializer.Serialize(write, recordsRequest, ns);

            XmlDocument res = responseRecord(recordsRequest);

            using (MemoryStream ms = new MemoryStream())
            {
                xmlSerializer.Serialize(ms, recordsRequest, ns);
                ms.Position = 0;
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreWhitespace = true;

                using (var xtr = XmlReader.Create(ms, settings)) {
                    output = new XmlDocument();
                    output.Load(xtr);
                }
            }

            return(res);
        }