Esempio n. 1
0
        private void Awake()
        {
            Configuration = GetComponent <BacktraceClient>().Configuration;
            if (Configuration == null || !Configuration.IsValid())
            {
                Debug.LogWarning("Configuration doesn't exists or provided serverurl/token are invalid");
                _enable = false;
                return;
            }

            DatabaseSettings = new BacktraceDatabaseSettings(Configuration);
            if (DatabaseSettings == null)
            {
                _enable = false;
                return;
            }
            if (Configuration.CreateDatabase)
            {
                Directory.CreateDirectory(Configuration.DatabasePath);
            }
            _enable = Configuration.Enabled && BacktraceConfiguration.ValidateDatabasePath(Configuration.DatabasePath);

            if (!_enable)
            {
                return;
            }

            _lastConnection = Time.time;

            BacktraceDatabaseContext     = new BacktraceDatabaseContext(DatabasePath, DatabaseSettings.RetryLimit, DatabaseSettings.RetryOrder);
            BacktraceDatabaseFileContext = new BacktraceDatabaseFileContext(DatabasePath, DatabaseSettings.MaxDatabaseSize, DatabaseSettings.MaxRecordCount);
            BacktraceApi = new BacktraceApi(Configuration.ToCredentials(), Convert.ToUInt32(Configuration.ReportPerMin));
        }
 /// <summary>
 /// Initialize new instance of Backtrace Database Context
 /// </summary>
 /// <param name="settings">Database settings</param>
 public BacktraceDatabaseContext(BacktraceDatabaseSettings settings)
 {
     _retryNumber          = checked ((int)settings.RetryLimit);
     RetryOrder            = settings.RetryOrder;
     DeduplicationStrategy = settings.DeduplicationStrategy;
     SetupBatch();
 }
Esempio n. 3
0
        /// <summary>
        /// Reload Backtrace database configuration. Reloading configuration is required, when you change
        /// BacktraceDatabase configuration options.
        /// </summary>
        public void Reload()
        {
            // validate configuration
            if (Configuration == null)
            {
                Configuration = GetComponent <BacktraceClient>().Configuration;
            }
            if (Configuration == null || !Configuration.IsValid())
            {
                Debug.LogWarning("Configuration doesn't exists or provided serverurl/token are invalid");
                Enable = false;
                return;
            }


            //setup database object
            DatabaseSettings = new BacktraceDatabaseSettings(Configuration);

            Enable = Configuration.Enabled && BacktraceConfiguration.ValidateDatabasePath(Configuration.DatabasePath);
            if (!Enable)
            {
                Debug.LogWarning("Cannot initialize database - invalid database configuration. Database is disabled");
                return;
            }
            CreateDatabaseDirectory();
            SetupMultisceneSupport();
            _lastConnection = Time.time;

            //Setup database context
            BacktraceDatabaseContext     = new BacktraceDatabaseContext(DatabasePath, DatabaseSettings.RetryLimit, DatabaseSettings.RetryOrder, DatabaseSettings.DeduplicationStrategy);
            BacktraceDatabaseFileContext = new BacktraceDatabaseFileContext(DatabasePath, DatabaseSettings.MaxDatabaseSize, DatabaseSettings.MaxRecordCount);
            BacktraceApi        = new BacktraceApi(Configuration.ToCredentials());
            _reportLimitWatcher = new ReportLimitWatcher(Convert.ToUInt32(Configuration.ReportPerMin));
        }
