示例#1
0
        private static AuthorMetadata MapAuthor(AuthorSummaryResource resource)
        {
            var author = new AuthorMetadata
            {
                ForeignAuthorId = resource.Id.ToString(),
                Name            = resource.Name.CleanSpaces(),
                TitleSlug       = resource.Id.ToString()
            };

            if (resource.RatingsCount.HasValue)
            {
                author.Ratings = new Ratings
                {
                    Votes = resource.RatingsCount ?? 0,
                    Value = resource.AverageRating ?? 0
                };
            }

            if (!NoPhotoRegex.IsMatch(resource.ImageUrl))
            {
                author.Images.Add(new MediaCover.MediaCover
                {
                    Url       = FullSizeImageRegex.Replace(resource.ImageUrl),
                    CoverType = MediaCoverTypes.Poster
                });
            }

            return(author);
        }
示例#2
0
        private static AuthorMetadata MapAuthor(AuthorSummaryResource resource)
        {
            var author = new AuthorMetadata
            {
                ForeignAuthorId = resource.GoodreadsId.ToString(),
                TitleSlug       = resource.TitleSlug,
                Name            = resource.Name.CleanSpaces(),
                Overview        = resource.Description,
                Ratings         = new Ratings {
                    Votes = resource.RatingsCount, Value = (decimal)resource.AverageRating
                }
            };

            if (resource.ImageUrl.IsNotNullOrWhiteSpace())
            {
                author.Images.Add(new MediaCover.MediaCover
                {
                    Url       = resource.ImageUrl,
                    CoverType = MediaCoverTypes.Poster
                });
            }

            author.Links.Add(new Links {
                Url = resource.Url, Name = "Goodreads"
            });

            return(author);
        }
示例#3
0
        private static AuthorMetadata MapAuthor(AuthorResource resource)
        {
            var author = new AuthorMetadata
            {
                ForeignAuthorId = resource.Id.ToString(),
                TitleSlug       = resource.Id.ToString(),
                Name            = resource.Name.CleanSpaces(),
                Overview        = resource.About,
                Gender          = resource.Gender,
                Hometown        = resource.Hometown,
                Born            = resource.BornOnDate,
                Died            = resource.DiedOnDate,
                Status          = resource.DiedOnDate < DateTime.UtcNow ? AuthorStatusType.Ended : AuthorStatusType.Continuing
            };

            if (!NoPhotoRegex.IsMatch(resource.LargeImageUrl))
            {
                author.Images.Add(new MediaCover.MediaCover
                {
                    Url       = FullSizeImageRegex.Replace(resource.LargeImageUrl),
                    CoverType = MediaCoverTypes.Poster
                });
            }

            author.Links.Add(new Links {
                Url = resource.Link, Name = "Goodreads"
            });

            return(author);
        }
示例#4
0
        public void DeleteDataEntity(Guid dataEntityId)
        {
            LoadEntityMetadata();

            Guid authorId = FindAuthorOfDataEntity(dataEntityId);

            AuthorMetadata author = this.metadata.Authors.First(a => a.AuthorId == authorId);

            for (int i = 0; i < author.EntityIds.Count; i++)
            {
                if (author.EntityIds[i].Id == dataEntityId)
                {
                    author.EntityIds.RemoveAt(i);
                    break;
                }
            }
            if (author.EntityIds.Count == 0)
            {
                this.metadata.Authors.Remove(author);
            }

            EntityMetadata entity = this.metadata.Entities.First(e => e.Id == dataEntityId);

            foreach (EntityAttribute attribute in entity.Attributes)
            {
                AttributeMetadata amd = this.metadata.Attributes.First(a => a.AttributeId == attribute.Id);
                for (int i = 0; i < amd.EntityIds.Count; i++)
                {
                    if (amd.EntityIds[i].Id == dataEntityId)
                    {
                        amd.EntityIds.RemoveAt(i);
                        break;
                    }
                }
                if (amd.EntityIds.Count == 0)
                {
                    this.metadata.Attributes.Remove(amd);
                }
            }

            this.metadata.Entities.Remove(entity);

            string payloadPath = Path.Combine(this.entityDirPath, dataEntityId.ToString());

            File.Delete(payloadPath);

            SaveEntityMetadata();
        }
