Пример #1
0
        private static Claims TicketToJson(string ticket, Func <string, string, bool> verifier, ClaimsAuthority claimsAuthority)
        {
            Contract.Assert(Conf.Preamble.Equals(ticket.Substring(0, Conf.Preamble.Length)), "preamble missing or corrupt");
            var versionAndClaimAndImpersonator = ticket.Substring(Conf.Preamble.Length).Split(Conf.VersionAndClaimAndImpersonatorSeperator);
            var version = versionAndClaimAndImpersonator[Conf.VersionIndex];
            var claimAndSignatureBlock = versionAndClaimAndImpersonator[Conf.ClaimIndex];
            var impersonator           = versionAndClaimAndImpersonator.Length + 1 == Conf.ImpersonatorIndex ? versionAndClaimAndImpersonator[Conf.ImpersonatorIndex] : string.Empty;

            Contract.Assert(!string.IsNullOrWhiteSpace(version), "parser error -- version is required");
            Contract.Assert(!string.IsNullOrWhiteSpace(claimAndSignatureBlock), "parser error -- claim and signature are required");
            var claimAndSignature  = claimAndSignatureBlock.Split(Conf.ClaimAndSignatureSeperator);
            var claimSectionsBlock = claimAndSignature[Conf.ClaimSectionsIndex];
            var signature          = claimAndSignature[Conf.SignatureIndex];
            var encoded            = claimSectionsBlock;
            var claimSections      = claimSectionsBlock.Split(Conf.SectionSeperator);
            var claimset           = claimSections[Conf.ClaimsetIndex];
            var details            = claimSections[Conf.DetailsIndex];
            var expiration         = claimSections[Conf.TimestampIndex];

            Contract.Assert(!string.IsNullOrWhiteSpace(claimset), "parser error -- claimset section is required");
            Contract.Assert(!string.IsNullOrWhiteSpace(details), "parser error -- details section is required");
            Contract.Assert(!string.IsNullOrWhiteSpace(expiration), "parser error -- expiration section is required");
            var detailBlocks  = details.Split(Conf.ItemSeperator);
            var len           = detailBlocks.Length;
            var i             = -1;
            var parsedDetails = new Dictionary <string, Dictionary <string, string> >();

            while (++i < len)
            {
                var block           = detailBlocks[i].Split(Conf.ClaimsetSeparator);
                var claimsetId      = new ArraySegment <string>(block, Conf.ClaimsetIdIndex, Conf.ClaimsetDetailsIndex - Conf.ClaimsetIdIndex).First();
                var rawDetailsArray = new ArraySegment <string>(block, Conf.ClaimsetDetailsIndex, block.Length - Conf.ClaimsetDetailsIndex).ToArray();
                var detailsArrayLen = rawDetailsArray.Length;
                var j            = -1;
                var parsedValues = new Dictionary <string, string>();
                while (++j < detailsArrayLen)
                {
                    var rules        = rawDetailsArray[j].Split(Conf.DetailSeperator);
                    var detailRuleId = rules[Conf.DetailsRuleIdIndex];
                    var detail       = rules[Conf.DetailsRuleIndex];
                    parsedValues[detailRuleId] = detail;
                }
                parsedDetails[claimsetId] = parsedValues;
            }
            var claimBlocks = claimset.Split(Conf.ItemSeperator);

            len = claimBlocks.Length;
            i   = -1;
            var claimsets           = new Dictionary <string, Claimset>();
            var knownIdentityValues = new Dictionary <string, string>();

            while (++i < len)
            {
                var block         = claimBlocks[i].Split(Conf.ClaimsetSeparator);
                var claimsetId    = block[Conf.ClaimsetIdIndex];
                var claimsetRules = int.Parse(block[Conf.ClaimsetRulesIndex], System.Globalization.NumberStyles.HexNumber);
                var claims        = new Dictionary <string, Claim>();
                var b             = 1;
                while (b <= claimsetRules)
                {
                    if (b == (b & claimsetRules))
                    {
                        var claimId           = b.ToString("x");
                        var claimOptionsValue = default(string);
                        if (parsedDetails.ContainsKey(claimsetId))
                        {
                            var claimsetDetails = parsedDetails[claimsetId];
                            var encodedValue    = claimsetDetails[claimId];
                            claimOptionsValue = Encoding.UTF8.GetString(Convert.FromBase64String(encodedValue));
                        }
                        var claimOptionsKind = !string.IsNullOrWhiteSpace(claimOptionsValue) ? ClaimKind.Identity : ClaimKind.Unknown;
                        claims[claimId] = new Claim(id: claimId, kind: claimOptionsKind, value: claimOptionsValue);
                    }
                    b *= 2;
                }
                claimsets[claimsetId] = new Claimset(id: claimsetId, claims: claims, signature: signature);
            }
            var result = new Claims(claimsets, Convert.ToDateTime(expiration), signature, encoded, ticket, verifier, claimsAuthority);

            return(result);
        }
