コード例 #1
0
        public void CreateNonCachingAndPathIncludingContext()
        {
            var result  = Mock.Of <IOperationContext>();
            var session = this.CreateSessionMock(result);

            var context = OperationContextFactory.CreateNonCachingPathIncludingContext(session.Object);

            session.VerifyThatAllDefaultValuesAreSet();
            session.VerifyThatFilterContainsPath();
            session.VerifyThatCachingIsDisabled();
            Assert.That(context, Is.EqualTo(result));
        }
コード例 #2
0
ファイル: CrudIT.cs プロジェクト: OpenDataSpace/CmisSync
        public void IgnoreRemoteFolder()
        {
            this.session.EnsureSelectiveIgnoreSupportIsAvailable();
            var folder = this.remoteRootDir.CreateFolder("ignored");

            folder.IgnoreAllChildren();

            var context   = OperationContextFactory.CreateContext(this.session, false, true);
            var underTest = this.session.GetObject(folder.Id, context) as IFolder;

            Assert.That(folder.AreAllChildrenIgnored(), Is.True);
            Assert.That(underTest.AreAllChildrenIgnored(), Is.True);
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RemoteObjectFetcher"/> class.
        /// Fetches remote CMIS Objects and adds them to the handled events.
        /// </summary>
        /// <param name="session">Session to be used.</param>
        /// <param name="storage">Storage to look for mapped objects.</param>
        public RemoteObjectFetcher(ISession session, IMetaDataStorage storage)
        {
            if (session == null)
            {
                throw new ArgumentNullException("Session instance is needed , but was null");
            }

            if (storage == null)
            {
                throw new ArgumentNullException("MetaDataStorage instance is needed, but was null");
            }

            this.session          = session;
            this.storage          = storage;
            this.operationContext = OperationContextFactory.CreateNonCachingPathIncludingContext(this.session);
        }
コード例 #5
0
        public void EnsureFileNameStaysEqualWhileUploading(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);

            IFolder folder = (IFolder)session.GetObjectByPath(remoteFolderPath);

            string filename = "testfile.txt";
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, filename);
            properties.Add(PropertyIds.ObjectTypeId, BaseTypeId.CmisDocument.GetCmisValue());
            try {
                IDocument doc = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + filename) as IDocument;
                if (doc != null)
                {
                    doc.Delete(true);
                }
            } catch (CmisObjectNotFoundException) {
            }

            IDocument emptyDoc = folder.CreateDocument(properties, null, null);
            int       length   = 1024 * 1024;

            byte[]        content       = new byte[length];
            ContentStream contentStream = new ContentStream();

            contentStream.FileName = filename;
            contentStream.MimeType = MimeType.GetMIMEType(filename);
            contentStream.Length   = content.Length;
            Action assert = delegate {
                Assert.That((session.GetObject(emptyDoc.Id, OperationContextFactory.CreateNonCachingPathIncludingContext(session)) as IDocument).Name, Is.EqualTo(filename));
            };

            using (var memstream = new AssertingStream(new MemoryStream(content), assert)) {
                contentStream.Stream = memstream;
                emptyDoc.SetContentStream(contentStream, true, true);
            }
        }
コード例 #6
0
ファイル: CoreModule.cs プロジェクト: BennyJ1982/SAPI
        /// <summary>
        /// This Operation is called, when the module shall initialize itself.
        /// </summary>
        /// <param name="typeRegistry">The type registry for service requests or registrations.</param>
        /// <inheritdoc/>
        public void Initialize(ITypeRegistry typeRegistry)
        {
            var odataObjectFactory = new ODataObjectFactory();

            var pathService                      = new ODataPathService();
            var modelItemNamingService           = new ModelItemNamingService();
            var navigationPropertyBuilderFactory = new NavigationPropertyBuilderFactory(modelItemNamingService);

            var modelBuilderFactory     = new ModelBuilderFactory(pathService, navigationPropertyBuilderFactory);
            var queryBuilderFactory     = new QueryBuilderFactory();
            var operationContextFactory = new OperationContextFactory(pathService);
            var dataTypeRegistry        = new DataTypeRegistry(new DefaultDataTypeKeyLookupStrategy());

            typeRegistry.RegisterInstance <IModelBuilderFactory>(modelBuilderFactory);
            typeRegistry.RegisterInstance <IDataTypeRegistry>(dataTypeRegistry);
            typeRegistry.RegisterInstance <IODataObjectFactory>(odataObjectFactory);
            typeRegistry.RegisterInstance <IODataPathService>(pathService);
            typeRegistry.RegisterInstance <IOperationContextFactory>(operationContextFactory);
            typeRegistry.RegisterInstance <IModelItemNamingService>(modelItemNamingService);
            typeRegistry.RegisterInstance <IQueryBuilderFactory>(queryBuilderFactory);
        }
コード例 #7
0
        /// <summary>
        /// Connect this instance.
        /// </summary>
        protected bool Connect()
        {
            lock (this.repoInfoLock) {
                try {
                    if (this.isForbidden)
                    {
                        return(false);
                    }

                    // Create session.
                    var session = this.SessionFactory.CreateSession(this.GetCmisParameter(this.RepoInfo), null, this.AuthProvider, null);

                    session.DefaultContext = OperationContextFactory.CreateDefaultContext(session);
                    this.Queue.AddEvent(new SuccessfulLoginEvent(this.RepoInfo.Address, session));
                    return(true);
                } catch (DotCMIS.Exceptions.CmisPermissionDeniedException e) {
                    Logger.Info(string.Format("Failed to connect to server {0}", this.RepoInfo.Address.ToString()), e);
                    this.Queue.AddEvent(new PermissionDeniedEvent(e));
                    this.isForbidden = true;
                } catch (CmisRuntimeException e) {
                    if (e.Message == "Proxy Authentication Required")
                    {
                        this.Queue.AddEvent(new ProxyAuthRequiredEvent(e));
                        Logger.Warn("Proxy Settings Problem", e);
                        this.isForbidden = true;
                    }
                    else
                    {
                        Logger.Error("Connection to repository failed: ", e);
                        this.Queue.AddEvent(new ExceptionEvent(e));
                    }
                } catch (CmisObjectNotFoundException e) {
                    Logger.Error("Failed to find cmis object: ", e);
                } catch (CmisBaseException e) {
                    Logger.Error("Failed to create session to remote " + this.RepoInfo.Address.ToString() + ": ", e);
                }

                return(false);
            }
        }
コード例 #8
0
ファイル: Op.cs プロジェクト: VladimirLevchuk/Operations
 public static IOperationContext Context(IDictionary <string, object> contextValues)
 {
     return(OperationContextFactory.Create(contextValues));
 }
コード例 #9
0
ファイル: Op.cs プロジェクト: VladimirLevchuk/Operations
 public static IOperationContext Context(object contextValues)
 {
     return(OperationContextFactory.Create(contextValues));
 }
コード例 #10
0
 /// <summary>
 /// Updates the object.
 /// </summary>
 /// <param name='session'>
 /// Session from where the object should be requested.
 /// </param>
 public void UpdateObject(ISession session)
 {
     this.CmisObject = session.GetObject(this.ObjectId, OperationContextFactory.CreateNonCachingPathIncludingContext(session));
 }