コード例 #1
0
        // =============================================
        // Remote Commands Functions
        // =============================================
        public RemoteCommand CheckForCommand(string serverKey)
        {
            using (var db = new MediaManagerDataContext())
            {
                var server = Loader.LoadServer(db, serverKey);

                if (server == null) return RemoteCommand.NoCommand;

                var commandQueue = server.ServerCommandQueues.FirstOrDefault(a => !a.InProgress);

                if (commandQueue != null)
                {
                    commandQueue.InProgress = true;
                    commandQueue.Started = DateTime.UtcNow;
                    if (commandQueue.Command != RemoteCommand.Transcode)
                    {
                        server.CurrentCommand = commandQueue.Command;
                    }
                    else
                    {
                        server.CurrentlyTranscoding = true;
                    }

                    db.SubmitChanges();

                    return commandQueue.Command;
                }
            }

            return RemoteCommand.NoCommand;
        }
コード例 #2
0
ファイル: Loader.cs プロジェクト: anlai/MyMediaManager
        public static List<NavLibrary> LoadLibraries(string username, VideoType videoType)
        {
            var cacheKey = username + (videoType == VideoType.Movie ? "MovieLibraries" : "ShowsLibraries");
            var names = new List<NavLibrary>();

            var cnames = (List<NavLibrary>)HttpContext.Current.Cache[cacheKey];

            if (cnames == null)
            {
                using (var db = new MediaManagerDataContext())
                {
                    var user = db.Users.FirstOrDefault(a => a.UserName == username);

                    if (user != null)
                    {
                        var libraries = user.UserXServers.Select(a => a.Server).SelectMany(a => a.Libraries);

                        names = videoType == VideoType.Movie ?
                            libraries.Where(a => a.ServerMedias.Any(b => b.Movie != null)).Select(a => new NavLibrary() {Name = a.Name, ServerName = a.Server.Name, ServerId = a.ServerId}).ToList()
                            : libraries.Where(a => a.ServerMedias.Any(b => b.Episode != null)).Select(a => new NavLibrary() {Name = a.Name, ServerName = a.Server.Name, ServerId = a.ServerId}).ToList();

                        // cache the value with a 15 minute sliding, and 1 day abolute expiration
                        HttpContext.Current.Cache.Add(cacheKey, names, null, DateTime.MaxValue, new TimeSpan(0, 0, 15, 0), CacheItemPriority.Normal, null);
                    }
                }
            }
            else
            {
                names = cnames;
            }

            return names;
        }
コード例 #3
0
        /// <summary>
        /// Creates media objects
        /// </summary>
        /// <param name="contentModels"></param>
        public void CreateMedia(List<ContentModel> contentModels)
        {
            using (var db = new MediaManagerDataContext())
            {
                var movies = contentModels.Where(a => a.VideoType == VideoType.Movie).Select(a => new { a.Title, a.SortName, a.RemoteSourceId }).Distinct();
                foreach (var movie in movies)
                {
                    EnsureMovie(db, new ContentModel() { Title = movie.Title, SortName = movie.SortName, RemoteSourceId = movie.RemoteSourceId });
                }

                db.SubmitChanges();
            }

            using (var db = new MediaManagerDataContext())
            {
                var shows = contentModels.Where(a => a.VideoType == VideoType.TvShowEpisode).Select(a => new { Title = a.ParentTitle, SortName = a.ParentSortTitle, RemoteSourceId = a.ParentRemoteSourceId }).Distinct();
                foreach (var show in shows)
                {
                    EnsureShow(db, show.Title, show.SortName, show.RemoteSourceId);
                }

                db.SubmitChanges();
            }

            using (var db = new MediaManagerDataContext())
            {
                var episodes = contentModels.Where(a => a.VideoType == VideoType.TvShowEpisode).Select(a => new { a.Title, a.SortName, a.Season, a.Episode, a.ParentRemoteSourceId, a.ParentTitle }).Distinct();
                foreach (var episode in episodes)
                {
                    EnsureEpisode(db, new ContentModel() { Title = episode.Title, SortName = episode.SortName, Season = episode.Season, Episode = episode.Episode, ParentRemoteSourceId = episode.ParentRemoteSourceId, ParentTitle = episode.ParentTitle }, loadShowOnly: true);
                }

                db.SubmitChanges();
            }
        }
