예제 #1
0
    /// <summary>
    /// Implements IDB.CachePlatformdata() Update the local DB cache of platform associated metadata
    /// </summary>
    /// <param name="platform">Robin.Platform associated with the DBPlatorm to update.</param>
    public void CachePlatformData(Platform platform)
    {
        GBPlatform GBPlatform = platform.GBPlatform;

        XDocument xDocument;

        Reporter.Tic("Attempting to cache " + GBPlatform.Title + "...", out int tic1);

        using WebClient webClient = new();

        string url = GBURL + $"platform/{GBPlatform.ID}/?api_key ={Keys.GiantBomb}";

        if (webClient.SafeDownloadStringDB(url, out string downloadText))
        {
            xDocument = XDocument.Parse(downloadText);

            GBPlatform.Title        = xDocument.SafeGetB("results", "name");
            GBPlatform.Abbreviation = xDocument.SafeGetB("results", "abbreviation");
            if (long.TryParse(xDocument.SafeGetB("results", "company"), out long company))
            {
                GBPlatform.Company = company;
            }
            GBPlatform.Deck  = xDocument.SafeGetB("results", "deck");
            GBPlatform.Price = xDocument.SafeGetB("results", "original_price");
            GBPlatform.Date  = DateTimeRoutines.SafeGetDate(xDocument.SafeGetB("results", "release_date"));
            Reporter.Toc(tic1);
        }

        else
        {
            Reporter.Toc(tic1, "Error communicating with GiantBomb.");
        }
        // end using webclient
    }
예제 #2
0
 // Uses the DateTimeRoutines library to parse the date
 // http://www.codeproject.com/Articles/33298/C-Date-Time-Parser
 public static DateTime FromFuzzyTime(string str, DateTimeRoutines.DateTimeFormat format = DateTimeRoutines.DateTimeFormat.USA_DATE)
 {
     DateTimeRoutines.ParsedDateTime dt;
     if (DateTimeRoutines.TryParseDateOrTime(str, format, out dt))
     {
         return(dt.DateTime);
     }
     throw new Exception("FromFuzzyTime parsing failed");
 }
예제 #3
0
        public DateTime getTime(string time, string date)
        {
            DateTime toReturn;

            if (DateTimeRoutines.TryParseDateTime(date + " " + time, DateTimeRoutines.DateTimeFormat.USA_DATE, out toReturn))
            {
                //this equals true..
                return(toReturn);
            }
            return(new DateTime(2012, 7, 18, 20, 25, 26, 0));
        }
 /// <summary>
 /// Tries to find date and time within the passed string and return it as ParsedDateTime object.
 /// </summary>
 /// <param name="str">string that contains date-time</param>
 /// <param name="default_format">format to be used preferably in ambivalent instances</param>
 /// <param name="parsed_date_time">parsed date-time output</param>
 /// <returns>true if both date and time were found, else false</returns>
 static public bool TryParseDateTime(this string str, DateTimeFormat default_format, out ParsedDateTime parsed_date_time)
 {
     if (DateTimeRoutines.TryParseDateOrTime(str, default_format, out parsed_date_time) &&
         parsed_date_time.IsDateFound &&
         parsed_date_time.IsTimeFound
         )
     {
         return(true);
     }
     parsed_date_time = null;
     return(false);
 }
예제 #5
0
 public static EventTimeResult getTime(string source)
 {
     DateTimeRoutines.ParsedDateTime dateTime;
     if (DateTimeRoutines.TryParseTime(source, DateTimeRoutines.DateTimeFormat.USA_DATE, out dateTime))
     {
         if (dateTime.IsTimeFound)
         {
             string rest = source.Substring(dateTime.IndexOfTime, dateTime.LengthOfTime);
             return(new EventTimeResult(dateTime.DateTime.ToShortTimeString(), rest, source));
         }
     }
     return(new EventTimeResult("", "", source));
 }
