예제 #1
0
        // This function is a helper which will read the database, and add any results onto the PRET dictionary.
        // It will automatically do the substitution
        public void QueryRemoteDB(ref Dictionary <string, string> PRET, ref YAML_Config yamlc, ref DB_Worker testDB, ref string[] post, string Y)
        {
            string[] sep = new string[] {};
            int      cnt = 1;

            if (Y.Substring(0, 1) == "[")
            {
                sep = Y.Substring(2, Y.Length - 4).Replace(" ", "").Split(",");
                cnt = sep.Count();
            }
            else
            {
                List <string> tmp = new List <string> {
                };                                     // This is a bit rubbish!
                tmp.Add(Y);
                sep = tmp.ToArray();
            }

            string serstr = yamlc.GetRM(Y);

            for (int j = 0; j < cnt; j++)
            {
                if (sep[j].Substring(sep[j].Length - 1) == "?")
                {
                    sep[j] = sep[j].Substring(0, sep[j].Length - 1);
                    for (int m = 1; m < 10; m++)
                    {
                        string upr = sep[j].ToUpper() + m.ToString();
                        serstr = serstr.Replace("#" + upr + "#", PRET.GetValueOrDefault(upr));
#if DEBUG
                        Console.WriteLine(sep[j] + m.ToString() + " - " + PRET.GetValueOrDefault(upr));
#endif
                    }
                }
                else
                {
                    string upr = sep[j].ToUpper();
                    serstr = serstr.Replace("#" + upr + "#", PRET.GetValueOrDefault(upr));
#if DEBUG
                    Console.WriteLine(sep[j] + " - " + PRET.GetValueOrDefault(upr));
#endif
                }
            }

            string PR = sep[0].ToUpper();

            post = testDB.Read(serstr);

            PRET.Add("MATCHINGCOUNT" + PR, post.Count().ToString());

            for (int i = 0; i < post.Count(); i++)
            {
                PRET.Add(PR.Substring(0, 3) + (i + 1).ToString(), post[i]);
            }
        }
예제 #2
0
        public void AlreadyCreatedSearch(ref YAML_Config yamlc, ref Dictionary <string, string> PRET)
        {
            // Cycle 0 - Check to see if we have the person in a local database as a PID
            // First find out if we already have the citizen
            // We need to ensure that we log what we are doing into the database
            var testDB = new DB_Worker(yamlc.GetLS("LODBC"),
                                       yamlc.GetLS("LSERVER"),  // server needed for IP based connections
                                       yamlc.GetLS("LDB"),
                                       yamlc.GetLS("LDBUN"),
                                       yamlc.GetLS("LDBPW"));

            // This is going to return a list of possible matches (should only be one)
            string[] ret = testDB.Read(yamlc.GetLM(yamlc.GetLM("SEARCH1")).Replace("#" + yamlc.GetLM("SEARCH1").ToUpper() + "#", MatchId));
            if (ret.Count() > 0)
            {
                PRET.Add("MATCHING", ret[0]);
                // We have a match, so would normally exit here
            }
        }
