示例#1
0
        public void ConstructorWithValidInput()
        {
            var exception = new Mock <DotCMIS.Exceptions.CmisPermissionDeniedException>().Object;
            var ev        = new PermissionDeniedEvent(exception);

            Assert.AreEqual(exception, ev.Exception);
        }
示例#2
0
        public void DoesNotCalculatesUntilDateIfHeaderContainsNotParsableDate()
        {
            var exception = Mock.Of <CmisPermissionDeniedException>(
                e => e.Data == CreateHeader("no date"));

            var underTest = new PermissionDeniedEvent(exception);

            Assert.That(underTest.IsBlockedUntil, Is.Null);
        }
示例#3
0
        public void CalculatesBlockingUntilDateWithFormattedDateAsInput()
        {
            var exception = Mock.Of <CmisPermissionDeniedException>(
                e => e.Data == CreateHeader(this.formatedDate));

            var underTest = new PermissionDeniedEvent(exception);

            Assert.That(underTest.IsBlockedUntil, Is.EqualTo(DateTime.Parse(this.formatedDate)));
        }
示例#4
0
        public void CalculatesBlockingUntilDate()
        {
            long seconds   = 120;
            var  exception = Mock.Of <CmisPermissionDeniedException>(
                e => e.Data == CreateHeader(seconds.ToString()));

            var underTest = new PermissionDeniedEvent(exception);

            Assert.That(underTest.IsBlockedUntil, Is.EqualTo(DateTime.UtcNow + TimeSpan.FromSeconds(seconds)).Within(1).Seconds);
        }
示例#5
0
        /// <summary>
        /// Connect this instance.
        /// </summary>
        /// <returns><c>true</c>, if connection was successful, otherwise <c>false</c></returns>
        protected bool Connect()
        {
            lock (this.repoInfoLock) {
                try {
                    if (this.isForbiddenUntil > DateTime.UtcNow)
                    {
                        return(false);
                    }

                    // Create session.
                    var session = this.SessionFactory.CreateSession(this.RepoInfo, authenticationProvider: this.AuthProvider);
                    Logger.Debug(session.RepositoryInfo.ToLogString());
                    this.cancelToken.ThrowIfCancellationRequested();
                    session.DefaultContext = OperationContextFactory.CreateDefaultContext(session);
                    this.cancelToken.ThrowIfCancellationRequested();
                    this.Queue.AddEvent(new SuccessfulLoginEvent(this.RepoInfo.Address, session));
                    this.lastSuccessfulLogin = DateTime.Now;
                    return(true);
                } catch (DotCMIS.Exceptions.CmisPermissionDeniedException e) {
                    Logger.Info(string.Format("Failed to connect to server {0}", this.RepoInfo.Address.ToString()), e);
                    var permissionDeniedEvent = new PermissionDeniedEvent(e);
                    this.Queue.AddEvent(permissionDeniedEvent);
                    this.isForbiddenUntil = permissionDeniedEvent.IsBlockedUntil ?? DateTime.MaxValue;
                } catch (CmisRuntimeException e) {
                    if (e.Message == "Proxy Authentication Required")
                    {
                        this.Queue.AddEvent(new ProxyAuthRequiredEvent(e));
                        Logger.Warn("Proxy Settings Problem", e);
                        this.isForbiddenUntil = DateTime.MaxValue;
                    }
                    else
                    {
                        Logger.Error("Connection to repository failed: ", e);
                        this.Queue.AddEvent(new ExceptionEvent(e));
                    }
                } catch (DotCMIS.Exceptions.CmisInvalidArgumentException e) {
                    Logger.Warn(string.Format("Failed to connect to server {0}", this.RepoInfo.Address.ToString()), e);
                    this.Queue.AddEvent(new ConfigurationNeededEvent(e));
                    this.isForbiddenUntil = DateTime.MaxValue;
                } catch (CmisObjectNotFoundException e) {
                    Logger.Error("Failed to find cmis object: ", e);
                } catch (CmisConnectionException e) {
                    Logger.Info(string.Format("Failed to create connection to \"{0}\". Will try again in {1} ms", this.RepoInfo.Address.ToString(), this.Interval));
                    Logger.Debug(string.Empty, e);
                } catch (CmisBaseException e) {
                    Logger.Error("Failed to create session to remote " + this.RepoInfo.Address.ToString() + ": ", e);
                }

                return(false);
            }
        }