public ReportViewModel(ReportArchive model)
 {
     this.Model              = model;
     this.NodeReportPane     = new ReportNodesTabViewModel(this);
     this.InstanceReportPane = new ReportInstancesTabViewModel(this);
     this.LicensesReportPane = new ReportLicensesTabViewModel(this);
 }
Пример #2
0
        internal void TryParse(string value, bool expectedResult, ReportArchive.ReportArchiveValue expectedMode)
        {
            ReportArchive actualMode;
            bool          actualResult = ReportArchive.TryParse(value, out actualMode);

            Assert.AreEqual(expectedResult, actualResult);
            Assert.AreEqual(expectedMode, actualMode.Value);
        }
Пример #3
0
        public void WhenTypeAnnotationIsMissing_ThenDeserializeThrowsFormatException()
        {
            var json = "{}";

            using (var reader = new StringReader(json))
            {
                Assert.Throws <FormatException>(() => ReportArchive.Deserialize(reader));
            }
        }
 public ReportItemsViewModelBase(ReportArchive model)
 {
     this.model         = model;
     this.dateSelection = new DateSelection()
     {
         StartDate = model.History.StartDate,
         EndDate   = model.History.EndDate
     };
 }
Пример #5
0
        /// <summary>
        /// Generates reports of the desired forms.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method adds the paths of the generated report documents to <see cref="ReportDocumentPaths" />.
        /// </para>
        /// </remarks>
        /// <param name="reportDirectory">The report directory.</param>
        /// <param name="reportName">The report name.</param>
        /// <param name="reportArchive">Determines whether to enclose the resulting test report in a compressed archive file.</param>
        /// <param name="reportFormats">The report formats to generate.</param>
        /// <param name="reportFormatOptions">The report formatter options.</param>
        /// <param name="reportManager">The report manager.</param>
        /// <param name="progressMonitor">A progress monitor for the operation.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="reportDirectory"/>,
        /// <paramref name="reportName"/>, <paramref name="reportFormats"/>, <paramref name="reportFormatOptions"/>,
        /// <paramref name="reportManager"/>, or <paramref name="progressMonitor"/> is null.</exception>
        public void GenerateReports(string reportDirectory, string reportName, ReportArchive reportArchive, IList <string> reportFormats,
                                    ReportFormatterOptions reportFormatOptions, IReportManager reportManager, IProgressMonitor progressMonitor)
        {
            if (reportDirectory == null)
            {
                throw new ArgumentNullException("reportDirectory");
            }
            if (reportName == null)
            {
                throw new ArgumentNullException("reportName");
            }
            if (reportFormats == null)
            {
                throw new ArgumentNullException("reportFormats");
            }
            if (reportFormatOptions == null)
            {
                throw new ArgumentNullException("reportFormatOptions");
            }
            if (reportManager == null)
            {
                throw new ArgumentNullException("reportManager");
            }
            if (progressMonitor == null)
            {
                throw new ArgumentNullException("progressMonitor");
            }

            var factory = new ReportContainerFactory(new FileSystem(), reportDirectory, reportName);

            using (progressMonitor.BeginTask("Generating reports.", reportFormats.Count))
                using (IReportContainer reportContainer = factory.MakeForSaving(reportArchive))
                {
                    IReportWriter reportWriter = reportManager.CreateReportWriter(report, reportContainer);

                    // Delete the report if it exists already.
                    reportContainer.DeleteReport();

                    // Format the report in all of the desired ways.
                    foreach (string reportFormat in reportFormats)
                    {
                        using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(1))
                            reportManager.Format(reportWriter, reportFormat, reportFormatOptions, subProgressMonitor);
                    }

                    // Save the full paths of the documents.
                    foreach (string reportDocumentPath in reportWriter.ReportDocumentPaths)
                    {
                        AddReportDocumentPath(Path.Combine(reportDirectory, reportDocumentPath));
                    }
                }
        }
Пример #6
0
        public void WhenTypeAnnotationIsWrong_ThenDeserializeThrowsFormatException()
        {
            var json = @"
            {
              '@type': 'type.googleapis.com/Google.Solutions.IapDesktop.Extensions.Activity.Foo',
              'start': '2019-12-01T00:00:00Z',
              'end': '2020-01-01T00:00:00Z'
            }";

            using (var reader = new StringReader(json))
            {
                Assert.Throws <FormatException>(() => ReportArchive.Deserialize(reader));
            }
        }
