예제 #1
0
        public ArtistEntity FromBusinessEntity(Artist businessEntity, ArtistConvertOptions options)
        {
            if (businessEntity == null)
            {
                return(null);
            }

            ArtistEntity dataEntity = new ArtistEntity()
            {
                ID           = businessEntity.ID,
                Name         = businessEntity.Name,
                PrivateMarks = businessEntity.PrivateMarks,
                Biography    = businessEntity.Biography,
                IsWaste      = businessEntity.IsWaste
            };

            if (options == ArtistConvertOptions.Full)
            {
                foreach (Tag tagBusinessEntity in businessEntity.Tags)
                {
                    TagEntity tagDataEntity = FromBusinessEntity(tagBusinessEntity);
                    dataEntity.Tags.Add(tagDataEntity);
                }

                foreach (Album albumBusinessEntity in businessEntity.Albums)
                {
                    AlbumEntity albumDataEntity = FromBusinessEntity(albumBusinessEntity);
                    dataEntity.Albums.Add(albumDataEntity);
                }
            }

            return(dataEntity);
        }
예제 #2
0
        public Artist FromDataEntity(ArtistEntity dataEntity, ArtistConvertOptions options)
        {
            if (dataEntity == null)
            {
                return(null);
            }

            Artist businessEntity = new Artist()
            {
                ID           = dataEntity.ID,
                Name         = dataEntity.Name,
                PrivateMarks = dataEntity.PrivateMarks,
                Biography    = dataEntity.Biography,
                IsWaste      = dataEntity.IsWaste
            };

            if (options == ArtistConvertOptions.Full)
            {
                foreach (TagEntity tagDataEntity in dataEntity.Tags)
                {
                    businessEntity.Tags.Add(FromDataEntity(tagDataEntity));
                }

                foreach (AlbumEntity albumEntity in dataEntity.Albums)
                {
                    businessEntity.Albums.Add(FromDataEntity(albumEntity, AlbumConvertOptions.Small));
                }
            }

            return(businessEntity);
        }
예제 #3
0
        public Task <Status> AddArtistInfoAsync(FullArtistInfo artistInfo, CancellationToken token)
        {
            return(Task.Run(async() =>
            {
                using var contextContainer = _dbContextFactory.Create();
                var context = contextContainer.Context;

                try
                {
                    var artist = new ArtistEntity
                    {
                        ProviderId = artistInfo.Artist.ProviderId,
                        Name = artistInfo.Artist.Name
                    };

                    context.Artists.Add(artist);
                    await context.SaveChangesAsync(token);

                    context.Albums.AddRange(artistInfo.Albums.Select(i => new AlbumEntity
                    {
                        ProviderId = i.ProviderId,
                        Name = i.Name,
                        ArtistId = artist.Id
                    }));
                    await context.SaveChangesAsync(token);

                    return Status.Ok;
                }
                catch (Exception)
                {
                    return Status.Fail;
                }
            }, token));
        }
예제 #4
0
    public void WhereLiteEqualsIB()
    {
        ArtistEntity michael = Database.Query <ArtistEntity>().SingleEx(a => a.Dead);

        var albums = (from a in Database.Query <AlbumEntity>()
                      where a.Author.ToLite().Is(michael.ToLite())
                      select a.ToLite()).ToList();
    }
예제 #5
0
    public void WhereLiteEqualsIBA()
    {
        ArtistEntity michael = Database.Query <ArtistEntity>().SingleEx(a => a.Dead);

        var albums = (from n in Database.Query <NoteWithDateEntity>()
                      where n.Target.ToLite().Is(michael.ToLite())
                      select n.ToLite()).ToList();
    }
 public static ArtistModel ToModel(this ArtistEntity artist)
 {
     return(new()
     {
         Id = artist.Id.ToItemId(),
         Name = artist.Name,
     });
 }
