Exemplo n.º 1
0
 /// <summary>
 /// create initial playlist rating
 /// </summary>
 ///
 /// <param name="playlist">
 /// rating to attach this rating to
 /// </param>
 ///
 /// <param name="song">
 /// song being rated
 /// </param>
 ///
 /// <param name="creator">
 /// initial creator of the rating
 /// </param>
 public PlaylistSongRating(Playlist playlist, Song song, FbUser creator)
     : this()
 {
     Song = song;
     Playlist = playlist;
     Creator = creator;
 }
Exemplo n.º 2
0
        public static PlaylistWithUserDTO Map(Playlist playlist, UserDTO user)
        {
            var playlistDTO = new PlaylistWithUserDTO()
            {
                Playlist = Mapper.Map<Playlist, PlaylistDTO>(playlist),
                User = user
            };

            return playlistDTO;
        }
Exemplo n.º 3
0
        private static void SetReferringPlaylistSong(
            long referringPlaylistSongRatingId,
            Playlist playlist,
            ref List<PlaylistSongRating> ratingsList)
        {
            var referalPlaylistSong = ratingsList.FirstOrDefault(
                rating => rating.Id == referringPlaylistSongRatingId);

            if (referalPlaylistSong == null)
            {
                //finding element and moving it to the first position
                referalPlaylistSong = playlist.Ratings.FirstOrDefault(
                    rating => rating.Id == referringPlaylistSongRatingId);

                //in case playlistRatin was deleted
                if (referalPlaylistSong != null)
                {
                    ratingsList.Insert(0, referalPlaylistSong);
                }
            }
            else
            {
                ratingsList.Remove(referalPlaylistSong);
                ratingsList.Insert(0, referalPlaylistSong);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// is the current usere admin of relevant fan page?
        /// </summary>
        ///
        /// <param name="user">
        /// user to be mapped
        /// </param>
        ///
        /// <param name="playlist">
        /// playlist with which current operation is executed
        /// </param>
        ///
        /// <param name="privileges">
        /// additional information: user privileges to be set in returned
        /// object
        /// </param>
        ///
        /// <param name="loggedInUserInfo">
        /// cookie information about currently logged in user
        /// </param>
        ///
        /// <returns>
        /// mapped user object with additional information
        /// </returns>
        public static UserDTO Map(FbUser user,
            FbCookieInfo loggedInUserInfo,
            Playlist playlist,
            UserPrivileges privileges = UserPrivileges.None)
        {
            if (user == null)
            {
                return null;
            }

            var userDTO = MemberDTOFactory.Map<UserDTO>(user, playlist);

            userDTO.role = privileges.ToString();
            userDTO.IsPageAdmin = loggedInUserInfo.IsAdmin;
            userDTO.HasLikedPage = loggedInUserInfo.HasLikedPage;

            if (playlist == null)
            {
                return userDTO;
            }

            if (loggedInUserInfo.IsAdmin)
            {
                userDTO.name = playlist.LocalBusiness.Name;
                userDTO.FBID = playlist.LocalBusiness.FanPageId;
            }

            // TODO: test this assumption: We're assuming that since a user
            // doesn't have a score, it means he didn't even add a song
            // since he didn't add a song, that's why we can set numOfSongsAdded to playlist's max
            if (userDTO.score == 0)
            {
                userDTO.numOfSongsLeft = playlist.NumOfSongsLimit;
            }
            else
            {
                var userInfo = user.PlaylistsInfo.FirstOrDefault(p => p.Playlist == playlist);
                //TODO: remove redundant NumOfVotes column
                userDTO.numOfVotes = userInfo.NumOfVotes;
                userDTO.numOfSongsLeft = playlist.GetNumOfSongsLeft(user);
            }

            return userDTO;
        }
Exemplo n.º 5
0
        /// <summary>
        /// updates locale of the current session
        /// </summary>
        ///
        /// <param name="fbLocale">
        /// Facebook locale as received from signed request
        /// </param>
        ///
        /// <param name="pls">
        /// playlist from which locale should be pulled
        /// </param>
        private void UpdateLocale(string fbLocale, Playlist pls)
        {
            /* if the session does not exist yet, bail out */
            if (HttpContext.Session == null)
            {
                return;
            }

            /* ensure the locale is set correctly */
            var requiredLocale = SelectRequiredLocale(pls, fbLocale);
            var cu = (CultureInfo)
                HttpContext.Session[SessionVariables.CULTURE];
            if (cu != null && cu.Name.Equals(requiredLocale))
            {
                /* if the currently set locale matches the required one, do
                 * nothing */
                return;
            }

            cu = new CultureInfo(requiredLocale);
            HttpContext.Session[SessionVariables.CULTURE] = cu;

            /* Finally setting culture for each request */
            Thread.CurrentThread.CurrentUICulture = cu;
            Thread.CurrentThread.CurrentCulture =
                CultureInfo.CreateSpecificCulture(cu.Name);
        }
Exemplo n.º 6
0
        private ActionResult ShowDefaultScreen(Playlist playlist,
            long referringPlaylisingSongRating)
        {
            var pageInfoDTO =
                BuildPageInfoDto(playlist.LocalBusiness, LoadStrings());

            pageInfoDTO.ReferringPlaylisingSongRating =
                referringPlaylisingSongRating;

            pageInfoDTO.Strings = LoadStrings();

            return View(MVC.Playlist.Views.Playlist, pageInfoDTO);
        }
Exemplo n.º 7
0
 /// <summary>
 /// map playlist object into playlist DTO passed to the client
 /// </summary>
 ///
 /// <param name="playlist">
 /// playlist to convert
 /// </param>
 ///
 /// <param name="uniqueVotersCount">
 /// number of unique voters for this playlist
 /// </param>
 ///
 /// <returns>
 /// DTO of the playlist
 /// </returns>
 public static PlaylistDTO Map(Playlist playlist)
 {
     var playlistDTO = Mapper.Map<Playlist, PlaylistDTO>(playlist);
     playlistDTO.PublishAdminContentToWall =
         (playlist.LocalBusiness != null) &&
         playlist.LocalBusiness.PublishAdminContentToWall;
     playlistDTO.PublishUserContentToWall =
         (playlist.LocalBusiness != null) &&
             playlist.LocalBusiness.PublishUserContentToWall;
     return playlistDTO;
 }
Exemplo n.º 8
0
 private static PlaylistSongRating SaveSong(IRepository repository, Playlist playlist, FbUser votingUser,
     string artistName, string songName, double duration, string videoId, short rating, string imageUrl)
 {
     var song = new Song
         {
             Name = songName,
             ArtistName = artistName,
             Duration = duration,
             VideoID = videoId,
             ImageUrl = imageUrl
         };
     repository.Save(song);
     var playlistRating = playlist.AddSong(song, votingUser, playlist.IsOwner(votingUser.Id));
     repository.SaveOrUpdate(playlistRating);
     return playlistRating;
 }
Exemplo n.º 9
0
        public virtual JsonResult DetachSong(Playlist playlist,
            long playlistSongRatingId)
        {
            if (playlist == null)
            {
                return BuildFailureResult(-1,
                    App_GlobalResources.Errors.invalidPlaylist);
            }

            var playlistSongRating = playlist.Ratings
                .FirstOrDefault(ratings => ratings.Id == playlistSongRatingId);
            if (playlistSongRating == null)
            {
                return BuildFailureResult(-1,
                    App_GlobalResources.Errors.noRatingsForSong);
            }

            /* detaching song also removes all the rating of the songs in the
             * playlist */
            if (!MatchUserPrivilege(playlist, UserPrivileges.Owner) &&
                !MatchUserPrivilege(playlistSongRating, UserPrivileges.Owner))
            {
                return BuildFailureResult(-1,
                    App_GlobalResources.Errors.accessDenied);
            }

            var rating = playlist.DetachSong(playlistSongRating, CurrentUser);
            Repository.Delete(rating);
            Repository.Save(CurrentUser);

            var userDTO = BuildUserDTO(playlist);

            var playlistDto = PlaylistDTOFactory.Map(playlist);

            var renderedData = new
                {
                    user = userDTO,
                    playlist = playlistDto,
                    FBPostId = playlistSongRating.FBPostId
                };

            return BuildSuccessResult(0, renderedData);
        }
Exemplo n.º 10
0
 private static UserPlaylistInfo GetUserInfo(
     Playlist playlist, FbUser user)
 {
     return (playlist == null) ? null : playlist.GetUserInfo(user);
 }
Exemplo n.º 11
0
        protected void RewardUser(Playlist playlist,
            UserPlaylistInfo.Operation operation)
        {
            var currentUserInfo = GetUserInfo(playlist, CurrentUser);
            if (currentUserInfo == null)
            {
                return;
            }

            currentUserInfo.UpdateUserScore(operation);
            Repository.SaveOrUpdate(currentUserInfo);
        }
Exemplo n.º 12
0
        /// <summary>
        /// create user DTO based on current user and additional information from
        /// specified playlist
        /// </summary>
        ///
        /// <param name="playlist">
        /// playlist to extract data from
        /// </param>
        ///
        /// <param name="defaultPriv">
        /// default user privileges to be set in the DTO, if not specified,
        /// will be detected based on current user access to specified playlist
        /// </param>
        ///
        /// <returns>
        /// mapped user DTO object
        /// </returns>
        protected UserDTO BuildUserDTO(Playlist playlist,
            UserPrivileges defaultPriv = UserPrivileges.NotSet)
        {
            var priv = (defaultPriv != UserPrivileges.NotSet) ?
                defaultPriv : GetCurrentUserPrivileges(playlist);

            var usrDTO = UserDTOFactory.Map(
                CurrentUser,
                CurrentUserFBInfo,
                playlist,
                priv);

            if (usrDTO != null)
            {
                return usrDTO;
            }

            /* return default values */
            return new UserDTO
                {
                    //these two values are always available via the connect cookie
                    IsPageAdmin = CurrentUserFBInfo.IsAdmin,
                    HasLikedPage = CurrentUserFBInfo.HasLikedPage,
                    TimeOffset = CurrentUserFBInfo.TimeOffset,
                    //default values
                    FBID = -1,
                    name = string.Empty,
                    numOfSongsLeft = -1,
                    role = "None",
                    score = 0,
                    summedScore = 0,
                };
        }
Exemplo n.º 13
0
 protected PlaylistWithUserDTO BuildPlaylistWithUserDTO(
     Playlist playlist)
 {
     return PlaylistWithUserDTOFactory.Map(playlist,
         BuildUserDTO(playlist));
 }
Exemplo n.º 14
0
        public virtual void RemovePlaylist(Playlist playlist)
        {
            if (Playlists.Contains(playlist))
            {
                Playlists.Remove(playlist);
                playlist.LocalBusiness = null;
                LastModified = DateTime.Now;
            }

            if (DefaultPlaylist == playlist)
            {
                DefaultPlaylist = Playlists.FirstOrDefault();
            }
        }
Exemplo n.º 15
0
        public virtual void AddPlaylist(Playlist playlist, bool replaceDefaultPlaylist = false)
        {
            if (!Playlists.Contains(playlist))
            {
                Playlists.Add(playlist);
                playlist.LocalBusiness = this;
                LastModified = DateTime.Now;
            }

            if (DefaultPlaylist == null || replaceDefaultPlaylist)
            {
                DefaultPlaylist = playlist;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// build JSON formatted response with result of rating: success of
        /// operation and updated positive and negative ratings
        /// </summary>
        ///
        /// <param name="playlist">
        /// current playlist
        /// </param>
        ///
        /// <param name="ratingInfo">
        /// rating information to be translated
        /// </param>
        ///
        /// <param name="isRatingSuccesful">
        /// success of rating operation
        /// </param>
        ///
        /// <param name="errorMsg">
        /// error message to return as a part of the response message
        /// </param>
        ///
        ///<returns>
        /// JSON formatted object with 3 fields: Success, NegativeRating, and
        /// PositiveRating
        /// </returns>
        private JsonResult GetRatingResult(Playlist playlist,
            SongWithUserRatingDTO ratingInfo,
            bool isRatingSuccesful,
            string errorMsg)
        {
            var pls = PlaylistDTOFactory.Map(playlist);
            var rdUser = BuildUserDTO(playlist);
            var renderedData = new
                {
                    Success = isRatingSuccesful,
                    SongInfo = ratingInfo,
                    error = errorMsg,
                    playlist = pls,
                    CurrentUser = rdUser
                };

            return BuildResult(
                (short) (isRatingSuccesful ? 0 : -1),
                errorMsg,
                renderedData);
        }
Exemplo n.º 17
0
        private bool IsVotingAllowed(Playlist playlist)
        {
            if (MatchUserPrivilege(playlist, UserPrivileges.Owner))
            {
                return true;
            }

            //if there's no NextPlayDate give it a true value
            var isEndDateOk =
                !playlist.NextPlayDate.HasValue ||
                 playlist.NextPlayDate > DateTime.Now;

            return isEndDateOk ; //if both dates are alright
        }
Exemplo n.º 18
0
        /// <summary>
        /// login operations
        /// </summary>
        ///
        /// <param name="accessToken">
        /// Facebook access token
        /// </param>
        ///
        /// <param name="userStatus">
        /// current state of the user
        /// </param>
        ///
        /// <param name="playlist">
        /// playlist being loged into
        /// </param>
        ///
        /// <returns>
        /// true if the user logged in successfully, false otherwise
        /// </returns>
        private bool LoginInternal(string accessToken, UserStatus userStatus,
            Playlist playlist = null)
        {
            CurrentUserFBInfo.AccessToken = accessToken;
            FacebookApp = (accessToken == null) ?
                new FacebookWebClient() : new FacebookWebClient(accessToken);

            var fbUser = GetLoggedInFbUser();

            var userId = long.Parse(fbUser.id);
            var user = SetLoggedInUser(userId);

            /* in case this is a user who approved the app back in the time we
             * didn't request email permission */
            if (user == null ||
                CurrentUser.Status == UserStatus.Pending ||
                CurrentUser.Status == UserStatus.Removed ||
                string.IsNullOrEmpty(CurrentUser.Email))
            {
                if (!SaveUser(fbUser, userStatus))
                {
                    return false;
                }

                user = SetLoggedInUser(userId);
                if (user == null)
                {
                    return false;
                }

                if (playlist != null)
                {
                    RewardUser(playlist, UserPlaylistInfo.Operation.Signup);
                }
            }
            else
            {
                RewardUser(playlist, UserPlaylistInfo.Operation.DayEntrance);
            }
            return true;
        }
Exemplo n.º 19
0
 private void SaveUserVisit(Playlist playlist, FbUser user)
 {
     var visit= new Visit{ Playlist = playlist, User = user, VisitDate = DateTime.Now};
     Repository.Save(visit);
 }
Exemplo n.º 20
0
        /// <summary>
        /// select required locale based on current user preferences, current
        /// playlist preferences and facebook user preferences
        /// </summary>
        ///
        /// <param name="pls">
        /// Playlist currently being viewed by the user
        /// </param>
        ///
        /// <param name="fbLocale">
        /// locale string from Facebook signed_user
        /// </param>
        ///
        /// <returns>
        /// string with required user locale
        /// </returns>
        private string SelectRequiredLocale(Playlist pls, string fbLocale)
        {
            /* possible values for locale names */
            var validLocales = Enum.GetNames(typeof (MvcApplication.Culture));

            if (CurrentUser != null &&
                !String.IsNullOrEmpty(CurrentUser.Locale) &&
                validLocales.Contains(CurrentUser.Locale))
            {
                return CurrentUser.Locale;
            }

            /* select customization based on the following preference:
             * 1. with both local business and playlsit set.
             * 2. with only playlist set.
             * 3. with only local business set. */
            if (pls != null && pls.LocalBusiness != null)
            {
                var cust =
                    Repository
                    .Query<Customizations>()
                    .Where(c => c.Playlist == pls)
                    .Where(c => c.LocalBusiness == pls.LocalBusiness)
                    .Where(c => c.Locale != null)
                    .Where(c => !c.Locale.Equals(string.Empty))
                    .FirstOrDefault() ??

                    Repository
                    .Query<Customizations>()
                    .Where(c => c.Playlist == pls)
                    .Where(c => c.Locale != null)
                    .Where(c => !c.Locale.Equals(string.Empty))
                    .FirstOrDefault() ??

                    Repository
                    .Query<Customizations>()
                    .Where(c => c.LocalBusiness == pls.LocalBusiness)
                    .Where(c => c.Locale != null)
                    .Where(c => !c.Locale.Equals(string.Empty))
                    .FirstOrDefault();

                if (cust != null && validLocales.Contains(cust.Locale))
                {
                    return cust.Locale;
                }
            }

            /* trim the "he_IL" notation to simple "he" */
            var tfbl = string.IsNullOrEmpty(fbLocale) ?
                null : fbLocale.Split(FB_LOCALE_SEPARATOR)[0];

            if (!String.IsNullOrEmpty(tfbl) && validLocales.Contains(tfbl))
            {
                return tfbl;
            }
            return Thread.CurrentThread.CurrentCulture.Name;
        }
Exemplo n.º 21
0
        //http://aabs.wordpress.com/2008/01/18/c-by-contract-using-expression-trees/
        static void Main(string[] args)
        {
            Console.WriteLine("Creating Tables...");

            var sessionFactory = new SessionFactory();

            Console.WriteLine("Finished Creating Tables!");
            Console.WriteLine("inserting new data...");
            IRepository repository = new NHibernateRepository(sessionFactory);
            foreach (var str in ConfigurationManager.ConnectionStrings)
            {
                if (!str.ToString().Contains("server=localhost") &&
                    !str.ToString().Contains(".\\SQLEXPRESS") &&
                    !str.ToString().Equals(String.Empty))
                {
                    Console.WriteLine("WTF? Don't run this on a remote server!");
                    Console.ReadKey();
                    return;
                }
            }
            try
            {
                repository.BeginTransaction();

                //stas 664118894
                var fbUser1 = new FbUser { Id = 585701767, JoinDate = DateTime.Now, Name = "anna", Status = UserStatus.Joined };
                var fbUser2 = new FbUser { Id = 806905557, JoinDate = DateTime.Now, Name = "stas", Status = UserStatus.Joined };
                var fbUser3 = new FbUser { Id = 716712905, JoinDate = DateTime.Now, Name = "dror", Status = UserStatus.Joined };
                //var fbUser3 = new FbUser { Id = 806905557, JoinDate = DateTime.Now, Name = "ran", Status = UserStatus.Joined };
                var fbUser4 = new FbUser { Id = 100000431166374, JoinDate = DateTime.Now, Name = "yadid", Status = UserStatus.Joined };

                repository.Save(fbUser1);
                repository.Save(fbUser2);
                repository.Save(fbUser3);
                repository.Save(fbUser4);

                var localBusiness1 = new LocalBusiness
                {
                    AddressCity = "Yehud",
                    AddressStreet = "Levi Eschol 1",
                    Category = "Music",
                    CreatedDate = DateTime.Now,
                    FacebookUrl = "http://www.facebook.com/pages/%D7%A7%D7%95%D7%9C%D7%95%D7%9C%D7%95/178456328876503",
                    FanPageId = 186841648018387,
                    //FanPageId = 258829897475960,
                    LastModified = DateTime.Now,
                    Name = "קולולו",
                    PublishUserContentToWall = false,
                    PublishAdminContentToWall = true,
                    Owners = new List<FbUser> { fbUser1, fbUser2, fbUser3, fbUser4 }
                };

                var uriBusiness = new LocalBusiness
                    {
                        AddressCity = "Faraway city",
                        AddressStreet = "Back alley",
                        Category = "Music",
                        CreatedDate = DateTime.Now,
                        FacebookUrl =
                            "https://www.facebook.com/pages/%D7%96%D7%9E%D7%A8-test/245866165438909",
                        FanPageId = 245866165438909,
                        FBFanPageAccessToken = "157721837628308|afd07c5be8ae8e01047a1156.1-662326561|juC8P9wsNLP5XirWXPCzEMF7qPU",
                        ImageUrl =
                            "https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yA/r/gPCjrIGykBe.gif",
                        LastModified = DateTime.Now,
                        Name = "זמר טסט",
                        PublishUserContentToWall = true,
                        PublishAdminContentToWall = true,
                        Owners =
                            new List<FbUser>
                                {fbUser1, fbUser2, fbUser3, fbUser4}
                    };

                var uriRadio = new Playlist
                    {
                        Name = "Radio Uri",
                        Description = "",
                        Image = "",
                        CreationDate = DateTime.Now,
                        LastModifiedDate = DateTime.Now,
                        NextPlayDate = DateTime.Parse("23/07/2013 08:55:00"),
                        IsUserModifyable = true,
                        NumOfSongsLimit = 5
                    };

                uriBusiness.AddPlaylist(uriRadio);
                uriBusiness.ImportPlaylist = uriRadio;
                repository.Save(uriBusiness);

                var radio1 = new Playlist
                {
                    Name = "Kululu-FM",
                    Description = "",
                    Image = "",
                    CreationDate = DateTime.Now,
                    LastModifiedDate = DateTime.Now,
                    NextPlayDate = DateTime.Parse("23/07/2012 08:55:00"),
                    IsUserModifyable = true,
                    NumOfSongsLimit = 5
                };

                localBusiness1.AddPlaylist(radio1);
                localBusiness1.ImportPlaylist = radio1;
                repository.Save(localBusiness1);

                var localBusiness2 = new LocalBusiness()
                {
                    Owners = new List<FbUser> { fbUser1 },
                    AddressCity = "Haifa",
                    AddressStreet = "Rauel Wallenberg",
                    Category = "Music",
                    CreatedDate = DateTime.Now,
                    FacebookUrl = "http://www.facebook.com/pages/%D7%A7%D7%95%D7%9C%D7%95%D7%9C%D7%95/178456328876503",
                    FanPageId = 1,
                    ImageUrl = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/195725_178456328876503_4279627_n.jpg",
                    LastModified = DateTime.Now,
                    PublishAdminContentToWall = true,
                    PublishUserContentToWall = false,
                    Name = "Kululu Test"
                };

                var radio2 = new Playlist
                {
                    Description = "",
                    Image = "",
                    CreationDate = DateTime.Now,
                    LastModifiedDate = DateTime.Now,
                    Name = "Radius-100FM",
                    NextPlayDate = DateTime.Parse("25/07/2011"),
                    IsUserModifyable = true,
                    NumOfSongsLimit = 10
                };

                localBusiness2.AddPlaylist(radio2);
                repository.Save(localBusiness2);

                var playlistSongRating = SaveSong(repository, radio1, fbUser1, "Cee Lo Green", "Bright Lights Bigger City", 231, "UBhdIcb84Hw", 1, "http://userserve-ak.last.fm/serve/126s/62075863.png");
                //radio1.AddRating(song, fbUser3, -1);
                radio1.RateSong(playlistSongRating, fbUser4, 1);
                radio1.RateSong(playlistSongRating, fbUser2, 1);
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);
                uriRadio.RateSong(playlistSongRating, fbUser4, 1);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "מוש בן ארי", "סתכל לי בעיניים", 249, "HwgVLsnaAoU", 1, "http://userserve-ak.last.fm/serve/126s/20443621.jpg");
                //radio1.AddRating(song, fbUser3, 1);
                radio1.RateSong(playlistSongRating, fbUser4, 1);
                radio1.RateSong(playlistSongRating, fbUser2, 1);
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);
                uriRadio.RateSong(playlistSongRating, fbUser4, 1);
                uriRadio.RateSong(playlistSongRating, fbUser2, 1);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "J.LO FT. Pitbull", "On The Floor", 267, "t4H_Zoh7G5A", 1, null);
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "גלעד שגב", "חנה'לה התבלבלה", 214, "vAlFB4Z7P2Y", 1, "http://userserve-ak.last.fm/serve/126s/163895.jpg");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "Adele", "Someone Like You", 306, "7AW9C3-qWug", 1, "http://userserve-ak.last.fm/serve/126s/58297847.png");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                SaveSong(repository, radio1, fbUser1, "Britney Spears", "Till The World Ends", 236, "qzU9OrZlKb8", 1, "http://userserve-ak.last.fm/serve/126s/59558187.png");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                SaveSong(repository, radio1, fbUser1, "Enrique Iglesias", "Tonight", 299, "Jx2yQejrrUE", 1, "http://userserve-ak.last.fm/serve/126s/65262750.png");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "Pitbull", "Give Me Everything", 267, "EPo5wWmKEaI", 1, "http://userserve-ak.last.fm/serve/126s/64990460.png");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                //radio1.AddRating(song, fbUser3, -1);
                radio1.RateSong(playlistSongRating, fbUser4, 1);
                radio1.RateSong(playlistSongRating, fbUser2, -1);
                uriRadio.RateSong(playlistSongRating, fbUser4, 1);
                uriRadio.RateSong(playlistSongRating, fbUser2, -1);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "Lady Gaga", "Born This Way", 440, "wV1FrqwZyKw", 1, "http://userserve-ak.last.fm/serve/126s/63387017.png");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "ברי סחרוף", "זמן של מספרים", 303, "PCwDDGYely0", 1, "http://userserve-ak.last.fm/serve/126s/784256.jpg");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "Depeche Mode", "Personal Jesus (The Stargate Mix)", 252, "3xLvArgSp3k", 1, "http://userserve-ak.last.fm/serve/126s/2126897.jpg");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "Diddy Dirty Money ft. Skylar Grey", "Coming Home", 251, "k-ImCpNqbJw", 1, null);
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "The Black Eyed Peas", "Just Can't Get Enough", 236, "OrTyD7rjBpw", 1, "http://userserve-ak.last.fm/serve/126s/65970878.png");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "Bob Sinclar & Raffaella Carrà", "Far l'Amore", 220, "rSmdeqxxLLk", 1, "http://userserve-ak.last.fm/serve/126s/26932877.jpg");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "Jessie J ft. B.o.B.", "Price Tag", 247, "qMxX-QOV9tI", 1, null);
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                //radio1.AddRating(song, fbUser3, -1);
                radio1.RateSong(playlistSongRating, fbUser4, -1);
                radio1.RateSong(playlistSongRating, fbUser2, -1);
                uriRadio.RateSong(playlistSongRating, fbUser4, -1);
                uriRadio.RateSong(playlistSongRating, fbUser2, -1);
                //radio2.AddRating(song, fbUser3, 1);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "Lady Gaga", "The Edge Of Glory", 328, "QeWBS0JBNzQ", 1, "http://userserve-ak.last.fm/serve/126s/63387017.png");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                //SaveSong(repository, radio1, fbUser1, "הפרוייקט של עידן רייכל - אִמָּא, אַבָּא וכל הַשְּׁאָר", "D98E89oUo6o", 1);
                playlistSongRating = SaveSong(repository, radio1, fbUser1, "אדיר גץ", "איך היא רוקדת", 236, "Pu2s7bboV9M", 1, "http://userserve-ak.last.fm/serve/126s/51539323.jpg");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "שלומי סרנגה", "זה רק נדמה לך", 218, "MaZIYKtIfnM", 1, "http://userserve-ak.last.fm/serve/126s/83144.jpg");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                playlistSongRating = SaveSong(repository, radio1, fbUser1, "מאור כהן", "ישראל", 183, "svjdhfKJbUc", 1, "http://userserve-ak.last.fm/serve/126s/311813.jpg");
                uriRadio.AddSong(playlistSongRating.Song, fbUser1, true);

                //radio2.RateSong(song, fbUser2, 1);
                //radio2.AddRating(song, fbUser3, 1);

                repository.CommitTransaction();
            }
            catch (Exception e)
            {
                repository.RollbackTransaction();
                repository.CloseSession();

                Console.WriteLine("*** Failure ({0}): {1}", e.GetType(), e.Message);
            }
            Console.WriteLine("Finished!");
            Console.ReadKey();
        }