Esempio n. 4
0
        public void Setup()
        {
            //mock file context
            var mockFileContext = new Mock <IBacktraceDatabaseFileContext>();

            mockFileContext.Setup(n => n.GetRecords())
            .Returns(new List <FileInfo>());
            mockFileContext.Setup(n => n.Clear());

            ////mock api
            var mockApi = new Mock <IBacktraceApi>();

            mockApi.Setup(n => n.Send(It.IsAny <BacktraceData>()))
            .Returns(BacktraceResult.OnError(It.IsAny <BacktraceReport>(), new Exception("error")));

            var backtraceDatabaseSettings = new BacktraceDatabaseSettings(_projectDirectory)
            {
                RetryLimit            = _batchLimit,
                RetryBehavior         = Types.RetryBehavior.NoRetry,
                AutoSendMode          = false,
                DeduplicationStrategy = DeduplicationStrategy.LibraryName | DeduplicationStrategy.Classifier | DeduplicationStrategy.Message
            };

            _backtraceDatabase = new BacktraceDatabase(backtraceDatabaseSettings)
            {
                BacktraceApi = mockApi.Object,
                BacktraceDatabaseFileContext = mockFileContext.Object
            };
            _backtraceDatabase.Start();
        }
Esempio n. 5
0
 /// <summary>
 /// Initialize new BacktraceDatabaseFileContext instance
 /// </summary>
 public BacktraceDatabaseFileContext(BacktraceDatabaseSettings settings)
 {
     _attachmentManager = new BacktraceDatabaseAttachmentManager(settings);
     _maxDatabaseSize   = settings.MaxDatabaseSize;
     _maxRecordNumber   = settings.MaxRecordCount;
     _path = settings.DatabasePath;
     _databaseDirectoryInfo = new DirectoryInfo(_path);
 }
Esempio n. 6
0
 /// <summary>
 /// Initializing Backtrace client instance
 /// </summary>
 /// <param name="sectionName">Backtrace configuration section in App.config or Web.config file. Default section is BacktraceCredentials</param>
 /// <param name="attributes">Client's attributes</param>
 /// <param name="databaseSettings">Backtrace database settings</param>
 /// <param name="reportPerMin">Numbers of records sending per one min</param>
 public BacktraceClient(
     BacktraceDatabaseSettings databaseSettings,
     string sectionName = "BacktraceCredentials",
     Dictionary <string, object> attributes = null,
     uint reportPerMin = 3)
     : base(BacktraceCredentials.ReadConfigurationSection(sectionName),
            attributes, new BacktraceDatabase(databaseSettings), reportPerMin)
 {
 }
Esempio n. 7
0
 /// <summary>
 /// Initializing Backtrace client instance with BacktraceCredentials
 /// </summary>
 /// <param name="backtraceCredentials">Backtrace credentials</param>
 /// <param name="databaseSettings">Backtrace database settings</param>
 /// <param name="attributes">Client's attributes</param>
 /// <param name="reportPerMin">Numbers of records sending per one minute</param>
 public BacktraceClient(
     BacktraceCredentials backtraceCredentials,
     BacktraceDatabaseSettings databaseSettings,
     Dictionary <string, object> attributes = null,
     uint reportPerMin = 3)
     : base(backtraceCredentials, attributes,
            databaseSettings, reportPerMin)
 {
 }
Esempio n. 8
0
 /// <summary>
 /// Initialize new instance of Backtrace Database Context
 /// </summary>
 /// <param name="settings">Database settings</param>
 public BacktraceDatabaseContext(BacktraceDatabaseSettings settings)
 {
     _path                 = settings.DatabasePath;
     _retryNumber          = checked ((int)settings.RetryLimit);
     _attachmentManager    = new BacktraceDatabaseAttachmentManager(settings);
     RetryOrder            = settings.RetryOrder;
     DeduplicationStrategy = settings.DeduplicationStrategy;
     SetupBatch();
 }
Esempio n. 9
0
 /// <summary>
 /// Initialize new client instance with BacktraceCredentials
 /// </summary>
 /// <param name="backtraceCredentials">Backtrace credentials to access Backtrace API</param>
 /// <param name="attributes">Additional information about current application</param>
 /// <param name="databaseSettings">Backtrace database settings</param>
 /// <param name="reportPerMin">Number of reports sending per one minute. If value is equal to zero, there is no request sending to API. Value have to be greater than or equal to 0</param>
 public BacktraceBase(
     BacktraceCredentials backtraceCredentials,
     Dictionary <string, object> attributes     = null,
     BacktraceDatabaseSettings databaseSettings = null,
     uint reportPerMin = 3)
     : this(backtraceCredentials, attributes, new BacktraceDatabase(databaseSettings),
            reportPerMin)
 {
 }
