public IndividualClass DecodeIndividual(HttpPerson person)
        {
            if (person != null)
            {
                IndividualClass   individual = new IndividualClass();
                PersonalNameClass name       = new PersonalNameClass();

                if (person.id != null)
                {
                    individual.SetXrefName(person.id.Substring(8)); // skip "profile-"
                }
                if (person.first_name != null)
                {
                    name.SetName(PersonalNameClass.PartialNameType.GivenName, person.first_name);
                }
                if (person.last_name != null)
                {
                    name.SetName(PersonalNameClass.PartialNameType.Surname, person.last_name);
                }
                if (person.former_name != null)
                {
                    name.SetName(PersonalNameClass.PartialNameType.BirthSurname, person.former_name);
                }

                name.SanityCheck();

                individual.SetPersonalName(name);
                if (person.gender != null)
                {
                    switch (person.gender)
                    {
                    case "male":
                        individual.SetSex(IndividualClass.IndividualSexType.Male);
                        break;

                    case "female":
                        individual.SetSex(IndividualClass.IndividualSexType.Female);
                        break;
                    }
                }

                if (person.birth_date != null)
                {
                    FamilyDateTimeClass birthDate = new FamilyDateTimeClass(
                        person.birth_date.gedcom);
                    individual.AddEvent(new IndividualEventClass(IndividualEventClass.EventType.Birth, birthDate));
                }
                if (person.death_date != null)
                {
                    FamilyDateTimeClass deathDate = new FamilyDateTimeClass(
                        person.death_date.gedcom);
                    individual.AddEvent(new IndividualEventClass(IndividualEventClass.EventType.Death, deathDate));
                }

                return(individual);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public bool GetPerson(ref IndividualClass person)
        {
            PersonalNameClass name = person.GetPersonalName();

            name.SetName(PersonalNameClass.PartialNameType.GivenName, propertyList[0].Value.ToString());
            name.SetName(PersonalNameClass.PartialNameType.MiddleName, propertyList[1].Value.ToString());
            name.SetName(PersonalNameClass.PartialNameType.Surname, propertyList[2].Value.ToString());
            name.SetName(PersonalNameClass.PartialNameType.BirthSurname, propertyList[3].Value.ToString());
            //name.SetName(PersonalNameClass.PartialNameType.GivenName, propertyList[4].Value.ToString());

            person.SetPersonalName(name);

            return(true);
        }
        public IEnumerator <IndividualClass> SearchPerson(String individualName, ProgressReporterInterface progressReporter = null)
        {
            if (printDecode)
            {
                trace.TraceInformation("SearchPerson(" + individualName + ")");
            }
            if (!authenticated)
            {
                Authenticate();
                GetTreeStats();
            }

            string sLine = null;

            try
            {
                string sURL = "https://www.geni.com/api/profile/search?names=" + individualName + "&&fields=id,name";

                WebRequest wrGETURL;
                wrGETURL = WebRequest.Create(sURL);
                if (authenticationToken != null)
                {
                    wrGETURL.Headers.Add("Authorization", String.Format("Bearer {0}", Uri.EscapeDataString(authenticationToken)));
                }

                if (printDecode)
                {
                    trace.TraceInformation("SearchPerson(" + individualName + ") = " + sURL);
                }

                Stream objStream;
                objStream = wrGETURL.GetResponse().GetResponseStream();

                StreamReader objReader = new StreamReader(objStream);

                sLine = objReader.ReadToEnd();
            }
            catch
            {
                if (printDecode)
                {
                    trace.TraceInformation("SearchPerson() FAIL");
                }
                //yield return new IndividualClass();
            }

            if (sLine != null)
            {
                if (printDecode)
                {
                    trace.TraceInformation("**********************************************************-start");
                    trace.TraceInformation("{0}:{1}", sLine.Length, sLine);
                    trace.TraceInformation("**********************************************************-end");
                }
                if ((sLine.StartsWith("<!DOCTYPE") || sLine.StartsWith("<HTML") || sLine.StartsWith("<html")))
                {
                    trace.TraceInformation("Bad format. Don't parse.");
                    trace.TraceInformation("**********************************************************-start");
                    trace.TraceInformation("{0}:{1}", sLine.Length, sLine);
                    trace.TraceInformation("**********************************************************-end");
                    trace.TraceInformation("SearchPerson() FAIL");
                    sLine = null;
                    yield return(null);
                }

                if (sLine != null)
                {
                    searchPersonResult = serializer.Deserialize <HttpSearchPersonResult>(sLine);

                    foreach (HttpSearchPerson person in searchPersonResult.results)
                    {
                        IndividualClass   individual = new IndividualClass();
                        PersonalNameClass name       = new PersonalNameClass();

                        name.SetName(PersonalNameClass.PartialNameType.NameString, person.name);
                        individual.SetXrefName(person.id.Substring(8)); // skip "profile-"
                        individual.SetPersonalName(name);
                        yield return(individual);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        void ParsePerson(string id, string data, TextParserSettings parserSettings)
        {
            ParsePersonState state = ParsePersonState.Name;

            IndividualClass person = new IndividualClass();

            person.SetXrefName(id);

            int               strPos  = 0;
            string            nameStr = "";
            PersonalNameClass name    = new PersonalNameClass();

            List <SubStringInstance> subList = CheckSubstrings(id, data, parserSettings);

            foreach (SubStringInstance item in subList)
            {
                EventDataString thisType = null;

                foreach (EventDataString str in parserSettings.eventList)
                {
                    if (str.type == item.type)
                    {
                        thisType = str;
                    }
                }
                if (thisType != null)
                {
                    DecodeEvent(ref person, item.type, data.Substring(item.start + thisType.start.Length, item.end - item.start - thisType.start.Length - thisType.end.Length));
                }
            }

            while (strPos < data.Length)
            {
                //string token = GetToken(ref strPos);
                char ch = data[strPos++];


                switch (state)
                {
                case ParsePersonState.Name:
                    if (ch == '.')
                    {
                        int firstNameStart;
                        int firstNameLength;
                        int lastNameStart;
                        int lastNameLength;
                        if (nameStr.IndexOf(',') >= 0)
                        {
                            firstNameStart = nameStr.IndexOf(',') + 1;
                            while ((firstNameStart < nameStr.Length) && (nameStr[firstNameStart] == ' '))
                            {
                                firstNameStart++;
                            }
                            firstNameLength = nameStr.Length - firstNameStart;
                            lastNameStart   = 0;
                            lastNameLength  = nameStr.IndexOf(',');
                        }
                        else
                        {
                            firstNameStart = 0;
                            if (nameStr.LastIndexOf(' ') >= 0)
                            {
                                firstNameLength = nameStr.LastIndexOf(' ');
                                lastNameStart   = firstNameLength + 1;
                                lastNameLength  = nameStr.Length - firstNameLength - 1;
                            }
                            else
                            {
                                firstNameLength = nameStr.Length;
                                lastNameStart   = firstNameLength;
                                lastNameLength  = 0;
                            }
                        }

                        if (firstNameLength > 0)
                        {
                            name.SetName(PersonalNameClass.PartialNameType.GivenName, nameStr.Substring(firstNameStart, firstNameLength));
                        }
                        if (lastNameLength > 0)
                        {
                            name.SetName(PersonalNameClass.PartialNameType.BirthSurname, nameStr.Substring(lastNameStart, lastNameLength));
                        }
                        person.SetPersonalName(name);
                        state = ParsePersonState.EventToken;
                    }
                    else
                    {
                        nameStr += ch;
                    }
                    break;
                }
            }
            person.Print();
            familyTree.AddIndividual(person);
        }