/// <summary> /// Initializes a new instance of the <see cref="TransactionsPage" /> class. /// </summary> /// <param name="analysisLogger">The analysis logger.</param> /// <param name="device">The device.</param> public TransactionsPage(IAnalysisLogger analysisLogger, IDevice device) { this.AnalysisLogger = analysisLogger; this.AnalysisLogger.TrackEvent(PageRequestedEvent.Create(this.GetType().Name)); this.InitializeComponent(); }
protected virtual TContext CreateContext( TOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, string filePath = null) { var context = new TContext { Logger = logger, RuntimeErrors = runtimeErrors }; if (filePath != null) { context.TargetUri = new Uri(filePath); if (options.ComputeFileHashes) { if (_pathToHashDataMap != null && _pathToHashDataMap.TryGetValue(filePath, out HashData hashData)) { context.Hashes = hashData; } else { context.Hashes = HashUtilities.ComputeHashes(filePath); } } } return(context); }
protected virtual TContext CreateContext( TOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, PropertiesDictionary policy = null, string filePath = null) { var context = new TContext { Logger = logger, RuntimeErrors = runtimeErrors, Policy = policy }; if (filePath != null) { context.TargetUri = new Uri(filePath); if ((options.DataToInsert.ToFlags() & OptionallyEmittedData.Hashes) != 0) { if (_pathToHashDataMap != null && _pathToHashDataMap.TryGetValue(filePath, out HashData hashData)) { context.Hashes = hashData; } else { context.Hashes = HashUtilities.ComputeHashes(filePath); } } } return(context); }
protected override TestAnalysisContext CreateContext( TestAnalyzeOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, PropertiesDictionary policy = null, string filePath = null) { TestAnalysisContext context = base.CreateContext(options, logger, runtimeErrors, policy, filePath); if (context.Policy == null) { context.Policy = new PropertiesDictionary(); context.Policy.SetProperty(TestRule.Behaviors, options.TestRuleBehaviors.AccessibleWithinContextOnly()); } TestRuleBehaviors behaviors = context.Policy.GetProperty(TestRule.Behaviors); context.IsValidAnalysisTarget = !behaviors.HasFlag(TestRuleBehaviors.RegardAnalysisTargetAsInvalid); context.TargetLoadException = behaviors.HasFlag(TestRuleBehaviors.RegardAnalysisTargetAsCorrupted) ? new InvalidOperationException() : null; context.Options = options; return(context); }
private bool Validate(string instanceFilePath, string schemaFilePath, IAnalysisLogger logger) { bool ok = true; try { string instanceText = File.ReadAllText(instanceFilePath); PerformSchemaValidation(instanceText, instanceFilePath, schemaFilePath, logger); } catch (JsonSyntaxException ex) { Result result = ex.ToSarifResult(); ReportResult(result, logger); // If the file isn't syntactically valid JSON, we won't be able to run // the skimmers, because they rely on being able to deserialized the file // into a SarifLog object. ok = false; } catch (SchemaValidationException ex) { ReportInvalidSchemaErrors(ex, schemaFilePath, logger); } // The framework will catch all other, unexpected exceptions, and it will // cause the tool to exit with a non-0 exit code. return(ok); }
private void PerformSchemaValidation( string instanceText, string instanceFilePath, string schemaFilePath, IAnalysisLogger logger) { string schemaText = null; if (schemaFilePath != null) { schemaText = FileSystem.ReadAllText(schemaFilePath); } else { string schemaResource = "Microsoft.CodeAnalysis.Sarif.Multitool.sarif-2.1.0.json"; using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(schemaResource)) using (var reader = new StreamReader(stream)) { schemaText = reader.ReadToEnd(); } } JsonSchema schema = SchemaReader.ReadSchema(schemaText, schemaFilePath); var validator = new Validator(schema); Result[] results = validator.Validate(instanceText, instanceFilePath); ReportResults(results, logger); }
protected static void LogToolNotification( IAnalysisLogger logger, string message, FailureLevel level = FailureLevel.Note, Exception ex = null) { ExceptionData exceptionData = null; if (ex != null) { exceptionData = new ExceptionData { Kind = ex.GetType().FullName, Message = ex.Message, Stack = Stack.CreateStacks(ex).FirstOrDefault() }; } TextWriter writer = level == FailureLevel.Error ? Console.Error : Console.Out; writer.WriteLine(message); logger.LogToolNotification(new Notification { Level = level, Message = new Message { Text = message }, Exception = exceptionData }); }
private static void ReportResult( Result result, IAnalysisLogger logger) { Rule rule = Json.Schema.Sarif.RuleFactory.GetRuleFromRuleId(result.RuleId); logger.Log(rule, result); }
private static void ReportResult( Result result, IAnalysisLogger logger) { ReportingDescriptor rule = RuleFactory.GetRuleFromRuleId(result.RuleId); logger.Log(rule, result); }
private static void ReportResult( Result result, IAnalysisLogger logger) { #if JSCHEMA_UPGRADED ReportingDescriptor rule = RuleFactory.GetRuleFromRuleId(result.RuleId); logger.Log(rule, result); #endif }
private static void ReportResults( Result[] results, IAnalysisLogger logger) { foreach (Result result in results) { ReportResult(result, logger); } }
internal Options( IEnumerable <Project> projects = null, IEnumerable <string> projectPaths = null, IEnumerable <string> sourcePaths = null, IEnumerable <IEnumerable <string> > symbolConfigurations = null, IEnumerable <string> alwaysIgnoredSymbols = null, IEnumerable <string> alwaysDefinedSymbols = null, IEnumerable <string> alwaysDisabledSymbols = null, Tristate undefinedSymbolValue = default(Tristate), IAnalysisLogger logger = null) { if (projectPaths != null) { List <Project> projectsToAdd = new List <Project>(); projectPaths.ToList().ForEach(filePath => { AnalyzerManager analyzerManager = new AnalyzerManager(); ProjectAnalyzer analyzer = analyzerManager.GetProject(filePath); projectsToAdd.AddRange(analyzerManager.GetWorkspace().CurrentSolution.Projects); }); projects = projectsToAdd.AsEnumerable(); } if (projects != null) { Documents = GetSharedDocuments(projects); } if (projects == null && sourcePaths != null) { var projectId = ProjectId.CreateNewId("AnalysisProject"); var solution = new AdhocWorkspace() .CurrentSolution .AddProject(projectId, "AnalysisProject", "AnalysisProject", LanguageNames.CSharp); foreach (var path in sourcePaths) { var documentId = DocumentId.CreateNewId(projectId); solution = solution.AddDocument( documentId, Path.GetFileName(path), new FileTextLoader(path, defaultEncoding: Encoding.UTF8)); } Documents = solution.Projects.Single().Documents.ToImmutableArray(); } _symbolConfigurations = CalculateSymbolConfigurations( alwaysDisabledSymbols, alwaysDefinedSymbols, alwaysIgnoredSymbols, symbolConfigurations); _undefinedSymbolValue = undefinedSymbolValue; Logger = logger ?? new ConsoleAnalysisLogger(); }
public DatabaseResolver(IAssignmentGraphWalker assignmentGraphWalker, IAnalysisLogger analysisLogger, List <IDatabaseAccessDetector> databaseAccessDetectors, IDatabaseFinder databaseFinder) { _assignmentGraphWalker = assignmentGraphWalker; _analysisLogger = analysisLogger; _databaseAccessDetectors = databaseAccessDetectors; _databaseFinder = databaseFinder; }
private static void ReportInvalidSchemaErrors( SchemaValidationException ex, string schemaFile, IAnalysisLogger logger) { foreach (Result result in ex.Results) { result.SetAnalysisTargetUri(schemaFile); ReportResult(result, logger); } }
protected override TestAnalysisContext CreateContext( TestAnalyzeOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, string filePath = null) { TestAnalysisContext context = base.CreateContext(options, logger, runtimeErrors, filePath); context.IsValidAnalysisTarget = options.RegardAnalysisTargetAsValid; context.TargetLoadException = options.RegardAnalysisTargetAsCorrupted ? new InvalidOperationException() : null; context.Options = options; return(context); }
protected override SarifValidationContext CreateContext( ValidateOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, PropertiesDictionary policy = null, string filePath = null) { SarifValidationContext context = base.CreateContext(options, logger, runtimeErrors, policy, filePath); context.SchemaFilePath = options.SchemaFilePath; context.UpdateInputsToCurrentSarif = options.UpdateInputsToCurrentSarif; return(context); }
protected override AnalyzeContext CreateContext( AnalyzeOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, PropertiesDictionary policy = null, string filePath = null) { AnalyzeContext context = base.CreateContext(options, logger, runtimeErrors, policy, filePath); var aggregatingLogger = (AggregatingLogger)context.Logger; aggregatingLogger.Loggers.Add(new TestLogger()); return(context); }
internal Options( IEnumerable <Project> projects = null, IEnumerable <string> projectPaths = null, IEnumerable <string> sourcePaths = null, IEnumerable <IEnumerable <string> > symbolConfigurations = null, IEnumerable <string> alwaysIgnoredSymbols = null, IEnumerable <string> alwaysDefinedSymbols = null, IEnumerable <string> alwaysDisabledSymbols = null, Tristate undefinedSymbolValue = default(Tristate), IAnalysisLogger logger = null) { if (projectPaths != null) { projects = Task.WhenAll(from path in projectPaths select MSBuildWorkspace.Create().OpenProjectAsync(path, CancellationToken.None)).Result; } if (projects != null) { Documents = GetSharedDocuments(projects); } if (projects == null && sourcePaths != null) { var projectId = ProjectId.CreateNewId("AnalysisProject"); var solution = new AdhocWorkspace() .CurrentSolution .AddProject(projectId, "AnalysisProject", "AnalysisProject", LanguageNames.CSharp); foreach (var path in sourcePaths) { var documentId = DocumentId.CreateNewId(projectId); solution = solution.AddDocument( documentId, Path.GetFileName(path), new FileTextLoader(path, defaultEncoding: Encoding.UTF8)); } Documents = solution.Projects.Single().Documents.ToImmutableArray(); } _symbolConfigurations = CalculateSymbolConfigurations( alwaysDisabledSymbols, alwaysDefinedSymbols, alwaysIgnoredSymbols, symbolConfigurations); _undefinedSymbolValue = undefinedSymbolValue; Logger = logger ?? new ConsoleAnalysisLogger(); }
internal Options( IEnumerable<Project> projects = null, IEnumerable<string> projectPaths = null, IEnumerable<string> sourcePaths = null, IEnumerable<IEnumerable<string>> symbolConfigurations = null, IEnumerable<string> alwaysIgnoredSymbols = null, IEnumerable<string> alwaysDefinedSymbols = null, IEnumerable<string> alwaysDisabledSymbols = null, Tristate undefinedSymbolValue = default(Tristate), IAnalysisLogger logger = null) { if (projectPaths != null) { projects = Task.WhenAll(from path in projectPaths select MSBuildWorkspace.Create().OpenProjectAsync(path, CancellationToken.None)).Result; } if (projects != null) { Documents = GetSharedDocuments(projects); } if (projects == null && sourcePaths != null) { var projectId = ProjectId.CreateNewId("AnalysisProject"); var solution = new AdhocWorkspace() .CurrentSolution .AddProject(projectId, "AnalysisProject", "AnalysisProject", LanguageNames.CSharp); foreach (var path in sourcePaths) { var documentId = DocumentId.CreateNewId(projectId); solution = solution.AddDocument( documentId, Path.GetFileName(path), new FileTextLoader(path, defaultEncoding: Encoding.UTF8)); } Documents = solution.Projects.Single().Documents.ToImmutableArray(); } _symbolConfigurations = CalculateSymbolConfigurations( alwaysDisabledSymbols, alwaysDefinedSymbols, alwaysIgnoredSymbols, symbolConfigurations); _undefinedSymbolValue = undefinedSymbolValue; Logger = logger ?? new ConsoleAnalysisLogger(); }
private void PerformSchemaValidation( string instanceText, string instanceFilePath, string schemaFilePath, IAnalysisLogger logger) { string schemaText = FileSystem.ReadAllText(schemaFilePath); JsonSchema schema = SchemaReader.ReadSchema(schemaText, schemaFilePath); var validator = new Validator(schema); Result[] results = validator.Validate(instanceText, instanceFilePath); ReportResults(results, logger); }
/// <summary> /// Initializes a new instance of the <see cref="App" /> class. /// </summary> /// <param name="device">The device.</param> /// <param name="analysisLogger">The analysis logger.</param> public App(IDevice device, IAnalysisLogger analysisLogger) { this.Device = device; this.AnalysisLogger = analysisLogger; this.InitializeComponent(); SyncfusionLicenseProvider.RegisterLicense("MTkwMDU4QDMxMzcyZTM0MmUzMENHeFNiTzVPdWtQdk5td09TY0RjRVhUQ1hORFF5cFFKMW5QdnN0RDRLMGc9"); App.Container = Bootstrapper.Run(); App.Container.RegisterInstance(this.Device, new ContainerControlledLifetimeManager()); App.Container.RegisterInstance(this.AnalysisLogger, new ContainerControlledLifetimeManager()); }
private static void ReportInvalidSchemaErrors( SchemaValidationException ex, string schemaFile, IAnalysisLogger logger) { foreach (SchemaValidationException schemaValidationException in ex.WrappedExceptions) { Result result = ResultFactory.CreateResult( schemaValidationException.JToken, schemaValidationException.ErrorNumber, schemaValidationException.Args); result.SetResultFile(schemaFile); ReportResult(result, logger); } }
/// <summary> /// Initializes a new instance of the <see cref="LoginPresenter" /> class. /// </summary> /// <param name="loginPage">The login page.</param> /// <param name="mainPage">The main page.</param> /// <param name="loginViewModel">The login view model.</param> /// <param name="device">The device.</param> /// <param name="securityServiceClient">The security service client.</param> /// <param name="transactionProcessorAclClient">The transaction processor acl client.</param> /// <param name="analysisLogger">The analysis logger.</param> public LoginPresenter(ILoginPage loginPage, IMainPage mainPage, LoginViewModel loginViewModel, IDevice device, ISecurityServiceClient securityServiceClient, ITransactionProcessorACLClient transactionProcessorAclClient, IAnalysisLogger analysisLogger) { this.MainPage = mainPage; this.LoginPage = loginPage; this.LoginViewModel = loginViewModel; this.Device = device; this.SecurityServiceClient = securityServiceClient; this.TransactionProcessorAclClient = transactionProcessorAclClient; this.AnalysisLogger = analysisLogger; }
protected virtual TContext CreateContext( TOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, string filePath = null) { var context = new TContext(); context.Logger = logger; context.RuntimeErrors = runtimeErrors; if (filePath != null) { context.TargetUri = new Uri(filePath); } return(context); }
protected override AnalyzeContext CreateContext( AnalyzeOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, PropertiesDictionary policy = null, string filePath = null) { AnalyzeContext context = base.CreateContext(options, logger, runtimeErrors, policy, filePath); context.Traces = options.Traces.Any() ? (DefaultTraces)Enum.Parse(typeof(DefaultTraces), string.Join("|", options.Traces)) : DefaultTraces.None; context.DynamicValidation = options.DynamicValidation; return(context); }
protected virtual TContext CreateContext( TOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, PropertiesDictionary policy = null, string filePath = null) { var context = new TContext { Logger = logger, RuntimeErrors = runtimeErrors, Policy = policy }; if (filePath != null) { context.TargetUri = new Uri(filePath); } return(context); }
/// <summary> /// Initializes a new instance of the <see cref="TransactionsPresenter" /> class. /// </summary> /// <param name="transactionsPage">The transactions page.</param> /// <param name="mobileTopupSelectOperatorPage">The mobile topup select operator page.</param> /// <param name="mobileTopupSelectOperatorViewModel">The mobile topup select operator view model.</param> /// <param name="mobileTopupPerformTopupPage">The mobile topup perform topup page.</param> /// <param name="mobileTopupPerformTopupViewModel">The mobile topup perform topup view model.</param> /// <param name="mobileTopupPaymentSuccessPage">The mobile topup payment success page.</param> /// <param name="mobileTopupPaymentFailedPage">The mobile topup payment failed page.</param> /// <param name="device">The device.</param> /// <param name="transactionProcessorAclClient">The transaction processor acl client.</param> /// <param name="analysisLogger">The analysis logger.</param> public TransactionsPresenter(ITransactionsPage transactionsPage, IMobileTopupSelectOperatorPage mobileTopupSelectOperatorPage, MobileTopupSelectOperatorViewModel mobileTopupSelectOperatorViewModel, IMobileTopupPerformTopupPage mobileTopupPerformTopupPage, MobileTopupPerformTopupViewModel mobileTopupPerformTopupViewModel, IMobileTopupPaymentSuccessPage mobileTopupPaymentSuccessPage, IMobileTopupPaymentFailedPage mobileTopupPaymentFailedPage, IDevice device, ITransactionProcessorACLClient transactionProcessorAclClient, IAnalysisLogger analysisLogger) { this.TransactionsPage = transactionsPage; this.MobileTopupSelectOperatorPage = mobileTopupSelectOperatorPage; this.MobileTopupSelectOperatorViewModel = mobileTopupSelectOperatorViewModel; this.MobileTopupPerformTopupPage = mobileTopupPerformTopupPage; this.MobileTopupPerformTopupViewModel = mobileTopupPerformTopupViewModel; this.MobileTopupPaymentSuccessPage = mobileTopupPaymentSuccessPage; this.MobileTopupPaymentFailedPage = mobileTopupPaymentFailedPage; this.Device = device; this.TransactionProcessorAclClient = transactionProcessorAclClient; this.AnalysisLogger = analysisLogger; }
private string Validate( string instanceFilePath, string schemaFilePath, IAnalysisLogger logger, bool updateToCurrentSarifVersion = true) { string instanceText = null; try { instanceText = FileSystem.ReadAllText(instanceFilePath); if (updateToCurrentSarifVersion) { PrereleaseCompatibilityTransformer.UpdateToCurrentVersion(instanceText, formatting: Formatting.Indented, out instanceText); } PerformSchemaValidation(instanceText, instanceFilePath, schemaFilePath, logger); } catch (JsonSyntaxException ex) { Result result = ex.ToSarifResult(); ReportResult(result, logger); // If the file isn't syntactically valid JSON, we won't be able to run // the skimmers, because they rely on being able to deserialized the file // into a SarifLog object. instanceText = null; } catch (SchemaValidationException ex) { ReportInvalidSchemaErrors(ex, schemaFilePath, logger); } // The framework will catch all other, unexpected exceptions, and it will // cause the tool to exit with a non-0 exit code. return(instanceText); }
/// <summary> /// Initializes a new instance of the <see cref="MobileTopupPaymentFailedPage" /> class. /// </summary> /// <param name="analysisLogger">The analysis logger.</param> public MobileTopupPaymentFailedPage(IAnalysisLogger analysisLogger) { this.AnalysisLogger = analysisLogger; this.AnalysisLogger.TrackEvent(PageRequestedEvent.Create(this.GetType().Name)); this.InitializeComponent(); }
protected override BinaryAnalyzerContext CreateContext(AnalyzeOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, string filePath = null) { BinaryAnalyzerContext binaryAnalyzerContext = base.CreateContext(options, logger, runtimeErrors, filePath); binaryAnalyzerContext.SymbolPath = options.SymbolsPath; binaryAnalyzerContext.LocalSymbolDirectories = options.LocalSymbolDirectories; _plugInFilePaths = options.PluginFilePaths; return(binaryAnalyzerContext); }
protected override SarifValidationContext CreateContext(ValidateOptions options, IAnalysisLogger logger, RuntimeConditions runtimeErrors, string filePath = null) { SarifValidationContext context = base.CreateContext(options, logger, runtimeErrors, filePath); context.SchemaFilePath = options.SchemaFilePath; return(context); }