コード例 #4
0
        public static CopyToDriveViewModel Create(MediaManagerDataContext db, string username)
        {
            var servers = Loader.LoadUserServers(db, username);

            var viewModel = new CopyToDriveViewModel()
                {
                    Servers = servers,
                    RequestedFiles = db.WishListFiles.Where(a => !a.Completed && servers.Contains(a.ServerMedia.Server)).ToList()
                };

            return viewModel;
        }
コード例 #5
0
        public static bool AreFriends(MediaManagerDataContext db, string username, int friendId)
        {
            var user = db.Users.FirstOrDefault(a => a.UserName == username);
            var friend = db.Users.FirstOrDefault(a => a.UserId == friendId);

            if (user != null && friend != null)
            {
                return user.Friends.Any(a => a.FriendUser == friend);
            }

            return false;
        }
コード例 #6
0
        public static WishListViewModel Create(MediaManagerDataContext db, string username)
        {
            var servers = Loader.LoadUserServers(db, username);

            var viewModel = new WishListViewModel()
                {
                    WishLists = db.WishLists.Where(a => a.User.UserName == username).ToList(),
                    RequestedFiles = db.WishListFiles.Where(a => servers.Contains(a.ServerMedia.Server) && !a.Completed).ToList()
                };

            return viewModel;
        }
コード例 #7
0
        public static ShowsIndexViewModel Create(MediaManagerDataContext db, string username, int friendId, string library, int? server, int? genreId, int? collectionId)
        {
            // make sure user is friends with the requesting user
            var friend = db.Users.FirstOrDefault(a => a.UserId == friendId);
            var user = db.Users.FirstOrDefault(a => a.UserName == username);
            if (friend == null || user == null || !user.Friends.Select(a => a.FriendUserId).Contains(friendId))
            {
                return null;
            }

            var viewModel = Generate(db, friend.UserName, library, server, genreId, collectionId);
            viewModel.Owner = friend.UserName;
            viewModel.FriendId = friendId;

            return viewModel;
        }
コード例 #8
0
        public static MoviesIndexViewModel Create(MediaManagerDataContext db, string username, int friendId, string library, int? server, int? collectionId, int? genreId)
        {
            var user = db.Users.FirstOrDefault(a => a.UserName == username);
            var friend = db.Users.FirstOrDefault(a => a.UserId == friendId);

            // make sure user is friends with the requesting user
            if (!SecurityHelpers.AreFriends(user, friend))
            {
                return null;
            }

            var viewModel = Generate(db, friend.UserName, library, server, collectionId, genreId);
            viewModel.Owner = friend.UserName;
            viewModel.friendID = friendId;

            return viewModel;
        }
コード例 #9
0
        public bool AvailableForTranscoding(string serverKey, DayOfWeek dayOfWeek, int hour)
        {
            using (var db = new MediaManagerDataContext())
            {
                var server = db.Servers.FirstOrDefault(a => a.Key == new Guid(serverKey) && a.IsActive);

                if (server != null)
                {
                    // override hold on transcoding, or currently executing remote job
                    if (server.HoldTranscoding || server.CurrentlyTranscoding) return false;

                    return server.TranscodingSchedules.Any(a => a.DayOfWeek == dayOfWeek.ToString() && a.Start <= hour && a.End > hour);
                }
            }

            return false;
        }
コード例 #10
0
        public static DifferencesViewModel Create(MediaManagerDataContext db, User user, User friend)
        {
            if (SecurityHelpers.AreFriends(user, friend))
            {
                var viewModel = new DifferencesViewModel()
                {
                    User = user,
                    Friend = friend,
                    UserServers = user.UserXServers.Select(a => a.Server).ToList(),
                    FriendServers = friend.UserXServers.Select(a => a.Server).ToList()
                };

                return viewModel;
            }

            return null;
        }
