示例#1
0
 public void AddTopic(Topic t)
 {
     t.parentName = this.Name;
     this.Topics.Add(t);
 }
示例#2
0
        /*
         * Gets all the sub-categories (or topics?) of jt, and hangs them under node?
         */
        //private static void decipherAreasJSON(JToken jt, Node node)
        private static void decipherAreasJSON(JToken jt, Category group)
        {
            if (jt is JProperty)
            {
                if (jt.ToObject<JProperty>().Name != IFIXIT_CATEGORY_OBJECT_KEY)
                {
            //                    Debug.WriteLine(" " + jt.ToObject<JProperty>().Name);

                    // since it's not a device, it must be a group
                    //Node curr = new Node(jt.ToObject<JProperty>().Name, new List<Node>());
                    Category curr = new Category(jt.ToObject<JProperty>().Name);

                    //FIXME this is where we add to the 1:M, right?
                    //group.Categories.Add(curr);
                    group.AddCategory(curr);
                    curr.Parent = group;
                    curr.parentName = group.Name;
                    if (jt.HasValues)
                    {
                        IJEnumerable<JToken> values = jt.Values();
                        foreach (JToken val in values)
                        {
                            decipherAreasJSON(val, curr);
                        }
                    }
                }
                // these are devices
                else
                {
                    IJEnumerable<JToken> devs = jt.Values();
                    foreach (JToken dev in devs)
                    {
                        Topic d = new Topic();
                        d.Name = dev.ToString();
                        /*
                        if (group.Devices == null)
                        {
                            group.Devices = new List<Topic>();
                        }
                         */
                        //group.Topics.Add(d);
                        group.AddTopic(d);
                        d.Parent = group;
                        d.parentName = group.Name;

                        //node.getChildrenList().Add(new Node(dev.ToString(), null));
            //                        Debug.WriteLine("  " + dev.ToString());
                    }
                }
            }
            else
            {
                // can currently safely ignore anything in this category
            //                Debug.WriteLine("\n" + jt.ToString() + " not a property\n");
            }
        }
示例#3
0
        /*
         * Insert the data from the JSON parser into the database
         */
        private bool insertDevInfoIntoDB(DeviceInfoHolder devInfo)
        {
            //something is wrong and the device was not found. Bail
            if (devInfo == null)
            {
                Debug.WriteLine("something went terribly wrong with a DeviceInfo. Bailing");
                NavigationService.GoBack();
                return false;
            }

            Topic top = null;
            Debug.WriteLine("putting device info into DB...");

            //try to get a topic of this name from the DB
            //if it fails, make a new one. if it works, update the old
            using (iFixitDataContext db = new iFixitDataContext(App.DBConnectionString))
            {
                bool gotTopicFromDB = true;
                top = DBHelpers.GetCompleteTopic(devInfo.topic_info.name, db);

                if (top == null)
                {
                    top = new Topic();
                    gotTopicFromDB = false;
                }

                //translate devInfo in a Topic()
                //name is already the same
                top.Name = devInfo.topic_info.name;
                top.parentName = devInfo.title;
                top.Contents = devInfo.description;
                top.ImageURL = devInfo.image.text + ".medium";
                top.Populated = true;

                //TODO inject metatdata here like # answers
                top.Description = "";
                top.Description += prepHTML(devInfo.contents, devInfo);

                //now do the same for all attached guides
                foreach (DIGuides g in devInfo.guides)
                {
                    Debug.WriteLine("\tguide " + g.title);

                    //search if the guide already exists, and get or update it
                    Guide gOld = new Guide();
                    gOld.FillFieldsFromDeviceInfo(navTopicName, g);
                    gOld = db.GuidesTable.FirstOrDefault(other => other.GuideID == gOld.GuideID);
                    if (gOld == null)
                    {
                        gOld = new Guide();
                        db.GuidesTable.InsertOnSubmit(gOld);
                    }

                    gOld.FillFieldsFromDeviceInfo(navTopicName, g);

                    // hang it below the topic, it its collection of guides
                    top.AddGuide(gOld);

                    //FIXME do we need to specifically add this to the guide table? is that magic?
                    db.SubmitChanges();
                }

                if (!gotTopicFromDB)
                {
                    db.TopicsTable.InsertOnSubmit(top);
                }

                //update the Topic() into the database
                db.SubmitChanges();

                //force the view model to update
                infoVM.UpdateData();
                updateInfoBrowser();

                //force the views to update
                this.InfoStack.DataContext = infoVM;
                this.GuidesStack.DataContext = infoVM;

                //disable the loading bars
                this.LoadingBarInfo.Visibility = System.Windows.Visibility.Collapsed;
                this.LoadingBarGuides.Visibility = System.Windows.Visibility.Collapsed;

            }

            return true;
        }