internal LocalPolicySetVersionCache(string xml, string version, PolicySetVersionStatus status, bool latest)
		{
			LoadPolicySetVersion(xml);
			m_Status = status;
			m_version = version;
			Latest = latest;
		}
Ejemplo n.º 2
0
		public static int GetStatusInt(PolicySetVersionStatus status)
		{
			switch (status)
			{
				case PolicySetVersionStatus.InProgress: return 0;
				case PolicySetVersionStatus.Enabled: return 2;
				case PolicySetVersionStatus.Disabled: return 3;
                case PolicySetVersionStatus.Deleted: return 4;
			}

			return 3;
		}
Ejemplo n.º 3
0
        public static IPolicySet ReadRuntimePolicySet(string filename, out PolicySetVersionStatus status)
        {
            status = PolicySetVersionStatus.Disabled;

            PolicyProxy runtimeCache = PolicyProxy.CreateLocalRuntimeCache();
            IPolicySetCache policySetCache = runtimeCache.GetPolicySet(filename);
            if (null == policySetCache)
                runtimeCache = PolicyProxy.CreateLocalPolicySourceCache();

            policySetCache = runtimeCache.GetPolicySet(filename);
            if (null == policySetCache)
                throw new Exception("Failed to load the runtime policy");

            status = policySetCache.LatestVersion.Status;

            PolicyConverterFactory factory = new PolicyConverterFactory(policySetCache);
            return factory.ConvertPolicySet(null);
        }
Ejemplo n.º 4
0
        public MDIChildForm AddPolicySetWindow(IPolicySet policySet, PolicySetVersionStatus status, string version)
        {
            Guid childFormId = Guid.NewGuid();
            string nodeName;
            if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "en")
                nodeName = string.Format(CultureInfo.CurrentCulture, "{0} - v{1} [{2}]", policySet.Name.Value, version, Workshare.Policy.PolicySuites.Instance.GetStatusText(status));
            else
                nodeName = string.Format(CultureInfo.CurrentCulture, "{0} - [{1}]", policySet.Name.Value, Workshare.Policy.PolicySuites.Instance.GetStatusText(status));

            TreeObject treeObject = new TreeObject(childFormId, (int)TreeViewControllerPolicyOriented.NodeType.PolicySet, nodeName, policySet);
            policySetTreeView.Nodes.Add(treeObject);

            MDIChildForm childForm = new MDIChildForm(childFormId, policySet, policySetTreeView, treeObject);
            ChildFormData childFormData = new ChildFormData(childFormId, childForm, status, policySet);
            treeObject.Tag = childFormData;

            policySetTreeView.SelectedNode = treeObject;

            return childForm;
        }
Ejemplo n.º 5
0
        public static IPolicySet ReadPolicySet(byte[] contents, string outputFilename, out PolicySetVersionStatus status)
        {
            using (FileStream fileStream = new FileStream(outputFilename, FileMode.Create))
            {
                fileStream.Write(contents, 0, contents.Length);

                fileStream.Flush();
            }
            
            try
            {
                if (outputFilename.EndsWith("runtimepolicy", true, System.Globalization.CultureInfo.InvariantCulture))
                    return ReadRuntimePolicySet(outputFilename, out status);
                else 
                    return ReadPolicySet(outputFilename, out status);
            }
            finally
            {
                File.Delete(outputFilename);
            }
        }
		internal LocalPolicySetVersionCache(LocalPolicySetVersionCache existing, string version, bool latest, PolicySetVersionStatus status)
		{
			m_name = existing.m_name;
			m_version = version;
			m_content = existing.Content;
			m_Status = status;


            if (existing.MasterCatalogue != null)
            {
                LocalPolicyCatalogueCache master = new LocalPolicyCatalogueCache(existing.MasterCatalogue as LocalPolicyCatalogueCache);
                master.ObjectModified += new ObjectModifiedEventHandler(OnObjectModified);
                m_masterCatalogue = master;
            }


			if (existing.m_refCatalogues != null)
			{
				foreach (LocalPolicyCatalogueCache existingCat in existing.m_refCatalogues)
				{
					LocalPolicyCatalogueCache newCat = new LocalPolicyCatalogueCache(existingCat);
                    newCat.ObjectModified += new ObjectModifiedEventHandler(OnObjectModified);
					m_refCatalogues.Add(newCat);
				}
			}


			if (existing.m_compiledSets != null)
			{
				foreach (LocalCompiledPolicySetCache existingCPS in existing.m_compiledSets)
				{
					LocalCompiledPolicySetCache newCPS = new LocalCompiledPolicySetCache(existingCPS);
                    newCPS.ObjectModified += new ObjectModifiedEventHandler(OnObjectModified);
					m_compiledSets.Add(newCPS);
				}
			}

			Latest = latest;
		}