コード例 #11
0
        public void CommandComplete(string serverKey, RemoteCommand remoteCommand, List<string> keys = null )
        {
            using (var db = new MediaManagerDataContext())
            {
                var server = Loader.LoadServer(db, serverKey);

                if (server == null) return;

                var commandQueue = server.ServerCommandQueues.FirstOrDefault(a => a.InProgress && a.Command == remoteCommand);

                // update the server's current status
                if (remoteCommand != RemoteCommand.Transcode)
                {
                    server.CurrentCommand = RemoteCommand.NoCommand;
                    if (remoteCommand == RemoteCommand.CopyFromDrive) server.CopyFromDrive = null;
                    if (remoteCommand == RemoteCommand.CopyToDrive)
                    {
                        if (keys == null)
                        {
                            db.WishListFiles.DeleteAllOnSubmit(db.WishListFiles.Where(a => a.ServerMedia.ServerId == server.Id && a.Approved));
                        }
                        else
                        {
                            db.WishListFiles.DeleteAllOnSubmit(db.WishListFiles.Where(a => a.ServerMedia.ServerId == server.Id && a.Approved && keys.Contains(a.ServerMedia.FilePath)));
                        }
                        server.CopyToDrive = null;

                    }
                }
                else
                {
                    server.CurrentlyTranscoding = false;
                }

                if (commandQueue != null)
                {
                    db.ServerCommandQueues.DeleteOnSubmit(commandQueue);
                }

                db.SubmitChanges();
            }
        }
コード例 #12
0
        /// <summary>
        /// Creates and ensures Library Names exist
        /// </summary>
        /// <param name="libraries"></param>
        /// <param name="serverKey"></param>
        public void EnsureLibraries(List<string> libraries, string serverKey)
        {
            using (var db = new MediaManagerDataContext())
            {
                var server = Loader.LoadServer(db, serverKey);

                if (server != null)
                {
                    foreach (var lib in libraries)
                    {
                        if (!db.Libraries.Any(a => a.Server == server && a.Name == lib))
                        {
                            db.Libraries.InsertOnSubmit(new Library() { Name = lib, Server = server });
                        }
                    }
                }

                db.SubmitChanges();
            }
        }
コード例 #13
0
        /// <summary>
        /// Creates ServerMedia object (assigns content to server) for Movie
        /// </summary>
        /// <param name="db"></param>
        /// <param name="server"></param>
        /// <param name="contentModel"></param>
        /// <param name="movie"></param>
        private void AssignMovieToServer(MediaManagerDataContext db, Server server, ContentModel contentModel, Movie movie)
        {
            // load the libraries for the specific server
            var libraries = db.Libraries.Where(a => a.Server == server).ToList();

            foreach (var file in contentModel.MediaModels)
            {
                // check and see if the files exist, if not then create a new one
                if (!db.ServerMedias.Any(a => a.Server == server && a.MediaId == file.MediaId))
                {
                    var mvs = new ServerMedia()
                    {
                        Server = server,
                        Movie = movie,
                        VideoId = file.VideoId,
                        MediaId = file.MediaId,
                        Resolution = file.Resolution,
                        AspectRatio = file.AspectRatio,
                        FilePath = file.FilePath,
                        DateAdded = file.DateAdded,
                        Size = file.Size,
                        LastCheckin = DateTime.Now,
                        Hash = contentModel.ModelHash,
                        Library = libraries.FirstOrDefault(a => a.Name == contentModel.LibraryName)
                    };

                    db.ServerMedias.InsertOnSubmit(mvs);
                }
            }
        }
