示例#1
0
文件: CCTests.cs 项目: kbdnr/Audiot
        public void XMLDeserialize()
        {
            ControlChanges cc   = null;
            string         path = @"C:\Users\sped\source\repos\audiot\AudiotLogic\ControlConfigs\sh01a.xml";

            XmlSerializer serializer = new XmlSerializer(typeof(ControlChanges));

            StreamReader reader = new StreamReader(path);

            cc = (ControlChanges)serializer.Deserialize(reader);
            reader.Close();
        }
        public MasterDetailView()
        {
            var outputChanges = SelectChanges(nameof(Output)).Where(obj => obj != null);

            //Dictionary<Type, object> dict = new Dictionary<Type, object>();
            outputChanges
            .CombineLatest(SelectChanges <string>(nameof(Id)).StartWith(Id), (a, b) => (a, b))
            .Select(vm =>
            {
                var id = vm.a.GetType().GetProperty(vm.b).GetValue(vm.a).ToString();
                return(id);
            }).Subscribe(NameChanges);

            outputChanges
            .CombineLatest(SelectChanges <IValueConverter>(nameof(DataConverter)).StartWith(default(IValueConverter)), (a, b) => (a, b))
            .SubscribeOn(TaskPoolScheduler.Default)
            .ObserveOnDispatcher()
            .Subscribe(collConv => Dispatcher.InvokeAsync(() =>
            {
                Convert(collConv.a, collConv.b, (items, conv) => conv.Convert(collConv.a, null, null, null) as IEnumerable);
            }, DispatcherPriority.Normal));

            SelectChanges <PropertyGroupDescription>().StartWith(PropertyGroupDescription)
            .CombineLatest(ControlChanges.Where(c => c.GetType() == typeof(DockPanel)).Take(1), (pgd, DockPanel) => (pgd, DockPanel)).Subscribe(_ =>
            {
                if ((_.DockPanel as DockPanel)?.FindResource("GroupedItems") is CollectionViewSource collectionViewSource)
                {
                    collectionViewSource.GroupDescriptions.Add(_.pgd);
                }
            });

            GroupClick = new Command.RelayCommand <string>(a => GroupNameChanges.OnNext(a));

            NameChanges
            .Merge(GroupNameChanges)
            .CombineLatest(ControlChanges.Select(c => c as TextBlock).Where(c => c != null),

                           (text, textBlock) => (text, textBlock))
            .ObserveOnDispatcher()
            .Subscribe(input =>
            {
                input.textBlock.Text       = input.text;
                input.textBlock.Visibility = Visibility.Visible;
                input.textBlock.IsEnabled  = true;
                input.textBlock.IsEnabled  = false;
            });

            GroupNameChanges.CombineLatest(
                SelectChanges <PropertyGroupDescription>().StartWith(PropertyGroupDescription),
                SelectChanges <IValueConverter>(nameof(DataConverter)).StartWith(default(IValueConverter)),
                SelectChanges <string>(nameof(Id)).StartWith(Id),
                (text, pg, conv, id) => (text, pg, conv, id))
            //.ObserveOn(TaskPoolScheduler.Default)
            .Subscribe(async input =>
            {
                await Dispatcher.InvokeAsync(() =>
                {
                    var paths = Items.Cast <object>();
                    var prop  = paths.First().GetType().GetProperty(input.pg.PropertyName);

                    // property-group-converter
                    var converter = input.pg.Converter;

                    var group = paths.Where(ad =>
                    {
                        bool result = converter != default ?
                                      input.text
                                      .Equals(converter.Convert(prop.GetValue(ad), null, null, null)) :
                                      input.text
                                      .Equals(prop.GetValue(ad));
                        return(result);
                    })
                                .Select(viewmodel =>
                                        new Property.KeyValue(
                                            viewmodel.GetType().GetProperty(input.id).GetValue(viewmodel).ToString(),
                                            viewmodel));
                    Convert(group, input.conv, (items, conv) => conv.Convert(items, null, null, null));
                }, DispatcherPriority.Background);
            });

            ContentTemplateSelector = new PropertyDataTemplateSelector();
        }