private void InternalSave(ValidationContext validationContext, bool force) { ArgumentValidator.ThrowIfNull("validationContext", validationContext); bool flag = XmlProcessingUtils.OptimizeRulePackXDoc(this.rulePackXDocument, validationContext.DcValidationConfig); if (force || flag || this.DataClassificationPresentationObject.IsDirty) { XElement rulePackageMetadataElement = XmlProcessingUtils.GetRulePackageMetadataElement(this.rulePackXDocument); ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails = XmlProcessingUtils.ReadDefaultRulePackageMetadata(rulePackageMetadataElement); this.adRulePack.AdminDisplayName = classificationRuleCollectionLocalizableDetails.Name; this.adRulePack.ReplicationSignature = this.GetCompressedFileData(validationContext); } }
internal static ClassificationRuleCollectionLocalizableDetails ReadRulePackageMetadata(XElement rulePackDetailsElement, CultureInfo cultureInfo = null) { ArgumentValidator.ThrowIfNull("rulePackDetailsElement", rulePackDetailsElement); ClassificationRuleCollectionLocalizableDetails result; try { string langCodeToUse = (cultureInfo != null) ? cultureInfo.Name : rulePackDetailsElement.Attribute("defaultLangCode").Value; XElement xelement = (from localizedDetails in rulePackDetailsElement.Elements(XmlProcessingUtils.GetMceNsQualifiedNodeName("LocalizedDetails")).AsParallel <XElement>() where langCodeToUse.Equals(localizedDetails.Attribute("langcode").Value, StringComparison.OrdinalIgnoreCase) select localizedDetails).SingleOrDefault <XElement>(); if (xelement != null) { string value = xelement.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("Name")).Value; string value2 = xelement.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("PublisherName")).Value; string value3 = xelement.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("Description")).Value; result = new ClassificationRuleCollectionLocalizableDetails { Name = value, PublisherName = value2, Description = value3, Culture = new CultureInfo(langCodeToUse, false) }; } else { if (cultureInfo == null) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents); } result = null; } } catch (NullReferenceException innerException) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, innerException); } catch (InvalidOperationException innerException2) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, innerException2); } catch (AggregateException ex) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, ex.Flatten()); } catch (CultureNotFoundException innerException3) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, innerException3); } return(result); }
private string ValidateAndReadMetadata(byte[] rulePackageRawData) { string result = null; try { XDocument xdocument = XmlProcessingUtils.ValidateRulePackageXmlContentsLite(rulePackageRawData); this.rulePackageIdentifier = XmlProcessingUtils.GetRulePackId(xdocument); this.rulePackVersion = (this.InstallDefaultCollection ? XmlProcessingUtils.SetRulePackVersionFromAssemblyFileVersion(xdocument) : XmlProcessingUtils.GetRulePackVersion(xdocument)); ClassificationRuleCollectionIdParameter classificationRuleCollectionIdParameter = ClassificationRuleCollectionIdParameter.Parse("*"); classificationRuleCollectionIdParameter.ShouldIncludeOutOfBoxCollections = true; List <TransportRule> list = base.GetDataObjects <TransportRule>(classificationRuleCollectionIdParameter, base.DataSession, ClassificationDefinitionUtils.GetClassificationRuleCollectionContainerId(base.DataSession)).ToList <TransportRule>(); this.existingRulePack = list.FirstOrDefault((TransportRule transportRule) => transportRule.Name.Equals(this.rulePackageIdentifier, StringComparison.OrdinalIgnoreCase)); this.validationContext = new ValidationContext(this.InstallDefaultCollection ? ClassificationRuleCollectionOperationType.ImportOrUpdate : ClassificationRuleCollectionOperationType.Import, base.CurrentOrganizationId, this.InstallDefaultCollection || (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled && this.OutOfBoxCollection), false, (IConfigurationSession)base.DataSession, this.existingRulePack, null, null); if (this.validationContext.DcValidationConfig != null && list.Count >= this.validationContext.DcValidationConfig.MaxRulePackages) { base.WriteError(new ClassificationRuleCollectionNumberExceedLimit(this.validationContext.DcValidationConfig.MaxRulePackages), ErrorCategory.InvalidOperation, null); } result = ClassificationRuleCollectionValidationUtils.ValidateRulePackageContents(this.validationContext, xdocument); this.rulePackageDetailsElement = XmlProcessingUtils.GetRulePackageMetadataElement(xdocument); ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails = XmlProcessingUtils.ReadDefaultRulePackageMetadata(this.rulePackageDetailsElement); this.defaultName = classificationRuleCollectionLocalizableDetails.Name; ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails2 = XmlProcessingUtils.ReadRulePackageMetadata(this.rulePackageDetailsElement, CultureInfo.CurrentCulture); this.localizedName = ((classificationRuleCollectionLocalizableDetails2 != null && classificationRuleCollectionLocalizableDetails2.Name != null) ? classificationRuleCollectionLocalizableDetails2.Name : this.defaultName); } catch (ClassificationRuleCollectionVersionValidationException ex) { this.WriteWarning(ex.LocalizedString); } catch (ClassificationRuleCollectionAlreadyExistsException exception) { base.WriteError(exception, ErrorCategory.InvalidOperation, null); } catch (ClassificationRuleCollectionInternalValidationException ex2) { base.WriteError(ex2, (-2147287038 == ex2.Error) ? ErrorCategory.ObjectNotFound : ErrorCategory.InvalidResult, null); } catch (ClassificationRuleCollectionTimeoutException exception2) { base.WriteError(exception2, ErrorCategory.OperationTimeout, null); } catch (LocalizedException exception3) { base.WriteError(exception3, ErrorCategory.InvalidData, null); } return(result); }
private string ValidateAgainstBusinessRulesAndReadMetadata(XDocument rulePackXDoc) { ExAssert.RetailAssert(this.rulePackageIdentifier != null && this.DataObject != null, "Business rules validation in Set-ClassificationRuleCollection must take place after the DataObject resolution"); string result = string.Empty; try { this.validationContext = new ValidationContext(ClassificationRuleCollectionOperationType.Update, base.CurrentOrganizationId, VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled && this.OutOfBoxCollection, false, (IConfigurationSession)base.DataSession, this.DataObject, null, null); result = ClassificationRuleCollectionValidationUtils.ValidateRulePackageContents(this.validationContext, rulePackXDoc); ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails = XmlProcessingUtils.ReadDefaultRulePackageMetadata(rulePackXDoc); this.defaultName = classificationRuleCollectionLocalizableDetails.Name; ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails2 = XmlProcessingUtils.ReadRulePackageMetadata(rulePackXDoc, CultureInfo.CurrentCulture); this.localizedName = ((classificationRuleCollectionLocalizableDetails2 != null && classificationRuleCollectionLocalizableDetails2.Name != null) ? classificationRuleCollectionLocalizableDetails2.Name : this.defaultName); if (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled && OrganizationId.ForestWideOrgId.Equals(((IDirectorySession)base.DataSession).SessionSettings.CurrentOrganizationId)) { this.WriteWarning(Strings.ClassificationRuleCollectionIneffectiveSharingViolationCheck); } SortedSet <string> sortedSet = new SortedSet <string>(); IList <string> deletedRulesInUse = ClassificationRuleCollectionValidationUtils.GetDeletedRulesInUse(base.DataSession, this.DataObject, sortedSet, rulePackXDoc); if (deletedRulesInUse.Count > 0) { LocalizedString message = Strings.ClassificationRuleCollectionSharingViolationSetOperationVerbose(this.localizedName ?? this.rulePackageIdentifier, string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, deletedRulesInUse), string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, sortedSet)); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionSharingViolationException, IList <string> >(new ClassificationRuleCollectionSharingViolationException(message), deletedRulesInUse); } } catch (ClassificationRuleCollectionSharingViolationException exception) { base.WriteError(exception, ErrorCategory.InvalidOperation, null); } catch (ClassificationRuleCollectionInternalValidationException ex) { base.WriteError(ex, (-2147287038 == ex.Error) ? ErrorCategory.ObjectNotFound : ErrorCategory.InvalidResult, null); } catch (ClassificationRuleCollectionTimeoutException exception2) { base.WriteError(exception2, ErrorCategory.OperationTimeout, null); } catch (LocalizedException exception3) { base.WriteError(exception3, ErrorCategory.InvalidData, null); } return(result); }