public void Initialize() { SqlBuildManager.Enterprise.EnterpriseConfiguration cfg = new EnterpriseConfiguration(); TableWatch tmp = new TableWatch(); tmp.Description = "For Testing"; tmp.EmailBody = "Email Body for Testing"; tmp.EmailSubject = "Email subject for testing"; Notify n = new Notify(); n.EMail = "*****@*****.**"; Notify b = new Notify(); n.EMail = "*****@*****.**"; tmp.Notify = new Notify[2]; tmp.Notify[0] = n; tmp.Notify[1] = b; tmp.Table = new Table[2]; Table t = new Table(); t.Name = "SqlBuild_Logging"; Table a = new Table(); a.Name = "master"; tmp.Table[0] = t; tmp.Table[1] = a; cfg.TableWatch = new TableWatch[1]; cfg.TableWatch[0] = tmp; EnterpriseConfigHelper.EnterpriseConfig = cfg; }
public bool Transform() { var configuration = new EnterpriseConfiguration(); string licensePath = "C:/Program Files/Saxonica/SaxonEE10.3N/bin/saxon-license.lic"; var licenseFile = new FileStream(licensePath, FileMode.Open); configuration.setConfigurationProperty(FeatureKeys.LICENSE_FILE_LOCATION, licensePath); var features = configuration.getLicenseFeature(FeatureKeys.OPTIMIZATION_LEVEL);; var teste1 = configuration.isLicenseFound(); //var teste42 = configuration.isLicensedFeature(FeatureKeys.OPTIMIZATION_LEVEL.); //var configUri = new Uri($@"{_rootPath}\SaxonXsltTransformer\config.xsd"); //var stream = new FileStream(configUri.OriginalString, FileMode.Open); //var processor = new Processor(stream, configUri); var processor = new Processor(true); var xsltCompiler = processor.NewXsltCompiler(); var xslUri = new Uri($@"{_rootPath}\BuiltInXsltTransformer\RawData.xsl"); var xsltExecutable = xsltCompiler.Compile(xslUri); var sourceDocument = processor.NewDocumentBuilder().Build(_xmlDocument); var xsltTransformer = xsltExecutable.Load(); xsltTransformer.InitialContextNode = sourceDocument; var destination = new XdmDestination(); xsltTransformer.Run(destination); ResultDocument = destination.XdmNode; return(true); }
public void GetPoliciesTest_AddDynamicIScriptPolicies() { EnterpriseConfiguration cfg = new EnterpriseConfiguration(); ScriptPolicy pol1 = new ScriptPolicy(); pol1.PolicyId = PolicyIdKey.WithNoLockPolicy; pol1.Enforce = true; ScriptPolicy pol2 = new ScriptPolicy(); pol2.PolicyId = PolicyIdKey.GrantExecutePolicy; pol2.Enforce = true; cfg.ScriptPolicy = new ScriptPolicy[] { pol1, pol2 }; EnterpriseConfigHelper.EnterpriseConfig = cfg; List <IScriptPolicy> actual; actual = PolicyHelper.GetPolicies(); Assert.IsTrue(actual.Count == 2, "Expected 2 policies but got " + actual.Count.ToString()); Assert.IsTrue(actual[0] is WithNoLockPolicy); Assert.IsTrue(actual[1] is GrantExecutePolicy); }
public void GetPoliciesTest_AddDynamicStoredProcParamPolicies() { EnterpriseConfiguration cfg = new EnterpriseConfiguration(); ScriptPolicyArgument arg = new ScriptPolicyArgument(); arg.Name = "Schema"; arg.Value = "dbo"; ScriptPolicy pol1 = new ScriptPolicy(); pol1.PolicyId = PolicyIdKey.StoredProcParameterPolicy; pol1.Enforce = true; pol1.Argument = new ScriptPolicyArgument[] { arg }; ScriptPolicy pol2 = new ScriptPolicy(); pol2.PolicyId = PolicyIdKey.StoredProcParameterPolicy; pol2.Enforce = true; pol2.Argument = new ScriptPolicyArgument[] { arg }; cfg.ScriptPolicy = new ScriptPolicy[] { pol1, pol2 }; EnterpriseConfigHelper.EnterpriseConfig = cfg; List <IScriptPolicy> actual; actual = PolicyHelper.GetPolicies(); Assert.IsTrue(actual.Count == 2, "Expected 2 policies but got " + actual.Count.ToString()); Assert.IsTrue(actual[0] is StoredProcParameterPolicy); Assert.IsTrue(actual[1] is StoredProcParameterPolicy); }
public void FeatureAccessTest_GetAndSet() { EnterpriseConfiguration target = new EnterpriseConfiguration(); FeatureAccess acc = new FeatureAccess(); acc.FeatureId = "TestID"; acc.Enabled = true; FeatureAccess[] expected = new FeatureAccess[] { acc }; FeatureAccess[] actual; target.FeatureAccess = expected; actual = target.FeatureAccess; Assert.AreEqual(expected, actual); }
public static List <p.IScriptPolicy> GetPolicies() { if (activePolicies != null && activePolicies.Count > 0) { return(activePolicies); } activePolicies = new List <p.IScriptPolicy>(); EnterpriseConfiguration cfg = EnterpriseConfigHelper.EnterpriseConfig; if (cfg.ScriptPolicy != null && cfg.ScriptPolicy.Length > 0) { foreach (ScriptPolicy policy in cfg.ScriptPolicy) { if (!policy.Enforce) { continue; } if (allPolicies.ContainsKey(policy.PolicyId)) { if ((allPolicies[policy.PolicyId] is p.IScriptPolicyMultiple)) //Create new instances for "Multiple" items... { p.IScriptPolicyMultiple tmpNew = (p.IScriptPolicyMultiple)Activator.CreateInstance(allPolicies[policy.PolicyId].GetType()); p.ViolationSeverity severity; p.ViolationSeverity.TryParse(policy.Severity.ToString(), true, out severity); tmpNew.Severity = severity; if (policy.ScriptPolicyDescription != null) { if (policy.ScriptPolicyDescription.ErrorMessage.Length > 0) { tmpNew.ErrorMessage = policy.ScriptPolicyDescription.ErrorMessage; } if (policy.ScriptPolicyDescription.LongDescription.Length > 0) { tmpNew.LongDescription = policy.ScriptPolicyDescription.LongDescription; } if (policy.ScriptPolicyDescription.ShortDescription.Length > 0) { tmpNew.ShortDescription = policy.ScriptPolicyDescription.ShortDescription; } } tmpNew.Severity = (SqlBuildManager.Interfaces.ScriptHandling.Policy.ViolationSeverity) Enum.Parse(typeof(SqlBuildManager.Interfaces.ScriptHandling.Policy.ViolationSeverity), policy.Severity.ToString()); if (policy.Argument != null) { foreach (ScriptPolicyArgument argument in policy.Argument) { tmpNew.Arguments.Add(new p.IScriptPolicyArgument() { Name = argument.Name, Value = argument.Value, IsGlobalException = argument.IsGlobalException, IsLineException = argument.IsLineException, FailureMessage = argument.FailureMessage, }); } } activePolicies.Add(tmpNew); } else if ((allPolicies[policy.PolicyId] is p.IScriptPolicyWithArguments) && policy.Argument != null) //Add arguments as needed { foreach (ScriptPolicyArgument argument in policy.Argument) { ((p.IScriptPolicyWithArguments)allPolicies[policy.PolicyId]).Arguments.Add(new p.IScriptPolicyArgument() { Name = argument.Name, Value = argument.Value, IsGlobalException = argument.IsGlobalException, IsLineException = argument.IsLineException, FailureMessage = argument.FailureMessage }); } allPolicies[policy.PolicyId].Severity = (SqlBuildManager.Interfaces.ScriptHandling.Policy.ViolationSeverity) Enum.Parse(typeof(SqlBuildManager.Interfaces.ScriptHandling.Policy.ViolationSeverity), policy.Severity.ToString()); activePolicies.Add(allPolicies[policy.PolicyId]); } else if (allPolicies[policy.PolicyId] is p.IScriptPolicy) { allPolicies[policy.PolicyId].Severity = (SqlBuildManager.Interfaces.ScriptHandling.Policy.ViolationSeverity) Enum.Parse(typeof(SqlBuildManager.Interfaces.ScriptHandling.Policy.ViolationSeverity), policy.Severity.ToString()); activePolicies.Add(allPolicies[policy.PolicyId]); } } else { log.LogWarning($"Unable to load unknown ScriptPolicy \"{policy.PolicyId}\""); } } log.LogDebug($"Loaded {activePolicies.Count.ToString()} script policy objects from EnterpriseConfiguration"); } else { log.LogWarning("No EnterpriseConfiguration settings found for ScriptPolicies. Loading all default policies"); activePolicies.AddRange(allPolicies.Values); } //Get only those that are "turned on" var a = from p in activePolicies where p.Enforce == true select p; if (a.Count() > 0) { activePolicies = a.ToList(); } log.LogDebug($"Loaded {activePolicies.Count.ToString()} script policy objects"); return(activePolicies); }