Ejemplo n.º 1
0
        private void AddFolder(FolderContainerDummy folder)
        {
            this.FileEnumerator[folder.Path] = folder;


            foreach (var cf in folder.GetChildFolders())
            {
                this.FileEnumerator[cf.Value.Path] = cf.Value;
            }
        }
Ejemplo n.º 2
0
        private FolderContainerDummy LoadTestData(string text)
        {
            FolderContainerDummy folder = null;

            using (var sr = new StringReader(text))
            {
                var line = "";
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.StartsWith("//"))
                    {
                        continue;
                    }

                    var items = line.Split(',');

                    if (items.Count(x => x != null && x.Length > 0) <= 0)
                    {
                        continue;
                    }
                    else if (folder == null)
                    {
                        folder = new FolderContainerDummy()
                        {
                            Path = items.Join(),
                        };
                        continue;
                    }
                    else if (folder.Folders == null)
                    {
                        folder.Folders = items
                                         .Where(x => x != null && x.Length > 0)
                                         .ToDictionary(x => x.Replace("\\", ""),
                                                       x => new FolderContainerDummy()
                        {
                            Path = folder.Path + x
                        });

                        foreach (var tt in folder.Folders)
                        {
                            this.AddFolder(tt.Value);
                        }

                        continue;
                    }
                    else if (items.Length < 9)
                    {
                        continue;
                    }

                    var name         = items[0] + ".png";
                    var relativePath = items[1].Split('\\').Where(x => x != null && x.Length > 0).ToArray();
                    var created      = ParseDateTime(items[2]);
                    var modified     = ParseDateTime(items[3]);
                    var size         = ParseInt(items[4]);
                    var height       = ParseInt(items[5]);
                    var width        = ParseInt(items[6]);
                    var rating       = ParseInt(items[7]);
                    var keywords     = items[8].Split(';').Where(x => x != null && x.Length > 0).ToArray();


                    var targetFolder = folder;
                    //if (relativePath.Length > 0)


                    foreach (var str in relativePath.Select(x => x))
                    {
                        var cfPath = targetFolder.Path + "\\" + str;
                        if (!targetFolder.Folders.ContainsKey(cfPath))
                        {
                            var childFolder = new FolderContainerDummy()
                            {
                                Path = cfPath,
                            };

                            childFolder.Folders = new Dictionary <string, FolderContainerDummy>();

                            targetFolder.Folders[cfPath] = childFolder;
                        }

                        foreach (var tt in targetFolder.Folders)
                        {
                            this.AddFolder(tt.Value);
                        }
                        targetFolder = targetFolder.Folders[cfPath];

                        foreach (var tt in targetFolder.Folders)
                        {
                            this.AddFolder(tt.Value);
                        }
                    }


                    var path = targetFolder.Path + @"\" + name;

                    var file = new ImageFileInformation()
                    {
                        Name         = name,
                        Path         = path,
                        DateCreated  = created,
                        DateModified = modified,
                        Size         = size,
                        Height       = height,
                        Width        = width,
                        Rating       = rating,
                        Keywords     = (keywords.Length > 0) ? new HashSet <string>(keywords) : null,
                    };

                    targetFolder.Files.Add(file);
                }
            }
            return(folder);
        }