예제 #6
0
        // Uses the DateTimeRoutines library to parse the date
        // http://www.codeproject.com/Articles/33298/C-Date-Time-Parser
        public static DateTime FromFuzzyTime(string str, string format = null)
        {
            DateTimeRoutines.DateTimeFormat dt_format = DateTimeRoutines.DateTimeFormat.USA_DATE;
            if (format == "UK")
            {
                dt_format = DateTimeRoutines.DateTimeFormat.UK_DATE;
            }

            DateTimeRoutines.ParsedDateTime dt;
            if (DateTimeRoutines.TryParseDateOrTime(str, dt_format, out dt))
            {
                return(dt.DateTime);
            }
            throw new Exception("FromFuzzyTime parsing failed");
        }
예제 #7
0
    public string getTimeRange(string source)
    {
        string TO     = String.Empty;
        string To_Use = source;

        if (FROM.Length == 0)
        {
            return("All Day");
        }
        source = source.Replace(FROM, "");
        source = source.Replace("-", "");
        string toReal   = "";
        bool   notFound = false;

        DateTimeRoutines.ParsedDateTime dt;
        if (DateTimeRoutines.TryParseTime(source, DateTimeRoutines.DateTimeFormat.USA_DATE, out dt))
        {
            if (dt.IsTimeFound)
            {
                TO     = dt.DateTime.ToShortTimeString();
                toReal = source.Substring(dt.IndexOfTime, dt.LengthOfTime);
            }
            else
            {
                notFound = true;
                toReal   = String.Empty;
            }
        }
        if (toReal.Length == 0)
        {
            return(REAL_TIME);
        }
        try
        {
            LONG_STRING = LONG_STRING.Replace(FROM, "");
            LONG_STRING = LONG_STRING.Replace(toReal, "");
        }
        catch (Exception ee) { }

        if (notFound)
        {
            return(REAL_TIME);
        }
        return(REAL_TIME + "-" + TO);
    }
예제 #8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!GlobalHandlers.SessionHandler.isLoggedIn())
     {
         Response.Redirect("~/admin/login/default.aspx", false);
         return;
     }
     if (!IsPostBack)
     {
         //initial load...
         //lets add to the filters
         filter = GlobalHandlers.DatabaseHandler.getFilters();
         foreach (Filter f in filter)
         {
             filters.Items.Add(f.Name);
         }
         try {
             if (Request.QueryString["date"] != null)
             {
                 //then its there, redrictced possibly, lets parse it.
                 DateTime dateT;
                 DateTimeRoutines.TryParseDate(Request.QueryString["date"], DateTimeRoutines.DateTimeFormat.USA_DATE, out dateT);
                 if (dateT != null)
                 {
                     //parsed successfully.
                     //lets set Date.Text to the date
                     date.Text = dateT.Month + "/" + dateT.Day + "/" + dateT.Year;
                 }
             }
         }
         catch (Exception eee)
         {
         }
     }
     else if (IsPostBack)
     {
         //yes this is a post back, so lets load our forms
         title.Text = Request.Form["title"].ToString();
         date.Text  = Request.Form["date"].ToString();
         filter     = GlobalHandlers.DatabaseHandler.getFilters();
     }
 }
예제 #9
0
        public DateTime should_parse_date(string date)
        {
            DateTimeRoutines.TryParseDateOrTime(date, DateTimeRoutines.DateTimeFormat.USDate, out var parsedDateTime);

            return(parsedDateTime.DateTime);
        }