示例#5
0
        private static AuthorMetadata MapAuthor(AuthorSummaryResource resource)
        {
            var author = new AuthorMetadata
            {
                ForeignAuthorId = resource.Id.ToString(),
                Name            = resource.Name.CleanSpaces(),
                TitleSlug       = resource.Id.ToString()
            };

            author.SortName          = author.Name.ToLower();
            author.NameLastFirst     = author.Name.ToLastFirst();
            author.SortNameLastFirst = author.NameLastFirst.ToLower();

            if (resource.RatingsCount.HasValue)
            {
                author.Ratings = new Ratings
                {
                    Votes = resource.RatingsCount ?? 0,
                    Value = resource.AverageRating ?? 0
                };
            }

            return(author);
        }
示例#6
0
        private static AuthorMetadata MapAuthorMetadata(AuthorResource resource)
        {
            var metadata = new AuthorMetadata
            {
                ForeignAuthorId = resource.ForeignId.ToString(),
                TitleSlug       = resource.ForeignId.ToString(),
                Name            = resource.Name.CleanSpaces(),
                Overview        = resource.Description,
                Ratings         = new Ratings {
                    Votes = resource.RatingCount, Value = (decimal)resource.AverageRating
                },
                Status = AuthorStatusType.Continuing
            };

            metadata.SortName          = metadata.Name.ToLower();
            metadata.NameLastFirst     = metadata.Name.ToLastFirst();
            metadata.SortNameLastFirst = metadata.NameLastFirst.ToLower();

            if (resource.ImageUrl.IsNotNullOrWhiteSpace())
            {
                metadata.Images.Add(new MediaCover.MediaCover
                {
                    Url       = resource.ImageUrl,
                    CoverType = MediaCoverTypes.Poster
                });
            }

            if (resource.Url.IsNotNullOrWhiteSpace())
            {
                metadata.Links.Add(new Links {
                    Url = resource.Url, Name = "Goodreads"
                });
            }

            return(metadata);
        }
示例#7
0
        public void InsertDataEntity(Guid userId, DataEntity dataEntity)
        {
            LoadEntityMetadata();

            AuthorMetadata        author;
            List <AuthorMetadata> authors = this.metadata.Authors.Where(a => a.AuthorId == userId).ToList();

            if (authors.Count == 1)
            {
                author = authors[0];
            }
            else
            {
                author = new AuthorMetadata();
                this.metadata.Authors.Add(author);
                author.AuthorId = userId;
            }

            author.EntityIds.Add(new EntityId(dataEntity.Id));

            foreach (Attribute attribute in dataEntity.Attributes)
            {
                AttributeMetadata        am;
                Attribute                modifiedClosureCopy = attribute;
                List <AttributeMetadata> ams = this.metadata.Attributes.Where(a => a.AttributeId == modifiedClosureCopy.Id).ToList();

                if (ams.Count == 1)
                {
                    am = ams[0];
                }
                else
                {
                    am = new AttributeMetadata();
                    this.metadata.Attributes.Add(am);
                    am.AttributeId = attribute.Id;
                }

                am.EntityIds.Add(new EntityId(dataEntity.Id));
            }

            EntityMetadata        entity;
            List <EntityMetadata> entities = this.metadata.Entities.Where(e => e.Id == dataEntity.Id).ToList();

            if (entities.Count == 1)
            {
                entity = entities[0];
            }
            else
            {
                entity = new EntityMetadata();
                this.metadata.Entities.Add(entity);
            }

            entity.Id        = dataEntity.Id;
            entity.Signature = Convert.ToBase64String(dataEntity.Signature.Value);
            foreach (Attribute attribute in dataEntity.Attributes)
            {
                entity.Attributes.Add(new EntityAttribute(attribute.Id, Convert.ToBase64String(attribute.Keyword)));
            }
            entity.Name   = Convert.ToBase64String(dataEntity.Payload.Name);
            entity.Size   = dataEntity.Payload.Size;
            entity.AesKey = Convert.ToBase64String(dataEntity.AesInfo.Key);
            entity.AesIV  = Convert.ToBase64String(dataEntity.AesInfo.IV);

            SaveEntityMetadata();

            File.WriteAllBytes(Path.Combine(this.entityDirPath, dataEntity.Id.ToString()), dataEntity.Payload.Content);
        }
示例#8
0
        private static BookFile Map(BookFile file, Edition edition, Book book, Author author, AuthorMetadata metadata)
        {
            file.Edition = edition;

            if (edition != null)
            {
                edition.Book = book;
            }

            if (author != null)
            {
                author.Metadata = metadata;
            }

            file.Author = author;

            return(file);
        }