コード例 #1
0
        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            object typeGuid = e.Data.GetData(typeof(Guid));

            if (typeGuid == null)
            {
                return;
            }

            var filterType = FiltersHelper.GetFilterType((Guid)typeGuid);
            var filter     = (IFilter)filterType.Assembly.CreateInstance(filterType.FullName);

            graphControl1.AddFilter(filter);
        }
コード例 #2
0
        private static IFilter GetFilter(XElement filterNode)
        {
            // ReSharper disable PossibleNullReferenceException
            var typeGuid   = new Guid(filterNode.Attribute(GraphFileFormat.Ver_0_1.Node_Filter_TypeGuid).Value);
            var filterType = FiltersHelper.GetFilterType(typeGuid);
            var filter     = (IFilter)filterType.Assembly.CreateInstance(filterType.FullName);

            Debug.Assert(filter != null);
            filter.NodeGuid = new Guid(filterNode.Attribute(GraphFileFormat.Ver_0_1.Node_Filter_NodeGuid).Value);

            XAttribute nameAttribute = filterNode.Attribute(GraphFileFormat.Ver_0_1.Node_Filter_Name);

            if (nameAttribute != null)
            {
                filter.Name = nameAttribute.Value;
            }

            var filterPropertyNodes = filterNode.Elements(GraphFileFormat.Ver_0_1.Node_FilterProperty);

            foreach (XElement element in filterPropertyNodes)
            {
                var propertyName           = element.Attribute(GraphFileFormat.Ver_0_1.Node_FilterProperty_Name).Value;
                var propertyValueAttribute = element.Attribute(GraphFileFormat.Ver_0_1.Node_FilterProperty_Value);
                var propertyValue          = propertyValueAttribute != null ? propertyValueAttribute.Value : null;
                var filterProperty         = filter.Properties[propertyName];

                switch (filterProperty.Type)
                {
                case FilterPropertyType.String:
                case FilterPropertyType.Enum:
                    filterProperty.Value = propertyValue;
                    break;

                case FilterPropertyType.Integer:
                    filterProperty.Value = int.Parse(propertyValue, GraphFileFormat.Ver_0_1.NumberStyles);
                    break;

                case FilterPropertyType.Float:
                    filterProperty.Value = float.Parse(propertyValue, GraphFileFormat.Ver_0_1.NumberStyles);
                    break;

                case FilterPropertyType.Size:
                    var sizeParts = propertyValue.Split(',');
                    var width     = int.Parse(sizeParts[0], GraphFileFormat.Ver_0_1.NumberStyles);
                    var height    = int.Parse(sizeParts[1], GraphFileFormat.Ver_0_1.NumberStyles);
                    filterProperty.Value = new Size(width, height);
                    break;

                case FilterPropertyType.Point:
                    var pointParts = propertyValue.Split(',');
                    var x          = int.Parse(pointParts[0], GraphFileFormat.Ver_0_1.NumberStyles);
                    var y          = int.Parse(pointParts[1], GraphFileFormat.Ver_0_1.NumberStyles);
                    filterProperty.Value = new Point(x, y);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(filter);
            // ReSharper restore PossibleNullReferenceException
        }