Inheritance: Caliburn.Micro.PropertyChangedBase
Exemple #1
0
 public void Play(ItemClass itm)
 {
     int idx = 0;
     foreach(var itmL in Items)
     {
         if(itmL.Path == itm.Path)
         {
             _itemPointer = idx;
             Play();
             return;
         }
         idx++;
     }
 }
Exemple #2
0
        private void GetFolders()
        {
            if (Path == null) return;
            TextBrush = AppStateSettings.Instance.Config.GetBrush("Presenter.TextBrush", Brushes.DeepPink);
            Folders.Clear();
            var l = GetItems(Path);
            var di = new DirectoryInfo(Path);
            Title = di.Name;
            foreach (var d in l.Where(k => k.Type == ItemType.folder && k.Visible))
            {
                Folders.Add(new Folder(d, this) { SeeThru = d.SeeThru, TextBrush = TextBrush });
            }
            var me = new ItemClass { Path = Path, Explorer = this };
            //MetroFolderList _items = GetTemplateChild("mflItems") as MetroFolderList;
            Items = new Folder(me, this) { TitleVibility = Visibility.Collapsed, Templated = false };
            Folders.Add(Items);

            if (PresenterLayers == null) return;
            if (!HasFullLayer) Previous = AppStateSettings.Instance.ViewDef.MapControl.Extent;
            var tl = HasFullLayer;
            HasFullLayer = false;
            PresenterLayers.ChildLayers.Clear();
            AppStateSettings.Instance.ViewDef.BaseLayer.Opacity = 1;
            AppStateSettings.Instance.ViewDef.MapControl.IsEnabled = true;
            var mainLayer = l.FirstOrDefault(k => k.Type == ItemType.csvlayer && k.Name.ToLower() == "layer");
            if (mainLayer != null)
            {
                AddLayer(mainLayer.Path);
            }
            else
            {
                FindLayerUp();
            }

            // add any other layer
            foreach (var a in l.Where(k => k.Type == ItemType.csvlayer && k.Name.ToLower() != "layer"))
            {
                AddLayer(a.Path);
            }

            //foreach (var ds in l.Where(k => k.Type == ItemType.dataservice))
            //{
            //    if (Plugin != null && Plugin.DataServer != null)
            //    {
            //        var ps = Plugin.DataServer.AddLocalDataService(ds.Path.Replace(ds.Name,""),Mode.server, ds.Name);
            //        if (ps != null)
            //        {
            //        }
            //    }
            //}

            if (tl && !HasFullLayer) AppStateSettings.Instance.ViewDef.MapControl.Extent = Previous;
        }
Exemple #3
0
        internal void SelectFolder(string p)
        {
            History.Add(Path);
            LastPath = Path;
            Path = p;

            GetFolders();
            ActiveConfig = GetActiveConfig(Path);
            var bg = GetActiveBackground(Path);
            if (bg != ActiveBackground) SetBackground(bg);

            var slb = GetTemplateChild("slbFolders") as SurfaceListBox;
            if (slb != null) slb.ItemsSource = Folders;

            //MetroFolderList _items = GetTemplateChild("mflItems") as MetroFolderList;
            //_items.Folder = Items;

            UpdateTitle();
            if (p != null && p.Contains("+"))
            {
                var items = GetOrderedItemListCurrentFolder(p).Where(k => k.Type != ItemType.folder).ToList();
                if (items.Any())
                {
                    SelectItem(items.First());
                }
            }
            //if (p!=null && p.Contains("+")) PlayAll();

            if (PresenterLayers == null) return;
            foreach (var i in PresenterLayers.ChildLayers)
            {
                var presenterLayer = i as PresenterLayer;
                if (presenterLayer == null) continue;
                foreach (var g in presenterLayer.Graphics.Graphics)
                {
                    var pa = g.Attributes["path"];
                    var fl = Convert.ToBoolean(g.Attributes["fulllayer"]);

                    if (!fl && pa.ToString() == Path)
                    {
                        AppStateSettings.Instance.ViewDef.MapControl.PanTo(g.Geometry);
                        AppStateSettings.Instance.ViewDef.MapControl.ZoomToResolution(3);
                    }
                }
            }

            CheckDataServices(Path);
            CheckLocalTileLayers(Path);

            if (ActivePathChanged != null)
                ActivePathChanged(this, new ItemSelectedArgs { Item = new ItemClass { Path = p, Type = ItemType.folder } });
        }
