public static UpdatesCollection Get_AniDBUpdates(long utcUpdateTime) { try { string uri = string.Format("http://{0}/GetUpdates.aspx?updatetime={1}", ServerSettings.WebCache_Address, utcUpdateTime); string xml = GetData(uri); if (xml.Trim().Length == 0) { return(null); } UpdatesCollection updateCol = new UpdatesCollection(); XmlDocument docUpdates = new XmlDocument(); docUpdates.LoadXml(xml); // populate the fields updateCol.RawAnimeIDs = TryGetProperty(docUpdates, "UpdatesCollection", "AnimeIDs"); updateCol.UpdateCount = long.Parse(TryGetProperty(docUpdates, "UpdatesCollection", "UpdateCount")); logger.Info("Get_AniDBUpdates:: {0} - {1}", updateCol.UpdateCount, updateCol.RawAnimeIDs); return(updateCol); } catch (Exception ex) { logger.ErrorException("Error in XMLService.Get_AniDBUpdates:: {0}" + ex.ToString(), ex); return(null); } }
public void RemoveFromCollection(UpdateObject obj) { UpdatesCollection.Remove(obj); if (UpdatesCollection.Count == 0 || UpdatesCollection.All(x => !x.IsActive)) { EventController.InvokeDownloadsComplete(); } }
public bool Exists(string name) { return(UpdatesCollection.ToArray().Any(update => update.FileName == name)); }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_GetUpdated"); try { List <int> animeIDsToUpdate = new List <int>(); ScheduledUpdateRepository repSched = new ScheduledUpdateRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); //DateTime localTime = DateTime.Now.AddDays(-30); long startTime = 0; // check the automated update table to see when the last time we ran this command ScheduledUpdate sched = repSched.GetByUpdateType((int)ScheduledUpdateType.AniDBUpdates); if (sched != null) { int freqHours = Utils.GetScheduledHours(ServerSettings.AniDB_Anime_UpdateFrequency); // if we have run this in the last 12 hours and are not forcing it, then exit TimeSpan tsLastRun = DateTime.Now - sched.LastUpdate; if (tsLastRun.TotalHours < freqHours) { if (!ForceRefresh) { return; } } } // get a list of updates in the last day from AniDB // startTime will contain the date/time from which the updates apply to if (!JMMService.AnidbProcessor.GetUpdated(ref animeIDsToUpdate, ref startTime)) { return; } long webUpdateTime = 0; if (sched == null) { // if this is the first time, lets ask web cache for everyting in the last 3 days DateTime localTime = DateTime.Now.AddDays(-3); DateTime utcTime = localTime.ToUniversalTime(); webUpdateTime = long.Parse(Utils.AniDBDate(utcTime)); sched = new ScheduledUpdate(); sched.UpdateType = (int)ScheduledUpdateType.AniDBUpdates; } else { logger.Trace("Last anidb info update was : {0}", sched.UpdateDetails); webUpdateTime = long.Parse(sched.UpdateDetails); } // now save the update time from AniDB // we will use this next time as a starting point when querying the web cache sched.LastUpdate = DateTime.Now; sched.UpdateDetails = startTime.ToString(); repSched.Save(sched); // we now have a listof updates in the last 24 hours // get more from the web cache UpdatesCollection colUpdates = XMLService.Get_AniDBUpdates(webUpdateTime); // get a unqiue list of anime id's if (colUpdates != null) { logger.Info("Web cache updates : Time={0} - Count={1} - List={2}", webUpdateTime, colUpdates.UpdateCount, colUpdates.RawAnimeIDs); foreach (int id in colUpdates.AnimeIDs) { if (!animeIDsToUpdate.Contains(id)) { animeIDsToUpdate.Add(id); } } } else { logger.Info("No web Web cache updates"); } int countAnime = 0; int countSeries = 0; foreach (int animeID in animeIDsToUpdate) { // update the anime from HTTP AniDB_Anime anime = repAnime.GetByAnimeID(animeID); if (anime == null) { logger.Trace("No local record found for Anime ID: {0}, so skipping...", animeID); continue; } logger.Info("Updating CommandRequest_GetUpdated: {0} ", animeID); // but only if it hasn't been recently updated TimeSpan ts = DateTime.Now - anime.DateTimeUpdated; if (ts.TotalHours > 4) { CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(animeID, true, false); cmdAnime.Save(); countAnime++; } // update the group status // this will allow us to determine which anime has missing episodes // so we wonly get by an amime where we also have an associated series AnimeSeries ser = repSeries.GetByAnimeID(animeID); if (ser != null) { CommandRequest_GetReleaseGroupStatus cmdStatus = new CommandRequest_GetReleaseGroupStatus(animeID, true); cmdStatus.Save(); countSeries++; } } logger.Info("Updating {0} anime records, and {1} group status records", countAnime, countSeries); } catch (Exception ex) { logger.Error("Error processing CommandRequest_GetUpdated: {0}", ex.ToString()); return; } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { AniDB_UpdatedRepository repUpdates = new AniDB_UpdatedRepository(); string updatetime = Utils.GetParam("updatetime"); long fupdatetime = 0; long.TryParse(updatetime, out fupdatetime); if (fupdatetime <= 0) { Response.Write(Constants.ERROR_XML); return; } // get all the records // we need to find all the records greater than the update time, and one record // which is just before the update time // this will ensure we get all records List <AniDB_Updated> allUpdateRecords = repUpdates.GetAll(); if (allUpdateRecords.Count == 0) { Response.Write(Constants.ERROR_XML); return; } List <string> allUpdates = new List <string>(); int idxSmallest = -1; // find the first record greater for (int i = 0; i < allUpdateRecords.Count; i++) { if (allUpdateRecords[i].UpdateTime > fupdatetime) { if (idxSmallest < 0) { idxSmallest = i; if (i > 0) { string[] ids = allUpdateRecords[i - 1].AnimeIDList.Split(','); foreach (string id in ids) { if (!allUpdates.Contains(id.Trim())) { allUpdates.Add(id.Trim()); } } } } // get a list of anime id's string[] ids2 = allUpdateRecords[i].AnimeIDList.Split(','); foreach (string id in ids2) { if (!allUpdates.Contains(id.Trim())) { allUpdates.Add(id.Trim()); } } } } UpdatesCollection colUpdates = new UpdatesCollection(); foreach (string id in allUpdates) { colUpdates.AddToCollection(int.Parse(id)); } string ret = Utils.ConvertToXML(colUpdates, typeof(UpdatesCollection)); Response.Write(ret); } catch (Exception ex) { Response.Write(ex.ToString()); return; } }