コード例 #14
0
        // =============================================
        // File Import / Copy Functions
        // =============================================
        public void ReportDrives(string serverKey, IList<DriveModel> driveModels)
        {
            using (var db = new MediaManagerDataContext())
            {
                var server = db.Servers.FirstOrDefault(a => a.Key == new Guid(serverKey) && a.IsActive);

                if (server != null)
                {
                    var existingDrives = db.ServerDrives.Where(a => a.Server.Key == new Guid(serverKey));
                    db.ServerDrives.DeleteAllOnSubmit(existingDrives);

                    var newDrives = driveModels.Select(a => new ServerDrive() { Name = a.Name, DriveType = a.DriveType.ToString(), VolumeLabel = a.VolumeLabel, AvailableSpace = a.AvailableSpace, ServerId = server.Id, Id = Guid.NewGuid() });
                    db.ServerDrives.InsertAllOnSubmit(newDrives);
                }

                db.SubmitChanges();
            }
        }
コード例 #15
0
        // =============================================
        // Transcoding Functions
        // =============================================
        public QueueModel TopQueue(string serverKey)
        {
            using (var db = new MediaManagerDataContext())
            {
                // exit if currently running job
                if (db.TranscodingQueues.Any(a => a.Server.Key == new Guid(serverKey) && !a.Complete && a.DateTimeStarted.HasValue))
                {
                    return null;
                }

                var queue = db.TranscodingQueues.FirstOrDefault(a => a.Server.Key == new Guid(serverKey) && a.Pending);

                // no job
                if (queue == null) return null;

                var qm = new QueueModel()
                    {
                        QueueId = queue.Id,
                        FilePath = queue.ServerMedia.FilePath,
                        TargetFormat = queue.TargetFormat.Name,
                        VideoType = queue.ServerMedia.Movie != null ? VideoType.Movie : VideoType.TvShowEpisode
                    };

                queue.Pending = false;
                queue.DateTimeStarted = DateTime.UtcNow;
                db.SubmitChanges();

                return qm;
            }
        }
コード例 #16
0
        /// <summary>
        /// Creates/Load Show Content Object
        /// </summary>
        /// <param name="db"></param>
        /// <param name="title"></param>
        /// <param name="sortTitle"></param>
        /// <param name="remoteSourceId"></param>
        /// <param name="loadOnly"></param>
        /// <returns></returns>
        private Show EnsureShow(MediaManagerDataContext db, string title, string sortTitle, string remoteSourceId, bool loadOnly = false)
        {
            if (!string.IsNullOrEmpty(remoteSourceId))
            {
                var sw = db.Shows.FirstOrDefault(a => a.SourceId == remoteSourceId);

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

                if (!loadOnly)
                {
                    var show = new Show() { SourceId = remoteSourceId, Title = title, SortName = sortTitle };
                    db.Shows.InsertOnSubmit(show);
                    return show;
                }

            }
            else
            {
                var st = db.Shows.FirstOrDefault(a => a.Title == title);

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

                var showT = new Show() { Title = title, SortName = sortTitle };
                db.Shows.InsertOnSubmit(showT);
                return showT;
            }
            return null;
        }
コード例 #17
0
        public void PopQueue(string serverKey, int queueId)
        {
            using (var db = new MediaManagerDataContext())
            {
                var queue = db.TranscodingQueues.FirstOrDefault(a => a.Server.Key == new Guid(serverKey) && a.Id == queueId);

                if (queue == null)
                {
                    throw new ArgumentException("Queue does not match server.");
                }

                queue.DateTimecompleted = DateTime.UtcNow;
                queue.Complete = true;

                db.SubmitChanges();
            }
        }
コード例 #18
0
ファイル: Loader.cs プロジェクト: anlai/MyMediaManager
 public static List<Server> LoadUserServers(MediaManagerDataContext db, string username)
 {
     var servers = db.UserXServers.Where(a => a.User.UserName == username).Select(a => a.Server);
     return servers.ToList();
 }
