protected void UpdateReleasedLanguages(DaedalicProductDatabaseContext context,
                                               int[] selectedLanguages, Release releaseToUpdate)
        {
            var oldLanguages = releaseToUpdate.Languages.ToList();

            foreach (var language in context.Language.ToList())
            {
                if (selectedLanguages.Contains(language.Id))
                {
                    if (!oldLanguages.Any(ol => ol.LanguageId == language.Id))
                    {
                        releaseToUpdate.Languages.Add(new ReleasedLanguage {
                            ReleaseId = releaseToUpdate.Id, LanguageId = language.Id
                        });
                    }
                }
                else
                {
                    ReleasedLanguage oldLanguage = releaseToUpdate.Languages.FirstOrDefault(ol => ol.LanguageId == language.Id);

                    if (oldLanguage != null)
                    {
                        context.Remove(oldLanguage);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public List <InsightResult> Run(DaedalicProductDatabaseContext context, ConfigurationData configuration)
        {
            // Query database.
            List <InsightResult> results = new List <InsightResult>();

            foreach (Release release in context.Release
                     .Include(r => r.Game)
                     .Include(r => r.ReleaseStatus)
                     .Include(r => r.Platform)
                     .Where(r => r.ReleaseDate.HasValue &&
                            r.ReleaseDate.Value < DateTime.UtcNow &&
                            r.ReleaseStatusId != configuration.FinishedReleaseStatus))
            {
                // Collect results.
                string platformName = release.Platform != null ? release.Platform.Name : "none";

                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Warning,
                    Item     = release,
                    Text     = $"{release.Game.Name} ({platformName}) release date {release.ReleaseDate.Value.ToShortDateString()} has passed, but status is still {release.ReleaseStatus.Name}."
                });
            }

            return(results);
        }
Ejemplo n.º 3
0
        protected async Task ChangeOrder <TItem>(DaedalicProductDatabaseContext context, Func <DaedalicProductDatabaseContext,
                                                                                               DbSet <TItem> > dbSetSelector, int?id, int change) where TItem : class, IIndexedModel, IOrderedModel
        {
            // Get current statuses.
            List <TItem> items = dbSetSelector(context).OrderBy(i => i.Order).ToList();

            // Assign current indices (fixes gaps caused by deletions).
            for (int i = 0; i < items.Count; ++i)
            {
                items[i].Order = i;
            }

            // Swap indices as desired.
            for (int i = 0; i < items.Count; ++i)
            {
                if (items[i].Id == id)
                {
                    int  otherIndex      = i + change;
                    bool otherIndexValid = otherIndex >= 0 && otherIndex < items.Count;

                    if (otherIndexValid)
                    {
                        items[i + change].Order = i;
                        items[i].Order          = i + change;
                    }

                    break;
                }
            }

            await context.SaveChangesAsync();
        }
        public List <InsightResult> Run(DaedalicProductDatabaseContext context, ConfigurationData configuration)
        {
            // Query database.
            List <InsightResult> results = new List <InsightResult>();

            // Check developers.
            foreach (Game game in context.Game.Include(g => g.Developer).Where(g => g.Developer == null))
            {
                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Warning,
                    Item     = game,
                    Text     = $"{game.Name} has no developer."
                });
            }

            // Check genres.
            foreach (Game game in context.Game.Include(g => g.Genre).Where(g => g.Genre == null))
            {
                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Warning,
                    Item     = game,
                    Text     = $"{game.Name} has no genre."
                });
            }

            // Check releases.
            foreach (Game game in context.Game.Include(g => g.Releases).Where(g => g.Releases.Count == 0))
            {
                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Warning,
                    Item     = game,
                    Text     = $"{game.Name} has no releases."
                });
            }

            // Check languages.
            foreach (Game game in context.Game.Include(g => g.SupportedLanguages).Where(g => g.SupportedLanguages.Count == 0))
            {
                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Warning,
                    Item     = game,
                    Text     = $"{game.Name} has no languages."
                });
            }

            return(results);
        }
        public List <InsightResult> Run(DaedalicProductDatabaseContext context, ConfigurationData configuration)
        {
            // Query database.
            List <UnreleasedLanguage> unreleasedLanguages = new List <UnreleasedLanguage>();

            foreach (Game game in context.Game
                     .Include(g => g.Releases)
                     .ThenInclude(r => r.Languages)
                     .Include(g => g.Releases)
                     .ThenInclude(r => r.Platform)
                     .Include(g => g.SupportedLanguages)
                     .ThenInclude(sl => sl.Language))
            {
                if (game.SupportedLanguages != null)
                {
                    foreach (Language language in game.SupportedLanguages.Select(sl => sl.Language).Distinct())
                    {
                        foreach (Platform platform in game.Releases.Where(r => r.Platform != null).Select(r => r.Platform).Distinct())
                        {
                            if (!game.Releases.Any(r => r.Platform == platform && r.Languages.Any(l => l.LanguageId == language.Id)))
                            {
                                unreleasedLanguages.Add(new UnreleasedLanguage {
                                    Game = game, Platform = platform, Language = language
                                });
                            }
                        }
                    }
                }
            }

            // Collect results.
            List <InsightResult> results = new List <InsightResult>();

            foreach (UnreleasedLanguage unreleasedLanguage in unreleasedLanguages)
            {
                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Information,
                    Item     = unreleasedLanguage.Game,
                    Text     = $"{unreleasedLanguage.Game.Name} supports {unreleasedLanguage.Language.Name}, but that language is not being released on {unreleasedLanguage.Platform.Name}."
                });
            }

            return(results);
        }
        protected void UpdateImplementedLanguages(DaedalicProductDatabaseContext context,
                                                  Dictionary <string, string> selectedLanguages, Game gameToUpdate)
        {
            var oldLanguages = gameToUpdate.ImplementedLanguages.ToList();
            var newLanguages = new List <ImplementedLanguage>();

            foreach (var language in context.Language.ToList())
            {
                string newLanguageStatus;

                if (!selectedLanguages.TryGetValue(language.Id.ToString(), out newLanguageStatus))
                {
                    continue;
                }

                int newLanguageStatusId;

                if (!int.TryParse(newLanguageStatus, out newLanguageStatusId))
                {
                    continue;
                }

                ImplementedLanguage implementedLanguage = gameToUpdate.ImplementedLanguages.FirstOrDefault(il => il.LanguageId == language.Id);

                if (implementedLanguage != null)
                {
                    implementedLanguage.LanguageStatusId = newLanguageStatusId;
                }
                else
                {
                    implementedLanguage = new ImplementedLanguage {
                        GameId = gameToUpdate.Id, LanguageId = language.Id, LanguageStatusId = newLanguageStatusId
                    };
                    gameToUpdate.ImplementedLanguages.Add(implementedLanguage);
                }
            }
        }
        public List <InsightResult> Run(DaedalicProductDatabaseContext context, ConfigurationData configuration)
        {
            // Query database.
            List <InsightResult> results = new List <InsightResult>();

            // Check GMC dates.
            foreach (Release release in context.Release.Include(r => r.Game).Include(r => r.Platform).Where(r => r.GmcDate == null))
            {
                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Warning,
                    Item     = release,
                    Text     = $"A release for {release.Game.Name} ({release.Platform.Name}) has no GMC date."
                });
            }

            // Check release dates.
            foreach (Release release in context.Release.Include(r => r.Game).Include(r => r.Platform).Where(r => r.ReleaseDate == null))
            {
                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Warning,
                    Item     = release,
                    Text     = $"A release for {release.Game.Name} ({release.Platform.Name}) has no release date."
                });
            }

            // Check version numbers.
            foreach (Release release in context.Release.Include(r => r.Game).Include(r => r.Platform).Where(r => r.Version.Length == 0))
            {
                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Warning,
                    Item     = release,
                    Text     = $"A release for {release.Game.Name} ({release.Platform.Name}) has no version number."
                });
            }

            // Check publishers.
            foreach (Release release in context.Release.Include(r => r.Game).Include(r => r.Platform).Include(r => r.Publisher).Where(r => r.Publisher == null))
            {
                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Warning,
                    Item     = release,
                    Text     = $"A release for {release.Game.Name} ({release.Platform.Name}) has no publisher."
                });
            }

            // Check engines.
            foreach (Release release in context.Release.Include(r => r.Game).Include(r => r.Platform).Include(r => r.Engine).Where(r => r.Engine == null))
            {
                results.Add(new InsightResult
                {
                    Severity = InsightResultSeverity.Warning,
                    Item     = release,
                    Text     = $"A release for {release.Game.Name} ({release.Platform.Name}) has no engine."
                });
            }

            return(results);
        }
        protected void UpdateSupportedLanguages(DaedalicProductDatabaseContext context,
                                                string[] selectedLanguages, Game gameToUpdate)
        {
            var oldLanguages = gameToUpdate.SupportedLanguages.ToList();
            var newLanguages = new List <SupportedLanguage>();

            foreach (string selectedLanguage in selectedLanguages)
            {
                string[] languageParts = selectedLanguage.Split('/');

                if (languageParts.Length < 2)
                {
                    continue;
                }

                int languageId;
                int languageTypeId;

                if (!int.TryParse(languageParts[0], out languageId))
                {
                    continue;
                }

                if (!int.TryParse(languageParts[1], out languageTypeId))
                {
                    continue;
                }

                newLanguages.Add(new SupportedLanguage
                {
                    GameId         = gameToUpdate.Id,
                    LanguageId     = languageId,
                    LanguageTypeId = languageTypeId
                });
            }

            foreach (var language in context.Language.ToList())
            {
                foreach (var languageType in context.LanguageType.ToList())
                {
                    SupportedLanguage newLanguage = newLanguages.FirstOrDefault(nl => nl.LanguageId == language.Id && nl.LanguageTypeId == languageType.Id);

                    if (newLanguage != null)
                    {
                        if (!oldLanguages.Any(ol => ol.LanguageId == language.Id && ol.LanguageTypeId == languageType.Id))
                        {
                            gameToUpdate.SupportedLanguages.Add(newLanguage);
                        }
                    }
                    else
                    {
                        SupportedLanguage oldLanguage = gameToUpdate.SupportedLanguages.FirstOrDefault(ol => ol.LanguageId == language.Id && ol.LanguageTypeId == languageType.Id);

                        if (oldLanguage != null)
                        {
                            context.Remove(oldLanguage);
                        }
                    }
                }
            }
        }