Пример #1
0
        public void Initialize()
        {
            string date = DateTime.Now.ToString("dd-MM-yyyy");

            Neo4jDataProvider dbNeo4j = new Neo4jDataProvider();
            RedisDataProvider dbRedis = new RedisDataProvider();

            StreamReader stream;

            //Check is database initialized
            if (dbNeo4j.UserExists("admin", "admin"))
            {
                return;
            }

            DeleteAllData();
            dbRedis.ResetHashCounter();

            #region Create users

            User admin = new User();
            admin.name     = "admin";
            admin.email    = "admin";
            admin.password = "******";
            admin.admin    = true;
            admin.date     = date;
            dbNeo4j.UserCreate(admin);
            try
            {
                stream = new StreamReader(HostingEnvironment.MapPath(userFilePath));
                while (!stream.EndOfStream)
                {
                    User user = new User();
                    user.name     = stream.ReadLine();
                    user.email    = stream.ReadLine();
                    user.password = stream.ReadLine();
                    user.admin    = false;
                    user.date     = date;
                    stream.ReadLine();
                    dbNeo4j.UserCreate(user);
                }
                stream.Close();
            }
            catch (Exception e)
            {
            }

            #endregion

            #region Create genres

            try
            {
                stream = new StreamReader(HostingEnvironment.MapPath(genresFilePath));
                while (!stream.EndOfStream)
                {
                    Genre genre = new Genre();
                    genre.name = stream.ReadLine();
                    stream.ReadLine();
                    dbNeo4j.GenreCreate(genre);
                }
                stream.Close();
            }
            catch (Exception e)
            {
            }

            #endregion

            #region Create artists

            try
            {
                stream = new StreamReader(HostingEnvironment.MapPath(artistFilePath));
                while (!stream.EndOfStream)
                {
                    Artist artist = new Artist();
                    artist.name      = stream.ReadLine();
                    artist.biography = stream.ReadLine();
                    artist.website   = stream.ReadLine();

                    string        genresClean     = Regex.Replace(stream.ReadLine(), " *, *", ",");
                    List <string> genreNames      = genresClean.Split(',').ToList();
                    List <string> checkGenres     = dbNeo4j.GenreRead();
                    List <string> validGenreNames = genreNames.Intersect(checkGenres).ToList();
                    List <Genre>  validGenres     = new List <Genre>();
                    foreach (string genreName in validGenreNames)
                    {
                        Genre tmp = new Genre();
                        tmp.name = genreName;
                        validGenres.Add(tmp);
                    }
                    dbNeo4j.ArtistCreate(artist, validGenres);
                    stream.ReadLine();
                }
                stream.Close();
            }
            catch (Exception e)
            {
            }
            #endregion

            #region Create songs

            string[] songPaths = Directory.GetFiles(HostingEnvironment.MapPath(songFolderPath));
            foreach (string songPath in songPaths)
            {
                try
                {
                    stream = new StreamReader(songPath);
                    Song song = new Song();
                    song.name = stream.ReadLine();
                    string artist = stream.ReadLine();
                    string user   = stream.ReadLine();
                    stream.ReadLine();
                    song.content = stream.ReadToEnd();
                    song.date    = date;
                    dbNeo4j.SongCreate(song, user, artist);
                    stream.Close();
                }
                catch (Exception e)
                {
                }
            }

            #endregion

            #region Create favorites

            try
            {
                stream = new StreamReader(HostingEnvironment.MapPath(favoritesFilePath));
                while (!stream.EndOfStream)
                {
                    string song   = stream.ReadLine();
                    string artist = stream.ReadLine();
                    string user   = stream.ReadLine();
                    stream.ReadLine();
                    dbNeo4j.SongAddToFavorites(song, artist, user);
                }
                stream.Close();
            }
            catch (Exception e)
            {
            }

            #endregion

            #region Create Comments

            try
            {
                stream = new StreamReader(HostingEnvironment.MapPath(commentsFilePath));
                while (!stream.EndOfStream)
                {
                    Comment comment = new Comment();
                    comment.title   = stream.ReadLine();
                    comment.content = stream.ReadLine();
                    comment.date    = date;
                    string song   = stream.ReadLine();
                    string artist = stream.ReadLine();
                    string user   = stream.ReadLine();
                    stream.ReadLine();
                    dbNeo4j.CommentCreate(comment, user, artist, song);
                }
                stream.Close();
            }
            catch (Exception e)
            {
            }

            #endregion

            #region Create requests

            try
            {
                stream = new StreamReader(HostingEnvironment.MapPath(songRequestFilePath));
                while (!stream.EndOfStream)
                {
                    SongRequest songRequest = new SongRequest();
                    songRequest.author = stream.ReadLine();
                    songRequest.artist = stream.ReadLine();
                    songRequest.song   = stream.ReadLine();
                    songRequest.date   = date;
                    stream.ReadLine();
                    dbNeo4j.SongRequestCreate(songRequest);
                }
                stream.Close();
            }
            catch (Exception e)
            {
            }

            #endregion

            #region Create songdrafts

            string[] songDraftPaths = Directory.GetFiles(HostingEnvironment.MapPath(songDraftFolderPath));
            foreach (string songDraftPath in songDraftPaths)
            {
                try
                {
                    stream = new StreamReader(songDraftPath);
                    SongDraft songDraft = new SongDraft();
                    songDraft.name   = stream.ReadLine();
                    songDraft.artist = stream.ReadLine();
                    string user = stream.ReadLine();
                    songDraft.content = stream.ReadToEnd();
                    songDraft.date    = date;
                    dbNeo4j.SongDraftCreate(songDraft, user);
                    stream.Close();
                    dbRedis.AddAdminNotification();
                }
                catch (Exception e)
                {
                }
            }

            #endregion
        }
