Пример #1
0
        /// <summary>
        /// Create a serialization of the current policy object in a stream (e.g. MemoryStream or FileStream)
        /// </summary>
        /// <param name="policyIdentifier"></param>
        /// <param name="format"></param>
        /// <param name="targetStream"></param>
        public void Serialize(string policyIdentifier, PolicySerializationFormat format, Stream targetStream)
        {
            var p = new TpmPolicy(this);

            p.Create(policyIdentifier);

            switch (format)
            {
            case PolicySerializationFormat.Xml:
            {
                var ser = new DataContractSerializer(typeof(TpmPolicy));
                ser.WriteObject(targetStream, p);
                break;
            }

            case PolicySerializationFormat.Json:
            {
                var ser = new DataContractJsonSerializer(typeof(TpmPolicy));
                ser.WriteObject(targetStream, p);
                break;
            }

            default:
                Globs.Throw <ArgumentException>("PolicyTree.Serialize: Unknown format " + format);
                break;
            }
            targetStream.Flush();
        }
Пример #2
0
        /// <summary>
        /// Load a policy from a stream (MemoryStream, FileStream) in the specified format
        /// </summary>
        /// <param name="format"></param>
        /// <param name="sourceStream"></param>
        public void Deserialize(PolicySerializationFormat format, Stream sourceStream)
        {
            TpmPolicy pol = null;

            switch (format)
            {
            case PolicySerializationFormat.Xml:
            {
                var ser = new DataContractSerializer(typeof(TpmPolicy));
                pol = (TpmPolicy)ser.ReadObject(sourceStream);
                break;
            }

            case PolicySerializationFormat.Json:
            {
                var ser = new DataContractJsonSerializer(typeof(TpmPolicy));
                pol = (TpmPolicy)ser.ReadObject(sourceStream);
                break;
            }

            default:
                Globs.Throw <ArgumentException>("PolicyTree.Deserialize: Unknown format " + format);
                return;
            }
            pol.AssociatedPolicy = this;
            PolicyRoot           = pol.PolicyRoot;
        }
Пример #3
0
 /// <summary>
 /// Create a serialization of the current policy object in a stream (e.g. MemoryStream or FileStream)
 /// </summary>
 /// <param name="policyIdentifier"></param>
 /// <param name="fileName"></param>
 public void Serialize(string policyIdentifier, PolicySerializationFormat format, Stream targetStream)
 {
     var p = new TpmPolicy(this);
     p.Create(policyIdentifier);
     
     switch(format)
     {
         case PolicySerializationFormat.Xml:
         {
             var ser = new DataContractSerializer(typeof(TpmPolicy));
             ser.WriteObject(targetStream, p);
             break;
         }
         case PolicySerializationFormat.Json:
         {
             var ser = new DataContractJsonSerializer(typeof(TpmPolicy));
             ser.WriteObject(targetStream, p);
             break;
         }
         default:
             Globs.Throw<ArgumentException>("PolicyTree.Serialize: Unknown format " + format);
             break;
     }
     targetStream.Flush();
 }