private static DataEntity Translate(EntityMetadata md) { DataEntity de = new DataEntity(); de.Id = md.Id; de.Signature = new Signature(Convert.FromBase64String(md.Signature)); de.Payload = new FilePayload(Convert.FromBase64String(md.Name), md.Size); de.Attributes = new List<Attribute>(); foreach (EntityAttribute a in md.Attributes) { de.Attributes.Add(new Attribute(a.Id, Convert.FromBase64String(a.Keyword))); } de.AesInfo = new AesEncryptionInfo(Convert.FromBase64String(md.AesKey), Convert.FromBase64String(md.AesIV)); return de; }
public void InsertDataEntity(Guid userId, DataEntity dataEntity) { LoadEntityMetadata(); AuthorMetadata author; List<AuthorMetadata> authors = this.metadata.Authors.Where(a => a.AuthorId == userId).ToList(); if (authors.Count == 1) { author = authors[0]; } else { author = new AuthorMetadata(); this.metadata.Authors.Add(author); author.AuthorId = userId; } author.EntityIds.Add(new EntityId(dataEntity.Id)); foreach (Attribute attribute in dataEntity.Attributes) { AttributeMetadata am; Attribute modifiedClosureCopy = attribute; List<AttributeMetadata> ams = this.metadata.Attributes.Where(a => a.AttributeId == modifiedClosureCopy.Id).ToList(); if (ams.Count == 1) { am = ams[0]; } else { am = new AttributeMetadata(); this.metadata.Attributes.Add(am); am.AttributeId = attribute.Id; } am.EntityIds.Add(new EntityId(dataEntity.Id)); } EntityMetadata entity; List<EntityMetadata> entities = this.metadata.Entities.Where(e => e.Id == dataEntity.Id).ToList(); if (entities.Count == 1) { entity = entities[0]; } else { entity = new EntityMetadata(); this.metadata.Entities.Add(entity); } entity.Id = dataEntity.Id; entity.Signature = Convert.ToBase64String(dataEntity.Signature.Value); foreach (Attribute attribute in dataEntity.Attributes) { entity.Attributes.Add(new EntityAttribute(attribute.Id, Convert.ToBase64String(attribute.Keyword))); } entity.Name = Convert.ToBase64String(dataEntity.Payload.Name); entity.Size = dataEntity.Payload.Size; entity.AesKey = Convert.ToBase64String(dataEntity.AesInfo.Key); entity.AesIV = Convert.ToBase64String(dataEntity.AesInfo.IV); SaveEntityMetadata(); File.WriteAllBytes(Path.Combine(this.entityDirPath, dataEntity.Id.ToString()), dataEntity.Payload.Content); }