コード例 #1
0
        private async Task <bool> IsFileEquals(Record a, ImageFileInformation b, Library library)
        {
            await this.AreEqualAsync(a.Id, b.Path);

            await this.AreEqualAsync(a.FileName, b.Name);


            await this.AreEqualAsync(a.DateCreated, b.DateCreated);

            await this.AreEqualAsync(a.DateModified, b.DateModified);

            await this.AreEqualAsync(a.Size, b.Size);

            await this.AreEqualAsync(a.Height, b.Height);

            await this.AreEqualAsync(a.Width, b.Width);

            await this.AreEqualAsync(a.Rating, b.Rating);

            var aa = a.TagSet.Read()
                     .Select(x => library.Tags.GetTagValue(x).Name)
                     .OrderBy(x => x).ToArray();

            var bb = b.Keywords?.OrderBy(x => x).ToArray() ?? new string[0];

            Assert.IsTrue(aa.SequenceEqual(bb, (x, y) => x.Equals(y)));

            return(true);
        }
コード例 #2
0
        /// <summary>
        ///     Validates.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        protected override ValidationResult IsValid(object value, ValidationContext context)
        {
            var fileEntity = value as FileEntity;

            if (fileEntity == null)
            {
                return(ValidationResult.Success);
            }

            var fileInformation = new ImageFileInformation();

            try
            {
                fileInformation.Read(fileEntity.Uri);
            }
            catch (ArgumentNullException)
            {
                return(new ValidationResult(FormatErrorMessage(context.DisplayName)));
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to receive file information: {0}", e);
                return(new ValidationResult(FormatErrorMessage(context.DisplayName)));
            }

            if (!_formats.Contains(fileInformation.Format))
            {
                return(new ValidationResult(FormatErrorMessage(context.DisplayName)));
            }

            return(ValidationResult.Success);
        }
コード例 #3
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);
        }