newbie idiot question

filthysockfilthysock Posts: 3
edited September 26, 2007 9:55AM in SQL Toolkit Previous Versions
So I have a project file created in the GUI version of SQL Compare.
I can load it into my .net project using Project.LoadFromDisk().

But what now, where is the method to go "run this project?" like I would by running the command line program with the /project option?

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 New member
    Hi,

    You may use the project options to populate the options of a normal comparison in code, for example:
    using System;
    using RedGate.SQLCompare.Engine;
    using RedGate.SQL.Shared;
    using System.Collections;
    
    namespace LoadAndSaveAProject
    {
        /// <summary>
        /// Demonstrates how to create a SQL Compare project file comparing WidgetProduction to
        /// WidgetStaging.
        /// </summary>
        class Program
        {
            static void Main(string[] args)
            {
                // Construct a project comparing WidgetProduction to WidgetStaging
                Project productionVsStaging = new Project();
    
                // By default the two data sources are created as LiveDatabaseSources with
                // the server name set to "(local)". You could also assign SnapshotSource
                // or FolderDataSource objects here.
                productionVsStaging.DataSource1.DatabaseName = "WidgetProduction";
                productionVsStaging.DataSource2.DatabaseName = "WidgetStaging";
    
                // Save a project file that can be opened by the SQL Compare UI
                productionVsStaging.SaveToDisk(@"c:\A sample project.scp");
    
                // Load the project we just saved back from disk
                Project productionVsStagingLoaded = Project.LoadFromDisk(@"c:\A sample project.scp");
                Database db1 = new Database();
                Database db2 = new Database();
                db1.Register(productionVsStagingLoaded.Source1AsLiveDB.ToConnectionProperties(),productionVsStagingLoaded.ComparisonOptions);
                db2.Register(productionVsStagingLoaded.Source2AsLiveDB.ToConnectionProperties(), productionVsStagingLoaded.ComparisonOptions);
                Differences diffs=db1.CompareWith(db2,productionVsStagingLoaded.ComparisonOptions);
                ArrayList objectsToCompare=productionVsStagingLoaded.SelectedFilters;
                foreach (Difference diff in diffs)
                {
                    if (objectsToCompare.Contains(diff)) diff.Selected = true;
                    else diff.Selected = false;
                }
                Work w = new Work();
                bool runOnTwo=true;
                if (productionVsStagingLoaded.Direction==SynchronizationDirection.From2To1) runOnTwo=false;
                w.BuildFromDifferences(diffs, productionVsStagingLoaded.ComparisonOptions, runOnTwo);
                Console.WriteLine(w.ExecutionBlock.GetString());
                Console.WriteLine(productionVsStagingLoaded.FileName);
    
                Console.WriteLine("Press [Enter]");
                Console.ReadLine();
            }
        }
    }
    
  • Hi,

    You may use the project options to populate the options of a normal comparison in code, for example:
    using System;
    using RedGate.SQLCompare.Engine;
    using RedGate.SQL.Shared;
    using System.Collections;
    
    namespace LoadAndSaveAProject
    {
        /// <summary>
        /// Demonstrates how to create a SQL Compare project file comparing WidgetProduction to
        /// WidgetStaging.
        /// </summary>
        class Program
        {
            static void Main(string[] args)
            {
                // Construct a project comparing WidgetProduction to WidgetStaging
                Project productionVsStaging = new Project();
    
                // By default the two data sources are created as LiveDatabaseSources with
                // the server name set to "(local)". You could also assign SnapshotSource
                // or FolderDataSource objects here.
                productionVsStaging.DataSource1.DatabaseName = "WidgetProduction";
                productionVsStaging.DataSource2.DatabaseName = "WidgetStaging";
    
                // Save a project file that can be opened by the SQL Compare UI
                productionVsStaging.SaveToDisk(@"c:\A sample project.scp");
    
                // Load the project we just saved back from disk
                Project productionVsStagingLoaded = Project.LoadFromDisk(@"c:\A sample project.scp");
                Database db1 = new Database();
                Database db2 = new Database();
                db1.Register(productionVsStagingLoaded.Source1AsLiveDB.ToConnectionProperties(),productionVsStagingLoaded.ComparisonOptions);
                db2.Register(productionVsStagingLoaded.Source2AsLiveDB.ToConnectionProperties(), productionVsStagingLoaded.ComparisonOptions);
                Differences diffs=db1.CompareWith(db2,productionVsStagingLoaded.ComparisonOptions);
                ArrayList objectsToCompare=productionVsStagingLoaded.SelectedFilters;
                foreach (Difference diff in diffs)
                {
                    if (objectsToCompare.Contains(diff)) diff.Selected = true;
                    else diff.Selected = false;
                }
                Work w = new Work();
                bool runOnTwo=true;
                if (productionVsStagingLoaded.Direction==SynchronizationDirection.From2To1) runOnTwo=false;
                w.BuildFromDifferences(diffs, productionVsStagingLoaded.ComparisonOptions, runOnTwo);
                Console.WriteLine(w.ExecutionBlock.GetString());
                Console.WriteLine(productionVsStagingLoaded.FileName);
    
                Console.WriteLine("Press [Enter]");
                Console.ReadLine();
            }
        }
    }
    
    Thats for that, exactly what i needed.
    Was thrown for a sec cause this
     if (objectsToCompare.Contains(diff)) diff.Selected = true;
    
    should have been this?
     if (objectsToCompare.Contains(diff.DatabaseObjectType)) diff.Selected = true;
    
    Thats why ArrayList is EVIL! No error, just doesn't work.
    Really, SelectedFilters should be the type List<DatabaseObjectType> :)
  • Brian DonahueBrian Donahue Posts: 6,590 New member
    Hi,

    Yes, selectedFilters appears to be an array of DatabaseObjectType. Maybe this bit of code is not particularly useful to include...
Sign In or Register to comment.