Beispiel #1
0
 /// <summary>
 /// This method is used for making EdgeWrapper object that can be sent on clint, from Edge<Guid, EdgeData>.
 /// </summary>
 /// <param name="edge">data that need to be sent to client</param>
 /// <returns>EdgeWrapper object that is prepared for sending</returns>
 public static EdgeWrapper TransformeEdge(Edge<Guid, EdgeData> edge)
 {
     EdgeWrapper edgeDataWraper = new EdgeWrapper();
     edgeDataWraper.ToNodeId = edge.ToNodeId;
     edgeDataWraper.Data = EdgeDataWrapper.TransformeEdgeData(edge.Data);
     return edgeDataWraper;
 }
Beispiel #2
0
        /// <summary>
        /// This method is used for transforming Node into NodeWrapper.
        /// </summary>
        /// <param name="node"> Node that need to be tranformed into NodeWrapper</param>
        /// <returns>NodeWrapper that is being result of transformation of Node</returns>
        public static NodeWrapper TransformeNode(Node <Guid, object, EdgeData> node)
        {
            if (node == null)
            {
                return(null);
            }
            NodeWrapper newNode = new NodeWrapper();

            newNode.Commited = node.Commited;
            newNode.NodeType = node.NodeType;
            newNode.Previous = node.Previous;

            ObjectWrapper newData = null;

            if (node.NodeType == NodeType.Type)
            {
                //getting name of type of node data.
                newData = ObjectWrapper.CreateObjectWrapper(node.Data);
                //this is needed because data contains string that is contain data that
                //identifies type in .NET. Because of that we need to change type of objectWrapper
                newData.TypeName = TypeSingleton.ExtractPropertyType(Type.GetType((String)node.Data));
                newNode.Data     = newData;
            }
            else
            {
                //getting type name of data, in case node.Data is null type will be null
                newData = ObjectWrapper.CreateObjectWrapper(node.Data);

                newNode.Data = newData;
            }

            foreach (KeyValuePair <Guid, object> item in node.Values)
            {
                //making ObjectWrapper from object
                ObjectWrapper ow = ObjectWrapper.CreateObjectWrapper(item.Value);
                //adding new Guid-ObjectWrapper pair into Values
                newNode.Values.Add(item.Key.ToString(), ow);
            }

            foreach (KeyValuePair <EdgeData, Edge <Guid, EdgeData> > item in node.Edges)
            {
                //getting type of key and value
                Type typeOfObject = item.Key.GetType();
                Type edgeDataType = typeof(EdgeData);
                if (typeOfObject.Equals(edgeDataType))
                {
                    EdgeDataWrapper edgeDataKey = EdgeDataWrapper.TransformeEdgeData(item.Key);

                    EdgeWrapper edgeWraper = EdgeWrapper.TransformeEdge(item.Value);

                    newNode.Edges.Add(new KeyValueWrapper(edgeDataKey, edgeWraper));
                }
                else
                {
                    throw new Exception("Unexpected type in node wraper!");
                }
            }
            return(newNode);
        }
Beispiel #3
0
        /// <summary>
        /// This method is used for making EdgeWrapper object that can be sent on clint, from Edge<Guid, EdgeData>.
        /// </summary>
        /// <param name="edge">data that need to be sent to client</param>
        /// <returns>EdgeWrapper object that is prepared for sending</returns>
        public static EdgeWrapper TransformeEdge(Edge <Guid, EdgeData> edge)
        {
            EdgeWrapper edgeDataWraper = new EdgeWrapper();

            edgeDataWraper.ToNodeId = edge.ToNodeId;
            edgeDataWraper.Data     = EdgeDataWrapper.TransformeEdgeData(edge.Data);
            return(edgeDataWraper);
        }
Beispiel #4
0
 public KeyValueWrapper(EdgeDataWrapper key, EdgeWrapper value)
 {
     this.Key   = key;
     this.Value = value;
 }
Beispiel #5
0
 public KeyValueWrapper(EdgeDataWrapper key, EdgeWrapper value)
 {
     this.Key = key;
     this.Value = value;
 }
Beispiel #6
0
        /// <summary>
        /// This method is used for parsing object into SortedList<EdgeData, Edge<Guid, EdgeData>>.
        /// SortedList<EdgeData, Edge<Guid, EdgeData>> is used for representing Edges in node.
        /// </summary>
        /// <param name="objectToParse">object that need to be transformed into
        /// SortedList<EdgeData, Edge<Guid, EdgeData>></param>
        /// <returns>SortedList<EdgeData, Edge<Guid, EdgeData>>, or if somthing is not right throws an Exception</returns>
        public static SortedList <EdgeData, Edge <Guid, EdgeData> > ParseEdges(Object objectToParse)
        {
            SortedList <EdgeData, Edge <Guid, EdgeData> > edges = new SortedList <EdgeData, Edge <Guid, EdgeData> >();

            if (objectToParse == null)
            {
                return(edges);
            }
            Dictionary <String, Object> dictiomaryToParse = objectToParse as Dictionary <String, Object>;

            if (dictiomaryToParse.ContainsKey(ARRAY) && (dictiomaryToParse)[ARRAY] is Object[])
            {
                Object[] tempArray = (dictiomaryToParse)[ARRAY] as Object[];

                //case when there is not Edges in array
                if (tempArray.Length == 0)
                {
                    return(edges);
                }

                foreach (Object o in tempArray)
                {
                    //transforming object into dictionary
                    if (o is Dictionary <String, Object> )
                    {
                        var tempDictionaryO = o as Dictionary <String, Object>;

                        // tempDictionaryO should continas KEY and VALUE
                        if (tempDictionaryO.ContainsKey(KEY) && tempDictionaryO.ContainsKey(VALUE))
                        {
                            Object objectEdgeData = tempDictionaryO[KEY];
                            if (objectEdgeData == null)
                            {
                                continue;
                            }

                            EdgeData edgeData          = EdgeDataWrapper.ParseEdgeData(objectEdgeData);
                            Object   objectEdge        = tempDictionaryO[VALUE];
                            Edge <Guid, EdgeData> edge = null;

                            if (objectEdge == null)
                            {
                                edges.Add(edgeData, null);
                            }
                            else
                            {
                                edge = EdgeWrapper.ParseEdge(objectEdge);
                            }
                            //add new edge into edges dictionary
                            edges.Add(edgeData, edge);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                return(edges);
            }
            else
            {
                throw new Exception("Object is not formated right!");
            }
        }