Esempio n. 10
0
 /// <summary>
 /// Create Backtrace database instance
 /// </summary>
 /// <param name="databaseSettings">Backtrace database settings</param>
 public BacktraceDatabase(BacktraceDatabaseSettings databaseSettings)
 {
     if (databaseSettings == null || string.IsNullOrEmpty(databaseSettings.DatabasePath))
     {
         return;
     }
     if (!Directory.Exists(databaseSettings.DatabasePath))
     {
         throw new ArgumentException("Databse path does not exists");
     }
     DatabaseSettings             = databaseSettings;
     BacktraceDatabaseContext     = new BacktraceDatabaseContext(databaseSettings);
     BacktraceDatabaseFileContext = new BacktraceDatabaseFileContext(DatabasePath, DatabaseSettings.MaxDatabaseSize, DatabaseSettings.MaxRecordCount);
 }
        /// <summary>
        /// Reload Backtrace database configuration. Reloading configuration is required, when you change
        /// BacktraceDatabase configuration options.
        /// </summary>
        public void Reload()
        {
            // validate configuration
            if (Configuration == null)
            {
                Configuration = GetComponent <BacktraceClient>().Configuration;
            }
            if (Instance != null)
            {
                return;
            }
            if (Configuration == null || !Configuration.IsValid())
            {
                Enable = false;
                return;
            }

#if UNITY_SWITCH
            Enable = false;
#else
            Enable = Configuration.Enabled && InitializeDatabasePaths();
#endif
            if (!Enable)
            {
                if (Configuration.Enabled)
                {
                    Debug.LogWarning("Cannot initialize database - invalid path to database. Database is disabled");
                }
                return;
            }


            //setup database object
            DatabaseSettings = new BacktraceDatabaseSettings(DatabasePath, Configuration);
            SetupMultisceneSupport();
            _lastConnection = Time.time;
            LastFrameTime   = Time.time;
            //Setup database context
            BacktraceDatabaseContext     = new BacktraceDatabaseContext(DatabaseSettings);
            BacktraceDatabaseFileContext = new BacktraceDatabaseFileContext(DatabaseSettings.DatabasePath, DatabaseSettings.MaxDatabaseSize, DatabaseSettings.MaxRecordCount);
            BacktraceApi        = new BacktraceApi(Configuration.ToCredentials());
            _reportLimitWatcher = new ReportLimitWatcher(Convert.ToUInt32(Configuration.ReportPerMin));
        }
Esempio n. 12
0
        public void Setup()
        {
            //mock file context
            var mockFileContext = new Mock <IBacktraceDatabaseFileContext>();

            mockFileContext.Setup(n => n.GetRecords())
            .Returns(new List <FileInfo>());
            mockFileContext.Setup(n => n.Clear());

            var backtraceDatabaseSettings = new BacktraceDatabaseSettings(_projectDirectory)
            {
                MaxRecordCount = _totalNumberOfReports,
                RetryBehavior  = Types.RetryBehavior.NoRetry
            };

            _backtraceDatabase = new BacktraceDatabase(backtraceDatabaseSettings)
            {
                BacktraceDatabaseFileContext = mockFileContext.Object
            };
            //start database
            _backtraceDatabase.Start();
        }