Exemplo n.º 22
0
        /// <summary>
        /// post to wall update of a single 
        /// </summary>
        ///
        /// <param name="fbapp">
        /// Facebook application used to post to wall
        /// </param>
        ///
        /// <param name="pls">
        /// playlist to test
        /// </param>
        ///
        /// <returns>
        /// has this playlist posted to the wall?
        /// </returns>
        private void PostPlaylistUpdateToWall(
            FacebookClient fbapp, Playlist pls)
        {
            /* input sanity check */
            if (pls == null)
            {
                Logger.Error("Null playlist");
                throw new ArgumentNullException("pls");
            }

            /* push only the request posts */
            if (!pls.IsPushesToWall)
            {
                return;
            }

            Logger.InfoFormat(
                "Processing playlist {0} ({1}) from fan page {1}",
                pls.Name, pls.Id, pls.LocalBusiness.FanPageId);

            /* don't post to wall if the playlist already ended */
            if (pls.NextPlayDate < DateTime.Now)
            {
                Logger.InfoFormat("Playlist {0} already completed", pls.Id);
                return;
            }

            /* if the next update time has not yet arrived, discard the
             * request */
            if (DateTime.Now < pls.NextUpdate)
            {
                Logger.InfoFormat(
                    "Playlist {0} should not post to wall yet", pls.Id);
                return;
            }

            /* calculate next update time: set the default to 24 hours */
            var increment = (pls.IncrementUpdate >= 1) ?
                pls.IncrementUpdate : 24;
            pls.NextUpdate = DateTime.Now.AddHours(increment);
            Repository.SaveOrUpdate(pls);

            Logger.InfoFormat("Playlist {0} posting, next update: {1}",
                pls.Id, pls.NextUpdate);

            /* get names of the first N songs */
            var rats = pls
                .Ratings
                .OrderByDescending(r => r.SummedPositiveRating)
                .Take(PERIODIC_POST_SONGS);
            var ratsStr = rats
                .Select(r => string.Format(
                    "{0} - {1}", r.Song.Name, r.Song.ArtistName))
                .ToArray();
            if (ratsStr.Length < 1)
            {
                Logger.InfoFormat("Playlist {0} has no ratings", pls.Id);
                return;
            }

            var wholeMsg = new StringBuilder(
                pls.UpdateDescriptionFormat ??
                App_GlobalResources.Strings.periodicWallPost);
            for (var i = 0; i < ratsStr.Length; i++)
            {
                wholeMsg.AppendFormat("{0}. ", i + 1);
                wholeMsg.Append(ratsStr[i]);
                if (i < (ratsStr.Length - 1))
                {
                    wholeMsg.Append(',');
                }
            }
            var wholeMsgStr = wholeMsg.ToString();

            Logger.InfoFormat("Playlist {0} posting update to wall: {1}",
                pls.Id, wholeMsgStr);

            try
            {

                /* create the link to kululu application on current fan page */
                var link = string.Format(
                    "{0}?sk=app_{1}",
                    pls.LocalBusiness.FacebookUrl,
                    FacebookApp.GetAppId());

                var res = Dror.Common.Utils.Facebook.PostToWall(
                    fbapp,
                    pls.LocalBusiness.FanPageId,
                    "Update from Kulu.lu",
                    wholeMsgStr,
                    GeneratePostImage(rats.ToList()),
                    link,
                    string.Empty,
                    string.Empty,
                    "link",
                    null);
                Logger.InfoFormat("Playlist {0} post to wall {1}",
                    pls.Id, !string.IsNullOrEmpty(res) ? "succeeded" : "failed");
            }
            catch (FacebookApiException e)
            {
                Logger.ErrorFormat(
                    "Playlist {0} failed to post to wall ({1}): {2}",
                    pls.Id, e.GetType(), e.Message);
            }
        }