/// ------------------------------------------------------------------------------------ /// <summary> /// if you call this every time the application starts, it will send reports on the /// specified launch number. It will get version number and name out of the application. /// </summary> /// <param name="applicationName">Name of the application.</param> /// <param name="applicationKey">The application registry key.</param> /// <param name="emailAddress">The e-mail address.</param> /// <param name="topMessage">The message at the top of the e-mail.</param> /// <param name="addStats">True to add crash and application runtime statistics to the /// report.</param> /// <param name="launchNumber">The needed launch count to show the dialog and ask for /// an e-mail.</param> /// <param name="assembly">The assembly to use for getting version information (can be /// <c>null</c>).</param> /// ------------------------------------------------------------------------------------ public static void DoTrivialUsageReport(string applicationName, RegistryKey applicationKey, string emailAddress, string topMessage, bool addStats, int launchNumber, Assembly assembly) { #if __MonoCS__ // TODO-Linux: crashes Flex investigate return; #else int launchCount = int.Parse((string)applicationKey.GetValue("launches", "0")); if (launchNumber == launchCount) { // Set the Application label to the name of the app if (assembly == null) { 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 UsageEmailDialog()) { d.TopLineText = topMessage; d.EmailAddress = emailAddress; d.EmailSubject = string.Format("{0} {1} Report {2} Launches", applicationName, version, launchCount); StringBuilder bldr = new StringBuilder(); bldr.AppendFormat("<report app='{0}' version='{1}'>", applicationName, version); bldr.AppendFormat("<stat type='launches' value='{0}'/>", launchCount); if (launchCount > 1) { int val = (int)applicationKey.GetValue("NumberOfSeriousCrashes", 0); bldr.AppendFormat("<stat type='NumberOfSeriousCrashes' value='{0}'/>", val); val = (int)applicationKey.GetValue("NumberOfAnnoyingCrashes", 0); bldr.AppendFormat("<stat type='NumberOfAnnoyingCrashes' value='{0}'/>", val); int csec = (int)applicationKey.GetValue("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(); } } #endif }
/// ------------------------------------------------------------------------------------ /// <summary> /// if you call this every time the application starts, it will send reports on the /// specified launch number. It will get version number and name out of the application. /// </summary> /// <param name="applicationName">Name of the application.</param> /// <param name="applicationKey">The application registry key.</param> /// <param name="emailAddress">The e-mail address.</param> /// <param name="topMessage">The message at the top of the e-mail.</param> /// <param name="addStats">True to add crash and application runtime statistics to the /// report.</param> /// <param name="launchNumber">The needed launch count to show the dialog and ask for /// an e-mail.</param> /// <param name="assembly">The assembly to use for getting version information (can be /// <c>null</c>).</param> /// ------------------------------------------------------------------------------------ public static void DoTrivialUsageReport(string applicationName, RegistryKey applicationKey, string emailAddress, string topMessage, bool addStats, int launchNumber, Assembly assembly) { int launchCount = int.Parse((string)applicationKey.GetValue("launches", "0")); if (launchNumber == launchCount) { // Set the Application label to the name of the app if (assembly == null) 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 UsageEmailDialog()) { d.TopLineText = topMessage; d.EmailAddress = emailAddress; d.EmailSubject = string.Format("{0} {1} Report {2} Launches", applicationName, version, launchCount); StringBuilder bldr = new StringBuilder(); bldr.AppendFormat("<report app='{0}' version='{1}' linux='{2}'>", applicationName, version, MiscUtils.IsUnix); bldr.AppendFormat("<stat type='launches' value='{0}'/>", launchCount); if (launchCount > 1) { int val = (int)applicationKey.GetValue("NumberOfSeriousCrashes", 0); bldr.AppendFormat("<stat type='NumberOfSeriousCrashes' value='{0}'/>", val); val = (int)applicationKey.GetValue("NumberOfAnnoyingCrashes", 0); bldr.AppendFormat("<stat type='NumberOfAnnoyingCrashes' value='{0}'/>", val); int csec = (int)applicationKey.GetValue("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(); } } }