public void WhenDataSetSizeIsTooBigValidationResultIsError()
        {
            // Prepare
            long           maxDatasetSizeInBytes    = 255;
            IConfiguration configuration            = MockFactory.ConfigurationWithMaximumDatasetSizeOf(maxDatasetSizeInBytes);
            MaximumDatasetSizeValidation validation = new MaximumDatasetSizeValidation(configuration);
            INamespaceInfo namespaceInfo            = MockFactory.NamespaceWithPathAndSize("c:\\sample_path", maxDatasetSizeInBytes + 1);

            // Exercise
            IValidationResult validationResult = validation.Validate(namespaceInfo);

            // Verify
            AssertExtension.ValidationResultIsError(validationResult, "Dataset validation does not trigger an error when dataset is too big.");
        }
Ejemplo n.º 2
0
        protected override IValidationResult DoValidate(INamespaceInfo namespaceInfo)
        {
            bool dataSetTooBig = namespaceInfo.TotalFileSizeInBytes > this._maxDataSetSize;

            if (dataSetTooBig)
            {
                return(new ValidationResult
                {
                    Result = Result.Fail,
                    Type = this.ValidationType,
                    Level = ResultLevel.Error,
                    Description = $"The dataset is too big. Maximum dataset size is {this._maxDataSetSize}.",
                    Path = namespaceInfo.Path
                });
            }

            return(this.SuccessfulResult);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the namespace that declares the code element, or the
        /// code element itself if it is an <see cref="INamespaceInfo"/>.
        /// </summary>
        /// <param name="codeElement">The code element, possibly null.</param>
        /// <returns>The namespace, or null if not found.</returns>
        public static INamespaceInfo GetNamespace(ICodeElementInfo codeElement)
        {
            INamespaceInfo @namespace = codeElement as INamespaceInfo;

            if (@namespace != null)
            {
                return(@namespace);
            }

            ITypeInfo type = GetType(codeElement);

            if (type != null)
            {
                return(type.Namespace);
            }

            return(null);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        private static string GetNamespaceName(ICodeElementInfo codeElement)
        {
            INamespaceInfo @namespace = ReflectionUtils.GetNamespace(codeElement);

            return(@namespace != null ? @namespace.Name : "");
        }
Ejemplo n.º 6
0
 /// <inheritdoc />
 public bool Equals(INamespaceInfo other)
 {
     return(Equals((object)other));
 }
 /// <inheritdoc />
 public bool Equals(INamespaceInfo other)
 {
     return Equals((object)other);
 }