예제 #1
0
        public AlgorithmRespDTO GetAlgorithmByCode(String code, bool hasMeta)
        {
            // single,如果找不到实体,则抛出异常
            DmeAlgorithm     alg          = base.Repository.GetDbContext().Queryable <DmeAlgorithm>().Single(a => a.SysCode == code);
            AlgorithmRespDTO algorithmDTO = ClassValueCopier <AlgorithmRespDTO> .Copy(alg);

            IList <DmeAlgorithmMeta> metas = base.Repository.GetDbContext().Queryable <DmeAlgorithmMeta>().Where(meta => meta.AlgorithmId == alg.Id).ToList();

            if (metas?.Count > 0)
            {
                foreach (var item in metas)
                {
                    EnumValueMetaType enumValueMetaType = EnumUtil.GetEnumObjByName <EnumValueMetaType>(item.DataType);
                    algorithmDTO.Metas.Add(new AlgorithmMetaDTO()
                    {
                        Name         = item.Name,
                        DataType     = (int)enumValueMetaType,
                        DataTypeCode = item.DataType,
                        DataTypeDesc = EnumUtil.GetEnumDescription(enumValueMetaType),
                        Inout        = item.Inout,
                        AlgorithmId  = item.AlgorithmId,
                        IsVisible    = item.IsVisible,
                        Remark       = item.Remark,
                        Alias        = item.Alias,
                        ReadOnly     = item.ReadOnly,
                        Required     = item.Required
                    });
                }
            }
            return(algorithmDTO);
        }
예제 #2
0
        public object DeleteAlgorithm(string code)
        {
            DmeAlgorithm dmeAlgorithm = base.Db.Queryable <DmeAlgorithm>().Single(alg => alg.SysCode == code);

            if (null == dmeAlgorithm)
            {
                throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"算法[{code}]不存在");
            }
            LOG.Info($"删除模型中依赖的算法[{code}]");
            base.Db.Deleteable <DmeRuleStepAttribute>().Where(rsa => rsa.AttributeValue.ToString() == code).ExecuteCommand();
            LOG.Info($"删除模型中依赖的算法参数信息");
            base.Db.Deleteable <DmeAlgorithmMeta>().Where(am => am.AlgorithmId == dmeAlgorithm.Id).ExecuteCommand();
            LOG.Info($"删除模型中依赖的算法实体信息");
            base.Db.Deleteable <DmeAlgorithm>().In(dmeAlgorithm.Id);

            return(true);
        }
예제 #3
0
        /// <summary>
        /// 获取算法实体
        /// </summary>
        /// <returns></returns>
        private DmeAlgorithm GetAlgorithmEntity()
        {
            var db = base.repository.GetDbContext();
            DmeRuleStepAttribute dmeRuleStepAttribute = db.Queryable <DmeRuleStepAttribute>().Single(rsa => rsa.RuleStepId == this.step.Id && rsa.AttributeCode == nameof(this.AlgorithmCode));

            if (null == dmeRuleStepAttribute)
            {
                throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, "没有找到步骤关联的算法属性值");
            }
            string       algorithmCode = dmeRuleStepAttribute.AttributeValue.ToString();
            DmeAlgorithm dmeAlgorithm  = db.Queryable <DmeAlgorithm>().Single(alg => alg.SysCode == algorithmCode);

            if (null == dmeAlgorithm)
            {
                throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"没有找到步骤关联的算法,编码[{algorithmCode}]");
            }
            return(dmeAlgorithm);
        }
예제 #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);
        }
예제 #5
0
        /// <summary>
        /// 覆写父类的方法
        /// </summary>
        /// <returns></returns>
        public new IDictionary <string, Property> ReadAttributes()
        {
            var          db           = repository.GetDbContext();
            DmeAlgorithm dmeAlgorithm = GetAlgorithmEntity();
            // 参数值封装成Property
            // 算法步骤的属性元数据,从表DME_ALGORITHM_META获取
            var algorithmParaMetas = db.Queryable <DmeAlgorithmMeta>().Where(am => am.AlgorithmId == dmeAlgorithm.Id).ToList();

            if (0 == algorithmParaMetas?.Count)
            {
                return(null);
            }
            IDictionary <string, Property> propertyDic = new Dictionary <string, Property>();

            foreach (var paraMetaItem in algorithmParaMetas)
            {
                propertyDic[paraMetaItem.Name] =
                    new Property(paraMetaItem.Name, paraMetaItem.Alias, EnumUtil.GetEnumObjByName <EnumValueMetaType>(paraMetaItem.DataType),
                                 null, null, paraMetaItem.Remark, null, paraMetaItem.IsVisible, paraMetaItem.ReadOnly, paraMetaItem.Required, "");
            }
            // 把算法编码加进去
            propertyDic[nameof(this.AlgorithmCode)] = new Property(nameof(this.AlgorithmCode), nameof(this.AlgorithmCode), EnumValueMetaType.TYPE_STRING);
            IList <DmeRuleStepAttribute> ruleStepAttributes = repository.GetDbContext().Queryable <DmeRuleStepAttribute>().Where(rsa => rsa.RuleStepId == this.step.Id).ToList();

            if (ruleStepAttributes?.Count > 0)
            {
                IDictionary <string, Property> dictionary = new Dictionary <string, Property>();
                Property property = null;
                foreach (var subAtt in ruleStepAttributes)
                {
                    if (!propertyDic.ContainsKey(subAtt.AttributeCode) || null == subAtt.AttributeValue)
                    {
                        continue;
                    }
                    property = propertyDic[subAtt.AttributeCode];
                    property.IsNeedPrecursor = subAtt.IsNeedPrecursor;
                    if (1 == subAtt.IsNeedPrecursor)
                    {
                        // 前驱参数格式:${步骤编码:属性编码}(已过时)
                        property.Value = subAtt.AttributeValue.ToString();//subAtt.AttributeValue.ToString().Substring(2, subAtt.AttributeValue.ToString().LastIndexOf("}")-2);
                        dictionary[subAtt.AttributeCode] = property;
                        continue;
                    }
                    if ((int)EnumValueMetaType.TYPE_FEATURECLASS == property.DataType ||
                        (int)EnumValueMetaType.TYPE_MDB_FEATURECLASS == property.DataType ||
                        (int)EnumValueMetaType.TYPE_SDE_FEATURECLASS == property.DataType)
                    {
                        // 如果是要素类,则值的格式:{"name":"图层名","source":"数据源唯一编码"}
                        JObject jObject = JObject.Parse(subAtt.AttributeValue.ToString());
                        property.Value          = jObject.GetValue("name").Value <string>();
                        property.DataSourceCode = jObject.GetValue("source").Value <string>();
                    }
                    else
                    {
                        property.Value = subAtt.AttributeValue;
                    }
                    dictionary[subAtt.AttributeCode] = property;
                }
                return(dictionary);
            }
            return(null);
        }