Inheritance: dsBaseLayer, INotifyPropertyChanged, IOnlineLayer, IStartStopLayer, IServiceLayer, IMenuLayer, ILayerWithMoreChildren, ITabLayer
示例#1
0
        public void UpdateLayerTabs(PoiService service, dsLayer layer)
        {
            var tabVisible = true;
            if (service.Settings != null)
            {
                tabVisible = service.Settings.TabBarVisible;
            }
            // check if it already exists

            Execute.OnUIThread(() =>
            {
                var inst = AppState.StartPanelTabItems.FirstOrDefault(
                    k => k.ModelInstance is TabItemViewModel &&
                    ((TabItemViewModel)k.ModelInstance).Service == service);

                if (inst == null && service.IsInitialized && tabVisible)
                {
                    var ptvm = new TabItemViewModel { Plugin = this, Service = service, Layer = layer };
                    var s = new StartPanelTabItem { Name = service.Name };
                    ptvm.TabItem = s;
                    if (!service.IsLocal || service.Mode == Mode.server)
                    {
                        s.SupportImage =
                            new BitmapImage(
                                new Uri("pack://application:,,,/csCommon;component/Resources/Icons/online.png"));
                    }
                    s.ModelInstance = ptvm;
                    AppState.AddStartPanelTabItem(s);
                }
                else if ((!service.IsInitialized || !tabVisible) && inst != null)
                {
                    AppState.RemoveStartPanelTabItem(inst);
                }
            });
        }
示例#2
0
        private void ServicesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Reset:
                    //TODO: remove layer
                    //foreach (var s in StaticLayers) {}
                    break;

                case NotifyCollectionChangedAction.Add:
                    // find out what the AutoStart services are
                    var ass = AppState.Config.Get("Services.AutoStart", "");
                    if (!string.IsNullOrEmpty(ass))
                    {
                        AutoStartServices = ass.Split(',').ToList();
                    }
                    foreach (var s in e.NewItems)
                    {
                        var ps = s as PoiService;
                        if (ps == null) continue;
                        dsBaseLayer newLayer;

                        if (ps.StaticService)
                        {
                            newLayer = new dsStaticLayer(ps, this) { Visible = true };
                            if (string.IsNullOrEmpty(ps.RelativeFolder))
                            {
                                AppState.ViewDef.AcceleratedLayers.ChildLayers.Add(newLayer);
                                newLayer.Parent = AppState.ViewDef.AcceleratedLayers;
                            }
                            else
                            {
                                var folder = AppState.ViewDef.FindOrCreateAcceleratedGroupLayer(ps.RelativeFolder.Trim('\\').Replace('\\', '/'));
                                folder.ChildLayers.Add(newLayer);
                                newLayer.Parent = folder;
                            }
                            StaticLayers.Add((dsStaticLayer)newLayer);
                            ps.Layer = newLayer;
                            newLayer.Initialize();
                            if (ps.AutoStart) 
                                ((dsStaticLayer)newLayer).Start();
                        }
                        else
                        {
                            newLayer = new dsLayer(ps, this) { Visible = true };
                            if (string.IsNullOrEmpty(ps.RelativeFolder))
                            {
                                AppState.ViewDef.Layers.ChildLayers.Add(newLayer);
                                newLayer.Parent = AppState.ViewDef.Layers;
                            }
                            else
                            {
                                var folder = AppState.ViewDef.FindOrCreateGroupLayer(ps.RelativeFolder.Trim('\\').Replace('\\', '/'));
                                folder.ChildLayers.Add(newLayer);
                                newLayer.Parent = folder;
                            }
                            Layers.Add((dsLayer)newLayer);
                            ps.Layer = newLayer;
                            newLayer.Initialize();
                            var myLayer = newLayer as dsLayer;
                            if (ps.AutoStart && !myLayer.IsStarted)
                                myLayer.Start();
                        }


                        #region old

                        //if (!ps.StaticService)
                        //{
                        //    if (AutoStartServices.Contains(ps.Name) )
                        //    {
                        //        this.Dsb.Subscribe(ps, Mode.server);
                        //    }
                        //    if (ps.AutoStart)
                        //    {
                        //        this.Dsb.Subscribe(ps, Mode.client);
                        //    }
                        //    AddDataService(ps);
                        //}
                        //else
                        //{
                        //    var sl = new dsStaticLayer(ps, this) { Visible = true };

                        //    ps.Layer = sl;
                        //    if (string.IsNullOrEmpty(ps.RelativeFolder))
                        //    {
                        //        AppState.ViewDef.AcceleratedLayers.ChildLayers.Add(sl);
                        //    }
                        //    else
                        //    {
                        //        var folder = AppState.ViewDef.FindOrCreateAcceleratedGroupLayer(ps.RelativeFolder.Trim('\\').Replace('\\','/'));
                        //        folder.ChildLayers.Add(sl);
                        //    }


                        //    sl.Initialize();
                        //    StaticLayers.Add(sl);
                        //    if (AutoStartServices.Contains(ps.Name))
                        //    {
                        //        Dsb.Subscribe(ps);
                        //    }
                        //    if (ps.AutoStart) sl.Start();
                        //}
                        #endregion
                    }
                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (var s in e.OldItems)
                    {
                        var ps = s as PoiService;
                        RemoveServiceTabItem(s as PoiService);
                        if (ps == null || !ps.StaticService) continue;
                        var l = StaticLayers.FirstOrDefault(k => k.Service == ps);
                        if (l != null) StaticLayers.Remove(l);
                    }
                    break;
            }
        }