Ejemplo n.º 1
0
        public static ModelInfoReqResponses.CompareValueResponse dispatch(
            VersionedModelClassNS.VersionedModelClass versionedModel,
            JObject jobj
            )
        {
            string layerId      = jobj["layerId"].ToString();
            string valueId      = jobj["valueId"].ToString();
            string compareValue = jobj["compareValue"].ToString();

            if (!versionedModel.getCurrent().layerDict.layers.ContainsKey(layerId))
            {
                return(new ModelInfoReqResponses.CompareValueResponseLayerNonexistentError());
            }
            if (!versionedModel.getCurrent().layerDict.layers[layerId].getValueNames().Contains(valueId))
            {
                return(new ModelInfoReqResponses.CompareValueResponseFieldNonexistentError());
            }

            bool isEqual = ModelUtilsNS.ModelUtils.compareFieldValue(
                versionedModel.getCurrent(),
                layerId,
                valueId,
                compareValue
                );

            return(new ModelInfoReqResponses.CompareValueResponseNoError(isEqual));
        }
Ejemplo n.º 2
0
        public static ModelVersioningReqResponses.ModelVersioningReqResponse dispatch(
            JObject jobj,
            VersionedModelClassNS.VersionedModelClass versionedModel
            )
        {
            string type = jobj["type"].ToString();

            if (type == "undo")
            {
                return(Undo.dispatch(jobj, versionedModel));
            }
            else if (type == "redo")
            {
                return(Redo.dispatch(jobj, versionedModel));
            }
            else if (type == "saveFile")
            {
                return(SaveFile.dispatch(jobj, versionedModel));
            }
            else if (type == "openFile")
            {
                return(OpenFile.dispatch(jobj, versionedModel));
            }
            else if (type == "deleteFile")
            {
                return(DeleteFile.dispatch(jobj, versionedModel));
            }
            else
            {
                throw new InvalidInfoReqType(type);
            }
        }
Ejemplo n.º 3
0
        public static ModelInfoReqResponses.EdgesBetweenVerticesResponse dispatch(
            VersionedModelClassNS.VersionedModelClass versionedModel,
            JObject jobj
            )
        {
            var           modelContainer = versionedModel.getCurrent();
            List <string> vertexIds      = new List <string>();

            foreach (var vertexId in (jobj["vertexIds"] as JArray).Children())
            {
                vertexIds.Add(vertexId.ToString());
            }

            List <string> edgeIds = ModelUtilsNS.ModelUtils.getEdgesBetweenVertices(
                modelContainer,
                vertexIds
                );

            var edges = new Dictionary <string, ResponseJson.EdgeData>();

            foreach (string edgeId in edgeIds)
            {
                GraphUtilsNS.GraphUtils.getEdgeJsonData(modelContainer.graph.edges[edgeId]);
                edges[edgeId] = GraphUtilsNS.GraphUtils.getEdgeJsonData(modelContainer.graph.edges[edgeId]);;
            }

            return(new ModelInfoReqResponses.EdgesBetweenVerticesResponseVerticesExist(edges));
        }
Ejemplo n.º 4
0
        public static ModelInfoReqResponses.ValidateEdgeResponse dispatch(
            VersionedModelClassNS.VersionedModelClass versionedModel,
            JObject jobj
            )
        {
            string edgeId         = jobj["edgeId"].ToString();
            string sourceVertexId = jobj["sourceVertexId"].ToString();
            string sourcePortId   = jobj["sourcePortId"].ToString();
            string targetVertexId = jobj["targetVertexId"].ToString();
            string targetPortId   = jobj["targetPortId"].ToString();

            string possibleProblemReason = ModelUtilsNS.ModelUtils.validateEdge(
                versionedModel.getCurrent(),
                edgeId,
                sourceVertexId,
                sourcePortId,
                targetVertexId,
                targetPortId
                );

            if (possibleProblemReason == null)
            {
                return(new ModelInfoReqResponses.ValidateEdgeResponseValid());
            }
            else
            {
                return(new ModelInfoReqResponses.ValidateEdgeResponseInvalid(possibleProblemReason));
            }
        }