Esempio n. 13
0
        public virtual void Setup()
        {
            //get project path
            string projectPath = Path.GetTempPath();

            //mock api
            var mockApi = new Mock <IBacktraceApi>();

            mockApi.Setup(n => n.Send(It.IsAny <BacktraceData>()))
            .Returns(new BacktraceResult());

            //mock file context
            var mockFileContext = new Mock <IBacktraceDatabaseFileContext>();

            mockFileContext.Setup(n => n.GetRecords())
            .Returns(new List <FileInfo>());

            //mock cache
            var mockCacheContext = new Mock <IBacktraceDatabaseContext>();

            mockFileContext.Setup(n => n.RemoveOrphaned(It.IsAny <IEnumerable <BacktraceDatabaseRecord> >()));
            mockFileContext.Setup(n => n.Clear());

            var settings = new BacktraceDatabaseSettings(projectPath)
            {
                RetryBehavior  = RetryBehavior.NoRetry,
                AutoSendMode   = false, //we don't want to test timers
                MaxRecordCount = 100,
                RetryLimit     = 3
            };

            _database = new BacktraceDatabase(settings)
            {
                BacktraceDatabaseContext     = new MockBacktraceDatabaseContext(projectPath, 3, RetryOrder.Stack),
                BacktraceDatabaseFileContext = mockFileContext.Object,
                BacktraceApi = mockApi.Object
            };
        }
 public BacktraceDatabaseContextMock(BacktraceDatabaseSettings settings) : base(settings)
 {
     _settings = settings;
 }
 /// <summary>
 /// Initialize new instance of Backtrace Database Context
 /// </summary>
 /// <param name="settings">Database settings</param>
 public BacktraceDatabaseContext(BacktraceDatabaseSettings settings)
     : this(settings.DatabasePath, settings.RetryLimit, settings.RetryOrder, settings.DeduplicationStrategy)
 {
 }
Esempio n. 16
0
        static void Main(string[] args)
        {
            //setup tls support for tested server
            ServicePointManager.SecurityProtocol =
                SecurityProtocolType.Tls
                | (SecurityProtocolType)0x00000300
                | (SecurityProtocolType)0x00000C00;

            var credentials = new BacktraceCredentials(ApplicationSettings.Host, ApplicationSettings.Token);
            // create Backtrace library configuration
            var configuartion = new BacktraceClientConfiguration(credentials)
            {
                ReportPerMin = 0
            };

            //initialize new BacktraceClient with custom configuration section readed from file App.config
            //Client will be initialized with values stored in default section name "BacktraceCredentials"
            BacktraceClient backtraceClientWithSectionCredentials = new BacktraceClient();

            //create new backtrace database settings
            BacktraceDatabaseSettings databaseSettings = new BacktraceDatabaseSettings(ApplicationSettings.DatabasePath);
            //create Backtrace database
            var database = new BacktraceDatabase(databaseSettings);
            //setup new client
            var backtraceClient = new BacktraceClient(credentials, databaseSettings);

            //Add new scoped attributes
            backtraceClient.Attributes["ClientAttributeNumber"]      = 1;
            backtraceClient.Attributes["ClientAttributeString"]      = "/string attribute";
            backtraceClient.Attributes["ClientAttributeCustomClass"] = new
            {
                Name = "Backtrace",
                Type = "Library"
            };
            //Add your own handler to client API
            backtraceClient.BeforeSend =
                (BacktraceData model) =>
            {
                var data = model;
                data.Attributes.Add("eventAtrtibute", "EventAttributeValue");
                return(data);
            };

            //Report a new exception from current application
            try
            {
                try
                {
                    int.Parse("abc");
                }
                catch (Exception inner)
                {
                    try
                    {
                        var openLog = File.Open("Not existing path", FileMode.Open);
                    }
                    catch
                    {
                        throw new FileNotFoundException("OutterException", inner);
                    }
                }
            }
            catch (Exception e)
            {
                var report = new BacktraceReport(
                    exception: e,
                    attributes: new Dictionary <string, object>()
                {
                    { "AttributeString", "string" }
                },
                    attachmentPaths: new List <string>()
                {
                    @"path to file attachment", @"patch to another file attachment"
                }
                    );
                var response = backtraceClient.Send(report);
            }
            //Report a new message
            var sendResult = backtraceClient.Send("Client message");
        }