コード例 #1
0
        public IEnumerable <ConfigurationDocumentHeader> ListDocuments(ConfigurationDocumentQuery query)
        {
            // choose the anonymous-access service if possible (if we're not querying for user docs)
            var serviceContract = query.UserType == ConfigurationDocumentQuery.DocumentUserType.Shared ?
                                  typeof(IApplicationConfigurationReadService) : typeof(IConfigurationService);

            var service = (IApplicationConfigurationReadService)Platform.GetService(serviceContract);

            using (service as IDisposable)
            {
                var response = service.ListConfigurationDocuments(new ListConfigurationDocumentsRequest(query));
                return(response.Documents);
            }
        }
コード例 #2
0
		/// <summary>
		/// Lists documents matching the specified query.
		/// </summary>
		/// <param name="query"></param>
		/// <returns></returns>
		protected ListConfigurationDocumentsResponse ListConfigurationDocumentsHelper(ConfigurationDocumentQuery query)
		{
			Platform.CheckNonNegative(query.FirstResult, "FirstResult");
			Platform.CheckArgumentRange(query.MaxResults, 0, 500, "MaxResults");

			var whereDocument = new ConfigurationDocumentSearchCriteria();
			var whereBody = new ConfigurationDocumentBodySearchCriteria();

			BuildDocumentQueryCriteria(query, whereDocument, whereBody);

			var broker = PersistenceContext.GetBroker<IConfigurationDocumentBroker>();
			var page = new SearchResultPage(query.FirstResult, query.MaxResults);
			var documents = broker.Find(whereDocument, whereBody, page);

			return new ListConfigurationDocumentsResponse(
				CollectionUtils.Map(documents, (ConfigurationDocument doc) => GetDocumentHeader(doc)));
		}
コード例 #3
0
 public ListConfigurationDocumentsRequest(ConfigurationDocumentQuery query)
 {
     this.Query = query;
 }
コード例 #4
0
		/// <summary>
		/// Builds criteria for querying documents.
		/// </summary>
		/// <param name="query"></param>
		/// <param name="whereDocument"></param>
		/// <param name="whereBody"></param>
		private static void BuildDocumentQueryCriteria(ConfigurationDocumentQuery query, ConfigurationDocumentSearchCriteria whereDocument, ConfigurationDocumentBodySearchCriteria whereBody)
		{
			var currentUser = Thread.CurrentPrincipal == null ? null : Thread.CurrentPrincipal.Identity.Name;

			// user type
			if (query.UserType == ConfigurationDocumentQuery.DocumentUserType.User)
			{
				// to query for user documents, we must have an authenticated user
				if (string.IsNullOrEmpty(currentUser))
					ThrowNotAuthorized();

				// current users documents only
				whereDocument.User.EqualTo(currentUser);
			}
			else
			{
				// shared documents only!
				// (authentication is irrelevant - shared documents can be queried anonymously)
				whereDocument.User.IsNull();
			}

			// document name
			if (query.DocumentName.IsSet && !string.IsNullOrEmpty(query.DocumentName.Value))
			{
				if (query.DocumentName.Operator == ConfigurationDocumentQuery.StringOperator.StartsWith)
				{
					whereDocument.DocumentName.StartsWith(query.DocumentName.Value);
				}
				else if (query.DocumentName.Operator == ConfigurationDocumentQuery.StringOperator.Exact)
				{
					whereDocument.DocumentName.EqualTo(query.DocumentName.Value);
				}
			}

			// document version
			if (query.Version.IsSet)
			{
				whereDocument.DocumentVersionString.EqualTo(VersionUtils.ToPaddedVersionString(query.Version.Value));
			}

			// instance key
			if (query.InstanceKey.IsSet)
			{
				if (query.InstanceKey.Value == null)
				{
					whereDocument.InstanceKey.IsNull(); // default instances only!
				}
				else
				{
					whereDocument.InstanceKey.EqualTo(query.InstanceKey.Value);
				}
			}

			// creation time
			if (query.CreationTime.IsSet)
			{
				if (query.CreationTime.Operator == ConfigurationDocumentQuery.DateTimeOperator.After)
				{
					whereDocument.CreationTime.MoreThan(query.CreationTime.Value);
				}
				else if (query.CreationTime.Operator == ConfigurationDocumentQuery.DateTimeOperator.Before)
				{
					whereDocument.CreationTime.LessThan(query.CreationTime.Value);
				}
			}

			// modified time
			if (query.ModifiedTime.IsSet)
			{
				if (query.ModifiedTime.Operator == ConfigurationDocumentQuery.DateTimeOperator.After)
				{
					whereBody.ModifiedTime.MoreThan(query.ModifiedTime.Value);
				}
				else if (query.ModifiedTime.Operator == ConfigurationDocumentQuery.DateTimeOperator.Before)
				{
					whereBody.ModifiedTime.LessThan(query.ModifiedTime.Value);
				}
			}
		}