Пример #2
0
        private void RunMenu()
        {
            Console.Clear();
            Console.WriteLine(
                "Choose a menu item: \n\n" +
                "1. See all claims\n\n" +
                "2. Take care of next claim\n\n" +
                "3. Enter a new claim\n\n");
            string selection = Console.ReadLine();

            if (selection == "1")
            {
                Queue <Claim> listOfContent = _claimRepo.SeeAllClaims();
                foreach (Claim claim in listOfContent)
                {
                    Console.WriteLine(claim.ClaimID);
                    Console.WriteLine(claim.ClaimType);
                    Console.WriteLine(claim.Description);
                    Console.WriteLine(claim.ClaimAmount);
                    Console.WriteLine(claim.DateOfIncident);
                    Console.WriteLine(claim.DateOfClaim);
                }
                Console.ReadKey();
            }
            else if (selection == "2")
            {
                Console.Clear();

                Claim currentClaim = _claimRepo.Peek();
                if (currentClaim == null)
                {
                    Console.WriteLine("No claims found.");
                    Thread.Sleep(3000);
                }
                else
                {
                    Console.WriteLine(
                        $"{currentClaim.ClaimID}\n" +
                        $"{currentClaim.ClaimType}\n" +
                        $"{currentClaim.Description}\n" +
                        $"{currentClaim.ClaimAmount}\n" +
                        $"{currentClaim.DateOfIncident}\n" +
                        $"{currentClaim.DateOfClaim}\n" +
                        $"{currentClaim.IsValid}\n");
                    Console.WriteLine("Do you want to deal with this claim now(y/n)?");
                    string yesOrNo = Console.ReadLine();
                    if (yesOrNo == "y")
                    {
                        _claimRepo.Dequeue();
                        RunMenu();
                    }
                    else if (yesOrNo == "n")
                    {
                        RunMenu();
                    }
                    else
                    {
                        Console.WriteLine("This is not a valid selection.");
                        Thread.Sleep(4000);
                    }
                }
            }

            else if (selection == "3")
            {
                Console.Clear();

                Claim claim4 = new Claim();
                Console.Write("Enter the claim id: ");
                claim4.ClaimID = int.Parse(Console.ReadLine());
                Console.Write("Enter the claim type: ");
                claim4.ClaimType = (ClaimType)Enum.Parse(typeof(ClaimType), Console.ReadLine());
                Console.Write("Enter a claim description: ");
                claim4.Description = Console.ReadLine();
                Console.Write("Amount of Damage: $");
                claim4.ClaimAmount = double.Parse(Console.ReadLine());
                Console.Write("Date of Accident: ");
                claim4.DateOfIncident = DateTime.Parse(Console.ReadLine());
                Console.Write("Date of Claim: ");
                claim4.DateOfClaim = DateTime.Parse(Console.ReadLine());

                _claimRepo.EnterNewClaim(claim4);
                RunMenu();
            }
        }