예제 #3
0
        // If we don't find it locally, we need to say we don't
        public void TrawlRemoteDatabase(ref YAML_Config yamlc, ref Dictionary <string, string> PRET)
        {
            var testDB = new DB_Worker(yamlc.GetRS("RODBC"),
                                       yamlc.GetRS("RSERVER"),  // server needed for IP based connections
                                       yamlc.GetRS("RDB"),
                                       yamlc.GetRS("RDBUN"),
                                       yamlc.GetRS("RDBPW"));

            // Lets get the search count
            int cnt = Convert.ToInt32(yamlc.GetRM("SEARCHCOUNT"));

            for (int i = 1; i <= cnt; i++)
            {
                string[] post = new string[] { };   // Although this gets populated, we don't actually do anything with it as it also populates PRET

                string se = yamlc.GetRM("SEARCH" + i);

                QueryRemoteDB(ref PRET, ref yamlc, ref testDB, ref post, se);
            }
        }
        public dynamic Process(ref YAML_Config yamlc, ref Dictionary <string, string> PRET)
        {
            // Pret is where we are going to put all of our answers
            //Dictionary <string,string> PRET = new Dictionary <string,string>{};

            // Find out what the PID and LoA values are
            PRET.Add("PID", GetSafe(this.Pid));
            PRET.Add("LOA", GetSafe(this.LevelOfAssurance));
            PRET.Add("USERNAME", GetSafe(this.Username));
            PRET.Add("PASSWORD", GetSafe(this.Password));
            PRET.Add("ACCOUNTID", GetSafe(this.AccountId));

            // We need to pull out the Firstname, Surname, and DoB, all of these have optional
            // properties

            // FIRST NAME
            try
            {
                PRET.Add("FN", GetSafe(this.FirstName?.Value));
                PRET.Add("FNVER", GetSafe(this.FirstName?.Verified).ToString());
                PRET.Add("FNTO", GetSafe(this.FirstName?.ToDate));
                PRET.Add("FNFROM", GetSafe(this.FirstName?.FromDate));
            }
            catch
            {
                // Something went wrong with the forenames (object not defined)
            }
            // Not sure what it would do if there wasn't a surname?
            // SURNAME LIST
            try
            {
                var Surnames = this.Surnames.GetEnumerator();

                // Enumerate over the different surnames
                try
                {
                    var cnt = 0;
                    while (Surnames.MoveNext())
                    {
                        cnt++;

                        var SNto = GetSafe(Surnames.Current.ToDate);

                        DateTime dtTD  = DateTime.Now;
                        DateTime dtNow = DateTime.Now;

                        if (string.IsNullOrEmpty(SNto)) // ToDate couild be blank, meaning they are still there
                        {
                            PRET.Add("SURNAMETO", SNto);
                            PRET.Add("SURNAMEFROM", GetSafe(Surnames.Current.FromDate));
                            PRET.Add("SURNAME", GetSafe(Surnames.Current.Value));
                            PRET.Add("SURNAMEVER", GetSafe(Surnames.Current.Verified).ToString());
                        }
                        else          // ToDate could be ahead of Now, meaning they are still living there
                        {
                            dtTD = Convert.ToDateTime(SNto);
                            if (DateTime.Compare(dtTD, dtNow) >= 0)
                            {
                                PRET.Add("SURNAMETO", SNto);
                                PRET.Add("SURNAMEFROM", GetSafe(Surnames.Current.FromDate));
                                PRET.Add("SURNAME", GetSafe(Surnames.Current.Value));
                                PRET.Add("SURNAMEVER", GetSafe(Surnames.Current.Verified).ToString());
                            }
                        }
                    }
                }
                finally
                {
                    Surnames.Dispose();
                }
            }
            catch
            {
            }

            // Gender
            try
            {
                PRET.Add("GENDER", GetSafe(this.Gender?.Value));
                PRET.Add("GENDERVER", GetSafe(this.Gender?.Verified).ToString());
                PRET.Add("GENDERTO", GetSafe(this.Gender?.ToDate));
                PRET.Add("GENDERFROM", GetSafe(this.Gender?.FromDate));
            }
            catch
            {
                // No Gender information
            }
            // Date of Birth
            try
            {
                PRET.Add("DOB", GetSafe(this.DateOfBirth?.Value));
                PRET.Add("DOBRVER", GetSafe(this.DateOfBirth?.Verified).ToString());
                PRET.Add("DOBTO", GetSafe(this.DateOfBirth?.ToDate));
                PRET.Add("DOBFROM", GetSafe(this.DateOfBirth?.FromDate));
            }
            catch
            {
                // No DOB info
            }
            // If this is NULL then no address would be searched.
            var Address = GetSafe(this.Address);

            try
            {
                var PCto = GetSafe(Address.ToDate);

                // -------------------------------------------------------------------------------
                // We need to decide which of the Addresses to use
                // -------------------------------------------------------------------------------
                DateTime dtTD  = DateTime.Now;
                DateTime dtNow = DateTime.Now;

                if (string.IsNullOrEmpty(PCto)) // ToDate couild be blank, meaning they are still there
                {
                    PRET.Add("INTERNATIONALPOSTCODE", GetSafe(Address?.InternationalPostCode));
                    PRET.Add("POSTCODE", GetSafe(Address?.PostCode));
                    PRET.Add("POSTCODEVER", GetSafe(Address?.Verified).ToString());
                    PRET.Add("POSTCODEFROM", GetSafe(Address?.FromDate));
                    PRET.Add("POSTCODETO", PCto);
                }
                else          // ToDate could be ahead of Now, meaning they are still living there
                {
                    dtTD = Convert.ToDateTime(PCto);
                    if (DateTime.Compare(dtTD, dtNow) >= 0)
                    {
                        PRET.Add("INTERNATIONALPOSTCODE", GetSafe(Address?.InternationalPostCode));
                        PRET.Add("POSTCODE", GetSafe(Address?.PostCode));
                        PRET.Add("POSTCODEVER", GetSafe(Address?.Verified).ToString());
                        PRET.Add("POSTCODEFROM", GetSafe(Address?.FromDate));
                        PRET.Add("POSTCODETO", PCto);
                    }
                }

                var Lines = Address.Lines.GetEnumerator();

                // Enumerate over the different addresses
                try
                {
                    var cnt = 1;
                    while (Lines.MoveNext())
                    {
                        PRET.Add("ADDRESS" + cnt.ToString(), GetSafe(Lines.Current));
                        cnt++;
                    }
                }
                finally
                {
                    Lines.Dispose();
                }
            }
            catch
            {
                // We don't need to do anything
            }
            // We need to ensure that we log what we are doing into the database
            var testDB = new DB_Worker(yamlc.GetLS("LODBC"),
                                       yamlc.GetLS("LSERVER"),  // server needed for IP based connections
                                       yamlc.GetLS("LDB"),
                                       yamlc.GetLS("LDBUN"),
                                       yamlc.GetLS("LDBPW"));


            string[] ret = testDB.Read(yamlc.GetLM(yamlc.GetLM("SEARCH1")).Replace("#" + yamlc.GetLM("SEARCH1").ToUpper() + "#", PRET.GetValueOrDefault(yamlc.GetLM("SEARCH1").ToUpper())));

            if (ret.Count() > 0)
            {
                PRET.Add("ALREADYEXISTS", ret[0].ToString());
            }
            else
            {
                string   Y   = yamlc.GetLC("SEARCH1");
                string[] sep = new string[] { };
                int      cnt = 1;
                if (Y.Substring(0, 1) == "[")
                {
                    sep = Y.Substring(2, Y.Length - 4).Replace(" ", "").Split(",");
                    cnt = sep.Count();
                }
                else
                {
                    List <string> tmp = new List <string> {
                    };                                       // This is a bit rubbish!
                    tmp.Add(Y);
                    sep = tmp.ToArray();
                }

                // Check if we have an account number, if we don't add a NULL statement
                if (string.IsNullOrEmpty(PRET.GetValueOrDefault(sep[1].ToUpper())))
                {
                    PRET[sep[1].ToUpper()] = "NULL";
                }
                // We always need to add the account ID if we know it
                testDB.Go(yamlc.GetLC(yamlc.GetLC("SEARCH1")).Replace("#" + sep[0].ToUpper() + "#", PRET.GetValueOrDefault(sep[0].ToUpper()))
                          .Replace("#" + sep[1].ToUpper() + "#", PRET.GetValueOrDefault(sep[1].ToUpper()))
                          );

                // This tries to report what the line was that we created in the database
                string[] retchk = testDB.Read(yamlc.GetLM(yamlc.GetLM("SEARCH1")).Replace("#" + yamlc.GetLM("SEARCH1").ToUpper() + "#", PRET.GetValueOrDefault(yamlc.GetLM("SEARCH1").ToUpper())));

                if (retchk.Count() > 0)
                {
                    PRET.Add("INSERTED", retchk[0].ToString());
                }
                else
                {
                    PRET.Add("INSERTING", "NewRecord");
                }
            }

            // We always return the PRET, not a success or failure, that is handled in the value controller
            return(PRET);
        }