Пример #7
0
        /// <summary>
        /// Saves the specified report.
        /// </summary>
        /// <param name="report"></param>
        /// <param name="reportArchive"></param>
        /// <param name="formatterName"></param>
        /// <param name="outputPath"></param>
        /// <param name="getOutputName"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        protected bool SaveReport(Report report, ReportArchive reportArchive, string formatterName, string outputPath, Func <string> getOutputName, ReportFormatterOptions options)
        {
            return(CaptureFileException(() => "The specified output directory is not a valid file path.", () =>
            {
                var factory = new ReportContainerFactory(new FileSystem(), outputPath, getOutputName());

                using (IReportContainer outputContainer = factory.MakeForSaving(reportArchive))
                {
                    IReportWriter reportWriter = reportManager.CreateReportWriter(report, outputContainer);
                    Context.ProgressMonitorProvider.Run(pm => reportManager.Format(reportWriter, formatterName, options, pm));
                    return true;
                }
            }));
        }
Пример #8
0
        public byte[] GetById(Report report)
        {
            byte[] reportFile = null;
            if (report.ReportType == "report")
            {
                Report reportnew = _reportRepository.FindBy(x => x.ReportID == report.ReportID).FirstOrDefault();
                reportFile = reportnew.ReportFile;
            }
            else
            {
                ReportArchive reportnew = _reportArchRepository.FindBy(x => x.ReportID == report.ReportID).FirstOrDefault();
                reportFile = reportnew.Report;
            }

            return(reportFile);
        }
Пример #9
0
        public void WhenImageAnnotatedAsWindowsSpla_ThenQueryWindowsSplaReturnsInstance()
        {
            var history = new InstanceSetHistory(
                new DateTime(2019, 12, 1, 0, 0, 0, DateTimeKind.Utc),
                new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                new[]
            {
                new InstanceHistory(
                    188550847350222232,
                    new InstanceLocator("project-1", "us-central1-a", "instance-1"),
                    InstanceHistoryState.Complete,
                    new ImageLocator("project-1", "image"),
                    new []
                {
                    new InstancePlacement(
                        new DateTime(2019, 12, 1, 0, 0, 0, DateTimeKind.Utc),
                        new DateTime(2019, 12, 2, 0, 0, 0, DateTimeKind.Utc)),
                    new InstancePlacement(
                        new DateTime(2019, 12, 2, 0, 0, 0, DateTimeKind.Utc),
                        new DateTime(2019, 12, 3, 0, 0, 0, DateTimeKind.Utc))
                })
            });

            var annotatedHistory = ReportArchive.FromInstanceSetHistory(history);

            annotatedHistory.AddLicenseAnnotation(
                new ImageLocator("project-1", "image"),
                OperatingSystemTypes.Windows,
                LicenseTypes.Spla);

            Assert.IsTrue(annotatedHistory.GetInstances(
                              OperatingSystemTypes.Windows,
                              LicenseTypes.Spla).Any());

            Assert.IsTrue(annotatedHistory.GetInstances(
                              OperatingSystemTypes.Windows | OperatingSystemTypes.Linux,
                              LicenseTypes.Spla | LicenseTypes.Byol).Any());

            Assert.IsFalse(annotatedHistory.GetInstances(
                               OperatingSystemTypes.Linux,
                               LicenseTypes.Spla).Any());

            Assert.IsFalse(annotatedHistory.GetInstances(
                               OperatingSystemTypes.Windows,
                               LicenseTypes.Byol).Any());
        }
Пример #10
0
        private bool Prepare()
        {
            outputPath = Args.ReportOutput ?? Environment.CurrentDirectory;

            try
            {
                inputFileNames = GenericCollectionUtils.ConvertAllToArray(Args.ReportPaths,
                                                                          path => new Pair <string, string>(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path)));
            }
            catch (ArgumentException exception)
            {
                Context.Logger.Log(LogSeverity.Error, "One or several of the specified reports are not valid file paths.", exception);
                return(false);
            }

            return(ReportArchive.TryParse(Args.ReportArchive, out reportArchive));
        }
        private bool Prepare()
        {
            outputPath = Args.ReportOutput ?? Environment.CurrentDirectory;

            try
            {
                inputPath = Path.GetDirectoryName(Args.ReportPath);
                inputName = Path.GetFileNameWithoutExtension(Args.ReportPath);
            }
            catch (ArgumentException exception)
            {
                Context.Logger.Log(LogSeverity.Error, "The specified report is not a valid file path.", exception);
                return(false);
            }

            return(ReportArchive.TryParse(Args.ReportArchive, out reportArchive));
        }
