Example #1
0
 public ActionResult Images(int id)
 {
     WgArtists data = new WgArtists();
     ArtistPage model = new ArtistPage();
     model.Artist = (from a in data.Artists where a.ArtistId == id select a).Single();
     model.Images = (from i in data.Images where i.ArtistId == id select i).OrderBy(i => i.DisplayOrder).ToList();
     return View(model);
 }
Example #2
0
        public ActionResult Bio(int id)
        {
            WgArtists  data  = new WgArtists();
            ArtistPage model = new ArtistPage();

            model.Artist = (from a in data.Artists where a.ArtistId == id select a).Single();
            model.Images = (from i in data.Images where i.ArtistId == id select i).ToList();
            return(View(model));
        }
 bool CanDelete(ArtistPage artistPage)
 {
     if (artistPage == null)
     {
         return(false);
     }
     return(ApplicationContext.Current.CurrentUser.Id == artistPage.PageOwnerId || //page owner
            ApplicationContext.Current.CurrentUser.IsAdministrator()); //administrator
 }
 private void SaveArtistPhoto(Artist artist, ArtistPage artistPage)
 {
     for (int i = 0; i < artistPage.ArtistPhotos.Count; i++)
     {
         Image img = Image.FromStream(HtmlRequestHelper.GetStream(artistPage.ArtistPhotos[i], artistPage.ArtistPhotos[i]));
         img.Save(@"D:\Project\MvcRockShop\Artist\" + artist.Id + "_" + i + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
         img.Dispose();
     }
 }
Example #5
0
        public ActionResult Artist(int id)
        {
            WgArtists  data  = new WgArtists();
            ArtistPage model = new ArtistPage();

            model.Artist   = (from a in data.Artists where a.ArtistId == id select a).Single();
            model.Images   = (from i in data.Images where i.ArtistId == id select i).OrderBy(i => i.DisplayOrder).ToList();
            model.SiteText = (from t in data.SiteText select t).ToList();
            return(View(model));
        }
Example #6
0
 bool CanEdit(ArtistPage ArtistPage)
 {
     if (ArtistPage == null)
     {
         return(false);
     }
     return(_workContext.CurrentCustomer.Id == ArtistPage.PageOwnerId || //page owner
            _workContext.CurrentCustomer.IsAdmin() || //administrator
            _artistPageManagerService.IsPageManager(ArtistPage.Id, _workContext.CurrentCustomer.Id)); //page manager
 }
 bool CanEdit(ArtistPage ArtistPage)
 {
     if (ArtistPage == null)
     {
         return(false);
     }
     return(ApplicationContext.Current.CurrentUser.Id == ArtistPage.PageOwnerId || //page owner
            ApplicationContext.Current.CurrentUser.IsAdministrator() || //administrator
            _artistPageManagerService.IsPageManager(ArtistPage.Id, ApplicationContext.Current.CurrentUser.Id)); //page manager
 }
        public ActionResult Create(Artist artist, int category)
        {
            ArtistPage artistPage = SearchEngine.SearchArtist(artist.Name);

            DomToArtist(artistPage, artist, category);
            db.Artists.Add(artist);
            db.SaveChanges();
            SaveArtistPhoto(artist, artistPage);
            SaveCover(artistPage.AlbumPages, artist.Albums.ToList());
            return(Content("新增成功"));
        }
Example #9
0
 public PageObjectManager()
 {
     LoginPage       = new LoginPage();
     HomePage        = new HomePage();
     AlbumPage       = new AlbumPage();
     ArtistPage      = new ArtistPage();
     PlaylistPage    = new PlaylistPage();
     QueuePage       = new QueuePage();
     SearchPage      = new SearchPage();
     YourLibraryPage = new YourLibraryPage();
 }
Example #10
0
        ArtistPage SaveRemoteArtistToDB(string artistJson)
        {
            if (string.IsNullOrEmpty(artistJson))
            {
                return(null);
            }

            var        artist     = (JObject)JsonConvert.DeserializeObject(artistJson);
            ArtistPage artistPage = new ArtistPage()
            {
                PageOwnerId      = _workContext.CurrentCustomer.IsAdmin() ? _workContext.CurrentCustomer.Id : 0,
                Biography        = artist["Description"].ToString(),
                Name             = artist["Name"].ToString(),
                Gender           = artist["Gender"].ToString(),
                HomeTown         = artist["HomeTown"].ToString(),
                RemoteEntityId   = artist["RemoteEntityId"].ToString(),
                RemoteSourceName = artist["RemoteSourceName"].ToString(),
                ShortDescription = "",
            };

            _artistPageService.Insert(artistPage);

            //we can now download the image from the server and store it on our own server
            //use the json we retrieved earlier

            if (!string.IsNullOrEmpty(artist["ImageUrl"].ToString()))
            {
                var imageUrl   = artist["ImageUrl"].ToString();
                var imageBytes = HttpHelper.ExecuteGET(imageUrl);
                if (imageBytes != null)
                {
                    var fileExtension = Path.GetExtension(imageUrl);
                    if (!String.IsNullOrEmpty(fileExtension))
                    {
                        fileExtension = fileExtension.ToLowerInvariant();
                    }

                    var contentType = PictureUtility.GetContentType(fileExtension);

                    var picture       = _pictureService.InsertPicture(imageBytes, contentType, artistPage.GetSeName(_workContext.WorkingLanguage.Id, true, false));
                    var artistPicture = new ArtistPagePicture()
                    {
                        EntityId     = artistPage.Id,
                        DateCreated  = DateTime.Now,
                        DateUpdated  = DateTime.Now,
                        DisplayOrder = 1,
                        PictureId    = picture.Id
                    };
                    _artistPageService.InsertPicture(artistPicture);
                }
            }
            return(artistPage);
        }
        ArtistPage SaveRemoteArtistToDB(string artistJson)
        {
            if (string.IsNullOrEmpty(artistJson))
            {
                return(null);
            }

            var artist     = (JObject)JsonConvert.DeserializeObject(artistJson);
            var artistPage = new ArtistPage()
            {
                PageOwnerId      = ApplicationContext.Current.CurrentUser.IsAdministrator() ? ApplicationContext.Current.CurrentUser.Id : 0,
                Biography        = artist["Description"].ToString(),
                Name             = artist["Name"].ToString(),
                Gender           = artist["Gender"].ToString(),
                HomeTown         = artist["HomeTown"].ToString(),
                RemoteEntityId   = artist["RemoteEntityId"].ToString(),
                RemoteSourceName = artist["RemoteSourceName"].ToString(),
                ShortDescription = "",
            };

            _artistPageService.Insert(artistPage);

            //we can now download the image from the server and store it on our own server
            //use the json we retrieved earlier

            if (!string.IsNullOrEmpty(artist["ImageUrl"].ToString()))
            {
                var imageUrl   = artist["ImageUrl"].ToString();
                var imageBytes = HttpHelper.ExecuteGet(imageUrl);
                if (imageBytes != null)
                {
                    var fileExtension = Path.GetExtension(imageUrl);
                    if (!String.IsNullOrEmpty(fileExtension))
                    {
                        fileExtension = fileExtension.ToLowerInvariant();
                    }

                    var contentType = PictureUtility.GetContentType(fileExtension);
                    var picture     = new Media()
                    {
                        Binary   = imageBytes,
                        MimeType = contentType,
                        Name     = artistPage.Name
                    };
                    _pictureService.WritePictureBytes(picture, _mediaSettings.PictureSaveLocation);

                    _pictureService.AttachMediaToEntity(artistPage, picture);
                }
            }
            return(artistPage);
        }
        public IHttpActionResult SaveArtist(ArtistPageModel model)
        {
            if (!ModelState.IsValid)
            {
                VerboseReporter.ReportError("Invalid data submitted. Please check all fields and try again.", "save_artist");
                return(RespondFailure());
            }

            if (!ApplicationContext.Current.CurrentUser.IsRegistered())
            {
                VerboseReporter.ReportError("Unauthorized access", "save_artist");
                return(RespondFailure());
            }

            //check to see if artist name already exists
            string artistJson;

            if (IsArtistPageNameAvailable(model.Name, out artistJson))
            {
                var artistPage = new ArtistPage()
                {
                    PageOwnerId      = ApplicationContext.Current.CurrentUser.Id,
                    Biography        = model.Description,
                    Name             = model.Name,
                    DateOfBirth      = model.DateOfBirth,
                    Gender           = model.Gender,
                    HomeTown         = model.HomeTown,
                    RemoteEntityId   = model.RemoteEntityId,
                    RemoteSourceName = model.RemoteSourceName,
                    ShortDescription = model.ShortDescription
                };

                _artistPageService.Insert(artistPage);

                if (artistJson != "")
                {
                    //we can now download the image from the server and store it on our own server
                    //use the json we retrieved earlier
                    var jObject = (JObject)JsonConvert.DeserializeObject(artistJson);

                    if (!string.IsNullOrEmpty(jObject["ImageUrl"].ToString()))
                    {
                        var imageUrl      = jObject["ImageUrl"].ToString();
                        var imageBytes    = HttpHelper.ExecuteGet(imageUrl);
                        var fileExtension = Path.GetExtension(imageUrl);
                        if (!string.IsNullOrEmpty(fileExtension))
                        {
                            fileExtension = fileExtension.ToLowerInvariant();
                        }

                        var contentType = PictureUtility.GetContentType(fileExtension);
                        var picture     = new Media()
                        {
                            Binary   = imageBytes,
                            Name     = model.Name,
                            MimeType = contentType
                        };
                        _pictureService.WritePictureBytes(picture, _mediaSettings.PictureSaveLocation);
                        //relate both page and picture
                        _pictureService.AttachMediaToEntity(artistPage, picture);
                    }
                }

                return(Response(new {
                    Success = true,
                    RedirectTo = Url.Route("ArtistPageUrl", new RouteValueDictionary()
                    {
                        { "SeName", artistPage.GetPermalink() }
                    })
                }));
            }
            else
            {
                return(Response(new {
                    Success = false,
                    Message = "DuplicateName"
                }));
            }
        }
        public IHttpActionResult GetRelatedArtists(int artistId)
        {
            var artistPage = _artistPageService.Get(artistId);
            var model      = new List <object>();

            if (string.IsNullOrEmpty(artistPage?.RemoteEntityId)) //if it's not a remote artist means some user has created it. so no related artists
            {
                return(Response(model));
            }

            var relatedArtistsRemoteCollection = _artistPageApiService.GetRelatedArtists(artistPage.RemoteEntityId);

            if (relatedArtistsRemoteCollection == null)
            {
                return(Response(model));
            }


            //get all the remote entity ids from the remote collection. We'll see those ids in our database to find matches
            //we'll deserialize the list to get the object items
            var relatedArtistDeserialized = new List <JObject>();

            foreach (var rarcItem in relatedArtistsRemoteCollection)
            {
                relatedArtistDeserialized.Add((JObject)JsonConvert.DeserializeObject(rarcItem));
            }
            //get the entity ids
            var relatedArtistsRemoteEntityIds = relatedArtistDeserialized.Select(x => x["RemoteEntityId"].ToString());

            //get all the related artists which we already have in our database
            var relatedArtistsInDB = _artistPageService.GetArtistPagesByRemoteEntityId(relatedArtistsRemoteEntityIds.ToArray());

            var relatedArtistsInDBIds = relatedArtistsInDB.Select(m => m.RemoteEntityId).ToList();

            //lets now find the ones which we don't have in our database. we'll save them by importing
            var relatedArtistsToBeImportedIds = relatedArtistsRemoteEntityIds.Except(relatedArtistsInDBIds).ToList();

            foreach (var reid in relatedArtistsToBeImportedIds)
            {
                var        artistJson        = relatedArtistDeserialized.First(x => x["RemoteEntityId"].ToString() == reid).ToString();
                ArtistPage relatedartistPage = SaveRemoteArtistToDB(artistJson);
                relatedArtistsInDB.Add(relatedartistPage); //add new page to list of db pages
            }

            foreach (var ra in relatedArtistsInDB)
            {
                var imageUrl = "";
                var pictures = ra.GetPictures();
                if (pictures != null && pictures.Count > 0)
                {
                    imageUrl = _pictureService.GetPictureUrl(pictures.First());
                }

                model.Add(new {
                    Name             = ra.Name,
                    Id               = ra.Id,
                    ImageUrl         = imageUrl,
                    ShortDescription = ra.ShortDescription,
                    SeName           = ra.GetPermalink(),
                    RemoteArtist     = false
                });
            }

            return(Response(model));
        }
        ArtistPage SaveRemoteArtistToDB(string artistJson)
        {
            if (string.IsNullOrEmpty(artistJson))
                return null;

            var artist = (JObject)JsonConvert.DeserializeObject(artistJson);
            var artistPage = new ArtistPage() {
                PageOwnerId = ApplicationContext.Current.CurrentUser.IsAdministrator() ? ApplicationContext.Current.CurrentUser.Id : 0,
                Biography = artist["Description"].ToString(),
                Name = artist["Name"].ToString(),
                Gender = artist["Gender"].ToString(),
                HomeTown = artist["HomeTown"].ToString(),
                RemoteEntityId = artist["RemoteEntityId"].ToString(),
                RemoteSourceName = artist["RemoteSourceName"].ToString(),
                ShortDescription = "",
            };

            _artistPageService.Insert(artistPage);

            //we can now download the image from the server and store it on our own server
            //use the json we retrieved earlier

            if (!string.IsNullOrEmpty(artist["ImageUrl"].ToString()))
            {
                var imageUrl = artist["ImageUrl"].ToString();
                var imageBytes = HttpHelper.ExecuteGet(imageUrl);
                if (imageBytes != null)
                {
                    var fileExtension = Path.GetExtension(imageUrl);
                    if (!String.IsNullOrEmpty(fileExtension))
                        fileExtension = fileExtension.ToLowerInvariant();

                    var contentType = PictureUtility.GetContentType(fileExtension);
                    var picture = new Media()
                    {
                        Binary = imageBytes,
                        MimeType = contentType,
                        Name = artistPage.Name
                    };
                    _pictureService.WritePictureBytes(picture, _mediaSettings.PictureSaveLocation);

                    _pictureService.AttachMediaToEntity(artistPage, picture);

                }

            }
            return artistPage;
        }
 bool CanEdit(ArtistPage ArtistPage)
 {
     if (ArtistPage == null)
         return false;
     return ApplicationContext.Current.CurrentUser.Id == ArtistPage.PageOwnerId //page owner
         || ApplicationContext.Current.CurrentUser.IsAdministrator() //administrator
         || _artistPageManagerService.IsPageManager(ArtistPage.Id, ApplicationContext.Current.CurrentUser.Id); //page manager
 }
        public IHttpActionResult SaveArtist(ArtistPageModel model)
        {
            if (!ModelState.IsValid)
            {
                VerboseReporter.ReportError("Invalid data submitted. Please check all fields and try again.", "save_artist");
                return RespondFailure();
            }

            if (!ApplicationContext.Current.CurrentUser.IsRegistered())
            {
                VerboseReporter.ReportError("Unauthorized access", "save_artist");
                return RespondFailure();
            }

            //check to see if artist name already exists
            string artistJson;
            if (IsArtistPageNameAvailable(model.Name, out artistJson))
            {
                var artistPage = new ArtistPage() {
                    PageOwnerId = ApplicationContext.Current.CurrentUser.Id,
                    Biography = model.Description,
                    Name = model.Name,
                    DateOfBirth = model.DateOfBirth,
                    Gender = model.Gender,
                    HomeTown = model.HomeTown,
                    RemoteEntityId = model.RemoteEntityId,
                    RemoteSourceName = model.RemoteSourceName,
                    ShortDescription = model.ShortDescription
                };

                _artistPageService.Insert(artistPage);

                if (artistJson != "")
                {
                    //we can now download the image from the server and store it on our own server
                    //use the json we retrieved earlier
                    var jObject = (JObject)JsonConvert.DeserializeObject(artistJson);

                    if (!string.IsNullOrEmpty(jObject["ImageUrl"].ToString()))
                    {
                        var imageUrl = jObject["ImageUrl"].ToString();
                        var imageBytes = HttpHelper.ExecuteGet(imageUrl);
                        var fileExtension = Path.GetExtension(imageUrl);
                        if (!string.IsNullOrEmpty(fileExtension))
                            fileExtension = fileExtension.ToLowerInvariant();

                        var contentType = PictureUtility.GetContentType(fileExtension);
                        var picture = new Media()
                        {
                            Binary = imageBytes,
                            Name = model.Name,
                            MimeType = contentType
                        };
                        _pictureService.WritePictureBytes(picture, _mediaSettings.PictureSaveLocation);
                        //relate both page and picture
                        _pictureService.AttachMediaToEntity(artistPage, picture);
                    }

                }

                return Response(new {
                    Success = true,
                    RedirectTo = Url.Route("ArtistPageUrl", new RouteValueDictionary()
                    {
                        { "SeName" , artistPage.GetPermalink()}
                    })
                });

            }
            else
            {
                return Response(new {
                    Success = false,
                    Message = "DuplicateName"
                });
            }
        }
 private void DomToArtist(ArtistPage artistPage, Artist artist, int categoryId)
 {
     artist.Albums = DomsToAlbums(artistPage.AlbumPages, categoryId);
 }
 private void DomToArtist(ArtistPage artistPage,Artist artist,int categoryId)
 {
     artist.Albums = DomsToAlbums(artistPage.AlbumPages, categoryId);
 }
 private void SaveArtistPhoto(Artist artist, ArtistPage artistPage)
 {
     for (int i = 0; i < artistPage.ArtistPhotos.Count; i++)
     {
         Image img=Image.FromStream(HtmlRequestHelper.GetStream(artistPage.ArtistPhotos[i],artistPage.ArtistPhotos[i]));
         img.Save(@"D:\Project\MvcRockShop\Artist\"+artist.Id+"_"+i+".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
         img.Dispose();
     }
 }
Example #20
0
        private static async Task <int> Main()
        {
            string?knownArtistListFilename = Environment.GetCommandLineArgs().Skip(1).FirstOrDefault();

            if (knownArtistListFilename == null)
            {
                Console.WriteLine("Please pass the filename of a newline-delimited text file containing a list of known artists to look up as the first argument.");
                return(1);
            }

            ISet <string> knownArtistNames = new HashSet <string>((await File.ReadAllLinesAsync(knownArtistListFilename, Encoding.UTF8)).Select(s => s.ToLowerInvariant()));

            var blockOptions = new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = MAX_PARALLEL_DOWNLOADS
            };

            TransformBlock <string, ArtistPage> fetchSource = new TransformBlock <string, ArtistPage>(async artistName => {
                Uri artistUri = FluentUriBuilder.From(BASE_URI.AbsoluteUri).Path(artistName.ToLowerInvariant()).ToUri();
                using HttpResponseMessage response = await CLIENT.GetAsync(artistUri);

                var artistPage = new ArtistPage {
                    artistName = artistName
                };
                if (response.IsSuccessStatusCode)
                {
                    artistPage.sourceCode = await response.Content.ReadAsStringAsync();
                }
                else
                {
                    Console.WriteLine($"Error: Failed to download artist page for {artistName}: {response.StatusCode}. Please check the artist name on {BASE_URI}");
                }

                return(artistPage);
            }, blockOptions);

            TransformManyBlock <ArtistPage, Relationship> extractRelationships = new TransformManyBlock <ArtistPage, Relationship>(page => {
                if (page.sourceCode == null)
                {
                    return(null);
                }

                MatchCollection artistNameMatches       = Regex.Matches(page.sourceCode, @"<a href=""(?<artistSlug>.+?)"" class=S id=s\d+>(?<artistName>.+?)</a>");
                IEnumerable <string> relatedArtistNames = artistNameMatches.Skip(1).Select(match => match.Groups["artistName"].Value);

                Match relationshipStrengthMatches           = Regex.Match(page.sourceCode, @"Aid\[0\]=new Array\(-1(?:,(?<strength>-?\d+(?:\.\d+)?))*\);");
                IEnumerable <double> relatedArtistStrengths = relationshipStrengthMatches.Groups["strength"].Captures.Select(capture => double.Parse(capture.Value));

                return(relatedArtistNames.Zip(relatedArtistStrengths)
                       .Select(tuple => new Relationship {
                    knownArtist = page.artistName, unknownArtist = tuple.First, strength = tuple.Second
                }));
            }, blockOptions);

            IDictionary <string, double> strengthsByArtistName = new Dictionary <string, double>();
            ActionBlock <Relationship>   incoming = new ActionBlock <Relationship>(relationship => {
                if (knownArtistNames.Contains(relationship.unknownArtist.ToLowerInvariant()))
                {
                    return;
                }
                strengthsByArtistName.TryGetValue(relationship.unknownArtist, out double existingStrength);
                strengthsByArtistName[relationship.unknownArtist] = existingStrength + relationship.strength;
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 1
            });
            var outgoing = new BufferBlock <IDictionary <string, double> >();

#pragma warning disable 4014
            incoming.Completion.ContinueWith(task => { outgoing.Post(strengthsByArtistName); });
#pragma warning restore 4014

            IPropagatorBlock <Relationship, IDictionary <string, double> > reduce = DataflowBlock.Encapsulate(incoming, outgoing);

            ActionBlock <IDictionary <string, double> > printReport = new ActionBlock <IDictionary <string, double> >(strengths => {
                IOrderedEnumerable <KeyValuePair <string, double> > sorted = strengths.OrderByDescending(pair => pair.Value);
                foreach ((string unknownArtistName, double strength) in sorted)
                {
                    Console.WriteLine($"{strength,5:N1}\t{unknownArtistName}");
                }
            });

            DataflowLinkOptions linkOptions = new DataflowLinkOptions {
                PropagateCompletion = true
            };
            fetchSource.LinkTo(extractRelationships, linkOptions);
            extractRelationships.LinkTo(reduce, linkOptions);
            reduce.LinkTo(printReport, linkOptions);

            foreach (string knownArtistName in knownArtistNames)
            {
                fetchSource.Post(knownArtistName);
            }

            fetchSource.Complete();
            await printReport.Completion;
            return(0);
        }
 bool CanDelete(ArtistPage artistPage)
 {
     if (artistPage == null)
         return false;
     return ApplicationContext.Current.CurrentUser.Id == artistPage.PageOwnerId //page owner
         || ApplicationContext.Current.CurrentUser.IsAdministrator(); //administrator
 }