예제 #10
0
    /// <summary>
    /// Implement IDB.CachePlatfomrReleases(). Go out to giantbomb.com and cache all known releases for the specified platform. Update the list of releases and store metadata for each one.
    /// </summary>
    /// <param name="platform">Robin.Platform associated with the GBPlatform to cache.</param>
    public static void CachePlatformReleases(Platform platform, bool reset = false)
    {
        using WebClient webClient = new();
        GBPlatform GBPlatform = platform.GBPlatform;
        string     startDate  = reset ? @"1900-01-01 01:01:01" : GBPlatform.CacheDate.ToString(DATEFORMAT);
        string     endDate    = DateTime.Now.ToString(DATEFORMAT);

        int       N_results;
        bool      haveResults;
        XDocument xdoc;

        Reporter.Report($"Checking GiantBomb for {GBPlatform.Title} releases...");

        string url = $"http://www.giantbomb.com/api/releases/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate},platform:{GBPlatform.ID}&field_list=id&sort=id:asc";

        if (webClient.SafeDownloadStringDB(url, out string downloadText))
        {
            xdoc        = XDocument.Parse(downloadText);
            haveResults = int.TryParse(xdoc.SafeGetB("number_of_total_results"), out N_results);
        }
        else
        {
            Reporter.Warn("Error communicating with GiantBomb.");
            return;
        }

        // If there are results, go through them
        if (haveResults && N_results != 0)
        {
            Dictionary <long, GBRelease> existingGBReleaseDict = R.Data.GBReleases.ToDictionary(x => x.ID);
            ILookup <long?, Release>     releaseLookupByGB_ID  = R.Data.Releases.Where(x => x.ID_GB != null).ToLookup(x => x.ID_GB);
            HashSet <GBRelease>          newGBReleases         = new();

            int N_pages = N_results / 100;
            Reporter.Report($"Found {N_results} {GBPlatform.Title} releases in GiantBomb");

            // Just do the first page again to save code then go through the rest of the results
            Reporter.Report("Loading sheet ");
            for (int i = 0; i <= N_pages; i++)
            {
                Reporter.ReportInline(" " + i);
                url = $"http://www.giantbomb.com/api/releases/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate}platform:{GBPlatform.ID}&offset={i * 100}&field_list=id,deck,game,image,region,name,maximum_players,release_date&sort=id:asc";

                // Put results into the GB Cache database
                if (webClient.SafeDownloadStringDB(url, out downloadText))
                {
                    xdoc = XDocument.Parse(downloadText);

                    foreach (XElement element in xdoc.Root.Element("results").Elements("release"))
                    {
                        // If the ID XML value was found
                        if (int.TryParse(element.SafeGetA("id"), out int id))
                        {
                            // Don't create this game if the title is null
                            string title = element.SafeGetA("name");
                            if (string.IsNullOrEmpty(title))
                            {
                                continue;
                            }

                            // Check if GBRelease is in database prior to this update, else add it
                            if (!existingGBReleaseDict.TryGetValue(id, out GBRelease GBRelease))
                            {
                                GBRelease = new GBRelease {
                                    ID = id, GBPlatform = platform.GBPlatform
                                };
                                newGBReleases.Add(GBRelease);
                            }

                            // If a release has changed platforms, catch it and zero out match
                            if (GBRelease.GBPlatform_ID != GBPlatform.ID)
                            {
                                GBRelease.GBPlatform_ID = GBPlatform.ID;

                                if (releaseLookupByGB_ID[GBRelease.ID].Any())
                                {
                                    foreach (Release release in releaseLookupByGB_ID[GBRelease.ID])
                                    {
                                        release.ID_GB = null;
                                    }
                                }
                            }

                            GBRelease.Title    = title;
                            GBRelease.Overview = element.SafeGetA("deck");
                            if (int.TryParse(element.SafeGetA("game", "id"), out id))
                            {
                                GBRelease.GBGame_ID = id;
                            }
                            if (int.TryParse(element.SafeGetA("maximum_players"), out id))
                            {
                                GBRelease.Players = id.ToString();
                            }

                            GBRelease.GBPlatform_ID = GBPlatform.ID;
                            if (int.TryParse(element.SafeGetA("region", "id"), out id))
                            {
                                GBRelease.Region = R.Data.Regions.FirstOrDefault(x => x.ID_GB == id) ?? R.Data.Regions.FirstOrDefault(x => x.Title.Contains("Unk"));
                            }

                            GBRelease.Date      = DateTimeRoutines.SafeGetDate(element.SafeGetA("release_date"));
                            GBRelease.BoxUrl    = element.SafeGetA("image", "medium_url");
                            GBRelease.ScreenUrl = element.SafeGetA("image", "screen_url");
                        }
                    }
                }
                else
                {
                    Reporter.Warn("Failure connecting to GiantBomb");
                    return;
                }
            }
            R.Data.GBReleases.AddRange(newGBReleases);
            Reporter.ReportInline("Finished.");
        }
        else
        {
            Reporter.Report("No releases returned by GiantBomb");
            return;
        }
        // end using webclient
    }
