public static void AddLocalServerInfo(this IDiagnostics diagnostics, IHostEnvironment environment = null, DbContext dbContext = null) { var hostName = Dns.GetHostName(); var thisAssembly = Assembly.GetEntryAssembly(); var assemblyName = thisAssembly.GetName(); var versionAttribute = thisAssembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>(); if (environment != null) { diagnostics.Environment = environment.EnvironmentName; } if (dbContext != null) { diagnostics.Database = dbContext.GetServerName() + "." + dbContext.GetDatabaseName(); } diagnostics.HostName = hostName; diagnostics.ServerName = Environment.MachineName; diagnostics.Version = $"{ assemblyName.Name } v{ versionAttribute.InformationalVersion }"; diagnostics.MemoryUsageForCurrentProcess = SystemInfo.MemoryUsageForCurrentProcess; diagnostics.CpuUsageForCurrentProcess = SystemInfo.CpuUsageForCurrentProcess; diagnostics.IpConnectionsForCurrentProcess = SystemInfo.IPConnectionsForCurrentProcess; diagnostics.MaximumCpuUsageForCurrentProcess = SystemInfo.MaximumCpuUsageForCurrentProcess; diagnostics.MaximumMemoryUsageForCurrentProcess = SystemInfo.MaximumMemoryUsageForCurrentProcess; diagnostics.MaximumIpConnectionsForCurrentProcess = SystemInfo.MaximumIPConnectionsForCurrentProcess; diagnostics.NetworkUtilization = SystemInfo.NetworkUtilization; diagnostics.SystemUpTime = SystemInfo.SystemUpTime; diagnostics.ProcessStartTime = Process.GetCurrentProcess().StartTime.ToUniversalTime(); }
private EventManifestCompilation(IDiagnostics diags, CompilationOptions opts) { this.diags = diags ?? throw new ArgumentNullException(nameof(diags)); this.opts = opts ?? throw new ArgumentNullException(nameof(opts)); msgIdGenFactory = () => new StableMessageIdGenerator(diags); }
public void AddModelACatchments(AmeliaBridge bridge, Mike1DData mike1DData, IDiagnostics diagnostics) { // Load all msm_Catchment rows, and load also User Defined Columnes (attachUserDefinedFields: true). Sort them by Muid. IEnumerable <msm_Catchment> catchments = bridge.DataSource.GetAllRows <msm_Catchment>(attachUserDefinedFields: true); catchments = catchments.OrderBy(catchment => catchment.Muid, StringComparer.OrdinalIgnoreCase); // Get a DataFactoryRainfallRunoff, which is required for easing the definition of catchments. DataFactoryRainfallRunoff rrDataFactory = bridge.CreateRainfallDataFactory(); foreach (msm_Catchment msmCatchment in catchments) { object val; // Check if this catchment has "ModelAParameterSet" defined if (msmCatchment.UserDefinedFieldsData.TryGetValue("ModelAParameterSet", out val)) { // Convert val to string and also load the impervious fraction string modelAParId = (string)val; double impervFraction = (double)msmCatchment.UserDefinedFieldsData["ImpervFraction"]; // Retrieve Model A parameter set matching "ModelAParameterSet" column value. msm_HParA catchmentParameters = bridge.DataSource.Get <msm_HParA>(modelAParId); // Create a Model A catchment ICatchmentTimeAreaData cta = rrDataFactory.PopulateRunoffA(msmCatchment, catchmentParameters, impervFraction * msmCatchment.Area.GetValueOrDefault()); // Give the catchment a new name, so it does not collide with the original catchment model. cta.ModelId += "-Imperv"; // Add the new Model A catchment to MIKE 1D. mike1DData.RainfallRunoffData.Catchments.Add((ICatchment)cta); } } }
public async Task Init(CancellationTokenSource cts) { if (initialized == true) { return; } AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; diagnostics = CreateDiagnostics(cts); var installation = Installations.Value.First(i => i.ApplicationPath == InstancePath); var hive = new VsHive(installation, Settings.VsRootSuffix); await VsInstance.Prepare(hive, Settings.GetExtensionsToInstall(), Settings.VsResetSettings, diagnostics); instance = await VsInstance.Launch(hive, Settings.GetLaunchTimeout(), diagnostics); if (Debugger.IsAttached) { await VsInstance.AttachDebugger(instance.Process, Settings.VsDebugMixedMode, diagnostics); } instance.SetAssemblyResolver(TestAssemblyDirectory); rmt = instance.GetOrCreateSingletonService <Rmt>("VsixTesting.Xunit", Settings.VsSecureChannel); remoteTestAssemblyRunner = CreateRemoteTestAssemblyRunner(cts); initialized = true; }
public Driver(Options options, IDiagnostics diagnostics = null) { Options = options; Diagnostics = diagnostics; if (Diagnostics == null) { Diagnostics = new TextDiagnosticPrinter(); } if (Options.OutputDir == null) { Options.OutputDir = Directory.GetCurrentDirectory(); } Assemblies = new List <IKVM.Reflection.Assembly>(); Context = new BindingContext(Diagnostics, new DriverOptions()); Context.ASTContext = new ASTContext(); Declaration.QualifiedNameSeparator = "_"; CppSharp.AST.Type.TypePrinterDelegate = type => { var typePrinter = new CppTypePrinter(); return(type.Visit(typePrinter)); }; }
public static Task <VsInstance> Launch(VsHive hive, TimeSpan timeout, IDiagnostics diagnostics) { Process process = null; KillProcessJob killProcessJob = null; return(diagnostics.RunAsync("Launching Instance", async output => { try { process = VisualStudioUtil.StartProcess(hive); killProcessJob = new KillProcessJob(process); var dte = await VisualStudioUtil.GetDTE(process, timeout); var invoker = (IRemoteComInvoker)dte.GetObject("VsixTesting.Invoker"); InvokeRemote(invoker, nameof(Remote.AutoKillWhenProcessExits), Process.GetCurrentProcess().Id); killProcessJob.Release(); return new VsInstance(hive.Version, process, dte, invoker); } catch { process?.Kill(); process?.Dispose(); throw; } })); }
public void SetStateInitialConditions(Mike1DData mike1DData, IDiagnostics diagnostics) { // State file name template IFilePath stateFilePath = mike1DData.Connection.FilePath.Clone(); stateFilePath.Extension = ".sta1d"; stateFilePath.FileNameWithoutExtension += "-{0}"; // DateTime of state to use. Here using mike1DData.SimulationStart; DateTime startTime = mike1DData.SimulationStart; stateFilePath.Path = string.Format(stateFilePath.Path, startTime.ToString("yyyyMMddTHHmmss")); // If state file exists, use it if (System.IO.File.Exists(stateFilePath.FullFilePath)) { StatestartInfo statestartInfo = new StatestartInfo(stateFilePath); mike1DData.StatestartInfos.Add(statestartInfo); diagnostics.Info("Using state file: " + stateFilePath.Path); } else { diagnostics.Info("Could not find any state file named: " + stateFilePath.Path); } }
public async Task Init(CancellationTokenSource cts) { if (initialized == true) { return; } AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; diagnostics = CreateDiagnostics(cts); if (testCases.OfType <VsTestCase>().GroupBy(c => c.Settings.SecureChannel).Count() >= 2) { throw new Exception($"All test methods sharing the same Visual Studio Instance must also use the same value for {nameof(ITestSettings.SecureChannel)}."); } var installation = Installations.Value.First(i => i.ApplicationPath == InstancePath); var hive = new VsHive(installation, Settings.RootSuffix); await VsInstance.Prepare(hive, GetExtensionsToInstall(), Settings.ResetSettings, diagnostics); instance = await VsInstance.Launch(hive, Settings.GetLaunchTimeout(), diagnostics); if (Debugger.IsAttached) { await VsInstance.AttachDebugger(instance.Process, Settings.DebugMixedMode, diagnostics); } instance.SetAssemblyResolver(TestAssemblyDirectory); rmt = instance.GetOrCreateSingletonService <Rmt>("VsixTesting.Xunit", Settings.SecureChannel); remoteTestAssemblyRunner = CreateRemoteTestAssemblyRunner(cts); initialized = true; }
private DataType ResolveDataType(DataType type, IDiagnostics diagnostics) { switch (type) { case UnresolvedType unresolvedType: if (!this.dataTypes.ContainsKey(unresolvedType.Type)) { var diag = new Diagnostic( DiagnosticStatus.Error, TypeIdentifierErrorDiagnosticsType, $"Unexpected type identifier: '{unresolvedType.Type}'", new List <Range> { unresolvedType.InputRange }); diagnostics.Add(diag); throw new NameResolverException($"unexpected type identifier: {unresolvedType.Type}"); } return(this.dataTypes[unresolvedType.Type]); case UnresolvedArrayType unresolvedArray: var childDataType = this.ResolveDataType(unresolvedArray.Child, diagnostics); return(new ArrayType(childDataType)); case UnresolvedFunctionType unresolved: return(new FunType( argTypes: unresolved.ArgTypes.Select(x => this.ResolveDataType(x, diagnostics)).ToList(), resultType: this.ResolveDataType(unresolved.ResultType, diagnostics))); } return(type); }
public void Write(IEnumerable <Message> messages, IDiagnostics diags) { var uniqueMessages = new List <Message>(); var messageIds = new HashSet <uint>(); foreach (var message in messages.Where(m => m.IsUsed)) { if (messageIds.Contains(message.Id)) { diags.ReportError( "Message '{0}' has duplicate id 0x{1:X}.", message.Name, message.Id); continue; } messageIds.Add(message.Id); uniqueMessages.Add(message); } uniqueMessages.StableSortBy(m => m.Id); var blocks = BuildBlocks(uniqueMessages); WriteResourceData(blocks, uniqueMessages); }
private void ProcessVariableDeclaration(VariableDeclaration var, IDiagnostics diagnostics) { string id = var.Identifier; var.VariableType = this.ResolveDataType(var.VariableType, diagnostics); if (this.variableBlocks.Peek().Contains(id)) { var diagnostic = new Diagnostic( DiagnosticStatus.Error, MultipleDeclarationsDiagnostic, $"Multiple declarations of variable name {id}", new List <Range> { var.InputRange }); diagnostics.Add(diagnostic); this.exceptions.Add(new NameResolverInternalException($"Multiple declarations of name {id}")); } if (!this.variables.ContainsKey(id)) { this.variables.Add(id, new Stack <VariableDeclaration>()); } this.variables[id].Push(var); this.variableBlocks.Peek().Add(id); }
public Driver(DriverOptions options, IDiagnostics diagnostics) { Options = options; Diagnostics = diagnostics; Project = new Project(); ParserOptions = new ParserOptions(); }
public PropertyGenerator(Class @class, IDiagnostics diags) { Diagnostics = diags; foreach (var method in @class.Methods.Where( m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator && m.IsGenerated)) DistributeMethod(method); }
/// <summary> /// Using the MIKE 1D controller to run a simulation /// <para> /// The controller gives more control of the simulation. /// It also pushes the responsibility of error reporting and /// summary information to the user. /// </para> /// </summary> /// <param name="setupFilepath">Path to setup file (.sim11, .mdb or .m1dx)</param> public static void ControllerRun(string setupFilepath) { // The controller factory Mike1DControllerFactory controllerFactory = new Mike1DControllerFactory(); IMike1DController controller = null; // Try-catch to catch any unexpected exception or runtime exceptions. try { // Diagnostics object receiving errors, warning and hints during // load and initialize. Diagnostics diagnostics = new Diagnostics("My Diagnostics"); // creates a new Mike 1D controller and load the setup controller = controllerFactory.OpenAndCreate(Connection.Create(setupFilepath), diagnostics); if (diagnostics.ErrorCountRecursive > 0) { throw new Exception("Loading errors, aborting"); } // Now the MIKE 1D data is available Mike1DData mike1DData = controller.Mike1DData; // Validate setup, returns a new diagnostics object IDiagnostics validated = controller.Validate(); if (validated.ErrorCountRecursive > 0) { throw new Exception("Validation errors, aborting"); } // Initialize simulation controller.Initialize(diagnostics); if (diagnostics.ErrorCountRecursive > 0) { throw new Exception("Initialization errors, aborting"); } // Run the simulation controller.Prepare(); controller.Run(); controller.Finish(); } catch (Exception e) { // Write exception to log file if (controllerFactory.LogFileWriter != null) { controllerFactory.LogFileWriter.ExceptionToLogFile(e); } // Call Finish, which should make sure to close down properly, and release any licences. if (controller != null) { try { controller.Finish(); } catch { } } // Rethrow exception throw; } }
public DiagnosticsItemViewModel(DiagnosticsItemModel model, IDiagnostics diagnostics) : base(model) { Model.Source = SourceToString(diagnostics.Source); foreach (var result in diagnostics.GetResults()) { Model.Results.Add(result); } }
public static void ReportError <T, TProperty>( T entity, LocatedRef <TProperty> value, IDiagnostics diags, IUniqueConstraint <T> constraint) where TProperty : class { diags.ReportError(value.Location, constraint.FormatMessage(entity)); }
public StableMessageIdGenerator(IDiagnostics diags) { if (diags == null) { throw new ArgumentNullException(nameof(diags)); } this.diags = diags; }
public void Process(Node node, IDiagnostics diagnostics) { this.ProcessNode(node, diagnostics); if (this.exceptions.Any()) { throw new NameResolverException("Name resolver fail.", this.exceptions); } }
public static Task RunAsync(this IDiagnostics diagnostics, string displayName, Action action) { return(diagnostics.RunAsync(displayName, output => { action(); return Task.FromResult(0); })); }
public Node GenerateAst(ParseTree <KjuAlphabet> parseTree, IDiagnostics diagnostics) { return(new ConverterProcess( this.symbolToOperationType, this.symbolToComparisonType, this.symbolToUnaryOperationType, diagnostics) .GenerateAst(parseTree)); }
public static Node MakeAstWithReturnsChecked( string programText, IDiagnostics diagnostics) { var ast = MakeAstWithTypesResolved(programText, diagnostics); ReturnChecker.Run(ast, diagnostics); return(ast); }
public PropertyGenerator(Class @class, IDiagnostics diags) { Diagnostics = diags; foreach (var method in @class.Methods.Where( m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator && m.IsGenerated)) { DistributeMethod(method); } }
public static Node MakeAstWithLinkedNames( string programText, IDiagnostics diagnostics) { var ast = GenerateAst(programText, diagnostics); NameResolver.Run(ast, diagnostics); return(ast); }
private void ProcessStructAllocation(StructAlloc structAlloc, IDiagnostics diagnostics) { if (structAlloc.AllocType is UnresolvedType unresolvedType) { var name = unresolvedType.Type; structAlloc.AllocType = this.ResolveDataType(unresolvedType, diagnostics); structAlloc.Declaration = this.structs[name].Peek(); } }
/// <summary> /// Stops the diagnostics /// </summary> /// <param name="context">HttpContext</param> protected virtual void Stop(HttpContext context) { if (null != m_diagnostics && context.Response.ContentType == "text/html") { m_diagnostics.Stop(); context.Response.Filter = new DiagnosticsResponseFilter(context.Response.Filter, m_diagnostics.ToHtmlString()); m_diagnostics = null; } }
public bool TryAdd(T item, IDiagnostics diags) { if (!IsUnique(item, diags)) { return(false); } Add(item); return(true); }
public static void ReportError <T, TProperty>( T entity, TProperty value, IDiagnostics diags, IUniqueConstraint <T> constraint) { diags.ReportError( entity is ISourceItem sourceItem ? sourceItem.Location : new SourceLocation(), constraint.FormatMessage(entity)); }
public static void Error(this IDiagnostics consumer, string msg) { var diagInfo = new DiagnosticInfo { Kind = DiagnosticKind.Error, Message = msg }; consumer.Emit(diagInfo); }
public EventTemplateDecompiler(IDiagnostics diags, DecompilationOptions opts) { this.diags = diags ?? throw new ArgumentNullException(nameof(diags)); this.opts = opts ?? throw new ArgumentNullException(nameof(opts)); if (opts.InputModule is null && (opts.InputEventTemplate is null || opts.InputMessageTable is null)) { throw new ArgumentException("No input files", nameof(opts)); } }
public EventTemplateReader(IDiagnostics diags, IEventManifestMetadata metadata = null) { this.diags = diags ?? throw new ArgumentNullException(nameof(diags)); this.metadata = metadata; var nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("win", WinEventSchema.Namespace); nsr = nsmgr; }
public AutoEnterExitTrace(IDiagnostics wd, TraceSource ts, string class_method) { _wd = wd; _ts = ts; _class_method = class_method; if (null != wd) { wd.WriteDiagnosticInfo(ts, TraceEventType.Verbose, TraceEventID.traceFunctionEntry, string.Format("tid:{0} Entering {1}", Thread.CurrentThread.ManagedThreadId, class_method)); } }
public static void Error(this IDiagnostics consumer, string msg, params object[] args) { var diagInfo = new DiagnosticInfo { Kind = DiagnosticKind.Error, Message = string.Format(msg, args) }; consumer.Emit(diagInfo); }
/// <summary> /// Starts the diagnostics /// </summary> /// <param name="context">HttpContext</param> protected virtual void Start(HttpContext context) { if (null == m_diagnostics) { m_diagnostics = CreateDiagnostics(); if (null != m_diagnostics) { m_diagnostics.Start(); } } }
public BindingContext(IDiagnostics diagnostics, DriverOptions options, ParserOptions parserOptions = null) { Options = options; Diagnostics = diagnostics; ParserOptions = parserOptions; Symbols = new SymbolContext(); Delegates = new Dictionary<Function, DelegatesPass.DelegateDefinition>(); TypeMaps = new TypeMapDatabase(); TypeMaps.SetupTypeMaps(Options.GeneratorKind); TranslationUnitPasses = new PassBuilder<TranslationUnitPass>(this); GeneratorOutputPasses = new PassBuilder<GeneratorOutputPass>(this); }
public DeclarationName(IDiagnostics diagnostics) { this.diagnostics = diagnostics; methodSignatures = new Dictionary<string, int>(); }