コード例 #5
0
		public ListConfigurationDocumentsRequest(ConfigurationDocumentQuery query)
		{
			this.Query = query;
		}
コード例 #6
0
        /// <summary>
        /// Lists documents matching the specified query.
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        protected ListConfigurationDocumentsResponse ListConfigurationDocumentsHelper(ConfigurationDocumentQuery query)
        {
            Platform.CheckNonNegative(query.FirstResult, "FirstResult");
            Platform.CheckArgumentRange(query.MaxResults, 0, 500, "MaxResults");

            var whereDocument = new ConfigurationDocumentSearchCriteria();
            var whereBody     = new ConfigurationDocumentBodySearchCriteria();

            BuildDocumentQueryCriteria(query, whereDocument, whereBody);

            var broker    = PersistenceContext.GetBroker <IConfigurationDocumentBroker>();
            var page      = new SearchResultPage(query.FirstResult, query.MaxResults);
            var documents = broker.Find(whereDocument, whereBody, page);

            return(new ListConfigurationDocumentsResponse(
                       CollectionUtils.Map(documents, (ConfigurationDocument doc) => GetDocumentHeader(doc))));
        }
コード例 #7
0
        /// <summary>
        /// Builds criteria for querying documents.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="whereDocument"></param>
        /// <param name="whereBody"></param>
        private static void BuildDocumentQueryCriteria(ConfigurationDocumentQuery query, ConfigurationDocumentSearchCriteria whereDocument, ConfigurationDocumentBodySearchCriteria whereBody)
        {
            var currentUser = Thread.CurrentPrincipal == null ? null : Thread.CurrentPrincipal.Identity.Name;

            // user type
            if (query.UserType == ConfigurationDocumentQuery.DocumentUserType.User)
            {
                // to query for user documents, we must have an authenticated user
                if (string.IsNullOrEmpty(currentUser))
                {
                    ThrowNotAuthorized();
                }

                // current users documents only
                whereDocument.User.EqualTo(currentUser);
            }
            else
            {
                // shared documents only!
                // (authentication is irrelevant - shared documents can be queried anonymously)
                whereDocument.User.IsNull();
            }

            // document name
            if (query.DocumentName.IsSet && !string.IsNullOrEmpty(query.DocumentName.Value))
            {
                if (query.DocumentName.Operator == ConfigurationDocumentQuery.StringOperator.StartsWith)
                {
                    whereDocument.DocumentName.StartsWith(query.DocumentName.Value);
                }
                else if (query.DocumentName.Operator == ConfigurationDocumentQuery.StringOperator.Exact)
                {
                    whereDocument.DocumentName.EqualTo(query.DocumentName.Value);
                }
            }

            // document version
            if (query.Version.IsSet)
            {
                whereDocument.DocumentVersionString.EqualTo(VersionUtils.ToPaddedVersionString(query.Version.Value));
            }

            // instance key
            if (query.InstanceKey.IsSet)
            {
                if (query.InstanceKey.Value == null)
                {
                    whereDocument.InstanceKey.IsNull();                     // default instances only!
                }
                else
                {
                    whereDocument.InstanceKey.EqualTo(query.InstanceKey.Value);
                }
            }

            // creation time
            if (query.CreationTime.IsSet)
            {
                if (query.CreationTime.Operator == ConfigurationDocumentQuery.DateTimeOperator.After)
                {
                    whereDocument.CreationTime.MoreThan(query.CreationTime.Value);
                }
                else if (query.CreationTime.Operator == ConfigurationDocumentQuery.DateTimeOperator.Before)
                {
                    whereDocument.CreationTime.LessThan(query.CreationTime.Value);
                }
            }

            // modified time
            if (query.ModifiedTime.IsSet)
            {
                if (query.ModifiedTime.Operator == ConfigurationDocumentQuery.DateTimeOperator.After)
                {
                    whereBody.ModifiedTime.MoreThan(query.ModifiedTime.Value);
                }
                else if (query.ModifiedTime.Operator == ConfigurationDocumentQuery.DateTimeOperator.Before)
                {
                    whereBody.ModifiedTime.LessThan(query.ModifiedTime.Value);
                }
            }
        }