Пример #12
0
        internal void Parse(string value, ReportArchive.ReportArchiveValue expectedMode)
        {
            ReportArchive actualMode = ReportArchive.Parse(value);

            Assert.AreEqual(expectedMode, actualMode.Value);
        }
Пример #13
0
        public void WhenSerializedAndDeserialized_ThenObjectsAreEquivalent()
        {
            var history = new InstanceSetHistory(
                new DateTime(2019, 12, 1, 0, 0, 0, DateTimeKind.Utc),
                new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                new[]
            {
                new InstanceHistory(
                    188550847350222232,
                    new InstanceLocator("project-1", "us-central1-a", "instance-1"),
                    InstanceHistoryState.Complete,
                    new ImageLocator("project-1", "windows"),
                    new []
                {
                    new InstancePlacement(
                        new DateTime(2019, 12, 1, 0, 0, 0, DateTimeKind.Utc),
                        new DateTime(2019, 12, 2, 0, 0, 0, DateTimeKind.Utc)),
                    new InstancePlacement(
                        new DateTime(2019, 12, 2, 0, 0, 0, DateTimeKind.Utc),
                        new DateTime(2019, 12, 3, 0, 0, 0, DateTimeKind.Utc))
                }),
                new InstanceHistory(
                    118550847350222232,
                    null,
                    InstanceHistoryState.MissingImage,
                    null,
                    new []
                {
                    new InstancePlacement(
                        "server-1",
                        new DateTime(2019, 12, 1, 0, 0, 0, DateTimeKind.Utc),
                        new DateTime(2019, 12, 2, 0, 0, 0, DateTimeKind.Utc))
                })
            });

            var annotatedHistory = ReportArchive.FromInstanceSetHistory(history);

            annotatedHistory.AddLicenseAnnotation(
                new ImageLocator("project-1", "windows"),
                OperatingSystemTypes.Windows,
                LicenseTypes.Spla);

            using (var memoryStream = new MemoryStream())
            {
                var s = new StringWriter();
                annotatedHistory.Serialize(s);

                var writer = new StreamWriter(memoryStream);
                annotatedHistory.Serialize(writer);
                writer.Flush();

                memoryStream.Position = 0;

                var restoredAnnotatedHistory = ReportArchive
                                               .Deserialize(new StreamReader(memoryStream));
                var restoredHistory = restoredAnnotatedHistory.History;

                Assert.AreEqual(history.StartDate, restoredHistory.StartDate);
                Assert.AreEqual(history.EndDate, restoredHistory.EndDate);

                Assert.AreEqual(2, restoredHistory.Instances.Count());
                var completeInstance = restoredHistory.Instances.First(i => i.InstanceId == 188550847350222232);

                Assert.AreEqual(history.Instances.First().Reference, completeInstance.Reference);

                Assert.AreEqual(history.Instances.First().Placements.Count(), completeInstance.Placements.Count());
                Assert.AreEqual(history.Instances.First().Placements.First().From, completeInstance.Placements.First().From);
                Assert.AreEqual(history.Instances.First().Placements.First().To, completeInstance.Placements.First().To);
                Assert.AreEqual(history.Instances.First().Placements.First().ServerId, completeInstance.Placements.First().ServerId);
                Assert.AreEqual(history.Instances.First().Placements.First().Tenancy, completeInstance.Placements.First().Tenancy);

                Assert.AreEqual(history.Instances.First().Placements.Last().From, completeInstance.Placements.Last().From);
                Assert.AreEqual(history.Instances.First().Placements.Last().To, completeInstance.Placements.Last().To);
                Assert.AreEqual(history.Instances.First().Placements.Last().ServerId, completeInstance.Placements.Last().ServerId);
                Assert.AreEqual(history.Instances.First().Placements.Last().Tenancy, completeInstance.Placements.Last().Tenancy);

                var annotation = restoredAnnotatedHistory.LicenseAnnotations[history.Instances.First().Image.ToString()];
                Assert.IsNotNull(annotation);
                Assert.AreEqual(OperatingSystemTypes.Windows, annotation.OperatingSystem);
                Assert.AreEqual(LicenseTypes.Spla, annotation.LicenseType);

                var incompleteInstance = restoredHistory.Instances.First(i => i.InstanceId == 118550847350222232);

                Assert.AreEqual(history.Instances.Last().InstanceId, incompleteInstance.InstanceId);
                Assert.AreEqual(history.Instances.Last().Reference, incompleteInstance.Reference);

                Assert.AreEqual(history.Instances.Last().Placements.Count(), incompleteInstance.Placements.Count());
                Assert.AreEqual(history.Instances.Last().Placements.First().From, incompleteInstance.Placements.First().From);
                Assert.AreEqual(history.Instances.Last().Placements.First().To, incompleteInstance.Placements.First().To);
                Assert.AreEqual(history.Instances.Last().Placements.First().ServerId, incompleteInstance.Placements.First().ServerId);
                Assert.AreEqual(history.Instances.Last().Placements.First().Tenancy, incompleteInstance.Placements.First().Tenancy);
            }
        }
