public override BackgroundStorageEntry GetFile(string path)
        {
            int i = path.LastIndexOf('/');
            var directory = new BackgroundStorageDirectory(this, path.Substring(0, i + 1));

            var name = path.Substring(i + 1);

            return new BackgroundStorageEntry(this, directory, name);
        }
        /// <summary>
        /// Helper function to get the absolute path for a given directory.
        /// </summary>
        /// <param name="dir">The directory to get the path for.</param>
        /// <returns>A DirectoryInfo for the absolute path.</returns>
        private DirectoryInfo GetAbsoluteDirectory(BackgroundStorageDirectory dir)
        {
            if (dir.IsRoot)
            {
                return(new DirectoryInfo(directory));
            }

            return(new DirectoryInfo(Path.Combine(directory, dir.Path.Substring(1).Replace('/', Path.DirectorySeparatorChar))));
        }
Example #3
0
        public override BackgroundStorageEntry GetFile(string path)
        {
            int i         = path.LastIndexOf('/');
            var directory = new BackgroundStorageDirectory(this, path.Substring(0, i + 1));

            var name = path.Substring(i + 1);

            return(new BackgroundStorageEntry(this, directory, name));
        }
        /// <summary>
        /// Gets all subdirectories of a specified directory.
        /// </summary>
        /// <param name="parent">The parent directory.</param>
        /// <returns>
        /// A list of subdirectories.
        /// </returns>
        public override IEnumerable<BackgroundStorageDirectory> GetDirectories(BackgroundStorageDirectory parent)
        {
            if (parent == null)
                throw new ArgumentNullException("parent");

            DirectoryInfo info = GetAbsoluteDirectory(parent);

            if (!info.Exists)
                throw new ArgumentException("Directory does not exist");

            foreach (var dir in info.GetDirectories().Where(d => d.Name != "[Thumbnails]"))
            {
                yield return new BackgroundStorageDirectory(this, parent.Path + dir.Name + "/");
            }
        }
Example #5
0
        /// <summary>
        /// Gets the listing of files and folders using HTTP.
        /// An requested URL looks like http://host/backgrounds/directory/list.
        /// </summary>
        /// <param name="directory"></param>
        /// <returns></returns>
        private IEnumerable <ListingEntry> GetListing(BackgroundStorageDirectory directory)
        {
            var result = client.GetAsync(directory.Path.Substring(1) + "list").WaitAndUnwrapException();

            if (result.StatusCode == HttpStatusCode.NotFound)
            {
                throw new FileNotFoundException();
            }

            if (!result.IsSuccessStatusCode)
            {
                throw new HttpRequestException();
            }

            var str = result.Content.ReadAsStringAsync().WaitAndUnwrapException();

            return(str.Split('\n').Where(p => p.Trim() != String.Empty).Select(p => new ListingEntry(p)).ToArray());
        }
        /// <summary>
        /// Gets all subdirectories of a specified directory.
        /// </summary>
        /// <param name="parent">The parent directory.</param>
        /// <returns>
        /// A list of subdirectories.
        /// </returns>
        public override IEnumerable <BackgroundStorageDirectory> GetDirectories(BackgroundStorageDirectory parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            DirectoryInfo info = GetAbsoluteDirectory(parent);

            if (!info.Exists)
            {
                throw new ArgumentException("Directory does not exist");
            }

            foreach (var dir in info.GetDirectories().Where(d => d.Name != "[Thumbnails]"))
            {
                yield return(new BackgroundStorageDirectory(this, parent.Path + dir.Name + "/"));
            }
        }
        /// <summary>
        /// Gets all available background files in a specified directory.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <returns>
        /// A list of background files (relative to the specified directory).
        /// </returns>
        public override IEnumerable <BackgroundStorageEntry> GetFiles(BackgroundStorageDirectory dir)
        {
            if (dir == null)
            {
                throw new ArgumentNullException("dir");
            }

            DirectoryInfo info = GetAbsoluteDirectory(dir);

            if (!info.Exists)
            {
                throw new ArgumentException("Directory does not exist");
            }

            foreach (var file in info.GetFiles())
            {
                var ext = file.Extension.ToLowerInvariant();

                if (AllowedImageTypes.ContainsKey(ext) || AllowedVideoTypes.ContainsKey(ext))
                {
                    yield return(new BackgroundStorageEntry(this, dir, file.Name));
                }
            }
        }
Example #8
0
 /// <summary>
 /// Gets all subdirectories of a specified directory.
 /// </summary>
 /// <param name="parent">The parent directory.</param>
 /// <returns>
 /// A list of subdirectories.
 /// </returns>
 public abstract IEnumerable<BackgroundStorageDirectory> GetDirectories(BackgroundStorageDirectory parent);
        private void ListBackgroundEntries(BackgroundStorageDirectory parent, StringBuilder sb, bool recursive = false)
        {
            foreach (var subdir in parent.Directories)
            {
                sb.Append(subdir.Path);
                sb.Append('\n');

                if (recursive)
                    ListBackgroundEntries(subdir, sb, true);
            }
            foreach (var file in parent.Files)
            {
                sb.Append(file.Path);
                sb.Append('\n');
            }
        }
 internal BackgroundStorageEntry(BackgroundStorage storage, BackgroundStorageDirectory parent, string name)
 {
     this.storage = storage;
     this.Name = name;
     this.Parent = parent;
 }
