Exemple #1
0
        public ReserveResult CheckLeaseReservations()
        {
            if (this.isDisposed)
            {
                throw new ObjectDisposedException("dbServices");
            }

            var dbServices = this.dbServices;

            try
            {
                // резервируем бд
                if (dbServices?.LockObject.CheckLease() == true)
                {
                    return(ReserveResult.FromValueResult(true, dbServices));
                }
                else
                {
                    // lease НЕ найдена, потеряна или НЕ действует
                    return(ReserveResult.FailResult());
                }
            }
            catch (Exception)
            {
                // ignore ??
                return(ReserveResult.FailResult());
            }
        }
Exemple #2
0
        public ReserveResult RenewLeaseReservations(/*CancellationToken token*/)
        {
            if (this.isDisposed)
            {
                throw new ObjectDisposedException("dbServices");
            }

            lock (this.sync)
            {
                if (this.isDisposed)
                {
                    throw new ObjectDisposedException("dbServices");
                }

                try
                {
                    using (var cts = CancellationTokenSource.CreateLinkedTokenSource(/*token,*/ this.onDisposeCancelSource.Token))
                    {
                        // резервируем бд
                        if (this.dbServices?.LockObject.CheckAndUpdateLease(cts.Token) == true)
                        {
                            return(ReserveResult.FromValueResult(true, this.dbServices));
                        }
                        else
                        {
                            // lease НЕ найдена, потеряна или НЕ действует
                            return(ReserveResult.FailResult());
                        }
                    }
                }
                //catch (OperationCanceledException)
                //{
                //    return ReserveResult.FailResult();
                //}
                catch (Exception)
                {
                    // ignore ??
                    return(ReserveResult.FailResult());
                }
            }
        }