Inheritance: RepositoryFactory
Esempio n. 1
0
        protected ManyToManyTestData CreateIdentifiableManyToManyData()
        {
            List <Tag> tagsSubset = TagFaker.Generate(3);
            List <IdentifiableArticleTag> joinsSubSet = _identifiableArticleTagFaker.Generate(3);
            Article articleTagsSubset = ArticleFaker.Generate();

            articleTagsSubset.IdentifiableArticleTags = joinsSubSet.ToHashSet();

            for (int index = 0; index < 3; index++)
            {
                joinsSubSet[index].Article = articleTagsSubset;
                joinsSubSet[index].Tag     = tagsSubset[index];
            }

            List <Tag> allTags = TagFaker.Generate(3).Concat(tagsSubset).ToList();
            List <IdentifiableArticleTag> completeJoin = _identifiableArticleTagFaker.Generate(6);

            Article articleWithAllTags = ArticleFaker.Generate();

            articleWithAllTags.IdentifiableArticleTags = joinsSubSet.ToHashSet();

            for (int index = 0; index < 6; index++)
            {
                completeJoin[index].Article = articleWithAllTags;
                completeJoin[index].Tag     = allTags[index];
            }

            List <IdentifiableArticleTag> allJoins = joinsSubSet.Concat(completeJoin).ToList();
            List <Article> articles = ArrayFactory.Create(articleTagsSubset, articleWithAllTags).ToList();

            return(new ManyToManyTestData(articles, allJoins, allTags));
        }
Esempio n. 2
0
        /// <inheritdoc />
        public EntityTagHeaderValue Generate(string requestUrl, string responseBody)
        {
            string fingerprint = _fingerprintGenerator.Generate(ArrayFactory.Create(requestUrl, responseBody));
            string eTagValue   = "\"" + fingerprint + "\"";

            return(EntityTagHeaderValue.Parse(eTagValue));
        }
Esempio n. 3
0
        protected (List <Article>, List <IdentifiableArticleTag>, List <Tag>) CreateIdentifiableManyToManyData()
        {
            var tagsSubset        = TagFaker.Generate(3);
            var joinsSubSet       = _identifiableArticleTagFaker.Generate(3);
            var articleTagsSubset = ArticleFaker.Generate();

            articleTagsSubset.IdentifiableArticleTags = joinsSubSet.ToHashSet();
            for (int i = 0; i < 3; i++)
            {
                joinsSubSet[i].Article = articleTagsSubset;
                joinsSubSet[i].Tag     = tagsSubset[i];
            }
            var allTags      = TagFaker.Generate(3).Concat(tagsSubset).ToList();
            var completeJoin = _identifiableArticleTagFaker.Generate(6);

            var articleWithAllTags = ArticleFaker.Generate();

            articleWithAllTags.IdentifiableArticleTags = joinsSubSet.ToHashSet();

            for (int i = 0; i < 6; i++)
            {
                completeJoin[i].Article = articleWithAllTags;
                completeJoin[i].Tag     = allTags[i];
            }

            var allJoins = joinsSubSet.Concat(completeJoin).ToList();
            var articles = ArrayFactory.Create(articleTagsSubset, articleWithAllTags).ToList();

            return(articles, allJoins, allTags);
        }