예제 #5
0
        // This takes the dictionary information that contains all of our extracted values and database
        // search results from trawling the remote database.
        // These are then processed to work out which is the best candidate for the match.
        public void Process(ref YAML_Config yamlc, ref Dictionary <string, string> PRET)
        {
            // OK there are various ways to be "clever" and come up with the right answer
            // Lets not for the moment, lets just see which ID has the most entries
            Dictionary <int, int> Counters = new Dictionary <int, int> {
            };

            // These will also count to see what number of each account are
            // going to be coming back.

            // Lets get the search count
            int cnt = Convert.ToInt32(yamlc.GetRM("SEARCHCOUNT"));

            // At the moment, we discard the broken out data, we have already at this
            // point decided to just use basic counting method, otherwise we actually
            // should be using a long hand version and not using the YAML interation
            for (int i = 1; i <= cnt; i++)
            {
                List <string[]> MyDBList = new List <string[]> {
                };

                // Make multi-part searches use the first term only
                string name = yamlc.GetRM("SEARCH" + i).ToUpper();
                if (name.Substring(0, 1) == "[")
                {
                    string[] sn = name.Substring(2, name.Length - 4).Replace(" ", "").Split(",");
                    name = sn[0];
                }

                // Remove the trailing ? if we are doing lines reading
                if (name.Substring(name.Length - 1, 1) == "?")
                {
                    name = name.Substring(0, name.Length - 1);
                }

                // If you want to do any specific modificatios to the weights so enhance the best match (or reduce one)
                // then you need to put the code here.
                // eg.
                switch (name)
                {
                case "SURNAME":
                // Call_Surname_SoundEx( ref PRET, ref Counters, ref MyDBList );
                case "DOB":
                // We may have decided to just use year of birth
                case "INTERNATIONALPOSTCODE":
                // maybe we have a special postcode reader to work out area
                case "POSTCODE":
                // maybe we have a special postcode reader to work out area
                case "ADDRESS1":
                case "ADDRESS2":
                case "ADDRESS3":
                case "ADDRESS4":
                case "ADDRESS5":
                case "ADDRESS6":
                case "ADDRESS7":
                case "ADDRESS8":
                // All the address ones come here, we may increase scoreds (any can be done) or add a new score
                // by doing address searches. E.g. +10 points for a matching line, +3 points for them being consecutive
                default:
                    // anything else it comes here
                    ExpandAndCount(ref PRET, ref Counters, ref MyDBList,
                                   "MATCHINGCOUNT" + name,
                                   name.Substring(0, 3),
                                   Convert.ToInt32(yamlc.GetRM("WEIGHT" + i)));

                    break;
                }
            }

            // Find out which of the ID's is there the most
            int cntr_i    = 0;
            int cntr_max  = 0;
            int cntr_same = 0;

            foreach (KeyValuePair <int, int> entry in Counters)
            {
                if (entry.Value == cntr_max)
                {
                    cntr_same++;
                }
                if (entry.Value > cntr_max)
                {
                    cntr_i = entry.Key; cntr_same = 0; cntr_max = entry.Value;
                }
            }

            // If we have more than one identity with the same number of maximum scores, then we can't decide between them and so we
            // must state that we don't know who the person is. (very likely a duplicate account in the remote database)
            if ((cntr_same > 0) || (cntr_max == 0))
            {
                PRET.Add("NOBESTCANDIDATE", "Total of " + (cntr_same + 1).ToString() + " same score of " + cntr_max.ToString() + " points.");
            }
            else
            {
                PRET.Add("BESTCANDIDATE", cntr_i.ToString() + " which scored " + cntr_max.ToString() + " points.");
            }
        }