Ejemplo n.º 5
0
        public static ModelInfoReqResponses.ValidateValueResponse dispatch(
            VersionedModelClassNS.VersionedModelClass versionedModel,
            JObject jobj
            )
        {
            string layerId  = jobj["layerId"].ToString();
            string valueId  = jobj["valueId"].ToString();
            string newValue = jobj["newValue"].ToString();

            if (!versionedModel.getCurrent().layerDict.layers.ContainsKey(layerId))
            {
                return(new ModelInfoReqResponses.ValidateValueResponseLayerNonexistentError());
            }
            if (!versionedModel.getCurrent().layerDict.layers[layerId].getValueNames().Contains(valueId))
            {
                return(new ModelInfoReqResponses.ValidateValueResponseFieldNonexistError(valueId));
            }
            if (versionedModel.getCurrent().layerDict.layers[layerId].getValueIsReadonly(valueId))
            {
                return(new ModelInfoReqResponses.ValidateValueResponseNoError("Field is read-only"));
            }

            // string may be null
            string validated = ModelUtilsNS.ModelUtils.validateFieldValue(
                versionedModel.getCurrent(),
                layerId,
                valueId,
                newValue
                );

            return(new ModelInfoReqResponses.ValidateValueResponseNoError(validated));
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
 public static ModelInfoReqResponses.SavedFileNamesResponse dispatch(
     VersionedModelClassNS.VersionedModelClass versionedModel,
     JObject jobj
     )
 {
     return(new ModelInfoReqResponses.SavedFileNamesResponse(versionedModel.getSavedFileNames()));
 }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        public static ModelInfoReqResponses.GetUniqueVertexIdsResponse dispatch(
            VersionedModelClassNS.VersionedModelClass versionedModel,
            JObject jobj
            )
        {
            var modelContainer = versionedModel.getCurrent();
            int count          = int.Parse(jobj["count"].ToString());

            List <string> vertexIds = ModelUtilsNS.ModelUtils.getUniqueVertexIds(modelContainer, count);

            return(new ModelInfoReqResponses.GetUniqueVertexIdsResponse(vertexIds));
        }
Ejemplo n.º 10
0
 public static ModelInfoReqResponses.GetListOfLayersResponse dispatch(
     VersionedModelClassNS.VersionedModelClass versionedModel
     )
 {
     return(new ModelInfoReqResponses.GetListOfLayersResponse(
                new List <ModelInfoReqResponses.GetListOfLayersResponse.LayerListElement> {
         new ModelInfoReqResponses.GetListOfLayersResponse.LayerListElement(
             "Unimplemented server feature",
             "Not implemented"
             )
     }
                ));
 }
Ejemplo n.º 11
0
        public static ModelInfoReqResponses.GetGraphDataResponse dispatch(
            VersionedModelClassNS.VersionedModelClass versionedModel,
            JObject jobj
            )
        {
            var modelContainer = versionedModel.getCurrent();

            ResponseJson.GraphData graphData = ModelUtilsNS.ModelUtils.getResponseJsonData(modelContainer);

            ModelInfoReqResponses.GetGraphDataResponse response = new ModelInfoReqResponses.GetGraphDataResponse(graphData);

            return(response);
        }
Ejemplo n.º 12
0
        public static void dispatch(JObject jobj, VersionedModelClassNS.VersionedModelClass versionedModel)
        {
            string clientId  = jobj["client_id"].ToString();
            string requestId = jobj["client_message"]["requestId"].ToString();

            JObject clientRequest = jobj["client_message"]["request"] as JObject;

            ExternalMessageSender.RequestResponder reqResponder = new ExternalMessageSender.RequestResponder(
                requestId,
                clientId
                );

            ModelRequests.Dispatcher.dispatch(clientRequest, reqResponder, versionedModel);
        }
Ejemplo n.º 13
0
 public static ModelInfoReqResponses.FileIsOpenResponse dispatch(
     VersionedModelClassNS.VersionedModelClass versionedModel,
     JObject jobj
     )
 {
     if (versionedModel.isFileCurrentlyOpen())
     {
         return(new ModelInfoReqResponses.FileIsOpenResponseOpen(versionedModel.unsafeGetCurrentFileName(), versionedModel.progressIsSaved()));
     }
     else
     {
         return(new ModelInfoReqResponses.FileIsOpenResponseNotOpen());
     }
 }
Ejemplo n.º 14
0
        public static ModelInfoReqResponses.GetLayerInfoResponse dispatch(
            VersionedModelClassNS.VersionedModelClass versionedModel,
            JObject jobj
            )
        {
            string layerId = jobj["layerId"].ToString();

            if (!versionedModel.getCurrent().layerDict.layers.ContainsKey(layerId))
            {
                return(new ModelInfoReqResponses.GetLayerInfoResponseLayerDoesNotExist());
            }

            ResponseJson.LayerData layerData = ModelUtilsNS.ModelUtils.getLayerJsonData(versionedModel.getCurrent(), layerId);

            return(new ModelInfoReqResponses.GetLayerInfoResponseLayerExists(layerData));
        }
Ejemplo n.º 15
0
        public static void dispatch(JObject jobj, VersionedModelClassNS.VersionedModelClass versionedModel)
        {
            var type = jobj["type"].ToString();

            if (type == "client_request")
            {
                ClientRequest.dispatch(jobj, versionedModel);
            }
            else if (type == "layer_data_response")
            {
                LayerDataResponse.dispatch(jobj);
            }
            else
            {
                throw new InvalidServerReqType(type);
            }
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            VersionedModelClassNS.VersionedModelClass versionedModel = new VersionedModelClassNS.VersionedModelClass();

            string[] ids = new string[] { "a", "b", "c", "d" };

            for (int i = 0; i < ids.Length; i++)
            {
                ModelUtilsNS.ModelUtils.addLayer(
                    versionedModel,
                    ids[i],
                    "Repeat",
                    10 * i,
                    10 * i
                    );
            }

            while (true)
            {
                string line = System.Console.In.ReadLine();
                try {
                    var jobj = Newtonsoft.Json.Linq.JObject.Parse(line);

                    System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
                    stopWatch.Start();

                    ServerRequests.Dispatcher.dispatch(jobj, versionedModel);

                    stopWatch.Stop();
                    // Get the elapsed time as a TimeSpan value.
                    System.TimeSpan ts          = stopWatch.Elapsed;
                    string          elapsedTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                                ts.Hours, ts.Minutes, ts.Seconds,
                                                                ts.Milliseconds / 10);
                    System.Console.Error.WriteLine("Request run time " + elapsedTime);
                } catch (System.Exception exp) {
                    System.Console.Error.WriteLine("Line: " + line);
                    System.Console.Error.WriteLine("Error: " + exp.ToString());
                }
            }
        }
