コード例 #1
0
ファイル: FimClient.cs プロジェクト: Predica/FimClient
        public IEnumerable <TResource> EnumerateAll <TResource>(string query, AttributesToFetch attributes = null) where TResource : RmResource
        {
            attributes = attributes ?? AttributesToFetch.All;

            var ctx = LogContext.WithConfigFormat();

            Initialize();

            try
            {
                _log.Debug(ctx.Format("Executing simple enumeration: {0} with attributes {1}"), query, attributes.GetNames().ToJSON());

                var results = _defaultClient.Enumerate(query, attributes.GetNames())
                              .Cast <TResource>()
                              .ToList();

                log_query_executed(ctx, "Simple enumeration {0} returned {1} results", query, results.Count);

                return(results);
            }
            catch (Exception exc)
            {
                var qee = new QueryExecutionException(query, exc);

                _log.ErrorException(ctx.Format("Error when trying to execute query " + query), qee);

                throw qee;
            }
        }
コード例 #2
0
ファイル: FimClient.cs プロジェクト: Predica/FimClient
        public RmResource FindById(string id, AttributesToFetch attributes = null)
        {
            Initialize();

            attributes = attributes ?? AttributesToFetch.All;

            var ctx = LogContext.WithConfigFormat();

            _log.Debug(ctx.Format("Finding object by id {0} with attributes {1}"), id, attributes.GetNames().ToJSON());

            RmResource resource = null;

            try
            {
                var reference = new RmReference(id);

                if (attributes != AttributesToFetch.All)
                {
                    attributes = attributes.AppendAttribute(RmResource.AttributeNames.ObjectType.Name);
                }

                resource = _defaultClient.Get(reference, attributes.GetNames());

                _log.Debug(ctx.Format("Found object with id {0}, type {1}"), id, resource.ObjectType);
            }
            catch
            {
                // catching exc - meaning that object not found

                _log.Warn(ctx.Format("Object with id {0} not found"), id);
            }
            return(resource);
        }
コード例 #3
0
        public void returns_null_if_no_names_passed___required_for_underlying_fim2010client_mechanisms__must_be_null_not_empty_collection()
        {
            var attributes = new AttributesToFetch();

            var names = attributes.GetNames();

            Assert.Null(names);
        }
コード例 #4
0
        public void returns_given_strings_as_array()
        {
            var attributes = new AttributesToFetch("attr1", "attr2", "attr3");

            var names = attributes.GetNames();

            Assert.Equal(new[] { "attr1", "attr2", "attr3" }, names);
        }
コード例 #5
0
        public void can_append_names_to_empty_names_list()
        {
            var attributes = new AttributesToFetch();

            var newAttributes = attributes.AppendAttribute("attr1");

            var names = newAttributes.GetNames();

            Assert.Equal(new[] { "attr1" }, names);
        }
コード例 #6
0
        public void does_not_append_duplicate_names()
        {
            var attributes = new AttributesToFetch("attr1", "attr2");

            var newAttributes = attributes.AppendAttribute("attr2");

            var names = newAttributes.GetNames();

            Assert.Equal(new[] { "attr1", "attr2" }, names);
        }
コード例 #7
0
        public void appends_new_name_to_the_list_and_creates_new_instance()
        {
            var attributes = new AttributesToFetch("attr1");

            var newAttributes = attributes.AppendAttribute("attr2");

            var names = newAttributes.GetNames();

            Assert.Equal(new[] { "attr1", "attr2" }, names);
        }
コード例 #8
0
        public void does_not_modify_original_instance()
        {
            var attributes = new AttributesToFetch("attr1");

            attributes.AppendAttribute("attr2");

            var names = attributes.GetNames();

            Assert.Equal(new[] { "attr1" }, names);
        }
コード例 #9
0
        /// <summary>
        /// Resets the properties of a dialog box to their default values.
        /// </summary>
        public override void Reset()
        {
            AllowedLocations          = Location.All;
            DefaultLocations          = Location.None;
            AllowedTypes              = ObjectType.All;
            DefaultTypes              = ObjectType.All;
            Providers                 = PathProvider.Default;
            MultiSelect               = false;
            SkipDomainControllerCheck = false;
            _selectedObjects          = null;
            ShowAdvancedView          = false;
            TargetComputer            = null;

            AttributesToFetch.Clear();
        }
