Example #1
0
        public async Task Connect([NotNull] string path)
        {
            var isExist = CheckFileExist(path);

            if (!isExist)
            {
                Logger.Log(LogLevel.Info, "Failed to connect to non-database file: {0}", path);
                return;
            }

            DisposeConnection();
            LocalDbContext context;

            try {
                context = new LocalDbContext(CreateConnection(path));
                var exists = context.Database.Exists();
            }
            catch (Exception e) {
                Logger.Log(LogLevel.Info, "Failed to connect to database file: {0}", path);
                Logger.Log(LogLevel.Error, e);
                throw;
            }

            await Migrate(context);

            this.Context             = context;
            this.CurrentDatabasePath = path;
            DatabaseChanged?.Invoke(this, path);
        }
 private void ChangeDatabase()
 {
     DatabaseDirty = true;
     if (DatabaseChanged != null)
     {
         DatabaseChanged.Invoke();
     }
 }
Example #3
0
 public static void Reconnect(string dataSource)
 {
     _instance?._delayedUpdateStart.Dispose();
     _instance?.Dispose();
     _instance = new GeneralDbContext(dataSource);
     Init();
     DatabaseChanged?.Invoke(_instance, dataSource);
 }
 private static List <Notification> CreateSampleNotificationsForFilterOutTest()
 {
     return(new List <Notification>
     {
         AlertRaised.Create(
             null,
             "DatabaseTopologyWarning",
             "DatabaseTopologyWarning_MSG",
             AlertType.DatabaseTopologyWarning,
             NotificationSeverity.Info),
         DatabaseChanged.Create(null, DatabaseChangeType.Put), // filtered out, DatabaseChange
         AlertRaised.Create(
             null,
             "LicenseManager_AGPL3",
             "LicenseManager_AGPL3_MSG",
             AlertType.ClusterTransactionFailure,
             NotificationSeverity.Info),
         AlertRaised.Create(
             null,
             "LicenseManager_AGPL3",
             "LicenseManager_AGPL3_MSG",
             AlertType.LicenseManager_AGPL3, // filtered out explicitly
             NotificationSeverity.Info),
         AlertRaised.Create(
             null,
             "RevisionsConfigurationNotValid",
             "RevisionsConfigurationNotValid_MSG",
             AlertType.RevisionsConfigurationNotValid, // filtered out explicitly
             NotificationSeverity.Info),
         AlertRaised.Create(
             null,
             "Certificates_ReplaceError",
             "Certificates_ReplaceError_MSG",
             AlertType.Certificates_ReplaceError,
             NotificationSeverity.Info),
         PerformanceHint.Create(
             null,
             "SlowIO",
             "SlowIO_MSG",
             PerformanceHintType.SlowIO, // filtered out, PerformanceHint
             NotificationSeverity.Info,
             "test"),
         PerformanceHint.Create(
             null,
             "SqlEtl_SlowSql",
             "SqlEtl_SlowSql_MSG",
             PerformanceHintType.SqlEtl_SlowSql, // filtered out, PerformanceHint
             NotificationSeverity.Info,
             "test"),
         OperationChanged.Create(null, 1, new Operations.OperationDescription(), new OperationState()
         {
             Result = new PersistableResult()
         }, false),
         DatabaseChanged.Create(null, DatabaseChangeType.Delete) // filtered out, DatabaseChange
     });
 }
        private void cmbDatabase_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbTable.Items.Clear();
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                Tables = connection.GetTableNames();
                Tables.ForEach(x => cmbTable.Items.Add(x));

                DatabaseChanged?.Invoke();
            }
        }
Example #6
0
 private void RaiseDatabaseChanged()
 {
     if (_deferedEventCount == 0)
     {
         LastModifiedDate = DateTime.UtcNow;
         DatabaseChanged?.Invoke(this, EventArgs.Empty);
         _deferedEventCalled = false;
     }
     else
     {
         _deferedEventCalled = true;
     }
 }
Example #7
0
        private DocumentDatabase ActuallyCreateDatabase(StringSegment databaseName, RavenConfiguration config, DateTime?wakeup = null)
        {
            IDisposable release = null;

            try
            {
                if (_serverStore.Disposed)
                {
                    ThrowServerIsBeingDisposed(databaseName);
                }

                //if false, this means we have started disposing, so we shouldn't create a database now
                release = EnterReadLockImmediately(databaseName);

                var db = CreateDocumentsStorage(databaseName, config, wakeup);
                _serverStore.NotificationCenter.Add(
                    DatabaseChanged.Create(databaseName.Value, DatabaseChangeType.Load));

                return(db);
            }
            catch (Exception e)
            {
                // if we are here, there is an error, and if there is an error, we need to clear it from the
                // resource store cache so we can try to reload it.
                // Note that we return the faulted task anyway, because we need the user to look at the error
                if (e.Data.Contains("Raven/KeepInResourceStore") == false)
                {
                    DatabasesCache.TryRemove(databaseName, out _);
                }

                if (_logger.IsInfoEnabled && e.InnerException is UnauthorizedAccessException)
                {
                    _logger.Info("Failed to load database because couldn't access certain file. Please check permissions, and make sure that nothing locks that file (an antivirus is a good example of something that can lock the file)", e);
                }

                throw;
            }
            finally
            {
                try
                {
                    _databaseSemaphore.Release();
                }
                catch (ObjectDisposedException)
                {
                    // nothing to do
                }

                release?.Dispose();
            }
        }
        // Call this when IsActive has changed.
        protected void RefreshActive()
        {
            if (IsActive)
            {
                EditorApplication.update -= AutoRefresh;
                EditorApplication.update += AutoRefresh;

                m_LastRefreshTime = EditorApplication.timeSinceStartup;
            }
            else
            {
                EditorApplication.update -= AutoRefresh;

                m_Data.Clear();
                m_IsReady = false;
                DatabaseChanged?.Invoke();
            }
        }
