Пример #1
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");
            }
        }
Пример #2
0
        /*
         * Called right as we are being navigated to
         */
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            Debug.WriteLine("A MagicPivot has been navigated to...");

            string navParentName = NavigationContext.QueryString[App.MagicParentTag];
            Debug.WriteLine("Looking for Key: " + navParentName);

            if (PhoneApplicationService.Current.State.ContainsKey(navParentName))
                this.thisCat = (Category)PhoneApplicationService.Current.State[navParentName];
            Debug.WriteLine("Saving in current.state: " + this.thisCat);
            Debug.WriteLine("I'm going to try to pull a category out: " + thisCat.Name);

            setupBinding(thisCat);
            string key = vm.selectedCategory.Name;
            if (key != null && this.State.ContainsKey(key))
            {
                int selectedTabIndex = (int)this.State[key];
                if (0 <= selectedTabIndex && selectedTabIndex < vm.Columns.Count)
                {
                    SmartPivot.SelectedIndex = selectedTabIndex;
                }
            }
        }
Пример #3
0
            public ColumnContent(Category c)
            {
                this.colCat = c;
                this.ColumnHeader = c.Name;

                ColContent = new List<InnerColumnContent>();

                TypeRefs = new Dictionary<string, string>();
            }
Пример #4
0
        //public MagicPivotViewModel(string pName, string selName, Pivot sp)
        public MagicPivotViewModel(Category selectedCategory, Pivot sp)
        {
            TabIndex = 0;
            Columns = new List<ColumnContent>();

            //this.ParentName = pName;
            //this.SelectedName = selName;
            this.selectedCategory = selectedCategory;

            myPivot = sp;

            Debug.WriteLine("Current category is " + this.selectedCategory.Name + " who's parent is " + this.selectedCategory.Parent.Name);
            //Debug.WriteLine("Made a new MagicPivot View Model with parent = " + pName + " & cur = " + selName);

            //force all data to update
            //if (ParentName != "" && Columns.Count == 0)
            if (Columns.Count == 0)
                UpdateData();
        }
Пример #5
0
        private void setupBinding(Category c)
        {
            //instantiate view model
            vm = new MagicPivotViewModel(c, SmartPivot);

            this.DataContext = vm;
            vm.Columns[vm.TabIndex].setColumnContent();
            SmartPivot.LoadingPivotItem += new EventHandler<PivotItemEventArgs>(SmartPivot_LoadingPivotItem);
        }
Пример #6
0
        //the callback hook that gets fired when the area hierarchy is finally retreived
        public void App_callAreasAPI(Category tree)
        {
            var _Worker = new BackgroundWorker();
            _Worker.DoWork += (s, e) =>
            {
                if (tree == null)
                {
                    //FIXME not sure this is what we really want to do...
                    return;
                }

                Debug.WriteLine("we got a tree, right? PROCESS IT");

                root = tree;

                //now async get images for all root categories
                List<Category> cats = root.Categories;
                thumbCount = 0;
                foreach (Category c in cats)
                {
                    Debug.WriteLine("thumb = " + c.Thumbnail);
                    if (c.Thumbnail == "")
                    {
                        ++thumbCount;
                        new JSONInterface2().populateDeviceInfo(c.Name, storeJSONCategoryInDB);
                    }
                }

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MainPage m = RootFrame.Content as MainPage;
                    if (m != null)
                        m.initDataBinding();
                });
            };
            _Worker.RunWorkerCompleted += (s, e) =>
            {
                if (thumbCount == 0)
                {
                    (RootFrame.Content as MainPage).StopLoadingIndication();
                    PhoneApplicationService.Current.State[LoadingScreenShown] = true;
                }
            };
            _Worker.RunWorkerAsync();
        }
Пример #7
0
        private void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            try
            {
                using (var reader = new StreamReader(e.Result))
                {
                    jsonResponse = reader.ReadToEnd();
                    JObject jo = JObject.Parse(jsonResponse);

                    //NO! This causes queries for 'root''s chilren to return 'root' as well
                    //mRootGroup.parentName = mRootGroup.Name;

                    //if we are processing a categories call (always yes now?)
                    if (categories)
                    {
                        IEnumerable<JProperty> props = jo.Properties();
                        foreach (JProperty p in props)
                        {
                            // You found a leaf node
                            if (p.Name.Equals(IFIXIT_CATEGORY_OBJECT_KEY))
                            {
                                break;
                            }
                            Category curr = new Category(p.Name);

                            mRootGroup.AddCategory(curr);
                            curr.Parent = mRootGroup;
                            curr.parentName = mRootGroup.Name;
                            //mRootGroup.Categories.Add(curr);

                            if (!p.HasValues)
                                break;
                            IJEnumerable<JToken> values = p.Values();
                            foreach (JToken t in values)
                            {
                                decipherAreasJSON(t, curr);
                            }
                        }
                    }

                    this.callAreasAPI.Invoke(mRootGroup);
                }
            }
            catch (WebException we)
            {
                //there was an exception using the internet connection. Return null
                this.callAreasAPI.Invoke(null);
            }
            catch (Newtonsoft.Json.JsonReaderException je)
            {
                this.callAreasAPI.Invoke(null);
            }
        }
Пример #8
0
 public void AddCategory(Category c)
 {
     c.parentName = this.Name;
     this.Categories.Add(c);
 }