コード例 #19
0
        /// <summary>
        /// Loads a text file to be used as a local cache
        /// </summary>
        /// <param name="serverKey"></param>
        /// <returns></returns>
        public string LoadCacheFile(string serverKey)
        {
            var sw = new StringWriter();
            using (var writer = new XmlTextWriter(sw))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("Catalog");

                using (var db = new MediaManagerDataContext())
                {
                    var server = Loader.LoadServer(db, serverKey);

                    if (server != null && server.ServerMedias.Any())
                    {
                        foreach (var sm in server.ServerMedias)
                        {
                            writer.WriteStartElement(sm.Movie != null ? "Movie" : "Episode");

                            writer.WriteAttributeString("ServerMediaId", XmlConvert.ToString(sm.Id));
                            writer.WriteAttributeString("MediaId", XmlConvert.ToString(sm.MediaId));
                            writer.WriteAttributeString("VideoId", XmlConvert.ToString(sm.VideoId));
                            writer.WriteAttributeString("Hash", sm.Hash);

                            writer.WriteEndElement();
                        }
                    }
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();

                writer.Flush();
            }

            return sw.ToString();
        }
コード例 #20
0
        /// <summary>
        /// Creates/Load Episode Content Object
        /// </summary>
        /// <param name="db"></param>
        /// <param name="contentModel"></param>
        /// <param name="loadShowOnly"></param>
        /// <param name="loadOnly"></param>
        /// <returns></returns>
        private Episode EnsureEpisode(MediaManagerDataContext db, ContentModel contentModel, bool loadShowOnly = false, bool loadOnly = false)
        {
            var show = EnsureShow(db, contentModel.ParentTitle, contentModel.ParentSortTitle, contentModel.ParentRemoteSourceId, loadShowOnly);

            if (show == null) return null;

            var ep = db.Episodes.FirstOrDefault(a => a.Show == show && a.Season == contentModel.Season && a.Episode1 == contentModel.Episode);

            if (ep != null && loadOnly)
            {
                return ep;
            }

            if (!loadOnly)
            {
                ep = new Episode() { Show = show, Season = contentModel.Season, Episode1 = contentModel.Episode, Title = contentModel.Title };
                db.Episodes.InsertOnSubmit(ep);
                return ep;
            }
            return null;
        }
コード例 #21
0
        /// <summary>
        /// Creates ServerMedia object (assigns content to server) for Show / Episode
        /// </summary>
        /// <param name="db"></param>
        /// <param name="server"></param>
        /// <param name="contentModel"></param>
        /// <param name="episode"></param>
        private void AssignEpisodeToServer(MediaManagerDataContext db, Server server, ContentModel contentModel, Episode episode)
        {
            var libraries = db.Libraries.Where(a => a.Server == server).ToList();

            foreach (var file in contentModel.MediaModels)
            {
                var sm = db.ServerMedias.FirstOrDefault(a => a.MediaId == file.MediaId);

                // media file does not exist on server, create new meida object
                if (sm == null)
                {
                    var evs = new ServerMedia()
                    {
                        Server = server,
                        Episode = episode,
                        VideoId = file.VideoId,
                        MediaId = file.MediaId,
                        Resolution = file.Resolution,
                        AspectRatio = file.AspectRatio,
                        FilePath = file.FilePath,
                        DateAdded = file.DateAdded,
                        Size = file.Size,
                        LastCheckin = DateTime.Now,
                        Hash = contentModel.ModelHash,
                        Library = libraries.FirstOrDefault(a => a.Name == contentModel.LibraryName)
                    };

                    db.ServerMedias.InsertOnSubmit(evs);
                }
                // update an existing
                else
                {
                    sm.VideoId = file.VideoId;
                    sm.MediaId = file.MediaId;
                    sm.Resolution = file.Resolution;
                    sm.AspectRatio = file.AspectRatio;
                    sm.FilePath = file.FilePath;
                    sm.DateAdded = file.DateAdded;
                    sm.Size = file.Size;
                    sm.LastCheckin = DateTime.Now;
                    sm.Hash = contentModel.ModelHash;
                    sm.Library = libraries.FirstOrDefault(a => a.Name == contentModel.LibraryName);
                }
            }
        }