Ejemplo n.º 7
0
        public void UpdatePolicyTreeNode(Guid key, PolicySetVersionStatus status, string version)
        {
            ChildFormData childFormData = GetChildFormData(key);
            if (null == childFormData)
                return;

            bool bModified = (childFormData.Form as MDIChildForm).IsModified;
            string statusString = bModified ?
									Workshare.Policy.PolicySuites.Instance.GetStatusText(PolicySetVersionStatus.InProgress) : 
									Workshare.Policy.PolicySuites.Instance.GetStatusText(status);

            string nodeName;
            if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "en")
                nodeName = string.Format(CultureInfo.CurrentCulture, "{0} - v{1} [{2}]", childFormData.PolicySet.Name.Value, version, statusString);
            else
                nodeName = string.Format(CultureInfo.CurrentCulture, "{0} - [{1}]", childFormData.PolicySet.Name.Value, statusString);
            
            int index = policySetTreeView.Nodes.IndexOfKey(key.ToString("B").ToUpper(CultureInfo.InvariantCulture));
            policySetTreeView.Nodes[index].Text = nodeName;
            (childFormData.Form as MDIChildForm).TreeViewController.RefreshMenu(key, bModified);

        }
Ejemplo n.º 8
0
        private void SetStatus(TreeNode selectedNode, PolicySetVersionStatus status)
        {
            if (null == selectedNode)
                return;

            LocalPolicySetVersionCache policySetVersion = selectedNode.Tag as LocalPolicySetVersionCache;
            if (null == policySetVersion)
                return;

            policySetVersion.Status = status;
            selectedNode.Text = GetVersionNodeString(policySetVersion);

            LocalPolicySetCache policySetCache = GetPolicySetCache(selectedNode);
            if (null == policySetCache)
                return;

            PolicyFileWriter fileWriter = new PolicyFileWriter();
            fileWriter.WriteFile(policySetCache, policySetCache.FileName, false);
        }
Ejemplo n.º 9
0
		internal IPolicySetVersionCache NewSuperSet(string xml, PolicySetVersionStatus status)
		{
			IPolicySetVersionCache old_lpsv = null;

			foreach (LocalPolicySetVersionCache lpsv in m_policySetVersions)
			{
				if (lpsv.Latest)
				{
					lpsv.Latest = false;
					old_lpsv = lpsv;
					break;
				}
			}

			LocalPolicySetVersionCache new_lpsv;

            if (old_lpsv == null)
            {
                double ver = 1.0d;
                new_lpsv = new LocalPolicySetVersionCache(xml, ver.ToString("N1", CultureInfo.CurrentCulture), status, true);
            }
            else
                new_lpsv = new LocalPolicySetVersionCache(xml, GetNewVersionString(old_lpsv.Version), status, true);

			m_policySetVersions.Add(new_lpsv);
			return new_lpsv;
		}
Ejemplo n.º 10
0
		private LocalPolicySetVersionCache NewVersionFromLatest(PolicySetVersionStatus status)
		{
			LocalPolicySetVersionCache existingVersion = (LocalPolicySetVersionCache)LatestVersion;
			string newVersionNumber = GetNewVersionString(LatestVersion.Version);
			existingVersion.Latest = false;
			
			LocalPolicySetVersionCache newVersion = new LocalPolicySetVersionCache(existingVersion, newVersionNumber, true, status);
			m_policySetVersions.Add(newVersion);
			return newVersion;
		}
