예제 #1
0
        public PopulationDataEntry FindByCode(Int32 code)
        {
            PopulationDataEntry retval = null;

            if (this.Geocode == code)
            {
                retval = this;
            }
            else
            {
                retval = SubEntities.FirstOrDefault(entry => (entry != null) && (entry.Geocode == code));
                if (retval == null)
                {
                    SubEntities.ForEach(delegate(PopulationDataEntry entity)
                    {
                        if ((retval == null) && (entity != null))
                        {
                            if (TambonHelper.IsBaseGeocode(entity.Geocode, code))
                            {
                                retval = entity.FindByCode(code);
                            }
                        }
                    });
                }
            }
            return(retval);
        }
예제 #2
0
 /// <summary>
 /// Sort the sub entity list by the geocode recursively.
 /// </summary>
 public void SortSubEntitiesByGeocode()
 {
     _subEntities = SubEntities.OrderBy(p => p.Geocode).ToList();
     foreach (var entry in SubEntities)
     {
         entry.SortSubEntitiesByGeocode();
     }
 }
예제 #3
0
 /// <summary>
 /// Sort the sub entity list by the english name recursively.
 /// </summary>
 public void SortSubEntitiesByEnglishName()
 {
     _subEntities = SubEntities.OrderBy(p => p.English).ToList();
     foreach (var entry in SubEntities)
     {
         entry.SortSubEntitiesByEnglishName();
     }
 }
        protected override void FindTest()
        {
            // Arrange
            var count = SubEntities.Count(entity => entity.ResultCheckBox.HasValue && entity.ResultCheckBox.Value);

            // Act
            var actual = SubItemRepository.Find(x => x.ResultCheckBox.Value).ToList();

            // Assert
            Assert.IsTrue(actual.Count == count);
        }
예제 #5
0
        protected void CreateItemsTest()
        {
            // Arrange
            var listToAdd = SubEntities.GetRange(1, 3);

            // Act
            SubItemRepository.AddRange(listToAdd);
            var actual = UnitOfWork.SaveChanges();

            // Assert
            Assert.AreEqual(EntityCount * 3, actual);
        }
예제 #6
0
        /// <summary>
        /// Deletes the sub-entities specified by name(s) passed in method's parameter(s).
        /// </summary>
        /// <param name="namesToDelete">The names of the entities to delete.</param>
        /// <returns>The amount of deleted entities</returns>
        public int DeleteSubEntities(params string[] namesToDelete)
        {
            int count = 0;

            for (int i = SubEntities.Count - 1; i >= 0; i--)
            {
                if (namesToDelete.Contains(SubEntities[i].Name))
                {
                    SubEntities.RemoveAt(i);
                    count++;
                }
            }
            return(count);
        }
예제 #7
0
        /// <summary>
        /// Deletes the sub-entities.
        /// </summary>
        /// <param name="entityToDeleteFilter">The "filter" function that returns <c>true</c> if the entity should be removed</param>
        /// <returns>The amount of deleted entities</returns>
        public virtual int DeleteSubEntities(Func <MetaEntity, bool> entityToDeleteFilter)
        {
            int count = 0;

            for (int i = SubEntities.Count - 1; i >= 0; i--)
            {
                if (entityToDeleteFilter.Invoke(SubEntities[i]))
                {
                    SubEntities.RemoveAt(i);
                    count++;
                }
            }
            return(count);
        }
예제 #8
0
        public Boolean CanWriteForWikipedia()
        {
            Boolean lResult = EntityTypeHelper.IsCompatibleEntityType(Type, EntityType.Amphoe);

            if (Type == EntityType.Tambon)
            {
                lResult = SubEntities.Find(
                    delegate(PopulationDataEntry lEntry)
                {
                    return(lEntry.Type == EntityType.Muban);
                }) != null;
            }
            return(lResult);
        }
