/// <summary> /// if you call this every time the application starts, it will send reports on those launches /// (e.g. {1, 10}) that are listed in the launches parameter. It will get version number and name out of the application. /// </summary> public static void DoTrivialUsageReport(string emailAddress, string topMessage, int[] launches) { int launchCount = int.Parse(RegistryAccess.GetStringRegistryValue("launches", "0")); foreach (int launch in launches) { if (launch == launchCount) { // Set the Application label to the name of the app Assembly assembly = Assembly.GetEntryAssembly(); string version = Application.ProductVersion; if (assembly != null) { object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false); version = (attributes != null && attributes.Length > 0) ? ((AssemblyFileVersionAttribute)attributes[0]).Version : Application.ProductVersion; } using (UsageEmailDialog d = new SIL.Utils.UsageEmailDialog()) { d.TopLineText = topMessage; d.EmailAddress = emailAddress; d.EmailSubject = string.Format("{0} {1} Report {2} Launches", Application.ProductName, version, launchCount); System.Text.StringBuilder bldr = new System.Text.StringBuilder(); bldr.AppendFormat("<report app='{0}' version='{1}'>", Application.ProductName, version); bldr.AppendFormat("<stat type='launches' value='{0}'/>", launchCount); if (launchCount > 1) { int val = RegistryAccess.GetIntRegistryValue("NumberOfSeriousCrashes", 0); bldr.AppendFormat("<stat type='NumberOfSeriousCrashes' value='{0}'/>", val); val = RegistryAccess.GetIntRegistryValue("NumberOfAnnoyingCrashes", 0); bldr.AppendFormat("<stat type='NumberOfAnnoyingCrashes' value='{0}'/>", val); int csec = RegistryAccess.GetIntRegistryValue("TotalAppRuntime", 0); int cmin = csec / 60; string sRuntime = String.Format("{0}:{1:d2}:{2:d2}", cmin / 60, cmin % 60, csec % 60); bldr.AppendFormat("<stat type='TotalAppRuntime' value='{0}'/>", sRuntime); } bldr.AppendFormat("</report>"); d.Body = bldr.ToString(); d.ShowDialog(); } break; } } }
// Function to read the checkpoint intervals from the previous invocation of the // splashscreen from the registry. private void ReadIncrements() { string sPBIncrementPerTimerInterval = RegistryAccess.GetStringRegistryValue(REGVALUE_PB_MILISECOND_INCREMENT, "0.0015"); double dblResult; if (Double.TryParse(sPBIncrementPerTimerInterval, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out dblResult) == true) { m_dblPBIncrementPerTimerInterval = dblResult; } else { m_dblPBIncrementPerTimerInterval = .0015; } string sPBPreviousPctComplete = RegistryAccess.GetStringRegistryValue(REGVALUE_PB_PERCENTS, ""); if (sPBPreviousPctComplete != "") { string [] aTimes = sPBPreviousPctComplete.Split(null); m_alPreviousCompletionFraction = new ArrayList(); for (int i = 0; i < aTimes.Length; i++) { double dblVal; if (Double.TryParse(aTimes[i], System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out dblVal)) { m_alPreviousCompletionFraction.Add(dblVal); } else { m_alPreviousCompletionFraction.Add(1.0); } } } else { m_bFirstLaunch = true; lblTimeRemaining.Text = ""; } }
/// <summary> /// Show the open file window to the user /// </summary> /// <param name="filter">Filter spec list, e.g. "CSV files (*.csv)|*.csv|Tab delimited txt files (*.txt)|*.txt|"</param> private void ShowOpenFileWindow(string filter) { const string WORKING_FOLDER = "Working_Directory"; var workingFolder = Settings.Default.WorkingFolder; if (string.IsNullOrWhiteSpace(workingFolder)) { workingFolder = RegistryAccess.GetStringRegistryValue(WORKING_FOLDER, ""); } if (!string.IsNullOrWhiteSpace(workingFolder)) { try { var diWorkingFolder = new DirectoryInfo(workingFolder); while (!diWorkingFolder.Exists) { if (diWorkingFolder.Parent == null) { workingFolder = string.Empty; break; } diWorkingFolder = diWorkingFolder.Parent; workingFolder = diWorkingFolder.FullName; } } catch { workingFolder = string.Empty; } } var fdlg = new OpenFileDialog { Title = mstrFldgTitle }; if (!string.IsNullOrWhiteSpace(workingFolder)) { fdlg.InitialDirectory = workingFolder; } else { fdlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } fdlg.Filter = filter; fdlg.FilterIndex = 1; fdlg.RestoreDirectory = false; if (fdlg.ShowDialog() == DialogResult.OK) { mstrLoadedfileName = fdlg.FileName; var fiDataFile = new FileInfo(mstrLoadedfileName); if (!fiDataFile.Exists) { return; } mstrLoadedfileName = fiDataFile.FullName; if (fiDataFile.Directory != null) { workingFolder = fiDataFile.Directory.FullName; } Settings.Default.WorkingFolder = workingFolder; Settings.Default.DataFileName = fiDataFile.Name; Settings.Default.Save(); RegistryAccess.SetStringRegistryValue(WORKING_FOLDER, workingFolder); } else { mstrLoadedfileName = null; } }
/// <summary> /// call this each time the application is launched if you have launch count-based reporting /// </summary> public static void IncrementLaunchCount() { int launchCount = 1 + int.Parse(RegistryAccess.GetStringRegistryValue("launches", "0")); RegistryAccess.SetStringRegistryValue("launches", launchCount.ToString()); }
private bool InstallRequiredRPackages() { var currentTask = "initializing"; try { if (mInstallRpacks) { currentTask = "installing default packages from " + mRepository; var rcommand = @"installPackages(c(" + mRpackList + @"), repository=""" + mRepository + @""")"; mRConnector.EvaluateNoReturn(rcommand); // Also confirm that we have the Bioconductor qvalue package // Check the registry for the most recent version of this program that has installed bioconductor and qvalue var appVersionBioconductorCheck = RegistryAccess.GetStringRegistryValue(REGVALUE_BIOCONDUCTOR_VERSION_CHECK, ""); var appVersionCurrent = clsRCmdLog.GetProgramVersion(); var updateRequired = !string.Equals(appVersionBioconductorCheck, appVersionCurrent); if (updateRequired && !string.IsNullOrWhiteSpace(appVersionBioconductorCheck)) { // Only update if the versions differ by at least 8 hours var currentVersionParts = appVersionCurrent.Split('.').ToList(); var lastUpdateParts = appVersionBioconductorCheck.Split('.').ToList(); if (currentVersionParts.Count >= 4 && lastUpdateParts.Count >= 4) { var versionDifferenceHours = GetVersionDifferenceHours(lastUpdateParts, currentVersionParts); if (versionDifferenceHours < 8) { updateRequired = false; mUpdateRpacks = false; } } } if (updateRequired) { currentTask = "installing Bioconductor from http://bioconductor.org/biocLite.R"; rcommand = @"source(""http://bioconductor.org/biocLite.R"")"; mRConnector.EvaluateNoReturn(rcommand); currentTask = "installing qvalue from Bioconductor"; rcommand = @"biocLite(""qvalue"", suppressUpdates=TRUE)"; mRConnector.EvaluateNoReturn(rcommand); RegistryAccess.SetStringRegistryValue(REGVALUE_BIOCONDUCTOR_VERSION_CHECK, appVersionCurrent); } } if (mUpdateRpacks) { currentTask = "updating packages using " + mRepository; var rcommand = @"update.packages(checkBuilt=TRUE, ask=FALSE,repos=""" + mRepository + @""")"; mRConnector.EvaluateNoReturn(rcommand); } return(true); } catch (Exception ex) { Log(mCustomLoggerEnabled, "Exception in InstallRequiredRPackages while " + currentTask + ": " + ex.Message, mCustomLogWriter); return(false); } }