예제 #1
0
파일: EsiaToken.cs 프로젝트: xeltan/EsiaNET
        private void Parse(string accessToken)
        {
            string[] parts         = accessToken.Split('.');
            string   payload       = Encoding.UTF8.GetString(Base64Decode(parts[1]));
            JObject  payloadObject = JObject.Parse(payload);

            Sid   = EsiaHelpers.PropertyValueIfExists("urn:esia:sid", payloadObject);
            SbjId = EsiaHelpers.PropertyValueIfExists("urn:esia:sbj_id", payloadObject);

            double seconds;
            string value = EsiaHelpers.PropertyValueIfExists("exp", payloadObject);

            if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
            {
                EndDate = EsiaHelpers.DateFromUnixSeconds(seconds);
            }

            value = EsiaHelpers.PropertyValueIfExists("nbf", payloadObject);

            if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
            {
                BeginDate = EsiaHelpers.DateFromUnixSeconds(seconds);
            }

            value = EsiaHelpers.PropertyValueIfExists("iat", payloadObject);

            if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
            {
                CreateDate = EsiaHelpers.DateFromUnixSeconds(seconds);
            }
        }
예제 #2
0
        public AddrInfo(JObject addrInfo)
        {
            if (addrInfo != null)
            {
                var value = EsiaHelpers.PropertyValueIfExists("type", addrInfo);

                switch (value)
                {
                case "PLV":
                    AddrType = AddrType.Residential;
                    break;

                default:
                    AddrType = AddrType.Registration;
                    break;
                }

                ZipCode            = EsiaHelpers.PropertyValueIfExists("zipCode", addrInfo);
                CountryId          = EsiaHelpers.PropertyValueIfExists("countryId", addrInfo);
                AddressStr         = EsiaHelpers.PropertyValueIfExists("addressStr", addrInfo);
                Building           = EsiaHelpers.PropertyValueIfExists("building", addrInfo);
                Frame              = EsiaHelpers.PropertyValueIfExists("frame", addrInfo);
                House              = EsiaHelpers.PropertyValueIfExists("house", addrInfo);
                Flat               = EsiaHelpers.PropertyValueIfExists("flat", addrInfo);
                FiasCode           = EsiaHelpers.PropertyValueIfExists("fiasCode", addrInfo);
                Region             = EsiaHelpers.PropertyValueIfExists("region", addrInfo);
                City               = EsiaHelpers.PropertyValueIfExists("city", addrInfo);
                District           = EsiaHelpers.PropertyValueIfExists("district", addrInfo);
                Area               = EsiaHelpers.PropertyValueIfExists("area", addrInfo);
                Settlement         = EsiaHelpers.PropertyValueIfExists("settlement", addrInfo);
                AdditionArea       = EsiaHelpers.PropertyValueIfExists("additionArea", addrInfo);
                AdditionAreaStreet = EsiaHelpers.PropertyValueIfExists("additionAreaStreet", addrInfo);
                Street             = EsiaHelpers.PropertyValueIfExists("street", addrInfo);
            }
        }
예제 #3
0
파일: DocInfo.cs 프로젝트: xeltan/EsiaNET
        public DocInfo(JObject docInfo)
        {
            DocType = DocType.None;

            if (docInfo != null)
            {
                var value = EsiaHelpers.PropertyValueIfExists("type", docInfo);

                switch (value)
                {
                case "RF_PASSPORT":
                    DocType = DocType.Passport;
                    break;

                case "FID_DOC":
                    DocType = DocType.Foreign;
                    break;

                case "RF_DRIVING_LICENSE":
                    DocType = DocType.DrivingLicense;
                    break;

                case "MLTR_ID":
                    DocType = DocType.Military;
                    break;

                case "FRGN_PASS":
                    DocType = DocType.ForeignPassport;
                    break;

                case "MDCL_PLCY":
                    DocType = DocType.MedicalPolicy;
                    break;

                case "BRTH_CERT":
                    DocType = DocType.BirthCert;
                    break;

                default:
                    DocType = DocType.None;
                    break;
                }

                Verified = docInfo["vrfStu"].Value <string>() == "VERIFIED";

                Series     = EsiaHelpers.PropertyValueIfExists("series", docInfo);
                Number     = EsiaHelpers.PropertyValueIfExists("number", docInfo);
                IssueDate  = EsiaHelpers.PropertyValueIfExists("issueDate", docInfo);
                IssueId    = EsiaHelpers.PropertyValueIfExists("issueId", docInfo);
                IssuedBy   = EsiaHelpers.PropertyValueIfExists("issuedBy", docInfo);
                ExpiryDate = EsiaHelpers.PropertyValueIfExists("expiryDate", docInfo);
                FirstName  = EsiaHelpers.PropertyValueIfExists("firstName", docInfo);
                LastName   = EsiaHelpers.PropertyValueIfExists("lastName", docInfo);
            }
        }
