コード例 #1
0
 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);
     }
 }
コード例 #2
0
ファイル: CliApp.cs プロジェクト: 522436301/Neuralium.Cli
        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);
        }
コード例 #3
0
ファイル: CliApp.cs プロジェクト: 522436301/Neuralium.Cli
        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);
            }
        }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
ファイル: Auth0Extensions.cs プロジェクト: ealsur/auth0search
        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);
        }
コード例 #6
0
        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));
        }
コード例 #7
0
 public LockableContext(int capacity)
 {
     Context      = new LockContext <Thread>(capacity);
     _slots.Value = new TrackingThreadLocal <LockableSlot>(() => null);
 }
コード例 #8
0
        public IActionResult Login(string returnUrl = null)
        {
            LockContext lockContext = HttpContext.GenerateLockContext(_options.Value, returnUrl);

            return(View(lockContext));
        }
コード例 #9
0
 public LockableContext(int capacity)
 {
     Context = new LockContext<Thread>(capacity);
     _slots.Value = new TrackingThreadLocal<LockableSlot>();
 }