Ejemplo n.º 17
0
        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));
        }
Ejemplo n.º 18
0
        public static ModelInfoReqResponses.ValueIsReadonlyResponse dispatch(
            VersionedModelClassNS.VersionedModelClass versionedModel,
            JObject jobj
            )
        {
            string layerId = jobj["layerId"].ToString();
            string valueId = jobj["valueId"].ToString();

            if (ModelUtilsNS.ModelUtils.isLayerValueOccupied(
                    versionedModel.getCurrent(),
                    layerId,
                    valueId
                    ))
            {
                return(new ModelInfoReqResponses.ValueIsReadonlyResponseIsReadonly(ModelInfoReqResponses.ReadonlyReason.port_is_occupied));
            }

            if (!ModelUtilsNS.ModelUtils.isLayerFieldParameter(versionedModel.getCurrent(), layerId, valueId))
            {
                return(new ModelInfoReqResponses.ValueIsReadonlyResponseIsReadonly(ModelInfoReqResponses.ReadonlyReason.value_is_not_modifiable));
            }

            return(new ModelInfoReqResponses.ValueIsReadonlyResponseNotReadonly());
        }
Ejemplo n.º 19
0
        public static ModelVersioningReqResponses.ModelVersioningReqResponse dispatch(JObject jobj, VersionedModelClassNS.VersionedModelClass versionedModel)
        {
            string fileName = jobj["fileName"].ToString();

            if (versionedModel.fileExistsWithName(fileName))
            {
                versionedModel.unsafeDelete(fileName);
            }

            return(new ModelVersioningReqResponses.DeleteFileReqResponse());
        }
Ejemplo n.º 20
0
        public static ModelVersioningReqResponses.ModelVersioningReqResponse dispatch(JObject jobj, VersionedModelClassNS.VersionedModelClass versionedModel)
        {
            JObject containedReq = jobj["req"] as JObject;

            return(ModelVersioningRequests.Dispatcher.dispatch(containedReq, versionedModel));
        }
