public static void AddServices(ServiceNode[] services) { ClearDB(); foreach (ServiceNode service in services) { var newService = new { ID = service.ID, SemanticThumbprint = service.SemanticThumbprint, SemanticName = service.SemanticName }; CurrClient.Cypher.Merge("(service:Service { ID : {ID} })") .OnCreate().Set("service = {newService}") .WithParams(new { ID = newService.ID, newService}) .ExecuteWithoutResults(); foreach (var semanticItem in service.ConsumeFields) { var newSemanticItem = new { ID = semanticItem }; CurrClient.Cypher.Merge("(semanticitem:SemanticItem { ID: {ID} })") .OnCreate().Set("semanticitem = {newSemanticItem}") .WithParams(new { ID = newSemanticItem.ID, newSemanticItem}).ExecuteWithoutResults(); // Relate together CurrClient.Cypher.Match("(service:Service)", "(semanticitem:SemanticItem)") .Where("service.ID = {serviceID} AND semanticitem.ID = {semanticItemID}") .WithParams(new { serviceID = newService.ID, semanticItemID = newSemanticItem.ID}) .Create("service<-[:RequiresInput]-semanticitem") .ExecuteWithoutResults(); } foreach (var semanticItem in service.ProducesFields) { var newSemanticItem = new { ID = semanticItem }; CurrClient.Cypher.Merge("(semanticitem:SemanticItem { ID: {ID} })") .OnCreate().Set("semanticitem = {newSemanticItem}") .WithParams(new { ID = newSemanticItem.ID, newSemanticItem }).ExecuteWithoutResults(); // Relate together CurrClient.Cypher.Match("(service:Service)", "(semanticitem:SemanticItem)") .Where("service.ID = {serviceID} AND semanticitem.ID = {semanticItemID}") .WithParams(new { serviceID = newService.ID, semanticItemID = newSemanticItem.ID }) .Create("service-[:ProvidesOutput]->semanticitem") .ExecuteWithoutResults(); } foreach(var consumesService in service.ConsumesServices) { var newServiceSemanticName = new { SemanticName = consumesService, }; CurrClient.Cypher.Merge("(serviceSemanticName:ServiceSemanticName { SemanticName: {SemanticName} })") .OnCreate().Set("serviceSemanticName = {newServiceSemanticName}") .WithParams(new { SemanticName = newServiceSemanticName.SemanticName, newServiceSemanticName }) .ExecuteWithoutResults(); CurrClient.Cypher.Match("(service:Service)", "(serviceSemanticName:ServiceSemanticName)") .Where("service.ID = {serviceID} AND serviceSemanticName.SemanticName = {semanticName}") .WithParams(new { serviceID = newService.ID, semanticName = newServiceSemanticName.SemanticName }) .Create("service<-[:RequiresService]-serviceSemanticName") .ExecuteWithoutResults(); } // ProducesFields self var serviceSemanticName = new { SemanticName = newService.SemanticName, }; CurrClient.Cypher.Merge("(serviceSemanticName:ServiceSemanticName { SemanticName: {SemanticName} })") .OnCreate().Set("serviceSemanticName = {serviceSemanticName}") .WithParams(new { SemanticName = serviceSemanticName.SemanticName, serviceSemanticName }) .ExecuteWithoutResults(); CurrClient.Cypher.Match("(service:Service)", "(serviceSemanticName:ServiceSemanticName)") .Where("service.ID = {serviceID} AND serviceSemanticName.SemanticName = {semanticName}") .WithParams(new { serviceID = newService.ID, semanticName = serviceSemanticName.SemanticName }) .Create("service-[:ProvidesService]->serviceSemanticName") .ExecuteWithoutResults(); } }
private static ServiceNode[] GetServiceNodes(ServiceModelType serviceModel, string name) { List<ServiceNode> serviceNodes = new List<ServiceNode>(); foreach (var operation in serviceModel.Service.SelectMany(ser => ser.Operation)) { var semanticCombination = GetCombinedSemanticHashValue(operation); var hashValue = CalculateHexThumbprintSha256(semanticCombination); ServiceNode serviceNode = new ServiceNode { ID = name + "_" + operation.name, SemanticName = operation.semanticTypeName, SemanticThumbprint = hashValue }; var semanticUsages = getTechSemanticStrArray(operation.Parameter); serviceNode.ConsumeFields.AddRange(semanticUsages); if (operation.ReturnValue != null) { var semanticProducing = getTechSemanticStrArray(operation.ReturnValue); serviceNode.ProducesFields.AddRange(semanticProducing); } if (operation.UsesOperation != null) { serviceNode.ConsumesServices.AddRange(operation.UsesOperation.Select(use => use.semanticTypeName)); } if (operation.RequiresContext != null) { var contextUsages = getTechSemanticStrArray(operation.RequiresContext); serviceNode.ConsumeFields.AddRange(contextUsages); } serviceNodes.Add(serviceNode); } return serviceNodes.ToArray(); }