Exemplo n.º 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
            }
        }
Exemplo n.º 4
0
        public void Configure(Application application,
                              string identifier,
                              Frame rootFrame = null,
                              Func <Exception, string> descriptionLoader = null,
                              string apiBase            = null,
                              string userId             = null,
                              string contactInformation = null)
        {
            if (this._application == null)
            {
                this._crashLogInfo = new CrashLogInformation()
                {
                    PackageName  = application.GetType().Namespace,
                    ProductID    = ManifestHelper.GetProductID(),
                    Version      = ManifestHelper.GetAppVersion(),
                    WindowsPhone = Environment.OSVersion.Version.ToString(),
                    Manufacturer = GetDeviceManufacturer(),
                    Model        = GetDeviceModel()
                };


                this._application = application;
                this._application.UnhandledException += OnUnhandledException;
                HockeyClient.ConfigureInternal(identifier,
                                               ManifestHelper.GetAppVersion(),
                                               userID: userId,
                                               apiBase: apiBase,
                                               contactInformation: contactInformation,
                                               userAgentName: Constants.UserAgentString,
                                               sdkName: Constants.SdkName,
                                               sdkVersion: Constants.SdkVersion,
                                               descriptionLoader: descriptionLoader,
                                               os: Environment.OSVersion.Platform.ToString(),
                                               osVersion: Environment.OSVersion.Version.ToString(),
                                               device: GetDeviceModel(),
                                               oem: GetDeviceManufacturer());
                if (rootFrame != null)
                {
                    //Idea based on http://www.markermetro.com/2013/01/technical/handling-unhandled-exceptions-with-asyncawait-on-windows-8-and-windows-phone-8/
                    AsyncSynchronizationContext.RegisterForFrame(rootFrame, this);
                }
            }
            else
            {
                throw new InvalidOperationException("CrashHandler was already configured!");
            }
        }
Exemplo n.º 5
0
        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);
                    }
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Create a CrashData object from an Exception and a given CrashLogInformation
 /// </summary>
 /// <param name="ex"></param>
 /// <param name="crashLogInfo"></param>
 /// <returns></returns>
 public ICrashData CreateCrashData(Exception ex, CrashLogInformation crashLogInfo)
 {
     return(new CrashData(this, ex, crashLogInfo));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Create a CrashData object from an Exception and a given CrashLogInformation
 /// </summary>
 /// <param name="ex"></param>
 /// <param name="crashLogInfo"></param>
 /// <returns></returns>
 public ICrashData CreateCrashData(Exception ex, CrashLogInformation crashLogInfo)
 {
     return new CrashData(this, ex, crashLogInfo);
 }