Ejemplo n.º 21
0
        public static ModelInfoReqResponses.ModelInfoReqResponse dispatch(
            JObject jobj,
            VersionedModelClassNS.VersionedModelClass versionedModel
            )
        {
            string type = jobj["type"].ToString();

            if (type == "validateEdge")
            {
                return(ValidateEdgeReq.dispatch(versionedModel, jobj));
            }
            else if (type == "edgesBetweenVertices")
            {
                return(EdgesBetweenVerticesReq.dispatch(versionedModel, jobj));
            }
            else if (type == "fileIsOpen")
            {
                return(FileIsOpenReq.dispatch(versionedModel, jobj));
            }
            else if (type == "savedFileNames")
            {
                return(SavedFileNamesReq.dispatch(versionedModel, jobj));
            }
            else if (type == "getPortInfo")
            {
                return(GetPortInfoReq.dispatch(versionedModel, jobj));
            }
            else if (type == "getLayerInfo")
            {
                return(GetLayerInfoReq.dispatch(versionedModel, jobj));
            }
            else if (type == "validateValue")
            {
                return(ValidateValueReq.dispatch(versionedModel, jobj));
            }
            else if (type == "compareValue")
            {
                return(CompareValueReq.dispatch(versionedModel, jobj));
            }
            else if (type == "validateLayerFields")
            {
                return(ValidateLayerFieldsReq.dispatch(versionedModel, jobj));
            }
            else if (type == "getUniqueEdgeIds")
            {
                return(GetUniqueEdgeIdsReq.dispatch(versionedModel, jobj));
            }
            else if (type == "getUniqueVertexIds")
            {
                return(GetUniqueVertexIdsReq.dispatch(versionedModel, jobj));
            }
            else if (type == "valueIsReadonly")
            {
                return(ValueIsReadonlyReq.dispatch(versionedModel, jobj));
            }
            else if (type == "getGraphData")
            {
                return(GetGraphDataReq.dispatch(versionedModel, jobj));
            }
            else if (type == "getListOfLayers")
            {
                return(GetListOfLayersReq.dispatch(versionedModel));
            }
            else
            {
                throw new InvalidInfoReqType(type);
            }
        }
Ejemplo n.º 22
0
        public static void dispatch(JObject jobj, ExternalMessageSender.RequestResponder reqResponder, VersionedModelClassNS.VersionedModelClass versionedModel)
        {
            string type = jobj["type"].ToString();

            if (type == "request_model_changes")
            {
                versionedModel.recordModel();
                ModelChangeReqResponseNS.ModelChangeReqResponse reqResponse = ModelChangeRequest.dispatch(versionedModel.getCurrent(), jobj);

                reqResponder.sendModelChangeReqResponse(reqResponse);
                ExternalMessageSender.DataChangedNotifier.notifyDataChanged(ModelUtilsNS.ModelUtils.getResponseJsonData(versionedModel.getCurrent()));
            }
            else if (type == "request_versioning_change")
            {
                ModelVersioningReqResponses.ModelVersioningReqResponse reqResponse = VersioningChangeRequest.dispatch(jobj, versionedModel);

                reqResponder.sendVersioningChangeReqResponse(reqResponse);
                ExternalMessageSender.DataChangedNotifier.notifyDataChanged(ModelUtilsNS.ModelUtils.getResponseJsonData(versionedModel.getCurrent()));
            }
            else if (type == "request_model_info")
            {
                ModelInfoReqResponses.ModelInfoReqResponse reqResponse = ModelInfoRequest.dispatch(jobj, reqResponder, versionedModel);
                reqResponder.sendModelInfoReqResponse(reqResponse);
            }
            else
            {
                throw new InvalidModelReqType(type);
            }
        }
Ejemplo n.º 23
0
 public static ModelVersioningReqResponses.RedoReqResponse dispatch(JObject jobj, VersionedModelClassNS.VersionedModelClass versionedModel)
 {
     versionedModel.tryRedo();
     return(new ModelVersioningReqResponses.RedoReqResponse());
 }
Ejemplo n.º 24
0
        public static ModelInfoReqResponses.ModelInfoReqResponse dispatch(JObject jobj, ExternalMessageSender.RequestResponder reqResponder, VersionedModelClassNS.VersionedModelClass versionedModel)
        {
            JObject req = jobj["req"] as JObject;

            return(ModelInfoRequests.Dispatcher.dispatch(req, versionedModel));
        }
Ejemplo n.º 25
0
        public static ModelVersioningReqResponses.ModelVersioningReqResponse dispatch(JObject jobj, VersionedModelClassNS.VersionedModelClass versionedModel)
        {
            string fileName = jobj["fileName"].ToString();

            versionedModel.saveToFile(fileName);

            return(new ModelVersioningReqResponses.SaveFileReqResponse());
        }