Beispiel #1
0
        public void EntityCollectionSerialize()
        {
            DynamicEntityCollection sourceEntity = MockData.CreateRelationDynamicEntityCollection();
            string json = JSONSerializerExecute.Serialize(sourceEntity);

            sourceEntity.ForEach(e => e.Fields.ForEach(f =>
            {
                Assert.IsTrue(json.Contains(f.Name), string.Format("不能再序列化的JSON中找到属性名{0}", f.Name));
            }));
        }
        public void EntitiyCollectionToStringTest()
        {
            DynamicEntityCollection TestData = new DynamicEntityCollection();

            //创建测试数据
            TestData.CopyFrom(MockData.CreateRelationDynamicEntityCollection());

            var result = TestData.ToString();

            Assert.IsTrue(!string.IsNullOrEmpty(result));
        }
Beispiel #3
0
        public static DynamicEntityCollection CreateRelationDynamicEntityCollection()
        {
            DynamicEntityCollection result = new DynamicEntityCollection();

            var item   = CreateDemoItem();
            var header = CreateDemoHeader();

            result.Add(item);
            result.Add(header);

            return(result);
        }
        /// <summary>
        /// 导出XML
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Export_Click(object sender, EventArgs e)
        {
            var req = Request;

            if (req.IsAuthenticated)
            {
                //var entityIDs = hd_entityID.Value.Split(',').Where(p => p.IsNotEmpty()).ToList();
                var entityIDs = ProcessDescInfoDeluxeGrid.SelectedKeys;
                if (!entityIDs.Any())
                {
                    return;
                }

                DynamicEntityCollection collection = new DynamicEntityCollection();
                try
                {
                    entityIDs.ForEach(id => collection.Add(DESchemaObjectAdapter.Instance.Load(id, DateTime.Now.SimulateTime()) as DynamicEntity));
                    //验证导出数据的完整性
                    string validResult = CheckEntityChildren.CheckSelectEntities(collection.Select(p => p.ID).ToArray());
                    validResult.IsNotEmpty().TrueThrow(validResult);

                    string fileName = "DynamicEntity" + "_" + DateTime.Now.SimulateTime().ToString("yyyyMMdd_HHmmss") + ".xml";
                    Response.AddHeader("Content-Disposition", "attachment; filename=\"" + ResponseExtensions.EncodeFileNameInContentDisposition(Response, fileName) + "\"");

                    var aaa = collection.ToXElement();
                    Response.Write(aaa.ToString());
                    Response.Flush();
                    Response.End();
                }
                catch (Exception ex)
                {
                    var exception = ex.GetRealException();
                    throw new HttpException("导出实体出错!\r\n" + exception.Message, ex.InnerException);
                }
            }
            else
            {
                throw new HttpException("请求的方式错误");
            }
        }
Beispiel #5
0
        public void ProcessRequest(HttpContext context)
        {
            var req = context.Request;

            if (req.IsAuthenticated)
            {
                var entityIDs = req.QueryString["id"].Split('|').Where(p => p.IsNotEmpty()).ToList();
                DynamicEntityCollection collection = new DynamicEntityCollection();
                try
                {
                    entityIDs.ForEach(id => collection.Add(DESchemaObjectAdapter.Instance.Load(id, DateTime.Now.SimulateTime()) as DynamicEntity));
                    //验证导出数据的完整性
                    string validResult = CheckEntityChildren.CheckSelectEntities(collection.Select(p => p.ID).ToArray());
                    validResult.IsNotEmpty().TrueThrow(validResult);

                    string fileName = "DynamicEntity" + "_" + DateTime.Now.SimulateTime().ToString("yyyyMMdd_HHmmss") + ".xml";
                    context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + MCS.Web.Library.ResponseExtensions.EncodeFileNameInContentDisposition(context.Response, fileName) + "\"");

                    XmlWriter writer = XmlWriter.Create(context.Response.Output);
                    writer.WriteStartDocument();

                    collection.ToXElement().WriteTo(writer);
                    writer.WriteEndDocument();

                    writer.Close();
                }
                catch (Exception ex)
                {
                    var exception = ex.GetRealException();
                    throw new HttpException("导出实体出错!\r\n" + exception.Message, ex.InnerException);
                }
            }
            else
            {
                throw new HttpException("请求的方式错误");
            }
        }