예제 #9
0
 internal AlignmentMultipleSegments(C3dDb.AlignmentMultipleSegments mseg)
     : base(mseg)
 {
     for (int i = 0; i < mseg.SubEntityCount; i++)
     {
         C3dDb.AlignmentSubEntity curve = mseg[i];
         if (curve is C3dDb.AlignmentSubEntityLine line)
         {
             SubEntities.Add(new AlignmentLine(line));
         }
         else if (curve is C3dDb.AlignmentSubEntityArc arc)
         {
             SubEntities.Add(new AlignmentArc(arc));
         }
     }
 }
예제 #10
0
        /// <summary>
        /// Writes the content of the entity to JSON (asynchronious way)
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="options">Some read/write options.</param>
        /// <param name="ct">The cancellation token.</param>
        /// <returns>Task.</returns>
        public async Task WriteToJsonAsync(JsonWriter writer, BitOptions options, CancellationToken ct = default)
        {
            await writer.WriteStartObjectAsync(ct).ConfigureAwait(false);

            await WritePropertiesToJsonAsync(writer, ct).ConfigureAwait(false);

            await writer.WritePropertyNameAsync("attrs", ct).ConfigureAwait(false);

            await Attributes.WriteToJsonAsync(writer, options, ct).ConfigureAwait(false);

            if (SubEntities.Count > 0)
            {
                await writer.WritePropertyNameAsync("ents", ct).ConfigureAwait(false);

                await SubEntities.WriteToJsonAsync(writer, options, ct).ConfigureAwait(false);
            }

            await writer.WriteEndObjectAsync(ct).ConfigureAwait(false);
        }
예제 #11
0
        /// <summary>
        /// Writes the content of the entity to JSON (asynchronious way)
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="options">Some read/write options.</param>
        /// <returns>Task.</returns>
        public async Task WriteToJsonAsync(JsonWriter writer, BitOptions options)
        {
            await writer.WriteStartObjectAsync().ConfigureAwait(false);

            await WritePropertiesToJsonAsync(writer).ConfigureAwait(false);

            await writer.WritePropertyNameAsync("attrs").ConfigureAwait(false);

            await Attributes.WriteToJsonAsync(writer, options).ConfigureAwait(false);

            if (SubEntities.Count > 0)
            {
                await writer.WritePropertyNameAsync("ents").ConfigureAwait(false);

                await SubEntities.WriteToJsonAsync(writer, options).ConfigureAwait(false);
            }

            await writer.WriteEndObjectAsync().ConfigureAwait(false);
        }
예제 #12
0
        public PopulationDataEntry(PopulationDataEntry value)
        {
            Type       = value.Type;
            Total      = value.Total;
            Male       = value.Male;
            Female     = value.Female;
            Households = value.Households;
            English    = value.English;
            Geocode    = value.Geocode;
            Obsolete   = value.Obsolete;
            Name       = value.Name;
            Comment    = value.Comment;

            foreach (Int32 lGeocode in value.mNewGeocode)
            {
                mNewGeocode.Add(lGeocode);
            }
            foreach (Int32 lGeocode in value.mGeocodeParent)
            {
                mGeocodeParent.Add(lGeocode);
            }
            foreach (PopulationDataEntry lSubEntity in value.SubEntities)
            {
                if (lSubEntity != null)
                {
                    SubEntities.Add((PopulationDataEntry)lSubEntity.Clone());
                }
            }
            foreach (EntityOffice lOffice in value.Offices)
            {
                Offices.Add((EntityOffice)lOffice.Clone());
            }
            foreach (String lOldName in value.OldNames)
            {
                mOldNames.Add(lOldName);
            }
            foreach (ConstituencyEntry lEntry in value.ConstituencyList)
            {
                ConstituencyList.Add((ConstituencyEntry)lEntry.Clone());
            }
        }