예제 #11
0
    public static void CachePlatformGames(Platform platform, bool reset = false)
    {
        GBPlatform GBPlatform = platform.GBPlatform;
        string     startDate  = reset ? @"1900-01-01 01:01:01" : GBPlatform.CacheDate.ToString(DATEFORMAT);
        string     endDate    = DateTime.Now.ToString(DATEFORMAT);

        using WebClient webClient = new();
        int       N_results;
        bool      haveResults;
        XDocument xdoc;

        Reporter.Report($"Checking GiantBomb for {platform.Title} games");

        var url = $"http://www.giantbomb.com/api/games/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate},platforms:{GBPlatform.ID}&field_list=id&sort=id:asc";


        if (webClient.SafeDownloadStringDB(url, out var downloadText))
        {
            xdoc        = XDocument.Parse(downloadText);
            haveResults = int.TryParse(xdoc.SafeGetB("number_of_total_results"), out N_results);
        }
        else
        {
            Reporter.Report("Error communicating with GiantBomb.");
            return;
        }

        // If there are results, go through them
        if (haveResults && N_results != 0)
        {
            int N_pages = N_results / 100;
            Reporter.Report("Found " + N_results + " games in GiantBomb");

            Reporter.Report("Loading sheet ");
            // Just do the first page again to save code then go through the rest of the results
            for (int i = 0; i <= N_pages; i++)
            {
                Reporter.ReportInline(i + " ");

                url = $"http://www.giantbomb.com/api/games/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate},platforms:{GBPlatform.ID}&offset={i * 100}&field_list=id,deck,developers,publishers,genres,image,name,release_date&sort=id:asc";

                // Put results into the GB Cache database
                if (webClient.SafeDownloadStringDB(url, out downloadText))
                {
                    xdoc = XDocument.Parse(downloadText);
                    foreach (XElement element in xdoc.Root.Element("results").Elements("game"))
                    {
                        // If the ID XML value was found
                        if (int.TryParse(element.SafeGetA("id"), out var intCatcher))
                        {
                            GBGame GBGame = R.Data.GBGames.FirstOrDefault(x => x.ID == intCatcher);

                            if (GBGame == null)
                            {
                                GBGame = new GBGame {
                                    ID = intCatcher
                                };
                                GBPlatform.GBGames.Add(GBGame);
                            }

                            GBGame.Title         = element.SafeGetA("name");
                            GBGame.Overview      = element.SafeGetA("deck");
                            GBGame.GBPlatform_ID = GBPlatform.ID;
                            GBGame.Date          = DateTimeRoutines.SafeGetDate(element.SafeGetA("release_date"));
                            GBGame.BoxFrontUrl   = element.SafeGetA("image", "medium_url");
                            GBGame.ScreenUrl     = element.SafeGetA("image", "screen_url");
                        }
                    }
                }
                else
                {
                    Reporter.Warn("Failure connecting to GiantBomb");
                    return;
                }
            }

            Reporter.Report("Finished.");
        }
        else
        {
            Reporter.Report("No results returned by GiantBomb");
            return;
        }
        // end using webclient
    }
