public ConvertFromPSCompatibilityJsonCommand() { _serializer = JsonProfileSerializer.Create(); }
protected override void EndProcessing() { CompatibilityProfileData profile; IEnumerable <Exception> errors; using (var pwsh = SMA.PowerShell.Create()) { var collectorBuilder = new CompatibilityProfileCollector.Builder(); if (ExcludeModulePathPrefix != null && ExcludeModulePathPrefix.Length > 0) { collectorBuilder.ExcludedModulePathPrefixes = ExcludeModulePathPrefix; } if (ExcludeAssemblyPathPrefix != null && ExcludeAssemblyPathPrefix.Length > 0) { collectorBuilder.ExcludedAssemblyPathPrefixes = ExcludeAssemblyPathPrefix; } using (var profileCollector = collectorBuilder.Build(pwsh)) { profile = string.IsNullOrEmpty(PlatformId) ? profileCollector.GetCompatibilityData(out errors) : profileCollector.GetCompatibilityData(PlatformId, out errors); } } // Report any problems we hit foreach (Exception e in errors) { this.WriteExceptionAsWarning(e); } if (Validate) { var validator = new QuickCheckValidator(); if (validator.IsProfileValid(profile, out IEnumerable <Exception> validationErrors)) { foreach (Exception validationError in validationErrors) { this.WriteExceptionAsWarning(validationError); } } } // If PassThru is set, just pass the object back and we're done if (PassThru) { WriteObject(profile); return; } // Set the default profile path if it was not provided string outFilePath; if (string.IsNullOrEmpty(OutFile)) { string profileName = ProfileName ?? profile.Id; outFilePath = GetProfilePath(profileName); } else { // Normalize the path to the output file we were given outFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(OutFile); } // Create the directory containing the profile // If it already exists, this call will do nothing // If it cannot be created or is a non-directory file, an exception will be raised, which we let users handle Directory.CreateDirectory(Path.GetDirectoryName(outFilePath)); // Create the JSON serializer JsonProfileSerializer jsonSerializer = NoCompress ? JsonProfileSerializer.Create(Formatting.Indented) : JsonProfileSerializer.Create(Formatting.None); // Write the file var outFile = new FileInfo(outFilePath); jsonSerializer.SerializeToFile(profile, outFile); // Return the FileInfo object for the profile WriteObject(outFile); }
protected override void BeginProcessing() { _serializer = JsonProfileSerializer.Create(NoWhitespace ? Formatting.None : Formatting.Indented); }