Exemple #4
0
 public void SetBackground(ItemClass bg)
 {
     ActiveBackground = bg;
     AppState.ViewDef.BaseLayers.Opacity = (bg == null) ? 1 : 0;
     if (bg != null)
     {
         AppState.TriggerScriptCommand(this, "background:" + bg.Path);
     }
 }
Exemple #5
0
        public void SelectItem(ItemClass item, double x = 0, double y = 0)
        {
            if (item == null)
            {
                ActivePath = "";
            }
            else
            {
                //var r = AppStateSettings.Instance.ViewDef.MapControl.Resolution;
                ActivePath = item.Path;
                if (item.Type == ItemType.folder || item.Type == ItemType.shortcut)
                {
                    SelectFolder(item.Path);
                    return;
                }
                if (item.Type == ItemType.web)
                {
                    AppState.TriggerScriptCommand(this, "web:" + item.Path);
                    //Process.Start(item.Path);
                }
                if (item.Type == ItemType.batch)
                {
                    Process.Start(item.Path);
                }
                if (item.Type == ItemType.script)
                {
                    var pth = new FileInfo(item.Path);
                    if (pth.Directory != null) {
                        //                        List<ItemClass> items = GetOrderedItemList(pth.Directory.FullName);
                        var items = GetOrderedItemListCurrentFolder(pth.Directory.FullName)
                                .Where(k => k.Type != ItemType.folder && k.Visible)
                                .ToList();
                        var tempi = items.FirstOrDefault(k => k.Path == item.Path && k.Visible);
                        var idx = items.IndexOf(tempi);

                        PreviousVisibility = (!CanShowNextPrevious || idx == 0)
                            ? Visibility.Collapsed
                            : Visibility.Visible;
                        NextVisibility = (!CanShowNextPrevious || items.Count == idx + 1)
                            ? Visibility.Collapsed
                            : Visibility.Visible;

                        PlManager.AddItem(item);
                        if (PlManager.Items.Count == 1)
                            PlManager.Play();
                        else
                            PlManager.Next();
                    }

                    //PlManager.ClearList();
                    //var pth = new FileInfo(item.Path);
                    //var items = GetOrderedItemList(pth.Directory.FullName);
                    ////foreach(var itm in items)
                    ////    PlManager.AddItem(itm);
                    //PlManager.AddItem(item);
                    //var idx = items.IndexOf(items.FirstOrDefault(k=>k.Name == item.Name));
                    //PreviousVisibility = idx == 0 ? Visibility.Collapsed : Visibility.Visible;
                    //NextVisibility = items.Count == idx + 1 ? Visibility.Collapsed : Visibility.Visible;
                    //PlManager.Play();
                    ////PlManager.Next();
                }

                //NextVisibility = Visibility.Visible;
                //PreviousVisibility = Visibility.Visible;
            }
            var a = new ItemSelectedArgs { Item = item };
            if (item != null) item.Explorer = this;

            if (x != 0) a.Pos = new Point(x, y);
            OnActivePathChanged(a);
        }
Exemple #6
0
 public static bool SameDirectoryPath(ItemClass source, ItemClass destination)
 {
     var sd = source.Path.Split('\\');
     var dd = destination.Path.Split('\\');
     if (sd.Any() && dd.Any())
         return sd[sd.Length - 2] == dd[dd.Length - 2];
     return false;
 }
Exemple #7
0
 private void PlManagerItemFinishedEvent(ItemClass ic)
 {
     Execute.OnUIThread(() =>
     {
         ActivePath = "";
         if (ActivePathChanged == null || ic == null) return;
         ic.Explorer = this;
         ActivePathChanged(this, new ItemSelectedArgs { Item = ic });
     });
 }
