Example #1
0
        public static Video VideoFromAnimeGroup(ISession session, AnimeGroup grp, int userid, List <AnimeSeries> allSeries)
        {
            Contract_AnimeGroup cgrp = grp.ToContract(grp.GetUserRecord(session, userid));

            if (StatsCache.Instance.StatGroupSeriesCount[grp.AnimeGroupID] == 1)
            {
                AnimeSeries ser = JMMServiceImplementation.GetSeriesForGroup(grp.AnimeGroupID, allSeries);
                if (ser != null)
                {
                    Contract_AnimeSeries cserie = ser.ToContract(ser.GetUserRecord(session, userid), true);
                    Video v = FromSerieWithPossibleReplacement(cserie, ser, userid);
                    v.AirDate = ser.AirDate.HasValue ? ser.AirDate.Value : DateTime.MinValue;
                    v.Group   = cgrp;
                    return(v);
                }
            }
            else
            {
                AnimeSeries ser = grp.DefaultAnimeSeriesID.HasValue ? allSeries.FirstOrDefault(a => a.AnimeSeriesID == grp.DefaultAnimeSeriesID.Value) : JMMServiceImplementation.GetSeriesForGroup(grp.AnimeGroupID, allSeries);
                if (ser != null)
                {
                    Video v = FromGroup(cgrp, ser.ToContract(ser.GetUserRecord(session, userid), true), userid);
                    v.Group   = cgrp;
                    v.AirDate = cgrp.Stat_AirDate_Min.HasValue ? cgrp.Stat_AirDate_Min.Value : DateTime.MinValue;
                    return(v);
                }
            }
            return(null);
        }