コード例 #22
0
        /// <summary>
        /// Assigns media objects to server
        /// </summary>
        /// <param name="contentModels"></param>
        /// <param name="serverKey"></param>
        public IEnumerable<CacheModel> UpdateContent(IEnumerable<ContentModel> contentModels, string serverKey)
        {
            // assign the media to servers
            using (var db = new MediaManagerDataContext())
            {
                var server = Loader.LoadServer(db, serverKey);

                if (server != null)
                {
                    foreach (var cm in contentModels)
                    {
                        if (cm.VideoType == VideoType.Movie)
                        {
                            var movie = EnsureMovie(db, cm, true);
                            AssignMovieToServer(db, server, cm, movie);
                        }

                        if (cm.VideoType == VideoType.TvShowEpisode)
                        {
                            var episode = EnsureEpisode(db, cm, true, true);
                            AssignEpisodeToServer(db, server, cm, episode);
                        }
                    }
                }

                db.SubmitChanges();
            }

            // get the ids
            using (var db = new MediaManagerDataContext())
            {
                var server = Loader.LoadServer(db, serverKey);
                var mediaIds = contentModels.SelectMany(a => a.MediaModels.Select(b => b.MediaId));

                var cache = db.ServerMedias.Where(a => a.Server == server && mediaIds.Contains(a.MediaId)).Select(a => new CacheModel()
                          {
                              VideoType = a.Movie != null ? VideoType.Movie : VideoType.TvShowEpisode,
                              ServerMediaId = a.Id,
                              VideoId = a.VideoId,
                              MediaId = a.MediaId,
                              Hash = a.Hash
                          });

                return cache.ToList();
            }
        }
コード例 #23
0
 public static MoviesIndexViewModel Create(MediaManagerDataContext db, string username, string library, int? server, int? collectionId, int? genreId)
 {
     return Generate(db, username, library, server, collectionId, genreId);
 }
コード例 #24
0
        private static MoviesIndexViewModel Generate(MediaManagerDataContext db, string username, string library, int? server, int? collectionId, int? genreId)
        {
            IQueryable<ServerMedia> serverMedia;

            if (!string.IsNullOrEmpty(library) && server.HasValue)
            {
                serverMedia = db.ServerMedias.Where( a =>
                        a.Server.UserXServers.Select(b => b.User.UserName).Contains(username)
                        && a.Movie != null
                        && a.ServerId == server.Value && a.Library.Name == library);
            }
            else
            {
                serverMedia = db.ServerMedias.Where( a =>
                    a.Server.UserXServers.Select(b => b.User.UserName).Contains(username)
                    && a.Movie != null
                    );
            }

            var viewModel = new MoviesIndexViewModel()
                {
                    WishlistFiles = db.WishLists.Where(a => a.User.UserName == username).SelectMany(a => a.WishListFiles)
                };

            //if (collectionId.HasValue)
            //{
            //    var collection = db.Collections.FirstOrDefault(a => a.Id == collectionId.Value);

            //    if (collection != null)
            //    {
            //        serverMedia = serverMedia.Where(a => a.MoviesXCollections.Select(b => b.Collection).Contains(collection));
            //        viewModel.Collection = collection;
            //    }
            //}

            //if (genreId.HasValue)
            //{
            //    var genre = db.Genres.FirstOrDefault(a => a.Id == genreId);

            //    if (genre != null)
            //    {
            //        serverMedia = serverMedia.Where(a => a.MoviesXGenres.Select(b => b.Genre).Contains(genre));
            //        viewModel.Genre = genre;
            //    }
            //}

            viewModel.MoviesViewModels = serverMedia.Select(a => new MoviesViewModel()
            {
                Id = a.Id,
                Title = a.Movie.Title,
                Year = a.Movie.Year,
                AspectRatio = a.AspectRatio,
                Resolution = a.Resolution,
                SortName = a.Movie.SortName,
                Queued = a.TranscodingQueues.Any(b => b.Pending),
                Transcoding = a.TranscodingQueues.Any(b => !b.Pending && b.DateTimeStarted.HasValue),
                DateAdded = a.DateAdded
            }).ToList();

            //viewModel.Collections = serverMedia.SelectMany(a => a.MoviesXCollections).GroupBy(mc => mc.Collection).OrderByDescending(
            //                            g => g.Count()).Select(g => g.Key).ToList();
            //viewModel.Genres =
            //    serverMedia.SelectMany(a => a.MoviesXGenres).GroupBy(mg => mg.Genre).OrderByDescending(g => g.Count()).Select
            //                            (g => g.Key).ToList();

            return viewModel;
        }
