Beispiel #1
0
        /// <summary>
        /// Method is used for creating ObjectWrapper. This method is created because 
        /// DateTime and TimeSpan types. When we transforming this two object
        /// we need to get only number of ticks from them. All other cases we just
        /// need to put object to Data property and object will be transformed in a right way.
        /// </summary>
        /// <param name="typeOfdata">Type of data object</param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ObjectWrapper CreateObjectWrapper(Object data)
        {
            ObjectWrapper ow = new ObjectWrapper();

            if(data == null)
            {
                ow.TypeName = null;
                ow.Data = null;
                return ow;
            }

            Type typeOfdata = data.GetType();
            ow.TypeName = TypeSingleton.ExtractPropertyType(typeOfdata);//typeOfdata.Name;

            if (typeOfdata.Equals(typeof(DateTime)) )
            {
                ow.Data = ((DateTime)data).Ticks;
            }
            else
            {
                if (typeOfdata.Equals(typeof(TimeSpan)))
                {
                    ow.Data = ((TimeSpan)data).Ticks;
                }
                else
                {
                    ow.Data = data;
                }
            }

            return ow;
        }
Beispiel #2
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!");
            }
        }