/*public AttrDef(Attribute_Def source) * { * if (source == null) return; * * Id = source.Id; * Name = source.Name ?? String.Empty; * Caption = source.Full_Name ?? String.Empty; * IsNotNull = source.Is_Not_Null ?? false; * IsUnique = source.Is_Unique ?? false; * MaxLength = source.Max_Length ?? 0; * MaxValue = source.Max_Value; * MinValue = source.Min_Value; * DefaultValue = source.Default_Value ?? String.Empty; * OrgTypeId = source.Org_Type_Id; * * if (!source.Data_TypesReference.IsLoaded) source.Data_TypesReference.Load(); * if (source.Data_Types != null) * { * Type = new TypeDef(source.Data_Types); * } * if (source.Enum_Id != null) * { * if (!source.Enum_DefsReference.IsLoaded) source.Enum_DefsReference.Load(); * * EnumDefType = new EnumDef * { * Description = source.Enum_Defs.Description, * Id = (Guid)source.Enum_Id, * Name = source.Enum_Defs.Name ?? String.Empty, * Caption = source.Enum_Defs.Full_Name ?? String.Empty * }; * } * if (source.Document_Id != null) * { * if (!source.Document_DefsReference.IsLoaded) source.Document_DefsReference.Load(); * DocDefType = new DocDef * { * Id = source.Document_Defs.Id, * Name = source.Document_Defs.Name ?? String.Empty, * Caption = source.Document_Defs.Full_Name ?? String.Empty, * AncestorId = source.Document_Defs.Ancestor_Id, * IsInline = source.Document_Defs.Is_Inline ?? false, * IsPublic = source.Document_Defs.Is_Public ?? false * }; * } * Script = source.CalculateScript; * BlobInfo = new BlobInfo * { * MaxHeight = source.BlobMaxHeight ?? 0, * MaxWidth = source.BlobMaxWidth ?? 0, * MaxSizeBytes = source.BlobMaxSizeBytes ?? 0, * IsImage = source.BlobIsImage ?? false * }; * }*/ public AttrDef(AttrDef source) { if (source == null) { return; } Id = source.Id; Name = source.Name; Caption = source.Caption; IsNotNull = source.IsNotNull; IsUnique = source.IsUnique; MaxLength = source.MaxLength; MaxValue = source.MaxValue; MinValue = source.MinValue; DefaultValue = source.DefaultValue; OrgTypeId = source.OrgTypeId; if (source.Type != null) { Type = new TypeDef { Id = source.Type.Id, Name = source.Type.Name } } ; if (source.EnumDefType != null) { EnumDefType = new EnumDef { Description = source.EnumDefType.Description, Id = source.EnumDefType.Id, Name = source.EnumDefType.Name, Caption = source.EnumDefType.Caption }; } if (source.DocDefType != null) { DocDefType = new DocDef { Id = source.DocDefType.Id, Name = source.DocDefType.Name, Caption = source.DocDefType.Caption, AncestorId = source.DocDefType.AncestorId, IsInline = source.DocDefType.IsInline, IsPublic = source.DocDefType.IsPublic }; } Script = source.Script; BlobInfo = new BlobInfo { MaxHeight = source.BlobInfo != null ? source.BlobInfo.MaxHeight : 0, MaxWidth = source.BlobInfo != null ? source.BlobInfo.MaxWidth : 0, MaxSizeBytes = source.BlobInfo != null ? source.BlobInfo.MaxSizeBytes : 0, IsImage = source.BlobInfo != null && source.BlobInfo.IsImage }; }
/// <summary> /// Десериализует документ /// </summary> /// <param name="xmlDoc">Строка содержащая xml сериализованного документа</param> /// <returns>Список Документов восстановленных из xml</returns> public IList <Doc> DeSerialize(string xmlDoc) { var xDocument = XDocument.Parse(xmlDoc); var docList = new List <Doc>(); if (xDocument.Root == null) { return(docList); } foreach (XElement xElementDoc in xDocument.Root.Elements()) { XAttribute xDocId = xElementDoc.Attribute("Id"); XAttribute xDocName = xElementDoc.Attribute("Name"); if (xDocId == null && xDocName == null) { throw new ApplicationException("Тип документа не указан"); } DocDef docDef = xDocId == null? _docDefRepository.DocDefByName(xDocName.Value) : _docDefRepository.DocDefById(Guid.Parse(xDocId.Value)); var doc = new Doc { Id = Guid.NewGuid(), DocDef = docDef, Attributes = new List <AttributeBase>() }; foreach (XElement xElementAttr in xElementDoc.Elements()) { XAttribute xElementId = xElementAttr.Attribute("Id"); XAttribute xElementName = xElementAttr.Attribute("Name"); if (xElementId == null && xElementName == null) { throw new ApplicationException("Невозможно определить атрибут"); } var atr = xElementId == null ? _attributeRepository.CreateAttribute(docDef.GetByName(xElementName.Value)) : _attributeRepository.CreateAttribute(docDef.GetById(Guid.Parse(xElementId.Value))); // _attributeRepository.GetAttributeByName(xElementName.Value, doc.DocDef.Id) : // _attributeRepository.GetAttributeById(Guid.Parse(xElementId.Value), Guid.Empty); int typeId = atr.AttrDef.Type.Id; switch (typeId) { case (short)CissaDataType.Enum: var enumId = atr.AttrDef.EnumDefType.Id; atr.ObjectValue = _enumRepository.GetEnumValueId(enumId, xElementAttr.Value); break; case (short)CissaDataType.Doc: break; case (short)CissaDataType.DocList: break; default: atr.ObjectValue = xElementAttr.Value; break; } //string attributeDefId = xElementAttr.Attribute("Id").Value; //string attributeDefName = xElementAttr.Attribute("AttributeDefName").Value; doc.Attributes.Add(atr); } docList.Add(doc); } return(docList); }