コード例 #25
0
        /// <summary>
        /// Creates/Load Movie Content Object
        /// </summary>
        /// <param name="db"></param>
        /// <param name="contentModel"></param>
        /// <param name="loadOnly"></param>
        /// <returns></returns>
        private Movie EnsureMovie(MediaManagerDataContext db, ContentModel contentModel, bool loadOnly = false)
        {
            // a remote source has been provided
            if (!string.IsNullOrEmpty(contentModel.RemoteSourceId))
            {
                var mv = db.Movies.FirstOrDefault(a => a.SourceId == contentModel.RemoteSourceId);

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

                if (!loadOnly)
                {
                    var movie = new Movie() { SourceId = contentModel.RemoteSourceId, Title = contentModel.Title, SortName = contentModel.SortName };
                    db.Movies.InsertOnSubmit(movie);
                    return movie;
                }
            }
            else
            {
                var mt = db.Movies.FirstOrDefault(a => a.Title == contentModel.Title);

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

                if (!loadOnly)
                {
                    var movieT = new Movie() { Title = contentModel.Title, SortName = contentModel.SortName };
                    db.Movies.InsertOnSubmit(movieT);
                    return movieT;
                }
            }
            return null;
        }
コード例 #26
0
        private static ShowsIndexViewModel Generate(MediaManagerDataContext db, string username, string library, int? server, int? genreId, int? collectionId)
        {
            IQueryable<ServerMedia> serverMedia;

            if (!string.IsNullOrEmpty(library) && server.HasValue)
            {
                serverMedia = db.ServerMedias.Where(a =>
                    a.Server.UserXServers.Select(b => b.User.UserName).Contains(username)
                    && a.Episode != null
                    && a.ServerId == server.Value
                    && a.Library.Name == library
                    );
            }
            else
            {
                serverMedia = db.ServerMedias.Where(a =>
                    a.Server.UserXServers.Select(b => b.User.UserName).Contains(username)
                    && a.Episode != null
                    );
            }

            var viewModel = new ShowsIndexViewModel()
                {
                    Genres = new List<Genre>(), Collections = new List<Collection>(), EpisodeCollections = new List<Collection>()
                };

            //if (genreId.HasValue)
            //{
            //    var genre = db.Genres.FirstOrDefault(a => a.Id == genreId);

            //    if (genre != null)
            //    {
            //        shows = shows.Where(a => a.TvShowsXGenres.Select(b => b.Genre).Contains(genre));
            //        viewModel.Genre = genre;
            //    }
            //}

            //if (collectionId.HasValue)
            //{
            //    var collection = db.Collections.FirstOrDefault(a => a.Id == collectionId);

            //    if (collection != null)
            //    {
            //        shows = shows.Where(a => a.TvShowsXCollections.Select(b => b.Collection).Contains(collection));
            //        viewModel.Collection = collection;
            //    }
            //}

            //var shows = serverMedia.Select(a => a.Episode.Show).Distinct();

            //viewModel.Shows = shows.Select(a => new ShowsViewModel()
            //{
            //    Id = a.Id,
            //    Title = a.Title,
            //    Year = a.Year,
            //    Seasons = a.Episodes.Select(b => b.Season).Distinct().Count(),
            //    Episodes = a.Episodes.Count,
            //    SortName = a.SortName,
            //    ServerId =
            //}).ToList();

            var shows = serverMedia.Select(a => new ShowsViewModel()
                {
                    Id = a.Episode.ShowId,
                    Title = a.Episode.Show.Title,
                    Year = a.Episode.Show.Year,
                    Seasons = a.Episode.Show.Episodes.Select(b => b.Season).Distinct().Count(),
                    Episodes = a.Episode.Show.Episodes.Count,
                    SortName = a.Episode.Show.SortName,
                    ServerId = a.ServerId
                });

            viewModel.Shows = shows.Distinct().ToList();

            //viewModel.Genres = shows.SelectMany(a => a.TvShowsXGenres).GroupBy(sg => sg.Genre).OrderByDescending(g => g.Count()).Select
            //        (g => g.Key).ToList();

            //viewModel.Collections = shows.SelectMany(a => a.TvShowsXCollections).GroupBy(sc => sc.Collection).OrderByDescending(
            //        c => c.Count()).Select(c => c.Key).ToList();

            //viewModel.EpisodeCollections =
            //    shows.SelectMany(a => a.TvShowEpisodes).SelectMany(a => a.TvShowEpisodesXCollections).GroupBy(
            //        ec => ec.Collection).OrderByDescending(c => c.Count()).Select(c => c.Key).ToList();

            return viewModel;
        }
