protected override IConfigurable PrepareDataObject()
        {
            TaskLogger.LogEnter();
            TransportRule transportRule;

            if (this.InstallDefaultCollection && this.existingRulePack != null)
            {
                transportRule = this.existingRulePack;
            }
            else
            {
                transportRule = (TransportRule)base.PrepareDataObject();
                transportRule.SetId(ClassificationDefinitionUtils.GetClassificationRuleCollectionContainerId(base.DataSession).GetChildId(this.rulePackageIdentifier));
                transportRule.OrganizationId = base.CurrentOrganizationId;
            }
            byte[] replicationSignature = null;
            try
            {
                replicationSignature = ClassificationRuleCollectionValidationUtils.PackAndValidateCompressedRulePackage(this.FileData, this.validationContext);
            }
            catch (LocalizedException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidData, null);
            }
            transportRule.AdminDisplayName = this.defaultName;
            transportRule.Xml = null;
            transportRule.ReplicationSignature = replicationSignature;
            TaskLogger.LogExit();
            return(transportRule);
        }
        protected override IConfigurable PrepareDataObject()
        {
            TaskLogger.LogEnter();
            TransportRule transportRule = null;

            try
            {
                transportRule = this.TryGetDataObject();
                XDocument rulePackXDoc;
                if (transportRule == null)
                {
                    transportRule = (TransportRule)base.PrepareDataObject();
                    string rawIdentity = this.ClassificationRuleCollectionIdentity.RawIdentity;
                    transportRule.SetId(ClassificationDefinitionUtils.GetClassificationRuleCollectionContainerId(base.DataSession).GetChildId(rawIdentity));
                    transportRule.OrganizationId = base.CurrentOrganizationId;
                    transportRule.Xml            = null;
                    string organizationId;
                    string name;
                    if (base.CurrentOrganizationId != null && base.CurrentOrganizationId.OrganizationalUnit != null)
                    {
                        organizationId = base.CurrentOrganizationId.OrganizationalUnit.ObjectGuid.ToString();
                        name           = base.CurrentOrganizationId.OrganizationalUnit.Name;
                    }
                    else
                    {
                        organizationId = base.CurrentOrgContainerId.ObjectGuid.ToString();
                        name           = base.CurrentOrgContainerId.DomainId.Name;
                    }
                    rulePackXDoc = ClassificationDefinitionUtils.CreateRuleCollectionDocumentFromTemplate(rawIdentity, organizationId, name);
                }
                else
                {
                    rulePackXDoc = ClassificationDefinitionUtils.GetRuleCollectionDocumentFromTransportRule(transportRule);
                }
                this.implementation = new DataClassificationCmdletsImplementation(this);
                this.implementation.Initialize(transportRule, rulePackXDoc);
            }
            catch (LocalizedException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidOperation, null);
            }
            TaskLogger.LogExit();
            return(transportRule);
        }
예제 #3
0
        internal override IEnumerable <T> GetObjects <T>(ADObjectId rootId, IDirectorySession session, IDirectorySession subTreeSession, OptionalIdentityData optionalData, out LocalizedString?notFoundReason)
        {
            IEnumerable <T> enumerable = Enumerable.Empty <T>();

            if (this.ShouldIncludeOutOfBoxCollections && VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled && base.InternalADObjectId == null)
            {
                bool flag  = false;
                bool flag2 = OrganizationId.ForestWideOrgId.Equals(session.SessionSettings.CurrentOrganizationId);
                if (flag2 && this.IsHierarchical && this.IsHierarchyValid)
                {
                    ClassificationRuleCollectionIdParameter classificationRuleCollectionIdParameter = new ClassificationRuleCollectionIdParameter(this.FriendlyName);
                    enumerable = classificationRuleCollectionIdParameter.GetObjects <T>(rootId, (IConfigDataProvider)session, optionalData, out notFoundReason);
                    flag       = true;
                }
                else if (!flag2 && !this.IsHierarchical)
                {
                    ITopologyConfigurationSession session2 = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(true, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 431, "GetObjects", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\transport\\ClassificationDefinitions\\ClassificationRuleCollectionIdParameter.cs");
                    enumerable = base.GetObjects <T>(ClassificationDefinitionUtils.GetClassificationRuleCollectionContainerId(session2), session2, null, out notFoundReason);
                    flag       = true;
                }
                if (flag)
                {
                    if (optionalData == null)
                    {
                        optionalData = new OptionalIdentityData();
                    }
                    List <T>    list        = enumerable.ToList <T>();
                    QueryFilter queryFilter = ClassificationRuleCollectionIdParameter.CreateExcludeFilter <T>(list);
                    if (queryFilter != null)
                    {
                        optionalData.AdditionalFilter = ((optionalData.AdditionalFilter == null) ? queryFilter : QueryFilter.AndTogether(new QueryFilter[]
                        {
                            optionalData.AdditionalFilter,
                            queryFilter
                        }));
                    }
                    enumerable = list;
                }
            }
            return(enumerable.Concat(base.GetObjects <T>(rootId, session, subTreeSession, optionalData, out notFoundReason)));
        }
        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);
        }