示例#1
0
        private IFolderItemViewModel InitializeView(IPathModel newPath)
        {
            string pathroot = string.Empty;
            IFolderItemViewModel selectedItem = null;

            string[] dirs;

            if (newPath == null)
            {
                if (string.IsNullOrEmpty(CurrentFolder) == false)
                {
                    return(null); // No parameter available at this time ...
                }
                else
                {
                    try
                    {
                        newPath = PathFactory.Create(CurrentFolder);
                    }
                    catch { }
                }
            }

            pathroot = newPath.PathRoot;
            dirs     = PathFactory.GetDirectories(newPath.Path);

            // add drives
            foreach (string s in Directory.GetLogicalDrives())
            {
                IFolderItemViewModel info = FolderControlsLib.Factory.CreateLogicalDrive(s);
                CurrentItemsAdd(info);

                // add items under current folder if we currently create the root folder of the current path
                if (string.Compare(pathroot, s, true) == 0)
                {
                    for (int i = 1; i < dirs.Length; i++)
                    {
                        try
                        {
                            string curdir = PathFactory.Join(dirs, 0, i + 1);

                            var curPath = PathFactory.Create(curdir);
                            var info2   = new FolderItemViewModel(curPath, dirs[i]);

                            CurrentItemsAdd(info2);
                        }
                        catch // Non-existing/unknown items will throw an exception here...
                        {
                        }
                    }

                    selectedItem = _CurrentItems.Last();
                }
            }

            return(selectedItem);
        }
示例#2
0
        /// <summary>
        /// Can be invoked to refresh the currently visible set of data.
        /// </summary>
        public FinalBrowseResult PopulateView(BrowseRequest request)
        {
            IPathModel newPath = request.NewLocation;

            // Make sure the task always processes the last input but is not started twice
            _SlowStuffSemaphore.WaitAsync();
            try
            {
                if (request.CancelTok != null)
                {
                    request.CancelTok.ThrowIfCancellationRequested();
                }

                // Initialize view with current path
                if (_CurrentItems.Count() == 0)
                {
                    CurrentItemsClear();
                    SelectedItem = InitializeView(newPath);
                }
                else
                {
                    var match = _CurrentItems.TryGet(newPath.Path);
                    if (match != null)
                    {
                        SelectedItem = match;
                    }
                    else
                    {
                        var folderItem = new FolderItemViewModel(newPath, newPath.Name);
                        SelectedItem = CurrentItemsAdd(folderItem);
                    }
                }

                // Force a selection on to the control when there is no selected item, yet
                // Select last item in the list (hoping this is what we want...)
                if (_CurrentItems.Count > 0 && SelectedItem == null)
                {
                    SelectedItem = _CurrentItems.Last();
                }

                return(FinalBrowseResult.FromRequest(request, BrowseResult.Complete));
            }
            catch (Exception exp)
            {
                //// Console.WriteLine("{0} -> {1}", exp.Message, exp.StackTrace);
                var result = FinalBrowseResult.FromRequest(request, BrowseResult.InComplete);
                result.UnexpectedError = exp;
                return(result);
            }
            finally
            {
                _SlowStuffSemaphore.Release();
            }
        }
示例#3
0
        /// <summary>
        /// Can be invoked to refresh the currently visible set of data.
        /// </summary>
        public bool PopulateView(IPathModel newPath)
        {
            lock (this._LockObject)
            {
                try
                {
                    CurrentItemClear();

                    // add drives
                    string pathroot = string.Empty;

                    if (newPath == null)
                    {
                        if (string.IsNullOrEmpty(this.CurrentFolder) == false)
                        {
                            try
                            {
                                pathroot = System.IO.Path.GetPathRoot(CurrentFolder);
                            }
                            catch
                            {
                                pathroot = string.Empty;
                            }
                        }
                    }
                    else
                    {
                        pathroot = System.IO.Path.GetPathRoot(newPath.Path);
                    }

                    foreach (string s in Directory.GetLogicalDrives())
                    {
                        IFolderItemViewModel info = FolderControlsLib.Factory.CreateLogicalDrive(s);
                        CurrentItemAdd(info);

                        // add items under current folder if we currently create the root folder of the current path
                        if (string.IsNullOrEmpty(pathroot) == false && string.Compare(pathroot, s, true) == 0)
                        {
                            string[] dirs;

                            if (newPath == null)
                            {
                                dirs = PathFactory.GetDirectories(CurrentFolder);
                            }
                            else
                            {
                                dirs = PathFactory.GetDirectories(newPath.Path);
                            }

                            for (int i = 1; i < dirs.Length; i++)
                            {
                                try
                                {
                                    string curdir = PathFactory.Join(dirs, 0, i + 1);

                                    var curPath = PathFactory.Create(curdir);
                                    info = new FolderItemViewModel(curPath, dirs[i], false);

                                    CurrentItemAdd(info);
                                }
                                catch // Non-existing/unknown items will thrown an exception here...
                                {
                                }
                            }

                            SelectedItem = _CurrentItems.Last();
                        }
                    }

                    // Force a selection on to the control when there is no selected item, yet
                    if (this._CurrentItems != null && SelectedItem == null)
                    {
                        if (this._CurrentItems.Count > 0)
                        {
                            this.SelectedItem = this._CurrentItems.Last();
                        }
                    }

                    return(true);
                }
                catch (Exception exp)
                {
                    Console.WriteLine("{0} -> {1}", exp.Message, exp.StackTrace);
                    return(false);
                }
            }
        }