예제 #4
0
        public VehicleInfo(JObject vehicleInfo)
        {
            if (vehicleInfo != null)
            {
                Id          = EsiaHelpers.PropertyValueIfExists("id", vehicleInfo);
                Name        = EsiaHelpers.PropertyValueIfExists("name", vehicleInfo);
                NumberPlate = EsiaHelpers.PropertyValueIfExists("numberPlate", vehicleInfo);

                var regObject = vehicleInfo["regCertificate"] as JObject;

                if (regObject != null)
                {
                    RegSeries = EsiaHelpers.PropertyValueIfExists("series", regObject);
                    RegNumber = EsiaHelpers.PropertyValueIfExists("number", regObject);
                }
            }
        }
예제 #5
0
        internal PersonInfo(JObject personInfo)
        {
            if (personInfo != null)
            {
                Id          = EsiaHelpers.PropertyValueIfExists("id", personInfo);
                FirstName   = EsiaHelpers.PropertyValueIfExists("firstName", personInfo);
                LastName    = EsiaHelpers.PropertyValueIfExists("lastName", personInfo);
                MiddleName  = EsiaHelpers.PropertyValueIfExists("middleName", personInfo);
                BirthPlace  = EsiaHelpers.PropertyValueIfExists("birthPlace", personInfo);
                Gender      = EsiaHelpers.PropertyValueIfExists("gender", personInfo);
                Citizenship = EsiaHelpers.PropertyValueIfExists("citizenship", personInfo);
                Snils       = EsiaHelpers.PropertyValueIfExists("snils", personInfo);
                Inn         = EsiaHelpers.PropertyValueIfExists("inn", personInfo);

                var value = EsiaHelpers.PropertyValueIfExists("trusted", personInfo);

                Trusted = !String.IsNullOrWhiteSpace(value) && value.ToLowerInvariant() == "true";

                if (!String.IsNullOrWhiteSpace(LastName))
                {
                    Name = LastName;

                    if (!String.IsNullOrWhiteSpace(FirstName))
                    {
                        Name = String.Format("{0} {1}", Name, FirstName);
                    }
                    if (!String.IsNullOrWhiteSpace(MiddleName))
                    {
                        Name = String.Format("{0} {1}", Name, MiddleName);
                    }
                }

                value = EsiaHelpers.PropertyValueIfExists("birthDate", personInfo);

                DateTime date;

                if (DateTime.TryParse(value, new CultureInfo("ru-RU"), DateTimeStyles.AssumeLocal, out date))
                {
                    BirthDate = date;
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Initialize a new instance with access token parameters
        /// </summary>
        /// <param name="accessToken">Access token</param>
        /// <param name="refreshToken">Refresh token</param>
        /// <param name="expiresIn">Expires in</param>
        /// <param name="payload">Payload object to parse</param>
        public EsiaToken(string accessToken, string refreshToken, string expiresIn, JObject payload) : this(accessToken)
        {
            RefreshToken = refreshToken;

            int expiresValue;

            if (Int32.TryParse(expiresIn, NumberStyles.Integer, CultureInfo.InvariantCulture, out expiresValue))
            {
                ExpiresIn = TimeSpan.FromSeconds(expiresValue);
            }

            if (payload != null)
            {
                Sid   = EsiaHelpers.PropertyValueIfExists("urn:esia:sid", payload);
                SbjId = EsiaHelpers.PropertyValueIfExists("urn:esia:sbj_id", payload);

                double seconds;
                string value = EsiaHelpers.PropertyValueIfExists("exp", payload);

                if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
                {
                    EndDate = EsiaHelpers.DateFromUnixSeconds(seconds);
                }

                value = EsiaHelpers.PropertyValueIfExists("nbf", payload);

                if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
                {
                    BeginDate = EsiaHelpers.DateFromUnixSeconds(seconds);
                }

                value = EsiaHelpers.PropertyValueIfExists("iat", payload);

                if (value != null && Double.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds))
                {
                    CreateDate = EsiaHelpers.DateFromUnixSeconds(seconds);
                }
            }
        }