Ejemplo n.º 1
0
        private DbDiffOptions CreateDbDiffOptions()
        {
            var opts = new DbDiffOptions();
            var log  = new CachingLogger(LogLevel.All);

            messageLogFrame1.Source = log;
            opts.DiffLogger         = log;
            if (m_dstDb.Dialect != null)
            {
                opts.LeftImplicitSchema = m_dstDb.Dialect.DefaultSchema;
            }
            if (m_srcDb.Dialect != null)
            {
                opts.RightImplicitSchema = m_srcDb.Dialect.DefaultSchema;
            }
            if (!m_dstDb.DatabaseCaps.MultipleSchema)
            {
                opts.SchemaMode = DbDiffSchemaMode.Ignore;
            }
            if (!m_srcDb.DatabaseCaps.MultipleSchema)
            {
                opts.SchemaMode = DbDiffSchemaMode.Ignore;
            }
            if (m_settings.IgnoreSchema)
            {
                opts.SchemaMode = DbDiffSchemaMode.Ignore;
            }
            opts.IgnoreAllTableProperties = m_settings.IgnoreAllTableProperties;
            opts.IgnoreColumnOrder        = m_settings.IgnoreColumnOrder;
            opts.IgnoreConstraintNames    = m_settings.IgnoreConstraintNames;
            opts.IgnoreTableProperties    = m_settings.IgnoreTableProperties;
            opts.IgnoreDataTypeProperties = m_settings.IgnoreDataTypeProperties;
            opts.IgnoreColumnCharacterSet = m_settings.IgnoreColumnCharacterSet;
            opts.IgnoreColumnCollation    = m_settings.IgnoreColumnCollation;
            opts.IgnoreCase = m_settings.IgnoreCase;
            opts.AllowRecreateConstraint     = true;
            opts.AllowRecreateSpecificObject = true;
            opts.AllowRecreateTable          = true;
            opts.AllowPairRenamedTables      = m_settings.AllowPairRenamedTables;
            return(opts);
        }
Ejemplo n.º 2
0
        public override bool Save()
        {
            var dialect = m_conn.Dialect ?? GenericDialect.Instance;
            var plan    = new AlterPlan();
            var opts    = new DbDiffOptions();
            var log     = new CachingLogger(LogLevel.Info);

            opts.AlterLogger = log;
            DbDiffTool.AlterDatabase(plan, new DbObjectPairing(m_origDb, m_db), opts);
            string alterSql = dialect.GenerateScript(dmp => plan.CreateRunner().Run(dmp, opts));

            if (!SqlConfirmForm.Run(alterSql, dialect, log))
            {
                return(false);
            }
            m_conn.AlterDatabase(plan, opts);
            objectGridView1.Modified = false;
            UpdateState();
            LoadStructure();
            return(true);
        }
        private async Task <bool> WriteResultsAsync(TContext rootContext)
        {
            int currentIndex = 0;
            var itemsSeen    = new HashSet <int>();

            ChannelReader <int> reader = _resultsWritingChannel.Reader;

            // Wait until there is work or the channel is closed.
            while (await reader.WaitToReadAsync())
            {
                // Loop while there is work to do.
                while (reader.TryRead(out int item))
                {
                    Debug.Assert(!itemsSeen.Contains(item));
                    itemsSeen.Add(item);

                    // This condition can occur if currentIndex moves
                    // ahead in array processing due to operations
                    // against it by other threads. For this case,
                    // since the relevant file has already been
                    // processed, we just ignore this notification.
                    if (currentIndex > item)
                    {
                        break;
                    }

                    TContext context = default;
                    try
                    {
                        context = _fileContexts[currentIndex];

                        while (context?.AnalysisComplete == true)
                        {
                            CachingLogger cachingLogger = ((CachingLogger)context.Logger);
                            IDictionary <ReportingDescriptor, IList <Result> > results = cachingLogger.Results;

                            if (results?.Count > 0)
                            {
                                if (context.Hashes != null)
                                {
                                    Debug.Assert(_run != null);
                                    int index = _run.GetFileIndex(new ArtifactLocation()
                                    {
                                        Uri = context.TargetUri
                                    });

                                    _run.Artifacts[index].Hashes = new Dictionary <string, string>
                                    {
                                        { "sha-256", context.Hashes.Sha256 },
                                    };
                                }

                                foreach (KeyValuePair <ReportingDescriptor, IList <Result> > kv in results)
                                {
                                    foreach (Result result in kv.Value)
                                    {
                                        rootContext.Logger.Log(kv.Key, result);
                                    }
                                }
                            }

                            if (cachingLogger.ToolNotifications != null)
                            {
                                foreach (Notification notification in cachingLogger.ToolNotifications)
                                {
                                    rootContext.Logger.LogToolNotification(notification);
                                }
                            }

                            if (cachingLogger.ConfigurationNotifications != null)
                            {
                                foreach (Notification notification in cachingLogger.ConfigurationNotifications)
                                {
                                    rootContext.Logger.LogConfigurationNotification(notification);
                                }
                            }

                            RuntimeErrors |= context.RuntimeErrors;

                            _fileContexts[currentIndex] = default;

                            context       = currentIndex < (_fileContexts.Count - 1)
                                ? context = _fileContexts[currentIndex + 1]
                                : default;

                            currentIndex++;
                        }
                    }
                    catch (Exception e)
                    {
                        context        = default;
                        RuntimeErrors |= Errors.LogUnhandledEngineException(rootContext, e);
                        ThrowExitApplicationException(context, ExitReason.ExceptionWritingToLogFile, e);
                    }
                }
            }

            Debug.Assert(currentIndex == _fileContexts.Count);
            Debug.Assert(itemsSeen.Count == _fileContexts.Count);

            return(true);
        }