예제 #12
0
    public void CachePlatformGamesAsync(Platform platform)
    {
        if (launchboxFile == null)
        {
            GetLaunchBoxFile();
        }

        // Create a dictionary of existing Games to speed lookups
        Dictionary <long, LBGame> existingLBGameDict = R.Data.LBGames.ToDictionary(x => x.ID);

        // Create a Hashset of LBGames to store any new LBGames that we discover
        HashSet <LBGame> newLBGames = new();

        List <XElement> platformGameElements = gameElementLookupByPlatform[platform.LBPlatform.Title].ToList();
        int             gameCount            = platformGameElements.Count;

        Reporter.Report($"Found {gameCount} {platform.LBPlatform.Title} games in LaunchBox zip file.");
        int j = 0;

        foreach (XElement gameElement in platformGameElements)
        {
            // Reporting only
            if ((gameCount / 10) != 0 && ++j % (gameCount / 10) == 0)
            {
                Reporter.Report("  Working " + j + " / " + gameCount + " " + platform.LBPlatform.Title + " games in the LaunchBox database.");
            }

            string title = gameElement.Element("Name")?.Value;

            // Don't create this game if the title or database ID is null
            if (string.IsNullOrEmpty(title) || !long.TryParse(gameElement.SafeGetA("DatabaseID"), out long id))
            {
                continue;
            }

            // Check if the game alredy exists in the local cache before trying to add it
            if (!existingLBGameDict.TryGetValue(id, out LBGame LBGame))
            {
                LBGame = new LBGame {
                    ID = id
                };
                newLBGames.Add(LBGame);
                Debug.WriteLine("New game: " + LBGame.Title);
            }

            // If a game has changed platforms, catch it and zero out match
            if (LBGame.LBPlatform_ID != platform.LBPlatform.ID)
            {
                LBGame.LBPlatform = platform.LBPlatform;
                Release release = R.Data.Releases.FirstOrDefault(x => x.ID_LB == LBGame.ID);
                if (release != null)
                {
                    release.ID_LB = null;
                }
            }

            // Set or overwrite game properties
            LBGame.Title = title;
            LBGame.Date  = DateTimeRoutines.SafeGetDateTime(gameElement.SafeGetA("ReleaseDate") ?? gameElement.SafeGetA("ReleaseYear") + @"-01-01 00:00:00");

            LBGame.Overview  = gameElement.Element("Overview")?.Value ?? LBGame.Overview;
            LBGame.Genres    = gameElement.Element("Genres")?.Value ?? LBGame.Genres;
            LBGame.Developer = gameElement.Element("Developer")?.Value ?? LBGame.Developer;
            LBGame.Publisher = gameElement.Element("Publisher")?.Value ?? LBGame.Publisher;
            LBGame.VideoUrl  = gameElement.Element("VideoUrl")?.Value ?? LBGame.VideoUrl;
            LBGame.WikiUrl   = gameElement.Element("WikipediaURL")?.Value ?? LBGame.WikiUrl;
            LBGame.Players   = gameElement.Element("MaxPlayers")?.Value ?? LBGame.Players;
        }
        R.Data.LBGames.AddRange(newLBGames);
    }
