public static WithConfigFormat ( ) : LogContext | ||
Результат | LogContext |
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); }
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; } }
private void Initialize() { if (_isDisposed) { throw new ObjectDisposedException("FimClient"); } if (_isInitialized) { return; } lock (_initializationSyncRoot) { if (_isInitialized) { return; } var ctx = LogContext.WithConfigFormat(); _log.Debug(ctx.Format("Initializing FIM client for user {0}"), System.Threading.Thread.CurrentPrincipal.Identity.Name); // client used for paged queries _pagedQueriesClient = _fimUrl == null ? new WsEnumerationClient() : new WsEnumerationClient(Bindings.ServiceMultipleTokenBinding_Common(_receiveTimeout, _maxReceivedMessageSize), DefaultEndpoints.WsEnumeration(_fimUrl)); // client used for all other operations _defaultClient = _fimUrl == null ? new DefaultClient() : new DefaultClient(_fimUrl, _receiveTimeout, _maxReceivedMessageSize); if (_credential != null) { _pagedQueriesClient.ClientCredentials.Windows.ClientCredential = _credential; _defaultClient.ClientCredential = _credential; } // reusing schema for all subsequent instances for performance reasons // each schema-refresh operation downloads ~1MB of xml that never changes if (_schema == null) { lock (_schemaSyncRoot) { if (_schema == null) { _log.Debug(ctx.Format("Downloading FIM schema...")); _schema = _defaultClient.RefreshSchema(); _log.Debug(ctx.Format("FIM schema downloaded")); } } } var resourceTypeFactory = CreateResourceTypeFactory(); _defaultClient.ResourceFactory = new RmResourceFactory(_schema, resourceTypeFactory); _defaultClient.RequestFactory = new RmRequestFactory(_schema); _isInitialized = true; _log.Debug(ctx.Format("FIM client initialized for user {0}"), System.Threading.Thread.CurrentPrincipal.Identity.Name); } }
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)); }