private void OnViewSchemaReaderProgressChanged(ViewSchema lastProcessed, int processed, int remaining)
 {
     var handler = ViewSchemaReaderProgressChanged;
     if (handler != null)
     {
         handler(this, new ViewSchemaReaderProgressChangedEventArgs(lastProcessed, processed, remaining));
     }
 }
        private static void AddSQLiteView(SQLiteConnection conn, ViewSchema vs, FailedViewDefinitionHandler handler)
        {
            // Prepare a CREATE VIEW DDL statement
            String stmt = vs.ViewSQL;
            
            // Execute the query in order to actually create the view.
            SQLiteTransaction tx = conn.BeginTransaction();
            try
            {
                var cmd = new SQLiteCommand(stmt, conn, tx);
                cmd.ExecuteNonQuery();

                tx.Commit();
            }
            catch (SQLiteException ex)
            {
                Log.Error("Error in \"AddSQLiteView\"", ex);
                tx.Rollback();

                // Rethrow the exception if it the caller didn't supply a handler.
                if (handler == null) { throw; }
                
                var updated = new ViewSchema();
                updated.ViewName = vs.ViewName;
                updated.ViewSQL = vs.ViewSQL;

                // Ask the user to supply the new view definition SQL statement
                String sql = handler(updated);

                if (sql != null)
                {
                    // Try to re-create the view with the user-supplied view definition SQL
                    updated.ViewSQL = sql;
                    AddSQLiteView(conn, updated, handler);
                }
            }
        }
        private List<ViewSchema> GetViews(SqlConversionProgressReportingHandler progressReportingHandler = null)
        {
            var views = new List<ViewSchema>();
            
            Regex removedbo = new Regex(@"dbo\.", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            using (var conn = new SqlConnection(_connectionString))
            {
                conn.Open();

                var cmd = new SqlCommand(@"SELECT TABLE_NAME, VIEW_DEFINITION from INFORMATION_SCHEMA.VIEWS", conn);
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var vs = new ViewSchema();

                        if (reader["TABLE_NAME"] == DBNull.Value) { continue; }
                        if (reader["VIEW_DEFINITION"] == DBNull.Value) { continue; }
                        vs.ViewName = (string)reader["TABLE_NAME"];
                        vs.ViewSQL = (string)reader["VIEW_DEFINITION"];

                        // Remove all ".dbo" strings from the view definition
                        vs.ViewSQL = removedbo.Replace(vs.ViewSQL, String.Empty);

                        views.Add(vs);
                    }
                }
            }

            Object stateLocker = new Object();
            int count = 0;
            int totalViews = views.Count;
            var parallelResult = Parallel.For(0, totalViews, i =>
            {
                var vs = views[i];
                count++;
                if (progressReportingHandler != null)
                {
                    progressReportingHandler(false, true, 50 + (int)(count * 50.0 / totalViews), "Parsed view " + vs.ViewName);
                }

                int viewsProcessed;
                lock (stateLocker)
                {
                    count++;
                    viewsProcessed = count; // Copy the current number of processed views to a local for future usage.
                }
                SqlServerToSQLite.CheckCancelled();
                if (progressReportingHandler != null)
                {
                    progressReportingHandler(false, true, (int)(count * 50.0 / totalViews), "Parsed table " + vs.ViewName);
                }
                _log.Debug("parsed view schema for [" + vs.ViewName + "]");

                int remaining = totalViews - viewsProcessed;
                OnViewSchemaReaderProgressChanged(vs, viewsProcessed, remaining);
            });

            while (!parallelResult.IsCompleted)
            {
                Thread.Sleep(1000);
            }
            _log.Debug("finished parsing all views in SQL Server schema");
            return views;
        }
Beispiel #4
0
 private string FailedViewDefinitionHandler(ViewSchema vs)
 {
     String updated = null;
     var dialog = new ViewFailureDialog();
     dialog.View = vs;
     DialogResult res = dialog.ShowDialog(this);
     if (res == DialogResult.OK)
     {
         updated = dialog.ViewSQL;
     }
     return updated;
 }
Beispiel #5
0
 private string OnFailedViewDefinitionHandler(ViewSchema vs)
 {
     string updated = null;
     Invoke(new MethodInvoker(() =>
     {
         updated = FailedViewDefinitionHandler(vs);
     }));
     return updated;
 }
 public ViewSchemaReaderProgressChangedEventArgs(ViewSchema lastProcessedView, int viewsProcessed, int viewsRemaining)
 {
     LastProcessedView = lastProcessedView;
     ViewsProcessed = viewsProcessed;
     ViewsRemaining = viewsRemaining;
 }
Beispiel #7
0
 private static string OnFailedViewDefinitionHandler(ViewSchema vs)
 {
     throw new NotImplementedException();
 }