Пример #1
0
 public MpperRelevanceItem(DataEntity entity, IProperty property, int index)
 {
     this.entity     = entity;
     this.property   = property;
     this.index      = index;
     this.setHandler = EntityMapperCacheManager.GetMapperCacheManager()[entity.GetType().Name].Value.FindSetDynamicHandle(property.Name);
 }
Пример #2
0
        private Transform CreateTransform(DataInventory dataInventory, DataEntity dataEntity)
        {
            var inventoryComponent = _bindComponentToDataDbRead.GetInventoryComponent(dataInventory);
            var prefab             = _factoryDataEntityPrefab.GetPrefab(dataEntity.GetType());
            var entityTransform    = prefab.InstantiateOnRootCanvas().transform;

            entityTransform.SetParent(inventoryComponent.CanvasInventory.transform);

            var sprite = dataEntity.Sprite;

            if (sprite == null)
            {
                throw new NullReferenceException($"{this}: Sprite cannot be null!");
            }
            var image = entityTransform.gameObject.GetComponentInChildren <Image>();

            image.sprite        = sprite;
            image.raycastTarget = false;

            return(entityTransform);
        }
Пример #3
0
        /// <summary>
        /// Converts the <i>DataEntity</i> object into a dynamic object. During the conversion, the passed query groups are being merged.
        /// </summary>
        /// <param name="dataEntity">The <i>DataEntity</i> object to be converted.</param>
        /// <param name="queryGroup">The query group to be merged.</param>
        /// <returns>An instance of converted dynamic object.</returns>
        public static object AsObject(this DataEntity dataEntity, QueryGroup queryGroup)
        {
            var expandObject = new ExpandoObject() as IDictionary <string, object>;

            dataEntity.GetType()
            .GetProperties()
            .ToList()
            .ForEach(property =>
            {
                expandObject[property.GetMappedName()] = property.GetValue(dataEntity);
            });
            queryGroup?
            .FixParameters()
            .GetAllQueryFields()?
            .ToList()
            .ForEach(queryField =>
            {
                expandObject[queryField.Parameter.Name] = queryField.Parameter.Value;
            });

            return((ExpandoObject)expandObject);
        }
Пример #4
0
 /// <summary>
 /// Gets the recursive data of the target <i>DataEntity</i> object.
 /// </summary>
 /// <param name="dataEntity">The target <i>DataEntity</i> object.</param>
 /// <returns>An enumerable list of <i>DataEntityChildListData</i> object.</returns>
 internal static IEnumerable <DataEntityChildListData> GetDataEntityChildrenData(this DataEntity dataEntity)
 {
     return(GetDataEntityChildrenData(dataEntity.GetType()));
 }
Пример #5
0
 /// <summary>
 /// Checks whether the data entity is updateable.
 /// </summary>
 /// <param name="dataEntity">The data entity instance to be checked.</param>
 /// <returns>A boolean value signifies whether the data entity is updateable.</returns>
 public static bool IsUpdateable(this DataEntity dataEntity)
 {
     return(IsUpdateable(dataEntity.GetType()));
 }
Пример #6
0
 /// <summary>
 /// Checks whether the data entity is inline mergeable.
 /// </summary>
 /// <param name="dataEntity">The data entity instance to be checked.</param>
 /// <returns>A boolean value signifies whether the data entity is inline mergeable.</returns>
 public static bool IsInlineMergeable(this DataEntity dataEntity)
 {
     return(IsInlineMergeable(dataEntity.GetType()));
 }
Пример #7
0
 /// <summary>
 /// Checks whether all data entity is deletable.
 /// </summary>
 /// <param name="dataEntity">The data entity instance to be checked.</param>
 /// <returns>A boolean value signifies whether all the data entity is deletable.</returns>
 public static bool IsDeletableAll(this DataEntity dataEntity)
 {
     return(IsDeletableAll(dataEntity.GetType()));
 }
Пример #8
0
 /// <summary>
 /// Checks whether the data entity is bulk insertable.
 /// </summary>
 /// <param name="dataEntity">The data entity instance to be checked.</param>
 /// <returns>A boolean value signifies whether the data entity is bulk insertable.</returns>
 public static bool IsBulkInsertable(this DataEntity dataEntity)
 {
     return(IsQueryable(dataEntity.GetType()));
 }
Пример #9
0
 /// <summary>
 /// Gets the mapped name of the data entity type on a target command. The identification process it to check the <i>RepoDb.Attributes.MapAttribute</i>
 /// and get the value of the <i>Name</i> property.
 /// </summary>
 /// <param name="dataEntity">The instance of the data entity where to get the mapped name.</param>
 /// <param name="command">The target command.</param>
 /// <returns>A string that contains the mapped name for the target command.</returns>
 public static string GetMappedName(this DataEntity dataEntity, Command command)
 {
     return(GetMappedName(dataEntity.GetType(), command));
 }
Пример #10
0
 /// <summary>
 /// Gets the identity property of the <i>DataEntity</i> object.
 /// </summary>
 /// <param name="dataEntity">The instance of data entity where to get the primary key property.</param>
 /// <returns>An instance of <i>System.Reflection.PropertyInfo</i> that corresponds to as a primary property of the data entity.</returns>
 public static PropertyInfo GetIdentityProperty(this DataEntity dataEntity)
 {
     return(GetIdentityProperty(dataEntity.GetType()));
 }
Пример #11
0
 internal static PropertyInfo GetPropertyByAttribute(this DataEntity dataEntity, Type attributeType)
 {
     return(GetPropertyByAttribute(dataEntity.GetType(), attributeType));
 }
