private async Task <ISearchResultCollection> GetResources(string Filter, string ObjectType) { ObjectTypeDefinition objectType = ResourceManagementSchema.GetObjectType(ObjectType); var attributes = objectType.Attributes.Select(t => t.SystemName); return(await Task.FromResult <ISearchResultCollection>( RmcWrapper.Client.GetResourcesAsync(Filter, attributes))); }
protected override void ProcessRecord() { CultureInfo locale = null; if (this.Locale != null) { locale = new CultureInfo(this.Locale); } IEnumerable <string> attributes = null; string filter = this.GetQueryString(); if (!this.Unconstrained.IsPresent) { if (this.AttributesToGet == null || this.AttributesToGet.Length == 0) { if (string.IsNullOrWhiteSpace(this.ExpectedObjectType)) { attributes = new List <string>() { "ObjectID" }; } else { ObjectTypeDefinition objectType = ResourceManagementSchema.GetObjectType(this.ExpectedObjectType); attributes = objectType.Attributes.Select(t => t.SystemName); } } else { attributes = this.AttributesToGet; } } int pageSize; if (this.PageSize > 0) { pageSize = this.PageSize; } else { pageSize = 200; } List <SortingAttribute> sortCriteria = new List <SortingAttribute>(); if (this.SortAttributes != null) { foreach (string attribute in this.SortAttributes) { sortCriteria.Add(new SortingAttribute(attribute, !this.Descending)); } } this.WriteObject(new RmaSearchPager(RmcWrapper.Client.GetResourcesPaged(filter, pageSize, attributes, sortCriteria, locale))); }
public static IEnumerable <string> GetAttributes(IncomingWebRequestContext context) { string attributes = context.UriTemplateMatch.QueryParameters[ParameterNames.Attributes]; string objectType = context.UriTemplateMatch.QueryParameters[ParameterNames.ObjectType]; if (attributes != null) { return(attributes.Split(',')); } if (objectType != null) { return(ResourceManagementSchema.GetObjectType(objectType).Attributes.Select(t => t.SystemName)); } return(null); }
public static RuntimeDefinedParameter GetAttributeNameParameter(string paramName, bool mandatory, int position, string objectType, string parameterSetName) { RuntimeDefinedParameter parameter = new RuntimeDefinedParameter(); parameter.Name = paramName; parameter.ParameterType = typeof(string); if (objectType == null) { List <string> attributeNames = new List <string>(); IList <ObjectTypeDefinition> objectTypes = ResourceManagementSchema.GetObjectTypes().ToList(); if (objectTypes.Count > 0) { foreach (ObjectTypeDefinition type in objectTypes) { attributeNames.AddRange(type.Attributes.Select(t => t.SystemName)); } if (attributeNames.Count > 0) { ValidateSetAttribute setAttribute = new ValidateSetAttribute(attributeNames.Distinct().OrderBy(t => t).ToArray()); parameter.Attributes.Add(setAttribute); } } } else { if (ResourceManagementSchema.ContainsObjectType(objectType)) { ValidateSetAttribute setAttribute = new ValidateSetAttribute(ResourceManagementSchema.GetObjectType(objectType).Attributes.OrderBy(t => t.SystemName).Select(t => t.SystemName).ToArray()); parameter.Attributes.Add(setAttribute); } } ParameterAttribute paramAttribute = new ParameterAttribute(); paramAttribute.Mandatory = mandatory; paramAttribute.Position = position; paramAttribute.ParameterSetName = parameterSetName; parameter.Attributes.Add(paramAttribute); return(parameter); }
private string GetReference(string value) { string[] split = this.ExpandVariables(value).Split('|'); if (split.Length != 3) { throw new ArgumentException(string.Format("The attribute operation of {0} on attribute {1} specifies a reference type, but does not have a string in the value of ObjectType|AttributeName|AttributeValue. The invalid value was {2}", this.Name, this.Operation, this.Value)); } ResourceObject resource = RmcWrapper.Client.GetResourceByKey(split[0], split[1], split[2], ResourceManagementSchema.GetObjectType(split[0]).Attributes.Select(t => t.SystemName).Except(ResourceManagementSchema.ComputedAttributes)); if (resource == null) { if (ConfigSyncControl.Preview) { return(Guid.NewGuid().ToString()); } else { throw new ArgumentException(string.Format("The attribute operation of {1} on attribute {0} specifies a reference to {2}, but the object was not found in the FIM service", this.Name, this.Operation, value)); } } return(resource.ObjectID.Value); }
public Stream GetResources() { try { string attributes = WebOperationContext.Current?.IncomingRequest.UriTemplateMatch.QueryParameters["attributes"]; string objectType = WebOperationContext.Current?.IncomingRequest.UriTemplateMatch.QueryParameters["objectType"]; string filter = WebOperationContext.Current?.IncomingRequest.UriTemplateMatch.QueryParameters["filter"]; CultureInfo locale = GetLocaleFromParameters(); if (filter == null) { if (objectType == null) { filter = "/*"; } else { filter = $"/{objectType}"; } } if (attributes != null) { return(ResourceManagementWebServicev1.GetResponse(Global.Client.GetResources(filter, attributes.Split(','), locale).ToList())); } if (objectType != null) { return(ResourceManagementWebServicev1.GetResponse(Global.Client.GetResources(filter, ResourceManagementSchema.GetObjectType(objectType).Attributes.Select(t => t.SystemName), locale).ToList())); } else { return(ResourceManagementWebServicev1.GetResponse(Global.Client.GetResources(filter, locale).ToList())); } } catch (WebFaultException) { throw; } catch (WebFaultException <ExceptionData> ) { throw; } catch (ResourceManagementException ex) { throw WebExceptionHelper.CreateWebException(HttpStatusCode.BadRequest, ex); } catch (ArgumentException ex) { throw WebExceptionHelper.CreateWebException(HttpStatusCode.BadRequest, ex); } catch (Exception ex) { throw WebExceptionHelper.CreateWebException(HttpStatusCode.InternalServerError, ex); } }
protected override async Task BeginProcessingAsync() { int loadingRetryOnException = 1; Start = DateTime.Now; if (ExportDirectory != null) { RMObserverSetting.ExportDirectory = ExportDirectory; } if (String.IsNullOrEmpty(RMObserverSetting.ExportDirectory)) { Dictionary <string, PSObject> result = Host.UI.Prompt( "EXPORT DIRECTORY", "Enter the path to the export directory", new System.Collections.ObjectModel.Collection <FieldDescription>() { new FieldDescription("Directory") } ); RMObserverSetting.ExportDirectory = result["Directory"].ToString(); } if (!Directory.Exists(RMObserverSetting.ExportDirectory)) { try { Directory.CreateDirectory(RMObserverSetting.ExportDirectory); } catch (Exception ex) { hasException = true; WriteError(new ErrorRecord(ex, "1", ErrorCategory.WriteError, RMObserverSetting.ExportDirectory)); throw ex; } } PrintHeader(); do { try { observedObjects = new List <ResourceObject>(); DateTime startTime = DateTime.Now; var loadingTasks = new List <Task>(); foreach (var config in RMObserverSetting.ObserverObjectSettings) { // Slowup call, otherwise ResourceManagementClient cannot answer the query. if (RMObserverSetting.OnLoadDelayInterval > 0) { await Task.Delay(RMObserverSetting.OnLoadDelayInterval); } if (!hasException) { Host.UI.WriteLine( string.Format("{0,-35} : {1}", config.ObjectType, config.XPathExpression)); } loadingTasks.Add(Task.Run(() => { ObjectTypeDefinition objectType = ResourceManagementSchema.GetObjectType(config.ObjectType); var attributes = objectType.Attributes.Select(t => t.SystemName); observedObjects.AddRange(RmcWrapper.Client.GetResources(config.XPathExpression, attributes)); })); } ; Host.UI.WriteLine(""); Host.UI.Write("Loading object to observer"); while (!Task.WhenAll(loadingTasks).IsCompleted) { await Task.Delay(200); foreach (Task t in loadingTasks.Where(t => t.IsFaulted)) { throw t.Exception; } Host.UI.Write("."); } ; Host.UI.WriteLine(""); Host.UI.WriteLine(String.Format("{0} Objects loaded in {1}", observedObjects.Count, DateTime.Now.Subtract(startTime).ToString())); Host.UI.WriteLine(""); hasException = false; } catch (Exception ex) { WriteError(new ErrorRecord(ex, "2", ErrorCategory.ReadError, null)); hasException = true; loadingRetryOnException++; Host.UI.WriteLine(ConsoleColor.Green, Host.UI.RawUI.BackgroundColor, ""); Host.UI.WriteLine(ConsoleColor.Green, Host.UI.RawUI.BackgroundColor, String.Format("An exception has occured while loading. Retry initial load ({0} / 3)", loadingRetryOnException)); Host.UI.WriteLine(ConsoleColor.Green, Host.UI.RawUI.BackgroundColor, ""); } } while (hasException && loadingRetryOnException < 3); if (!hasException) { if (FullSyncOnStartup.IsPresent) { Host.UI.Write("Processing initial synchronization"); await ProcessingFullSynchronization(); Host.UI.WriteLine(""); Host.UI.Write("Initial synchronization completed."); } Host.UI.WriteLine(""); Host.UI.WriteLine(ConsoleColor.Green, Host.UI.RawUI.BackgroundColor, "Initializing completed"); Host.UI.WriteLine(ConsoleColor.Green, Host.UI.RawUI.BackgroundColor, "Observing changes can be abortet by pressing ESC"); Host.UI.WriteLine(""); } }