Пример #1
0
        /// <summary>
        /// Remove all pages with PageKind == PageKind.Proxy.
        /// </summary>
        private void ClearProxies()
        {
            //clear proxies
            var deletePageData = PagesData.Where(x => x.Kind == PageKind.Proxy);
            var deleteObjects  = deletePageData.Select(x => x.NavData);

            _context.Send((s) =>
            {
                TopItemSource.RemoveAll(x => deleteObjects.Contains(x));
            }, null);

            PagesData.RemoveAll(x => x.Kind == PageKind.Proxy);
        }
Пример #2
0
        private void OnProxiesCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                foreach (var el in e.NewItems)
                {
                    if (el is IChannelProxy proxy)
                    {
                        //recievePage
                        RecieveChannelPage recievePage = null;
                        _context.Send((s) =>
                        {
                            recievePage             = new RecieveChannelPage();
                            recievePage.DataContext = new RecieveChannelPageVM(proxy);
                        }, null);

                        ContentPageData recievePageData = new ContentPageData(new NavMenuItemData()
                        {
                            IsDropdownItem = false, IsSelected = false
                        },
                                                                              "#NavMenuRecieveProxyPage",
                                                                              "RecievedProxyPageIcon",
                                                                              PageKind.Proxy,
                                                                              recievePage,
                                                                              ChangePage);
                        PagesData.Add(recievePageData);


                        //monitorPage
                        MonitorChannelPage monitorPage = null;
                        _context.Send((s) =>
                        {
                            monitorPage             = new MonitorChannelPage();
                            monitorPage.DataContext = new MonitorChannelPageVM(proxy);
                        }, null);

                        ContentPageData monitorPageData = new ContentPageData(new NavMenuItemData()
                        {
                            IsDropdownItem = false, IsSelected = false
                        },
                                                                              "#NavMenuMonitorProxyPage",
                                                                              "MonitorProxyPageIcon",
                                                                              PageKind.Proxy,
                                                                              monitorPage,
                                                                              ChangePage);
                        PagesData.Add(monitorPageData);


                        ContentPageDataForProxy channelViewData = new ContentPageDataForProxy(new NavMenuItemData()
                        {
                            IsDropdownItem = true, IsSelected = false
                        },
                                                                                              "NavMenuProxyIcon",
                                                                                              proxy,
                                                                                              PageKind.Proxy);
                        channelViewData.NavData.AddDropdownItem(recievePageData.NavData);
                        channelViewData.NavData.AddDropdownItem(monitorPageData.NavData);

                        PagesData.Add(channelViewData);

                        _context.Post((s) =>
                        {
                            int insertIndex = PagesData.Where(x => x.Kind == PageKind.Channel || x.Kind == PageKind.Proxy).Max(x => TopItemSource.IndexOf(x.NavData));
                            if (insertIndex < 0)
                            {
                                insertIndex = 0;
                            }
                            else
                            {
                                insertIndex++;
                            }

                            TopItemSource.Insert(insertIndex, channelViewData.NavData);
                        }, null);
                    }
                }
            }


            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
            {
                ClearProxies();
            }


            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
            {
                var objectsToRemove = PagesData.Where(x => IsContentPageDataContainsProxies(x, e.OldItems)).Select(x => x.NavData);

                _context.Send((s) =>
                {
                    TopItemSource.RemoveAll(x => objectsToRemove.Contains(x));
                }, null);

                if (e.OldItems != null)
                {
                    foreach (var el in e.OldItems)
                    {
                        if (el is IChannelProxy proxy)
                        {
                            proxy.Dispose();
                        }
                    }
                }
            }
        }
Пример #3
0
        private void OnDevicePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e != null && e.PropertyName != "Device")
            {
                return;
            }


            ClearChannels();


            if (Settings.Instance.Device == null)
            {
                return;
            }


            Settings.Instance.Device.IsConnectedChanged += (object s, EventArgs args) =>
            {
                if (s == Settings.Instance.Device)
                {
                    if (Settings.Instance.Device.IsConnected)
                    {
                        OnDevicePropertyChanged(null, null);
                    }
                    else
                    {
                        ClearChannels();
                    }
                }
            };

            if (!Settings.Instance.Device.IsConnected)
            {
                return;
            }


            //create views
            foreach (var el in Settings.Instance.Device.Channels.Reverse())
            {
                //recievePage
                var recievePage = new RecieveChannelPage();
                recievePage.DataContext = new RecieveChannelPageVM(el);

                ContentPageData recievePageData = new ContentPageData(new NavMenuItemData()
                {
                    IsDropdownItem = false, IsSelected = false
                },
                                                                      "#NavMenuRecieveChannelPage",
                                                                      "RecievedChannelPageIcon",
                                                                      PageKind.Channel,
                                                                      recievePage,
                                                                      ChangePage);
                PagesData.Add(recievePageData);


                //monitorPage
                var monitorPage = new MonitorChannelPage();
                monitorPage.DataContext = new MonitorChannelPageVM(el);

                ContentPageData monitorPageData = new ContentPageData(new NavMenuItemData()
                {
                    IsDropdownItem = false, IsSelected = false
                },
                                                                      "#NavMenuMonitorChannelPage",
                                                                      "MonitorChannelPageIcon",
                                                                      PageKind.Channel,
                                                                      monitorPage,
                                                                      ChangePage);
                PagesData.Add(monitorPageData);


                ContentPageData channelViewData = new ContentPageData(new NavMenuItemData()
                {
                    IsDropdownItem = true, IsSelected = false
                },
                                                                      "#" + el.ToString() + "NavMenu",
                                                                      el.ToString() + "Icon",
                                                                      PageKind.Channel);
                channelViewData.NavData.AddDropdownItem(recievePageData.NavData);
                channelViewData.NavData.AddDropdownItem(monitorPageData.NavData);

                PagesData.Add(channelViewData);

                _context.Post((s) =>
                {
                    int insertIndex = PagesData.Where(x => x.Kind == PageKind.Channel).Max(x => TopItemSource.IndexOf(x.NavData));
                    if (insertIndex < 0)
                    {
                        insertIndex = 0;
                    }
                    TopItemSource.Insert(insertIndex, channelViewData.NavData);
                }, null);
            }
        }