public JMMServer.Providers.Azure.CrossRef_AniDB_MAL ToContractAzure()
        {
            JMMServer.Providers.Azure.CrossRef_AniDB_MAL contract = new JMMServer.Providers.Azure.CrossRef_AniDB_MAL();

            contract.AnimeID            = AnimeID;
            contract.MALID              = MALID;
            contract.MALTitle           = MALTitle;
            contract.StartEpisodeType   = StartEpisodeType;
            contract.StartEpisodeNumber = StartEpisodeNumber;
            contract.CrossRefSource     = CrossRefSource;

            contract.AnimeID            = AnimeID;
            contract.CrossRefSource     = CrossRefSource;
            contract.MALID              = MALID;
            contract.MALTitle           = MALTitle;
            contract.StartEpisodeNumber = StartEpisodeNumber;
            contract.StartEpisodeType   = AnimeID;

            contract.Username = ServerSettings.AniDB_Username;
            if (ServerSettings.WebCache_Anonymous)
            {
                contract.Username = Constants.AnonWebCacheUsername;
            }

            return(contract);
        }
        public JMMServer.Providers.Azure.CrossRef_AniDB_MAL ToContractAzure()
        {
            JMMServer.Providers.Azure.CrossRef_AniDB_MAL contract = new JMMServer.Providers.Azure.CrossRef_AniDB_MAL();

            contract.AnimeID = AnimeID;
            contract.MALID = MALID;
            contract.MALTitle = MALTitle;
            contract.StartEpisodeType = StartEpisodeType;
            contract.StartEpisodeNumber = StartEpisodeNumber;
            contract.CrossRefSource = CrossRefSource;

            contract.AnimeID = AnimeID;
            contract.CrossRefSource = CrossRefSource;
            contract.MALID = MALID;
            contract.MALTitle = MALTitle;
            contract.StartEpisodeNumber = StartEpisodeNumber;
            contract.StartEpisodeType = AnimeID;

            contract.Username = ServerSettings.AniDB_Username;
            if (ServerSettings.WebCache_Anonymous)
                contract.Username = Constants.AnonWebCacheUsername;

            return contract;
        }
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_MALSearchAnime: {0}", AnimeID);

            try
            {
                // first check if the user wants to use the web cache
                if (ServerSettings.WebCache_MAL_Get)
                {
                    try
                    {
                        JMMServer.Providers.Azure.CrossRef_AniDB_MAL crossRef = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBMAL(AnimeID);
                        if (crossRef != null)
                        {
                            logger.Trace("Found MAL match on web cache for {0} - id = {1} ({2}/{3})", AnimeID, crossRef.MALID, crossRef.StartEpisodeType, crossRef.StartEpisodeNumber);
                            MALHelper.LinkAniDBMAL(AnimeID, crossRef.MALID, crossRef.MALTitle, crossRef.StartEpisodeType, crossRef.StartEpisodeNumber, true);

                            return;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                string searchCriteria          = "";
                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_Anime           anime    = repAnime.GetByAnimeID(AnimeID);
                if (anime == null)
                {
                    return;
                }

                searchCriteria = anime.MainTitle;

                // if not wanting to use web cache, or no match found on the web cache go to TvDB directly
                anime malResults = MALHelper.SearchAnimesByTitle(searchCriteria);

                if (malResults.entry.Length == 1)
                {
                    logger.Trace("Using MAL search result for search on {0} : {1} ({2})", searchCriteria, malResults.entry[0].id, malResults.entry[0].title);
                    MALHelper.LinkAniDBMAL(AnimeID, malResults.entry[0].id, malResults.entry[0].title, (int)enEpisodeType.Episode, 1, false);
                }
                else if (malResults.entry.Length == 0)
                {
                    logger.Trace("ZERO MAL search result results for: {0}", searchCriteria);
                }
                else
                {
                    // if the title's match exactly and they have the same amount of episodes, we will use it
                    foreach (animeEntry res in malResults.entry)
                    {
                        if (res.title.Equals(anime.MainTitle, StringComparison.InvariantCultureIgnoreCase) && res.episodes == anime.EpisodeCountNormal)
                        {
                            logger.Trace("Using MAL search result for search on {0} : {1} ({2})", searchCriteria, res.id, res.title);
                            MALHelper.LinkAniDBMAL(AnimeID, res.id, res.title, (int)enEpisodeType.Episode, 1, false);
                        }
                    }
                    logger.Trace("Too many MAL search result results for, skipping: {0}", searchCriteria);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_MALSearchAnime: {0} - {1}", AnimeID, ex.ToString());
                return;
            }
        }