/// <summary> /// Obtains a license from the application data path and adds it to the <paramref name="licenses"/> if exists. /// </summary> /// <param name="key">The encryption key to verify the license.</param> /// <param name="licenses">The licenses collection.</param> private void AddLicenseFromPaths(RSACryptoServiceProvider key, List <License> licenses) { LicenseFile lic = null; using (Stream stream = FileNames.CreateLicenseFileStream(FileMode.Open, FileAccess.Read, FileShare.Read)) lic = LicenseFile.LoadFile(stream, key); if (lic != null) { licenses.Add(lic); } }
/// <summary> /// This saves the license in the proper location. /// </summary> /// <param name="licenseFile">The license file to save.</param> /// <param name="key">The encryption key to verify the license.</param> /// <param name="useIsolatedStorage">Save to IsolatedStorage if true if saving in the application data path causes an exception.</param> /// <param name="appDataFilePath">The application data file path.</param> private void Save (LicenseFile licenseFile, RSACryptoServiceProvider key, bool useIsolatedStorage, string appDataFilePath) { Debug.WriteLine("OpenLicenseProvider: Save Function"); try { using (Stream fileStream = FileNames.CreateLicenseFileStream(FileMode.Create, FileAccess.Write, FileShare.Write)) licenseFile.SaveFile(fileStream, key); } catch (Exception ex) { if (!useIsolatedStorage) { throw new LicenseFileException(Resources.ErrStr_SaveLicense_UnableToSaveLicense + ex.Message); } } if (useIsolatedStorage) { using (Stream writer = IsolatedStorageAccess.CreateIsolatedStorageLicenseStream(FileMode.Create)) licenseFile.SaveFile(writer, key); } }