/// <summary> /// Disables all versions in a policy set that are not equal to the latest version /// </summary> public static void DisableOldVersions(IPolicySetCache cache) { IPolicySetVersionCache ver = (LocalPolicySetVersionCache)cache.LatestVersion; foreach (IPolicySetVersionCache versions in cache.PolicySetVersions) { if (0 == string.Compare(ver.Version, versions.Version)) continue; if (versions.Status == PolicySetVersionStatus.Enabled) versions.Status = PolicySetVersionStatus.Disabled; } }
private void WriteToZipStream(ZipOutputStream zipOutputStream, IPolicySetCache set, bool runtime) { const int maxCompression = 9; zipOutputStream.SetLevel(maxCompression); AddZipEntryToZipOutputStream(zipOutputStream, WritePolicySetProperties(set, runtime), "properties.xml"); AddOnePolicySetVersionASZipEntry(set.LatestVersion, zipOutputStream, runtime); zipOutputStream.Flush(); zipOutputStream.Finish(); }
public void WriteFile(IPolicySetCache set, string filename, bool runtime) { using (System.IO.MemoryStream outputMemoryStream = new System.IO.MemoryStream()) { using (ZipOutputStream zipOutputStream = new ZipOutputStream(outputMemoryStream)) { WriteToZipStream(zipOutputStream, set, runtime); Crypto.Instance.WriteStreamToEncryptedFile(outputMemoryStream, filename); } } }
public System.IO.Stream WriteToStream(IPolicySetCache set, bool runtime) { using (System.IO.MemoryStream outputMemoryStream = new System.IO.MemoryStream()) { using (ZipOutputStream zipOutputStream = new ZipOutputStream(outputMemoryStream)) { WriteToZipStream(zipOutputStream, set, runtime); System.IO.Stream returnStream = new System.IO.MemoryStream(); Crypto.Instance.WriteStreamToEncryptedStream(outputMemoryStream, returnStream, false); returnStream.Flush(); returnStream.Position = 0; return returnStream; } } }
public PolicySetVersionConverter_1_9(IPolicySetCache policySetCache, PolicyConverterFactory.AddPolicyLoadConversionMessageDelegate AddConversionMessage) : base(policySetCache, AddConversionMessage) { }
public PolicyConverterBase(IPolicySetCache policySetCache, PolicyConverterFactory.AddPolicyLoadConversionMessageDelegate AddConversionMessage) { m_addConversionMessage = AddConversionMessage; m_policySetCache = policySetCache; m_versionStatus = policySetCache.LatestVersion.Status; }
public MockConverter(IPolicySetCache policySetCache) : base(policySetCache, null) { }
public PolicyConverterFactory(IPolicySetCache policySetCache) { m_policySetCache = policySetCache; }
/// <summary> /// Creates a new version from the latest version in an IPolicySetCache /// </summary> public static IPolicySetVersionCache NewVersionFromLatest(IPolicySetCache cache, VersionFactory factory, PolicySetVersionStatus status) { IPolicySetVersionCache existingVersion = cache.LatestVersion; string newVersionNumber = NextVersion(existingVersion.Version); existingVersion.Latest = false; IPolicySetVersionCache newVersion = factory.NewVersionCache(existingVersion, newVersionNumber, true, status); cache.PolicySetVersions.Add(newVersion); return newVersion; }
/// <summary> /// Setup constructor /// </summary> /// <param name="policySet">Policy set to build</param> /// <param name="encoding">String encoding used when reading from the zip file</param> /// <param name="factory">Factory, used from creating version cache objects</param> public PolicySetCacheBuilder(IPolicySetCache policySet, Encoding encoding, VersionFactory factory) { m_PolicySet = policySet; m_Encoding = encoding; m_Factory = factory; }
/// <summary> /// Sets the version status, according to save option /// </summary> public static void SetSaveVersionStatus(IPolicySetCache cache, VersionFactory factory, SaveOption option) { IPolicySetVersionCache ver = cache.LatestVersion; switch (option) { case SaveOption.Delete: ver.Status = PolicySetVersionStatus.Deleted; break; case SaveOption.Disable: { DisableOldVersions(cache); if (ver.Status == PolicySetVersionStatus.Enabled) ver.Status = PolicySetVersionStatus.Disabled; } break; case SaveOption.SaveOnly: { if (PolicySetVersionStatus.Enabled != ver.Status) ver.Status = PolicySetVersionStatus.InProgress; } break; case SaveOption.SaveNew: { if (ver.Status == PolicySetVersionStatus.Enabled) ver = NewVersionFromLatest(cache, factory, PolicySetVersionStatus.InProgress); else ver.Status = PolicySetVersionStatus.InProgress; } break; case SaveOption.Publish: { if (ver.Status == PolicySetVersionStatus.InProgress || ver.Status == PolicySetVersionStatus.Disabled) ver.Status = PolicySetVersionStatus.Enabled; else if (ver.Status == PolicySetVersionStatus.Enabled) ver = NewVersionFromLatest(cache, factory, PolicySetVersionStatus.Enabled); DisableOldVersions(cache); } break; default: { Utilities.ErrorMessage errorMessage = new Utilities.ErrorMessage( "STATUS_NOT_IMPL", "Workshare.Policy.ClientCache.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new Exception(errorMessage.DisplayString); } } }
private ICompiledPolicySetCache GetCompiledPolicySet(PolicyResponseObject policyResponseObject, IPolicySetCache policySetCache) { ChannelType channel = PolicyTypeMappings.Lookup[policyResponseObject.UniversalRequestObject.PolicyType]; if (0 == policyResponseObject.UniversalRequestObject.Attachments.Count) { ICompiledPolicySetCache compiledPolicySetCache = policySetCache.LatestVersion.GetCompiledPolicySet(channel.ToString(), policyResponseObject.RunAt == RunAt.Client ? "Client (reduced email only)" : "Server (reduced email only)"); if (null != compiledPolicySetCache) return compiledPolicySetCache; } return policySetCache.LatestVersion.GetCompiledPolicySet(channel.ToString(), policyResponseObject.RunAt == RunAt.Client ? "Client" : "Server"); }
private string WritePolicySetProperties(IPolicySetCache set, bool runtime) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "yes"); XmlElement root = xmlDoc.CreateElement("PolicyProperties"); XmlAttribute attType = xmlDoc.CreateAttribute("type"); attType.Value = runtime ? "COMPILED" : "SOURCE"; root.Attributes.Append(attType); // TODO: AP: Remove condition // (it's a bit lazy because it saves me having to rewrite all the unit tests that check legacy policy XML // formats. It works because policy properties without the policyType attribute default to the legacy policy type) if (set.LatestPolicyType != PolicyType.Legacy) { XmlAttribute attPolicyType = xmlDoc.CreateAttribute("policyType"); attPolicyType.Value = set.LatestPolicyType.ToString(); root.Attributes.Append(attPolicyType); } XmlElement latestver = xmlDoc.CreateElement("LatestVersion"); latestver.InnerText = set.LatestVersion.Version; XmlElement versions = xmlDoc.CreateElement("Versions"); foreach (IPolicySetVersionCache psv in set.PolicySetVersions) { XmlElement version = xmlDoc.CreateElement("Version"); XmlAttribute name = xmlDoc.CreateAttribute("name"); name.Value = psv.Version; XmlAttribute status = xmlDoc.CreateAttribute("status"); switch (psv.Status) { case PolicySetVersionStatus.InProgress: status.Value = "InProgress"; break; case PolicySetVersionStatus.Enabled: status.Value = "Enabled"; break; case PolicySetVersionStatus.Disabled: status.Value = "Disabled"; break; } version.Attributes.Append(name); version.Attributes.Append(status); versions.AppendChild(version); } root.AppendChild(latestver); root.AppendChild(versions); xmlDoc.AppendChild(root); return xmlDoc.OuterXml; }
internal bool Load(string policyname, PolicyConverterFactory.AddPolicyLoadConversionMessageDelegate AddConversionMessage) { if (null == m_proxy) throw new Workshare.Policy.Exceptions.ArgumentNullException("policySetCache", "A null policy set cache object was passed in"); m_policyname = policyname; m_cacheSet = m_proxy.GetPolicySet(policyname); if (m_cacheSet == null) { Logger.LogError(policyname + " returned null PolicySetCache - does the policyset exist or is it deleted?"); return false; } else if (m_cacheSet.LatestVersion.Status == PolicySetVersionStatus.Deleted) { Logger.LogError("Latest version status set to deleted for policyset" + policyname); return false; } PolicyConverterFactory policySetConverter = new PolicyConverterFactory(m_cacheSet); m_data = policySetConverter.ConvertPolicySet(AddConversionMessage); // This has been added to enforce the full loading of the PolicySet ///////////////////////////////////////////////////// // Unfortunately we don't have time to corect the load before the up and comming release. // We will probably leave it here for future generations to marvel over! JE,MM,TT 03.06.2011 PolicySetValidator policySetValidator = new PolicySetValidator(m_data); policySetValidator.Validate(); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //We UnEscape the xml here as we dont want the users to see escaped characters in the descriptions foreach (ICondition condition in m_data.MasterCatalogue.Conditions) { condition.Name.Value = StringUtilities.UnEscapeXML(condition.Name.Value); } return true; }
internal void New(string policyname, IPolicySet policyset) { if (null == m_proxy) throw new Workshare.Policy.Exceptions.ArgumentNullException("policySetCache", "A null policy set cache object was passed in"); m_policyname = policyname; m_cacheSet = m_proxy.NewPolicySet(policyname); m_cacheSet.LatestPolicyType = policyset.PolicyType; m_data = policyset; }