Ejemplo n.º 1
0
        public static async Task ValidateSchemaAsync(CdmCorpusDefinition cdmCorpus, CdmValidationStep finishStep)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Console.WriteLine("Validate schema...");
            Func <CdmValidationStep, Task <CdmValidationStep> > validateStep = null;

            validateStep = async(currentStep) =>
            {
                var resolveReferencesAndValidateTask = await Task.Run(() => cdmCorpus.ResolveReferencesAndValidateAsync(currentStep, finishStep, null)).ConfigureAwait(false);

                Func <CdmValidationStep, Task <CdmValidationStep> > validationFunc = null;
                try
                {
                    validationFunc = async(r) =>
                    {
                        CdmValidationStep nextStep = r;
                        if (nextStep == CdmValidationStep.Error)
                        {
                            Console.WriteLine("validation step failed");
                            return(CdmValidationStep.Error);
                        }
                        else if (nextStep == CdmValidationStep.Finished)
                        {
                            Console.WriteLine("validation finished");
                            stopwatch.Stop();
                            Console.WriteLine(stopwatch.Elapsed);
                            return(CdmValidationStep.Finished);
                        }
                        else
                        {
                            // success resolving all imports
                            return(await validateStep(nextStep).ConfigureAwait(false));
                        }
                    };
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception during validation");
                    Console.WriteLine(e.Message);
                }
                return(await validationFunc(resolveReferencesAndValidateTask).ConfigureAwait(false));
            };

            await validateStep(CdmValidationStep.Start).ConfigureAwait(false);
        }