private void ApplyEnabledState(bool enabled)
        {
            lock (_serviceLock)
            {
                if (enabled && ChannelGroup != null)
                {
                    ApplicationLifecycleHelper.Instance.UnhandledExceptionOccurred += OnUnhandledExceptionOccurred;
                    ChannelGroup.SendingLog      += ChannelSendingLog;
                    ChannelGroup.SentLog         += ChannelSentLog;
                    ChannelGroup.FailedToSendLog += ChannelFailedToSendLog;
                }
                else if (!enabled)
                {
                    ApplicationLifecycleHelper.Instance.UnhandledExceptionOccurred -= OnUnhandledExceptionOccurred;
                    if (ChannelGroup != null)
                    {
                        ChannelGroup.SendingLog      -= ChannelSendingLog;
                        ChannelGroup.SentLog         -= ChannelSentLog;
                        ChannelGroup.FailedToSendLog -= ChannelFailedToSendLog;
                    }

                    // If we delete files while processing them, it will trigger noisy file errors.
                    // In Android, tasks are executed in a queue, so the disable has to wait files to be processed, we can improve windows SDK to use a queue and be more async when it comes to handling files and avoid locking later.
                    // But for now we emulate the same behavior by waiting here to fix the threading issue.
                    ProcessPendingErrorsTask?.Wait();
                    ErrorLogHelper.RemoveAllStoredErrorLogFiles();
                    _unprocessedManagedErrorLogs.Clear();
                    _lastSessionErrorReportTaskSource = null;
                }
            }
        }
示例#2
0
        public void RemoveAllStoredErrorLogFiles()
        {
            var mockDirectory = Mock.Of <Directory>();

            Mock.Get(mockDirectory).Setup(d => d.Exists()).Returns(true);
            ErrorLogHelper.Instance._crashesDirectory = mockDirectory;
            ErrorLogHelper.RemoveAllStoredErrorLogFiles();
            Mock.Get(mockDirectory).Verify(d => d.Delete(true));
        }
示例#3
0
        public void RemoveAllStoredErrorLogFilesDoesNotThrow(Type exceptionType)
        {
            // Use reflection to create an exception of the given C# type.
            var exception     = exceptionType.GetConstructor(Type.EmptyTypes).Invoke(null) as System.Exception;
            var mockDirectory = Mock.Of <Directory>();

            ErrorLogHelper.Instance._crashesDirectory = mockDirectory;
            Mock.Get(mockDirectory).Setup(d => d.EnumerateFiles(It.IsAny <string>())).Throws(exception);
            ErrorLogHelper.RemoveAllStoredErrorLogFiles();

            // No exception should be thrown.
        }