示例#1
0
        protected override async Task <bool> Compile(
            GenerateCommandContext context,
            string path,
            Configuration config,
            ClientGenerator generator,
            IReadOnlyList <DocumentInfo> documents,
            ICollection <HCError> errors)
        {
            string hashFile = FileSystem.CombinePath(
                path,
                WellKnownDirectories.Generated,
                WellKnownFiles.Hash);

            if (await SkipCompileAsync(hashFile, documents, context.Force)
                .ConfigureAwait(false))
            {
                return(true);
            }

            generator.ModifyOptions(o =>
            {
                o.LanguageVersion = context.Language;
                o.EnableDISupport = context.DISupport;
            });

            generator.SetNamespace(context.Namespace);

            IReadOnlyList <HCError> validationErrors = generator.Validate();

            if (validationErrors.Count > 0)
            {
                foreach (HCError error in validationErrors)
                {
                    errors.Add(error);
                }
                return(false);
            }

            await generator.BuildAsync().ConfigureAwait(false);

            await Task.Run(() => File.WriteAllText(hashFile, CreateHash(documents)))
            .ConfigureAwait(false);

            if (context.PersistedQueryFile is { } fileName)
            {
                using IActivity activity = Output.WriteActivity("Export queries", fileName);
                FileSystem.EnsureDirectoryExists(FileSystem.GetDirectoryName(fileName));
                await generator.ExportPersistedQueriesAsync(fileName).ConfigureAwait(false);
            }

            return(true);
        }