Пример #14
0
        public void WhenJsonValid_ThenDeserializeReturnsObject()
        {
            var json = @"
            {
              '@type': 'type.googleapis.com/Google.Solutions.IapDesktop.Extensions.Activity.ReportArchive',
              'annotatedInstanceSetHistory': {
                'history': {
                  'start': '2019-12-01T00:00:00Z',
                  'end': '2020-01-01T00:00:00Z',
                  'instances': [
                    {
                      'id': 188550847350222232,
                      'vm': {
                        'zone': 'us-central1-a',
                        'resourceType': 'instances',
                        'projectId': 'project-1',
                        'name': 'instance-1'
                      },
                      'placements': [
                        {
                          'tenancy': 1,
                          'from': '2019-12-01T00:00:00Z',
                          'to': '2019-12-02T00:00:00Z'
                        },
                        {
                          'tenancy': 1,
                          'from': '2019-12-02T00:00:00Z',
                          'to': '2019-12-03T00:00:00Z'
                        }
                      ],
                      'image': {
                        'resourceType': 'images',
                        'projectId': 'project-1',
                        'name': 'windows'
                      },
                      'state': 0
                    },
                    {
                      'id': 118550847350222232,
                      'placements': [
                        {
                          'tenancy': 2,
                          'server': 'server-1',
                          'from': '2019-12-01T00:00:00Z',
                          'to': '2019-12-02T00:00:00Z'
                        }
                      ],
                      'state': 3
                    }
                  ]
                },
                'licenseAnnotations': {
                  'projects/project-1/global/images/windows': {
                    'licenseType': 4,
                    'os': 2
                  }
                }
              }
            }";

            using (var reader = new StringReader(json))
            {
                var restoredAnnotatedHistory = ReportArchive.Deserialize(reader);
                var restoredHistory          = restoredAnnotatedHistory.History;

                Assert.AreEqual(new DateTime(2019, 12, 1, 0, 0, 0, DateTimeKind.Utc), restoredHistory.StartDate);
                Assert.AreEqual(new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc), restoredHistory.EndDate);

                Assert.AreEqual(2, restoredHistory.Instances.Count());
                var completeInstance = restoredHistory.Instances.First(i => i.InstanceId == 188550847350222232);

                Assert.AreEqual(InstanceHistoryState.Complete, completeInstance.State);
                Assert.AreEqual(
                    new InstanceLocator("project-1", "us-central1-a", "instance-1"),
                    completeInstance.Reference);

                Assert.AreEqual(2, completeInstance.Placements.Count());
                Assert.AreEqual(new DateTime(2019, 12, 1, 0, 0, 0, DateTimeKind.Utc), completeInstance.Placements.First().From);
                Assert.AreEqual(new DateTime(2019, 12, 2, 0, 0, 0, DateTimeKind.Utc), completeInstance.Placements.First().To);
                Assert.IsNull(completeInstance.Placements.First().ServerId);
                Assert.AreEqual(Tenancies.Fleet, completeInstance.Placements.First().Tenancy);

                Assert.AreEqual(new DateTime(2019, 12, 2, 0, 0, 0, DateTimeKind.Utc), completeInstance.Placements.Last().From);
                Assert.AreEqual(new DateTime(2019, 12, 3, 0, 0, 0, DateTimeKind.Utc), completeInstance.Placements.Last().To);
                Assert.IsNull(completeInstance.Placements.Last().ServerId);
                Assert.AreEqual(Tenancies.Fleet, completeInstance.Placements.Last().Tenancy);


                var annotation = restoredAnnotatedHistory.LicenseAnnotations["projects/project-1/global/images/windows"];
                Assert.IsNotNull(annotation);
                Assert.AreEqual(OperatingSystemTypes.Windows, annotation.OperatingSystem);
                Assert.AreEqual(LicenseTypes.Spla, annotation.LicenseType);

                var incompleteInstance = restoredHistory.Instances.First(i => i.InstanceId == 118550847350222232);

                Assert.AreEqual(InstanceHistoryState.MissingImage, incompleteInstance.State);
                Assert.IsNull(incompleteInstance.Reference);

                Assert.AreEqual(1, incompleteInstance.Placements.Count());
                Assert.AreEqual(new DateTime(2019, 12, 1, 0, 0, 0, DateTimeKind.Utc), incompleteInstance.Placements.First().From);
                Assert.AreEqual(new DateTime(2019, 12, 2, 0, 0, 0, DateTimeKind.Utc), incompleteInstance.Placements.First().To);
                Assert.AreEqual("server-1", incompleteInstance.Placements.First().ServerId);
                Assert.AreEqual(Tenancies.SoleTenant, incompleteInstance.Placements.First().Tenancy);
            }
        }
