/// <summary> /// This method updates the profile information which can be sended to the server if enabled /// </summary> /// <param name="config"></param> public void UpdateSystemProfileInformation(NetSparkleConfiguration config) { // check if profile data is enabled if (!EnableSystemProfiling) { return; } // check if we need an update if (DateTime.Now - config.LastProfileUpdate < new TimeSpan(7, 0, 0, 0)) { return; } // touch the profile update time config.TouchProfileTime(); // start the profile thread Thread t = new Thread(ProfileDataThreadStart); t.Start(config); }
private void ShowDiagnosticWindowIfNeeded() { if (_DiagnosticWindow.InvokeRequired) { _DiagnosticWindow.Invoke(new Action(ShowDiagnosticWindowIfNeeded)); } else { // check the diagnotic value NetSparkleConfiguration config = new NetSparkleConfiguration(_AppReferenceAssembly); if (config.ShowDiagnosticWindow || ShowDiagnosticWindow) { Point newLocation = new Point(); newLocation.X = Screen.PrimaryScreen.Bounds.Width - _DiagnosticWindow.Width; newLocation.Y = 0; _DiagnosticWindow.Location = newLocation; _DiagnosticWindow.Show(); } } }
/// <summary> /// Profile data thread /// </summary> /// <param name="obj">the configuration object</param> private void ProfileDataThreadStart(object obj) { try { if (SystemProfileUrl != null) { // get the config NetSparkleConfiguration config = obj as NetSparkleConfiguration; // collect data NetSparkleDeviceInventory inv = new NetSparkleDeviceInventory(config); inv.CollectInventory(); // build url String requestUrl = inv.BuildRequestUrl(SystemProfileUrl + "?"); // perform the webrequest HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest; if (request != null) { request.UseDefaultCredentials = true; request.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials; using (WebResponse response = request.GetResponse()) { // close the response response.Close(); } } } } catch (Exception ex) { // No exception during data send ReportDiagnosticMessage(ex.Message); } }
/// <summary> /// This method updates the profile information which can be sended to the server if enabled /// </summary> /// <param name="config">the configuration</param> public void UpdateSystemProfileInformation(NetSparkleConfiguration config) { // check if profile data is enabled if (!EnableSystemProfiling) return; // check if we need an update if (DateTime.Now - config.LastProfileUpdate < new TimeSpan(7, 0, 0, 0)) return; // touch the profile update time config.TouchProfileTime(); // start the profile thread Thread t = new Thread(ProfileDataThreadStart); t.Start(config); }
/// <summary> /// This method checks if an update is required. During this process the appcast /// will be downloaded and checked against the reference assembly. Ensure that /// the calling process has access to the internet and read access to the /// reference assembly. This method is also called from the background loops. /// </summary> /// <param name="config">the configuration</param> /// <param name="latestVersion">returns the latest version</param> /// <returns><c>true</c> if an update is required</returns> public bool IsUpdateRequired(NetSparkleConfiguration config, out NetSparkleAppCastItem latestVersion) { // report ReportDiagnosticMessage("Downloading and checking appcast"); // init the appcast NetSparkleAppCast cast = new NetSparkleAppCast(_AppCastUrl, config); // check if any updates are available try { latestVersion = cast.GetLatestVersion(); } catch (Exception e) { // show the exeception message ReportDiagnosticMessage("Error during app cast download: " + e.Message); // just null the version info latestVersion = null; } if (latestVersion == null) { ReportDiagnosticMessage("No version information in app cast found"); return false; } else { ReportDiagnosticMessage("Lastest version on the server is " + latestVersion.Version); } // set the last check time ReportDiagnosticMessage("Touch the last check timestamp"); config.TouchCheckTime(); // check if the available update has to be skipped if (latestVersion.Version.Equals(config.SkipThisVersion)) { ReportDiagnosticMessage("Latest update has to be skipped (user decided to skip version " + config.SkipThisVersion + ")"); return false; } // check if the version will be the same then the installed version Version v1 = new Version(config.InstalledVersion); Version v2 = new Version(latestVersion.Version); if (v2 <= v1) { ReportDiagnosticMessage("Installed version is valid, no update needed (" + config.InstalledVersion + ")"); return false; } // ok we need an update return true; }
public NetSparkleDeviceInventory(NetSparkleConfiguration config) { _config = config; }
public NetSparkleAppCast(String castUrl, NetSparkleConfiguration config) { _config = config; _castUrl = castUrl; }
/// <summary> /// This method will be executed as worker thread /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void _worker_DoWork(object sender, DoWorkEventArgs e) { // store the did run once feature Boolean goIntoLoop = true; Boolean checkTSP = true; Boolean doInitialCheck = _DoInitialCheck; Boolean isInitialCheck = true; // start our lifecycles do { // set state Boolean bUpdateRequired = false; // notify if (checkLoopStarted != null) { checkLoopStarted(this); } // report status if (doInitialCheck == false) { ReportDiagnosticMessage("Initial check prohibited, going to wait"); doInitialCheck = true; goto WaitSection; } // report status ReportDiagnosticMessage("Starting update loop..."); // read the config ReportDiagnosticMessage("Reading config..."); NetSparkleConfiguration config = GetApplicationConfig(); // calc CheckTasp Boolean checkTSPInternal = checkTSP; if (isInitialCheck && checkTSPInternal) { checkTSPInternal = !_ForceInitialCheck; } // check if it's ok the recheck to software state if (checkTSPInternal) { TimeSpan csp = DateTime.Now - config.LastCheckTime; if (csp < _CheckFrequency) { ReportDiagnosticMessage(String.Format("Update check performed within the last {0} minutes!", _CheckFrequency.TotalMinutes)); goto WaitSection; } } else { checkTSP = true; } // when sparkle will be deactivated wait an other cycle if (config.CheckForUpdate == false) { ReportDiagnosticMessage("Check for updates disabled"); goto WaitSection; } // update the runonce feature goIntoLoop = !config.DidRunOnce; // update profile information is needed UpdateSystemProfileInformation(config); // check if update is required NetSparkleAppCastItem latestVersion = null; bUpdateRequired = IsUpdateRequired(config, out latestVersion); if (!bUpdateRequired) { goto WaitSection; } // show the update window ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " + latestVersion.Version); // send notification if needed UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs() { NextAction = nNextUpdateAction.showStandardUserInterface, ApplicationConfig = config, LatestVersion = latestVersion }; if (updateDetected != null) { updateDetected(this, ev); } // check results switch (ev.NextAction) { case nNextUpdateAction.performUpdateUnattended: { ReportDiagnosticMessage("Unattended update whished from consumer"); EnableSilentMode = true; ReportProgress(1, latestVersion); break; } case nNextUpdateAction.prohibitUpdate: { ReportDiagnosticMessage("Update prohibited from consumer"); break; } case nNextUpdateAction.showStandardUserInterface: default: { ReportDiagnosticMessage("Standard UI update whished from consumer"); ReportProgress(1, latestVersion); break; } } WaitSection: // reset initialcheck isInitialCheck = false; // notify if (checkLoopFinished != null) { checkLoopFinished(this, bUpdateRequired); } // report wait statement ReportDiagnosticMessage(String.Format("Sleeping for an other {0} minutes, exit event or force update check event", _CheckFrequency.TotalMinutes)); // wait for if (!goIntoLoop) { break; } else { // build the event array WaitHandle[] handles = new WaitHandle[1]; handles[0] = _exitHandle; // wait for any int i = WaitHandle.WaitAny(handles, _CheckFrequency); if (WaitHandle.WaitTimeout == i) { ReportDiagnosticMessage(String.Format("{0} minutes are over", _CheckFrequency.TotalMinutes)); continue; } // check the exit hadnle if (i == 0) { ReportDiagnosticMessage("Got exit signal"); break; } // check an other check needed if (i == 1) { ReportDiagnosticMessage("Got force update check signal"); checkTSP = false; continue; } } } while (goIntoLoop); // reset the islooping handle _loopingHandle.Reset(); }
/// <summary> /// Constructor /// </summary> /// <param name="castUrl">the URL of the appcast file</param> /// <param name="config">the current configuration</param> public NetSparkleAppCast(string castUrl, NetSparkleConfiguration config) { _config = config; _castUrl = castUrl; }
/// <summary> /// This method shows the update ui and allows to perform the /// update process /// </summary> /// <param name="currentItem"></param> public void ShowUpdateNeededUI(NetSparkleAppCastItem currentItem) { // create the form NetSparkleForm frm = new NetSparkleForm(currentItem, ApplicationIcon, ApplicationWindowIcon); // configure the form frm.TopMost = true; if (HideReleaseNotes) frm.RemoveReleaseNotesControls(); // show it DialogResult dlgResult = frm.ShowDialog(); if (dlgResult == DialogResult.No) { // skip this version NetSparkleConfiguration config = new NetSparkleConfiguration(_AppReferenceAssembly); config.SetVersionToSkip(currentItem.Version); } else if (dlgResult == DialogResult.Yes) { // download the binaries InitDownloadAndInstallProcess(currentItem); } }
/// <summary> /// This method reads the local sparkle configuration for the given /// reference assembly /// </summary> /// <param name="AppReferenceAssembly"></param> /// <returns></returns> public NetSparkleConfiguration GetApplicationConfig() { NetSparkleConfiguration config; config = new NetSparkleConfiguration(_AppReferenceAssembly); return config; }