private ILockContext GetOrAdd(TKey key) { lock (_global) { if (false == _locks.TryGetValue(key, out LockContext context)) { LockContext add = null; try { add = new LockContext(); _locks[key] = add; context = add; add = null; } finally { if (add != null) { add.Dispose(); } } } context.IncrementUsages(); return(context); } }
protected override Task ProcessLoop(LockContext lockContext) { try { var result = loop.ExecuteOnce(c => { if (c is CommandGroup <Neuralium.Cli.Classes.Runtime.ApiCommands> group) { if (group.InstantiatedCommand is CommandBase <API, API_METHODS> command) { command.Arguments = this.CmdModeratorInteractiveOptions; command.Api = this.api; } } }); if (result == CommandResult.Terminate) { this.Shutdown(); } } catch (Exception e) { Console.WriteLine(e); this.Shutdown(); } return(Task.CompletedTask); }
protected override async Task Initialize(LockContext lockContext) { await base.Initialize(lockContext).ConfigureAwait(false); try { await this.api.Connect().ConfigureAwait(false); } catch (Exception ex) { throw new ApplicationException("Failed to run daemon", ex); } }
protected override async Task Initialize(LockContext lockContext) { await base.Initialize(lockContext).ConfigureAwait(false); try { await this.api.Connect().ConfigureAwait(false); } catch (Exception ex) { Console.WriteLine($"Failed to run daemon: {ex.Message}, will now shutdown...."); Shutdown(); } }
public static LockContext GenerateLockContext(this HttpContext httpContext, OpenIdConnectOptions options, string returnUrl = null) { LockContext lockContext = new LockContext(); // Set the options lockContext.ClientId = options.ClientId; // retrieve the domain from the authority Uri authorityUri; if (Uri.TryCreate(options.Authority, UriKind.Absolute, out authorityUri)) { lockContext.Domain = authorityUri.Host; } // Set the redirect string callbackUrl = BuildRedirectUri(httpContext.Request, options.CallbackPath); lockContext.CallbackUrl = callbackUrl; // Add the nonce. var nonce = options.ProtocolValidator.GenerateNonce(); httpContext.Response.Cookies.Append( OpenIdConnectDefaults.CookieNoncePrefix + options.StringDataFormat.Protect(nonce), NonceProperty, new CookieOptions { HttpOnly = true, Secure = httpContext.Request.IsHttps, Expires = DateTime.UtcNow + options.ProtocolValidator.NonceLifetime }); lockContext.Nonce = nonce; // Since we are handling the 1st leg of the Auth (redirecting to /authorize), we need to generate the correlation ID so the // OAuth middleware can validate it correctly once it picks up from the 2nd leg (receiving the code) var properties = new AuthenticationProperties() { ExpiresUtc = options.SystemClock.UtcNow.Add(options.RemoteAuthenticationTimeout), RedirectUri = returnUrl ?? "/" }; properties.Items[OpenIdConnectDefaults.RedirectUriForCodePropertiesKey] = callbackUrl; GenerateCorrelationId(httpContext, options, properties); // Generate State lockContext.State = Uri.EscapeDataString(options.StateDataFormat.Protect(properties)); // return the Lock context return(lockContext); }
protected DBResult LockRec(LowLevelTransaction lltx, TreePage page, int index, LockFlags lockFlags, bool add = false) { var count = page.TreeHeader.Count; if (add && lockFlags.IsDocument()) { lltx.LockManager.ExtendRecLockCap(page.Position, index, count); } var req = new LockContext() { Flags = lockFlags, Index = _index, Page = page.Position, Transaction = lltx.Transaction, RecordIndex = index, RecordCount = count, }; return(lltx.LockManager.Lock(ref req)); }
public LockableContext(int capacity) { Context = new LockContext <Thread>(capacity); _slots.Value = new TrackingThreadLocal <LockableSlot>(() => null); }
public IActionResult Login(string returnUrl = null) { LockContext lockContext = HttpContext.GenerateLockContext(_options.Value, returnUrl); return(View(lockContext)); }
public LockableContext(int capacity) { Context = new LockContext<Thread>(capacity); _slots.Value = new TrackingThreadLocal<LockableSlot>(); }