Example #11
0
 public override IEnumerable <BackgroundStorageDirectory> GetDirectories(BackgroundStorageDirectory parent)
 {
     return(GetListing(parent).Where(e => e.IsDirectory).Select(e => new BackgroundStorageDirectory(this, e.Path)).OrderBy(d => d.Name));
 }
Example #12
0
 public override IEnumerable <BackgroundStorageEntry> GetFiles(BackgroundStorageDirectory directory)
 {
     return(GetListing(directory).Where(e => !e.IsDirectory).Select(e => new BackgroundStorageEntry(this, directory, Path.GetFileName(e.Path))).OrderBy(f => f.Name));
 }
 public override IEnumerable<BackgroundStorageEntry> GetFiles(BackgroundStorageDirectory directory)
 {
     return GetListing(directory).Where(e => !e.IsDirectory).Select(e => new BackgroundStorageEntry(this, directory, Path.GetFileName(e.Path))).OrderBy(f => f.Name);
 }
 public override IEnumerable<BackgroundStorageDirectory> GetDirectories(BackgroundStorageDirectory parent)
 {
     return GetListing(parent).Where(e => e.IsDirectory).Select(e => new BackgroundStorageDirectory(this, e.Path)).OrderBy(d => d.Name);
 }
        /// <summary>
        /// Gets the listing of files and folders using HTTP.
        /// An requested URL looks like http://host/backgrounds/directory/list.
        /// </summary>
        /// <param name="directory"></param>
        /// <returns></returns>
        private IEnumerable<ListingEntry> GetListing(BackgroundStorageDirectory directory)
        {
            var result = client.GetAsync(directory.Path.Substring(1) + "list").WaitAndUnwrapException();
            if (result.StatusCode == HttpStatusCode.NotFound)
                throw new FileNotFoundException();

            if (!result.IsSuccessStatusCode)
                throw new HttpRequestException();

            var str = result.Content.ReadAsStringAsync().WaitAndUnwrapException();

            return str.Split('\n').Where(p => p.Trim() != String.Empty).Select(p => new ListingEntry(p)).ToArray();
        }
 /// <summary>
 /// Gets all available background files in a specified directory.
 /// </summary>
 /// <param name="directory">The directory.</param>
 /// <returns>
 /// A list of background files.
 /// </returns>
 public abstract IEnumerable <BackgroundStorageEntry> GetFiles(BackgroundStorageDirectory directory);
 /// <summary>
 /// Gets all subdirectories of a specified directory.
 /// </summary>
 /// <param name="parent">The parent directory.</param>
 /// <returns>
 /// A list of subdirectories.
 /// </returns>
 public abstract IEnumerable <BackgroundStorageDirectory> GetDirectories(BackgroundStorageDirectory parent);
        /// <summary>
        /// Gets all available background files in a specified directory.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <returns>
        /// A list of background files (relative to the specified directory).
        /// </returns>
        public override IEnumerable<BackgroundStorageEntry> GetFiles(BackgroundStorageDirectory dir)
        {
            if (dir == null)
                throw new ArgumentNullException("dir");

            DirectoryInfo info = GetAbsoluteDirectory(dir);

            if (!info.Exists)
                throw new ArgumentException("Directory does not exist");

            foreach (var file in info.GetFiles())
            {
                var ext = file.Extension.ToLowerInvariant();

                if (AllowedImageTypes.ContainsKey(ext) || AllowedVideoTypes.ContainsKey(ext))
                    yield return new BackgroundStorageEntry(this, dir, file.Name);
            }
        }
 internal BackgroundStorageEntry(BackgroundStorage storage, BackgroundStorageDirectory parent, string name)
 {
     this.storage = storage;
     this.Name    = name;
     this.Parent  = parent;
 }
        /// <summary>
        /// Helper function to get the absolute path for a given directory.
        /// </summary>
        /// <param name="dir">The directory to get the path for.</param>
        /// <returns>A DirectoryInfo for the absolute path.</returns>
        private DirectoryInfo GetAbsoluteDirectory(BackgroundStorageDirectory dir)
        {
            if (dir.IsRoot)
                return new DirectoryInfo(directory);

            return new DirectoryInfo(Path.Combine(directory, dir.Path.Substring(1).Replace('/', Path.DirectorySeparatorChar)));
        }
        private void SelectEntry(string remainingSelectPath, BackgroundStorageDirectory currentNode, TreeViewItem currentContainer)
        {
            var i = remainingSelectPath.IndexOf('\\');
            if (i >= 0)
            {
                string next = remainingSelectPath.Substring(0, i);
                remainingSelectPath = remainingSelectPath.Substring(i + 1);

                currentNode = currentNode.Directories.First((dir) => dir.Name == next);
                currentContainer = currentContainer.ItemContainerGenerator.ContainerFromItem(currentNode) as TreeViewItem;
                currentContainer.IsExpanded = true;
                currentContainer.ItemContainerGenerator.StatusChanged += (sender, args) =>
                {
                    if (currentContainer.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
                        SelectEntry(remainingSelectPath, currentNode, currentContainer);
                };
            }
            else
            {
                imageListView.SelectedItem = currentNode.Files.Where(file => file.Name == remainingSelectPath).SingleOrDefault();
                currentContainer.IsSelected = true;
                currentContainer.BringIntoView();
                imageListView.Focus();
            }
        }
Example #22
0
 /// <summary>
 /// Gets all available background files in a specified directory.
 /// </summary>
 /// <param name="directory">The directory.</param>
 /// <returns>
 /// A list of background files.
 /// </returns>
 public abstract IEnumerable<BackgroundStorageEntry> GetFiles(BackgroundStorageDirectory directory);