Пример #15
0
        internal static void ConfigureLauncherFromArguments(TestLauncher launcher, EchoArguments arguments)
        {
            launcher.RuntimeSetup = new RuntimeSetup();
            GenericCollectionUtils.ForEach(arguments.PluginDirectories, x => launcher.RuntimeSetup.AddPluginDirectory(x));

            if (arguments.ShadowCopy.HasValue)
            {
                launcher.TestProject.TestPackage.ShadowCopy = arguments.ShadowCopy.Value;
            }

            if (arguments.Debug.HasValue && arguments.Debug.Value)
            {
                launcher.TestProject.TestPackage.DebuggerSetup = new DebuggerSetup();
            }

            if (arguments.ApplicationBaseDirectory != null)
            {
                launcher.TestProject.TestPackage.ApplicationBaseDirectory = new DirectoryInfo(arguments.ApplicationBaseDirectory);
            }

            if (arguments.WorkingDirectory != null)
            {
                launcher.TestProject.TestPackage.WorkingDirectory = new DirectoryInfo(arguments.WorkingDirectory);
            }

            if (arguments.RuntimeVersion != null)
            {
                launcher.TestProject.TestPackage.RuntimeVersion = arguments.RuntimeVersion;
            }

            GenericCollectionUtils.ForEach(arguments.Files, launcher.AddFilePattern);

            foreach (string hintDirectory in arguments.HintDirectories)
            {
                launcher.TestProject.TestPackage.AddHintDirectory(new DirectoryInfo(hintDirectory));
            }

            if (arguments.ReportDirectory != null)
            {
                launcher.TestProject.ReportDirectory = arguments.ReportDirectory;
            }

            if (arguments.ReportNameFormat != null)
            {
                launcher.TestProject.ReportNameFormat = arguments.ReportNameFormat;
            }

            launcher.TestProject.ReportArchive = ReportArchive.Parse(arguments.ReportArchive);
            GenericCollectionUtils.ForEach(arguments.ReportTypes, launcher.AddReportFormat);

            if (arguments.RunnerType != null)
            {
                launcher.TestProject.TestRunnerFactoryName = arguments.RunnerType;
            }
            GenericCollectionUtils.ForEach(arguments.RunnerExtensions, x => launcher.TestProject.AddTestRunnerExtensionSpecification(x));

            foreach (string option in arguments.ReportFormatterProperties)
            {
                KeyValuePair <string, string> pair = StringUtils.ParseKeyValuePair(option);
                launcher.ReportFormatterOptions.AddProperty(pair.Key, pair.Value);
            }

            foreach (string option in arguments.RunnerProperties)
            {
                KeyValuePair <string, string> pair = StringUtils.ParseKeyValuePair(option);
                launcher.TestRunnerOptions.AddProperty(pair.Key, pair.Value);
            }

            launcher.DoNotRun          = arguments.DoNotRun;
            launcher.IgnoreAnnotations = arguments.IgnoreAnnotations;

            if (!String.IsNullOrEmpty(arguments.Filter))
            {
                launcher.TestExecutionOptions.FilterSet = FilterUtils.ParseTestFilterSet(arguments.Filter);
            }

            launcher.EchoResults = !arguments.NoEchoResults;
            launcher.ShowReports = arguments.ShowReports;

            if (arguments.RunTimeLimitInSeconds >= 0)
            {
                launcher.RunTimeLimit = TimeSpan.FromSeconds(arguments.RunTimeLimitInSeconds);
            }
        }