예제 #7
0
        public void CrawlArtists(List <Cast> castItems)
        {
            if (castItems == null)
            {
                return;
            }

            try
            {
                string artistPageContent = string.Empty;

                TableManager        tblMgr = new TableManager();
                List <ArtistEntity> aeList = new List <ArtistEntity>();

                foreach (Cast cast in castItems)
                {
                    if (string.IsNullOrEmpty(cast.link))
                    {
                        continue;
                    }

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(cast.link);
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            #region Get Artist Page Content
                            using (Stream receiveStream = response.GetResponseStream())
                            {
                                using (StreamReader readStream =
                                           response.CharacterSet == null ?
                                           new StreamReader(receiveStream)
                                        : new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet)))
                                {
                                    artistPageContent = readStream.ReadToEnd();
                                }
                            }
                            #endregion
                        }
                    }

                    ArtistEntity artist = PopulateArtistsDetails(artistPageContent, cast.link);
                    aeList.Add(artist);
                }

                //tblMgr.UpdateArtistItemById(aeList);

                foreach (ArtistEntity obj in aeList)
                {
                    tblMgr.UpdateArtistById(obj);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
예제 #8
0
    public void WhereLiteEquals()
    {
        ArtistEntity wretzky = Database.Query <ArtistEntity>().SingleEx(a => a.Sex == Sex.Female);

        BandEntity smashing = (from b in Database.Query <BandEntity>()
                               from a in b.Members
                               where a.ToLite().Is(wretzky.ToLite())
                               select b).SingleEx();
    }
예제 #9
0
        public void UpdateMListEntity()
        {
            using (Transaction tr = new Transaction())
            {
                ArtistEntity artist = Database.Query <ArtistEntity>().FirstEx();

                int count = Database.MListQuery((BandEntity a) => a.Members).UnsafeUpdateMList()
                            .Set(mle => mle.Element, mle => artist)
                            .Execute();
                //tr.Commit();
            }
        }
예제 #10
0
        public void UpdateIbaLiteCoallesce()
        {
            using (Transaction tr = new Transaction())
            {
                ArtistEntity michael = Database.Query <ArtistEntity>().SingleEx(a => a.Dead);

                int count = Database.Query <NoteWithDateEntity>().UnsafeUpdate()
                            .Set(a => a.OtherTarget, a => a.OtherTarget ?? michael.ToLite())
                            .Execute();
                //tr.Commit();
            }
        }
예제 #11
0
        public void UpdateIbaLiteConditional()
        {
            using (Transaction tr = new Transaction())
            {
                ArtistEntity michael = Database.Query <ArtistEntity>().SingleEx(a => a.Dead);

                int count = Database.Query <NoteWithDateEntity>().UnsafeUpdate()
                            .Set(a => a.OtherTarget, a => a.CreationTime > DateTime.Today ? michael.ToLite() : null)
                            .Execute();
                //tr.Commit();
            }
        }
예제 #12
0
        public void UpdateIbFieConditional()
        {
            using (Transaction tr = new Transaction())
            {
                ArtistEntity michael = Database.Query <ArtistEntity>().SingleEx(a => a.Dead);

                int count = Database.Query <AlbumEntity>().UnsafeUpdate()
                            .Set(a => a.Author, a => a.Id > 1 ? michael : null)
                            .Execute();
                //tr.Commit();
            }
        }
예제 #13
0
    public void UpdateIbaFie()
    {
        using (var tr = new Transaction())
        {
            ArtistEntity michael = Database.Query <ArtistEntity>().SingleEx(a => a.Dead);

            int count = Database.Query <NoteWithDateEntity>().UnsafeUpdate()
                        .Set(a => a.Target, a => michael)
                        .Execute();
            //tr.Commit();
        }
    }
예제 #14
0
    public void UpdateIbaConditional()
    {
        using (var tr = new Transaction())
        {
            ArtistEntity michael = Database.Query <ArtistEntity>().SingleEx(a => a.Dead);

            int count = Database.Query <NoteWithDateEntity>().UnsafeUpdate()
                        .Set(a => a.Target, a => a.CreationTime > Clock.Now ? michael : null !)
                        .Execute();
            //tr.Commit();
        }
    }
예제 #15
0
        public static bool UpdateArtistById(this IStore store, ArtistEntity artist)
        {
            Debug.Assert(artist != null);
            var list = new List <ArtistEntity> {
                artist
            };
            var retList = store.UpdateArtistItemById(list);

            Debug.Assert(retList.Count == 1);
            var key = retList.Keys.FirstOrDefault();

            return((key != null) ? retList[key] : false);
        }
예제 #16
0
        public void UpdateMListLite()
        {
            using (Transaction tr = new Transaction())
            {
                ArtistEntity artist = Database.Query <ArtistEntity>().FirstEx();

                int count = Database.MListQuery((ArtistEntity a) => a.Friends).UnsafeUpdateMList()
                            .Set(mle => mle.Element, mle => artist.ToLite())
                            .Set(mle => mle.Parent, mle => artist)
                            .Execute();

                var list = Database.MListQuery((ArtistEntity a) => a.Friends);
                //tr.Commit();
            }
        }
예제 #17
0
        private Artist SaveArtist(Artist artist, SoundCloudLiteContext context)
        {
            ArtistEntity result;

            if (artist.Id != Guid.Empty)
            {
                result = context.Artists.First(x => x.Id == artist.Id).MapToEntity(artist);
            }
            else
            {
                result    = new ArtistEntity().MapToEntity(artist);
                result.Id = Guid.NewGuid();
                context.Artists.Add(result);
            }

            return(result.MapToModel());
        }
예제 #18
0
        public async Task <IActionResult> Put(int id, [FromBody] ArtistEntity value)
        {
            try
            {
                var artist = myDbContext.Artist.Find(value.artistId);
                artist.Name      = value.name;
                artist.Birthdate = value.birthdate;
                artist.Country   = value.country;
                artist.City      = value.city;

                myDbContext.SaveChanges();
                return(Ok(artist));
            }
            catch
            {
                return(BadRequest());
            }
        }
예제 #19
0
        private string GetTwitterHandle(string type, string name)
        {
            TableManager tbl = new TableManager();

            switch (type)
            {
            case "movie":
                MovieEntity movie = tbl.GetMovieByUniqueName(name);
                return(movie.TwitterHandle);

            case "artist":
                ArtistEntity artist = tbl.GetArtist(name);
                return(artist.TwitterHandle);

            case "critics":
                return(string.Empty);
            }

            return(string.Empty);
        }
예제 #20
0
 public async Task <IActionResult> Post([FromBody] ArtistEntity value)
 {
     try
     {
         var artist = new Artist()
         {
             ArtistId  = value.artistId,
             Name      = value.name,
             Birthdate = value.birthdate,
             Country   = value.country,
             City      = value.city,
         };
         myDbContext.Add(artist);
         myDbContext.SaveChanges();
         return(Ok(artist));
     }
     catch
     {
         return(BadRequest());
     }
 }
예제 #21
0
        public ArtistEntity PopulateArtistsDetails(string html, string url)
        {
            try
            {
                ArtistEntity artist = new ArtistEntity();
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                htmlDoc.OptionFixNestedTags = true;
                htmlDoc.LoadHtml(html);
                if (htmlDoc.DocumentNode != null)
                {
                    HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body");
                    if (bodyNode == null)
                    {
                        Console.WriteLine("body node is null");
                    }
                    else
                    {
                        artist.RowKey     = artist.ArtistId = Guid.NewGuid().ToString();
                        artist.ArtistName = GetArtistName(bodyNode);
                        artist.UniqueName = artist.ArtistName.Replace(" ", "-");
                        artist.Bio        = GetArtistBio(bodyNode);
                        artist.Born       = GetArtistBirthDetails(bodyNode);
                        artist.MovieList  = GetMovieList(bodyNode);
                        artist.Posters    = GetArtistPosters(url + "mediaindex", artist.UniqueName, bodyNode);
                        artist.Popularity = Util.DEFAULT_POPULARITY;
                        artist.MyScore    = Util.DEFAULT_SCORE;
                        artist.JsonString = string.Empty;
                    }
                }

                return(artist);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.Message);
                return(null);
            }
        }