Ejemplo n.º 1
0
        bool InstantiateTeacher(dynamic dataDict, Tuple<string, string> when_id)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            mLogger.Log(methodName, "", 3);

            bool success = true;

            Teacher teacher = new Teacher();
            Credentials credentials = new Credentials();
            PersonName pName = new PersonName();
            Google_apps gApps = new Google_apps();

            // Get each dp (datapoint) found in dataDict
            foreach (KeyValuePair<string, dynamic> dpParent in dataDict)
            {
                if (dpParent.Value != null)
                {
                    Type valueType = dpParent.Value.GetType();
                    if (valueType.IsGenericType)
                    {
                        // This value item is not just another string value but (probably) another dictionary
                        Type baseType = valueType.GetGenericTypeDefinition();
                        if (baseType == typeof(Dictionary<,>))
                        {
                            mLogger.Log(methodName, string.Format("Getting data for Key: {0}", dpParent.Key), 3);
                            foreach (KeyValuePair<string, dynamic> dpChild in dpParent.Value)
                            {
                                mLogger.Log(methodName, string.Format("Key: {0}     Value: {1}", dpChild.Key, dpChild.Value), 3);

                                if (dpParent.Key == "credentials")
                                {
                                    PropertyInfo pi = credentials.GetType().GetProperty(dpChild.Key);
                                    ValidateClassProperty(pi, dpChild.Key, "Credentials");
                                    pi.SetValue(credentials, Convert.ChangeType(dpChild.Value, pi.PropertyType), null);
                                }
                                else if (dpParent.Key == "name")
                                {
                                    PropertyInfo pi = pName.GetType().GetProperty(dpChild.Key);
                                    ValidateClassProperty(pi, dpChild.Key, "PersonName");
                                    pi.SetValue(pName, Convert.ChangeType(dpChild.Value, pi.PropertyType), null);
                                }
                                else if (dpParent.Key == "google_apps")
                                {
                                    PropertyInfo pi = gApps.GetType().GetProperty(dpChild.Key);
                                    ValidateClassProperty(pi, dpChild.Key, "Google_apps");
                                    pi.SetValue(gApps, Convert.ChangeType(dpChild.Value, pi.PropertyType), null);
                                }
                            }
                        }
                    }
                    else if (valueType.Name == "String")
                    {
                        mLogger.Log(methodName, string.Format("Key: {0}     Value: {1}", dpParent.Key, dpParent.Value), 3);

                        PropertyInfo pi = teacher.GetType().GetProperty(dpParent.Key);
                        ValidateClassProperty(pi, dpParent.Key, "Teacher");
                        pi.SetValue(teacher, Convert.ChangeType(dpParent.Value, pi.PropertyType), null);
                    }
                }
            }
            //  check whether we are instantiating for event data and if so, set event_type and id
            if (when_id.Item1 == "current_attributes")
            {
                teacher.event_type = when_id.Item1;
            }
            else if (when_id.Item1 == "previous_attributes")
            {
                teacher.event_type = when_id.Item1;
                teacher.id = when_id.Item2;
            }

            teacher.credentials = credentials;
            teacher.name = pName;
            teacher.google_apps = gApps;
            mWrappedData.Teachers.Add(teacher);

            return success;
        }
Ejemplo n.º 2
0
        bool InstantiateTeacher(dynamic dataDict, Tuple <string, string> when_id)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            mLogger.Log(methodName, "", 3);

            bool success = true;

            Teacher     teacher     = new Teacher();
            Credentials credentials = new Credentials();
            PersonName  pName       = new PersonName();
            Google_apps gApps       = new Google_apps();

            // Get each dp (datapoint) found in dataDict
            foreach (KeyValuePair <string, dynamic> dpParent in dataDict)
            {
                if (dpParent.Value != null)
                {
                    Type valueType = dpParent.Value.GetType();
                    if (valueType.IsGenericType)
                    {
                        // This value item is not just another string value but (probably) another dictionary
                        Type baseType = valueType.GetGenericTypeDefinition();
                        if (baseType == typeof(Dictionary <,>))
                        {
                            mLogger.Log(methodName, string.Format("Getting data for Key: {0}", dpParent.Key), 3);
                            foreach (KeyValuePair <string, dynamic> dpChild in dpParent.Value)
                            {
                                mLogger.Log(methodName, string.Format("Key: {0}     Value: {1}", dpChild.Key, dpChild.Value), 3);

                                if (dpParent.Key == "credentials")
                                {
                                    PropertyInfo pi = credentials.GetType().GetProperty(dpChild.Key);
                                    ValidateClassProperty(pi, dpChild.Key, "Credentials");
                                    pi.SetValue(credentials, Convert.ChangeType(dpChild.Value, pi.PropertyType), null);
                                }
                                else if (dpParent.Key == "name")
                                {
                                    PropertyInfo pi = pName.GetType().GetProperty(dpChild.Key);
                                    ValidateClassProperty(pi, dpChild.Key, "PersonName");
                                    pi.SetValue(pName, Convert.ChangeType(dpChild.Value, pi.PropertyType), null);
                                }
                                else if (dpParent.Key == "google_apps")
                                {
                                    PropertyInfo pi = gApps.GetType().GetProperty(dpChild.Key);
                                    ValidateClassProperty(pi, dpChild.Key, "Google_apps");
                                    pi.SetValue(gApps, Convert.ChangeType(dpChild.Value, pi.PropertyType), null);
                                }
                            }
                        }
                    }
                    else if (valueType.Name == "String")
                    {
                        mLogger.Log(methodName, string.Format("Key: {0}     Value: {1}", dpParent.Key, dpParent.Value), 3);

                        PropertyInfo pi = teacher.GetType().GetProperty(dpParent.Key);
                        ValidateClassProperty(pi, dpParent.Key, "Teacher");
                        pi.SetValue(teacher, Convert.ChangeType(dpParent.Value, pi.PropertyType), null);
                    }
                }
            }
            //  check whether we are instantiating for event data and if so, set event_type and id
            if (when_id.Item1 == "current_attributes")
            {
                teacher.event_type = when_id.Item1;
            }
            else if (when_id.Item1 == "previous_attributes")
            {
                teacher.event_type = when_id.Item1;
                teacher.id         = when_id.Item2;
            }

            teacher.credentials = credentials;
            teacher.name        = pName;
            teacher.google_apps = gApps;
            mWrappedData.Teachers.Add(teacher);

            return(success);
        }