/// <summary> /// Initializes a new instance of the ResourceObject class /// </summary> /// <param name="opType">The type of modification to set on the object</param> /// <param name="client">The client used for further operations on this object</param> /// <param name="locale">The localization culture that this object is represented as</param> private ResourceObject(OperationType opType, ResourceManagementClient client, CultureInfo locale) { this.ModificationType = opType; this.attributes = new AttributeValueCollection(); this.client = client; this.Locale = locale; }
/// <summary> /// Sets the internal attribute value collection with the initial values contained in the dictionary /// </summary> /// <param name="values">The initial attributes and values to set</param> /// <param name="permissions">The permission hints for the attributes</param> private void SetInitialAttributeValues(Dictionary <string, List <string> > values, Dictionary <string, AttributePermission> permissions) { this.attributes = new AttributeValueCollection(); this.HasPermissionHints = false; foreach (KeyValuePair <string, List <string> > kvp in values) { string attributeName = kvp.Key; AttributeTypeDefinition d = this.ObjectType[attributeName]; AttributePermission p = AttributePermission.Unknown; if (permissions != null) { if (permissions.ContainsKey(attributeName)) { p = permissions[attributeName]; if (p != AttributePermission.Unknown) { this.HasPermissionHints = true; } } } if (d != null) { if (!d.IsMultivalued && kvp.Value.Count > 1) { throw new InvalidOperationException($"The attribute {d.SystemName} is listed in the schema as a multivalued attribute, but more than one value was returned"); } if (kvp.Value.Count == 0) { this.attributes.Add(d.SystemName, new AttributeValue(d, p)); continue; } if (d.IsMultivalued) { this.attributes.Add(d.SystemName, new AttributeValue(d, p, kvp.Value)); } else { this.attributes.Add(d.SystemName, new AttributeValue(d, p, kvp.Value.First())); } if (d.SystemName == AttributeNames.Locale) { this.Locale = new CultureInfo(kvp.Value.First()); } } } this.AddRemainingAttributesFromSchema(); }
/// <summary> /// Sets the internal attribute value collection with the initial values contained in the dictionary /// </summary> /// <param name="values">The initial attributes and values to set</param> private void SetInitialAttributeValues(Dictionary<string, List<string>> values) { this.attributes = new AttributeValueCollection(); foreach (KeyValuePair<string, List<string>> kvp in values) { if (kvp.Value.Count == 0) { continue; } string attributeName = kvp.Key; AttributeTypeDefinition d = this.ObjectType[attributeName]; if (d != null) { if (!d.IsMultivalued && kvp.Value.Count > 1) { throw new InvalidOperationException("The attribute {0} is listed in the schema as a multivalued attribute, but more than one value was returned"); } if (d.IsMultivalued) { this.attributes.Add(d.SystemName, new AttributeValue(d, kvp.Value)); } else { this.attributes.Add(d.SystemName, new AttributeValue(d, kvp.Value.First())); } if (d.SystemName == AttributeNames.Locale) { this.Locale = new CultureInfo(kvp.Value.First()); } } } this.AddRemainingAttributesFromSchema(); }