Пример #12
0
 /// <summary>
 /// Gets a mapped command type of the <i>DataEntity</i> object based on the target command.
 /// </summary>
 /// <param name="dataEntity">The instance of data entity where to get the mapped command type.</param>
 /// <param name="command">The target command.</param>
 /// <returns>A command type object used by the data entity for the target command.</returns>
 public static CommandType GetCommandType(this DataEntity dataEntity, Command command)
 {
     return(GetCommandType(dataEntity.GetType(), command));
 }
Пример #13
0
 /// <summary>
 /// Gets the list of <i>System.Reflection.PropertyInfo</i> objects from the data entity class based on the
 /// target command.
 /// </summary>
 /// <param name="dataEntity">The instance of the data entity where to get the list of the properties.</param>
 /// <param name="command">The target command.</param>
 /// <returns>The list of data entity properties based on the target command.</returns>
 public static IEnumerable <PropertyInfo> GetPropertiesFor(this DataEntity dataEntity, Command command)
 {
     return(GetPropertiesFor(dataEntity.GetType(), command));
 }
Пример #14
0
        private static void WriteDataEntity(DataEntity dataEntity, List <String[]> fieldsMatrix)
        {
            String[] fieldsRow = Enumerable.Repeat(String.Empty, s_Properties.Length).ToArray();
            fieldsRow[10] = String.Join(",", dataEntity.CollectRegulations.Select(x => x.ToString().ToUpperInvariant()));
            fieldsRow[11] = String.Join(",", dataEntity.PostRegulations.Select(x => x.ToString().ToUpperInvariant()));

            if (dataEntity is DataParameter dataParameter)
            {
                fieldsRow[1] = "SIMM";

                switch (dataParameter)
                {
                case AddOnNotionalFactor addOnNotionalFactor:
                    fieldsRow[0] = "Param_AddOnNotionalFactor";
                    fieldsRow[3] = addOnNotionalFactor.Qualifier;
                    fieldsRow[7] = (dataParameter.Parameter * 100m).Normalize().ToString(CultureInfo.InvariantCulture);
                    break;

                case AddOnProductMultiplier addOnProductMultiplier:
                    fieldsRow[0] = "Param_ProductClassMultiplier";
                    fieldsRow[3] = addOnProductMultiplier.Product.ToString();
                    fieldsRow[7] = (dataParameter.Parameter + 1m).Normalize().ToString(CultureInfo.InvariantCulture);
                    break;

                default:
                    throw new InvalidDataException($"Invalid data entity type {dataEntity.GetType().Name}.");
                }
            }
            else if (dataEntity is DataValue dataValue)
            {
                Amount amount = dataValue.Amount;

                if (amount.Currency != Currency.Usd)
                {
                    fieldsRow[7] = amount.ToString(CultureInfo.InvariantCulture, CurrencyCodeSymbol.None);
                    fieldsRow[8] = amount.Currency.ToString().ToUpperInvariant();
                }
                else
                {
                    fieldsRow[9] = amount.ToString(CultureInfo.InvariantCulture, CurrencyCodeSymbol.None);
                }

                switch (dataEntity)
                {
                case AddOnFixedAmount _:
                    fieldsRow[0] = "Param_AddOnFixedAmount";
                    fieldsRow[1] = "SIMM";
                    break;

                case AddOnNotional addOnNotional:
                    fieldsRow[0]  = "Notional";
                    fieldsRow[1]  = "SIMM";
                    fieldsRow[3]  = addOnNotional.Qualifier;
                    fieldsRow[12] = addOnNotional.PortfolioId;
                    fieldsRow[13] = addOnNotional.TradeId;
                    fieldsRow[14] = addOnNotional.EndDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
                    break;

                case Notional notional:
                    fieldsRow[0]  = "Notional";
                    fieldsRow[1]  = "Schedule";
                    fieldsRow[2]  = notional.Product.ToString();
                    fieldsRow[12] = notional.PortfolioId;
                    fieldsRow[13] = notional.TradeId;
                    fieldsRow[14] = notional.EndDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
                    break;

                case PresentValue presentValue:
                    fieldsRow[0]  = "PV";
                    fieldsRow[1]  = "Schedule";
                    fieldsRow[2]  = presentValue.Product.ToString();
                    fieldsRow[12] = presentValue.PortfolioId;
                    fieldsRow[13] = presentValue.TradeId;
                    fieldsRow[14] = presentValue.EndDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
                    break;

                case Sensitivity sensitivity:
                {
                    fieldsRow[0] = sensitivity.Identifier;
                    fieldsRow[1] = "SIMM";
                    fieldsRow[2] = sensitivity.Product.ToString();
                    fieldsRow[3] = sensitivity.Qualifier.Replace("/", String.Empty);

                    if (sensitivity.Bucket is Currency currency)
                    {
                        if (sensitivity.Identifier == "Risk_IRCurve")
                        {
                            fieldsRow[4] = ((Int32)currency.Volatility + 1).ToString();
                        }
                    }
                    else if (!(sensitivity.Bucket is Placeholder))
                    {
                        fieldsRow[4] = sensitivity.Bucket.ToString();
                    }

                    fieldsRow[5]  = sensitivity.Label1;
                    fieldsRow[6]  = DataValidator.FormatLibor(sensitivity.Label2, false);
                    fieldsRow[12] = sensitivity.PortfolioId;
                    fieldsRow[13] = sensitivity.TradeId;
                    fieldsRow[14] = sensitivity.EndDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);

                    break;
                }

                default:
                    throw new InvalidDataException($"Invalid data entity type {dataEntity.GetType().Name}.");
                }
            }

            fieldsMatrix.Add(fieldsRow);
        }