예제 #1
0
        public InterfaceOperation Update(InterfaceOperation interfaceOperation)
        {
            Operation operation = this.Info(interfaceOperation.Id);

            interfaceOperation.LastUpdated = operation.LastUpdated;
            interfaceOperation.Step = operation.Step;

            return interfaceOperation;
        }
예제 #2
0
        /// <summary>
        /// 初始化接口集合
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public static async Task InitInterfaceOperations(IServiceProvider serviceProvider, AppDbContext context)
        {
            var      baseType = typeof(IManageInterface);
            Assembly assembly = baseType.GetTypeInfo().Assembly;
            var      types    = assembly.GetTypes()
                                .Where(t => t.GetInterfaces().Contains(baseType))
                                .ToList();

            if (types != null && types.Count > 0)
            {
                var existInterfaceNames = context.InterfaceOperations.Where(x => x.ParentName == null).Select(x => x.Name).ToList();
                var existOpers          = await context.QueryListBySqlAsync <InterfaceOperationModel>(AuthorityManager.GET_ALL_OPERATION_SQL);

                foreach (var t in types)
                {
                    var groupDesc = t.GetCustomAttribute <InterfaceGroupAttribute>();
                    if (!existInterfaceNames.Contains(t.Name))
                    {
                        if (groupDesc != null)
                        {
                            var model = new InterfaceOperation()
                            {
                                CreateTime  = DateTime.UtcNow,
                                Name        = t.Name,
                                GroupName   = groupDesc.GroupName,
                                Description = groupDesc.Description,
                                ParentName  = null
                            };

                            context.InterfaceOperations.Add(model);
                        }
                    }

                    var fieldInfos = t.GetFields();
                    var list       = new List <InterfaceOperation>();
                    foreach (var f in fieldInfos)
                    {
                        var operName = f.GetRawConstantValue().ToString();
                        if (!string.IsNullOrWhiteSpace(operName) && existOpers.Count(x => x.InterfaceName == t.Name && x.OperationName == operName) == 0)
                        {
                            var desc = f.GetCustomAttribute <DescriptionAttribute>();
                            if (desc != null)
                            {
                                var oper = new InterfaceOperation()
                                {
                                    CreateTime  = DateTime.UtcNow,
                                    ParentName  = t.Name,
                                    GroupName   = groupDesc.GroupName,
                                    Description = desc.Description,
                                    Name        = f.GetRawConstantValue().ToString()
                                };
                                if (oper.Name.CompareIgnoreCase("read") && list.Count > 0)
                                {
                                    list.Insert(0, oper);
                                }
                                else if (oper.Name.CompareIgnoreCase("write") && list.Count > 1)
                                {
                                    list.Insert(1, oper);
                                }
                                else if (oper.Name.CompareIgnoreCase("delete") && list.Count > 2)
                                {
                                    list.Insert(2, oper);
                                }
                                else
                                {
                                    list.Add(oper);
                                }
                            }
                        }
                    }
                    if (list.Count > 0)
                    {
                        context.InterfaceOperations.AddRange(list);
                    }

                    await context.SaveChangesAsync();
                }
            }
        }