protected override void ProcessRecord()
        {
            Configuration configuration = new Configuration();

            // prepare namespace validations
            var namespaceValidations = new List <INamespaceValidation>()
            {
                new InvalidFilenameValidation(configuration),
                new FilenamesCharactersValidation(configuration),
                new MaximumFileSizeValidation(configuration),
                new MaximumPathLengthValidation(configuration),
                new MaximumFilenameLengthValidation(configuration),
                new MaximumTreeDepthValidation(configuration),
                new MaximumDatasetSizeValidation(configuration),
            };

            // prepare system validations
            var systemValidations = new List <ISystemValidation>
            {
                new OSVersionValidation(configuration),
            };

            if (this.CanRunNamespaceChecks)
            {
                systemValidations.Add(new FileSystemValidation(configuration, this.Path));
            }

            // construct validation descriptions
            List <IValidationDescription> validationDescriptions = new List <IValidationDescription>();

            namespaceValidations.ForEach(o => validationDescriptions.Add((IValidationDescription)o));
            systemValidations.ForEach(o => validationDescriptions.Add((IValidationDescription)o));

            // output writers
            TextSummaryOutputWriter summaryWriter   = new TextSummaryOutputWriter(new AfsConsoleWriter(), validationDescriptions);
            PsObjectsOutputWriter   psObjectsWriter = new PsObjectsOutputWriter(this);

            this.WriteVerbose($"Path = {this.Path}");
            this.WriteVerbose($"ComputerName = {this.ComputerName}");
            this.WriteVerbose($"ComputerNameValue = {this.ComputerNameValue.Value}");
            this.WriteVerbose($"CanRunNamespaceChecks = {this.CanRunNamespaceChecks}");
            this.WriteVerbose($"CanRunSystemChecks = {this.CanRunSystemChecks}");
            this.WriteVerbose($"CanRunEstimation = {this.CanRunEstimation}");
            this.WriteVerbose($"SkipNamespaceChecks = {this.SkipNamespaceChecks}");
            this.WriteVerbose($"SkipSystemChecks = {this.SkipSystemChecks}");
            this.WriteVerbose($"Quiet = {this.Quiet}");
            this.WriteVerbose($"NumberOfSystemChecks = {systemValidations.Count}");
            this.WriteVerbose($"NumberOfNamespaceChecks = {namespaceValidations.Count}");

            long totalObjectsToScan = 0;

            if (this.CanRunEstimation && !this.SkipNamespaceChecks.ToBool())
            {
                IProgressReporter progressReporter = new NamespaceEstimationProgressReporter(this);
                progressReporter.Show();
                progressReporter.AddSteps(1);

                Stopwatch stopwatch = Stopwatch.StartNew();

                INamespaceInfo namespaceInfoEstimation;
                try
                {
                    namespaceInfoEstimation = this.RunActionWithUncConnectionIfNeeded <INamespaceInfo>(
                        () => new NamespaceEnumerator().Run(new AfsDirectoryInfo(this.Path), this.MaximumDurationOfNamespaceEstimation));
                }
                catch (System.IO.DirectoryNotFoundException)
                {
                    if (this.IsNetworkPath.Value)
                    {
                        this.WriteWarning(
                            $"Accessing network path {this.Path}' as {this.UserName} didn't work." + Environment.NewLine +
                            $"Consider using -Credential parameter to provide creentials of the user account with appropriate access.");
                    }
                    throw;
                }

                stopwatch.Stop();

                totalObjectsToScan += namespaceInfoEstimation.NumberOfDirectories + namespaceInfoEstimation.NumberOfFiles;
                progressReporter.CompleteStep();
                progressReporter.Complete();
                string   namespaceCompleteness = namespaceInfoEstimation.IsComplete ? "complete" : "incomplete";
                TimeSpan duration = stopwatch.Elapsed;

                this.WriteVerbose($"Namespace estimation took {duration.TotalSeconds:F3} seconds and is {namespaceCompleteness}");
            }
            else
            {
                this.WriteVerbose("Skipping estimation.");
            }

            if (this.CanRunSystemChecks && !this.SkipSystemChecks.ToBool())
            {
                IProgressReporter progressReporter = new SystemCheckProgressReporter(this);
                progressReporter.Show();

                progressReporter.AddSteps(systemValidations.Count);
                Stopwatch stopwatch = Stopwatch.StartNew();
                this.PerformSystemChecks(systemValidations, progressReporter, this, summaryWriter, psObjectsWriter);
                stopwatch.Stop();
                progressReporter.Complete();
                TimeSpan duration = stopwatch.Elapsed;

                this.WriteVerbose($"System checks took {duration.TotalSeconds:F3} seconds");
            }
            else
            {
                this.WriteVerbose("Skipping system checks.");
            }

            INamespaceInfo namespaceInfo = null;

            if (this.CanRunNamespaceChecks && !this.SkipNamespaceChecks.ToBool())
            {
                IProgressReporter progressReporter = new NamespaceScanProgressReporter(this);
                progressReporter.Show();
                progressReporter.AddSteps(totalObjectsToScan);

                Stopwatch stopwatch = Stopwatch.StartNew();
                namespaceInfo = this.RunActionWithUncConnectionIfNeeded <INamespaceInfo>(
                    () => this.StorageEval(namespaceValidations, progressReporter, this, summaryWriter, psObjectsWriter));
                stopwatch.Stop();
                progressReporter.Complete();

                TimeSpan duration           = stopwatch.Elapsed;
                long     namespaceFileCount = namespaceInfo.NumberOfFiles;
                double   fileThroughput     = namespaceFileCount > 0 ? duration.TotalMilliseconds / namespaceFileCount : 0.0;
                this.WriteVerbose($"Namespace scan took {duration.TotalSeconds:F3} seconds with throughput of {fileThroughput:F3} milliseconds per file");
            }
            else
            {
                this.WriteVerbose("Skipping namespace checks.");
            }

            if (!this.Quiet.ToBool())
            {
                summaryWriter.WriteReport(this.ComputerNameValue.Value, namespaceInfo);
            }
            else
            {
                this.WriteVerbose("Skipping report.");
            }
        }