예제 #13
0
    /// <summary>
    /// Cache data for a selected LBPlatforms in the local database from an xml file downloaded from Launchbox.
    /// </summary>
    /// <param name="platform">Robin.Platform associated with the LBPlatform to cache.</param>
    public void CachePlatformData(Platform platform)
    {
        Reporter.Tic($"Caching data for {platform.Title}...", out int tic1);
        if (launchboxFile == null)
        {
            GetLaunchBoxFile();
        }

        // Create a dictionary of existing LBPlatforms to speed lookups
        Dictionary <string, LBPlatform> platformDictionary = R.Data.LBPlatforms.ToDictionary(x => x.Title);

        // Create a Hashset of LBPlatforms to store any new LBPlatforms that we discover
        HashSet <LBPlatform> newLBPlatforms = new();

        foreach (XElement platformElement in platformElements)
        {
            string tempTitle = platformElement.Element("Name").Value;

            // If a bad titl is found or the title is gamewave, just bail
            if (string.IsNullOrEmpty(tempTitle) || Regex.IsMatch(tempTitle, @"Game*.Wave", RegexOptions.IgnoreCase))
            {
                continue;
            }

#if DEBUG
            Stopwatch watch1 = Stopwatch.StartNew();
#endif
            // Check whether the LBPlatform exists before trying to add it. LBPlatforms have no ID, so check by title. If the title isn't found, this might be because the LBPlatform is new or because the title has been changed. The merge window lets the user decide.
            if (!platformDictionary.TryGetValue(tempTitle, out LBPlatform LBPlatform))
            {
                LBPlatform = new LBPlatform();

                Application.Current.Dispatcher.Invoke(() =>
                {
                    MergeWindow mergeWindow = new(tempTitle);

                    switch (mergeWindow.ShowDialog())
                    {
                    case true:                             // Merge the new platform with existing
                        LBPlatform = mergeWindow.SelectedLBPlatform;
                        break;

                    case false:                             // Add the new platform
                        newLBPlatforms.Add(LBPlatform);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                });
            }
#if DEBUG
            Debug.WriteLine("PB: " + watch1.ElapsedMilliseconds); watch1.Restart();
#endif
            // Whether the LBPlatorm is new or old, overwrite everything with the newest data
            LBPlatform.Title        = tempTitle;
            LBPlatform.Date         = DateTimeRoutines.SafeGetDate(platformElement.SafeGetA("Date"));
            LBPlatform.Developer    = platformElement.Element("Developer")?.Value ?? LBPlatform.Developer;
            LBPlatform.Manufacturer = platformElement.Element("Manufacturer")?.Value ?? LBPlatform.Manufacturer;
            LBPlatform.Cpu          = platformElement.Element("Cpu")?.Value ?? LBPlatform.Cpu;
            LBPlatform.Memory       = platformElement.Element("Memory")?.Value ?? LBPlatform.Memory;
            LBPlatform.Graphics     = platformElement.Element("Graphics")?.Value ?? LBPlatform.Graphics;
            LBPlatform.Sound        = platformElement.Element("Sound")?.Value ?? LBPlatform.Sound;
            LBPlatform.Display      = platformElement.Element("Display")?.Value ?? LBPlatform.Display;
            LBPlatform.Media        = platformElement.Element("Media")?.Value ?? LBPlatform.Media;
            LBPlatform.Display      = platformElement.Element("Display")?.Value ?? LBPlatform.Display;
            LBPlatform.Controllers  = platformElement.Element("MaxControllers")?.Value ?? LBPlatform.Controllers;
            LBPlatform.Category     = platformElement.Element("Category")?.Value ?? LBPlatform.Category;
#if DEBUG
            Debug.WriteLine("PC: " + watch1.ElapsedMilliseconds); watch1.Restart();
#endif
        }

        R.Data.LBPlatforms.AddRange(newLBPlatforms);
        Reporter.Toc(tic1, "all platforms cached.");
    }
예제 #14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string   loadNumber  = String.Empty;
            ListItem forSelected = null;

            try
            {
                if (Request.QueryString["date"] != null)
                {
                    string date      = Request.QueryString["date"].ToString();
                    string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month);
                    string toset     = monthName + " " + date + " " + DateTime.Now.Year;
                    loadNumber = date;
                    date       = toset;
                    loadDate   = date;
                    loadToday  = false;
                    DateTime n = new DateTime(DateTime.Now.Year, DateTime.Now.Month, Int32.Parse(loadNumber));
                    forSelected = new ListItem(n.DayOfWeek.ToString() + ", " + monthName + " " + n.Day, n.Day + "");
                }
            }
            catch (Exception eee)
            {
                GlobalHandlers.Debugger.write(eee.ToString());
            }

            setupDefaultHeader();
            if (loadToday)
            {
                Date.Text = "Lunch menu for: " + DateTime.Now.ToString("dddd, MMMMM d");
                if (DateTime.Now.isWeekday())
                {
                    string[] lunchItems = GlobalHandlers.DatabaseHandler.getListOfItemsForToday();

                    if (lunchItems == null)
                    {
                        panel.Controls.Add(new LiteralControl("<tr><td>No information</td></tr>"));
                        return;
                    }

                    foreach (string item in lunchItems)
                    {
                        panel.Controls.Add(new LiteralControl("<tr><td>" + item + "</td></tr>"));
                    }
                }
                else
                {
                    panel.Controls.Add(new LiteralControl("<tr><td>No information</td></tr>"));
                }
            }
            else if (!loadToday)
            {
                DateTime d;
                DateTimeRoutines.TryParseDate(loadDate, DateTimeRoutines.DateTimeFormat.USA_DATE, out d);
                GlobalHandlers.Debugger.write("getting this far loadDate:" + loadDate);
                if (d == null)
                {
                    panel.Controls.Add(new LiteralControl("<tr><td>No information</td></tr>"));
                    return;
                }
                Date.Text = "Lunch menu for: " + d.ToString("dddd, MMMMM d");
                if (d.isWeekday())
                {
                    string[] lunchItems = GlobalHandlers.DatabaseHandler.getListOfItemsForADay(loadNumber);
                    if (lunchItems == null)
                    {
                        panel.Controls.Add(new LiteralControl("<tr><td>No information</td></tr>"));
                        return;
                    }

                    foreach (string item in lunchItems)
                    {
                        panel.Controls.Add(new LiteralControl("<tr><td>" + item + "</td></tr>"));
                    }
                }
                else
                {
                    panel.Controls.Add(new LiteralControl("<tr><td>No information</td></tr>"));
                }
            }
            foreach (DateTime day in AllDatesInMonth(DateTime.Now.Year, DateTime.Now.Month))
            {
                if (day.isWeekday() && day >= DateTime.Now)
                {
                    combo.Items.Add(new ListItem(day.DayOfWeek.ToString() + ", " + DateTime.Now.ToString("MMMM") + " " + day.Day, day.Day + ""));
                }
            }
            combo.SelectedIndex = combo.Items.IndexOf(forSelected);
        }