Esempio n. 4
0
        /// <summary>
        /// Extracts the resources for the current layer by going through all populated relationships of the (left resources of the previous layer.
        /// </summary>
        private (Dictionary <RelationshipProxy, List <IIdentifiable> >, Dictionary <RelationshipProxy, List <IIdentifiable> >) ExtractResources(
            IEnumerable <IResourceNode> leftNodes)
        {
            // RelationshipAttr_prevLayer->currentLayer  => prevLayerResources
            var leftResourcesGrouped = new Dictionary <RelationshipProxy, List <IIdentifiable> >();

            // RelationshipAttr_prevLayer->currentLayer  => currentLayerResources
            var rightResourcesGrouped = new Dictionary <RelationshipProxy, List <IIdentifiable> >();

            foreach (IResourceNode node in leftNodes)
            {
                IEnumerable leftResources = node.UniqueResources;
                IReadOnlyCollection <RelationshipProxy> relationships = node.RelationshipsToNextLayer;

                ExtractLeftResources(leftResources, relationships, rightResourcesGrouped, leftResourcesGrouped);
            }

            MethodInfo processResourcesMethod = GetType().GetMethod(nameof(ProcessResources), BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (KeyValuePair <RelationshipProxy, List <IIdentifiable> > pair in rightResourcesGrouped)
            {
                RightType type = pair.Key.RightType;
                IList     list = CollectionConverter.CopyToList(pair.Value, type);
                processResourcesMethod !.MakeGenericMethod(type).Invoke(this, ArrayFactory.Create <object>(list));
            }

            return(leftResourcesGrouped, rightResourcesGrouped);
        }
Esempio n. 5
0
        private (List <Article>, List <Tag>) CreateDummyData()
        {
            var tagsSubset        = TagFaker.Generate(3);
            var joinsSubSet       = ArticleTagFaker.Generate(3);
            var articleTagsSubset = ArticleFaker.Generate();

            articleTagsSubset.ArticleTags = joinsSubSet.ToHashSet();
            for (int i = 0; i < 3; i++)
            {
                joinsSubSet[i].Article = articleTagsSubset;
                joinsSubSet[i].Tag     = tagsSubset[i];
            }

            var allTags      = TagFaker.Generate(3).Concat(tagsSubset).ToList();
            var completeJoin = ArticleTagFaker.Generate(6);

            var articleWithAllTags = ArticleFaker.Generate();

            articleWithAllTags.ArticleTags = completeJoin.ToHashSet();

            for (int i = 0; i < 6; i++)
            {
                completeJoin[i].Article = articleWithAllTags;
                completeJoin[i].Tag     = allTags[i];
            }

            var articles = ArrayFactory.Create(articleTagsSubset, articleWithAllTags).ToList();

            return(articles, allTags);
        }
Esempio n. 6
0
        public void CanGenerateMultiDimensionArray()
        {
            int fixedValue = 9;

            var factoryMock = new Mock<IFactory<int>>();
            factoryMock.Setup(f => f.Generate()).Returns(fixedValue);
            int[] dimension = new[] { 5,2,3,8,9};
            var arrayFactory = new ArrayFactory<int>(factoryMock.Object, dimension);
            var result =arrayFactory.Generate() as int[,,,,];

            bool anyDiff = false;

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        for (int l = 0; l < 8; l++)
                        {
                            for (int m = 0; m < 9; m++)
                            {
                                if (result[i,j,k,l,m] != fixedValue)
                                    anyDiff = true;
                            }
                        }
                    }
                }
            }

            Assert.False(anyDiff);
        }
Esempio n. 7
0
        /// <summary>
        /// Given a source of resources, gets the implicitly affected resources from the database and calls the BeforeImplicitUpdateRelationship hook.
        /// </summary>
        private void FireForAffectedImplicits(Type resourceTypeToInclude, IDictionary <RelationshipAttribute, IEnumerable> implicitsTarget,
                                              ResourcePipeline pipeline, IEnumerable existingImplicitResources = null)
        {
            IResourceHookContainer container =
                _containerProvider.GetResourceHookContainer(resourceTypeToInclude, ResourceHook.BeforeImplicitUpdateRelationship);

            if (container == null)
            {
                return;
            }

            IDictionary <RelationshipAttribute, IEnumerable> implicitAffected =
                _containerProvider.LoadImplicitlyAffected(implicitsTarget, existingImplicitResources);

            if (!implicitAffected.Any())
            {
                return;
            }

            Dictionary <RelationshipAttribute, IEnumerable> inverse = new Dictionary <RelationshipAttribute, IEnumerable>();

            foreach (KeyValuePair <RelationshipAttribute, IEnumerable> pair in implicitAffected)
            {
                var inverseRelationship = _resourceGraph.GetInverseRelationship(pair.Key);
                if (inverseRelationship != null)
                {
                    inverse.Add(inverseRelationship, pair.Value);
                }
            }

            IRelationshipsDictionary resourcesByRelationship = CreateRelationshipHelper(resourceTypeToInclude, inverse);

            CallHook(container, ResourceHook.BeforeImplicitUpdateRelationship, ArrayFactory.Create <object>(resourcesByRelationship, pipeline));
        }
