public void Add(ITextElement text)
 {
     if (TextsList.Count == 0 || TextsList.Last() != text)
     {
         TextsList.Add(text);
     }
 }
예제 #2
0
        public Dictionary <string, BsonValue> RetrieveDict()
        {
            //name of my collection
            var documents  = MongoCollection.Find(new BsonDocument()).ToList();
            var dictionary = new Dictionary <string, BsonValue>();

            List <Dictionary <string, BsonValue> > dictList = new List <Dictionary <string, BsonValue> >();

            foreach (BsonDocument bsons in documents)
            {
                var internalDict = new Dictionary <string, BsonValue>();
                Recurse(bsons, internalDict);
                dictList.Add(internalDict);
            }

            //var valTest = dictList[3]["readResults"][0]["lines"][0]["text"].RawValue;
            int  i     = 0;
            bool total = false;

            foreach (Dictionary <string, BsonValue> keyValuePairs in dictList)
            {
                List <string> simplifiedDict     = new List <string>();
                List <string> simplifiedCashDict = new List <string>();
                while (true)
                {
                    try
                    {
                        if (i == 0)
                        {
                            var dateTime = keyValuePairs["createdDateTime"].RawValue;
                            simplifiedDict.Add((string)dateTime);
                            simplifiedCashDict.Add((string)dateTime);
                            total = false;
                        }
                        var valTest = keyValuePairs["readResults"][0]["lines"][i++]["text"].RawValue;
                        simplifiedDict.Add((string)valTest);
                        string simpVal = valTest.ToString();
                        if (simpVal.Contains("$"))
                        {
                            simplifiedCashDict.Add(RemoveSpecialCharacters((string)valTest));
                            total = false;
                        }
                        else if (simpVal.Contains("TOTAL") || simpVal.Contains("Total"))
                        {
                            total = true;
                        }
                        else if (total)
                        {
                            simplifiedCashDict.Add(RemoveSpecialCharacters((string)valTest));
                            total = false;
                        }
                    }
                    catch (Exception e)
                    {
                        TextsList.Add(simplifiedDict);
                        if (simplifiedCashDict.Count > 1)
                        {
                            CashList.Add(simplifiedCashDict);
                        }
                        i = 0;
                        break;
                    }
                }
            }



            //Console.WriteLine("The list of databases are:");

            //foreach (BsonDocument doc in documents)
            //{
            //    Console.WriteLine(doc.ToString());
            //}
            return(dictionary = dictList.ElementAt <Dictionary <string, BsonValue> >(0));
        }