예제 #15
0
    /// <summary>
    /// Implement IDB.CachePlatfomrReleases(). Go out to gamesdb.com and cache all known releases for the specified platform. Update the list of releases and store metadata for each one.
    /// </summary>
    /// <param name="platform">Robin.Platform associated with the GDBPlatform to cache.</param>
    public void CachePlatformReleases(Platform platform)
    {
        Reporter.Tic($"Getting {platform.Title} release list from Games DB...", out int tic1);
        GDBPlatform GDBPlatform = platform.GDBPlatform;

        // Update list of GDBReleases for this platform from xml file
        using (WebClient webclient = new())
        {
            // API to get xml file containing all gamesdb releases for this platform.
            string url = $"{baseUrl}GetPlatformGames.php?platform={GDBPlatform.ID}";

            // Put existing GDBReleases in a dictionary for lookup performance
            var existingGDBReleaseDict          = R.Data.GDBReleases.ToDictionary(x => x.ID);
            HashSet <GDBRelease> newGDBReleases = new();

            if (webclient.SafeDownloadStringDB(url, out string downloadText))
            {
                XDocument xDocument = XDocument.Parse(downloadText);

                foreach (XElement element in xDocument.Root.Elements("Game"))
                {
                    // Don't create this game if the title is null
                    string title = element.Element("GameTitle")?.Value;
                    if (string.IsNullOrEmpty(title))
                    {
                        continue;
                    }

                    // Check if gbdRelease exists before creating new one. Whether it exists or not, overwrite properties with properties from xml file.
                    long id = long.Parse(element.Element("id")?.Value);
                    if (!existingGDBReleaseDict.TryGetValue(id, out GDBRelease GDBRelease))
                    {
                        GDBRelease = new GDBRelease {
                            ID = id
                        };
                        newGDBReleases.Add(GDBRelease);
                    }

                    GDBRelease.Title = title;
                    GDBRelease.Date  = DateTimeRoutines.SafeGetDate(element.SafeGetA("ReleaseDate") ?? "01-01-1901");

                    // If a release has changed platforms, catch it and zero out match
                    if (GDBRelease.GDBPlatform_ID != GDBPlatform.ID)
                    {
                        GDBRelease.GDBPlatform_ID = GDBPlatform.ID;
                        Release release = R.Data.Releases.FirstOrDefault(x => x.ID_GDB == id);
                        if (release != null)
                        {
                            release.ID_GDB = null;
                        }
                    }
                }
            }
            GDBPlatform.GDBReleases.UnionWith(newGDBReleases);
            Reporter.Toc(tic1);
        }

        // Temporarily set wait time to 1 ms while caching tens of thousands of games. Sorry GDB.
        int waitTimeHolder = DBTimers.GamesDB.WaitTime;

        DBTimers.GamesDB.WaitTime = 1;

        int releaseCount = GDBPlatform.GDBReleases.Count;
        int i            = 0;

        // Cache metadata for each individual game
        foreach (GDBRelease GDBRelease in GDBPlatform.GDBReleases)
        {
            if (releaseCount / 10 != 0 && i++ % (releaseCount / 10) == 0)
            {
                Reporter.Report($"{i} / {releaseCount}");
            }

            CacheReleaseData(GDBRelease);
        }
        DBTimers.GamesDB.WaitTime = waitTimeHolder;
    }
