Example #1
0
 public static void SaveToFile(string path, MyLicence licence)
 {
     using (MemoryStream memoryStream = new MemoryStream())
     {
         new XmlSerializer(typeof(MyLicence)).Serialize((Stream)memoryStream, (object)licence);
         byte[] bytes = ProtectedData.Protect(memoryStream.ToArray(), (byte[])null, DataProtectionScope.LocalMachine);
         File.WriteAllBytes(path, bytes);
     }
 }
Example #2
0
        public MyLicence GetLicence()
        {
            string    path      = Path.Combine(this.BasePath, "licence.dat");
            MyLicence myLicence = (MyLicence)null;

            if (File.Exists(path))
            {
                myLicence = MyLicence.LoadFromFile(path);
            }
            return(myLicence);
        }
Example #3
0
        public void SetLicence(MyLicence lic)
        {
            string path = Path.Combine(this.BasePath, "licence.dat");

            if (lic == null)
            {
                File.Delete(path);
            }
            else
            {
                MyLicence.SaveToFile(path, lic);
            }
        }
Example #4
0
 public static MyLicence LoadFromFile(string path)
 {
     if (!File.Exists(path))
     {
         return((MyLicence)null);
     }
     try
     {
         byte[]        buffer        = ProtectedData.Unprotect(File.ReadAllBytes(path), (byte[])null, DataProtectionScope.LocalMachine);
         XmlSerializer xmlSerializer = new XmlSerializer(typeof(MyLicence));
         MemoryStream  memoryStream1 = new MemoryStream(buffer);
         MemoryStream  memoryStream2 = memoryStream1;
         MyLicence     myLicence     = xmlSerializer.Deserialize((Stream)memoryStream2) as MyLicence;
         memoryStream1.Close();
         return(myLicence);
     }
     catch (Exception ex)
     {
         return((MyLicence)null);
     }
 }