예제 #1
0
        /// <summary>
        /// This method is used for getting Edge<Guid, EdgeData> from object that should be Edge.
        /// </summary>
        /// <param name="objectToParse">object that need to be transformed into Edge,
        /// if this is not possible this method throw an Exception</param>
        /// <returns>Edge<Guid, EdgeData> that represent transformed object from objectToParse.
        /// If objectToParse is null, this method will return null</returns>
        public static Edge <Guid, EdgeData> ParseEdge(Object objectToParse)
        {
            if (objectToParse == null)
            {
                return(null);
            }
            if (objectToParse is Dictionary <String, Object> )
            {
                Dictionary <String, Object> dictionaryToParse = objectToParse as Dictionary <String, Object>;
                if (dictionaryToParse.ContainsKey(TO_NODE_ID) && dictionaryToParse.ContainsKey(DATA))
                {
                    Guid     toNodeId = (Guid)ObjectWrapper.ParseObjectWrapper(dictionaryToParse[TO_NODE_ID]);
                    EdgeData edgeData = (EdgeData)EdgeDataWrapper.ParseEdgeData(dictionaryToParse[DATA]);

                    Edge <Guid, EdgeData> edge = new Edge <Guid, EdgeData>(toNodeId, edgeData);

                    return(edge);
                }
                else
                {
                    throw new Exception("Edge object is not formated in right way!");
                }
            }
            else
            {
                throw new Exception("Edge object is not formated in right way!");
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #4
0
        /// <summary>
        /// TransformeEdgeData is transforming EdgeData to EdgeDataWrapper
        /// </summary>
        /// <param name="edgeData">data that need to transformed</param>
        /// <returns></returns>
        public static EdgeDataWrapper TransformeEdgeData(EdgeData edgeData)
        {
            EdgeDataWrapper edgeDataWraped = new EdgeDataWrapper();

            edgeDataWraped.Flags    = edgeData.Flags;
            edgeDataWraped.Semantic = edgeData.Semantic;

            ObjectWrapper objectWithType = ObjectWrapper.CreateObjectWrapper(edgeData.Data);

            //type of object is needed so that clent know what is type of data that is received
            edgeDataWraped.Data = objectWithType;

            return(edgeDataWraped);
        }
예제 #5
0
 public KeyValueWrapper(EdgeDataWrapper key, EdgeWrapper value)
 {
     this.Key   = key;
     this.Value = value;
 }
예제 #6
0
 public KeyValueWrapper(EdgeDataWrapper key, EdgeWrapper value)
 {
     this.Key = key;
     this.Value = value;
 }
예제 #7
0
        /// <summary>
        /// TransformeEdgeData is transforming EdgeData to EdgeDataWrapper
        /// </summary>
        /// <param name="edgeData">data that need to transformed</param>
        /// <returns></returns>
        public static EdgeDataWrapper TransformeEdgeData(EdgeData edgeData)
        {
            EdgeDataWrapper edgeDataWraped = new EdgeDataWrapper();
            edgeDataWraped.Flags = edgeData.Flags;
            edgeDataWraped.Semantic = edgeData.Semantic;

            ObjectWrapper objectWithType = ObjectWrapper.CreateObjectWrapper(edgeData.Data);
            //type of object is needed so that clent know what is type of data that is received
            edgeDataWraped.Data = objectWithType;

            return edgeDataWraped;
        }
예제 #8
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!");
            }
        }