Beispiel #1
0
        internal void HandleException(Exception unhandledException)
        {
            CrashLogInformation crashInfo = this._crashLogInfo;

            //TODO refactor in next version
            if (this._crashLogInfo.PackageName == null)
            {
                this._crashLogInfo = HockeyClient.Current.AsInternal().PrefilledCrashLogInfo;
            }
            ICrashData cd = HockeyClient.Current.AsInternal().CreateCrashData(unhandledException, this._crashLogInfo);

            var crashId = Guid.NewGuid();

            try
            {
                IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
                if (!store.DirectoryExists(Constants.CrashDirectoryName))
                {
                    store.CreateDirectory(Constants.CrashDirectoryName);
                }

                String filename = string.Format("{0}{1}.log", Constants.CrashFilePrefix, crashId);
                using (FileStream stream = store.CreateFile(Path.Combine(Constants.CrashDirectoryName, filename)))
                {
                    cd.Serialize(stream);
                }
            }
            catch (Exception ex)
            {
                HockeyClient.Current.AsInternal().HandleInternalUnhandledException(ex);
            }
        }
        private void HandleException(Exception e)
        {
            try
            {
                string crashID  = Guid.NewGuid().ToString();
                String filename = String.Format("{0}{1}.log", Constants.CrashFilePrefix, crashID);

                CrashLogInformation logInfo = new CrashLogInformation()
                {
                    PackageName     = Application.Current.GetType().Namespace,
                    Version         = HockeyClient.Current.AsInternal().VersionInfo,
                    OperatingSystem = Environment.OSVersion.Platform.ToString(),
                    Windows         = Environment.OSVersion.Version.ToString() + Environment.OSVersion.ServicePack,
                    Manufacturer    = "",
                    Model           = ""
                };

                ICrashData crash = HockeyClient.Current.AsInternal().CreateCrashData(e, logInfo);
                using (FileStream stream = File.Create(Path.Combine(Constants.GetPathToHockeyCrashes(), filename)))
                {
                    crash.Serialize(stream);
                    stream.Flush();
                }
            }
            catch (Exception ex)
            {
                HockeyClient.Current.AsInternal().HandleInternalUnhandledException(ex);
            }
        }
        private void ExceptionHandler(object sender, UnhandledExceptionEventArgs e)
        {
            // check if we are allowed to handle exceptions
            if (_disposed)
            {
                return;
            }

            // the exception handler as self should never throw an exception so that the flow is
            // not interrupted by some bad code here
            try
            {
                // We need to ensure that the crash file location realy exists before we start
                // writing a file into it
                if (!Directory.Exists(_crashFileLocaton))
                {
                    Directory.CreateDirectory(_crashFileLocaton);
                }

                // Every exception needs a unique identifier
                string crashID = Guid.NewGuid().ToString();

                // The filename is generated by the identifier
                String filename = String.Format("{0}.log", crashID);

                // generate the full filename
                filename = Path.Combine(_crashFileLocaton, filename);

                // Generate the model HockeyApp is using for logging crashes
                CrashLogInformation logInfo = new CrashLogInformation()
                {
                    PackageName     = _packageName,
                    Version         = _packageVersion,
                    OperatingSystem = Environment.OSVersion.ToString(),
                };


                // Now it's time to build a real creash report and write them to the file
                ICrashData crash = HockeyClient.Instance.CreateCrashData(e.ExceptionObject as Exception, logInfo);
                using (FileStream stream = File.Create(filename))
                {
                    crash.Serialize(stream);
                }
            }
            catch (Exception)
            {
                // Ignore all exceptions
            }
        }
Beispiel #4
0
        /// <summary>
        /// Handle exception asyncronously
        /// </summary>
        /// <param name="ex">the exception that should be saved to a crashlog</param>
        public async Task HandleExceptionAsync(Exception ex)
        {
            ICrashData cd = this.CreateCrashData(ex);

            var crashId = Guid.NewGuid();

            try {
                using (MemoryStream stream = new MemoryStream()) {
                    cd.Serialize(stream);
                    stream.Seek(0, SeekOrigin.Begin);
                    await this.PlatformHelper.WriteStreamToFileAsync(stream, string.Format("{0}{1}.log", SDKConstants.CrashFilePrefix, crashId), SDKConstants.CrashDirectoryName);
                }
            } catch (Exception e) {
                HandleInternalUnhandledException(e);
            }
        }
        public CrashHandler()
        {
            HockeyApp.HockeyClient.Configure(this._appID, Assembly.GetExecutingAssembly().GetName().Version.ToString());

            this.crashFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            this.crashFilePath = Path.Combine(this.crashFilePath, "Hoch");

            AppDomain.CurrentDomain.UnhandledException += (a, b) =>
            {
                string crashID  = Guid.NewGuid().ToString();
                String filename = String.Format("{0}{1}.log", _crashFilePrefix, crashID);

                CrashLogInformation logInfo = new CrashLogInformation()
                {
                    PackageName     = "HockeyUploaderConsole",
                    Version         = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                    OperatingSystem = Environment.OSVersion.ToString(),
                };

                ICrashData crash  = HockeyClient.Instance.CreateCrashData(b.ExceptionObject as Exception, logInfo);
                FileStream stream = File.Create(Path.Combine(this._crashFilePrefix, filename));
                crash.Serialize(stream);
                stream.Flush();
                stream.Close();
            };

            if (Directory.Exists(this.crashFilePath))
            {
                foreach (string filename in Directory.GetFiles(this.crashFilePath, _crashFilePrefix + "*.log"))
                {
                    try
                    {
                        FileStream fs = File.OpenRead(filename);
                        ICrashData cd = HockeyClient.Instance.Deserialize(fs);
                        fs.Close();
                        cd.SendDataAsync().Wait();
                        File.Delete(filename);
                    }
                    catch (Exception ex)
                    {
                        Program.LogToConsole("Error sending crash-information: " + ex.Message);
                    }
                }
            }
        }
Beispiel #6
0
        public void HandleException(Exception ex)
        {
            if (!this.PlatformHelper.PlatformSupportsSyncWrite)
            {
                throw new Exception("PlatformHelper implementation error.");
            }
            ICrashData cd      = this.CreateCrashData(ex);
            var        crashId = Guid.NewGuid();

            try {
                using (MemoryStream stream = new MemoryStream()) {
                    cd.Serialize(stream);
                    stream.Seek(0, SeekOrigin.Begin);
                    this.PlatformHelper.WriteStreamToFileSync(stream, string.Format("{0}{1}.log", SDKConstants.CrashFilePrefix, crashId), SDKConstants.CrashDirectoryName);
                }
            } catch (Exception e) {
                HandleInternalUnhandledException(e);
            }
        }