/// <summary> /// Activates the data array containing the premium data. /// </summary> /// <param name="data">Data to activate</param> public static LicenceKeyResults Activate(byte[] data) { try { DataSet dataSet = null; // Validate the data provided is correct. try { dataSet = StreamFactory.Create(data); } catch (MobileException ex) { EventLog.Warn(ex); return(LicenceKeyResults.DataInvalid); } // Check the configuration. try { CheckConfig(); } catch (Exception ex) { EventLog.Warn(ex); return(LicenceKeyResults.Config); } // Write the file to the binary data path. try { File.WriteAllBytes(Detection.Configuration.Manager.BinaryFilePath, data); File.SetLastAccessTimeUtc(Detection.Configuration.Manager.BinaryFilePath, dataSet.Published); } catch (IOException ex) { EventLog.Warn(ex); return(LicenceKeyResults.WriteDataFile); } // Switch in the new data to complete activation. WebProvider.Refresh(); EventLog.Info(String.Format( "Activated binary data file '{0}' with new version " + "dated the '{1:d}'.", AutoUpdate.MasterBinaryDataFile.FullName, dataSet.Published)); } catch (Exception ex) { EventLog.Warn(ex); return(LicenceKeyResults.GenericFailure); } return(LicenceKeyResults.Success); }
/// <summary> /// Checks if a new data file is available for download and if it is /// newer than the current data on disk, if enough time has passed /// between now and the write time of the current data in memory. See /// Constants.AutoUpdateWait. This method is designed to be used in a /// seperate thread from the one performing detection. /// </summary> internal static void CheckForUpdate(object state) { try { // If licence keys are available auto update. if (LicenceKey.Keys.Length > 0) { // Check that there is a binary file, and that either the // active provider is not available indicating no source // data file, or if is available that the next update is // in the past, or that the device data being used is the // free lite version. if (MasterBinaryDataFile != null && (WebProvider.ActiveProvider == null || WebProvider.ActiveProvider.DataSet.NextUpdate < DateTime.UtcNow || WebProvider.ActiveProvider.DataSet.Name == "Lite")) { var downloadResult = Download(LicenceKey.Keys); if (downloadResult == LicenceKeyResults.Success) { WebProvider.Refresh(); } } } } catch (ThreadAbortException ex) { EventLog.Warn(new MobileException( "Auto update download thread aborted", ex)); } catch (Exception ex) { if (MasterBinaryDataFile != null && MasterBinaryDataFile.FullName != null) { EventLog.Warn(new MobileException(String.Format( "Exception auto update download binary data file '{0}'.", MasterBinaryDataFile.FullName), ex)); } else { EventLog.Fatal(ex); } } }