예제 #16
0
    /// <summary>
    /// Cache metadata from gamesdb.com API for a GDBRelease.
    /// </summary>
    /// <param name="GDBRelease">GDBRelease whose metadat is to be cached.</param>
    public void CacheReleaseData(GDBRelease GDBRelease)
    {
        // URL of gamesdb API to cache metadata for one release
        string url = $"{baseUrl}GetGame.php?id=" + GDBRelease.ID;

        using WebClient webclient = new();
        // Pull down the xml file containing game data from gamesdb
        if (webclient.SafeDownloadStringDB(url, out string downloadText))
        {
            XDocument xDocument = XDocument.Parse(downloadText);

            GDBRelease.Title     = xDocument.SafeGetB("Game", "GameTitle") ?? GDBRelease.Title;
            GDBRelease.Developer = xDocument.SafeGetB("Game", "Developer") ?? GDBRelease.Developer;
            GDBRelease.Publisher = xDocument.SafeGetB("Game", "Publisher") ?? GDBRelease.Publisher;
            GDBRelease.Players   = xDocument.SafeGetB("Game", "Players") ?? GDBRelease.Players;
            GDBRelease.Overview  = xDocument.SafeGetB("Game", "Overview") ?? GDBRelease.Overview;

            GDBRelease.Rating = double.Parse(xDocument.SafeGetB("Game", "Rating") ?? "0", CultureInfo.InvariantCulture);
            GDBRelease.Genre  = string.Join(",", xDocument.Root.Descendants("genre").Select(x => x.Value));
            GDBRelease.Date   = DateTimeRoutines.SafeGetDate(xDocument.SafeGetB("Game", "ReleaseDate"));

            string coop = xDocument.SafeGetB("Game", "Co-op");
            if ((coop != null) && ((coop.ToLower() == "true") || (coop.ToLower() == "yes")))
            {
                GDBRelease.Coop = true;
            }
            else
            {
                GDBRelease.Coop = false;
            }

            string BaseImageUrl = xDocument.SafeGetB("baseImgUrl");

            if (BaseImageUrl != null)
            {
                url = xDocument.SafeGetBoxArt("front");
                if (url != null)
                {
                    GDBRelease.BoxFrontUrl = BaseImageUrl + url;
                }

                url = xDocument.SafeGetBoxArt("back");
                if (url != null)
                {
                    GDBRelease.BoxBackUrl = BaseImageUrl + url;
                }

                url = xDocument.SafeGetB("Game", "Images", "banner");
                if (url != null)
                {
                    GDBRelease.BannerUrl = BaseImageUrl + url;
                }

                url = xDocument.SafeGetB("Game", "Images", "screenshot", "original");
                if (url != null)
                {
                    GDBRelease.ScreenUrl = BaseImageUrl + url;
                }

                url = xDocument.SafeGetB("Game", "Images", "clearlogo");
                if (url != null)
                {
                    GDBRelease.LogoUrl = BaseImageUrl + url;
                }
            }
        }
        else
        {
            Reporter.Report("Failure getting " + GDBRelease.Title + ", ID " + GDBRelease.ID + " from Games DB.");
        }
    }