Ejemplo n.º 11
0
		protected virtual void CreateVersion(string xml, string version, PolicySetVersionStatus status, bool latest)
		{
            if (m_bDecryptXML)
                xml = Crypto.Instance.DecryptXml(xml);

			LocalPolicySetVersionCache psv = new LocalPolicySetVersionCache(xml, version, status, latest);
			m_policySetVersions.Add(psv);
		}
Ejemplo n.º 12
0
		private void LoadVersionProperties(ZipFile zipfile, string version, PolicySetVersionStatus status, bool latest)
		{
			ZipEntry zipEntry = zipfile.GetEntry(version + "/policysetversion.xml");

			if (zipEntry == null)
			{
				if (latest)
					Logger.LogError(@"Failed to find the policy set file - this is not a valid policy set file.");
				return;
			}

			CreateVersion(ReadEntry(zipfile, zipEntry), version, status, latest);
		}
Ejemplo n.º 13
0
		/// <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;
		}
Ejemplo n.º 14
0
		private void ShowNewForm(IPolicySet policySet, PolicySetVersionStatus status, ref MDIChildForm child)
		{
			child = m_policySetExplorer.AddPolicySetWindow(policySet, status, PolicySuites.Instance.GetVersion(policySet));
			child.FormClosed += childForm_FormClosed;

			if (!m_policySetExplorer.Visible)
			{
				m_policySetExplorer.MdiParent = this;
				m_policySetExplorer.Dock = DockStyle.Left;
			}

			// Make it a child of this MDI form before showing it.
			child.MdiParent = this;

			child.Dock = DockStyle.Fill;
			child.Text = MDIParentMenuHelper.Instance.GetPolicySetDisplayName(policySet);
			child.Init();
			m_policySetExplorer.ActivateWindow(child);
		}
Ejemplo n.º 15
0
		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()));
			}
		}
Ejemplo n.º 16
0
		/// <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);
		}
Ejemplo n.º 17
0
 public static IPolicySet ReadPolicySet(string filename, out PolicySetVersionStatus status)
 {
     PolicySetItem policySetItem = PolicySuite.Instance.LoadPolicySet("localhost", filename);
     status = policySetItem.CacheSet.LatestVersion.Status;
     return policySetItem.Data;
 }
Ejemplo n.º 18
0
        public PolicyConverterBase(IPolicySetCache policySetCache, PolicyConverterFactory.AddPolicyLoadConversionMessageDelegate AddConversionMessage)
        {
            m_addConversionMessage = AddConversionMessage;
            m_policySetCache = policySetCache;
			m_versionStatus = policySetCache.LatestVersion.Status;
        }
Ejemplo n.º 19
0
		//	TODO: AP: Using IPolicySetCache.NewVersion() would be nicer than this factory

		/// <summary>
		/// Creates a new policy set version (default is <see cref="LocalPolicySetVersionCache">)
		/// </summary>
		public virtual IPolicySetVersionCache NewVersionCache(string xml, string version, PolicySetVersionStatus status, bool latest)
		{
			return new LocalPolicySetVersionCache(xml, version, status, latest);
		}
Ejemplo n.º 20
0
 /// <summary>
 /// This constructor will initialise the internal members
 /// </summary>
 public PolicySetVersionCache()
 {
     m_status = PolicySetVersionStatus.Enabled;
     System.IO.FileInfo info = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
     m_rules = new TraceRuleStore(info.Directory.FullName);
 }
Ejemplo n.º 21
0
		/// <summary>
		/// Creates a new policy set version
		/// </summary>
		private void CreateVersion(string xml, string version, PolicySetVersionStatus status, bool latest)
		{
			if (m_DecryptXml)
			{
				xml = Crypto.Instance.DecryptXml(xml);
			}
			IPolicySetVersionCache psv = m_Factory.NewVersionCache(xml, version, status, latest);
			m_PolicySet.PolicySetVersions.Add(psv);
		}