Пример #2
0
        //GET /Song/Approve/
        public ActionResult Approve(string user, string artist, string name, string content, string approve)
        {
            ViewBag.showNav = false;
            //Samo admin moze da appruvuje
            if (Session["user"] == null || ((ViewUser)Session["user"]).admin == false)
            {
                return(Redirect("/"));
            }

            PageViewModel pageModel = new PageViewModel();

            pageModel.user = (ViewUser)(Session["user"]);

            Neo4jDataProvider dbNeo4j = new Neo4jDataProvider();

            if (approve != null)
            {
                //Promenjeni podatci
                ViewSong draft = new ViewSong();
                draft.creator  = user;
                draft.name     = name;
                draft.content  = content;
                draft.artist   = artist;
                draft.approved = false;
                draft.date     = DateTime.Now.ToString("dd-MM-yyyy");

                ViewBag.draft = draft;
                if (artist == null && name == null && content == null)
                {
                    return(View(pageModel));
                }
                if (artist == null || name == null || content == null)
                {
                    ViewBag.error = "Data is missing from required fields.";
                }
                else if (artist.Length < 1 || name.Length < 1 || content.Length < 1)
                {
                    ViewBag.error = "Data is missing from required fields.";
                }

                if (ViewBag.error != null)
                {
                    return(View(pageModel));
                }

                //Provera da li postoji Artist
                List <string> allArtists = dbNeo4j.ArtistRead();
                if (!allArtists.Contains(artist))
                {
                    ViewBag.noArtist = true;
                    return(View(pageModel));
                }


                //Kriranje nove pesme
                Song song = new Song();
                song.name    = name;
                song.content = content;
                song.date    = DateTime.Now.ToString("dd-MM-yyyy");
                song.link    = "/" + artist + "/" + user + "/";

                dbNeo4j.SongCreate(song, user, artist);
                SongDraft songDraft = new SongDraft();
                songDraft.name   = name;
                songDraft.artist = artist;
                dbNeo4j.SongDraftDelete(songDraft, user);
                dbNeo4j.SongRequestDelete(artist, name);

                return(Redirect("/User/"));
            }
            ViewBag.draft = dbNeo4j.SongDraftRead(user, artist, name);

            return(View(pageModel));
        }