Пример #1
0
        private void BuildView()
        {
            var row = GetSelectedRow();
            var indicatorDescriptions = new List <IndicatorDescription>();
            var favorites             = owner.getFavoriteIndicators();

            for (var i = 0; i < indicators.Count; i++)
            {
                var indi         = indicators[i];
                var sources      = indi.SeriesSourcesDisplay == null ? new string[] {} : indi.SeriesSourcesDisplay.Split(new[] { ';' });
                var depends      = "";
                var dependErrors = "";
                foreach (var source in sources)
                {
                    if (!source.Contains('/'))
                    {
                        if (!string.IsNullOrEmpty(depends))
                        {
                            depends += "; ";
                        }
                        depends += source;
                        continue;
                    }
                    var sourceParams = source.Split(new[] { '/' });
                    if (sourceParams.Count() != 3)
                    {
                        if (!string.IsNullOrEmpty(dependErrors))
                        {
                            dependErrors += "; ";
                        }
                        dependErrors += Localizer.GetString("TitleSyntaxErrorSmall") + ": " + source;
                        continue;
                    }
                    var dependIndex = indicatorDescriptions.FindIndex(ind => ind.Name == sourceParams[0]);
                    if (dependIndex == -1)
                    {
                        if (!string.IsNullOrEmpty(dependErrors))
                        {
                            dependErrors += "; ";
                        }
                        dependErrors += sourceParams[0];
                        continue;
                    }
                    if (!string.IsNullOrEmpty(depends))
                    {
                        depends += "; ";
                    }
                    depends += indicatorDescriptions[dependIndex].Number;
                }
                if (!string.IsNullOrEmpty(dependErrors))
                {
                    depends = dependencyError + dependErrors;
                }
                indicatorDescriptions.Add(new IndicatorDescription(indi.UniqueName, null,
                                                                   favorites.Contains(indi.GetType().Name))
                {
                    TypeName        = indi.GetType().Name,
                    DisplayTypeName = indi.Name,
                    Number          = i + 1,
                    Depends         = depends
                });
            }
            fastGrid.DataBind(indicatorDescriptions);
            fastGrid.CheckSize();
            SelectRow(row);
            fastGrid.Invalidate();
        }
        private void FillIndicators()
        {
            var listIndis = new List <IndicatorDescription>();
            var favIndis  = owner.getFavoriteIndicators();

            foreach (var tp in PluginManager.Instance.typeIndicators)
            {
                var attrName =
                    Attribute.GetCustomAttributes(tp, true).FirstOrDefault(a => a is LocalizedDisplayNameAttribute) as
                    DisplayNameAttribute;
                if (attrName == null)
                {
                    attrName =
                        Attribute.GetCustomAttributes(tp, true).FirstOrDefault(a => a is DisplayNameAttribute) as
                        DisplayNameAttribute;
                }
                if (attrName == null)
                {
                    continue;
                }

                var attrCat =
                    Attribute.GetCustomAttributes(tp, true).FirstOrDefault(a => a is LocalizedCategoryAttribute) as
                    CategoryAttribute;
                if (attrCat == null)
                {
                    attrCat =
                        Attribute.GetCustomAttributes(tp, true).FirstOrDefault(a => a is CategoryAttribute) as
                        CategoryAttribute;
                }
                var catName = attrCat == null?Localizer.GetString("TitleMain") : attrCat.Category;

                var isFav = favIndis.Contains(tp.Name);

                listIndis.Add(new IndicatorDescription(attrName.DisplayName, catName, isFav)
                {
                    TypeName = tp.Name
                });
            }

            // прибайндить к гриду
            gridView.DataBind(listIndis);

            // записать в дерево
            foreach (var desc in listIndis)
            {
                var cat = string.IsNullOrEmpty(desc.Category) ? "-" : desc.Category;

                // найти или создать родительский узел для категории
                TreeNode node;
                var      parentNodes = treeView.Nodes.Find(cat, false);
                if (parentNodes.Length > 0)
                {
                    node = parentNodes[0];
                }
                else
                {
                    node = treeView.Nodes.Add(cat, cat);
                }

                // добавить узел
                var itemNode = node.Nodes.Add(desc.Name, desc.Name);
                itemNode.Tag = desc;
            }
        }