Example #9
0
        private DocumentDatabase ActuallyCreateDatabase(StringSegment databaseName, RavenConfiguration config, DateTime?wakeup = null)
        {
            IDisposable release = null;

            try
            {
                if (_serverStore.Disposed)
                {
                    ThrowServerIsBeingDisposed(databaseName);
                }

                //if false, this means we have started disposing, so we shouldn't create a database now
                release = EnterReadLockImmediately(databaseName);

                var db = CreateDocumentsStorage(databaseName, config, wakeup);
                _serverStore.NotificationCenter.Add(
                    DatabaseChanged.Create(databaseName.Value, DatabaseChangeType.Load));

                return(db);
            }
            catch (Exception e)
            {
                if (_logger.IsInfoEnabled && e.InnerException is UnauthorizedAccessException)
                {
                    _logger.Info("Failed to load database because couldn't access certain file. Please check permissions, and make sure that nothing locks that file (an antivirus is a good example of something that can lock the file)", e);
                }

                throw;
            }
            finally
            {
                try
                {
                    _databaseSemaphore.Release();
                }
                catch (ObjectDisposedException)
                {
                    // nothing to do
                }

                release?.Dispose();
            }
        }
        private void WaitAndFinishDatabaseUpdate()
        {
            if (m_PendingData == null)
            {
                return;
            }

            if (DoTraceLogs)
            {
                Debug.Log($"Finished updating {name} at {EditorApplication.timeSinceStartup:0.00}");
            }

            EditorApplication.update -= WaitAndFinishDatabaseUpdate;
            m_WorkerThread            = null;

            m_IsReady = true;

            var pendingData = m_PendingData;

            m_PendingData = null;
            m_Data.Clear();

            // Mark update as finished.
            m_PendingUpdate = false;

            // If preferences were changed while waiting.
            if (!IsActive)
            {
                m_IsReady = false;
                return;
            }

            // Process the gathered data in the main thread, since Unity API is not thread-safe.
            WaitAndFinishDatabaseUpdate(pendingData);

            DatabaseChanged?.Invoke();
        }
Example #11
0
        public void UploadFile(RemoteFileInfo request)
        {
            // kill target file, if already exists
            string filePath = Path.Combine(Constants.GetCurrentDirectoryPath, Constants.DB_NAME);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            const int chunkSize = 2048;
            var       buffer    = new byte[chunkSize];

            using (var writeStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write))
            {
                do
                {
                    // read bytes from input stream
                    int bytesRead = request.FileByteStream.Read(buffer, 0, chunkSize);
                    if (bytesRead == 0)
                    {
                        break;
                    }

                    // write bytes to output stream
                    writeStream.Write(buffer, 0, bytesRead);
                } while (true);

                writeStream.Close();
            }

            if (DatabaseChanged != null)
            {
                DatabaseChanged.Invoke(null, null);
            }
        }
 public static void OnDatabaseChanged()
 {
     DatabaseChanged?.Invoke(null, null);
 }
Example #13
0
 private void RaiseDatabaseChanged()
 {
     Console.WriteLine("DatabaseChanged");
     DatabaseChanged?.Invoke(this, EventArgs.Empty);
 }
        private void WaitAndFinishDatabaseUpdate()
        {
            if (m_PendingStatuses == null)
            {
                return;
            }

            if (DoTraceLogs)
            {
                Debug.Log($"Finished Update Database at {EditorApplication.timeSinceStartup:0.00}");
            }

            EditorApplication.update -= WaitAndFinishDatabaseUpdate;
            m_WorkerThread            = null;

            var statuses = m_PendingStatuses;

            m_PendingStatuses = null;
            StatusDatas.Clear();

            // Mark update as finished.
            PendingUpdate = false;

            // If preferences were changed while waiting.
            if (!IsActive)
            {
                return;
            }

            // Process the gathered statuses in the main thread, since Unity API is not thread-safe.
            foreach (var foundStatusData in statuses)
            {
                // Because structs can't be modified in foreach.
                var statusData = foundStatusData;

                // Meta statuses are also considered. They are shown as the asset status.
                if (statusData.Path.EndsWith(".meta", StringComparison.OrdinalIgnoreCase))
                {
                    statusData.Path = statusData.Path.Substring(0, statusData.Path.LastIndexOf(".meta"));
                }

                // Conflicted is with priority.
                if (statusData.IsConflicted)
                {
                    statusData.Status = VCFileStatus.Conflicted;
                }

                var guid = AssetDatabase.AssetPathToGUID(statusData.Path);
                if (string.IsNullOrEmpty(guid))
                {
                    // Files were added in the background without Unity noticing.
                    // When the user focuses on Unity, it will refresh them as well.
                    continue;
                }

                // File was added to the repository but is missing in the working copy.
                // The proper way to check this is to parse the working revision from the svn output (when used with -u)
                if (statusData.RemoteStatus == VCRemoteFileStatus.Modified &&
                    statusData.Status == VCFileStatus.Normal &&
                    string.IsNullOrEmpty(guid)
                    )
                {
                    continue;
                }

                // TODO: Test tree conflicts.
                SetStatusData(guid, statusData, false);

                AddModifiedFolders(statusData);
            }

            DatabaseChanged?.Invoke();
        }
 private static void OnDatabaseChanged(ModeltypEnum typ)
 {
     DatabaseChanged?.Invoke(typ, EventArgs.Empty);
 }
Example #16
0
 public void NotifyChange()
 {
     DatabaseChanged?.Invoke();
 }
 private void OnDatabaseChange(DataItemEventArgs <T> e)
 {
     DatabaseChanged?.Invoke(this, e);
 }