예제 #6
0
        public dynamic Process(ref YAML_Config yamlc, ref Dictionary <string, string> PRET)
        {
            //Dictionary<string,string> PRET = new Dictionary<string,string>{};

            // Find out what the cycle3 matching values are
            PRET.Add("HASHPID", GetSafe(this.HashedPid));
            PRET.Add("MATCHID", GetSafe(this.MatchId));
            PRET.Add("LOA", GetSafe(this.LevelOfAssurance));

            // Date of Birth
            PRET.Add("DOB", GetSafe(this.MatchingDataset?.DateOfBirth?.Value));
            PRET.Add("DOBVER", GetSafe(this.MatchingDataset?.DateOfBirth?.Verified).ToString());  // bool
            PRET.Add("DOBTO", GetSafe(this.MatchingDataset?.DateOfBirth?.To));
            PRET.Add("DOBFROM", GetSafe(this.MatchingDataset?.DateOfBirth?.From));

            // Get the drivers license, although really this could be any kind
            // of attribute, not sure how we "Differentiate" between them,
            try
            {
                PRET.Add("DRIVERSLICENSE", GetSafe(this.Cycle3Dataset?.Attributes?.DriversLicence));
            }
            catch
            {
                // Driver license is missing
            }

            // Not sure what it would do if there wasn't a surname?
            // SURNAME LIST
            try
            {
                var Surnames = this.MatchingDataset.Surnames.GetEnumerator();

                // Enumerate over the different surnames
                try
                {
                    var cnt = 0;
                    while (Surnames.MoveNext())
                    {
                        cnt++;

                        var SNto = GetSafe(Surnames.Current?.To);

                        DateTime dtTD  = DateTime.Now;
                        DateTime dtNow = DateTime.Now;

                        if (string.IsNullOrEmpty(SNto)) // ToDate couild be blank, meaning they are still there
                        {
                            PRET.Add("SURNAMETO", SNto);
                            PRET.Add("SURNAMEFROM", GetSafe(Surnames.Current?.From));
                            PRET.Add("SURNAME", GetSafe(Surnames.Current?.Value));
                            PRET.Add("SURNAMEVER", GetSafe(Surnames.Current?.Verified).ToString());
                        }
                        else          // ToDate could be ahead of Now, meaning they are still living there
                        {
                            dtTD = Convert.ToDateTime(SNto);
                            if (DateTime.Compare(dtTD, dtNow) >= 0)
                            {
                                PRET.Add("SURNAMETO", SNto);
                                PRET.Add("SURNAMEFROM", GetSafe(Surnames.Current?.From));
                                PRET.Add("SURNAME", GetSafe(Surnames.Current?.Value));
                                PRET.Add("SURNAMEVER", GetSafe(Surnames.Current?.Verified).ToString());
                            }
                        }
                    }
                }
                finally
                {
                    Surnames.Dispose();
                }
            }
            catch
            {
            }


            try
            {
                // If this is NULL then no address would be searched.
                var Address = this.MatchingDataset.Addresses.GetEnumerator();

                // Enumerate over the different addresses
                int count = 0;
                try
                {
                    while (Address.MoveNext())
                    {
                        count++;

                        var PCto = GetSafe(Address.Current?.ToDate);

                        // -------------------------------------------------------------------------------
                        // We need to decide which of the Addresses to use
                        // -------------------------------------------------------------------------------
                        DateTime dtTD  = DateTime.Now;
                        DateTime dtNow = DateTime.Now;

                        Boolean thisAddr = false;

                        if (string.IsNullOrEmpty(PCto)) // ToDate couild be blank, meaning they are still there
                        {
                            PRET.Add("INTERNATIONALPOSTCODE", GetSafe(Address.Current?.InternationalPostCode));
                            PRET.Add("POSTCODE", GetSafe(Address.Current?.PostCode));
                            PRET.Add("POSTCODEVER", GetSafe(Address.Current?.Verified).ToString());
                            PRET.Add("POSTCODEFROM", GetSafe(Address.Current?.FromDate));
                            PRET.Add("POSTCODETO", PCto);
                            thisAddr = true;
                        }
                        else          // ToDate could be ahead of Now, meaning they are still living there
                        {
                            dtTD = Convert.ToDateTime(PCto);
                            if (DateTime.Compare(dtTD, dtNow) >= 0)
                            {
                                PRET.Add("INTERNATIONALPOSTCODE", GetSafe(Address.Current?.InternationalPostCode));
                                PRET.Add("POSTCODE", GetSafe(Address.Current?.PostCode));
                                PRET.Add("POSTCODEVER", GetSafe(Address.Current?.Verified).ToString());
                                PRET.Add("POSTCODEFROM", GetSafe(Address.Current?.FromDate));
                                PRET.Add("POSTCODETO", PCto);
                                thisAddr = true;
                            }
                        }

                        try
                        {
                            var Lines = Address.Current.Lines.GetEnumerator();

                            if (thisAddr) // ToDate couild be blank, meaning they are still there
                            {
                                try
                                {
                                    var cnt = 1;
                                    while (Lines.MoveNext())
                                    {
                                        PRET.Add("ADDRESS" + cnt.ToString(), GetSafe(Lines.Current));
                                        cnt++;
                                    }
                                }
                                finally
                                {
                                    Lines.Dispose();
                                }
                            }
                        }
                        catch
                        {
                            // No addresse lines
                        }
                    }
                }
                finally
                {
                    Address.Dispose();
                }
            }
            catch
            {
                // No address enumerator at all
            }


            // We need to search the database to find out if we have a match
            // new { result = myReturn, matching_count = myCount };

            return(PRET);
        }