Esempio n. 8
0
        private Expression ExtensionMethodCall(Expression source, string operationName, Type keyType,
                                               LambdaExpression keySelector)
        {
            var typeArguments = ArrayFactory.Create(LambdaScope.Parameter.Type, keyType);

            return(Expression.Call(_extensionType, operationName, typeArguments, source, keySelector));
        }
        /// <summary>
        /// This method creates a new instance of class <see cref="Beam{TProfile}"/>.
        /// This is a step to create the input fot finite element analysis.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="degreesOfFreedom"></param>
        /// <returns>A new instance of class <see cref="Beam{TProfile}"/>.</returns>
        public override async Task <Beam <TProfile> > BuildBeam(BeamRequest <TProfile> request, uint degreesOfFreedom)
        {
            GeometricProperty geometricProperty = new GeometricProperty();

            if (request.Profile.Area != null && request.Profile.MomentOfInertia != null)
            {
                geometricProperty.Area = await ArrayFactory.CreateVectorAsync(request.Profile.Area.Value, request.NumberOfElements).ConfigureAwait(false);

                geometricProperty.MomentOfInertia = await ArrayFactory.CreateVectorAsync(request.Profile.MomentOfInertia.Value, request.NumberOfElements).ConfigureAwait(false);
            }
            else
            {
                geometricProperty.Area = await this._geometricProperty.CalculateArea(request.Profile, request.NumberOfElements).ConfigureAwait(false);

                geometricProperty.MomentOfInertia = await this._geometricProperty.CalculateMomentOfInertia(request.Profile, request.NumberOfElements).ConfigureAwait(false);
            }

            var beam = new Beam <TProfile>()
            {
                Fastenings        = await this._mappingResolver.BuildFastenings(request.Fastenings).ConfigureAwait(false),
                Forces            = await this._mappingResolver.BuildForceVector(request.Forces, degreesOfFreedom).ConfigureAwait(false),
                GeometricProperty = geometricProperty,
                Length            = request.Length,
                Material          = MaterialFactory.Create(request.Material),
                NumberOfElements  = request.NumberOfElements,
                Profile           = request.Profile
            };

            return(beam);
        }
