Ejemplo n.º 1
0
        /// <inheritdoc />
                #pragma warning disable CA1506 // TODO: Decomplexify
        public async Task <IDmbProvider> FromCompileJob(CompileJob compileJob, CancellationToken cancellationToken)
        {
            if (compileJob == null)
            {
                throw new ArgumentNullException(nameof(compileJob));
            }

            // ensure we have the entire compile job tree
            logger.LogTrace("Loading compile job {0}...", compileJob.Id);
            await databaseContextFactory.UseContext(
                async db => compileJob = await db
                .CompileJobs
                .AsQueryable()
                .Where(x => x.Id == compileJob.Id)
                .Include(x => x.Job).ThenInclude(x => x.StartedBy)
                .Include(x => x.RevisionInformation).ThenInclude(x => x.PrimaryTestMerge).ThenInclude(x => x.MergedBy)
                .Include(x => x.RevisionInformation).ThenInclude(x => x.ActiveTestMerges).ThenInclude(x => x.TestMerge).ThenInclude(x => x.MergedBy)
                .FirstAsync(cancellationToken)
                .ConfigureAwait(false))
            .ConfigureAwait(false);                     // can't wait to see that query

            if (!compileJob.Job.StoppedAt.HasValue)
            {
                // This happens if we're told to load the compile job that is currently finished up
                // It can constitute an API violation if it's returned by the DreamDaemonController so just set it here
                // Bit of a hack, but it should work out to be the same value
                logger.LogTrace("Setting missing StoppedAt for CompileJob job...");
                compileJob.Job.StoppedAt = DateTimeOffset.Now;
            }

            var providerSubmitted = false;
            var newProvider       = new DmbProvider(compileJob, ioManager, () =>
            {
                if (providerSubmitted)
                {
                    CleanJob(compileJob);
                }
            });

            try
            {
                var primaryCheckTask   = ioManager.FileExists(ioManager.ConcatPath(newProvider.PrimaryDirectory, newProvider.DmbName), cancellationToken);
                var secondaryCheckTask = ioManager.FileExists(ioManager.ConcatPath(newProvider.PrimaryDirectory, newProvider.DmbName), cancellationToken);

                if (!(await primaryCheckTask.ConfigureAwait(false) && await secondaryCheckTask.ConfigureAwait(false)))
                {
                    logger.LogWarning("Error loading compile job, .dmb missing!");
                    return(null);                    // omae wa mou shinderu
                }

                lock (jobLockCounts)
                {
                    if (!jobLockCounts.TryGetValue(compileJob.Id, out int value))
                    {
                        value = 1;
                        jobLockCounts.Add(compileJob.Id, 1);
                    }
                    else
                    {
                        jobLockCounts[compileJob.Id] = ++value;
                    }

                    logger.LogTrace("Compile job {0} lock count now: {1}", compileJob.Id, value);

                    providerSubmitted = true;
                    return(newProvider);
                }
            }
            finally
            {
                if (!providerSubmitted)
                {
                    newProvider.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
                #pragma warning disable CA1506 // TODO: Decomplexify
        public async Task <IDmbProvider> FromCompileJob(CompileJob compileJob, CancellationToken cancellationToken)
        {
            if (compileJob == null)
            {
                throw new ArgumentNullException(nameof(compileJob));
            }

            // ensure we have the entire metadata tree
            logger.LogTrace("Loading compile job {0}...", compileJob.Id);
            await databaseContextFactory.UseContext(
                async db => compileJob = await db
                .CompileJobs
                .AsQueryable()
                .Where(x => x.Id == compileJob.Id)
                .Include(x => x.Job)
                .ThenInclude(x => x.StartedBy)
                .Include(x => x.RevisionInformation)
                .ThenInclude(x => x.PrimaryTestMerge)
                .ThenInclude(x => x.MergedBy)
                .Include(x => x.RevisionInformation)
                .ThenInclude(x => x.ActiveTestMerges)
                .ThenInclude(x => x.TestMerge)
                .ThenInclude(x => x.MergedBy)
                .FirstAsync(cancellationToken)
                .ConfigureAwait(false))
            .ConfigureAwait(false);                     // can't wait to see that query

            if (!compileJob.Job.StoppedAt.HasValue)
            {
                // This happens when we're told to load the compile job that is currently finished up
                // It constitutes an API violation if it's returned by the DreamDaemonController so just set it here
                // Bit of a hack, but it works out to be nearly if not the same value that's put in the DB
                logger.LogTrace("Setting missing StoppedAt for CompileJob.Job #{0}...", compileJob.Job.Id);
                compileJob.Job.StoppedAt = DateTimeOffset.UtcNow;
            }

            var providerSubmitted = false;

            void CleanupAction()
            {
                if (providerSubmitted)
                {
                    CleanJob(compileJob);
                }
            }

            var newProvider = new DmbProvider(compileJob, ioManager, CleanupAction);

            try
            {
                const string LegacyADirectoryName = "A";
                const string LegacyBDirectoryName = "B";

                var dmbExistsAtRoot = await ioManager.FileExists(
                    ioManager.ConcatPath(
                        newProvider.Directory,
                        newProvider.DmbName),
                    cancellationToken)
                                      .ConfigureAwait(false);

                if (!dmbExistsAtRoot)
                {
                    logger.LogTrace("Didn't find .dmb at game directory root, checking A/B dirs...");
                    var primaryCheckTask = ioManager.FileExists(
                        ioManager.ConcatPath(
                            newProvider.Directory,
                            LegacyADirectoryName,
                            newProvider.DmbName),
                        cancellationToken);
                    var secondaryCheckTask = ioManager.FileExists(
                        ioManager.ConcatPath(
                            newProvider.Directory,
                            LegacyBDirectoryName,
                            newProvider.DmbName),
                        cancellationToken);

                    if (!(await primaryCheckTask.ConfigureAwait(false) && await secondaryCheckTask.ConfigureAwait(false)))
                    {
                        logger.LogWarning("Error loading compile job, .dmb missing!");
                        return(null);                        // omae wa mou shinderu
                    }

                    // rebuild the provider because it's using the legacy style directories
                    // Don't dispose it
                    logger.LogDebug("Creating legacy two folder .dmb provider targeting {0} directory...", LegacyADirectoryName);
                    newProvider = new DmbProvider(compileJob, ioManager, CleanupAction, Path.DirectorySeparatorChar + LegacyADirectoryName);
                }

                lock (jobLockCounts)
                {
                    if (!jobLockCounts.TryGetValue(compileJob.Id, out int value))
                    {
                        value = 1;
                        jobLockCounts.Add(compileJob.Id, 1);
                    }
                    else
                    {
                        jobLockCounts[compileJob.Id] = ++value;
                    }

                    providerSubmitted = true;

                    logger.LogTrace("Compile job {0} lock count now: {1}", compileJob.Id, value);
                    return(newProvider);
                }
            }
            finally
            {
                if (!providerSubmitted)
                {
                    newProvider.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
                #pragma warning disable CA1506 // TODO: Decomplexify
        public async Task <IDmbProvider> FromCompileJob(CompileJob compileJob, CancellationToken cancellationToken)
        {
            if (compileJob == null)
            {
                throw new ArgumentNullException(nameof(compileJob));
            }

            // ensure we have the entire compile job tree
            await databaseContextFactory.UseContext(async db => compileJob = await db.CompileJobs.Where(x => x.Id == compileJob.Id)
                                                    .Include(x => x.Job).ThenInclude(x => x.StartedBy)
                                                    .Include(x => x.RevisionInformation).ThenInclude(x => x.PrimaryTestMerge).ThenInclude(x => x.MergedBy)
                                                    .Include(x => x.RevisionInformation).ThenInclude(x => x.ActiveTestMerges).ThenInclude(x => x.TestMerge).ThenInclude(x => x.MergedBy)
                                                    .FirstAsync(cancellationToken).ConfigureAwait(false)).ConfigureAwait(false); // can't wait to see that query

            logger.LogTrace("Loading compile job {0}...", compileJob.Id);
            var providerSubmitted = false;
            var newProvider       = new DmbProvider(compileJob, ioManager, () =>
            {
                if (providerSubmitted)
                {
                    CleanJob(compileJob);
                }
            });

            try
            {
                var primaryCheckTask   = ioManager.FileExists(ioManager.ConcatPath(newProvider.PrimaryDirectory, newProvider.DmbName), cancellationToken);
                var secondaryCheckTask = ioManager.FileExists(ioManager.ConcatPath(newProvider.PrimaryDirectory, newProvider.DmbName), cancellationToken);

                if (!(await primaryCheckTask.ConfigureAwait(false) && await secondaryCheckTask.ConfigureAwait(false)))
                {
                    logger.LogWarning("Error loading compile job, .dmb missing!");
                    return(null);                    // omae wa mou shinderu
                }

                lock (this)
                {
                    if (!jobLockCounts.TryGetValue(compileJob.Id, out int value))
                    {
                        value = 1;
                        jobLockCounts.Add(compileJob.Id, 1);
                    }
                    else
                    {
                        jobLockCounts[compileJob.Id] = ++value;
                    }

                    logger.LogTrace("Compile job {0} lock count now: {1}", compileJob.Id, value);

                    providerSubmitted = true;
                    return(newProvider);
                }
            }
            finally
            {
                if (!providerSubmitted)
                {
                    newProvider.Dispose();
                }
            }
        }