Example #2
0
        void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // An import folder cannot be both the drop source and the drop destination
                if (chkDropDestination.IsChecked.HasValue && chkDropSource.IsChecked.HasValue &&
                    chkDropDestination.IsChecked.Value &&
                    chkDropSource.IsChecked.Value)
                {
                    MessageBox.Show(JMMServer.Properties.Resources.ImportFolders_SameFolder,
                                    JMMServer.Properties.Resources.Error,
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // The import folder location cannot be blank. Enter a valid path on OMM Server
                if (string.IsNullOrEmpty(txtImportFolderLocation.Text))
                {
                    MessageBox.Show(JMMServer.Properties.Resources.ImportFolders_BlankImport,
                                    JMMServer.Properties.Resources.Error,
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    txtImportFolderLocation.Focus();
                    return;
                }

                Contract_ImportFolder contract = new Contract_ImportFolder();
                if (importFldr.ImportFolderID == 0)
                {
                    contract.ImportFolderID = null;
                }
                else
                {
                    contract.ImportFolderID = importFldr.ImportFolderID;
                }
                contract.ImportFolderName     = "NA";
                contract.ImportFolderLocation = txtImportFolderLocation.Text.Trim();
                contract.IsDropDestination    = chkDropDestination.IsChecked.Value ? 1 : 0;
                contract.IsDropSource         = chkDropSource.IsChecked.Value ? 1 : 0;
                contract.IsWatched            = chkIsWatched.IsChecked.Value ? 1 : 0;

                JMMServiceImplementation           imp      = new JMMServiceImplementation();
                Contract_ImportFolder_SaveResponse response = imp.SaveImportFolder(contract);
                if (!string.IsNullOrEmpty(response.ErrorMessage))
                {
                    MessageBox.Show(response.ErrorMessage, JMMServer.Properties.Resources.Error, MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }

                ServerInfo.Instance.RefreshImportFolders();
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }

            this.DialogResult = true;
            this.Close();
        }
Example #3
0
        public static Video GenerateFromAnimeGroup(ISession session, AnimeGroup grp, int userid,
                                                   List <AnimeSeries> allSeries)
        {
            Contract_AnimeGroup cgrp = grp.GetUserContract(userid);
            int subgrpcnt            = grp.GetAllChildGroups().Count;

            if ((cgrp.Stat_SeriesCount == 1) && (subgrpcnt == 0))
            {
                AnimeSeries ser = JMMServiceImplementation.GetSeriesForGroup(grp.AnimeGroupID, allSeries);
                if (ser != null)
                {
                    Contract_AnimeSeries cserie = ser.GetUserContract(userid);
                    if (cserie != null)
                    {
                        Video v = GenerateFromSeries(cserie, ser, ser.GetAnime(session), userid);
                        v.AirDate   = ser.AirDate;
                        v.UpdatedAt = ser.LatestEpisodeAirDate.HasValue
                            ? ser.LatestEpisodeAirDate.Value.ToUnixTime()
                            : null;
                        v.Group = cgrp;
                        return(v);
                    }
                }
            }
            else
            {
                AnimeSeries ser = grp.DefaultAnimeSeriesID.HasValue
                    ? allSeries.FirstOrDefault(a => a.AnimeSeriesID == grp.DefaultAnimeSeriesID.Value)
                    : allSeries.Find(a => a.AirDate != DateTime.MinValue);
                if ((ser == null) && (allSeries != null && allSeries.Count > 0))
                {
                    ser = allSeries[0];
                }
                Contract_AnimeSeries cserie = ser?.GetUserContract(userid);
                Video v = FromGroup(cgrp, cserie, userid, subgrpcnt);
                v.Group     = cgrp;
                v.AirDate   = cgrp.Stat_AirDate_Min ?? DateTime.MinValue;
                v.UpdatedAt = cgrp.LatestEpisodeAirDate?.ToUnixTime();
                v.Rating    = "" + Math.Round((grp.AniDBRating / 100), 1);
                List <Tag> newTags = new List <Tag>();
                foreach (AniDB_Tag tag in grp.Tags)
                {
                    Tag      newTag   = new Tag();
                    TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
                    newTag.Value = textInfo.ToTitleCase(tag.TagName.Trim());
                    if (!newTags.Contains(newTag))
                    {
                        newTags.Add(newTag);
                    }
                }
                v.Genres = newTags;
                if (ser != null)
                {
                    List <AnimeTitle> newTitles = new List <AnimeTitle>();
                    foreach (AniDB_Anime_Title title in ser.GetAnime(session).GetTitles())
                    {
                        AnimeTitle newTitle = new AnimeTitle();
                        newTitle.Title    = title.Title;
                        newTitle.Language = title.Language;
                        newTitle.Type     = title.TitleType;
                        newTitles.Add(newTitle);
                    }
                    v.Titles = newTitles;

                    v.Roles = new List <RoleTag>();

                    //TODO Character implementation is limited in JMM, One Character, could have more than one Seiyuu
                    if (ser.GetAnime(session).Contract?.AniDBAnime?.Characters != null)
                    {
                        foreach (Contract_AniDB_Character c in ser.GetAnime(session).Contract.AniDBAnime.Characters)
                        {
                            string ch = c?.CharName;
                            Contract_AniDB_Seiyuu seiyuu = c?.Seiyuu;
                            if (!string.IsNullOrEmpty(ch))
                            {
                                RoleTag t = new RoleTag();
                                t.Value = seiyuu?.SeiyuuName;
                                if (seiyuu != null)
                                {
                                    t.TagPicture = Helper.ConstructSeiyuuImage(seiyuu.AniDB_SeiyuuID);
                                }
                                t.Role            = ch;
                                t.RoleDescription = c?.CharDescription;
                                t.RolePicture     = Helper.ConstructCharacterImage(c.CharID);
                                v.Roles.Add(t);
                            }
                        }
                    }
                }
                return(v);
            }
            return(null);
        }
Example #4
0
 /// <summary>
 /// List all saved Import Folders
 /// </summary>
 /// <returns></returns>
 private object GetFolders()
 {
     List<Contract_ImportFolder> list = new JMMServiceImplementation().GetImportFolders();
     return list;
 }
Example #5
0
        private object GetAllFiles_old()
        {
            JMMServiceImplementation _impl = new JMMServiceImplementation();
            Dictionary<int, string> files = new Dictionary<int, string>();
            foreach (VideoLocal file in _impl.GetAllFiles())
            {
                files.Add(file.VideoLocalID, file.FileName);
            }

            return files;
        }
Example #6
0
 /// <summary>
 /// Edit folder giving fulll ImportFolder object with ID
 /// </summary>
 /// <returns></returns>
 private object EditFolder()
 {
     ImportFolder folder = this.Bind();
     if (!String.IsNullOrEmpty(folder.ImportFolderLocation) && folder.ImportFolderID != 0)
     {
         try
         {
             if (folder.IsDropDestination == 1 && folder.IsDropSource == 1)
             {
                 return new APIMessage(409, "The Folder Can't be both Destination and Source Simultaneously");
             }
             else
             {
                 if (folder.ImportFolderID != 0 & folder.ToContract().ImportFolderID.HasValue)
                 {
                     Contract_ImportFolder_SaveResponse response = new JMMServiceImplementation().SaveImportFolder(folder.ToContract());
                     if (!string.IsNullOrEmpty(response.ErrorMessage))
                     {
                         return new APIMessage(500, response.ErrorMessage);
                     }
                     else
                     {
                         return APIStatus.statusOK();
                     }
                 }
                 else
                 {
                     return new APIMessage(409, "The Import Folder must have an ID");
                 }
             }
         }
         catch
         {
             return APIStatus.internalError();
         }
     }
     else
     {
         return new APIMessage(400, "ImportFolderLocation and ImportFolderID missing");
     }
 }
Example #7
0
        /// <summary>
        /// Add Folder to Import Folders Repository
        /// </summary>
        /// <returns></returns>
        private object AddFolder()
        {
            try
            {
                Contract_ImportFolder folder = this.Bind();
                if (folder.ImportFolderLocation != "")
                {
                    try
                    {
                        Contract_ImportFolder_SaveResponse response = new JMMServiceImplementation().SaveImportFolder(folder);

                        if (string.IsNullOrEmpty(response.ErrorMessage))
                        {
                            return APIStatus.statusOK();
                        }
                        else
                        {
                            return new APIMessage(500, response.ErrorMessage);
                        }
                    }
                    catch
                    {
                        return APIStatus.internalError();
                    }
                }
                else
                {
                    return new APIMessage(400, "Bad Request: The Folder path must not be Empty");
                }
            }
            catch (ModelBindingException)
            {
                return new APIMessage(400, "Bad binding");
            }
        }
Example #8
0
        private object VoteOnSerie2()
        {
            Request request = this.Request;
            Entities.JMMUser user = (Entities.JMMUser)this.Context.CurrentUser;
            API_Call_Parameters ser = this.Bind();

            JMMServiceImplementation _impl = new JMMServiceImplementation();

            _impl.VoteAnime(ser.id, (decimal)ser.score, (int)AniDBAPI.enAniDBVoteType.Anime);

            return APIStatus.statusOK();
        }
Example #9
0
 private object MarkSerieWatched(bool status, int max_episodes, int type)
 {
     Request request = this.Request;
     Entities.JMMUser user = (Entities.JMMUser)this.Context.CurrentUser;
     JMMServiceImplementation _impl = new JMMServiceImplementation();
     API_Call_Parameters para = this.Bind();
     return _impl.SetWatchedStatusOnSeries(para.id, status, max_episodes, type, user.JMMUserID);
 }
Example #10
0
 private object GetUnrecognisedFiles(int max_limit)
 {
     Request request = this.Request;
     Entities.JMMUser user = (Entities.JMMUser)this.Context.CurrentUser;
     Dictionary<int, string> files = new Dictionary<int, string>();
     JMMServiceImplementation _impl = new JMMServiceImplementation();
     int i = 0;
     foreach (Contract_VideoLocal file in _impl.GetUnrecognisedFiles(user.JMMUserID))
     {
         i++;
         files.Add(file.VideoLocalID, file.FileName);
         if (i >= max_limit) break;
     }
     return files;
 }
Example #11
0
        private object GetRecentFiles_old(int max_limit)
        {
            Request request = this.Request;
            Entities.JMMUser user = (Entities.JMMUser)this.Context.CurrentUser;

            JMMServiceImplementation _impl = new JMMServiceImplementation();

            List<RecentFile> files = new List<RecentFile>();

            foreach (VideoLocal file in _impl.GetFilesRecentlyAdded(max_limit))
            {
                RecentFile recent = new RecentFile();
                recent.path = file.FileName;
                recent.id = file.VideoLocalID;
                if (file.EpisodeCrossRefs.Count() == 0)
                {
                    recent.success = false;
                }
                else
                {
                    recent.success = true;
                }
                files.Add(recent);
            }

            return files;
        }