Esempio n. 10
0
        /// <summary>
        /// Extracts the resources for the current layer by going through all populated relationships
        /// of the (left resources of the previous layer.
        /// </summary>
        private (Dictionary <RelationshipProxy, List <IIdentifiable> >, Dictionary <RelationshipProxy, List <IIdentifiable> >) ExtractResources(IEnumerable <IResourceNode> leftNodes)
        {
            // RelationshipAttr_prevLayer->currentLayer  => prevLayerResources
            var leftResourcesGrouped = new Dictionary <RelationshipProxy, List <IIdentifiable> >();

            // RelationshipAttr_prevLayer->currentLayer  => currentLayerResources
            var rightResourcesGrouped = new Dictionary <RelationshipProxy, List <IIdentifiable> >();

            foreach (var node in leftNodes)
            {
                var leftResources = node.UniqueResources;
                var relationships = node.RelationshipsToNextLayer;

                ExtractLeftResources(leftResources, relationships, rightResourcesGrouped, leftResourcesGrouped);
            }

            var processResourcesMethod = GetType().GetMethod(nameof(ProcessResources), BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (var kvp in rightResourcesGrouped)
            {
                var type = kvp.Key.RightType;
                var list = TypeHelper.CopyToList(kvp.Value, type);
                processResourcesMethod !.MakeGenericMethod(type).Invoke(this, ArrayFactory.Create <object>(list));
            }

            return(leftResourcesGrouped, rightResourcesGrouped);
        }
Esempio n. 11
0
        public T CreateMockObject()
        {
            IFactory <T> factory = null;

            if (typeof(T).IsPrimitive || typeof(T) == typeof(string) || typeof(T) == typeof(decimal))
            {
                factory = new PrimitiveFactory <T>();
            }
            else if (typeof(T).IsArray)
            {
                factory = new ArrayFactory <T>();
            }
            else if (typeof(IEnumerable).IsAssignableFrom(typeof(T)))
            {
                factory = new CollectionFactory <T>();
            }
            else if (typeof(T).IsClass && typeof(T) != typeof(string))
            {
                factory = new ClassFactory <T>();
            }
            else if (typeof(T).IsValueType)
            {
                factory = null; //TODO: Handle structs
            }

            return(factory.Create());
        }
Esempio n. 12
0
 public static Generator <Accumulator <T, T[]> > ToArrayAccumulatable <T>(ArrayFactory <T> factory)
 {
     return(delegate()
     {
         return new ArrayAccumulator <T>(factory, new System.Collections.Generic.List <T>());
     });
 }
Esempio n. 13
0
        private FilterExpression CreateFilterByIds <TId>(ICollection <TId> ids, AttrAttribute idAttribute, FilterExpression existingFilter)
        {
            var idChain = new ResourceFieldChainExpression(idAttribute);

            FilterExpression filter = null;

            if (ids.Count == 1)
            {
                var constant = new LiteralConstantExpression(ids.Single().ToString());
                filter = new ComparisonExpression(ComparisonOperator.Equals, idChain, constant);
            }
            else if (ids.Count > 1)
            {
                var constants = ids.Select(id => new LiteralConstantExpression(id.ToString())).ToList();
                filter = new EqualsAnyOfExpression(idChain, constants);
            }

            // @formatter:keep_existing_linebreaks true

            return(filter == null
                ? existingFilter
                : existingFilter == null
                    ? filter
                    : new LogicalExpression(LogicalOperator.And, ArrayFactory.Create(filter, existingFilter)));

            // @formatter:keep_existing_linebreaks restore
        }
Esempio n. 14
0
        private (List <Article>, List <Tag>) CreateDummyData()
        {
            List <Tag>        tagsSubset        = TagFaker.Generate(3);
            List <ArticleTag> joinsSubSet       = ArticleTagFaker.Generate(3);
            Article           articleTagsSubset = ArticleFaker.Generate();

            articleTagsSubset.ArticleTags = joinsSubSet.ToHashSet();

            for (int index = 0; index < 3; index++)
            {
                joinsSubSet[index].Article = articleTagsSubset;
                joinsSubSet[index].Tag     = tagsSubset[index];
            }

            List <Tag>        allTags      = TagFaker.Generate(3).Concat(tagsSubset).ToList();
            List <ArticleTag> completeJoin = ArticleTagFaker.Generate(6);

            Article articleWithAllTags = ArticleFaker.Generate();

            articleWithAllTags.ArticleTags = completeJoin.ToHashSet();

            for (int index = 0; index < 6; index++)
            {
                completeJoin[index].Article = articleWithAllTags;
                completeJoin[index].Tag     = allTags[index];
            }

            List <Article> articles = ArrayFactory.Create(articleTagsSubset, articleWithAllTags).ToList();

            return(articles, allTags);
        }
Esempio n. 15
0
 public static Generator <Accumulator <T, T[]> > ToArrayAccumulatable <T>(
     T initial_value, ArrayFactory <T> factory)
 {
     return(delegate()
     {
         List <T> list = new System.Collections.Generic.List <T>();
         list.Add(initial_value);
         return new ArrayAccumulator <T>(factory, list);
     });
 }
Esempio n. 16
0
        /// <summary>
        /// Fires the AfterUpdateRelationship hook
        /// </summary>
        private void FireAfterUpdateRelationship(IResourceHookContainer container, IResourceNode node, ResourcePipeline pipeline)
        {
            Dictionary <RelationshipAttribute, IEnumerable> currentResourcesGrouped = node.RelationshipsFromPreviousLayer.GetRightResources();
            // the relationships attributes in currentResourcesGrouped will be pointing from a
            // resource in the previous layer to a resource in the current (nested) layer.
            // For the nested hook we need to replace these attributes with their inverse.
            // See the FireNestedBeforeUpdateHooks method for a more detailed example.
            var resourcesByRelationship = CreateRelationshipHelper(node.ResourceType, ReplaceKeysWithInverseRelationships(currentResourcesGrouped));

            CallHook(container, ResourceHook.AfterUpdateRelationship, ArrayFactory.Create <object>(resourcesByRelationship, pipeline));
        }
Esempio n. 17
0
        public void ResourceToDocument_ResourceList_CanBuild()
        {
            // Arrange
            DummyResource[] resources = ArrayFactory.Create(new DummyResource(), new DummyResource());

            // Act
            Document document = _builder.PublicBuild(resources);
            var      data     = (List <ResourceObject>)document.Data;

            // Assert
            Assert.Equal(2, data.Count);
        }
Esempio n. 18
0
        public override FilterExpression OnApplyFilter(FilterExpression existingFilter)
        {
            var resourceContext        = _resourceGraph.GetResourceContext <TResource>();
            var isSoftDeletedAttribute = resourceContext.Attributes.Single(attribute => attribute.Property.Name == nameof(ISoftDeletable.IsSoftDeleted));

            var isNotSoftDeleted = new ComparisonExpression(ComparisonOperator.Equals,
                                                            new ResourceFieldChainExpression(isSoftDeletedAttribute), new LiteralConstantExpression("false"));

            return(existingFilter == null
                ? (FilterExpression)isNotSoftDeleted
                : new LogicalExpression(LogicalOperator.And, ArrayFactory.Create(isNotSoftDeleted, existingFilter)));
        }
Esempio n. 19
0
        /// <inheritdoc />
        public void AfterRead <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline) where TResource : class, IIdentifiable
        {
            if (GetHook(ResourceHook.AfterRead, resources, out var container, out var node))
            {
                container.AfterRead((HashSet <TResource>)node.UniqueResources, pipeline);
            }

            Traverse(_traversalHelper.CreateNextLayer(node), ResourceHook.AfterRead, (nextContainer, nextNode) =>
            {
                CallHook(nextContainer, ResourceHook.AfterRead, ArrayFactory.Create <object>(nextNode.UniqueResources, pipeline, true));
            });
        }
