internal IEnumerable <Relation> GetRelationsByPattern(string searchPattern) { var relations = new List <Relation>(); if (Directory.Exists(Settings.RelationsStoragePath)) { var relationFilePaths = System.IO.Directory.GetFiles(Settings.RelationsStoragePath, searchPattern + ".xml"); foreach (var relationFilePath in relationFilePaths) { var relationFileInfo = new FileInfo(relationFilePath); var relationFileContent = ""; using (var reader = relationFileInfo.OpenRead()) { var relationFileBytes = new byte[reader.Length]; reader.Read(relationFileBytes, 0, (int)reader.Length); relationFileContent = Encoding.UTF8.GetString(relationFileBytes); } var relationById = RelationSerializer.FromXml(relationFileContent); // TODO: The source / destination of this relation might not be a file in the future but for the moment that's all this provider supports var relation = new Relation(relationById.Type, this.Get <File>(relationById.SourceId), this.Get <File>(relationById.DestinationId), relationById.Ordinal, relationById.MetaData.ToArray()); relations.Add(relation); } } return(relations); }
public void RelationSerializerTests_FromXml_Works() { //Arrange var sourceId = new HiveId(Guid.NewGuid()); var destinationId = new HiveId(Guid.NewGuid()); var relationType = new RelationType("TestRelationType"); var xml = string.Format( @"<relation type=""{0}"" sourceId=""{1}"" destinationId=""{2}"" ordinal=""0""> <metaDatum key=""test1"" value=""value1"" /> <metaDatum key=""test2"" value=""value2"" /> </relation>", relationType.RelationName, sourceId.ToString(HiveIdFormatStyle.AsUri), destinationId.ToString(HiveIdFormatStyle.AsUri)); //Act var relation = RelationSerializer.FromXml(xml); //Assert Assert.IsTrue(relation != null); Assert.IsTrue(relation.Type.RelationName == relationType.RelationName); Assert.IsTrue(relation.SourceId.ToString(HiveIdFormatStyle.AsUri) == sourceId.ToString(HiveIdFormatStyle.AsUri)); Assert.IsTrue(relation.DestinationId.ToString(HiveIdFormatStyle.AsUri) == destinationId.ToString(HiveIdFormatStyle.AsUri)); Assert.IsTrue(relation.Ordinal == 0); Assert.IsTrue(relation.MetaData.Count == 2); Assert.IsTrue(relation.MetaData.Single(x => x.Key == "test1").Value == "value1"); Assert.IsTrue(relation.MetaData.Single(x => x.Key == "test2").Value == "value2"); }
private IEnumerable <Relation> GetRelationsByPattern(string searchPattern) { var relations = new List <Relation>(); if (Directory.Exists(_relationsFolder)) { var relationFilePaths = System.IO.Directory.GetFiles(_relationsFolder, searchPattern + ".xml"); foreach (var relationFilePath in relationFilePaths) { var relationFileInfo = new FileInfo(relationFilePath); var relationFileContent = ""; using (var reader = relationFileInfo.OpenRead()) { var relationFileBytes = new byte[reader.Length]; reader.Read(relationFileBytes, 0, (int)reader.Length); relationFileContent = Encoding.UTF8.GetString(relationFileBytes); } var relation = RelationSerializer.FromXml(relationFileContent); relation.Source = GetEntity <File>(relation.SourceId); // TODO: Might not be a file? relation.Destination = GetEntity <File>(relation.DestinationId); // TODO: Might not be a file? relations.Add(relation); } } return(relations); }