internal static void ValidateRulePackage(XDocument rulePackXDoc, string rulePackContents) { string mceExecutablePath = ClassificationDefinitionUtils.GetMceExecutablePath(true); if (mceExecutablePath == null || !File.Exists(mceExecutablePath)) { throw new COMException("Unable to locate the Microsoft Classification Engine", -2147287038); } try { using (ActivationContextActivator.FromInternalManifest(mceExecutablePath, Path.GetDirectoryName(mceExecutablePath))) { MicrosoftClassificationEngine microsoftClassificationEngine = new MicrosoftClassificationEngine(); PropertyBag propertyBag = new PropertyBag(); RulePackageLoader rulePackageLoader = new RulePackageLoader(); microsoftClassificationEngine.Init(propertyBag, rulePackageLoader); RULE_PACKAGE_DETAILS rule_PACKAGE_DETAILS = default(RULE_PACKAGE_DETAILS); rule_PACKAGE_DETAILS.RulePackageSetID = "not-used-here"; rule_PACKAGE_DETAILS.RulePackageID = "test-rule-pack"; rule_PACKAGE_DETAILS.RuleIDs = null; RULE_PACKAGE_DETAILS rule_PACKAGE_DETAILS2 = rule_PACKAGE_DETAILS; rulePackageLoader.SetRulePackage(rule_PACKAGE_DETAILS2.RulePackageID, rulePackContents); try { MicrosoftClassificationEngine microsoftClassificationEngine2 = microsoftClassificationEngine; RULE_PACKAGE_DETAILS rule_PACKAGE_DETAILS3 = rule_PACKAGE_DETAILS2; microsoftClassificationEngine2.GetClassificationDefinitions(ref rule_PACKAGE_DETAILS3); } catch (COMException ex) { if (ex.ErrorCode == -2147220978) { List <string> value = ClassificationEngineValidator.GetInvalidRegexes(microsoftClassificationEngine, rulePackageLoader, rulePackXDoc).ToList <string>(); ex.Data[ClassificationEngineValidator.BadRegexesKey] = value; } throw ex; } } } catch (ActivationContextActivatorException) { throw new COMException("Unable to instantiate the Microsoft Classification Engine", -2147164127); } }
private static void ValidateRulePackageContentsAgainstMce(OrganizationId currentOrganizationId, XDocument rulePackXDocument, string rulePackContents) { Task task = Task.Factory.StartNew(delegate() { ClassificationEngineValidator.ValidateRulePackage(rulePackXDocument, rulePackContents); }); try { task.Wait(30000); } catch (AggregateException ex) { ex.Handle((Exception exception) => ClassificationRuleCollectionRuntimeValidator.HandleClassificationEngineValidatorException(exception, currentOrganizationId)); } if (task.Status != TaskStatus.RanToCompletion) { ClassificationDefinitionsDiagnosticsReporter.Instance.WriteClassificationEngineTimeoutInValidation(0, currentOrganizationId, 30000); throw new ClassificationRuleCollectionTimeoutException(); } }