コード例 #27
0
ファイル: Loader.cs プロジェクト: anlai/MyMediaManager
 public static Server LoadServer(MediaManagerDataContext db, string serverKey)
 {
     var server = db.Servers.FirstOrDefault(a => a.Key == new Guid(serverKey) && a.IsActive);
     return server;
 }
コード例 #28
0
        public CopyModel CopyFiles(string serverKey)
        {
            using (var db = new MediaManagerDataContext())
            {
                var server = db.Servers.FirstOrDefault(a => a.Key == new Guid(serverKey) && a.IsActive);

                if (server != null  && server.CurrentCommand == RemoteCommand.CopyToDrive)
                {
                    //var targetDrive = server.ServerDrives.FirstOrDefault(a => a.Selected);
                    var targetDrive = server.CopyToDrive;

                    if (targetDrive != null)
                    {
                        var wlfiles = db.WishListFiles.Where(a => a.ServerMedia.Server == server && a.Approved);

                        var results = new List<KeyValuePair<string, VideoType>>();

                        results.AddRange(wlfiles.Select(a => new KeyValuePair<string, VideoType>(a.ServerMedia.FilePath, a.ServerMedia.Movie != null ? VideoType.Movie : VideoType.TvShowEpisode)));

                        db.SubmitChanges();

                        return new CopyModel() { Drive = server.CopyToDrive, Files = results };
                    }
                }
            }

            return null;
        }
コード例 #29
0
        /// <summary>
        /// Removes a server media object from a server
        /// </summary>
        /// <param name="mediaIds"></param>
        /// <param name="serverKey"></param>
        public void RemoveContent(IEnumerable<int> mediaIds, string serverKey)
        {
            using (var db = new MediaManagerDataContext())
            {
                var server = Loader.LoadServer(db, serverKey);

                if (server != null)
                {
                    //foreach (var id in mediaIds)
                    //{
                    //    var sm = db.ServerMedias.FirstOrDefault(a => a.Id == id && a.Server == server);
                    //    if (sm != null)
                    //    {
                    //        db.ServerMedias.DeleteOnSubmit(sm);
                    //    }
                    //}

                    var medias = db.ServerMedias.Where(a => mediaIds.Contains(a.Id) && a.Server == server);
                    db.WishListFiles.DeleteAllOnSubmit(medias.SelectMany(a => a.WishListFiles));
                    db.ServerMedias.DeleteAllOnSubmit(medias);

                    db.SubmitChanges();
                }
            }
        }
コード例 #30
0
        public string CopyFromDrive(string serverKey)
        {
            using (var db = new MediaManagerDataContext())
            {
                var server = db.Servers.FirstOrDefault(a => a.Key == new Guid(serverKey) && a.IsActive);

                if (server != null)
                {
                    if (server.CurrentCommand == RemoteCommand.CopyFromDrive)
                    {
                        return server.CopyFromDrive;
                    }
                }
            }

            return null;
        }