Beispiel #6
0
        ///// <summary>
        ///// 复制一个实体
        ///// </summary>
        ///// <param name="entityID">实体ID</param>
        ///// <param name="category">类别ID</param>
        ///// <returns></returns>
        //private string CopyChildEntity(string entityID, string category)
        //{
        //    string codeName = string.Empty;

        //    #region 实体创建新实体及其子实体,。
        //    //待复制的实体
        //    DynamicEntity oldEntity = DESchemaObjectAdapter.Instance.Load(entityID) as DynamicEntity;
        //    //要复制的实体
        //    DynamicEntity entity = DESchemaObjectAdapter.Instance.Load(entityID) as DynamicEntity;
        //    List<FieldIDMapping> listMappingField = new List<FieldIDMapping>();
        //    //记录外部实体
        //    List<OuterEntity> outers = new List<OuterEntity>();
        //    List<OuterEntity> oldOuters = new List<OuterEntity>();
        //    //记录字段与外部字段的mapping
        //    foreach (var item in entity.OuterEntities)
        //    {
        //        outers.Add(item);
        //    }

        //    //记录字段与外部字段的mapping
        //    foreach (var item in oldEntity.OuterEntities)
        //    {
        //        oldOuters.Add(item);
        //    }

        //    //复制指标实体
        //    foreach (var item in entity.Fields)
        //    {
        //        if (item.FieldType == FieldTypeEnum.Collection)
        //        {
        //            DynamicEntity childEntity = DEDynamicEntityAdapter.Instance.LoadByCodeName(item.ReferenceEntityCodeName) as DynamicEntity;
        //            item.ReferenceEntityCodeName = CopyChildEntity(childEntity.ID, category);
        //        }
        //    }
        //    //从新NEW当前实体及其子表的ID和VersionTime,从而创建一个新的实体
        //    entity.BuildNewEntity(category);

        //    #endregion

        //    #region 复制外部实体和Mapping
        //    foreach (OuterEntity outerEntity in outers)
        //    {
        //        //构建新的外部实体
        //        outerEntity.BuildNewEntity();
        //        //构建新的实体映射关系
        //        EntityMapping entityMapping = new EntityMapping()
        //        {
        //            InnerEntity = entity,
        //            OuterEntityID = outerEntity.ID,
        //            OuterEntityName = outerEntity.Name,
        //            OuterEntityInType = outerEntity.CustomType,
        //            EntityFieldMappingCollection = new List<EntityFieldMapping>()
        //        };
        //        //循环新实体中每个字段,如果有外部实体字段则创建实体和字段映射关系
        //        foreach (DynamicEntityField newField in entity.Fields)
        //        {
        //            if (string.IsNullOrEmpty(newField.ReferenceEntityCodeName) ||
        //                newField.OuterEntityFields == null ||
        //                newField.OuterEntityFields.Count==0)
        //            {
        //                continue;
        //            }

        //            OuterEntityField newOutField = newField.OuterEntityFields[0];
        //            newOutField.ID = Guid.NewGuid().ToString();
        //            //构建新的字段映射关系
        //            EntityFieldMapping fieldMapping = new EntityFieldMapping()
        //            {
        //                FieldID = newField.ID,
        //                FieldDefaultValue = newField.DefaultValue,
        //                FieldDesc = newField.Description,
        //                FieldLength = newField.Length,
        //                FieldName = newField.Name,
        //                FieldTypeName = newField.FieldType.ToString(),
        //                //OuterFieldID = newOutField.ID,
        //                //OuterFieldName = newOutField.Name,
        //                SortNo = newField.SortNo
        //            };

        //            entityMapping.EntityFieldMappingCollection.Add(fieldMapping);
        //        }
        //        this.AddEntityMapping(entityMapping);

        //    }
        //    #endregion

        //    #region 复制外部实体
        //    /*
        //    foreach (OuterEntity outerEntity in outers)
        //    {
        //        //旧的外部实体
        //        OuterEntity oldOuterEntity = oldOuters.Where(p => p.Name == outerEntity.Name).FirstOrDefault();
        //        if (oldOuterEntity != null && oldOuterEntity.Fields != null)
        //        {
        //            //构建新的外部实体
        //            outerEntity.BuildNewEntity();
        //            //字段之间的mapping入库
        //            foreach (var oldField in oldEntity.Fields)
        //            {
        //                foreach (var item in oldOuterEntity.Fields)
        //                {
        //                    var mappingField = oldField.OuterEntityFields.Where(p => p.ID == item.ID).FirstOrDefault();
        //                    if (mappingField != null)
        //                    {

        //                        var newField = entity.Fields.Where(p => p.ID == oldField.ID).FirstOrDefault();
        //                        var newOuterField = outerEntity.Fields.Where(p => p.Name == mappingField.Name).FirstOrDefault();
        //                        FieldIDMapping mapping = new FieldIDMapping();
        //                        mapping.OldFieldID = oldField.ID;
        //                        mapping.NewFieldID = newField.ID;
        //                        mapping.OldOuterFieldID = mappingField.ID;
        //                        mapping.NewOuterFieldID = newOuterField.ID;
        //                        listMappingField.Add(mapping);
        //                    }
        //                }
        //            }
        //        }

        //        #region 构建Mapping
        //        List<EntityFieldMapping> entityFieldMappingCollection = new List<EntityFieldMapping>();
        //        foreach (var item in entity.Fields)
        //        {
        //            var idMapping = listMappingField.Where(p => p.NewFieldID == item.ID).FirstOrDefault();
        //            var oField = outerEntity.Fields.Where(p => p.ID == idMapping.NewOuterFieldID).FirstOrDefault();
        //            if (oField == null)
        //            {
        //                continue;
        //            }
        //            string outerFieldName = oField.Name;
        //            EntityFieldMapping fieldMapping = new EntityFieldMapping()
        //            {
        //                FieldID = idMapping.NewFieldID,
        //                FieldDefaultValue = item.DefaultValue,
        //                FieldDesc = item.Description,
        //                FieldLength = item.Length,
        //                FieldName = item.Name,
        //                FieldTypeName = item.FieldType.ToString(),
        //                OuterFieldID = idMapping.NewOuterFieldID,
        //                OuterFieldName = outerFieldName,
        //                SortNo = item.SortNo
        //            };

        //            entityFieldMappingCollection.Add(fieldMapping);
        //        }

        //        EntityMapping entityMapping = new EntityMapping()
        //        {
        //            InnerEntity = entity,
        //            OuterEntityID = outerEntity.ID,
        //            OuterEntityName = outerEntity.Name,
        //            OuterEntityInType = outerEntity.CustomType,
        //            EntityFieldMappingCollection = entityFieldMappingCollection
        //        };

        //        this.AddEntityMapping(entityMapping);
        //        #endregion
        //    }
        //     */

        //    #endregion

        //    //新实体入库
        //    this.AddEntity(entity);
        //    codeName = entity.CodeName;
        //    return codeName;
        //}

        #endregion

        /// <summary>
        /// 复制多个实体到多个类别下
        /// </summary>
        /// <param name="entitiesIDs">实体的id集合</param>
        /// <param name="categories">目标类别id集合</param>
        public void MoveEntities(List <string> entitiesIDs, List <string> categories)
        {
            //todo:@海军此处加参数非空校验

            //筛选出有主子关系的id
            string        error   = string.Empty;
            List <string> copyIDs = new List <string>();

            copyIDs.AddRange(entitiesIDs);

            List <string> mainIDs = new List <string>();

            #region  除带有主表的 子表id
            foreach (var entityID in entitiesIDs)
            {
                if (!copyIDs.Contains(entityID))
                {
                    continue;
                }

                var entity = DESchemaObjectAdapter.Instance.Load(entityID) as DynamicEntity;
                var childs = entity.Fields.Where(p => p.FieldType == Library.SOA.DataObjects.Dynamics.Enums.FieldTypeEnum.Collection);
                if (childs.Count() > 0)
                {
                    mainIDs.Add(entityID);
                    foreach (var item in childs)
                    {
                        copyIDs.Remove(item.ReferenceEntity.ID);
                    }
                }
            }

            #endregion

            #region 循环类别,向类别中复制实体

            #region 移动实体
            foreach (var category in categories)
            {
                //获取当前类别
                //copyIDs是待操作的主实体编码
                foreach (var entityID in copyIDs)
                {
                    try
                    {
                        using (TransactionScope scope = TransactionScopeFactory.Create())
                        {
                            //复制实体(包含子实体)
                            CopyChildEntity(entityID, category);

                            //删除实体(包含子实体)
                            #region

                            //取出待删除的主实体
                            DynamicEntity delEntity = DESchemaObjectAdapter.Instance.Load(entityID) as DynamicEntity;

                            DynamicEntityCollection collToDel = new DynamicEntityCollection();

                            collToDel.Add(delEntity);

                            delEntity.Fields.Where(p => p.FieldType == FieldTypeEnum.Collection && p.ReferenceEntityCodeName.IsNotEmpty()).ForEach(item =>
                            {
                                DynamicEntity childEntity = DEDynamicEntityAdapter.Instance.LoadByCodeName(item.ReferenceEntityCodeName) as DynamicEntity;

                                DeleteEntity(childEntity.ID);
                            });

                            DeleteEntity(delEntity);
                            #endregion

                            scope.Complete();
                        }
                    }
                    catch (Exception e)
                    {
                        error += e.Message + "\r\n";
                    }
                }
            }
            #endregion

            #endregion
            if (!string.IsNullOrEmpty(error))
            {
                throw new Exception(error);
            }
        }