예제 #13
0
        private PopulationDataEntry FindByNameAndType(String iValue, EntityType iEntityType, Boolean iAllowOldNames, Boolean iAllowObsolete, Int32 iPosition)
        {
            PopulationDataEntry retval = null;

            SubEntities.Sort(
                delegate(PopulationDataEntry a, PopulationDataEntry b)
            {
                return(a.Geocode.CompareTo(b.Geocode));
            }
                );

            foreach (PopulationDataEntry lEntity in SubEntities)
            {
                if (lEntity.SameNameAndType(iValue, iEntityType))
                {
                    if ((!lEntity.IsObsolete()) | iAllowObsolete)
                    {
                        iPosition--;
                        if (iPosition < 0)
                        {
                            retval = lEntity;
                            break;
                        }
                    }
                }
                if (iAllowOldNames & (lEntity.OldNames.Contains(iValue)) & (EntityTypeHelper.IsCompatibleEntityType(lEntity.Type, iEntityType)))
                {
                    if ((!lEntity.IsObsolete()) | iAllowObsolete)
                    {
                        iPosition--;
                        if (iPosition < 0)
                        {
                            retval = lEntity;
                            break;
                        }
                    }
                }
            }
            return(retval);
        }
예제 #14
0
        protected void DeleteRangeTest(string propertyName)
        {
            // Arrange
            var itemsToDelete = SubEntities.GetRange(1, 2);
            var valueToMatch1 = typeof(TSubEntity).GetProperty(propertyName)?.GetValue(SubEntities[1]);
            var valueToMatch2 = typeof(TSubEntity).GetProperty(propertyName)?.GetValue(SubEntities[2]);
            var valueToMatch3 = typeof(TSubEntity).GetProperty(propertyName)?.GetValue(SubEntities[3]);

            // Act
            SubItemRepository.RemoveRange(itemsToDelete);
            var actual         = UnitOfWork.SaveChanges();
            var remainingItems = SubItemRepository.GetAll().ToList();
            var found1         = false;
            var found2         = false;
            var found3         = false;

            foreach (var remainingItem in remainingItems)
            {
                var value = typeof(TSubEntity).GetProperty(propertyName)?.GetValue(remainingItem);
                if (value != null && value.Equals(valueToMatch1))
                {
                    found1 = true;
                }
                if (value != null && value.Equals(valueToMatch2))
                {
                    found2 = true;
                }
                if (value != null && value.Equals(valueToMatch3))
                {
                    found3 = true;
                }
            }

            // Assert
            Assert.AreEqual(2, actual);
            Assert.IsFalse(found1);
            Assert.IsFalse(found2);
            Assert.IsTrue(found3);
        }
예제 #15
0
        /// <summary>Reads the entity content from JSON (asynchronous way).</summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Task.</returns>
        /// <exception cref="BadJsonFormatException"></exception>
        public async Task ReadFromJsonAsync(JsonReader reader)
        {
            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new BadJsonFormatException(reader.Path);
            }

            Attributes.Clear();
            SubEntities.Clear();

            while ((await reader.ReadAsync().ConfigureAwait(false)) &&
                   reader.TokenType != JsonToken.EndObject)
            {
                if (reader.TokenType != JsonToken.PropertyName)
                {
                    throw new BadJsonFormatException(reader.Path);
                }

                var propName = reader.Value.ToString();
                if (propName == "attrs")
                {
                    await reader.ReadAsync().ConfigureAwait(false); //reading first StartArray token

                    await Attributes.ReadFromJsonAsync(reader).ConfigureAwait(false);
                }
                else if (propName == "ents")
                {
                    await reader.ReadAsync().ConfigureAwait(false); //reading first StartArray token

                    await SubEntities.ReadFromJsonAsync(reader).ConfigureAwait(false);
                }
                else
                {
                    await ReadOnePropertyFromJsonAsync(reader, propName).ConfigureAwait(false);
                }
            }
        }
예제 #16
0
 public ContextSubEntity GetSubEntity(SubEntityBindingPointCategoryEnum category)
 {
     return(SubEntities.Find(x => x.Category == category));
 }
예제 #17
0
 public EntityLook ToEntityLook()
 {
     return(new EntityLook(BonesId, Skins.ToArray(), Colors.ToArray(), Scales.ToArray(), SubEntities.ConvertAll <SubEntity>(x => x.ToSubEntity()).ToArray()));
 }