Exemple #8
0
        public List<ItemClass> GetItems(string folder)
        {
            if (Cache.ContainsKey(folder)) return Cache[folder];
            var l = new List<ItemClass>();
            var dir = new DirectoryInfo(folder);

            try
            {
                var di = dir.GetDirectories().ToList().OrderBy(k => k.Name).ToList();
                if (folder == StartPath && AdditionalFolders.Any())
                {
                    di.AddRange(from af in AdditionalFolders where Directory.Exists(af) select new DirectoryInfo(af));
                }
                foreach (var d in di)
                {
                    //if (!d.Name.StartsWith("_"))
                    {
                        var ic = new ItemClass { Name = d.Name, Path = d.FullName, Type = ItemType.folder };

                        if (d.Name.StartsWith("_")) ic.Visible = false;

                        if (ic.Name.ToLower() == "_tiles")
                        {
                            if (!localTileLayers.ContainsKey(d.FullName))
                            {
                                var ltl = new LocalTileLayer { Path = d.FullName, Visible = false };
                                AppStateSettings.Instance.ViewDef.Layers.ChildLayers.Add(ltl);
                                localTileLayers.Add(d.FullName, ltl);
                            }
                            ic.Type = ItemType.tilelayer;
                        }                        
                        if (ic.Name.Contains("^"))
                        {
                            ic.Presentation = true;
                            ic.Name = ic.Name.Replace("^", "");
                            ic.Type = ItemType.presentation;
                        }

                        l.Add(ic);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log("MetroExplorer", "Error get directories", e.Message, Logger.Level.Error);
            }

            if (!dir.Exists) return l;

            var f = dir.GetFiles();

            if (f.Length > 0)
            {
                var fi = f.ToList().OrderBy(k => k.Name).ToList();
                foreach (var d in fi)
                {
                    var dd = d.Name.ToLower().Split('.');
                    var path = d.FullName;
                    var fileExtension = d.Extension.ToLower();
                    if (dd[0] != dir.Name.ToLower())
                    {
                        // TODO EV Transform to switch statement
                        if (fileExtension == ".config")
                        {
                            var ic = new ItemClass
                            {
                                Path      = path,
                                Type      = ItemType.config,
                                Attractor = false,
                                Visible   = false,
                                Name      = d.Name.Substring(0, d.Name.Length - 7)
                            };
                            ic.ReadConfig();
                            l.Add(ic);
                        }
                        if (fileExtension == ".pdf")
                        {
                            // check if dir exists
                            if (!l.Any(k => k.Name == d.Name && k.Type == ItemType.presentation))
                            {
                                AddPdfDownload(new FileInfo(path));
                            }
                        }
                        if (fileExtension == ".url")
                        {
                            var c = File.ReadAllLines(path);
                            if (c.Length > 0)
                            {
                                var ic = new ItemClass
                                {
                                    Path      = c[0],
                                    Type      = ItemType.web,
                                    Attractor = false,
                                    Visible   = true,
                                    Name      = d.Name.Substring(0, d.Name.Length - 4)
                                };
                                l.Add(ic);
                            }
                        }
                        if (fileExtension == ".link")
                        {
                            var c = File.ReadAllLines(path);
                            if (c.Length > 0)
                            {
                                var nd = new DirectoryInfo(Path + c[0]);
                                if (nd.Exists)
                                {
                                    var ic = new ItemClass
                                    {
                                        Path      = nd.FullName,
                                        Type      = ItemType.shortcut,
                                        Attractor = false,
                                        Visible   = true,
                                        Name      = d.Name.Substring(0, d.Name.Length - 5)
                                    };
                                    l.Add(ic);
                                }
                            }
                        }
                        if (fileExtension == ".bat")
                        {
                            var ic = new ItemClass
                            {
                                Path      = path,
                                Type      = ItemType.batch,
                                Attractor = false,
                                Visible   = true,
                                Name      = d.Name
                            };
                            l.Add(ic);
                        }
                        if (fileExtension == ".csv")
                        {
                            var ic = new ItemClass
                            {
                                Path      = path,
                                Type      = d.Name.StartsWith("shortcuts") ? ItemType.shortcutList : ItemType.csvlayer,
                                Attractor = false,
                                Visible   = false,
                                Name      = d.Name
                            };
                            l.Add(ic);
                        }
                        if (fileExtension.StartsWith(".htm"))
                        {
                            var ic = new ItemClass
                            {
                                Path      = path,
                                Type      = ItemType.website,
                                Attractor = false,
                                Visible   = true,
                                Name      = d.Name.Substring(0, d.Name.Length - 5)
                            };
                            l.Add(ic);
                        }
                        if (fileExtension == ".ds") // UNDONE: PoiServiceExtensions.Contains(fileExtension)) // == ".ds"))
                        {
                            var ic = new ItemClass
                            {
                                Path      = path,
                                Type      = ItemType.dataservice,
                                Attractor = false,
                                Visible   = false,
                                Name      = d.Name
                            };
                            l.Add(ic);
                            //if (!dataServices.ContainsKey(d.FullName)) {
                            if (!Plugin.DataServer.Services.Any(s => Equals(s.FileName, path))) {
                                var ps = Plugin.DataServer.AddLocalDataService(d.Directory.FullName, Mode.client, path, d.Directory.FullName);
                                ps.IsVisible = false;
                                ps.Tapped += PsTapped;
                                ps.AutoStart = true;
                                Plugin.DataServer.Services.Add(ps);
                                //Plugin.DataServer.Subscribe(ps);
                                if (!dataServices.ContainsKey(path)) {
                                    try {
                                        dataServices.Add(path, ps);
                                    }
                                    catch (SystemException e) {
                                        AppStateSettings.Instance.TriggerNotification("Error parsing " + path);
                                        AppStateSettings.Instance.TriggerNotification(e.Message);
                                        if (e.InnerException != null) AppStateSettings.Instance.TriggerNotification(e.InnerException.Message);
                                    }
                                    Dispatcher.Invoke(() => CheckDataServices(Path));
                                }
                            }
                        }

                        if (_scripts.Contains(fileExtension))
                        {
                            var ic = new ItemClass
                            {
                                Path      = path,
                                ImagePath = path,
                                Type      = ItemType.script,
                                Name      = dd[0]
                            };
                            l.Add(ic);
                        }
                        if (_images.Contains(fileExtension))
                        {
                            var ic = new ItemClass
                            {
                                Path      = path,
                                ImagePath = path,
                                Type      = ItemType.image,
                                Name      = dd[0]
                            };
                            l.Add(ic);
                        }
                        if (_videos.Contains(fileExtension))
                        {
                            if (dd[0].ToLower() == "_background")
                            {
                                var ic = new ItemClass
                                {
                                    Path = path,
                                    Type = ItemType.videobackground,
                                    Name = dd[0]
                                };
                                l.Add(ic);
                            }
                            else
                            {
                                var ic = new ItemClass
                                {
                                    Path = path,
                                    Type = ItemType.video,
                                    Name = dd[0]
                                };
                                l.Add(ic);
                            }
                        }
                    }
                    if (Extensions.ContainsKey(fileExtension))
                    {
                        var ic = new ItemClass { Path = path, ImagePath = "", Type = ItemType.unknown, Name = dd[0] };
                        l.Add(ic);
                    }
                }

                foreach (var i in l)
                {
                    if (i.Visible) i.Visible = !i.Name.StartsWith("_");
                    i.Attractor = i.Name.Contains("~");
                    i.Name = i.Name.Replace("~", "");

                    if (i.Name.Contains("!")) i.SeeThru = false;
                    if (i.SeeThru) i.Name = i.Name.Replace("!", "");

                    i.Name = i.Name.Replace("+", "");
                }

                var tbr = new List<ItemClass>();
                var currentDirectory = Directory.GetCurrentDirectory();
                foreach (var ic in l.Where(k => k.Type != ItemType.image))
                {
                    if (ic == null || ic.Name == null) continue;
                    var i = l.FirstOrDefault(k => k.Name != null && string.Equals(k.Name, ic.Name, StringComparison.InvariantCultureIgnoreCase) && k.Type == ItemType.image);
                    if (i == null)
                    {
                        switch (ic.Type)
                        {
                            case ItemType.web:
                                ic.ImagePath = System.IO.Path.Combine(currentDirectory, @"Images\html.jpg");
                                break;

                            case ItemType.video:
                                ic.ImagePath = System.IO.Path.Combine(currentDirectory, @"Images\video.jpg");
                                break;

                            case ItemType.website:
                                ic.ImagePath = System.IO.Path.Combine(currentDirectory, @"Images\info.jpg");
                                break;

                            case ItemType.batch:
                                ic.ImagePath = System.IO.Path.Combine(currentDirectory, @"Images\batch.png");
                                break;
                        }
                        continue;
                    }

                    tbr.Add(i);
                    ic.ImagePath = i.Path;
                }
                foreach (var i in tbr) l.Remove(i);

                // if a presentation has nog imagepath, use first file( must be image) in presentation folder
                foreach (var i in l.Where(k => k.Type == ItemType.presentation && k.ImagePath == null))
                {
                    var iff = Directory.GetFiles(i.Path);
                    if (iff.Length > 0)
                    {
                        i.ImagePath = iff.First();
                    }
                }
            }

            Cache[folder] = l;

            return l;
        }
        public void StartScript(ItemClass item)
        {
            MetroExplorer.NextVisibility = Visibility.Visible;
            MetroExplorer.PreviousVisibility = Visibility.Visible;
            DemoScript.ScriptPath = item.Path;
            if (scriptThread != null && scriptThread.IsAlive) scriptThread.Abort();
            scriptThread = new Thread(DemoScript.StartScript);
            DemoScript.ScriptStarted += (e, s) =>
                ScriptRunning = true;
            DemoScript.ScriptFinished += (e, s) => Execute.OnUIThread(() =>
            {
                ScriptRunning = false;
                AppState.ViewDef.ChangeMapType(BaseMap);
                AppState.ViewDef.StartTransition();

                DemoScript.ZoomTo(-19913273.2361002,
                    -16885380.7637054,
                    20161743.4494782,
                    15174632.5847574,
                    effect: true);
                MetroExplorer.UpdateTitle();
                MetroExplorer.NextVisibility =
                    Visibility.Collapsed;
            });
            scriptThread.Start();
        }
Exemple #10
0
 public MetroItemViewModel(ItemClass item, int x, int y, int spanx, int spany, MetroExplorer explorer)
 {
     Explorer = explorer;
     Item = item;
     Col = x;
     Row = y;
     ColSpan = spanx;
     RowSpan = spany;
     Image = Item.ImagePath;
     switch (item.Type)
     {
         case ItemType.folder:
             var di = new DirectoryInfo(item.Path);
             Name = di.Name;
             Image = "http://www.tno.nl/images/contactpers/mihielvandermeulen.jpg";
             foreach (var f in di.GetFiles())
             {
                 if (f.Name.ToLower().Contains(di.Name.ToLower() + "."))
                 {
                     Image = f.FullName;
                 }
             }
             
             break;
         case ItemType.image:
             var fi = new FileInfo(item.Path);
             Name = fi.Name.Split('.')[0];
             Image = item.Path;
             break;
         case ItemType.video:
             var fv = new FileInfo(item.Path);
             Name = fv.Name.Split('.')[0];
             Image = item.ImagePath;
             break;
         case ItemType.unknown:
             var fu = new FileInfo(item.Path);
             Name = fu.Name.Split('.')[0];
             Image = item.ImagePath;                         
             break;
     }
     
 }
Exemple #11
0
 public void AddItem(ItemClass item)
 {
     Items.Add(item);
 }
Exemple #12
0
        public Folder(ItemClass item, MetroExplorer explorer)
        {

            Directory = new DirectoryInfo(item.Path);

            Name = Directory.Name;

            InitTemplates();
            Explorer = explorer;

            
        }
Exemple #13
0
        //protected override void OnViewLoaded(object view)
        //{
        //    base.OnViewLoaded(view);
        //    _view = (FolderView) view;

        //    _view.SetBinding(FrameworkElement.WidthProperty, new Binding("SegWidth") {Source = Explorer});
        //    _view.SetBinding(FrameworkElement.HeightProperty, new Binding("SegHeight") { Source = Explorer });

        //    _view.gScaleGrid.SetBinding(Grid.WidthProperty, new Binding("ScaleWidth") { Source = Explorer });
        //    _view.gScaleGrid.SetBinding(Grid.HeightProperty, new Binding("ScaleHeight") { Source = Explorer });

        //    GetFiles();

        //}


        

        public void GetFiles()
        {
            var l = new List<ItemClass>();
            Items = new BindableCollection<MetroItemViewModel>();
            
            if (Directory.Exists)
            {
                List<DirectoryInfo> di = Directory.GetDirectories().ToList().OrderBy(k => k.Name).ToList();                
                List<FileInfo> fi = Directory.GetFiles().ToList().OrderBy(k => k.Name).ToList();

                foreach (var d in di)
                {
                    if (!d.Name.StartsWith("_"))
                    {
                        var ic = new ItemClass() {Path = d.FullName, ImagePath = d.FullName, Type = ItemType.folder};
                        l.Add(ic);
                    }
                }

                

                foreach (var d in fi)
                {
                    if (!d.Name.StartsWith("_"))
                    {
                        string[] dd = d.Name.ToLower().Split('.');
                        if (dd[0] != Directory.Name.ToLower())
                        {
                            if (d.Extension.ToLower() == ".pdf")
                            {
                                
                            }
                            if (Explorer.images.Contains(d.Extension.ToLower()))
                            {
                                var ic = new ItemClass() {Path = d.FullName, Type = ItemType.image, Name = dd[0]};
                                l.Add(ic);
                            }
                            if (Explorer.videos.Contains(d.Extension.ToLower()))
                            {
                                var ic = new ItemClass()
                                             {
                                                 Path = d.FullName,
                                                 ImagePath = d.FullName,
                                                 Type = ItemType.video,
                                                 Name = dd[0]
                                             };
                                l.Add(ic);
                            }
                            if (Explorer.scripts.Contains(d.Extension.ToLower()))
                            {
                                var ic = new ItemClass()
                                             {
                                                 Path = d.FullName,
                                                 Type = ItemType.script,
                                                 Name = dd[0]
                                             };
                            }
                        }
                        if (Explorer.Extensions.ContainsKey(d.Extension.ToLower()))
                        {
                            var ic = new ItemClass()
                                         {Path = d.FullName, ImagePath = "", Type = ItemType.unknown, Name = dd[0]};
                            l.Add(ic);
                        }
                    }
                }

                List<ItemClass> tbr = new List<ItemClass>();
                foreach (var ic in l.Where(k => k.Type != ItemType.image))
                {
                    if (ic != null && ic.Name!=null)
                    {
                        var i = l.FirstOrDefault(k => k.Name!=null && k.Name.ToLower() == ic.Name.ToLower() && k.Type == ItemType.image);
                        if (i != null)
                        {
                            tbr.Add(i);
                            ic.ImagePath = i.Path;
                        }
                    }
                }
                foreach (var i in tbr) l.Remove(i);

                //var view = Caliburn.Micro.ViewModelLocator.(new MetroItemViewModel(fi[0], 0, 0, 2, 2));

                if (Templated)
                {
                    FolderTemplate ft = Templates.FirstOrDefault(k => k.Items.Count == l.Count);

                    int c = 0;
                    if (ft != null)
                    {
                        foreach (var i in ft.Items)
                        {
                            Items.Add(new MetroItemViewModel(l[c], i.Col, i.Row, i.Colspan, i.Rowspan, Explorer));
                            c += 1;
                        }
                    }
                }



            }
        }