Example #1
0
 public Result RegistryAlgorithm([FromBody] AlgorithmAddReqDTO dto)
 {
     if (ModelState.IsValid)
     {
         return(base.Success(base.algorithmService.AddAlgorithm(dto)));
     }
     // 参数验证失败
     return(base.Error(ModelState));
 }
Example #2
0
 private void GetAlgParameters(IDictionary <String, Property> parameters, string parameterType, AlgorithmAddReqDTO algorithmAddReqDTO)
 {
     if (parameters != null && parameters.Count > 0)
     {
         AlgorithmMetaReqDTO tempAlgMeta = null;
         foreach (var item in parameters)
         {
             tempAlgMeta = new AlgorithmMetaReqDTO
             {
                 Name      = item.Value.Name,
                 DataType  = EnumUtil.GetEnumName <EnumValueMetaType>(item.Value.DataType),
                 Inout     = parameterType,
                 IsVisible = item.Value.IsVisible,
                 Remark    = item.Value.Remark,
                 Alias     = item.Value.Alias,
                 ReadOnly  = item.Value.ReadOnly
             };
             algorithmAddReqDTO.Metas.Add(tempAlgMeta);
         }
     }
 }
Example #3
0
        public object RegistryAlgorithmFromLocal(string algCode)
        {
            String baseDir = AppDomain.CurrentDomain.BaseDirectory;
            // String registerFile = Path.Combine(new string[] { baseDir, "register.json" });
            //if (!File.Exists(registerFile))
            //{
            //    throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"注册文件[{registerFile}]不存在");
            //}
            //String jsonText = File.ReadAllText(registerFile);
            //JObject jObject = JObject.Parse(jsonText);
            //JToken[] jTokens = jObject["Algorithms"].ToArray<JToken>();
            //if (null == jTokens || 0 == jTokens.Length)
            //{
            //    LOG.Warn("在注册文件中没有找到节点[Algorithms]的内容");
            //    return false;
            //}
            IList <AlgorithmRegisterDTO> registerAlgorithms = Register.Algorithms;

            if (0 == registerAlgorithms?.Count)
            {
                return(false);
            }
            IAlgorithm tempAlgorithm = null;

            foreach (var item in registerAlgorithms)
            {
                try
                {
                    string   assemblyPath = Path.Combine(baseDir, item.Assembly);
                    Assembly assembly     = Assembly.LoadFile(assemblyPath);
                    if (null == assembly)
                    {
                        LOG.Warn($"程序集文件[{assemblyPath}]不存在");
                        continue;
                    }
                    string fullName = item.MainClass;
                    if (string.IsNullOrEmpty(fullName))
                    {
                        LOG.Warn($"接口名称缺失[MainClass]");
                        continue;
                    }
                    tempAlgorithm = (IAlgorithm)assembly.CreateInstance(fullName, true);
                    if (null == tempAlgorithm)
                    {
                        LOG.Warn($"接口[{fullName}]创建实例为空");
                        continue;
                    }
                    if (string.IsNullOrEmpty(algCode) || algCode.Equals(tempAlgorithm.SysCode))
                    {
                        AlgorithmAddReqDTO algorithmAddReqDTO = new AlgorithmAddReqDTO
                        {
                            SysCode   = tempAlgorithm.SysCode,
                            Name      = tempAlgorithm.Name,
                            Alias     = tempAlgorithm.Alias,
                            Version   = tempAlgorithm.Version,
                            Remark    = tempAlgorithm.Remark,
                            Type      = tempAlgorithm.AlgorithmType.Code,
                            Extension = JsonConvert.SerializeObject(tempAlgorithm.AlgorithmType.Metadata)
                        };
                        algorithmAddReqDTO.Metas = new List <AlgorithmMetaReqDTO>();
                        // 输入参数
                        this.GetAlgParameters((IDictionary <String, Property>)tempAlgorithm.InParams, AlgorithmParameterType.IN, algorithmAddReqDTO);
                        // 输出参数
                        this.GetAlgParameters((IDictionary <String, Property>)tempAlgorithm.OutParams, AlgorithmParameterType.OUT, algorithmAddReqDTO);
                        // 特征参数
                        this.GetAlgParameters((IDictionary <String, Property>)tempAlgorithm.FeatureParams, AlgorithmParameterType.IN_F, algorithmAddReqDTO);
                        // 持久化数据
                        this.AddAlgorithm(algorithmAddReqDTO);
                        if (string.IsNullOrEmpty(algCode))
                        {
                            // 表示所有,继续遍历其它算法
                            continue;
                        }
                        else
                        {
                            // 表示指定算法
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    LOG.Error(ex, "注册本地算法失败");
                    continue;
                }
            }
            return(true);
        }
Example #4
0
        public object AddAlgorithm(AlgorithmAddReqDTO dto)
        {
            DbResult <AlgorithmRespDTO> result = base.Repository.GetDbContext().Ado.UseTran <AlgorithmRespDTO>(() =>
            {
                DmeAlgorithm alg = base.Repository.GetDbContext().Queryable <DmeAlgorithm>().Where(a => a.SysCode == dto.SysCode).First();
                if (null == alg)
                {
                    alg            = ClassValueCopier <DmeAlgorithm> .Copy(dto);
                    alg.CreateTime = DateUtil.CurrentTimeMillis;
                    alg.Extension  = JsonConvert.SerializeObject(dto.Extension);
                    alg.Id         = base.Repository.GetDbContext().Insertable <DmeAlgorithm>(alg).ExecuteReturnIdentity();
                }
                else
                {
                    // 进行更新操作
                    alg.Name      = dto.Name;
                    alg.Alias     = dto.Alias;
                    alg.Version   = dto.Version;
                    alg.Remark    = dto.Remark;
                    alg.Type      = dto.Type;
                    alg.Extension = JsonConvert.SerializeObject(dto.Extension);
                    if (!base.Repository.GetDbContext().Updateable <DmeAlgorithm>().ExecuteCommandHasChange())
                    {
                        throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, "更新算法信息失败,无详情信息。");
                    }
                    if (dto.Metas != null && dto.Metas.Count > 0)
                    {
                        // 删除算法的输入输出参数这些元数据信息,必须ExecuteCommand,否则无效
                        base.Repository.GetDbContext().Deleteable <DmeAlgorithmMeta>().Where(am => am.AlgorithmId == alg.Id).ExecuteCommand();
                    }
                }
                // 重新注册算法参数元数据
                AlgorithmRespDTO algorithmRespDTO = ClassValueCopier <AlgorithmRespDTO> .Copy(alg);
                if (dto.Metas != null && dto.Metas.Count > 0)
                {
                    algorithmRespDTO.Metas = new List <AlgorithmMetaDTO>();
                    DmeAlgorithmMeta meta  = null;
                    foreach (var item in dto.Metas)
                    {
                        meta             = ClassValueCopier <DmeAlgorithmMeta> .Copy(item);
                        meta.AlgorithmId = alg.Id;
                        meta.Id          = base.Repository.GetDbContext().Insertable <DmeAlgorithmMeta>(meta).ExecuteReturnIdentity();
                        EnumValueMetaType enumValueMetaType = EnumUtil.GetEnumObjByName <EnumValueMetaType>(item.DataType);
                        algorithmRespDTO.Metas.Add(new AlgorithmMetaDTO()
                        {
                            Name         = item.Name,
                            DataType     = (int)enumValueMetaType,
                            DataTypeCode = item.DataType,
                            DataTypeDesc = EnumUtil.GetEnumDescription(enumValueMetaType),
                            Inout        = item.Inout,
                            AlgorithmId  = alg.Id,
                            IsVisible    = item.IsVisible,
                            Remark       = item.Remark,
                            Alias        = item.Alias,
                            ReadOnly     = item.ReadOnly,
                            Required     = item.Required
                        });
                    }
                }
                return(algorithmRespDTO);
            });

            return(result.Data);
        }