Exemplo n.º 1
0
        /// <summary>
        /// This method is used for getting EdgeData from object that should be EdgeData.
        /// </summary>
        /// <param name="objectToParse">object that need to be transformed to EdgeData</param>
        /// <returns>EdgeData that was in form of object</returns>
        public static EdgeData ParseEdgeData(Object objectToParse)
        {
            if (objectToParse == null)
            {
                return(null);
            }

            if (objectToParse is Dictionary <String, Object> )
            {
                Dictionary <String, Object> dictionaryRepresentationOfObject = (Dictionary <String, Object>)objectToParse;

                if (dictionaryRepresentationOfObject.ContainsKey(FLAGS) &&
                    dictionaryRepresentationOfObject.ContainsKey(SEMANTIC) &&
                    dictionaryRepresentationOfObject.ContainsKey(DATA))
                {
                    int       flagsValue = (int)dictionaryRepresentationOfObject[FLAGS];
                    EdgeType  semnatic   = (EdgeType)dictionaryRepresentationOfObject[SEMANTIC];
                    EdgeFlags flags      = (EdgeFlags)flagsValue;
                    Object    data       = ObjectWrapper.ParseObjectWrapper(dictionaryRepresentationOfObject[DATA]);
                    EdgeData  edgeData   = new EdgeData(semnatic, flags, data);
                    return(edgeData);
                }
                else
                {
                    throw new Exception("Object is not formated right!");
                }
            }
            else
            {
                throw new Exception("Object is not formated right!");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Making KeyValuePair from objects that are representing Guid, and Object.
        /// </summary>
        /// <param name="key">object that is containing Guid data</param>
        /// <param name="value">object that is containing Object data</param>
        /// <returns></returns>
        public static KeyValuePair <Guid, Object> ParseValues(Object key, Object value)
        {
            //in case key is null, that should not happend
            if (key == null)
            {
                throw new ArgumentNullException();
            }
            try
            {
                Guid rezKey = (Guid)ObjectWrapper.ParseObjectWrapper(key);

                Object rezValue = ObjectWrapper.ParseObjectWrapper(value);

                //case when some data is not formated in right way
                if (rezKey == null || rezKey == Guid.Empty || rezValue == null)
                {
                    throw new ArgumentNullException();
                }

                return(new KeyValuePair <Guid, object>(rezKey, rezValue));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 3
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!");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// ParseNode is method that is trying to transform an object into Node object
        /// </summary>
        /// <param name="objectToParse"> object that needs to be transformed</param>
        /// <returns>Node object or is throwing an Exception</returns>
        public static Node <Guid, Object, EdgeData> ParseNode(Object objectToParse)
        {
            if (objectToParse is Dictionary <String, Object> )
            {
                Dictionary <String, Object> nodeRepresentation = objectToParse as Dictionary <String, Object>;

                //checking if there is everything in objectToParse that should be there
                if (nodeRepresentation.ContainsKey(PREVIOUS) &&
                    nodeRepresentation[PREVIOUS] is Dictionary <string, object> &&
                    nodeRepresentation.ContainsKey(COMMITED) &&
                    nodeRepresentation[COMMITED] is Boolean &&
                    nodeRepresentation.ContainsKey(NODE_TYPE) &&
                    nodeRepresentation[NODE_TYPE] is int &&
                    nodeRepresentation.ContainsKey(DATA) &&
                    nodeRepresentation.ContainsKey(VALUES) &&
                    nodeRepresentation[VALUES] is Dictionary <String, Object> &&
                    nodeRepresentation.ContainsKey(EDGES))
                {
                    //getting Guid of previous Node
                    Dictionary <string, object> previousDict = nodeRepresentation[PREVIOUS] as Dictionary <string, object>;
                    if (previousDict.ContainsKey(VALUE) && previousDict[VALUE] is String)
                    {
                        Guid previous = new Guid(previousDict[VALUE] as String);
                    }
                    else
                    {
                        throw new Exception("Object is not formated in right way! Previous Guid is missing!");
                    }

                    Boolean  commited = (Boolean)nodeRepresentation[COMMITED];
                    NodeType nodeType = (NodeType)((int)nodeRepresentation[NODE_TYPE]);

                    Object data = ObjectWrapper.ParseObjectWrapper(nodeRepresentation[DATA]);
                    Dictionary <Guid, Object> values = new Dictionary <Guid, object>();

                    //getting Dictionary that is contining Values dictionary
                    Dictionary <String, Object> valuesDict = (Dictionary <String, Object>)nodeRepresentation[VALUES];

                    if (valuesDict.ContainsKey(ARRAY) && valuesDict[ARRAY] is Object[])
                    {
                        Object[] tempList = (Object[])valuesDict[ARRAY];

                        foreach (Object o in tempList)
                        {
                            if (o is Dictionary <String, object> )
                            {
                                Dictionary <String, object> tempDict = o as Dictionary <String, object>;

                                if (tempDict.ContainsKey(KEY) && tempDict.ContainsKey(VALUE))
                                {
                                    Guid   key   = (Guid)ObjectWrapper.ParseObjectWrapper(tempDict[KEY]);
                                    Object value = ObjectWrapper.ParseObjectWrapper(tempDict[VALUE]);

                                    values.Add(key, value);
                                }
                            }
                            else
                            {
                                throw new Exception("Object is not formated in right way!");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Object is not formated in right way!");
                    }

                    Object edges = nodeRepresentation[EDGES];

                    SortedList <EdgeData, Edge <Guid, EdgeData> > edgesSortedList = NodeWrapper.ParseEdges(edges);
                    Node <Guid, Object, EdgeData> serverNode = new Node <Guid, object, EdgeData>(nodeType, data, edgesSortedList, values);
                    return(serverNode);
                }
                else
                {
                    throw new Exception("Object is not formated in right way!");
                }
            }
            else
            {
                throw new Exception("Object is not formated in right way!");
            }
        }