Example #1
0
        public async Task SerializeAsync(Stream stream, string projectFilePath, ProjectFile projectFile, IMessageSink messageSink)
        {
            // Create a message repository that can be used to test if there were any errors.
            var messageRepository = new InMemoryMessageRepository();

            var compositeMessageSink = await this.CreateCompositeMessageSinkAsync(projectFilePath, messageSink, messageRepository, Constants.ProjectFileSerializationFunctionalityName);

            // Test message output.
            await compositeMessageSink.AddOutputMessageAsync(this.NowUtcProvider, $"Serialization of:\n{projectFilePath}");

            // Change all project reference paths to be relative, not absolute, using the input project file path.
            foreach (var projectReference in projectFile.ProjectReferences)
            {
                var projectReferenceRelativePath = this.StringlyTypedPathOperator.GetRelativePathFileToFile(projectFilePath, projectReference.ProjectFilePath);

                projectReference.ProjectFilePath = projectReferenceRelativePath;
            }

            // Validate project file.
            await this.ValidateProjectFileAsync(projectFile, messageSink);

            await this.RelativeFilePathsVisualStudioProjectFileSerializer.Serialize(stream, projectFile, compositeMessageSink);

            // Any errors?
        }
Example #2
0
      public async Task <bool> Equals(IVisualStudioProjectFile x, IVisualStudioProjectFile y, IMessageSink messageSink)
      {
          var areEqual = true;

          var generateDocumentationFileAreEqual = await this.CompareSettable(x.GenerateDocumentationFile, y.GenerateDocumentationFile, messageSink, nameof(x.GenerateDocumentationFile));

          areEqual &= generateDocumentationFileAreEqual;

          var isPackableAreEqual = await this.CompareSettable(x.IsPackable, y.IsPackable, messageSink, nameof(x.IsPackable));

          areEqual &= isPackableAreEqual;

          var languageVersionAreEqual = await this.CompareSettable(x.LanguageVersion, y.LanguageVersion, messageSink, nameof(x.LanguageVersion));

          areEqual &= languageVersionAreEqual;

          var noWarnAreEqual = await this.CompareSettable(x.NoWarn, y.NoWarn, messageSink, nameof(x.NoWarn));

          areEqual &= noWarnAreEqual;

          var outputTypeAreEqual = await this.CompareSettable(x.OutputType, y.OutputType, messageSink, nameof(x.OutputType));

          areEqual &= outputTypeAreEqual;

          var sdkAreEqual = await this.CompareSettable(x.SDK, y.SDK, messageSink, nameof(x.SDK));

          areEqual &= sdkAreEqual;

          var targetFrameworkAreEqual = await this.CompareSettable(x.TargetFramework, y.TargetFramework, messageSink, nameof(x.TargetFramework));

          areEqual &= targetFrameworkAreEqual;


          var packageReferenceComparisonMessageRepository = new InMemoryMessageRepository();

          var packageReferencesEqual = await x.PackageReferences.SequenceEqualAsync(y.PackageReferences, DefaultIPackageReferenceEqualityComparer.Instance, this.NowUtcProvider, packageReferenceComparisonMessageRepository, false);

          if (!packageReferencesEqual)
          {
              await messageSink.AddErrorMessageAsync(this.NowUtcProvider, "Package references not equal.");

              await messageSink.CopyFromAsync(packageReferenceComparisonMessageRepository);
          }
          areEqual &= packageReferencesEqual;

          var projectReferenceComparisonMessageRepository = new InMemoryMessageRepository();

          var projectReferencesEqual = await x.ProjectReferences.SequenceEqualAsync(y.ProjectReferences, DefaultProjectReferenceEqualityComparer.Instance, this.NowUtcProvider, projectReferenceComparisonMessageRepository);

          if (!projectReferencesEqual)
          {
              await messageSink.AddErrorMessageAsync(this.NowUtcProvider, "Project references not equal.");

              await messageSink.CopyFromAsync(packageReferenceComparisonMessageRepository);
          }
          areEqual &= projectReferencesEqual;

          return(areEqual);
      }