Пример #2
0
        /// <summary>
        /// Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            Configuration configuration = new Configuration();

            // prepare namespace validations
            IList <INamespaceValidation> namespaceValidations = ValidationsFactory.GetNamespaceValidations(configuration);

            // prepare system validations
            IList <ISystemValidation> systemValidations = ValidationsFactory.GetSystemValidations(configuration, Path);

            // output writers
            var validationResultWriter = new PSValidationResultOutputWriter();
            var outputWriters          = new List <IOutputWriter>
            {
                validationResultWriter
            };

            WriteVerbose($"Path = {Path}");
            WriteVerbose($"ComputerName = {ComputerName}");
            WriteVerbose($"ComputerNameValue = {ComputerNameValue.Value}");
            WriteVerbose($"CanRunNamespaceChecks = {CanRunNamespaceChecks}");
            WriteVerbose($"CanRunSystemChecks = {CanRunSystemChecks}");
            WriteVerbose($"CanRunEstimation = {CanRunEstimation}");
            WriteVerbose($"SkipNamespaceChecks = {SkipNamespaceChecks}");
            WriteVerbose($"SkipSystemChecks = {SkipSystemChecks}");
            WriteVerbose($"NumberOfSystemChecks = {systemValidations.Count}");
            WriteVerbose($"NumberOfNamespaceChecks = {namespaceValidations.Count}");

            long totalObjectsToScan = 0;

            if (CanRunEstimation && !SkipNamespaceChecks.ToBool())
            {
                IProgressReporter progressReporter = new NamespaceEstimationProgressReporter(this);
                progressReporter.Show();
                progressReporter.AddSteps(1);

                Stopwatch stopwatch = Stopwatch.StartNew();

                INamespaceInfo namespaceInfoEstimation;
                try
                {
                    namespaceInfoEstimation = RunActionWithUncConnectionIfNeeded <INamespaceInfo>(
                        () => new NamespaceEnumerator().Run(new AfsDirectoryInfo(Path), MaximumDurationOfNamespaceEstimation));
                }
                catch (System.IO.DirectoryNotFoundException)
                {
                    if (IsNetworkPath.Value)
                    {
                        WriteWarning(
                            $"Accessing network path {Path}' as {UserName} didn't work." + Environment.NewLine +
                            $"Consider using -Credential parameter to provide creentials of the user account with appropriate access.");
                    }
                    throw;
                }

                stopwatch.Stop();

                totalObjectsToScan += namespaceInfoEstimation.NumberOfDirectories + namespaceInfoEstimation.NumberOfFiles;
                progressReporter.CompleteStep();
                progressReporter.Complete();
                string   namespaceCompleteness = namespaceInfoEstimation.IsComplete ? "complete" : "incomplete";
                TimeSpan duration = stopwatch.Elapsed;

                WriteVerbose($"Namespace estimation took {duration.TotalSeconds:F3} seconds and is {namespaceCompleteness}");
            }
            else
            {
                WriteVerbose("Skipping estimation.");
            }

            if (CanRunSystemChecks && !SkipSystemChecks.ToBool())
            {
                IProgressReporter progressReporter = new SystemCheckProgressReporter(this);
                progressReporter.Show();

                progressReporter.AddSteps(systemValidations.Count);
                Stopwatch stopwatch = Stopwatch.StartNew();
                PerformSystemChecks(systemValidations, progressReporter, this, outputWriters);
                stopwatch.Stop();
                progressReporter.Complete();
                TimeSpan duration = stopwatch.Elapsed;

                WriteVerbose($"System checks took {duration.TotalSeconds:F3} seconds");
            }
            else
            {
                WriteVerbose("Skipping system checks.");
            }

            INamespaceInfo namespaceInfo = null;

            if (CanRunNamespaceChecks && !SkipNamespaceChecks.ToBool())
            {
                IProgressReporter progressReporter = new NamespaceScanProgressReporter(this);
                progressReporter.Show();
                progressReporter.AddSteps(totalObjectsToScan);

                Stopwatch stopwatch = Stopwatch.StartNew();
                namespaceInfo = RunActionWithUncConnectionIfNeeded <INamespaceInfo>(
                    () => StorageEval(namespaceValidations, progressReporter, this, outputWriters));
                stopwatch.Stop();
                progressReporter.Complete();

                TimeSpan duration           = stopwatch.Elapsed;
                long     namespaceFileCount = namespaceInfo.NumberOfFiles;
                double   fileThroughput     = namespaceFileCount > 0 ? duration.TotalMilliseconds / namespaceFileCount : 0.0;
                WriteVerbose($"Namespace scan took {duration.TotalSeconds:F3} seconds with throughput of {fileThroughput:F3} milliseconds per file");
            }
            else
            {
                WriteVerbose("Skipping namespace checks.");
            }

            var validationModel = validationResultWriter.Validation;

            validationModel.ComputerName = ComputerNameValue.Value;
            if (namespaceInfo != null)
            {
                validationModel.NamespacePath           = namespaceInfo.Path;
                validationModel.NamespaceDirectoryCount = namespaceInfo.NumberOfDirectories;
                validationModel.NamespaceFileCount      = namespaceInfo.NumberOfFiles;
            }
            WriteObject(validationModel);
        }