public static ModelInfoReqResponses.ValidateLayerFieldsResponse dispatch( VersionedModelClassNS.VersionedModelClass versionedModel, JObject jobj ) { Dictionary <string, string> fieldValues = new Dictionary <string, string>(); foreach (var fieldEntry in (jobj["fieldValues"] as JObject).Properties()) { fieldValues[fieldEntry.Name] = fieldEntry.Value.ToString(); } string layerId = jobj["layerId"].ToString(); if (!versionedModel.getCurrent().layerDict.layers.ContainsKey(layerId)) { return(new ModelInfoReqResponses.ValidateLayerFieldsResponseLayerNonexistentError()); } Layers.Layer layer = versionedModel.getCurrent().layerDict.layers[layerId]; foreach (var fieldEntry in fieldValues) { if (!layer.getValueNames().Contains(fieldEntry.Key)) { return(new ModelInfoReqResponses.ValidateLayerFieldsResponseFieldNonexistent(fieldEntry.Key)); } } var validated = ModelUtilsNS.ModelUtils.validateLayerFields( versionedModel.getCurrent(), layerId, fieldValues ); return(new ModelInfoReqResponses.ValidateLayerFieldsResponseNoError(validated.errors, validated.warnings)); }
public static ResponseJson.LayerData getLayerJsonData( ModelClassNS.ModelClass modelStruct, string layerId ) { Layers.Layer layer = modelStruct.layerDict.layers[layerId]; var ports = new Dictionary <string, ResponseJson.LayerPortData>(); var fields = new Dictionary <string, ResponseJson.LayerFieldData>(); foreach (string portName in layer.getPortNames()) { ports[portName] = new ResponseJson.LayerPortData { valueName = layer.getValueNameOfPort(portName), }; } List <string> occupiedValueNames = modelStruct.edgesByVertex[layerId].edgesIn.Select((string edgeId) => { return(modelStruct.layerDict.layers[layerId].getValueNameOfPort(modelStruct.graph.edges[edgeId].targetPortId)); }).ToList(); foreach (string fieldName in layer.getValueNames()) { bool fieldOccupiedByEdge = occupiedValueNames.Contains(fieldName); fields[fieldName] = new ResponseJson.LayerFieldData { value = layer.getValueString(fieldName), fieldIsReadonly = fieldOccupiedByEdge || layer.getValueIsReadonly(fieldName) }; } return(new ResponseJson.LayerData { ports = ports, fields = fields, }); }
public static void addLayer( VersionedModelClassNS.VersionedModelClass versionedModel, string layerId, string layerType, float x, float y ) { ModelClassNS.ModelClass modelClass = versionedModel.getCurrent(); Layers.Layer layer = Layers.Layer.getNewLayerByType(layerType); NetworkContainersNS.Vertex newVertex = new NetworkContainersNS.Vertex { label = layerType + " Layer", xLocation = x, yLocation = y, ports = new Dictionary <string, NetworkContainersNS.NetworkPort>() }; List <string> inputPortNames = new List <string>(); List <string> outputPortNames = new List <string>(); foreach (string portName in layer.getPortNames()) { if (layer.getValueIsReadonly(layer.getValueNameOfPort(portName))) { outputPortNames.Add(portName); } else { inputPortNames.Add(portName); } } for (int i = 0; i < inputPortNames.Count; i++) { // System.Console.Error.WriteLine(((float)(i + 1)) / ((float)(inputPortNames.Count + 1))); newVertex.ports[inputPortNames[i]] = new NetworkContainersNS.NetworkPort { side = NetworkContainersNS.SideType.Top, position = ((float)(i + 1)) / ((float)(inputPortNames.Count + 1)), type = NetworkContainersNS.PortType.Input, }; } for (int i = 0; i < outputPortNames.Count; i++) { newVertex.ports[outputPortNames[i]] = new NetworkContainersNS.NetworkPort { side = NetworkContainersNS.SideType.Bottom, position = ((float)(i + 1)) / ((float)(outputPortNames.Count + 1)), type = NetworkContainersNS.PortType.Output, }; } modelClass.graph.vertices[layerId] = newVertex; modelClass.layerDict.layers[layerId] = layer; modelClass.edgesByVertex[layerId] = new ModelClassNS.VertexEdgesInfo(); }
private static void propagateEdge(ModelClassNS.ModelClass modelStruct, string edgeId) { NetworkContainersNS.Edge edge = modelStruct.graph.edges[edgeId]; Layers.Layer sourceLayer = modelStruct.layerDict.layers[edge.sourceVertexId]; Layers.Layer targetLayer = modelStruct.layerDict.layers[edge.targetVertexId]; string sourceFieldName = sourceLayer.getValueNameOfPort(edge.sourcePortId); string targetFieldName = targetLayer.getValueNameOfPort(edge.targetPortId); bool edgeIsConsistent = targetLayer.compareFieldValue(targetFieldName, sourceLayer.getValueString(sourceFieldName)); if (edgeIsConsistent) { edge.consistency = NetworkContainersNS.ConsistencyType.Consistent; return; } string validateFieldValue = targetLayer.validateFieldString(targetFieldName, sourceLayer.getValueString(sourceFieldName)); if (validateFieldValue != null) { edge.consistency = NetworkContainersNS.ConsistencyType.Inconsistent; return; } Layers.LayersValidated validatedUpdate = targetLayer.validateSetFields(new Dictionary <string, string>() { { targetFieldName, sourceLayer.getValueString(sourceFieldName) }, }); if (validatedUpdate.errors.Count != 0) { edge.consistency = NetworkContainersNS.ConsistencyType.Inconsistent; return; } targetLayer.setFields(new Dictionary <string, string>() { { targetFieldName, sourceLayer.getValueString(sourceFieldName) }, }); edge.consistency = NetworkContainersNS.ConsistencyType.Consistent; }
public static ModelInfoReqResponses.GetPortInfoResponse dispatch( VersionedModelClassNS.VersionedModelClass versionedModel, JObject jobj ) { string vertexId = jobj["vertexId"].ToString(); string portId = jobj["portId"].ToString(); if (!versionedModel.getCurrent().graph.vertices.ContainsKey(vertexId)) { return(new ModelInfoReqResponses.GetPortInfoResponseCouldNotFindPort()); } if (!versionedModel.getCurrent().graph.vertices[vertexId].ports.ContainsKey(portId)) { return(new ModelInfoReqResponses.GetPortInfoResponseCouldNotFindPort()); } Layers.Layer layer = versionedModel.getCurrent().layerDict.layers[vertexId]; string valueName = layer.getValueNameOfPort(portId); string fieldValue = layer.getValueString(valueName); return(new ModelInfoReqResponses.GetPortInfoResponseCouldFindPort(fieldValue)); }