Ejemplo n.º 1
0
        public void loadProjectTree(Project project, ValispaceAPI valispace)
        {
            var componentById = new Dictionary <Int64, Dictionary <string, object> >();
            var valiById      = new Dictionary <Int64, Dictionary <string, object> >();
            var roots         = new List <Dictionary <string, object> >();

            Component processDatasetTree(Dictionary <string, object> root)
            {
                var TopItem   = new TreeViewItem();
                var component = new Component()
                {
                    Name  = (string)root["name"],
                    Id    = (Int64)root["id"],
                    Items = new List <object>(),
                };

                TopItem.Header = component.Name;
                Dictionary <string, object> comp_root = valispace.getComponent(component.Id);

                if (comp_root.ContainsKey("valis"))
                {
                    var  valis      = (Newtonsoft.Json.Linq.JArray)comp_root["valis"];
                    bool containsDS = false;
                    if (valis != null)
                    {
                        foreach (var vali in valis)
                        {
                            var valiId   = (Int64)vali;
                            var valiData = valiById[valiId];
                            if ((string)valiData["path"] == "DataSets")
                            {
                                DataSet thisDataSet = new DataSet()
                                {
                                    Name   = (string)valiData["name"],
                                    parent = component,
                                    //dataset_ID = (Int64)valiData["datasets"],
                                    vali_ID = valiId
                                };
                                TreeViewItem itemVali = new TreeViewItem();
                                itemVali.Header = thisDataSet.Name;

                                containsDS = true;
                                TopItem.Items.Add(itemVali);
                                if (!allDataSets.ContainsKey(thisDataSet.Name))
                                {
                                    allDataSets.Add(thisDataSet.Name, thisDataSet);
                                    allDataSetsbyID.Add(thisDataSet.vali_ID, thisDataSet);
                                }
                            }
                        }
                    }
                    if (containsDS)
                    {
                        m_ValiDSTree.Items.Add(TopItem);
                    }
                }

                if (root.ContainsKey("children"))
                {
                    var children = (Newtonsoft.Json.Linq.JArray)root["children"];

                    if (children != null)
                    {
                        foreach (var child in children)
                        {
                            var componentId   = (Int64)child;
                            var componentData = componentById[componentId];

                            component.Items.Add(processDatasetTree(componentData));
                        }
                    }
                }



                return(component);
            }

            var projectComponents = valispace.getComponents(project.Id, project.Name);
            var projectValis      = valispace.getValis(project.Id);

            foreach (var vali in projectValis)
            {
                valiById.Add((Int64)vali["id"], vali);
            }

            var items = new List <Component>();

            foreach (var component in projectComponents)
            {
                if (component["parent"] == null)
                {
                    roots.Add(component);
                }
                else
                {
                    componentById.Add((Int64)component["id"], component);
                }
            }



            foreach (var root in roots)
            {
                items.Add(processDatasetTree(root));
            }

            //valiTree_XAML.Items.Add(items);
            //DataSet_Tree.ItemsSource = items;
            //TreeViewItem item = DataSet_Tree.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem;
            //item.IsExpanded = true;
            //((TreeViewItem)projectTree.Items[0]).IsExpanded = true;
        }
Ejemplo n.º 2
0
        public void loadProjectTree(Project project)
        {
            var componentById = new Dictionary <Int64, Dictionary <string, object> >();
            var valiById      = new Dictionary <Int64, Dictionary <string, object> >();
            var roots         = new List <Dictionary <string, object> >();

            // var componentChildren = new Dictionary<Int64, List<Dictionary<string, object>>>();

            Component processComponent(Dictionary <string, object> root)
            {
                var component = new Component()
                {
                    Name  = (string)root["name"],
                    Items = new List <object>(),
                };
                Dictionary <string, object> comp_root = valispace.getComponent((Int64)root["id"]);

                if (comp_root.ContainsKey("valis"))
                {
                    //var valis = (Newtonsoft.Json.Linq.JArray)root["valis"];
                    var valis = (Newtonsoft.Json.Linq.JArray)comp_root["valis"];

                    if (valis != null)
                    {
                        foreach (var vali in valis)
                        {
                            var valiId   = (Int64)vali;
                            var valiData = valiById[valiId];
                            if ((string)valiData["path"] != "DataSets")
                            {
                                Vali thisVali = new Vali()
                                {
                                    Name  = (string)valiData["name"],
                                    Value = (double)valiData["value"],
                                    unit  = (string)valiData["unit"],
                                    Id    = valiId
                                };
                                component.Items.Add(thisVali);
                                allValis.Add(thisVali.Name, thisVali);
                                allValisbyID.Add(thisVali.Id.ToString(), thisVali);
                            }
                        }
                    }
                }

                if (root.ContainsKey("children"))
                {
                    var children = (Newtonsoft.Json.Linq.JArray)root["children"];

                    if (children != null)
                    {
                        foreach (var child in children)
                        {
                            var componentId   = (Int64)child;
                            var componentData = componentById[componentId];

                            component.Items.Add(processComponent(componentData));
                        }
                    }
                }



                return(component);
            }

            var projectComponents = valispace.getComponents(project.Id, project.Name);
            var projectValis      = valispace.getValis(project.Id);

            foreach (var vali in projectValis)
            {
                valiById.Add((Int64)vali["id"], vali);
            }

            var items = new List <Component>();

            foreach (var component in projectComponents)
            {
                if (component["parent"] == null)
                {
                    roots.Add(component);
                }
                else
                {
                    componentById.Add((Int64)component["id"], component);
                }
            }



            foreach (var root in roots)
            {
                items.Add(processComponent(root));
            }

            projectTree.ItemsSource = items;
            TreeViewItem item = projectTree.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem;
            //item.IsExpanded = true;
            //((TreeViewItem)projectTree.Items[0]).IsExpanded = true;
        }