private void AddOnePolicySetVersionASZipEntry( IPolicySetVersionCache version, ZipOutputStream zipOutputStream, bool runtime) { string policySetVersion = WritePolicySetVersion(version, runtime); string entryName = version.Version + "/policysetversion.xml"; AddZipEntryToZipOutputStream(zipOutputStream, policySetVersion, entryName); }
private void CompileNxBrePolicySet(IPolicySetVersionCache version, IPolicySet policySet, string target) { if ((null == version) || (null == policySet) || (string.IsNullOrEmpty(target))) return; NxPolicyStore nxBreStore = new NxPolicyStore(); nxBreStore.ResourceManager = ResourcesCache.GetResources(); policySet.Export(nxBreStore); CompiledPolicySetExtractor cpse = new CompiledPolicySetExtractor(nxBreStore.XMLRepresentation); List<string> channels = cpse.GetChannelNames(); foreach (string channel in channels) { string objects = cpse.GetObjects(channel); string rules = cpse.GetRules(channel); ICompiledPolicySetCache cps = version.GetCompiledPolicySet(channel, target); if (cps == null) { cps = version.NewCompiledPolicySet(channel, target, rules, objects); } else { cps.Content = rules; cps.ObjectReferences = objects; } SaveLanguages(cpse.GetLanguages(), cps); } }
public void SaveCompiledStreams(IPolicySetVersionCache version, IPolicySet policySet) { if ((null == version) || (null == policySet)) return; CompileNxBrePolicySet(version, policySet, "Client"); }
/// <summary> /// This method removes old compiled policies from a version cache. /// </summary> /// <param name="version">The PolicySetVersionCache to remove the items from</param> /// <param name="targets">The names of the target types you wish to remove.</param> private static void RemoveExistingPolicies(IPolicySetVersionCache version, string[] targets) { if (version.GetType() == typeof(Workshare.Policy.ClientCache.LocalPolicySetVersionCache)) { foreach (string target in targets) { TargetMatchPredicate matchingPredicate = new TargetMatchPredicate(target); version.CompiledPolicySets.RemoveAll(matchingPredicate.Evaluate); } } }
public BaseContentScanner(string name, IPolicySetVersionCache cache, PolicyType policyType, string runAt) { SkipDiscovery = false; m_policySetName = name; m_cache = cache; //keep it for cloning. m_runAt = (RunAt) Enum.Parse(typeof(RunAt), runAt); m_policyType = policyType; string channel = GetChannelForPolicyType(policyType); //Get the primary compiled cache ICompiledPolicySetCache icpsc = cache.GetCompiledPolicySet(channel, runAt); m_gpp = InitialiseGPP(icpsc); //For performance, a separate cache is available for messages with 0 attachments - this will be passed to a //separate policy processor. if (PolicyType.ClientEmail == policyType || PolicyType.Mta == policyType) { foreach (ICompiledPolicySetCache compiled in cache.CompiledPolicySets) { //Ignore any other channels that we come across. if (channel != compiled.Channel) continue; //Perfect matches on 'target' should be discarded - we already found the primary cache in the call to GetCompiledPolicySet. if (0 == string.Compare(runAt, compiled.Target, StringComparison.InvariantCultureIgnoreCase)) continue; if (compiled.Target.Contains(runAt)) { m_zeroAttachmentGpp = InitialiseGPP(compiled); break; //Assumes that (for example) the 'Client - reduced policy set' compiled cache will always contain the word 'Client' } } } }
private void ShowPolicySetVersion(IPolicySetVersionCache psv) { Version verForm = new Version(psv); ShowDetail(verForm); }
private string GetVersionNodeString(IPolicySetVersionCache version) { string nodestring = version.Version + ((version.Latest) ? " (latest)" : ""); nodestring += " " + version.Status; return nodestring; }
public Version(IPolicySetVersionCache version) { InitializeComponent(); xmlTreeView1.Xml = version.Content; }
/// <summary> /// This constructor will initialise the internal members /// </summary> public PolicySetCache() { m_versionCache = new PolicySetVersionCache(); }
private static void SetVersionStatus(IPolicySetVersionCache policySetCache, PolicySetVersionStatus version) { // TODO: AP: Why not make IPolicySetVersionCache.Status writable? if (policySetCache is LocalPolicySetVersionCache) { (policySetCache as LocalPolicySetVersionCache).Status = version; } else { throw new NotImplementedException(string.Format(CultureInfo.CurrentCulture,"Unhandled policy set cache type \"{0}\"",policySetCache.GetType())); } }
/// <summary> /// Creates a new policy set version (default is <see cref="LocalPolicySetVersionCache">) /// </summary> public virtual IPolicySetVersionCache NewVersionCache(IPolicySetVersionCache existing, string version, bool latest, PolicySetVersionStatus status) { return new LocalPolicySetVersionCache((LocalPolicySetVersionCache)existing, version, latest, status); }
private string WritePolicySetVersion(IPolicySetVersionCache version, bool runtime) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "yes"); XmlElement root = xmlDoc.CreateElement("PolicySet"); XmlAttribute id = xmlDoc.CreateAttribute("id"); id.Value = Convert.ToString((version as LocalPolicySetVersionCache).ID, CultureInfo.InvariantCulture); XmlAttribute rootname = xmlDoc.CreateAttribute("name"); rootname.Value = version.GetName("en"); root.Attributes.Append(id); root.Attributes.Append(rootname); XmlElement content = xmlDoc.CreateElement("Content"); if (!runtime) { content.InnerXml = version.Content; } // create the catalogues XmlElement cats = xmlDoc.CreateElement("Catalogues"); if (!runtime) { //add the master cat if (version.MasterCatalogue != null) cats.AppendChild(WriteCatalogueInfo(xmlDoc, version.MasterCatalogue, true)); //add the ref catalogues foreach (IPolicyCatalogueCache cat in version.ReferenceCatalogues) cats.AppendChild(WriteCatalogueInfo(xmlDoc, cat, false)); } // create the compiled policy sets XmlElement compiledsets = xmlDoc.CreateElement("CompiledPolicySets"); foreach (ICompiledPolicySetCache cps in version.CompiledPolicySets) { if (cps.Target == "Client" && ((cps.Channel == "SMTP") || (cps.Channel == "ActiveContent"))) compiledsets.AppendChild(WriteCompiledPolicySetInfo(xmlDoc, cps)); } root.AppendChild(content); root.AppendChild(cats); root.AppendChild(compiledsets); xmlDoc.AppendChild(root); return xmlDoc.OuterXml; }
internal static void TestVersionIsReadOnly(IPolicySetVersionCache version) { try { version.Content = "try and update"; Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } try { version.NewCompiledPolicySet("", "", "", ""); Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } try { version.NewMasterCatalogue(""); Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } try { version.NewReferenceCatalgue(""); Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } foreach (ICompiledPolicySetCache cps in version.CompiledPolicySets) { if (cps != null) { try { cps.Content = "try and update"; Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } try { cps.ObjectReferences = "try and update"; Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } try { cps.NewLanguage("", "", false); Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } foreach (IPolicyLanguageTableCache lplt in cps.Languages) { try { lplt.Content = "try and update"; Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } } } } if (version.MasterCatalogue != null) { try { version.MasterCatalogue.Content = "try and update"; Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } try { version.MasterCatalogue.NewLanguage("", "", false); Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } foreach (IPolicyLanguageTableCache lplt in version.MasterCatalogue.Languages) { try { lplt.Content = "try and update"; Assert.Fail("Failed to throw exception when updating a read-only version"); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Unable to update version information, this version is not the latest and therefore read-only"); } } } }