/// <summary> /// get edges from diagram stream /// </summary> /// <param name="stream"></param> /// <returns></returns> public List <mxGraphModelRootMxCell> ProcessDigramEdges(StringReader stream, int assessment_id) { List <mxGraphModelRootMxCell> edges = new List <mxGraphModelRootMxCell>(); if (stream != null) { XmlSerializer deserializer = new XmlSerializer(typeof(mxGraphModel)); var diagramXml = (mxGraphModel)deserializer.Deserialize((stream)); mxGraphModelRootObject o = new mxGraphModelRootObject(); Type objectType = typeof(mxGraphModelRootMxCell); foreach (var item in diagramXml.root.Items) { if (item.GetType() == objectType) { var addLayerVisible = (mxGraphModelRootMxCell)item; var layerVisibility = getLayerVisibility(addLayerVisible.parent, assessment_id); addLayerVisible.visible = layerVisibility.visible; addLayerVisible.layerName = layerVisibility.layerName; edges.Add(addLayerVisible); } } } return(edges); }
/// <summary> /// get vertices from diagram stream /// </summary> /// <param name="stream"></param> /// <returns></returns> public List <mxGraphModelRootObject> ProcessDiagramVertices(StringReader stream, int assessment_id) { List <mxGraphModelRootObject> vertices = new List <mxGraphModelRootObject>(); if (stream != null) { XmlSerializer deserializer = new XmlSerializer(typeof(mxGraphModel)); var diagramXml = (mxGraphModel)deserializer.Deserialize((stream)); mxGraphModelRootObject o = new mxGraphModelRootObject(); Type objectType = typeof(mxGraphModelRootObject); LayerManager layers = new LayerManager(db, assessment_id); foreach (var item in diagramXml.root.Items) { if (item.GetType() == objectType) { var addLayerVisible = (mxGraphModelRootObject)item; string parentId = !string.IsNullOrEmpty(addLayerVisible.mxCell.parent) ? addLayerVisible.mxCell.parent : addLayerVisible.parent ?? "0"; var layerVisibility = layers.GetLastLayer(parentId); addLayerVisible.visible = layerVisibility.visible ?? "true"; addLayerVisible.layerName = layerVisibility.layerName ?? string.Empty; vertices.Add(addLayerVisible); } } } return(vertices); }
/// <summary> /// Update fields of components /// </summary> /// <param name="vertice"></param> /// <param name="assessmentId"></param> public void SaveComponent(mxGraphModelRootObject vertice, int assessmentId) { try { var stream = GetDiagramXml(assessmentId); XmlSerializer serializer = new XmlSerializer(typeof(mxGraphModel)); var diagramXml = (mxGraphModel)serializer.Deserialize(stream); for (int i = 0; i < diagramXml.root.Items.Length; i++) { mxGraphModelRootObject item = new mxGraphModelRootObject(); Type objectType = typeof(mxGraphModelRootObject); if (diagramXml.root.Items[i].GetType() == objectType) { item = (mxGraphModelRootObject)diagramXml.root.Items[i]; } if (item.id == vertice.id) { item.label = vertice.label; int Component_Symbol_Id = getFromLegacyName(vertice.assetType).Component_Symbol_Id; item.mxCell.style = this.SetImage(Component_Symbol_Id, item.mxCell.style); item.internalLabel = vertice.label; item.HasUniqueQuestions = vertice.HasUniqueQuestions; item.Criticality = vertice.Criticality; item.Description = vertice.Description; item.HostName = vertice.HostName; diagramXml.root.Items[i] = (object)item; } } SaveDiagramXml(assessmentId, diagramXml); } catch (Exception ex) { var message = ex.Message; } finally { } }
/// <summary> /// Update fields of zone /// </summary> /// <param name="vertice"></param> /// <param name="assessmentId"></param> public void SaveZone(mxGraphModelRootObject vertice, int assessmentId) { try { var stream = GetDiagramXml(assessmentId); XmlSerializer serializer = new XmlSerializer(typeof(mxGraphModel)); var diagramXml = (mxGraphModel)serializer.Deserialize(stream); for (int i = 0; i < diagramXml.root.Items.Length; i++) { mxGraphModelRootObject item = new mxGraphModelRootObject(); Type objectType = typeof(mxGraphModelRootObject); if (diagramXml.root.Items[i].GetType() == objectType) { item = (mxGraphModelRootObject)diagramXml.root.Items[i]; } if (item.id == vertice.id) { item.label = vertice.label; item.zoneType = vertice.zoneType; item.SAL = vertice.SAL; item.internalLabel = vertice.label; diagramXml.root.Items[i] = (object)item; } } SaveDiagramXml(assessmentId, diagramXml); } catch (Exception ex) { var message = ex.Message; } finally { } }