Esempio n. 20
0
        public ArrayFactoryShould()
        {
            _engine = new Mock <IDependencyEngine>();

            _elementType    = typeof(Boo);
            _arrayType      = _elementType.MakeArrayType();
            _enumerableType = typeof(IEnumerable <>).MakeGenericType(_elementType);
            _services       = Mock.Of <IServiceProvider>();

            _factory = new ArrayFactory();

            SetupApplicableDependencies(_engine, _elementType);
        }
Esempio n. 21
0
        private SparseFieldSetExpression GetSparseFieldSet(string parameterValue, ResourceContext resourceContext)
        {
            SparseFieldSetExpression sparseFieldSet = _sparseFieldSetParser.Parse(parameterValue, resourceContext);

            if (sparseFieldSet == null)
            {
                // We add ID on an incoming empty fieldset, so that callers can distinguish between no fieldset and an empty one.
                AttrAttribute idAttribute = resourceContext.Attributes.Single(attribute => attribute.Property.Name == nameof(Identifiable.Id));
                return(new SparseFieldSetExpression(ArrayFactory.Create(idAttribute)));
            }

            return(sparseFieldSet);
        }
Esempio n. 22
0
        public void test_GetObject()
        {
            ArrayFactory arrayFactory = new ArrayFactory();

            arrayFactory.ElementType = typeof(string);
            arrayFactory.Elements    = new string[] { "a", "b" };

            Assert.AreEqual(arrayFactory.GetObjectType(), typeof(string[]), "GetObjectType failed");
            string[] obj = arrayFactory.GetObject() as string[];
            Assert.AreEqual(obj.Length, 2, "Invalid result object");
            Assert.AreEqual(obj[0], "a", "Invalid first element of result object");
            Assert.AreEqual(obj[1], "b", "Invalid second element of result object");
        }
