Exemplo n.º 1
0
        public Name MakeTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default)
        {
            if (def.Tag == TypeTag.Group)
            {
                return(new Name(SyntaxHelpers.MakeAllLower(def.Name)));
            }
            else
            {
                string name;

                switch (usage)
                {
                case NameUsage.Default:
                    if (def.Tag == TypeTag.Interface)
                    {
                        goto case NameUsage.Interface;
                    }

                    switch (def.SpecialName)
                    {
                    case SpecialName.NothingSpecial:
                        name = def.Name;
                        break;

                    case SpecialName.MethodParamsStruct:
                        name = MakeParamsStructName(def.UsingMethod);
                        break;

                    case SpecialName.MethodResultStruct:
                        name = MakeResultStructName(def.UsingMethod);
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                    break;

                case NameUsage.Namespace:
                    name = def.Name;
                    break;

                case NameUsage.Interface:
                    name = "I" + def.Name;
                    break;

                case NameUsage.Proxy:
                    name = def.Name + "Proxy";
                    break;

                case NameUsage.Skeleton:
                    name = def.Name + "Skeleton";
                    break;

                default:
                    throw new NotImplementedException();
                }

                return(new Name(name));
            }
        }
Exemplo n.º 2
0
 private void WriteCommonBody(TextWriter writer, string submitterName, NameUsage nameUsage)
 {
     writer.WriteLine("Your Name: {0}", submitterName);
     writer.WriteLine(
         "Name Usage: {0}",
         nameUsage == NameUsage.FullName ? "You may use the full name" :
         nameUsage == NameUsage.FirstNameLastInitial ? "First Name, Last Initial" :
         nameUsage == NameUsage.FirstNameOnly ? "First Name Only" :
         "ANONYMOUS"
         );
 }
Exemplo n.º 3
0
        public Name MakeTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default)
        {
            string name;

            switch (usage)
            {
            case NameUsage.Default:
                if (def.Tag == TypeTag.Interface)
                {
                    goto case NameUsage.Interface;
                }

                switch (def.SpecialName)
                {
                case SpecialName.NothingSpecial:
                    name = GetCodeIdentifier(def);
                    break;

                case SpecialName.MethodParamsStruct:
                    name = MakeParamsStructName(def.UsingMethod);
                    break;

                case SpecialName.MethodResultStruct:
                    name = MakeResultStructName(def.UsingMethod);
                    break;

                default:
                    throw new NotImplementedException();
                }
                break;

            case NameUsage.Namespace:
                name = GetCodeIdentifier(def);
                break;

            case NameUsage.Interface:
                name = "I" + GetCodeIdentifier(def);
                break;

            case NameUsage.Proxy:
                name = string.Format(ProxyClassFormat, GetCodeIdentifier(def));
                break;

            case NameUsage.Skeleton:
                name = string.Format(SkeletonClassFormat, GetCodeIdentifier(def));
                break;

            default:
                throw new NotImplementedException();
            }

            return(new Name(name));
        }
Exemplo n.º 4
0
        public SimpleNameSyntax MakeGenericTypeNameForAttribute(TypeDefinition def, NameUsage usage)
        {
            var name = MakeTypeName(def, usage);

            if (def.GenericParameters.Count > 0)
            {
                return(GenericName(name.Identifier).AddTypeArgumentListArguments());
            }
            else
            {
                return(name.IdentifierName);
            }
        }
Exemplo n.º 5
0
        public SimpleNameSyntax MakeGenericTypeNameForAttribute(TypeDefinition def, NameUsage usage)
        {
            var name = MakeTypeName(def, usage);

            if (def.GenericParameters.Count > 0)
            {
                var args = Enumerable.Repeat(OmittedTypeArgument(), def.GenericParameters.Count);
                return(GenericName(name.Identifier).AddTypeArgumentListArguments(args.ToArray()));
            }
            else
            {
                return(name.IdentifierName);
            }
        }
