/// <summary>
        /// Evaluates the violations for the rule.
        /// </summary>
        /// <remarks></remarks>
        public override IEnumerable <ValidationResult> Validate()
        {
            List <ValidationResult> errors = new List <ValidationResult>();

            this.ValidateObject();

            tracer.Info(
                Resources.ValidateGuidanceDocument_TraceInitial, this.CurrentElement.InstanceName);

            // Get guidance document path
            var documentFilePath = GuidanceDocumentHelper.GetDocumentPath(tracer,
                                                                          this.CurrentElement.AsElement(), this.UriReferenceService);

            if (this.processor == null)
            {
                this.processor = new TocGuidanceProcessor(documentFilePath,
                                                          this.CurrentElement.Parent.Parent.PatternToolkitInfo.Identifier, this.CurrentElement.ProjectContentPath);
            }

            // Validate document
            errors.AddRange(this.processor.ValidateDocument());

            tracer.Info(
                Resources.ValidateGuidanceDocument_TraceValidation, this.CurrentElement.InstanceName, !errors.Any());

            return(errors);
        }
        /// <summary>
        /// Returns the result of evaluation of this provider.
        /// </summary>
        /// <remarks></remarks>
        public override object Evaluate()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.GuidanceDocumentPathProvider_TraceInitial, this.CurrentElement.InstanceName);

            var result = GuidanceDocumentHelper.GetDocumentPath(tracer, this.CurrentElement, this.UriReferenceService);

            tracer.Info(
                Resources.GuidanceDocumentPathProvider_TraceEvaluation, this.CurrentElement.InstanceName, result);

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Executes this commmand.
        /// </summary>
        /// <remarks></remarks>
        public override void Execute()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.CreateGuidanceDocumentsCommand_TraceInitial, this.CurrentElement.InstanceName);

            // Get guidance document path
            var documentFilePath = GuidanceDocumentHelper.GetDocumentPath(tracer,
                                                                          this.CurrentElement.AsElement(), this.UriReferenceService);

            if (this.processor == null)
            {
                this.processor = new TocGuidanceProcessor(documentFilePath,
                                                          this.CurrentElement.Parent.Parent.PatternToolkitInfo.Identifier, this.CurrentElement.ProjectContentPath);
            }

            // Validate document first
            tracer.Info(
                Resources.CreateGuidanceDocumentsCommand_TraceValidatingDocument, documentFilePath);

            this.ErrorList.Clear(documentFilePath);
            var errors = this.processor.ValidateDocument();

            if (errors.Any())
            {
                tracer.Info(
                    Resources.CreateGuidanceDocumentsCommand_TraceDocumentValidationFailed, documentFilePath, errors.Count());

                this.ErrorList.AddRange(documentFilePath, errors);
                return;
            }

            // Ensure content container exists
            var container = EnsureContentContainer();

            if (container == null)
            {
                return;
            }

            var tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            try
            {
                // Generate documents to temporary location
                tracer.Info(
                    Resources.CreateGuidanceDocumentsCommand_TraceTempGeneration, tempPath);

                var generatedFiles = this.processor.GenerateWorkflowDocuments(tempPath);

                tracer.Info(
                    Resources.CreateGuidanceDocumentsCommand_TraceSyncingDocuments, tempPath, container.GetLogicalPath());

                // Rationalize generated documents with project container
                SyncGeneratedProjectFiles(generatedFiles.ToDictionary <string, string>(gf => gf), tempPath, container);
            }
            finally
            {
                CleanupGeneratedDocuments(tempPath);
            }
        }