Example #3
0
        public async Task <ProjectFile> DeserializeAsync(Stream stream, string projectFilePath, IMessageSink messageSink)
        {
            // Create a message repository that can be used to test if there were any errors.
            var messageRepository = new InMemoryMessageRepository();

            var compositeMessageSink = await this.CreateCompositeMessageSinkAsync(projectFilePath, messageSink, messageRepository, Constants.ProjectFileDeserializationFunctionalityName);

            // Test message output.
            await compositeMessageSink.AddOutputMessageAsync(this.NowUtcProvider, $"Deserialization of:\n{projectFilePath}");

            // Now deserialize.
            var projectFile = await this.RelativeFilePathsVisualStudioProjectFileSerializer.Deserialize(stream, compositeMessageSink);

            // Change all project reference paths to be absolute, not relative, using the input project file path.
            foreach (var projectReference in projectFile.ProjectReferences)
            {
                var projectReferenceAbsolutePath = this.StringlyTypedPathOperator.Combine(projectFilePath, projectReference.ProjectFilePath);

                projectReference.ProjectFilePath = projectReferenceAbsolutePath;
            }

            // Validate the project file.
            await this.ValidateProjectFileAsync(projectFile, compositeMessageSink);

            // If there are any error messages, and the deserializations settings say we should throw if there are any error messages, throw an exception.
            var errorMessages = await messageRepository.GetErrorsAsync();

            if (errorMessages.Any())
            {
                if (this.VisualStudioProjectFileDeserializationSettings.ThrowIfAnyErrorAtEnd)
                {
                    var messagesOutputFilePath = await this.GetMessagesOutputFilePathAsync(Constants.ProjectFileDeserializationFunctionalityName, projectFilePath);

                    throw new Exception($"There were deserialization errors. See:\n{messagesOutputFilePath}");
                }
            }

            return(projectFile);
        }
Example #4
0
        /// <summary>
        /// Demo init.
        /// </summary>
        private static void Init()
        {
            Paging.Try1();

            /*
             * var config = Saritasa.Tools.Messages.Configuration.XmlConfiguration.AppConfig;
             * CommandPipeline = (ICommandPipeline)config.First();
             */

            // We will use in memory repository.
            inMemoryMessageRepository = new InMemoryMessageRepository();

            // Create command pipeline manually.
            CommandPipeline = new CommandPipeline();
            CommandPipeline.AddMiddlewares(
                new CommandValidationMiddleware(),
                new CommandHandlerLocatorMiddleware(Assembly.GetEntryAssembly()),
                new CommandHandlerExecutorMiddleware(),
                new RepositoryMiddleware(inMemoryMessageRepository)
                );

            // Create query pipeline manually.
            QueryPipeline = new QueryPipeline();
            QueryPipeline.AddMiddlewares(
                new QueryObjectResolverMiddleware(),
                new QueryExecutorMiddleware(),
                new RepositoryMiddleware(inMemoryMessageRepository)
                );

            // Create event pipeline manually.
            EventPipeline = new EventPipeline();
            EventPipeline.AddMiddlewares(
                new EventHandlerLocatorMiddleware(Assembly.GetEntryAssembly()),
                new EventHandlerExecutorMiddleware(),
                new RepositoryMiddleware(inMemoryMessageRepository)
                );
        }
Example #5
0
        private async Task <IMessageSink> CreateCompositeMessageSinkAsync(string projectFilePath, IMessageSink parentMessageSink, InMemoryMessageRepository inMemoryMessageRepository, string functionalityName)
        {
            // Now create the messages output file sink for this functionality.
            var messagesOutputFilePath = await this.GetMessagesOutputFilePathAsync(functionalityName, projectFilePath);

            var fileFormattedMessageSink = new FileFormattedMessageSink(this.StringlyTypedPathOperator, messagesOutputFilePath);

            // Create composite message sink for all sub-functionality to use, including 1) the parent functionality's message sink, the message repository for use in determining if there were any errors, and the file message sink for persistence of messages from this functionality.
            var compositeMessageSink = new CompositeMessageSink(this.MessageFormatter, new[] { parentMessageSink, inMemoryMessageRepository }, new[] { fileFormattedMessageSink });

            return(compositeMessageSink);
        }