Exemplo n.º 6
0
        public SimpleNameSyntax MakeGenericTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default)
        {
            var name = MakeTypeName(def, usage);

            if (def.GenericParameters.Count > 0)
            {
                return(GenericName(name.Identifier)
                       .AddTypeArgumentListArguments(def
                                                     .GenericParameters
                                                     .Select(p => GetGenericTypeParameter(p).IdentifierName).ToArray()));
            }
            else
            {
                return(name.IdentifierName);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds frequency data for a name.
        /// </summary>
        /// <param name="name">The name to add data to.</param>
        /// <param name="sex">The sex for which this data is being added.</param>
        /// <param name="year">The year in which the name was used.</param>
        /// <param name="occs">The number of times the name was used.</param>
        private void AddFrequency(Name name, Sex sex, Int32 year, Int64 occs)
        {
            // try to get the usage version of this name
            NameUsage usage = name.UsageFor(this.Culture, sex);

            // create it if it does not exist
            if (usage == null)
            {
                usage        = new NameUsage(this.Culture, sex);
                usage.NameID = name.ID;
                usage.Name   = name;

                name.Usage.Add(usage);

                this.context.Usage.Add(usage);
                this.Commit();
            }

            // try to get an existing frequency entry
            DateTime periodStart = new DateTime(year, 1, 1);
            DateTime periodEnd   = new DateTime(year, 12, 31);

            NameFrequency frequency = usage.Frequency.SingleOrDefault(x =>
                                                                      x.PeriodStart.Equals(periodStart) && x.PeriodEnd.Equals(periodEnd));

            // create it if it doesn't exist
            if (frequency == null)
            {
                frequency             = new NameFrequency(periodStart, periodEnd);
                frequency.NameUsedID  = usage.ID;
                frequency.NameUsed    = usage;
                frequency.Type        = FrequencyType.Birth;
                frequency.Occurrences = occs;

                usage.Frequency.Add(frequency);

                this.context.Frequency.Add(frequency);
                this.Commit();
            }
        }
Exemplo n.º 8
0
        public SimpleNameSyntax MakeGenericTypeName(TypeDefinition def, Model.Type boundType, NameUsage usage = NameUsage.Default)
        {
            var name = MakeTypeName(def, usage);

            if (def.GenericParameters.Count > 0)
            {
                return(GenericName(name.Identifier)
                       .AddTypeArgumentListArguments(def
                                                     .GetLocalTypeParameters()
                                                     .Select(p => ResolveGenericParameter(p, boundType, def)).ToArray()));
            }
            else
            {
                return(name.IdentifierName);
            }
        }
Exemplo n.º 9
0
 private void WriteCommonBody(TextWriter writer, string submitterName, NameUsage nameUsage)
 {
     writer.WriteLine("Your Name: {0}", submitterName);
     writer.WriteLine(
         "Name Usage: {0}",
         nameUsage == NameUsage.FullName ? "You may use the full name" :
         nameUsage == NameUsage.FirstNameLastInitial ? "First Name, Last Initial" :
         nameUsage == NameUsage.FirstNameOnly ? "First Name Only" :
         "ANONYMOUS"
     );
 }
Exemplo n.º 10
0
        /// <summary>
        /// Imports name data from <paramref name="source"/>.
        /// </summary>
        /// <param name="source">
        /// The data source to import name data from.
        /// </param>
        public void Import(INameImportSource source)
        {
            this.InitContext();

            // read from the input source until that's no longer possible
            while(source.Read())
            {
                // try to load the field values from the current row
                String nameStr = this.GetField(source, NameProperty.Name);
                String maleOccsStr = this.GetField(source, NameProperty.MaleOccurrences);
                String femaleOccsStr = this.GetField(source, NameProperty.FemaleOccurrences);
                String yearStr = this.GetField(source, NameProperty.Year);
                String surnameStr = this.GetField(source, NameProperty.Surname);

                // set some default values
                Int32 year = this.DefaultYear; 
                Int64 maleOccs = 0;
                Int64 femaleOccs = 0;

                // try to parse field data, if available
                if(!String.IsNullOrWhiteSpace(maleOccsStr))
                    maleOccs = Int64.Parse(maleOccsStr, NumberStyles.AllowThousands);
                if(!String.IsNullOrWhiteSpace(femaleOccsStr))
                    femaleOccs = Int64.Parse(femaleOccsStr, NumberStyles.AllowThousands);
                if(!String.IsNullOrWhiteSpace(yearStr))
                    year = Convert.ToInt32(yearStr);

                if (!String.IsNullOrWhiteSpace(surnameStr))
                {
                    surnameStr = surnameStr.Trim();

                    if (this.onProcessing != null)
                        this.onProcessing(this.entries, surnameStr);

                    // try to find an existing entry for this name in the database
                    Name name = this.FindOrCreateName(surnameStr);

                    NameUsage familyUsage = name.UsageFor(this.Culture, true);

                    if(familyUsage == null)
                    {
                        familyUsage = new NameUsage(this.Culture, Sex.NotApplicable);
                        familyUsage.FamilyName = true;
                        familyUsage.NameID = name.ID;
                        familyUsage.Name = name;

                        name.Usage.Add(familyUsage);

                        this.context.Usage.Add(familyUsage);
                        this.Commit();
                    }
                }

                if (!String.IsNullOrWhiteSpace(nameStr))
                {
                    nameStr = nameStr.Trim();

                    if (this.onProcessing != null)
                        this.onProcessing(this.entries, nameStr);

                    // try to find an existing entry for this name in the database
                    Name name = this.FindOrCreateName(nameStr);

                    // add usage and frequency data for the current name
                    if (maleOccs > 0)
                    {
                        this.AddFrequency(name, Sex.Male, year, maleOccs);
                    }
                    if (femaleOccs > 0)
                    {
                        this.AddFrequency(name, Sex.Female, year, femaleOccs);
                    }

                    // update the static probabilities for the current name
                    foreach (NameUsage usage in name.Usage)
                    {
                        usage.RecalculateProbability();
                    }

                    entries++;
                }
            }

            // save all remaining changes
            context.SaveChanges();
            context.Dispose();
            context = null;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Adds frequency data for a name.
        /// </summary>
        /// <param name="name">The name to add data to.</param>
        /// <param name="sex">The sex for which this data is being added.</param>
        /// <param name="year">The year in which the name was used.</param>
        /// <param name="occs">The number of times the name was used.</param>
        private void AddFrequency(Name name, Sex sex, Int32 year, Int64 occs)
        {
            // try to get the usage version of this name
            NameUsage usage = name.UsageFor(this.Culture, sex);

            // create it if it does not exist
            if (usage == null)
            {
                usage = new NameUsage(this.Culture, sex);
                usage.NameID = name.ID;
                usage.Name = name;

                name.Usage.Add(usage);

                this.context.Usage.Add(usage);
                this.Commit();
            }

            // try to get an existing frequency entry
            DateTime periodStart = new DateTime(year, 1, 1);
            DateTime periodEnd = new DateTime(year, 12, 31);

            NameFrequency frequency = usage.Frequency.SingleOrDefault(x =>
                x.PeriodStart.Equals(periodStart) && x.PeriodEnd.Equals(periodEnd));

            // create it if it doesn't exist
            if (frequency == null)
            {
                frequency = new NameFrequency(periodStart, periodEnd);
                frequency.NameUsedID = usage.ID;
                frequency.NameUsed = usage;
                frequency.Type = FrequencyType.Birth;
                frequency.Occurrences = occs;

                usage.Frequency.Add(frequency);

                this.context.Frequency.Add(frequency);
                this.Commit();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Imports name data from <paramref name="source"/>.
        /// </summary>
        /// <param name="source">
        /// The data source to import name data from.
        /// </param>
        public void Import(INameImportSource source)
        {
            this.InitContext();

            // read from the input source until that's no longer possible
            while (source.Read())
            {
                // try to load the field values from the current row
                String nameStr       = this.GetField(source, NameProperty.Name);
                String maleOccsStr   = this.GetField(source, NameProperty.MaleOccurrences);
                String femaleOccsStr = this.GetField(source, NameProperty.FemaleOccurrences);
                String yearStr       = this.GetField(source, NameProperty.Year);
                String surnameStr    = this.GetField(source, NameProperty.Surname);

                // set some default values
                Int32 year       = this.DefaultYear;
                Int64 maleOccs   = 0;
                Int64 femaleOccs = 0;

                // try to parse field data, if available
                if (!String.IsNullOrWhiteSpace(maleOccsStr))
                {
                    maleOccs = Int64.Parse(maleOccsStr, NumberStyles.AllowThousands);
                }
                if (!String.IsNullOrWhiteSpace(femaleOccsStr))
                {
                    femaleOccs = Int64.Parse(femaleOccsStr, NumberStyles.AllowThousands);
                }
                if (!String.IsNullOrWhiteSpace(yearStr))
                {
                    year = Convert.ToInt32(yearStr);
                }

                if (!String.IsNullOrWhiteSpace(surnameStr))
                {
                    surnameStr = surnameStr.Trim();

                    if (this.onProcessing != null)
                    {
                        this.onProcessing(this.entries, surnameStr);
                    }

                    // try to find an existing entry for this name in the database
                    Name name = this.FindOrCreateName(surnameStr);

                    NameUsage familyUsage = name.UsageFor(this.Culture, true);

                    if (familyUsage == null)
                    {
                        familyUsage            = new NameUsage(this.Culture, Sex.NotApplicable);
                        familyUsage.FamilyName = true;
                        familyUsage.NameID     = name.ID;
                        familyUsage.Name       = name;

                        name.Usage.Add(familyUsage);

                        this.context.Usage.Add(familyUsage);
                        this.Commit();
                    }
                }

                if (!String.IsNullOrWhiteSpace(nameStr))
                {
                    nameStr = nameStr.Trim();

                    if (this.onProcessing != null)
                    {
                        this.onProcessing(this.entries, nameStr);
                    }

                    // try to find an existing entry for this name in the database
                    Name name = this.FindOrCreateName(nameStr);

                    // add usage and frequency data for the current name
                    if (maleOccs > 0)
                    {
                        this.AddFrequency(name, Sex.Male, year, maleOccs);
                    }
                    if (femaleOccs > 0)
                    {
                        this.AddFrequency(name, Sex.Female, year, femaleOccs);
                    }

                    // update the static probabilities for the current name
                    foreach (NameUsage usage in name.Usage)
                    {
                        usage.RecalculateProbability();
                    }

                    entries++;
                }
            }

            // save all remaining changes
            context.SaveChanges();
            context.Dispose();
            context = null;
        }