/// <summary> /// 获取算法 /// </summary> /// <returns></returns> public AlgorithmDTO GetAlgorithm() { var db = base.repository.GetDbContext(); AlgorithmDTO algorithmDTO = new AlgorithmDTO { Algorithm = GetAlgorithmEntity() }; algorithmDTO.MetaDefine = JsonConvert.DeserializeObject <AlgorithmMetaDefine>(algorithmDTO.Algorithm.Extension.ToString()); String baseDir = AppDomain.CurrentDomain.BaseDirectory; String assemblyPath = Path.Combine(baseDir, algorithmDTO.MetaDefine.Assembly); Assembly assembly = Assembly.LoadFile(assemblyPath); if (null == assembly) { LOG.Warn($"程序集文件[{assemblyPath}]不存在"); throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"程序集文件[{assemblyPath}]不存在"); } IAlgorithm algorithm = (IAlgorithm)assembly.CreateInstance(algorithmDTO.MetaDefine.MainClass, true); if (null == algorithm) { LOG.Warn($"接口[{algorithmDTO.MetaDefine.MainClass}]创建实例为空"); throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"程序集文件[{assemblyPath}]不存在"); } algorithmDTO.AlgorithmInstance = algorithm; return(algorithmDTO); }
public Algorithm ConvertToAlgorithm(AlgorithmDTO algorithmDTO) { return(new Algorithm { Id = algorithmDTO.Id, Name = algorithmDTO.Name, Description = algorithmDTO.Description, IsActive = algorithmDTO.IsActive }); }
public IHttpActionResult ChangeAlgorithm(AlgorithmDTO algorithm) { try { quiz.ChangeAlgorithm(algorithm); return(Ok(algorithm)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public Result Run() { // 找到算法输入依赖的算法实体 AlgorithmDTO dto = this.ruleStepMeta.GetAlgorithm(); // 找到这个步骤注入的参数值 var db = base.repository.GetDbContext(); List <DmeRuleStepAttribute> stepAttributes = db.Queryable <DmeRuleStepAttribute>().Where(rsa => rsa.RuleStepId == this.step.Id).ToList(); if (0 == stepAttributes?.Count) { LOG.Warn("没有找到步骤关联的参数设置,停止执行"); return(new Result(EnumSystemStatusCode.DME_FAIL, "没有找到步骤关联的参数设置,停止执行", null)); } IDictionary <string, Property> inputParams = dto.AlgorithmInstance.InParams; // 载入参数值 IDictionary <string, Property> paraValues = new Dictionary <string, Property>(); foreach (var item in stepAttributes) { if (!inputParams.ContainsKey(item.AttributeCode)) { continue; } Property inputParaProperty = inputParams[item.AttributeCode]; if (1 == item.IsNeedPrecursor) { // 前驱参数 if (null == item.AttributeValue || string.IsNullOrEmpty(item.AttributeValue.ToString()) || !item.AttributeValue.ToString().Contains(":")) { throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"步骤[{step.SysCode}]的参数[{item.AttributeCode}]无效,值[{inputParaProperty.Value}]"); } string preStepName = item.AttributeValue.ToString().Split(":")[0]; string preAttributeName = item.AttributeValue.ToString().Split(":")[1]; DmeRuleStepAttribute preRuleStepAttribute = db.Queryable <DmeRuleStepAttribute, DmeRuleStep> ((rsa, rs) => new object[] { rs.Id == rsa.RuleStepId }) .Where((rsa, rs) => rs.ModelId == step.ModelId && rs.Name == preStepName && rsa.AttributeCode == preAttributeName) .Single(); if (null == preRuleStepAttribute) { throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"步骤[{step.SysCode}]的参数[{item.AttributeCode}]无效,找不到前驱参数信息"); } paraValues[item.AttributeCode] = base.GetStepAttributeValue(preStepName, preAttributeName);// new Property(item.AttributeCode, item.AttributeCode, EnumValueMetaType.TYPE_UNKNOWN, preRuleStepAttribute.AttributeValue); } else { if (inputParaProperty.DataType == (int)EnumValueMetaType.TYPE_FEATURECLASS) { // 这种类型,要注意解析数据源 JObject featureClassJson = JObject.Parse(item.AttributeValue.ToString()); string featureClassName = featureClassJson.GetValue("name").Value <string>(); string sourceId = featureClassJson.GetValue("source").Value <string>(); // 根据sourceId查找数据源实体 DmeDataSource dataSource = base.repository.GetDbContext().Queryable <DmeDataSource>().Single(ds => ds.SysCode == sourceId); InputFeatureClassDTO inputFeatureClassDTO = new InputFeatureClassDTO { Name = featureClassName, Source = ClassValueCopier <DataSourceDTO> .Copy(dataSource) }; paraValues[item.AttributeCode] = new Property(item.AttributeCode, item.AttributeCode, EnumValueMetaType.TYPE_OBJECT, inputFeatureClassDTO); } else { paraValues[item.AttributeCode] = new Property(item.AttributeCode, item.AttributeCode, EnumValueMetaType.TYPE_UNKNOWN, item.AttributeValue); } } } dto.AlgorithmInstance.Init(paraValues); Result result = dto.AlgorithmInstance.Execute(); // 保存输出 if (result != null && EnumUtil.GetEnumDisplayName(EnumSystemStatusCode.DME_SUCCESS).Equals(result.Status)) { base.SaveOutput(dto.AlgorithmInstance.OutParams); return(new Result(EnumSystemStatusCode.DME_SUCCESS, "执行完毕", true)); } return(new Result(EnumSystemStatusCode.DME_FAIL, "执行失败,无异常信息", false)); }
public void ChangeAlgorithm(AlgorithmDTO algorithm) { Algorithm newAlgorithm = quiz.GetAlgorithm(algorithm.Id); quiz.UpdateAlgorithms(newAlgorithm); }