private static void BeginRequest(object sender, System.EventArgs e) { var scopeManager = new ScopeManager(); scopeManager.BeginScope(); HttpContext.Current.Items["ScopeManager"] = scopeManager; }
public override object Execute(Func <object>[] args) { var result = args[0](); ScopeManager.Add(ReturnVarName, result); return(result); }
/// <summary> /// Writes the json. /// </summary> /// <param name="writer">The writer.</param> /// <param name="value">The value.</param> /// <param name="serializer">The serializer.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var serialize = true; if (_jsonSerializer.PreserveReferences) { var scopeName = SerializationContextHelper.GetSerializationReferenceManagerScopeName(); using (var scopeManager = ScopeManager <ReferenceManager> .GetScopeManager(scopeName)) { var referenceManager = scopeManager.ScopeObject; var referenceInfo = referenceManager.GetInfo(value); if (referenceInfo != null && !referenceInfo.IsFirstUsage) { writer.WriteStartObject(); writer.WritePropertyName(Json.JsonSerializer.GraphRefId); writer.WriteValue(referenceInfo.Id); writer.WriteEndObject(); serialize = false; } } } if (serialize) { _jsonSerializer.Serialize((ModelBase)value, writer); } }
/// <summary> /// Initializes a new instance of the <see cref="ModelBase"/> class. /// <para /> /// Only constructor for the ModelBase. /// </summary> /// <param name="info">SerializationInfo object, null if this is the first time construction.</param> /// <param name="context">StreamingContext object, simple pass a default new StreamingContext() if this is the first time construction.</param> /// <remarks> /// Call this method, even when constructing the object for the first time (thus not deserializing). /// </remarks> protected ModelBase(SerializationInfo info, StreamingContext context) { Initialize(); // Make sure this is not a first time call or custom call with null if (info != null) { _serializationInfo = info; // Too bad we cannot put this in the BinarySerializer, but BinarySerialization works bottom => top. We // do need the GraphId though, thus we are setting it here var scopeName = SerializationContextHelper.GetSerializationScopeName(); using (var scopeManager = ScopeManager <SerializationContextScope <BinarySerializationContextInfo> > .GetScopeManager(scopeName)) { var referenceManager = scopeManager.ScopeObject.ReferenceManager; int?graphId = null; try { // Binary graphId = (int)info.GetValue("GraphId", typeof(int)); } catch (Exception) { // Swallow } if (graphId.HasValue) { referenceManager.RegisterManually(graphId.Value, this); } } } }
public override string Gen() { string code = string.Empty; ScopeManager.FunctionEnter(name); ScopeManager.ScopeEnter(); if (body != null) { code += $"${name}:\n"; code += "push\trbp\n"; code += "mov\trbp, rsp\n"; code += $"sub\trsp, {SymbolTable.CurFunVarSize}\n"; code += body.Gen(); code += $"{name}_rtn:\n"; code += "leave\n"; code += "ret\n"; } ScopeManager.ScopeLeave(); ScopeManager.FunctionLeave(); return(code); }
public override string Gen() { int falseLabel = CodeGenUtils.LabelNum++; int endIf = CodeGenUtils.LabelNum++; string code = string.Empty; ScopeManager.ScopeEnter(); CodeGenUtils.StackDepth = 0; code += condition?.Gen() ?? string.Empty; code += $"cmp\trax, 0\n"; code += $"je _L{falseLabel}\n"; code += body?.Gen() ?? string.Empty; code += $"jmp _L{endIf}\n"; code += $"_L{falseLabel}:\n"; ScopeManager.ScopeLeave(); code += elseStmt?.Gen() ?? string.Empty; code += $"_L{endIf}:\n"; return(code); }
private void OnDeserialized(StreamingContext context) { IsDeserializedDataAvailable = true; if (_serializationInfo == null) { // Probably a custom serializer which will populate us in a different way return; } var scopeName = SerializationContextHelper.GetSerializationReferenceManagerScopeName(); using (var scopeManager = ScopeManager <SerializationScope> .GetScopeManager(scopeName, () => new SerializationScope(SerializationFactory.GetBinarySerializer(), SerializationConfiguration))) { var serializer = scopeManager.ScopeObject.Serializer; var configuration = scopeManager.ScopeObject.Configuration; var dependencyResolver = this.GetDependencyResolver(); var serializationContextInfoFactory = dependencyResolver.Resolve <ISerializationContextInfoFactory>(serializer.GetType()); var serializationContext = serializationContextInfoFactory.GetSerializationContextInfo(serializer, this, _serializationInfo, configuration); serializer.Deserialize(this, serializationContext, configuration); } DeserializationSucceeded = true; }
public Parser(Runtime runtime, Scanner scanner) { this.runtime = runtime; this.scanner = scanner; scopeManager = new ScopeManager(runtime); }
/// <summary> /// Initializes a new instance of the <see cref="SerializationContext{TContext}" /> class. /// </summary> /// <param name="model">The model, can be <c>null</c> for value types.</param> /// <param name="modelType">Type of the model.</param> /// <param name="context">The context.</param> /// <param name="contextMode">The context mode.</param> /// <param name="configuration">The configuration.</param> /// <exception cref="ArgumentNullException">The <paramref name="modelType" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="context" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="configuration" /> is <c>null</c>.</exception> public SerializationContext(object model, Type modelType, TContext context, SerializationContextMode contextMode, ISerializationConfiguration configuration = null) { Argument.IsNotNull("modelType", modelType); Argument.IsNotNull("context", context); Argument.IsNotNull("configuration", configuration); Model = model; ModelType = modelType; ModelTypeName = modelType.GetSafeFullName(false); Context = context; ContextMode = contextMode; TypeStack = new Stack <Type>(); Configuration = configuration; var scopeName = SerializationContextHelper.GetSerializationReferenceManagerScopeName(); _typeStackScopeManager = ScopeManager <Stack <Type> > .GetScopeManager(scopeName, () => new Stack <Type>()); TypeStack = _typeStackScopeManager.ScopeObject; _referenceManagerScopeManager = ScopeManager <ReferenceManager> .GetScopeManager(scopeName); ReferenceManager = _referenceManagerScopeManager.ScopeObject; _serializableToken = CreateSerializableToken(); }
private static void BeginRequest() { var scopeManager = new ScopeManager(); scopeManager.BeginScope(); HttpContext.Current.Items["ScopeManager"] = scopeManager; }
/// <summary> /// コード生成を開始 /// </summary> /// <param name="name"></param> /// <param name="prog"></param> public static void CodeGen(string name, List<MTopStmt> prog) { var assembly_name = new AssemblyName(name); var assembly_builder = AppDomain.CurrentDomain.DefineDynamicAssembly( assembly_name, AssemblyBuilderAccess.RunAndSave); var module_builder = assembly_builder.DefineDynamicModule(name, name + ".exe"); _scope_manager = new ScopeManager<ScopeItem>(); _function_table = new Dictionary<string, MethodBuilder>(); var type_builder = module_builder.DefineType("MokkosuProgram", TypeAttributes.Public); foreach (var top_stmt in prog) { CompileTopStmt(type_builder, top_stmt); } type_builder.CreateType(); if (!_function_table.ContainsKey("main")) { throw new MError("main関数が定義されていません。"); } var main_fun = _function_table["main"]; assembly_builder.SetEntryPoint(main_fun); assembly_builder.Save(name + ".exe"); }
/// <summary> /// Gets the current serialization scope. /// </summary> /// <param name="configuration">The configuration.</param> /// <returns></returns> protected virtual ScopeManager <SerializationScope> GetCurrentSerializationScopeManager(ISerializationConfiguration configuration) { var scopeName = SerializationContextHelper.GetSerializationReferenceManagerScopeName(); var scopeManager = ScopeManager <SerializationScope> .GetScopeManager(scopeName, () => new SerializationScope(this, configuration ?? DefaultSerializationConfiguration)); return(scopeManager); }
public FeedVerificationResult VerifyFeed(string source, bool authenticateIfRequired = true) { var result = FeedVerificationResult.Valid; Log.Debug("Verifying feed '{0}'", source); using (ScopeManager <AuthenticationScope> .GetScopeManager(source.GetSafeScopeName(), () => new AuthenticationScope(authenticateIfRequired))) { try { var repository = _packageRepositoryFactory.CreateRepository(source); repository.GetPackages().Take(1).Count(); } catch (WebException ex) { result = HandleWebException(ex, source); } catch (UriFormatException ex) { Log.Debug(ex, "Failed to verify feed '{0}', a UriFormatException occurred", source); result = FeedVerificationResult.Invalid; } catch (Exception ex) { Log.Debug(ex, "Failed to verify feed '{0}'", source); result = FeedVerificationResult.Invalid; } } Log.Debug("Verified feed '{0}', result is '{1}'", source, result); return(result); }
public void MultipleLevelScoping() { ScopeManager <object> scopeManager = null; using (scopeManager = ScopeManager <object> .GetScopeManager("object")) { Assert.AreEqual(1, scopeManager.RefCount); using (ScopeManager <object> .GetScopeManager("object")) { Assert.AreEqual(2, scopeManager.RefCount); using (ScopeManager <object> .GetScopeManager("object")) { Assert.AreEqual(3, scopeManager.RefCount); } Assert.AreEqual(2, scopeManager.RefCount); } Assert.AreEqual(1, scopeManager.RefCount); } Assert.AreEqual(0, scopeManager.RefCount); }
private void OnDeserialized(StreamingContext context) { #if NET || NETCORE if (_serializationInfo is null) { // Probably a custom serializer which will populate us in a different way return; } var scopeName = SerializationContextHelper.GetSerializationReferenceManagerScopeName(); using (var scopeManager = ScopeManager <SerializationScope> .GetScopeManager(scopeName, BinarySerializationScopeFactory)) { var serializer = scopeManager.ScopeObject.Serializer; var configuration = scopeManager.ScopeObject.Configuration; var dependencyResolver = this.GetDependencyResolver(); var serializationContextInfoFactory = dependencyResolver.Resolve <ISerializationContextInfoFactory>(serializer.GetType()); var serializationContext = serializationContextInfoFactory.GetSerializationContextInfo(serializer, this, _serializationInfo, configuration); serializer.Deserialize(this, serializationContext, configuration); } #else throw new NotSupportedInPlatformException("It's adviced to no longer use binary serialization on this platform"); #endif }
public override string Gen() { int startLabel = CodeGenUtils.LabelNum++; int endLabel = CodeGenUtils.LabelNum++; string code = string.Empty; ScopeManager.ScopeEnter(); CodeGenUtils.StackDepth = 0; code += preExpr?.Gen() ?? string.Empty; code += $"_L{startLabel}:\n"; CodeGenUtils.StackDepth = 0; code += condition?.Gen() ?? string.Empty; if (condition != null) { code += $"cmp\trax, 0\n"; code += $"je _L{endLabel}\n"; } code += body?.Gen() ?? string.Empty; CodeGenUtils.StackDepth = 0; code += loopExpr?.Gen() ?? string.Empty; code += $"jmp _L{startLabel}\n"; code += $"_L{endLabel}:\n"; ScopeManager.ScopeLeave(); return(code); }
private static void CompileAndBuildExecutable() { var scan = new Scanner(); scan.SetSource(File.ReadAllText(FILE_LOCATION), 0); var parser = new Parser(scan); parser.Parse(); var root = parser.SyntaxTreeRoot; var mgr = new ScopeManager(); var first = new FirstPass(root, mgr); var second = new SecondPass(root, mgr); first.Run(); second.Run(); const string asmName = "sample1-test"; var cg = new CodeGenerator(asmName); cg.Generate(root); cg.WriteAssembly(); }
internal Scope(Container container, ScopeManager manager, Scope parentScope) : this(container) { Requires.IsNotNull(manager, nameof(manager)); this.ParentScope = parentScope; this.manager = manager; }
protected override async Task <bool> SaveAsync() { var editablePackageSource = EditablePackageSources; if (editablePackageSource == null) { return(false); } if (editablePackageSource.Any(x => x.IsValid == null)) { return(false); } _ignoreNextPackageUpdate = true; PackageSources = editablePackageSource.Select(x => { using (ScopeManager <AuthenticationScope> .GetScopeManager(x.Source.GetSafeScopeName(), () => new AuthenticationScope(false))) { var packageSource = _packageSourceFactory.CreatePackageSource(x.Source, x.Name, x.IsEnabled, false); return(packageSource); } }).ToArray(); return(await base.SaveAsync()); }
private void EnsureSubscribedToScope(ScopeManager<ReferenceManager> scopeManager, string scopeName) { if (!_scopeInfo.ContainsKey(scopeName)) { _scopeInfo.Add(scopeName, new XmlScopeNamespaceInfo(scopeName)); scopeManager.ScopeClosed += OnScopeClosed; } }
private void EnsureSubscribedToScope(ScopeManager <SerializationContextScope <XmlSerializationContextInfo> > scopeManager, string scopeName) { if (!_scopeInfo.ContainsKey(scopeName)) { _scopeInfo.Add(scopeName, new XmlScopeNamespaceInfo(scopeName)); scopeManager.ScopeClosed += OnScopeClosed; } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { if (_referenceManagerScopeManager != null) { _referenceManagerScopeManager.Dispose(); _referenceManagerScopeManager = null; } }
private void EnsureSubscribedToScope(ScopeManager <ReferenceManager> scopeManager, string scopeName) { if (!_scopeInfo.ContainsKey(scopeName)) { _scopeInfo.Add(scopeName, new XmlScopeNamespaceInfo(scopeName)); scopeManager.ScopeClosed += OnScopeClosed; } }
public BorrowAssignmentLifetimeValidator(FunctionDefinitionNode function, IErrorManager errors, ExpressionTypeManager types, ScopeManager scopes) { _function = function; _errors = errors; _scopes = scopes; _types = types; _lifetimeResolver = new BorrowPointerLifetimeResolver(scopes); }
public async Task <AuthenticationCredentials> GetCredentialsAsync(Uri uri, bool previousCredentialsFailed) { Log.Debug("Requesting credentials for '{0}'", uri); bool?result = null; var credentials = new AuthenticationCredentials(uri); using (_pleaseWaitInterruptService.Value.InterruptTemporarily()) { await DispatchHelper.DispatchIfNecessaryAsync(() => { var uriString = uri.ToString().ToLower(); using (var scopeManager = ScopeManager <AuthenticationScope> .GetScopeManager(uriString.GetSafeScopeName(), () => new AuthenticationScope())) { var authenticationScope = scopeManager.ScopeObject; var credentialsPrompter = new CredentialsPrompter(_configurationService) { Target = uriString, UserName = string.Empty, Password = string.Empty, AllowStoredCredentials = !previousCredentialsFailed, ShowSaveCheckBox = true, WindowTitle = "Credentials required", MainInstruction = "Credentials are required to access this feed", Content = string.Format("In order to continue, please enter the credentials for {0} below.", uri), IsAuthenticationRequired = authenticationScope.CanPromptForAuthentication }; authenticationScope.HasPromptedForAuthentication = true; result = credentialsPrompter.ShowDialog(); if (result ?? false) { credentials.UserName = credentialsPrompter.UserName; credentials.Password = credentialsPrompter.Password; } else { credentials.StoreCredentials = false; } } }); } if (result ?? false) { Log.Debug("Successfully requested credentials for '{0}' using user '{1}'", uri, credentials.UserName); return(credentials); } Log.Debug("Failed to request credentials for '{0}'", uri); return(null); }
/// <summary> /// 型推論の開始 /// </summary> /// <param name="prog">プログラム</param> public static void Run(List<MTopStmt> prog) { env = new ScopeManager<MType>(); function_table = new Dictionary<string, FunctionInfo>(); foreach (var top_stmt in prog) { TypeinfTopStmt(top_stmt); } }
public override string Gen() { ScopeManager.ScopeEnter(); string code = body?.Gen() ?? string.Empty; ScopeManager.ScopeLeave(); return(code); }
public PExpr Visit(FunctionExpr e) { Closure[] c = new Closure[e.Closures.Count]; for (int i = 0; i < c.Length; ++i) { var v = e.Closures[i]; c[i] = new Closure(v, ScopeManager.FindRegistered(v)); } return(new PExpr(new FunctionObj(e, c))); }
public void EndCurrentScope_InScope_EndsScope() { var container = new ServiceContainer(); ScopeManager manager = container.ScopeManagerProvider.GetScopeManager(); container.BeginScope(); container.EndCurrentScope(); Assert.IsNull(manager.CurrentScope); }
private static void RunSemanticPasses(Node root) { var mgr = new ScopeManager(); var first = new FirstPass(root, mgr); var second = new SecondPass(root, mgr); first.Run(); second.Run(); }
public void ReturnsTrueForExistignScope() { Assert.IsFalse(ScopeManager <string> .ScopeExists()); using (var scopeManager = ScopeManager <string> .GetScopeManager()) { Assert.IsTrue(ScopeManager <string> .ScopeExists()); } Assert.IsFalse(ScopeManager <string> .ScopeExists()); }
public ITransaction StartTransaction(IHub hub, ITransactionContext context) { var transaction = new TransactionTracer(hub, context) { IsSampled = true }; var(currentScope, _) = ScopeManager.GetCurrent(); currentScope.Transaction = transaction; return(transaction); }
/// <summary> /// Disposes the managed resources. /// </summary> protected override void DisposeManaged() { base.DisposeManaged(); if (_scopeManager != null) { _scopeManager.Dispose(); _scopeManager = null; } Uninitialize(); }
private static void BeginRequest(object sender, EventArgs eventArgs) { var application = sender as HttpApplication; if (application == null) { return; } var scopeManager = new ScopeManager(); scopeManager.BeginScope(); application.Context.Items["ScopeManager"] = scopeManager; }
internal ScopeFactoryExport(ScopeManager scopeManager, CompositionScopeDefinition catalog, ComposablePartDefinition partDefinition, ExportDefinition exportDefinition) : base(partDefinition, exportDefinition) { this._scopeManager = scopeManager; this._catalog = catalog; }
/// <summary> /// Creates new XslReader instance with given <see cref="XslCompiledTransform"/>, /// mode (multithreaded/singlethreaded) and initial buffer size. The buffer will be /// expanded if necessary to be able to store any element start tag with all its /// attributes. /// </summary> /// <param name="xslTransform">Loaded <see cref="XslCompiledTransform"/> object</param> /// <param name="multiThread">Defines in which mode (multithreaded or singlethreaded) /// this instance of XslReader will operate</param> /// <param name="initialBufferSize">Initial buffer size (number of nodes, not bytes)</param> public XslReader(XslCompiledTransform xslTransform, bool multiThread, int initialBufferSize) { this.xslCompiledTransform = xslTransform; this.multiThread = multiThread; this.initialBufferSize = initialBufferSize; nameTable = new NameTable(); pipe = this.multiThread ? new TokenPipeMultiThread(initialBufferSize) : new TokenPipe(initialBufferSize); writer = new BufferWriter(pipe, nameTable); scope = new ScopeManager(nameTable); SetUndefinedState(ReadState.Initial); }