public static RuntimeDefinedParameter GetObjectTypeParameter(string paramName, bool mandatory, int position, bool allowWildcard, string parameterSetName) { RuntimeDefinedParameter parameter = new RuntimeDefinedParameter(); parameter.Name = paramName; parameter.ParameterType = typeof(string); IList <ObjectTypeDefinition> objectTypes = ResourceManagementSchema.GetObjectTypes().ToList(); if (objectTypes.Count > 0) { List <string> objectTypeNames = objectTypes.OrderBy(t => t.SystemName).Select(t => t.SystemName).ToList(); if (allowWildcard) { objectTypeNames.Add("*"); } ValidateSetAttribute setAttribute = new ValidateSetAttribute(objectTypeNames.ToArray()); parameter.Attributes.Add(setAttribute); } ParameterAttribute paramAttribute = new ParameterAttribute(); paramAttribute.Mandatory = mandatory; paramAttribute.Position = position; paramAttribute.ParameterSetName = parameterSetName; parameter.Attributes.Add(paramAttribute); return(parameter); }
public Stream GetResourceByKey(string objectType, string key, string keyValue) { try { ResourceManagementSchema.ValidateAttributeName(key); ResourceManagementSchema.ValidateObjectTypeName(objectType); CultureInfo locale = WebResponseHelper.GetLocale(); ResourceObject resource = Global.Client.GetResourceByKey(objectType, key, keyValue, locale); if (resource == null) { throw new ResourceNotFoundException(); } return(WebResponseHelper.GetResponse(resource, false)); } catch (WebFaultException) { throw; } catch (WebFaultException <Error> ) { throw; } catch (Exception ex) { ResourceManagementWebServicev2.HandleException(ex); throw; } }
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 void RemoveAttributeValue(string id, string attribute, string value) { try { ResourceManagementSchema.ValidateAttributeName(attribute); ResourceManagementWebServicev2.ValidateID(id); CultureInfo locale = WebResponseHelper.GetLocale(); ResourceObject resource; if (ResourceManagementSchema.IsAttributeMultivalued(attribute)) { resource = Global.Client.GetResource(id, locale); } else { resource = Global.Client.GetResource(id, new[] { attribute }, locale); } if (resource == null) { throw new ResourceNotFoundException(); } if (!resource.Attributes.ContainsAttribute(attribute)) { WebResponseHelper.ThrowAttributeNotFoundException(attribute); } resource.Attributes[attribute].RemoveValue(value, true); Global.Client.SaveResource(resource, locale); WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NoContent; } catch (WebFaultException) { throw; } catch (WebFaultException <Error> ) { throw; } catch (Exception ex) { ResourceManagementWebServicev2.HandleException(ex); throw; } }
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 Stream GetResourceByKey(string objectType, string key, string keyValue) { ResourceObject resource; try { ResourceManagementSchema.ValidateAttributeName(key); ResourceManagementSchema.ValidateObjectTypeName(objectType); CultureInfo locale = GetLocaleFromParameters(); resource = Global.Client.GetResourceByKey(objectType, key, keyValue, locale); if (resource == null) { throw new ResourceNotFoundException(); } } catch (WebFaultException) { throw; } catch (WebFaultException <ExceptionData> ) { throw; } catch (ResourceNotFoundException) { throw WebExceptionHelper.CreateWebException(HttpStatusCode.NotFound); } 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); } return(ResourceManagementWebServicev1.GetResponse(resource)); }
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); }
public Stream GetResourceAttributeByID(string id, string attribute) { try { ResourceManagementSchema.ValidateAttributeName(attribute); ResourceManagementWebServicev2.ValidateID(id); CultureInfo locale = WebResponseHelper.GetLocale(); ResourceObject resource = Global.Client.GetResource(id, new[] { attribute }, locale); if (resource == null) { throw new ResourceNotFoundException(); } if (!resource.Attributes.ContainsAttribute(attribute)) { WebResponseHelper.ThrowAttributeNotFoundException(attribute); } List <string> result = resource.Attributes[attribute].ToStringValues().ToList(); return(WebResponseHelper.GetResponse(result, true)); } catch (WebFaultException) { throw; } catch (WebFaultException <Error> ) { throw; } catch (Exception ex) { ResourceManagementWebServicev2.HandleException(ex); throw; } }
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); } }
public KeyValuePair <string, string[]> GetResourceAttributeByKey(string objectType, string key, string keyValue, string attribute) { try { ResourceManagementSchema.ValidateAttributeName(attribute); ResourceManagementSchema.ValidateObjectTypeName(objectType); CultureInfo locale = GetLocaleFromParameters(); ResourceObject resource = Global.Client.GetResourceByKey(objectType, key, keyValue, new List <string>() { attribute }, locale); if (resource == null) { throw new ResourceNotFoundException(); } object value = resource.Attributes[attribute].Value; List <string> valuesToReturn = new List <string>(); if (value is string) { valuesToReturn.Add(value as string); } else if (value is byte[]) { valuesToReturn.Add(Convert.ToBase64String((byte[])value)); } else { IEnumerable values = value as IEnumerable; if (values != null) { foreach (object enumvalue in values) { if (enumvalue is DateTime) { valuesToReturn.Add(((DateTime)enumvalue).ToResourceManagementServiceDateFormat()); } else if (enumvalue is byte[]) { valuesToReturn.Add(Convert.ToBase64String((byte[])enumvalue)); } else { valuesToReturn.Add(enumvalue.ToString()); } } } else { valuesToReturn.Add(value.ToString()); } } return(new KeyValuePair <string, string[]>(attribute, valuesToReturn.ToArray())); } catch (WebFaultException) { throw; } catch (WebFaultException <ExceptionData> ) { throw; } catch (ResourceNotFoundException) { throw WebExceptionHelper.CreateWebException(HttpStatusCode.NotFound); } 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); } }
/// <summary> /// Initializes a new instance of the XPathDereferencedExpression class /// </summary> /// <param name="objectType">The object type used in the expression</param> /// <param name="dereferenceAttribute">The name of the attribute to dereference</param> /// <param name="query">The query used to build the expression</param> /// <param name="wrapFilterXml">Indicates if the resulting expression should be wrapped in an XML filter element</param> public XPathDereferencedExpression(string objectType, string dereferenceAttribute, IXPathQueryObject query, bool wrapFilterXml) : base(objectType, query, wrapFilterXml) { this.DereferenceAttribute = dereferenceAttribute; ResourceManagementSchema.ValidateObjectTypeName(this.DereferenceAttribute); }
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(""); } }