internal static CompileResult CompileExpression( this EvaluationContextBase evaluationContext, string expr, DkmEvaluationFlags compilationFlags, ImmutableArray <Alias> aliases, DiagnosticFormatter formatter, out ResultProperties resultProperties, out string error, out ImmutableArray <AssemblyIdentity> missingAssemblyIdentities, CultureInfo preferredUICulture, CompilationTestData testData) { var diagnostics = DiagnosticBag.GetInstance(); var result = evaluationContext.CompileExpression(expr, compilationFlags, aliases, diagnostics, out resultProperties, testData); if (diagnostics.HasAnyErrors()) { bool useReferencedModulesOnly; error = evaluationContext.GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, EvaluationContextBase.SystemCoreIdentity, out useReferencedModulesOnly, out missingAssemblyIdentities); } else { error = null; missingAssemblyIdentities = ImmutableArray <AssemblyIdentity> .Empty; } diagnostics.Free(); return(result); }
internal static CompileResult CompileExpression( this EvaluationContextBase evaluationContext, string expr, DkmEvaluationFlags compilationFlags, ImmutableArray <Alias> aliases, out string error, CompilationTestData testData = null, DiagnosticFormatter formatter = null) { ResultProperties resultProperties; ImmutableArray <AssemblyIdentity> missingAssemblyIdentities; var result = evaluationContext.CompileExpression( expr, compilationFlags, aliases, formatter ?? DebuggerDiagnosticFormatter.Instance, out resultProperties, out error, out missingAssemblyIdentities, EnsureEnglishUICulture.PreferredOrNull, testData); Assert.Empty(missingAssemblyIdentities); return(result); }
public static bool UserGroupsContains(this EvaluationContextBase context, string group) { var retVal = context.UserGroups != null; if (retVal) { retVal = context.UserGroups.Any(x => string.Equals(x, group, StringComparison.InvariantCultureIgnoreCase)); } return(retVal); }
internal static CompileResult CompileExpression( this EvaluationContextBase context, string expr, out string error, CompilationTestData testData = null, DiagnosticFormatter formatter = null) { ResultProperties resultProperties; return(CompileExpression(context, expr, out resultProperties, out error, testData, formatter)); }
internal static CompileResult CompileExpressionWithRetry( ImmutableArray <MetadataBlock> metadataBlocks, EvaluationContextBase context, ExpressionCompiler.CompileDelegate <CompileResult> compile, DkmUtilities.GetMetadataBytesPtrFunction getMetaDataBytesPtr, out string errorMessage) { return(ExpressionCompiler.CompileWithRetry( metadataBlocks, DebuggerDiagnosticFormatter.Instance, (blocks, useReferencedModulesOnly) => context, compile, getMetaDataBytesPtr, out errorMessage)); }
internal static CompileResult CompileAssignment( this EvaluationContextBase context, string target, string expr, out string error, CompilationTestData testData = null, DiagnosticFormatter formatter = null ) { ResultProperties resultProperties; ImmutableArray <AssemblyIdentity> missingAssemblyIdentities; var result = context.CompileAssignment( target, expr, ImmutableArray <Alias> .Empty, formatter ?? DebuggerDiagnosticFormatter.Instance, out resultProperties, out error, out missingAssemblyIdentities, EnsureEnglishUICulture.PreferredOrNull, testData ); Assert.Empty(missingAssemblyIdentities); // This is a crude way to test the language, but it's convenient to share this test helper. var isCSharp = context.GetType().Namespace.IndexOf("csharp", StringComparison.OrdinalIgnoreCase) >= 0; var expectedFlags = error != null ? DkmClrCompilationResultFlags.None : isCSharp ? DkmClrCompilationResultFlags.PotentialSideEffect : DkmClrCompilationResultFlags.PotentialSideEffect | DkmClrCompilationResultFlags.ReadOnlyResult; Assert.Equal(expectedFlags, resultProperties.Flags); Assert.Equal(default(DkmEvaluationResultCategory), resultProperties.Category); Assert.Equal(default(DkmEvaluationResultAccessType), resultProperties.AccessType); Assert.Equal(default(DkmEvaluationResultStorageType), resultProperties.StorageType); Assert.Equal( default(DkmEvaluationResultTypeModifierFlags), resultProperties.ModifierFlags ); return(result); }
private async Task InnerSetShopperDataFromMember(EvaluationContextBase evalContextBase, string customerId) { var member = await _memberIdResolver.ResolveMemberByIdAsync(customerId); if (member != null && member is Contact contact) { evalContextBase.ShopperGender = contact.GetDynamicPropertyValue("gender", string.Empty); if (contact.BirthDate != null) { var zeroTime = new DateTime(1, 1, 1); var span = DateTime.UtcNow - contact.BirthDate.Value; evalContextBase.ShopperAge = (zeroTime + span).Year - 1; } evalContextBase.UserGroups = contact.Groups?.ToArray(); evalContextBase.GeoTimeZone = contact.TimeZone; //TODO: Set other fields from customer } }
internal static ReadOnlyCollection <byte> CompileGetLocals( this EvaluationContextBase context, ArrayBuilder <LocalAndMethod> locals, bool argumentsOnly, out string typeName, CompilationTestData testData, DiagnosticDescription[] expectedDiagnostics = null) { var diagnostics = DiagnosticBag.GetInstance(); var result = context.CompileGetLocals( locals, argumentsOnly, ImmutableArray <Alias> .Empty, diagnostics, out typeName, testData); diagnostics.Verify(expectedDiagnostics ?? DiagnosticDescription.None); diagnostics.Free(); return(result); }
internal static EvaluationContext CreateMethodContext <TAppDomain>( TAppDomain appDomain, GetMetadataContextDelegate <TAppDomain> getMetadataContext, SetMetadataContextDelegate <TAppDomain> setMetadataContext, ImmutableArray <MetadataBlock> metadataBlocks, object?symReader, Guid moduleVersionId, int methodToken, int methodVersion, uint ilOffset, int localSignatureToken, MakeAssemblyReferencesKind kind) { CSharpCompilation compilation; int offset = EvaluationContextBase.NormalizeILOffset(ilOffset); if (kind == MakeAssemblyReferencesKind.DirectReferencesOnly) { // Avoid using the cache for referenced assemblies only // since this should be the exceptional case. compilation = metadataBlocks.ToCompilationReferencedModulesOnly(moduleVersionId); return(EvaluationContext.CreateMethodContext( compilation, symReader, moduleVersionId, methodToken, methodVersion, offset, localSignatureToken)); } var contextId = MetadataContextId.GetContextId(moduleVersionId, kind); var previous = getMetadataContext(appDomain); var assemblyContexts = previous.Matches(metadataBlocks) ? previous.AssemblyContexts : ImmutableDictionary <MetadataContextId, CSharpMetadataContext> .Empty; CSharpMetadataContext previousMetadataContext; assemblyContexts.TryGetValue(contextId, out previousMetadataContext); // Re-use the previous compilation if possible. compilation = previousMetadataContext.Compilation; if (compilation != null) { // Re-use entire context if method scope has not changed. var previousContext = previousMetadataContext.EvaluationContext; if (previousContext != null && previousContext.MethodContextReuseConstraints.HasValue && previousContext.MethodContextReuseConstraints.GetValueOrDefault().AreSatisfied(moduleVersionId, methodToken, methodVersion, offset)) { return(previousContext); } } else { compilation = metadataBlocks.ToCompilation(moduleVersionId, kind); } var context = EvaluationContext.CreateMethodContext( compilation, symReader, moduleVersionId, methodToken, methodVersion, offset, localSignatureToken); if (context != previousMetadataContext.EvaluationContext) { setMetadataContext( appDomain, new MetadataContext <CSharpMetadataContext>( metadataBlocks, assemblyContexts.SetItem(contextId, new CSharpMetadataContext(context.Compilation, context))), report: kind == MakeAssemblyReferencesKind.AllReferences); } return(context); }