コード例 #10
0
ファイル: FimClient.cs プロジェクト: Predica/FimClient
        private DataPage <TResource> ExecuteAdjustedQuery <TResource>(string query, Pagination pagination, SortingInstructions sorting, AttributesToFetch attributes = null) where TResource : RmResource
        {
            attributes = attributes ?? AttributesToFetch.All;

            Initialize();

            var ctx = LogContext.WithConfigFormat();

            _log.Debug(ctx.Format("Executing query {0} with paging: {1}, sorting {2} and attributes {3}"), query, pagination.ToJSON(), sorting.ToJSON(), attributes.GetNames().ToJSON());

            // first request - only to get enumeration context and total rows count
            var enumerationRequest = new EnumerationRequest(query);

            // do not fetch any items - total count only; however this cannot be set to 0 because then total count is not returned (is always set to 0)
            enumerationRequest.MaxElements = 1;
            // get only ObjectID attribute to minimize overhead caused by this operation which returns elements not used for further processing
            enumerationRequest.Selection = new List <string>
            {
                RmResource.AttributeNames.ObjectID.Name
            };
            var enumerateResponse = _pagedQueriesClient.Enumerate(enumerationRequest);

            long totalCount = enumerateResponse.Count ?? 0;

            // second request - to actually get desired data
            var pullRequest = new PullRequest();

            // set enumeration context from previous query
            pullRequest.EnumerationContext = enumerateResponse.EnumerationContext;

            // if attributes names to fetch defined...
            var attributeNames = attributes.GetNames();

            if (attributeNames != null)
            {
                // ... set them to context
                pullRequest.EnumerationContext.Selection         = new Selection();
                pullRequest.EnumerationContext.Selection.@string = attributeNames.ToList();
            }
            else
            {
                pullRequest.EnumerationContext.Selection = null;
            }

            // if paging defined...
            if (pagination.PageSize != Pagination.AllPagesSize)
            {
                // set current page's first row index...
                pullRequest.EnumerationContext.CurrentIndex = pagination.GetFirstRowIndex();
                // ...and page size
                pullRequest.MaxElements = pagination.PageSize;
            }
            // ... if not - get all elements
            else
            {
                // reset current row index...
                pullRequest.EnumerationContext.CurrentIndex = 0;
                // ... page size to max (this may throw if message size exceeds configured maximum, but this situation - getting all items using this method - is not likely to happen)
                pullRequest.MaxElements = int.MaxValue;
            }

            // if sorting defined...
            if (sorting != SortingInstructions.None)
            {
                var sortingAttribute = new SortingAttribute()
                {
                    Ascending = sorting.Order == SortOrder.Ascending,
                    Value     = sorting.AttributeName
                };
                // due to implementation details of these classes, new instances of each of them needs to be created
                pullRequest.EnumerationContext.Sorting = new Sorting
                {
                    SortingAttribute = new List <SortingAttribute>
                    {
                        sortingAttribute
                    }
                };
            }

            var pullResponse = _pagedQueriesClient.Pull(pullRequest);
            var results      = _defaultClient.ResourceFactory.CreateResource(pullResponse)
                               .Cast <TResource>()
                               .ToList();

            log_query_executed(ctx, "Paged query {0} returned {1} results and {2} total count", query, results.Count, totalCount);

            return(new DataPage <TResource>(results, totalCount));
        }
コード例 #11
0
ファイル: FimClient.cs プロジェクト: Predica/FimClient
        public DataPage <TResource> EnumeratePage <TResource>(string query, Pagination pagination, SortingInstructions sorting, AttributesToFetch attributes = null) where TResource : RmResource
        {
            if (pagination == null)
            {
                throw new ArgumentNullException("pagination");
            }
            if (sorting == null)
            {
                throw new ArgumentNullException("sorting");
            }

            try
            {
                return(ExecuteAdjustedQuery <TResource>(query, pagination, sorting, attributes));
            }
            catch (Exception exc)
            {
                var qee = new QueryExecutionException(query, exc);

                _log.ErrorException("Error when trying to execute query " + query, qee);

                throw qee;
            }
        }