/* for test purposes */ public static bool ExecuteJavaRunner(AnalysisConfig config, IEnumerable<string> userCmdLineArguments, ILogger logger, string exeFileName, string propertiesFileName) { Debug.Assert(File.Exists(exeFileName), "The specified exe file does not exist: " + exeFileName); Debug.Assert(File.Exists(propertiesFileName), "The specified properties file does not exist: " + propertiesFileName); IgnoreSonarRunnerHome(logger); IEnumerable<string> allCmdLineArgs = GetAllCmdLineArgs(propertiesFileName, userCmdLineArguments, config); IDictionary<string, string> envVarsDictionary = GetAdditionalEnvVariables(logger); Debug.Assert(envVarsDictionary != null); logger.LogInfo(Resources.MSG_CallingSonarRunner); ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(exeFileName, logger) { CmdLineArgs = allCmdLineArgs, WorkingDirectory = Path.GetDirectoryName(exeFileName), EnvironmentVariables = envVarsDictionary }; ProcessRunner runner = new ProcessRunner(); bool success = runner.Execute(runnerArgs); success = success && !runner.ErrorsLogged; if (success) { logger.LogInfo(Resources.MSG_SonarRunnerCompleted); } else { logger.LogError(Resources.ERR_SonarRunnerExecutionFailed); } return success; }
public static void Route(ILogger logger, string msg) { if (!msg.IsNullOrEmpty()) { if (msg.StartsWith(StartVerbose)) _isVerboseMode = true; else if (msg.StartsWith(StopVerbose)) _isVerboseMode = false; else { if (msg.StartsWith(Verbose)) logger.LogVerbose(msg.Substring(Verbose.Length)); else if (msg.StartsWith(Success)) logger.LogSuccess(msg.Substring(Success.Length)); else if (msg.StartsWith(Warning)) logger.LogWarning(msg.Substring(Warning.Length)); else if (msg.StartsWith(Error)) logger.LogError(msg.Substring(Error.Length)); else if (msg.StartsWith(Header)) { _isVerboseMode = false; logger.LogHeader(msg.Substring(Header.Length)); } else if (_isVerboseMode) logger.LogVerbose(msg); else logger.LogInfo(msg); } } else { //logger.LogInfo(msg); } }
public void TraceData(TraceEventType eventType, int id, object data) { switch (eventType) { case TraceEventType.Critical: case TraceEventType.Error: _loggerSink?.LogError($"{id}: {data.ToString()}"); break; case TraceEventType.Warning: _loggerSink?.LogWarning($"{id}: {data.ToString()}"); break; default: _loggerSink?.LogInfo($"{id}: {data.ToString()}"); break; } }
internal X509Certificate GetCertificate(string url) { _log?.LogInfo($"Getting certificate from url '{url}'"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); return(request.ServicePoint.Certificate); }
private static int PreProcess(IBuildAgentUpdater updater, IBootstrapperSettings settings, ILogger logger) { string downloadBinPath = settings.DownloadDirectory; logger.LogInfo(Resources.MSG_PreparingDirectories); if (!Utilities.TryEnsureEmptyDirectories(logger, settings.TempDirectory, downloadBinPath)) { return ErrorCode; } string server = settings.SonarQubeUrl; Debug.Assert(!string.IsNullOrWhiteSpace(server), "Not expecting the server url to be null/empty"); logger.LogDebug(Resources.MSG_ServerUrl, server); logger.LogInfo(Resources.MSG_CheckingForUpdates); if (!updater.TryUpdate(server, downloadBinPath, logger)) { logger.LogError(Resources.ERROR_FailedToUpdateRunnerBinaries); return ErrorCode; } if (!updater.CheckBootstrapperApiVersion(settings.SupportedBootstrapperVersionsFilePath, settings.BootstrapperVersion)) { logger.LogError(Resources.ERROR_VersionMismatch); return ErrorCode; } var preprocessorFilePath = settings.PreProcessorFilePath; ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(preprocessorFilePath, logger) { CmdLineArgs = settings.ChildCmdLineArgs, WorkingDirectory = settings.TempDirectory, }; ProcessRunner runner = new ProcessRunner(); runner.Execute(runnerArgs); return runner.ExitCode; }
private static void LogProcessingCompleted(AnalysisPhase phase, int exitCode, ILogger logger) { string phaseLabel = phase == AnalysisPhase.PreProcessing ? Resources.PhaseLabel_PreProcessing : Resources.PhaseLabel_PostProcessing; if (exitCode == ProcessRunner.ErrorCode) { logger.LogError(Resources.ERROR_ProcessingFailed, phaseLabel, exitCode); } else { logger.LogInfo(Resources.MSG_ProcessingSucceeded, phaseLabel); } }
public static void LogAssemblyVersion(Assembly assembly, string description, ILogger logger) { if (assembly == null) { throw new ArgumentNullException("assembly"); } if (logger == null) { throw new ArgumentNullException("logger"); } logger.LogInfo("{0} {1}", description, assembly.GetName().Version); }
/// <summary> /// Reads file IPAddress.txt from the same dir as the application and attempts /// to read the IP address from it. /// </summary> /// <returns>The IP Address read from the file, null for all other conditions</returns> public async Task <IPAddress> LoadIPAddress(ILogger logger = default) { if (!File.Exists(FILE_NAME)) { logger?.LogInfo($"{FILE_NAME} does not exist"); return(null); } logger?.LogInfo($"Opening '{FILE_NAME}'"); using var fileStream = File.OpenRead(FILE_NAME); using var fileReader = new StreamReader(fileStream); var fileStr = await fileReader.ReadToEndAsync(); if (IPAddress.TryParse(fileStr, out var address)) { logger?.LogInfo($"Found IP address in file '{FILE_NAME}'"); return(address); } logger?.LogInfo($"Unable to parse IPAddress, found text in '{FILE_NAME}', text: '{fileStr}'"); return(null); }
public async Task <bool> EnsureDbExists(IProjectSettings project, int retries = 3) { DbContext context = null; var result = false; try { context = new StockContext(project); var i = 0; while (!result && i < retries) { ++i; result = await context.Database.EnsureCreatedAsync(); } if (result) { _logger?.LogInfo("Created database."); } else { _logger?.LogWarning($"Could not create database after {i} retires."); } } catch (Exception e) { _logger?.LogError(e); } finally { if (context != null) { await context.DisposeAsync(); } } return(result); }
protected override void OnStart(string[] args) { base.OnStart(args); var builder = new ContainerBuilder(); builder.RegisterModule(new TradeReporterModule()); var container = builder.Build(); _reporter = container.Resolve<ITradeReportGenerator>(); _logger = container.Resolve<ILogger>(); _logger.LogInfo("Service Started"); _thread = new Thread(RunReport); _thread.Start(); }
private static void InternalCopyTargetsFile(ILogger logger) { if (logger == null) { throw new ArgumentNullException("logger"); } logger.LogInfo(Resources.MSG_UpdatingMSBuildTargets); string sourceTargetsPath = Path.Combine(Path.GetDirectoryName(typeof(TeamBuildPreProcessor).Assembly.Location), "Targets", LoaderTargetsName); Debug.Assert(File.Exists(sourceTargetsPath), String.Format(System.Globalization.CultureInfo.InvariantCulture, "Could not find the loader .targets file at {0}", sourceTargetsPath)); CopyIfDifferent(sourceTargetsPath, DestinationDirectories, logger); }
public AMQPSender(string amqpsAddress, string eventHubName, string defaultSubject, string defaultDeviceId, string defaultDeviceDisplayName, ILogger logger) { Logger = SafeLogger.FromLogger(logger); #if DEBUG_LOG Logger.LogInfo("Connecting to Event hub"); #endif if (defaultSubject == null || defaultDeviceId == null || defaultDeviceDisplayName == null || eventHubName == null) { throw new ArgumentException("defaultSubject, defaultDeviceId, defaultDeviceDisplayName, eventHubName cannot be null"); } _defaultSubject = defaultSubject; _defaultDeviceId = defaultDeviceId; _defaultDeviceDisplayName = defaultDeviceDisplayName; _senders = new SendersPool(amqpsAddress, eventHubName, Constants.ConcurrentConnections, Logger); }
private static void InternalExecute(AnalysisConfig config, IEnumerable <string> userCmdLineArguments, ILogger logger, ProjectInfoAnalysisResult result) { ProjectInfoReportBuilder.WriteSummaryReport(config, result, logger); if (result.FullPropertiesFilePath == null) { // We expect a detailed error message to have been logged explaining // why the properties file generation could not be performed logger.LogInfo(Resources.MSG_PropertiesGenerationFailed); } else { string exeFileName = FindRunnerExe(config, logger); if (exeFileName != null) { result.RanToCompletion = ExecuteJavaRunner(config, userCmdLineArguments, logger, exeFileName, result.FullPropertiesFilePath); } } }
protected void Application_Start(object sender, EventArgs e) { var host = new WebHost(); host.Configure(); host.Start(); try { ILogger logger = NinjectDependencyResolver.Current.Resolve <ILogger>(); if (logger != null) { NinjectDependencyResolver.Current.Resolve <ICorrelationIdHelper>().SetCorrelationId(Guid.Empty); logger.LogInfo("Application started."); } } catch { } }
/// <summary> /// 请求报表接口 /// </summary> /// <param name="servername"></param> /// <param name="arguments"></param> /// <returns></returns> public bool RequestFujicaReport(string servername, Dictionary<string, object> arguments) { string parkingCode = "";//车编 string licensePlate = "";//车牌号或卡号 try { if (arguments.ContainsKey("ParkingCode") && arguments["ParkingCode"] != null) { parkingCode = arguments["ParkingCode"].ToString(); } if (arguments.ContainsKey("LicensePlate")&& arguments["LicensePlate"] != null) { licensePlate = arguments["LicensePlate"].ToString(); } string jsonstr = m_serializer.Serialize(arguments); string timestamp = GenerateTimeStamp(); string sign = GetSignContentV2(string.Format("param={0}&secret={1}×tamp={2}", jsonstr, Fujica_secret, timestamp), Fujica_privatekey); HttpHelp._headers.Clear(); HttpHelp.Headers.Add("sign", sign); HttpHelp.Headers.Add("appid", Fujica_appid); HttpHelp.Headers.Add("timestamp", timestamp); string result = HttpHelp.HttpPost(Fujica_url + servername, jsonstr); Dictionary<string, object> resultdic = m_serializer.Deserialize<Dictionary<string, object>>(result); if ((bool)resultdic["IsSuccess"]) { this.FujicaResult = result; m_logger.LogInfo(LoggerLogicEnum.Communication, "", parkingCode, licensePlate, "Fujica.com.cn.Tools.RequestFujicaReportStatistical.RequestFujicaReport", string.Format("接口执行成功,请求接口:{0},请求字符串:{1},原始返回结果:{2}", servername, m_serializer.Serialize(arguments), result)); } else { this.FujicaResult = result; m_logger.LogWarn(LoggerLogicEnum.Communication, "", parkingCode, licensePlate, "Fujica.com.cn.Tools.RequestFujicaReportStatistical.RequestFujicaReport", string.Format("接口执行不成功,请求接口:{0},请求字符串:{1},原始返回结果:{2}", servername, m_serializer.Serialize(arguments), result)); return false; } return true; } catch (Exception ex) { m_logger.LogFatal(LoggerLogicEnum.Communication, "", parkingCode, licensePlate, "Fujica.com.cn.Tools.RequestFujicaReportStatistical.RequestFujicaReport", string.Format("请求业务抛出异常,请求接口:{0},异常信息:{1}", servername, ex.ToString())); return false; } }
public Task <Unit> Handle(OpenSwitchCommand request, CancellationToken cancellationToken) { _logger.LogInfo($"[SwitchCommandHandler::TurnOffSwitchCommand] Sending {request.Command.ToString()} command to {request.Gid}"); using (SwitchStatusCommandingProxy commandingProxy = _proxyFactory.CreateProxy <SwitchStatusCommandingProxy, ISwitchStatusCommandingContract>(EndpointNames.SwitchStatusCommandingEndpoint)) { try { commandingProxy.SendOpenCommand(request.Gid); } catch (Exception ex) { _logger.LogError("[SwitchCommandHandler::TurnOffSwitchCommand] SwitchCommandHandler failed on TurnOffSwitch handler.", ex); throw; } } return(null); }
private async void ProcessRecord(StreamRequestContext context, KinesisEvent.KinesisEventRecord record) { var correlationId = string.Empty; try { var customerNotifications = StreamUtils.GetStreamRecord <CustomerNotificationDTO>(record.Kinesis.Data); _logger.LogInfo($"Call Type: {customerNotifications.Event.RequestType} number: {customerNotifications.Customer.NotificationNumber} status:{customerNotifications.Event.RequestStatus}", context); if (customerNotifications.Event.RequestType == "Digital" && customerNotifications.Event.RequestStatus == "REQUEST CONFIRMED") { HttpClient client = new HttpClient(); var caseId = customerNotifications.CaseData != null?customerNotifications.CaseData.CaseId.ToString() : ""; var clientId = customerNotifications.CaseData != null?customerNotifications.CaseData.ClientId.ToString() : ""; var callbackRefNumber = customerNotifications.Customer != null?customerNotifications.Customer.CallbackRefNumber.ToString() : ""; var notificationNumber = customerNotifications.Customer != null?customerNotifications.Customer.NotificationNumber.ToString() : ""; var values = new Dictionary <string, string> { { "CallbackRefNumber", callbackRefNumber } }; var content = new FormUrlEncodedContent(values); var response = await client.PostAsync("", content); var responseString = await response.Content.ReadAsStringAsync(); } } catch (BatchProcessingException processingException) { throw; } catch (Exception ex) { throw; } }
/// <summary> /// Gets the reset date. /// </summary> /// <param name="logger"> </param> /// <param name="cache"> </param> /// <param name="fixingCalendar"> </param> /// <param name="commodityForwardFpML">The fraFpML.</param> /// <param name="nameSpace"></param> /// <returns></returns> private static DateTime GetResetDate(ILogger logger, ICoreCache cache, IBusinessCalendar fixingCalendar, CommodityForward commodityForwardFpML, String nameSpace) { var effectiveDateId = fraFpML.adjustedEffectiveDate.id; var fixingdateRef = fraFpML.fixingDateOffset.dateRelativeTo.href; DateTime resetDate = fraFpML.adjustedEffectiveDate.Value; if (fixingCalendar == null) { fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, fraFpML.fixingDateOffset.businessCenters, nameSpace); } if (fixingdateRef == effectiveDateId) { resetDate = AdjustedDateHelper.ToAdjustedDate(fixingCalendar, fraFpML.adjustedEffectiveDate.Value, fraFpML.fixingDateOffset); } logger.LogInfo("Reset date set."); return(resetDate); }
public async Task ProduceReportsAsync( IEasJobContext easContext, IEnumerable <EasCsvRecord> models, IEnumerable <ValidationErrorModel> errors, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return; } _logger.LogInfo("EAS Reporting service called"); var reportOutputFilenames = new List <string>(); if (!string.IsNullOrWhiteSpace(easContext.ReportOutputFileNames)) { reportOutputFilenames.AddRange(easContext.ReportOutputFileNames.Split('|')); } foreach (var validationReport in _validationReports) { var reportsGenerated = await validationReport.GenerateReportAsync(easContext, models, errors, cancellationToken); reportOutputFilenames.AddRange(reportsGenerated); } foreach (var report in _easReports) { var reportsGenerated = await report.GenerateReportAsync(easContext, models, errors, cancellationToken); reportOutputFilenames.AddRange(reportsGenerated); } await _resultReport.GenerateReportAsync(easContext, models, errors, cancellationToken); var zipName = _fileNameService.GetZipName(easContext.Ukprn, easContext.JobId, _zipName); await _zipService.CreateZipAsync(zipName, reportOutputFilenames, easContext.Container.ToString(), cancellationToken); easContext.ReportOutputFileNames = string.Join("|", reportOutputFilenames); }
public async Task <ActionResult> Login([FromBody] LoginUser loginUser) { _logger.LogInfo($"{ loginUser.UserName} logging in."); if (!ModelState.IsValid) { _logger.LogInfo("Username & password required"); return(BadRequest(ModelState)); } AppUser user = await _userRepository.FindIdentityUser(loginUser.UserName); if (user == null) { _logger.LogInfo("Invalid username or password"); return(BadRequest(new { error = "Invalid username or password" })); } else { bool passwordValid = await _userRepository.CheckPassword(user, loginUser.Password); if (passwordValid) { string refreshToken = _tokenFactory.GenerateToken(); string remoteIpAddress = HttpContext.Connection.RemoteIpAddress?.MapToIPv4().ToString(); if (remoteIpAddress == null) { if (Request.Headers.ContainsKey("X-Forwarded-For")) { remoteIpAddress = Request.Headers["X-Forwarded-For"]; } } User us = _userRepository.FindUser(user); us.AddRefreshToken(refreshToken, us.Id, remoteIpAddress); await _userRepository.Update(us); var accessToken = await _jwtFactory.GenerateEncodedToken(us.IdentityId.ToString(), us.UserName); _logger.LogInfo("Valid login details"); return(Ok(new LoginResponse(accessToken, refreshToken))); } else { return(Ok(new LoginResponse(new [] { new Error { Code = 666, Description = "Invalid username or password" } }))); } } }
/// <summary> /// Handle user login. /// </summary> /// <returns></returns> public async Task <bool> Login() { Random rand = new Random(); if (_isLoggedIn) { _webExplorer.OpenInstagram("/"); return(true); } _webExplorer.OpenInstagram(URL_LOGIN); await Task.Delay(rand.Next(1000, 3000)); try { await _userExplorer.Login(_config.Username, _config.Password); _isLoggedIn = true; } catch (LoginException e) { await _logger.LogWarning("Login failed [username="******"]"); return(false); } catch (AccountSecurityException e) { await _logger.LogWarning("Login failed for security reasons [username="******"]"); return(false); } catch (RuntimeException e) { await _logger.LogError(e.Message); return(false); } await _logger.LogInfo(String.Format("Login for {0} - success.", _config.Username)); return(true); }
protected override bool TryGetBinaryReportFile(AnalysisConfig config, ITeamBuildSettings settings, ILogger logger, out string binaryFilePath) { var urls = urlProvider.GetCodeCoverageReportUrls(config.GetTfsUri(), config.GetBuildUri(), logger); Debug.Assert(urls != null, "Not expecting the returned list of urls to be null"); var continueProcessing = true; binaryFilePath = null; switch (urls.Count()) { case 0: logger.LogInfo(Resources.PROC_DIAG_NoCodeCoverageReportsFound); break; case 1: var url = urls.First(); var targetFileName = Path.Combine(config.SonarOutputDir, DownloadFileName); var result = downloader.DownloadReport(config.GetTfsUri(), url, targetFileName, logger); if (result) { binaryFilePath = targetFileName; } else { continueProcessing = false; logger.LogError(Resources.PROC_ERROR_FailedToDownloadReport); } break; default: // More than one continueProcessing = false; logger.LogError(Resources.PROC_ERROR_MultipleCodeCoverageReportsFound); break; } return(continueProcessing); }
public WebRTCAudioProcessor(ILogger logger, int frameSize, int samplingRate, int channels, int reverseSamplingRate, int reverseChannels) { bool ok = false; foreach (var s in supportedSamplingRates) { if (samplingRate == s) { ok = true; break; } } if (!ok) { logger.LogError("WebRTCAudioProcessor: input sampling rate ({0}) must be 8000, 16000, 32000 or 48000", samplingRate); disposed = true; return; } this.logger = logger; this.inFrameSize = frameSize; this.processFrameSize = samplingRate * supportedFrameLenMs / 1000; if (this.inFrameSize / this.processFrameSize * this.processFrameSize != this.inFrameSize) { logger.LogError("WebRTCAudioProcessor: input frame size ({0} samples / {1} ms) must be equal to or N times more than webrtc processing frame size ({2} samples / 10 ms)", this.inFrameSize, 1000f * this.inFrameSize / samplingRate, processFrameSize); disposed = true; return; } this.samplingRate = samplingRate; this.channels = channels; this.reverseSamplingRate = reverseSamplingRate; this.reverseChannels = reverseChannels; this.proc = webrtc_audio_processor_create(samplingRate, channels, this.processFrameSize, samplingRate /* reverseSamplingRate to be converted */, reverseChannels); setConfigParam(ConfigParam.AEC_DELAY_AGNOSTIC, 1); setConfigParam(ConfigParam.AEC_EXTENDED_FILTER, 1); webrtc_audio_processor_init(this.proc); if (this.inFrameSize != this.processFrameSize) { logger.LogWarning("WebRTCAudioProcessor: Frame size is {0} ms. For efficency, set it to 10 ms.", 1000 * this.inFrameSize / samplingRate); } logger.LogInfo("WebRTCAudioProcessor create sampling rate {0}, frame samples {1}", samplingRate, this.inFrameSize / this.channels); }
public IHttpActionResult UpdateUser([FromUri] int userId, [FromBody] UserSummary userSummary) { try { logger.LogDebug("User Data Update for user with ID: {0}", userId); if (!ModelState.IsValid) { var errorMessage = new ErrorMessage(HttpStatusCode.BadRequest, ErrorCode.BadArgument, "Errors in User data", ModelState); var stateErrors = errorMessage.GetStateErrors(); logger.LogWarning("User with id `{0}` was not updated. Reason: invalid User data. ({1})", userId, stateErrors); return(ResponseMessage(errorMessage.GetError())); } if (!storeService.DoesStoreExists(userSummary.StoreID)) { var errorMessage = new ErrorMessage() { ErrorCode = ErrorCode.StoreNotFound, Message = $"Store with id {userSummary.StoreID} does not exists" }; logger.LogWarning("User data for user with id `{0}` was not updated. Reason: invalid Store ID: `{1}`, does not exists", userId, userSummary.StoreID); return(ResponseMessage(errorMessage.GetError())); } else { logger.LogInfo("User with id `{0}` was successfully updated", userId); return(Ok(userService.EditUser(userSummary, userId))); } } catch (InvalidOperationException) { var errorMessage = new ErrorMessage() { HttpCode = HttpStatusCode.NotFound, ErrorCode = ErrorCode.UserNotFound, Message = $"User with id {userId} not found" }; logger.LogWarning("User with id `{0}` was not updated. Reason: user was not found in database.", userId); return(ResponseMessage(errorMessage.GetError())); } catch (Exception ex) { logger.LogError($"Error happend during user update", ex); return(InternalServerError()); } }
private void OnMatchingTweetReceived(object sender, MatchedTweetReceivedEventArgs args) { string message = args.Tweet .ToTweet(args.MatchingTracks) .ToJson(); try { _logger.LogInfo($"Sending message: {message}"); if (!args.Tweet.IsRetweet) { _eventHubClient.Send(new EventData(Encoding.UTF8.GetBytes(message))); } } catch (Exception ex) { _logger.LogError(ex); throw; } }
/// <summary> /// Logging method which allows the developer to log a message without instantiating a logger instance. /// </summary> /// <param name="message">The message which should be logged.</param> /// <param name="type">Identifies the type of information which should be logged.</param> public static void Log(string message, LogType type) { // instanciate the default logger instance ILogger logger = Logger.Instance; LogMessage lMessage = new LogMessage(message, type); // decide which logging type should be used if (type == LogType.ERROR) { logger.LogError(lMessage); } else if (type == LogType.INFO) { logger.LogInfo(lMessage); } else if (type == LogType.WARNING) { logger.LogWarning(lMessage); } }
private static void DeletePhotoFromDisk(Java.IO.File file) { try { var deleted = file.Delete(); if (!deleted) { _logger.LogInfo($"File has not been deleted: {file.AbsolutePath}"); } } catch (Exception e) { _logger.LogError($"Can't delete file: {file.AbsolutePath}", e); } finally { file.Dispose(); } }
/// <summary> /// Copy the contents of one directory to another /// </summary> /// <param name="sourceDirectory">The source folder</param> /// <param name="targetDirectory">the target folder</param> public void CopyAll(DirectoryInfo sourceDirectory, DirectoryInfo targetDirectory) { Directory.CreateDirectory(targetDirectory.FullName); // Copy each file into the new directory. foreach (FileInfo fi in sourceDirectory.GetFiles()) { var msg = $"Copying {targetDirectory.FullName}\\{fi.Name}"; _Logger.LogInfo(msg); fi.CopyTo(Path.Combine(targetDirectory.FullName, fi.Name), true); } // Copy each subdirectory using recursion. foreach (DirectoryInfo diSourceSubDir in sourceDirectory.GetDirectories()) { DirectoryInfo nextTargetSubDir = targetDirectory.CreateSubdirectory(diSourceSubDir.Name); CopyAll(diSourceSubDir, nextTargetSubDir); } }
public async Task PersistSourceDataAsync(INcsJobContextMessage ncsJobContextMessage, CancellationToken cancellationToken) { var sourceData = new Source() { UKPRN = ncsJobContextMessage.Ukprn, TouchpointId = ncsJobContextMessage.TouchpointId, SubmissionDate = ncsJobContextMessage.DssTimeStamp, DssJobId = ncsJobContextMessage.DssJobId, CreatedOn = _dateTimeProvider.GetNowUtc() }; using (var context = _ncsContext()) { context.Sources.Add(sourceData); await context.SaveChangesAsync(cancellationToken); _logger.LogInfo("NCS Source data persisted Successfully."); } }
public async Task <IFileDataCache> GetFileDataCacheAsync(int ukPrn, CancellationToken cancellationToken) { string fileDataString; string key = string.Format(FILEDATA_BY_UKPRN_KEY, ukPrn.ToString()); try { fileDataString = await _keyValuePersistenceService.GetAsync(key, cancellationToken); } catch (Exception ex) { _logger.LogError($"File Data Cache retrieval exception for the Key \'{key}\' ", ex); throw; } var fileDataCache = _jsonSerializationService.Deserialize <FileDataCache>(fileDataString); _logger.LogInfo($"Key \'{key}\' found in the store"); return(fileDataCache); }
public async Task <bool> Callback(IReportServiceContext reportServiceContext, CancellationToken cancellationToken) { _logger.LogInfo("Data Match Reporting callback invoked", jobIdOverride: reportServiceContext.JobId); cancellationToken.ThrowIfCancellationRequested(); string reportZipFileKey; if (reportServiceContext.IsIlrSubmission) { reportZipFileKey = $"{reportServiceContext.Ukprn}_{reportServiceContext.JobId}_Reports.zip"; } else { reportZipFileKey = $"R{reportServiceContext.ReturnPeriod:00}_{reportServiceContext.Ukprn}_Reports.zip"; } MemoryStream memoryStream = new MemoryStream(); var zipFileExists = await _streamableKeyValuePersistenceService.ContainsAsync(reportZipFileKey, cancellationToken); if (zipFileExists) { await _streamableKeyValuePersistenceService.GetAsync(reportZipFileKey, memoryStream, cancellationToken); } using (memoryStream) { bool needZip; using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Update, true)) { needZip = await ExecuteTasks(reportServiceContext, archive, cancellationToken); } if (needZip) { await _streamableKeyValuePersistenceService.SaveAsync(reportZipFileKey, memoryStream, cancellationToken); } } return(true); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILogger logger) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error/500"); } app.UseStatusCodePagesWithReExecute("/Error/{0}"); app.UseRequestLocalization(new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture("en-US", "en-US") }); app.UseStaticFiles(); app.UseImagesCache(); app.UseMvc(routes => { routes.MapRoute( name: "images", template: "images/{id:int}", defaults: new { controller = "Category", action = "Image" }); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); var properties = new Dictionary <string, string> { { "ApplicationLocation", env.ContentRootPath } }; logger.LogInfo("Application start", properties); }
public void Process(string assemblyFile, IAssemblyResolver resolver) { _log.LogInfo($"Aspect Injector has started for {Path.GetFileName(assemblyFile)}"); var pdbPresent = AreSymbolsFound(assemblyFile); var assembly = ReadAssembly(assemblyFile, resolver, pdbPresent); ProcessAssembly(assembly); if (!_log.IsErrorThrown) { _log.LogInfo("Assembly has been patched."); WriteAssembly(assembly, assemblyFile, pdbPresent); } }
public void RunTests(IEnumerable <TestCase> testCasesToRun, ITestFrameworkReporter reporter, IDebuggedProcessLauncher launcher, bool isBeingDebugged, string solutionDirectory, IProcessExecutor executor) { TestCase[] testCasesToRunAsArray = testCasesToRun as TestCase[] ?? testCasesToRun.ToArray(); _logger.LogInfo(String.Format(Resources.NumberOfTestsRunningMessage, testCasesToRunAsArray.Length)); lock (this) { if (_canceled) { return; } ComputeTestRunner(reporter, isBeingDebugged, solutionDirectory); } _runner.RunTests(testCasesToRunAsArray, solutionDirectory, null, null, isBeingDebugged, launcher, executor); if (_settings.ParallelTestExecution) { _schedulingAnalyzer.PrintStatisticsToDebugOutput(); } }
public bool ProcessCoverageReports() { if (!succesfullyInitialised) { throw new InvalidOperationException(Resources.EX_CoverageReportProcessorNotInitialised); } Debug.Assert(config != null, "Expecting the config to not be null. Did you call Initialise() ?"); // Fetch all of the report URLs logger.LogInfo(Resources.PROC_DIAG_FetchingCoverageReportInfoFromServer); var success = TryGetBinaryReportFile(config, settings, logger, out string binaryFilePath); if (success && binaryFilePath != null) { success = ProcessBinaryCodeCoverageReport(binaryFilePath); } return(success); }
public static void ListInboxMessages(EmailAccount inboxOwner, ILogger logger) { using (var client = new ImapClient()) { client.ServerCertificateValidationCallback = (s, c, h, e) => true; // Accept all certificates client.Connect(inboxOwner.EmailHost, inboxOwner.ImapPort, useSsl: false); client.Authenticate(inboxOwner.EmailAddress, inboxOwner.EmailPassword); var inbox = client.Inbox; // Always available inbox.Open(FolderAccess.ReadOnly); logger.LogInfo($"Total messages: {inbox.Count}"); logger.LogInfo($"Recent messages: {inbox.Recent}"); for (int i = 0; i < inbox.Count; i++) { var message = inbox.GetMessage(i); logger.LogInfo($"Subject: {message.Subject}"); string body = message.TextBody; TeatimeEmail te = JsonConvert.DeserializeObject <TeatimeEmail>(body); //TeatimeEmail te = XmlConvert.DeserializeObject<TeatimeEmail>(body); logger.LogInfo($"From: {te.FromEmailAddress}"); foreach (string toEmailAddress in te.ToEmailAddresses) { logger.LogInfo($"To: {toEmailAddress}"); } logger.LogInfo($"Topic: {te.TopicName}"); logger.LogInfo($"Message: {te.MessageText}"); } foreach (var summary in inbox.Fetch(0, -1, MessageSummaryItems.Full | MessageSummaryItems.UniqueId)) { logger.LogInfo($"[summary] {summary.Index:D2}: {summary.Envelope.Subject}"); } client.Disconnect(true); } }
private static void DiscoverTests(string executable, ITestFrameworkReporter reporter, SettingsWrapper settings, ILogger logger, IDiaResolverFactory diaResolverFactory) { settings.ExecuteWithSettingsForExecutable(executable, () => { if (!VerifyExecutableTrust(executable, settings, logger) || !IsGoogleTestExecutable(executable, settings.TestDiscoveryRegex, logger)) { return; } int nrOfTestCases = 0; Action <TestCase> reportTestCases = tc => { reporter.ReportTestsFound(tc.Yield()); logger.DebugInfo("Added testcase " + tc.DisplayName); nrOfTestCases++; }; var factory = new TestCaseFactory(executable, logger, settings, diaResolverFactory); factory.CreateTestCases(reportTestCases); logger.LogInfo("Found " + nrOfTestCases + " tests in executable " + executable); }, logger); }
/* for test purposes */ public static bool ExecuteJavaRunner(AnalysisConfig config, IEnumerable<string> userCmdLineArguments, ILogger logger, string exeFileName, string propertiesFileName) { Debug.Assert(File.Exists(exeFileName), "The specified exe file does not exist: " + exeFileName); Debug.Assert(File.Exists(propertiesFileName), "The specified properties file does not exist: " + propertiesFileName); IgnoreSonarScannerHome(logger); IEnumerable<string> allCmdLineArgs = GetAllCmdLineArgs(propertiesFileName, userCmdLineArguments, config); IDictionary<string, string> envVarsDictionary = GetAdditionalEnvVariables(logger); Debug.Assert(envVarsDictionary != null); logger.LogInfo(Resources.MSG_SonarScannerCalling); Debug.Assert(!String.IsNullOrWhiteSpace(config.SonarRunnerWorkingDirectory), "The working dir should have been set in the analysis config"); Debug.Assert(Directory.Exists(config.SonarRunnerWorkingDirectory), "The working dir should exist"); ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(exeFileName, logger) { CmdLineArgs = allCmdLineArgs, WorkingDirectory = config.SonarRunnerWorkingDirectory, EnvironmentVariables = envVarsDictionary }; ProcessRunner runner = new ProcessRunner(); // SONARMSBRU-202 Note that the Sonar Scanner may write warnings to stderr so // we should only rely on the exit code when deciding if it ran successfully bool success = runner.Execute(runnerArgs); if (success) { logger.LogInfo(Resources.MSG_SonarScannerCompleted); } else { logger.LogError(Resources.ERR_SonarScannerExecutionFailed); } return success; }
private void InternalDownloadReport(string tfsUri, string reportUrl, string reportDestinationPath, ILogger logger) { VssHttpMessageHandler vssHttpMessageHandler = GetHttpHandler(tfsUri, logger); logger.LogInfo(Resources.DOWN_DIAG_DownloadCoverageReportFromTo, reportUrl, reportDestinationPath); using (HttpClient httpClient = new HttpClient(vssHttpMessageHandler)) using (HttpResponseMessage response = httpClient.GetAsync(reportUrl).Result) { if (response.IsSuccessStatusCode) { using (FileStream fileStream = new FileStream(reportDestinationPath, FileMode.Create, FileAccess.Write)) { response.Content.CopyToAsync(fileStream).Wait(); } } else { logger.LogError(Resources.PROC_ERROR_FailedToDownloadReportReason, reportUrl, response.StatusCode, response.ReasonPhrase); } } }
/// <summary> /// Compiles the supplied code into a new assembly /// </summary> private static Assembly CompileAssembly(string code, string outputFilePath, ILogger logger) { CSharpCodeProvider provider = new CSharpCodeProvider(); CompilerParameters options = new CompilerParameters(); options.OutputAssembly = outputFilePath; options.GenerateExecutable = true; options.GenerateInMemory = false; CompilerResults result = provider.CompileAssemblyFromSource(options, code); if (result.Errors.Count > 0) { foreach (string item in result.Output) { logger.LogInfo(item); } Assert.Fail("Test setup error: failed to create dynamic assembly. See the test output for compiler output"); } return result.CompiledAssembly; }
protected override bool TryGetBinaryReportFile(AnalysisConfig config, TeamBuildSettings settings, ILogger logger, out string binaryFilePath) { IEnumerable<string> urls = this.urlProvider.GetCodeCoverageReportUrls(config.GetTfsUri(), config.GetBuildUri(), logger); Debug.Assert(urls != null, "Not expecting the returned list of urls to be null"); bool continueProcessing = true; binaryFilePath = null; switch (urls.Count()) { case 0: logger.LogInfo(Resources.PROC_DIAG_NoCodeCoverageReportsFound); break; case 1: string url = urls.First(); string targetFileName = Path.Combine(config.SonarOutputDir, DownloadFileName); bool result = this.downloader.DownloadReport(config.GetTfsUri(), url, targetFileName, logger); if (result) { binaryFilePath = targetFileName; } else { continueProcessing = false; logger.LogError(Resources.PROC_ERROR_FailedToDownloadReport); } break; default: // More than one continueProcessing = false; logger.LogError(Resources.PROC_ERROR_MultipleCodeCoverageReportsFound); break; } return continueProcessing; }
private VssHttpMessageHandler GetHttpHandler(string tfsUri, ILogger logger) { VssCredentials vssCreds = null; Uri tfsCollectionUri = new Uri(tfsUri); using (TfsTeamProjectCollection collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsCollectionUri)) { // Build agents run non-attended and most often non-interactive so make sure not to create a credential prompt collection.ClientCredentials.AllowInteractive = false; collection.EnsureAuthenticated(); logger.LogInfo(Resources.DOWN_DIAG_ConnectedToTFS, tfsUri); // We need VSS credentials that encapsulate all types of credentials (NetworkCredentials for TFS, OAuth for VSO) TfsConnection connection = collection as TfsConnection; vssCreds = connection.ClientCredentials.ConvertToVssCredentials(tfsCollectionUri); } Debug.Assert(vssCreds != null, "Not expecting ConvertToVssCredentials "); VssHttpMessageHandler vssHttpMessageHandler = new VssHttpMessageHandler(vssCreds, new VssHttpRequestSettings()); return vssHttpMessageHandler; }
/// <summary> /// Start the service /// </summary> /// <remarks>This service is not receiving any arguments at the moment</remarks> /// <param name="args">Arguments to receive when starting the service</param> protected override void OnStart(string[] args) { log4net.Config.XmlConfigurator.Configure(); log = LogFactory.GetLogger(typeof(Service)); log.LogInfo("Service Started."); try { //get service credential details if (!string.IsNullOrEmpty(serviceUserName)) { //Check what is the user for this service. If the user doesn't exist then it should create it. MembershipUser membershipUser = Membership.GetUser(serviceUserName); if (membershipUser == null) { //Could not acquire user. log.LogFatal("Eagle Service cannot acquire user to execute tasks and it is going to stop."); return; } //Add the identity and principal of our internal service user to the current principal Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(membershipUser.ProviderUserKey.ToString()), null); ServiceTaskManager.Initialize(); } else { //Could not acquire user. log.LogFatal("Eagle Service cannot acquire user to execute tasks and it is going to stop."); } } catch (Exception e) { log.LogError("Error on service start", ex: e); } }
/// <summary> /// Get the value of the SONAR_SCANNER_OPTS variable that controls the amount of memory available to the JDK so that the sonar-runner doesn't /// hit OutOfMemory exceptions. If no env variable with this name is defined then a default value is used. /// </summary> private static string GetSonarScannerOptsValue(ILogger logger) { string existingValue = Environment.GetEnvironmentVariable(SonarScannerOptsVariableName); if (!String.IsNullOrWhiteSpace(existingValue)) { logger.LogInfo(Resources.MSG_SonarScannerOptsAlreadySet, SonarScannerOptsVariableName, existingValue); return existingValue; } else { logger.LogInfo(Resources.MSG_SonarScannerOptsDefaultUsed, SonarScannerOptsVariableName, SonarRunnerOptsDefaultValue); return SonarRunnerOptsDefaultValue; } }
public static AppConfiguration GetConfig(ILogger logger) { AppConfiguration config = new AppConfiguration { CredentialToUse = new NetworkCredential(CloudConfigurationManager.GetSetting("UserName"), CloudConfigurationManager.GetSetting("Password")), UseXml = ReadConfigValue("SendJson", "[Send Xml if 'false', otherwise Json]").ToLowerInvariant().Contains("false"), XmlTemplate = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).GetSection("MergeToXML").SectionInformation.GetRawXml(), ServiceBusConnectionString = ReadConfigValue("Microsoft.ServiceBus.ServiceBusConnectionString", "[Service Bus connection string]"), EventHubName = ReadConfigValue("Microsoft.ServiceBus.EventHubToUse", "[event hub name]"), MessageSubject = ReadConfigValue("MessageSubject", "[Message subject]"), MessageDeviceId = ReadConfigValue("MessageDeviceId", "[Message device Id]"), MessageDeviceDisplayName = ReadConfigValue("MessageDeviceDisplayName", "[Message device name]") }; if (!int.TryParse(ReadConfigValue("SleepTimeMs", "[Sleep time]"), out config.SleepTimeMs)) { logger.LogInfo("Incorrect SleepTimeMs value, using default..."); //default sleep time interval is 10 sec config.SleepTimeMs = 10000; } return config; }
private static void LogProcessingStarted(AnalysisPhase phase, ILogger logger) { string phaseLabel = phase == AnalysisPhase.PreProcessing ? Resources.PhaseLabel_PreProcessing : Resources.PhaseLabel_PostProcessing; logger.LogInfo(Resources.MSG_ProcessingStarted, phaseLabel); }
private bool FetchArgumentsAndRulesets(ProcessedArgs args, string configDir, ILogger logger, out IDictionary<string, string> serverSettings) { string hostUrl = args.GetSetting(SonarProperties.HostUrl); serverSettings = null; ISonarQubeServer server = this.serverFactory.Create(args); try { // Fetch the SonarQube project properties logger.LogInfo(Resources.MSG_FetchingAnalysisConfiguration); serverSettings = server.GetProperties(args.ProjectKey, logger); // Generate the FxCop rulesets logger.LogInfo(Resources.MSG_GeneratingRulesets); GenerateFxCopRuleset(server, args.ProjectKey, "csharp", "cs", "fxcop", Path.Combine(configDir, FxCopCSharpRuleset), logger); GenerateFxCopRuleset(server, args.ProjectKey, "vbnet", "vbnet", "fxcop-vbnet", Path.Combine(configDir, FxCopVBNetRuleset), logger); } catch (WebException ex) { if (Utilities.HandleHostUrlWebException(ex, hostUrl, logger)) { return false; } throw; } finally { Utilities.SafeDispose(server); } return true; }
private static ProjectInfoValidity ClassifyProject(ProjectInfo projectInfo, IEnumerable<ProjectInfo> projects, ILogger logger) { if (projectInfo.IsExcluded) { logger.LogInfo(Resources.MSG_ProjectIsExcluded, projectInfo.FullPath); return ProjectInfoValidity.ExcludeFlagSet; } if (!IsProjectGuidValue(projectInfo)) { logger.LogWarning(Resources.WARN_InvalidProjectGuid, projectInfo.ProjectGuid, projectInfo.FullPath); return ProjectInfoValidity.InvalidGuid; } if (HasDuplicateGuid(projectInfo, projects)) { logger.LogWarning(Resources.WARN_DuplicateProjectGuid, projectInfo.ProjectGuid, projectInfo.FullPath); return ProjectInfoValidity.DuplicateGuid; } return ProjectInfoValidity.Valid; }
public Scanner(ILogger logger) { _logger = logger; _waitEvents = new HybridDictionary(); _recevedEvents = new HybridDictionary(); _events = new Queue(); _mre = new ManualResetEvent(false); _validPageLengths = new ValidPageLength[MAX_SHEET_FORMATS]; _validPageOffsets = new ValidPageOffset[MAX_SHEET_FORMATS]; _sheetScanning = false; _scannerBusy = false; foreach (HardwareConfiguration t in s_ports) { _currentConfiguration = t; Socket udpSocketSend = null; Socket udpSocketReceive = null; Socket tcpSocket = null; try { udpSocketSend = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Unspecified); udpSocketReceive = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Unspecified); udpSocketReceive.Bind(new IPEndPoint(System.Net.IPAddress.Any, _currentConfiguration.UdpPortReceive)); byte[] data = { 1, 0, 0, 0 }; var um = new UserMessage(Command.umConnect, data); EndPoint ep = new IPEndPoint(LOCAL_HOST, _currentConfiguration.UdpPortSend); udpSocketSend.SendTo(um.Buffer, ep); if (!udpSocketReceive.Poll(TIMEOUT, SelectMode.SelectRead)) { continue; } data = new byte[1024]; udpSocketReceive.ReceiveFrom(data, ref ep); um = new UserMessage(data); if (um.Command != Command.umConnect) { throw new Exception("ScannerWantNotConnect"); } var cc = new UmConnectConfirmation(um.Data); if (cc.Answer != 1) { throw new Exception("ScannerWantNotConnect"); } _status = cc.Status; tcpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Unspecified); tcpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); ep = new IPEndPoint(System.Net.IPAddress.Any, _currentConfiguration.TcpPport); tcpSocket.Bind(ep); tcpSocket.Listen(1); ScannerSocket.SetBuffers(tcpSocket); _scannerSocket = new ScannerSocket(tcpSocket.Accept()); udpSocketSend.Close(); udpSocketReceive.Close(); tcpSocket.Close(); _workThread = new Thread(Work); _workThread.Start(); _sendEventsThread = new Thread(SendEvents); _sendEventsThread.Start(); um = SendAndWaitAnswer(Command.umGetVersion); DriverVersion = (new Versions(um.Data)).Driver; switch (_currentConfiguration.ScannerVersion) { case ScannerVersion.V2003: _sh = new SIB2003.SharedMemory(); break; case ScannerVersion.V2005: _sh = new SIB2005.SharedMemory(); break; case ScannerVersion.V2009: _sh = new SIB2009.SharedMemory(); break; case ScannerVersion.V2010: _sh = new SIB2010.SharedMemory(); break; } _x = new short[NUMBER_OF_SIDES]; _x[0] = _x[1] = 0; _y = new short[NUMBER_OF_SIDES]; _y[0] = _y[1] = 0; ScanningEnabled = false; ReloadProperties(); ReloadManufProps(); ReloadWhiteCoeffs(); logger.LogInfo(Message.ScannerManagerDetectedHardware, _currentConfiguration.ScannerVersion, _currentConfiguration.MaxLines, _currentConfiguration.DotsOneLine, _currentConfiguration.DotsOneSide, _currentConfiguration.SizeofBinaryBuffer, _currentConfiguration.SizeofHalftoneBuffer); break; } finally { if (udpSocketSend != null) udpSocketSend.Close(); if (udpSocketReceive != null) udpSocketReceive.Close(); if (tcpSocket != null) tcpSocket.Close(); } } if (_scannerSocket == null) { throw new Exception("не дождались соединения со сканером"); } }
public string LoadAndFixFile(string sarifFilePath, ILogger logger) { if (!File.Exists(sarifFilePath)) { // file cannot be found -> inherently unfixable logger.LogInfo(Resources.MSG_SarifFileNotFound, sarifFilePath); return null; } string inputSarifFileString = File.ReadAllText(sarifFilePath); if (IsValidJson(inputSarifFileString)) { // valid input -> no fix required logger.LogDebug(Resources.MSG_SarifFileIsValid, sarifFilePath); return sarifFilePath; } logger.LogDebug(Resources.MSG_SarifFileIsInvalid, sarifFilePath); if (!IsSarifFromRoslynV1(inputSarifFileString)) { // invalid input NOT from Roslyn V1 -> unfixable logger.LogWarning(Resources.WARN_SarifFixFail); return null; } string changedSarif = ApplyFixToSarif(inputSarifFileString); if (!IsValidJson(changedSarif)) { // output invalid -> unfixable logger.LogWarning(Resources.WARN_SarifFixFail); return null; } else { //output valid -> write to new file and return new path string writeDir = Path.GetDirectoryName(sarifFilePath); string newSarifFileName = Path.GetFileNameWithoutExtension(sarifFilePath) + FixedFileSuffix + Path.GetExtension(sarifFilePath); string newSarifFilePath = Path.Combine(writeDir, newSarifFileName); File.WriteAllText(newSarifFilePath, changedSarif); logger.LogInfo(Resources.MSG_SarifFixSuccess, newSarifFilePath); return newSarifFilePath; } }
internal DiaResolver(string binary, string pathExtension, ILogger logger, bool debugMode) { _binary = binary; _logger = logger; _debugMode = debugMode; string pdb = FindPdbFile(binary, pathExtension); if (pdb == null) { _logger.LogWarning($"Couldn't find the .pdb file of file '{binary}'. You will not get any source locations for your tests."); return; } if (!TryCreateDiaInstance(Dia140) && !TryCreateDiaInstance(Dia120) && !TryCreateDiaInstance(Dia110)) { _logger.LogError("Couldn't find the msdia.dll to parse *.pdb files. You will not get any source locations for your tests."); return; } if (_debugMode) _logger.LogInfo($"Parsing pdb file \"{pdb}\""); _fileStream = File.Open(pdb, FileMode.Open, FileAccess.Read, FileShare.Read); _diaDataSource.loadDataFromIStream(new DiaMemoryStream(_fileStream)); dynamic diaSession110Or140; _diaDataSource.openSession(out diaSession110Or140); _diaSession = new DiaSessionAdapter(diaSession110Or140); }
private static string FindTrxFile(string buildRootDirectory, ILogger logger) { Debug.Assert(!string.IsNullOrEmpty(buildRootDirectory)); Debug.Assert(Directory.Exists(buildRootDirectory), "The specified build root directory should exist: " + buildRootDirectory); logger.LogInfo(Resources.TRX_DIAG_LocatingTrx); string trxFilePath = null; string testResultsPath = Path.Combine(buildRootDirectory, TestResultsFolderName); if (Directory.Exists(testResultsPath)) { string[] trxFiles = Directory.GetFiles(testResultsPath, "*.trx"); switch (trxFiles.Length) { case 0: logger.LogInfo(Resources.TRX_DIAG_NoTestResultsFound); break; case 1: trxFilePath = trxFiles[0]; logger.LogInfo(Resources.TRX_DIAG_SingleTrxFileFound, trxFilePath); break; default: logger.LogWarning(Resources.TRX_WARN_MultipleTrxFilesFound, string.Join(", ", trxFiles)); break; } } else { logger.LogInfo(Resources.TRX_DIAG_TestResultsDirectoryNotFound, testResultsPath); } return trxFilePath; }
//--// public DeviceAdapterLoader( IList<String> sources, IList<SensorEndpoint> endpoints, ILogger logger ) { _logger = SafeLogger.FromLogger( logger ); #if DEBUG_LOG _logger.LogInfo( "Starting loading Data Intakes" ); #endif _dataIntakes = new List<DeviceAdapterAbstract>( ); if( endpoints != null ) { foreach( SensorEndpoint endpoint in endpoints ) { _SensorEndpoints.Add( endpoint ); } } #if DEBUG_LOG else { _logger.LogInfo( "No list of SensorEndpoints in configuration file, continuing..." ); } #endif // // enumerate all types with a IDeviceAdapter interface look in the current directory, in the // running assembly directory and in the entry and executing assembly // var directories = new List<String>( ); directories.Add( Directory.GetCurrentDirectory( ) ); var di1 = Path.GetDirectoryName( Assembly.GetEntryAssembly( ).Location ); var di2 = Path.GetDirectoryName( Assembly.GetCallingAssembly( ).Location ); var di3 = Path.GetDirectoryName( Assembly.GetExecutingAssembly( ).Location ); // do not duplicate search paths if( !directories.Contains( di1 ) ) { directories.Add( di1 ); } if( !directories.Contains( di2 ) ) { directories.Add( di2 ); } if( !directories.Contains( di3 ) ) { directories.Add( di3 ); } //for each filename will store a flag - whether it was specified at config or not Dictionary<String, bool> sourcesToLoad = new Dictionary<string, bool>( ); if( sources != null && sources.Any( ) ) { foreach( var filename in sources ) { sourcesToLoad.Add( filename, true ); } } else { #if DEBUG_LOG _logger.LogInfo( "No list of DeviceAdapters in configuration file, continuing..." ); #endif foreach( string directory in directories ) { //Dinar: dont want to try all windows/system32 directory for now if( !directory.ToLowerInvariant( ).Contains( "system32" ) ) { foreach( string filename in Directory.GetFiles( directory ) ) { //false flag - file was not specified at config sourcesToLoad.Add( filename, false ); } } } } // try and load assemblies from path var nameTypeDict = new Dictionary<string, Type>( ); string notLoadedSpecifiedSources = ""; string notLoadedNotSpecifiedSources = ""; foreach( KeyValuePair<string, bool> source in sourcesToLoad ) { string fileName = source.Key; try { Assembly assm = null; // try path from config first if( File.Exists( fileName ) ) { assm = Assembly.LoadFrom( fileName ); // remember this directory as a potential source var lastDir = Path.GetDirectoryName( fileName ); if( !directories.Contains( lastDir ) ) { directories.Add( lastDir ); } } else { // try the other directories foreach( var d in directories ) { var assmName = Path.GetFileName( fileName ); // try again string assmPath = Path.Combine( d, assmName ); if( File.Exists( assmPath ) ) { assm = Assembly.LoadFrom( assmPath ); } } if( assm == null ) { // Log that we did not load our data sources correctly if( source.Value ) { notLoadedSpecifiedSources += fileName; } else { notLoadedNotSpecifiedSources += fileName; } notLoadedSpecifiedSources += "; "; continue; } } Debug.Assert( assm != null ); foreach( Type t in assm.GetExportedTypes( ) ) { //Get all classes that implement the required interface if( t.GetInterface( "IDeviceAdapter", false ) != null ) { #if DEBUG_LOG _logger.LogInfo( "IDeviceAdapter assembly loaded: " + t.Name ); #endif nameTypeDict.Add( t.Name, t ); //Add to Dictonary } } } catch( Exception ) { //dont want to stop loading another modules if one fails if( source.Value ) { notLoadedSpecifiedSources += fileName; } else { notLoadedNotSpecifiedSources += fileName; } notLoadedNotSpecifiedSources += "; "; } } if( notLoadedSpecifiedSources.Length > 0 ) { _logger.LogError( String.Format( "Following Data Intakes were specificied, but could not be loaded: {0}", notLoadedSpecifiedSources ) ); } if( notLoadedNotSpecifiedSources.Length > 0 ) { _logger.LogError( String.Format( "Following files are not specificied, and could not be loaded as Data Intakes: {0}", notLoadedNotSpecifiedSources ) ); } foreach( KeyValuePair<string, Type> t in nameTypeDict ) { try { DeviceAdapterAbstract di = ( DeviceAdapterAbstract )Activator.CreateInstance( t.Value, new object[] { _logger } ); if( di != null ) { #if DEBUG_LOG _logger.LogInfo( "IDeviceAdapter instance created: " + t.Key ); #endif //adding instance without endpoint if acceptable if( di.SetEndpoint( ) ) { _dataIntakes.Add( di ); } foreach( SensorEndpoint sensorEndpoint in _SensorEndpoints ) { DeviceAdapterAbstract diWithEndpoint = ( DeviceAdapterAbstract )Activator.CreateInstance( t.Value, new object[] { _logger } ); if( diWithEndpoint.SetEndpoint( sensorEndpoint ) ) { _dataIntakes.Add( diWithEndpoint ); } } } } catch( Exception ex ) { // dont want to stop creating another instances if one fails _logger.LogError( String.Format( "Exception on Creating DeviceAdapter Instance \"{0}\": {1}", t.Key, ex.Message ) ); } } }
/// <summary> /// Compiles the supplied code into a new assembly /// </summary> private static Assembly CompileAssembly(string code, string outputFilePath, string asmVersion, ILogger logger) { string versionedCode = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"[assembly:System.Reflection.AssemblyVersionAttribute(""{0}"")] {1}", asmVersion, code); CompilerResults result = null; using (CSharpCodeProvider provider = new CSharpCodeProvider()) { CompilerParameters options = new CompilerParameters(); options.OutputAssembly = outputFilePath; options.GenerateExecutable = true; options.GenerateInMemory = false; result = provider.CompileAssemblyFromSource(options, versionedCode); if (result.Errors.Count > 0) { foreach (string item in result.Output) { logger.LogInfo(item); } Assert.Fail("Test setup error: failed to create dynamic assembly. See the test output for compiler output"); } } return result.CompiledAssembly; }
private static void InternalExecute(AnalysisConfig config, IEnumerable<string> userCmdLineArguments, ILogger logger, ProjectInfoAnalysisResult result) { ProjectInfoReportBuilder.WriteSummaryReport(config, result, logger); if (result.FullPropertiesFilePath == null) { // We expect a detailed error message to have been logged explaining // why the properties file generation could not be performed logger.LogInfo(Resources.MSG_PropertiesGenerationFailed); } else { string exeFileName = FindRunnerExe(config, logger); if (exeFileName != null) { result.RanToCompletion = ExecuteJavaRunner(config, userCmdLineArguments, logger, exeFileName, result.FullPropertiesFilePath); } } }
private static void IgnoreSonarScannerHome(ILogger logger) { if (!String.IsNullOrWhiteSpace( Environment.GetEnvironmentVariable(SonarScannerHomeVariableName))) { logger.LogInfo(Resources.MSG_SonarScannerHomeIsSet); Environment.SetEnvironmentVariable(SonarScannerHomeVariableName, String.Empty); } }
public ProjectInfoAnalysisResult Execute(AnalysisConfig config, IEnumerable<string> userCmdLineArguments, ILogger logger) { if (config == null) { throw new ArgumentNullException("config"); } if (userCmdLineArguments == null) { throw new ArgumentNullException("cmdLineArguments"); } if (logger == null) { throw new ArgumentNullException("logger"); } ProjectInfoAnalysisResult result = PropertiesFileGenerator.GenerateFile(config, logger); Debug.Assert(result != null, "Not expecting the file generator to return null"); ProjectInfoReportBuilder.WriteSummaryReport(config, result, logger); result.RanToCompletion = false; if (result.FullPropertiesFilePath == null) { // We expect a detailed error message to have been logged explaining // why the properties file generation could not be performed logger.LogInfo(Resources.MSG_PropertiesGenerationFailed); } else { string exeFileName = FindRunnerExe(config, logger); if (exeFileName != null) { result.RanToCompletion = ExecuteJavaRunner(config, userCmdLineArguments, logger, exeFileName, result.FullPropertiesFilePath); } } return result; }
/// <summary> /// Order specified types by their dependencies. /// </summary> public static IEnumerable<SingletonDef> OrderByDeps(IEnumerable<SingletonDef> singletonDefs, IFactory factory, ILogger logger) { Argument.NotNull(() => singletonDefs); Argument.NotNull(() => factory); logger.LogInfo("Ordering singletons:"); singletonDefs .SelectMany(singletonDef => { return singletonDef.dependencyNames .Select(dependencyName => new { Type = singletonDef, DependencyName = dependencyName }); }) .GroupBy(singletonDef => singletonDef.DependencyName) .Each(singletonGroup => { if (singletonGroup.Count() > 1) { logger.LogError("Multiple singletons defined as the dependency " + singletonGroup.Key); singletonGroup.Each(singletonDef => { logger.LogInfo(singletonDef.Type.singletonType.Name + " defined as dependency " + singletonDef.DependencyName + "( from DLL " + singletonDef.Type.singletonType.Assembly.FullName + ")"); }); } }); var dependencyMap = singletonDefs .SelectMany(singletonDef => { return singletonDef.dependencyNames .Select(dependencyName => new { Type = singletonDef, DependencyName = dependencyName }); }) .ToDictionary(i => i.DependencyName, i => i.Type); var defsRemaining = new Queue<SingletonDef>(singletonDefs); var dependenciesSatisfied = new HashSet<string>(); var output = new List<SingletonDef>(); var defsAlreadySeen = new Dictionary<SingletonDef, int>(); var maxTypesSeen = 5; while (defsRemaining.Count > 0) { var singletonDef = defsRemaining.Dequeue(); // Get the names of all types that this singleton is dependent on. var singletonDependsOn = DetermineDeps(singletonDef.singletonType, factory, new string[0]).ToArray(); var allDepsSatisfied = singletonDependsOn .Where(dependencyName => dependencyMap.ContainsKey(dependencyName)) // Only care about dependencies that are satisifed by other singletons. .All(dependencyName => dependenciesSatisfied.Contains(dependencyName)); // Have we seen all other singletons yet that this singleton is dependent on? if (allDepsSatisfied) { output.Add(singletonDef); logger.LogInfo("\t" + singletonDef.singletonType.Name); logger.LogInfo("\t\tImplements: " + singletonDef.dependencyNames.Join(", ")); logger.LogInfo("\t\tDepends on:"); singletonDependsOn.Each(dependencyName => logger.LogInfo("\t\t\t" + dependencyName)); logger.LogInfo("\t\tDepends on (singletons):"); singletonDependsOn .Where(dependencyName => dependencyMap.ContainsKey(dependencyName)) .Each(dependencyName => logger.LogInfo("\t\t\t" + dependencyName + (dependenciesSatisfied.Contains(dependencyName) ? " (satisfied)" : " (unsatisified)"))); singletonDef.dependencyNames.Each(dependencyName => dependenciesSatisfied.Add(dependencyName)); } else { int timesSeen; if (defsAlreadySeen.TryGetValue(singletonDef, out timesSeen)) { if (timesSeen >= maxTypesSeen) { throw new ApplicationException("Already seen type: " + singletonDef.singletonType.Name + ", it is possible there is a circular dependency between types or it might be that a dependency can't be satisfied."); } // Increment the number of times we have seen this type. ++defsAlreadySeen[singletonDef]; } else { // Record the types we have already attempted to process to make sure we are not // iterating forever on a circular dependency. defsAlreadySeen[singletonDef] = 1; } defsRemaining.Enqueue(singletonDef); } } return output.ToArray(); }
public static void LogAssemblyVersion(ILogger logger, System.Reflection.Assembly assembly, string description) { if (logger == null) { throw new ArgumentNullException("logger"); } if (assembly == null) { throw new ArgumentNullException("assembly"); } if (string.IsNullOrWhiteSpace(description)) { throw new ArgumentNullException("description"); } logger.LogInfo("{0} {1}", description, assembly.GetName().Version); }