Esempio n. 23
0
        public IEnumerable LoadDbValues(LeftType resourceTypeForRepository, IEnumerable resources, params RelationshipAttribute[] relationshipsToNextLayer)
        {
            LeftType idType = ObjectFactory.GetIdType(resourceTypeForRepository);

            MethodInfo parameterizedGetWhere =
                GetType().GetMethod(nameof(GetWhereWithInclude), BindingFlags.NonPublic | BindingFlags.Instance) !.MakeGenericMethod(resourceTypeForRepository,
                                                                                                                                     idType);

            IEnumerable <object> resourceIds = ((IEnumerable <object>)resources).Cast <IIdentifiable>().Select(resource => resource.GetTypedId());
            IList idsAsList = CollectionConverter.CopyToList(resourceIds, idType);
            var   values    = (IEnumerable)parameterizedGetWhere.Invoke(this, ArrayFactory.Create <object>(idsAsList, relationshipsToNextLayer));

            return(values == null ? null : CollectionConverter.CopyToHashSet(values, resourceTypeForRepository));
        }
        private void RegisterImplementations(Assembly assembly, Type interfaceType, ResourceDescriptor resourceDescriptor)
        {
            var genericArguments = interfaceType.GetTypeInfo().GenericTypeParameters.Length == 2
                ? ArrayFactory.Create(resourceDescriptor.ResourceType, resourceDescriptor.IdType)
                : ArrayFactory.Create(resourceDescriptor.ResourceType);

            var result = TypeLocator.GetGenericInterfaceImplementation(assembly, interfaceType, genericArguments);

            if (result != null)
            {
                var(implementation, registrationInterface) = result.Value;
                _services.AddScoped(registrationInterface, implementation);
            }
        }
        public override FilterExpression OnApplyFilter(FilterExpression existingFilter)
        {
            // Use case: automatically exclude deleted resources for all requests.

            ResourceContext resourceContext    = ResourceGraph.GetResourceContext <CallableResource>();
            AttrAttribute   isDeletedAttribute = resourceContext.Attributes.Single(attribute => attribute.Property.Name == nameof(CallableResource.IsDeleted));

            var isNotDeleted = new ComparisonExpression(ComparisonOperator.Equals, new ResourceFieldChainExpression(isDeletedAttribute),
                                                        new LiteralConstantExpression(bool.FalseString));

            return(existingFilter == null
                ? (FilterExpression)isNotDeleted
                : new LogicalExpression(LogicalOperator.And, ArrayFactory.Create(isNotDeleted, existingFilter)));
        }
Esempio n. 26
0
        /// <inheritdoc />
        public void AfterRead <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline)
            where TResource : class, IIdentifiable
        {
            GetHookResult <TResource> result = GetHook(ResourceHook.AfterRead, resources);

            if (result.Succeeded)
            {
                result.Container.AfterRead((HashSet <TResource>)result.Node.UniqueResources, pipeline);
            }

            TraverseNodesInLayer(_nodeNavigator.CreateNextLayer(result.Node), ResourceHook.AfterRead, (nextContainer, nextNode) =>
            {
                CallHook(nextContainer, ResourceHook.AfterRead, ArrayFactory.Create <object>(nextNode.UniqueResources, pipeline, true));
            });
        }
