public static List <DataItemMapping> BusinessKeyComponentMappingList(string sourceBusinessKeyDefinition, string targetBusinessKeyDefinition)
        {
            // Set the return type
            List <DataItemMapping> returnList = new List <DataItemMapping>();

            // Evaluate key components for source and target key definitions
            var sourceBusinessKeyComponentList = businessKeyComponentList(sourceBusinessKeyDefinition);
            var targetBusinessKeyComponentList = businessKeyComponentList(targetBusinessKeyDefinition);

            int counter = 0;

            foreach (string keyPart in sourceBusinessKeyComponentList)
            {
                bool businessKeyEval = false;

                if (keyPart.StartsWith("'") && keyPart.EndsWith("'"))
                {
                    //businessKeyEval = "HardCoded";
                    businessKeyEval = true;
                }

                DataItemMapping keyComponent = new DataItemMapping();

                DataItem sourceColumn = new DataItem();
                DataItem targetColumn = new DataItem();

                sourceColumn.name             = keyPart;
                sourceColumn.isHardCodedValue = businessKeyEval;

                keyComponent.sourceDataItem = sourceColumn;

                var indexExists = targetBusinessKeyComponentList.ElementAtOrDefault(counter) != null;
                if (indexExists)
                {
                    targetColumn.name = targetBusinessKeyComponentList[counter];
                }
                else
                {
                    targetColumn.name = "";
                }

                keyComponent.targetDataItem = targetColumn;

                returnList.Add(keyComponent);
                counter++;
            }

            return(returnList);
        }
        internal static string EvaluateBusinessKey(DataItemMapping businessKey)
        {
            var businessKeyEval = "";

            if (businessKey.sourceDataItem.name.Contains("'"))
            {
                businessKeyEval = businessKey.sourceDataItem.name;
            }
            else
            {
                businessKeyEval = "[" + businessKey.sourceDataItem.name + "]";
            }

            return(businessKeyEval);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a list of Data Item Mappings for a source- and target Business Key definition.
        /// The Business Keys will be split into components and mapped in order.
        /// </summary>
        /// <param name="sourceBusinessKeyDefinition"></param>
        /// <param name="targetBusinessKeyDefinition"></param>
        /// <returns></returns>
        public static List <DataItemMapping> GetBusinessKeyComponentDataItemMappings(string sourceBusinessKeyDefinition, string targetBusinessKeyDefinition)
        {
            // Set the return type
            List <DataItemMapping> returnList = new List <DataItemMapping>();

            // Evaluate key components for source and target key definitions
            var sourceBusinessKeyComponentList = GetBusinessKeyComponentList(sourceBusinessKeyDefinition);
            var targetBusinessKeyComponentList = GetBusinessKeyComponentList(targetBusinessKeyDefinition);

            int counter = 0;

            // Only the source can be a hard-coded value, as it is mapped to a target.
            foreach (string keyPart in sourceBusinessKeyComponentList)
            {
                // Is set to true if there are quotes in the key part.

                DataItemMapping keyComponent = new DataItemMapping();

                List <dynamic> sourceColumns = new List <dynamic>();

                DataItem sourceColumn = new DataItem();
                DataItem targetColumn = new DataItem();

                sourceColumn.name             = keyPart;
                sourceColumn.isHardCodedValue = keyPart.StartsWith("'") && keyPart.EndsWith("'");

                sourceColumns.Add(sourceColumn);

                keyComponent.sourceDataItems = sourceColumns;

                var indexExists = targetBusinessKeyComponentList.ElementAtOrDefault(counter) != null;
                if (indexExists)
                {
                    targetColumn.name = targetBusinessKeyComponentList[counter];
                }
                else
                {
                    targetColumn.name = "";
                }

                keyComponent.targetDataItem = targetColumn;

                returnList.Add(keyComponent);
                counter++;
            }

            return(returnList);
        }
Ejemplo n.º 4
0
        public virtual async Task <MenuDto> CreateAsync(MenuCreateDto input)
        {
            var layout = await LayoutRepository.GetAsync(input.LayoutId);

            var data = await DataRepository.GetAsync(layout.DataId);

            var menu = await MenuManager.CreateAsync(
                GuidGenerator.Create(),
                layout.Id,
                input.Path,
                input.Name,
                input.Component,
                input.DisplayName,
                input.Redirect,
                input.Description,
                layout.PlatformType,
                input.ParentId,
                CurrentTenant.Id,
                input.IsPublic);

            // 利用布局约定的数据字典来校验必须的路由元数据,元数据的加入是为了适配多端路由
            foreach (var dataItem in data.Items)
            {
                if (!input.Meta.TryGetValue(dataItem.Name, out object meta))
                {
                    if (!dataItem.AllowBeNull)
                    {
                        throw new BusinessException(PlatformErrorCodes.MenuMissingMetadata)
                              .WithData("Name", dataItem.DisplayName)
                              .WithData("DataName", data.DisplayName);
                    }
                    // 是否需要设定默认值
                    menu.SetProperty(dataItem.Name, dataItem.DefaultValue);
                }
                else
                {
                    // 需要检查参数是否有效
                    menu.SetProperty(dataItem.Name, DataItemMapping.MapToString(dataItem.ValueType, meta));
                }
            }

            await CurrentUnitOfWork.SaveChangesAsync();

            return(ObjectMapper.Map <Menu, MenuDto>(menu));
        }
Ejemplo n.º 5
0
        public virtual async Task <MenuDto> UpdateAsync(Guid id, MenuUpdateDto input)
        {
            var menu = await MenuRepository.GetAsync(id);

            // 利用布局约定的数据字典来校验必须的路由元数据,元数据的加入是为了适配多端路由
            var layout = await LayoutRepository.GetAsync(menu.LayoutId);

            var data = await DataRepository.GetAsync(layout.DataId);

            foreach (var dataItem in data.Items)
            {
                if (!input.Meta.TryGetValue(dataItem.Name, out object meta))
                {
                    if (!dataItem.AllowBeNull)
                    {
                        throw new BusinessException(PlatformErrorCodes.MenuMissingMetadata)
                              .WithData("Name", dataItem.DisplayName)
                              .WithData("DataName", data.DisplayName);
                    }
                    // 是否需要设定默认值?
                    menu.SetProperty(dataItem.Name, dataItem.DefaultValue);
                }
                else
                {
                    // 与现有的数据做对比
                    var menuMeta = menu.GetProperty(dataItem.Name);
                    if (menuMeta != null && menuMeta.Equals(meta))
                    {
                        continue;
                    }
                    // 需要检查参数是否有效
                    menu.SetProperty(dataItem.Name, DataItemMapping.MapToString(dataItem.ValueType, meta));
                }
            }

            if (!string.Equals(menu.Name, input.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                menu.Name = input.Name;
            }
            if (!string.Equals(menu.DisplayName, input.DisplayName, StringComparison.InvariantCultureIgnoreCase))
            {
                menu.DisplayName = input.DisplayName;
            }
            if (!string.Equals(menu.Description, input.Description, StringComparison.InvariantCultureIgnoreCase))
            {
                menu.Description = input.Description;
            }
            if (!string.Equals(menu.Path, input.Path, StringComparison.InvariantCultureIgnoreCase))
            {
                menu.Path = input.Path;
            }
            if (!string.Equals(menu.Redirect, input.Redirect, StringComparison.InvariantCultureIgnoreCase))
            {
                menu.Redirect = input.Redirect;
            }
            if (!string.Equals(menu.Component, input.Component, StringComparison.InvariantCultureIgnoreCase))
            {
                menu.Component = input.Component;
            }

            menu.IsPublic = input.IsPublic;

            await MenuManager.UpdateAsync(menu);

            await CurrentUnitOfWork.SaveChangesAsync();

            return(ObjectMapper.Map <Menu, MenuDto>(menu));
        }