Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RaygunClient" /> class.
        /// </summary>
        /// <param name="apiKey">The API key.</param>
        public RaygunClient(string apiKey)
        {
            _apiKey = apiKey;

            _fileManager = new RaygunFileManager();
            _fileManager.Intialise();

            MaxReportsStoredOnDevice = RaygunFileManager.MAX_STORED_REPORTS_UPPER_LIMIT;

            // Setting default user information.
            var anonUser = GetAnonymousUserInfo();

            _userInfo = anonUser;
            _user     = anonUser.Identifier;

            _wrapperExceptions.Add(typeof(TargetInvocationException));
            _wrapperExceptions.Add(typeof(AggregateException));

            try
            {
                var clientVersion = new AssemblyName(GetType().Assembly.FullName).Version.ToString();
                RaygunLogger.Info(string.Format("Configuring Raygun ({0})", clientVersion));
            }
            catch
            {
                // Ignore
            }
        }
Esempio n. 2
0
        private void SendAllStoredCrashReports()
        {
            if (!HasInternetConnection)
            {
                RaygunLogger.Debug("Not sending stored crash reports due to no internet connection");
                return;
            }

            // Get all stored crash reports.
            var reports = _fileManager.GetAllStoredCrashReports();

            RaygunLogger.Info(string.Format("Attempting to send {0} stored crash report(s)", reports.Count));

            // Quick escape if there's no crash reports.
            if (reports.Count == 0)
            {
                return;
            }

            try
            {
                Task.Run(async() =>
                {
                    // Use a single HttpClient for all requests.
                    using (var client = new HttpClient())
                    {
                        foreach (var report in reports)
                        {
                            await SendStoredReportAsync(client, report);
                        }
                    }
                }).ContinueWith(t =>
                {
                    if (t != null && t.IsFaulted)
                    {
                        RaygunLogger.Error("Fault occurred when sending stored reports - clearing stored reports");

                        try
                        {
                            // If there was an issue then clear the stored reports.
                            _fileManager.RemoveFiles(reports);
                        }
                        catch (Exception e)
                        {
                            RaygunLogger.Error("Failed to remove stored report due to error: " + e.Message);
                        }
                    }

                    if (t != null && t.Exception != null)
                    {
                        // Consume all errors as we dont want them being sent.
                        t.Exception.Handle((e) =>
                        {
                            RaygunLogger.Error("Error occurred while sending stored reports: " + e.Message);
                            return(true); // Handled
                        });
                    }
                });
            }
            catch (Exception e)
            {
                RaygunLogger.Error("Failed to send stored reports due to error: " + e.Message);
            }
        }