Esempio n. 27
0
        public void CanGenerateOneDimensionArray()
        {
            int fixedValue = 9;

            var factoryMock = new Mock<IFactory<int>>();
            factoryMock.Setup(f => f.Generate()).Returns(fixedValue);
            int[] dimension = new[] {5};
            var arrayFactory = new ArrayFactory<int>(factoryMock.Object, dimension);
            var result = (int[]) arrayFactory.Generate();

            for (int i = 0; i < result.Length; i++)
            {
                Assert.Equal(fixedValue, result[i]);
            }
        }
        /// <summary>
        /// This method calculates the vector with the beam moment of inertia.
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="numberOfElements"></param>
        /// <returns></returns>
        public override async Task <double[]> CalculateMomentOfInertia(CircularProfile profile, uint numberOfElements)
        {
            double momentOfInertia;

            if (profile.Thickness == null)
            {
                momentOfInertia = Math.PI * Math.Pow(profile.Diameter, 4) / 64;
            }
            else
            {
                momentOfInertia = (Math.PI / 64) * (Math.Pow(profile.Diameter, 4) - Math.Pow(profile.Diameter - 2 * profile.Thickness.Value, 4));
            }

            return(await ArrayFactory.CreateVectorAsync(momentOfInertia, numberOfElements).ConfigureAwait(false));
        }
        /// <summary>
        /// This method calculates the vector with the beam area.
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="numberOfElements"></param>
        /// <returns></returns>
        public override async Task <double[]> CalculateArea(CircularProfile profile, uint numberOfElements)
        {
            double area;

            if (profile.Thickness == null)
            {
                area = Math.PI * Math.Pow(profile.Diameter, 2) / 4;
            }
            else
            {
                area = (Math.PI / 4) * (Math.Pow(profile.Diameter, 2) - Math.Pow(profile.Diameter - 2 * profile.Thickness.Value, 2));
            }

            return(await ArrayFactory.CreateVectorAsync(area, numberOfElements).ConfigureAwait(false));
        }
        /// <summary>
        /// This method calculates the vector with the beam or piezoelectric area.
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="numberOfElements"></param>
        /// <returns></returns>
        public override async Task <double[]> CalculateArea(RectangularProfile profile, uint numberOfElements)
        {
            double area;

            if (profile.Thickness == null)
            {
                area = profile.Height * profile.Width;
            }
            else
            {
                area = (profile.Height * profile.Width) - ((profile.Height - 2 * profile.Thickness.Value) * (profile.Width - 2 * profile.Thickness.Value));
            }

            return(await ArrayFactory.CreateVectorAsync(area, numberOfElements).ConfigureAwait(false));
        }
        /// <summary>
        /// This method calculates the vector with the beam moment of inertia.
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="numberOfElements"></param>
        /// <returns></returns>
        public override async Task <double[]> CalculateMomentOfInertia(RectangularProfile profile, uint numberOfElements)
        {
            double momentOfInertia;

            if (profile.Thickness == null)
            {
                momentOfInertia = Math.Pow(profile.Height, 3) * profile.Width / 12;
            }
            else
            {
                momentOfInertia = (Math.Pow(profile.Height, 3) * profile.Width - (Math.Pow(profile.Height - 2 * profile.Thickness.Value, 3) * (profile.Width - 2 * profile.Thickness.Value))) / 12;
            }

            return(await ArrayFactory.CreateVectorAsync(momentOfInertia, numberOfElements).ConfigureAwait(false));
        }
        /// <summary>
        /// This method calculates the vector with the piezoelectric moment of inertia.
        /// </summary>
        /// <param name="piezoelectricProfile"></param>
        /// <param name="numberOfElements"></param>
        /// <param name="elementsWithPiezoelectric"></param>
        /// <param name="numberOfPiezoelectricsPerElement"></param>
        /// <returns></returns>
        public override async Task <double[]> CalculatePiezoelectricMomentOfInertia(RectangularProfile piezoelectricProfile, RectangularProfile beamProfile, uint numberOfElements, uint[] elementsWithPiezoelectric, uint numberOfPiezoelectricsPerElement)
        {
            double momentOfInertia;

            if (numberOfPiezoelectricsPerElement <= 2 || numberOfPiezoelectricsPerElement > 0)
            {
                momentOfInertia = numberOfPiezoelectricsPerElement * ((Math.Pow(piezoelectricProfile.Height, 3) * piezoelectricProfile.Width / 12) + (piezoelectricProfile.Height * piezoelectricProfile.Width * Math.Pow((beamProfile.Height + piezoelectricProfile.Height) / 2, 2)));
            }
            else
            {
                throw new NotImplementedException($"Not implemented moment of inertia calculation to number of piezoelectric:{numberOfPiezoelectricsPerElement}.");
            }

            return(await ArrayFactory.CreateVectorAsync(momentOfInertia, numberOfElements, elementsWithPiezoelectric).ConfigureAwait(false));
        }