Esempio n. 1
0
        private void ApplyDeprovision(DbSynchronizerConfiguration configuration, Action <DbSyncScopeDescription> defineScope)
        {
            using (var connection = new SqlConnection(configuration.ConnectionString))
            {
                var provision = new SqlSyncScopeDeprovisioning(connection)
                {
                    ObjectPrefix = configuration.ObjectPrefix ?? string.Empty,
                    ObjectSchema = configuration.ObjectSchema ?? string.Empty,
                };
                //var scopeDescription = new DbSyncScopeDescription(configuration.ScopeName);
                //defineScope(scopeDescription);
                provision.DeprovisionScope(configuration.ScopeName);

                /*
                 * if (!provision.ScopeExists(configuration.ScopeName))
                 * {
                 *  var scopeDescription = new DbSyncScopeDescription(configuration.ScopeName);
                 *  defineScope(scopeDescription);
                 *  provision.SetCreateTableDefault(DbSyncCreationOption.Skip);
                 *  provision.PopulateFromScopeDescription(scopeDescription);
                 *  provision.Apply();
                 * }
                 */
            }
        }
        /// <summary>
        /// Xóa 1 SCOPE khỏi 1 Server nếu có
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="scope_name"></param>
        /// <returns></returns>
        public static int drop_sync_scope(String connectionString, String scope_name)
        {
            SqlConnection serverConn = new SqlConnection(connectionString);
            if (!isExist(serverConn))
            {
                return -1;
            }

            try
            {
                SqlSyncScopeDeprovisioning del = new SqlSyncScopeDeprovisioning(serverConn);
                //Delete Current Scope
                del.DeprovisionScope(scope_name);
                return 1;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return -1;
            }
            finally
            {
                serverConn.Dispose();
            }
        }
Esempio n. 3
0
        internal void Deprovision(SyncDatabase db, SqlConnection connection, DbSyncScopeDescription scopeDesc)
        {
            this.GetDescriptionForTables(db.Tables, connection, ref scopeDesc);

            var provision = new SqlSyncScopeProvisioning(connection, scopeDesc);

            if (provision.ScopeExists(scopeDesc.ScopeName))
            {
                try
                {
                    var deprovision = new SqlSyncScopeDeprovisioning(connection);

                    Log.Info("[DistributedDb] Deprovision Scope [" + scopeDesc.ScopeName + "] Start", this);

                    deprovision.DeprovisionScope(scopeDesc.ScopeName);

                    Log.Info("[DistributedDb] Deprovision Scope [" + scopeDesc.ScopeName + "] End", this);
                }
                catch (Exception ex)
                {
                    Log.Error("[DistributedDb] Deprovision Scope [" + scopeDesc.ScopeName + "] Error", ex, this);
                }
            }
            else
            {
                Log.Info("[DistributedDb] Deprovision Scope [" + scopeDesc.ScopeName + "] Skipped", this);
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            try
            {
                string strclientConn = TechnicalConfig.GetConfiguration()["clientConn"].ToString();
                string strscopename  = TechnicalConfig.GetConfiguration()["ScopeName"].ToString();

                SqlConnection clientConn = new SqlConnection(@strclientConn);
                // define a new scope
                //DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("SyncScopeCHAIComputer");
                // Remove the scope from the database
                //SqlSyncScopeDeprovisioning scopeDeprovisioning = new SqlSyncScopeDeprovisioning(serverConn);
                SqlSyncScopeDeprovisioning scopeDeprovisioning = new SqlSyncScopeDeprovisioning(clientConn);
                // Remove the scope.
                scopeDeprovisioning.DeprovisionScope(strscopename);

                Console.WriteLine("Server Successfully DeProvisioned.");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }
Esempio n. 5
0
        public static void Deprovision(string serverConnectionString, string clientConnectionString)
        {
            // Connection to  SQL Server database
            SqlConnection serverConn = new SqlConnection(serverConnectionString);

            // Connection to SQL client database
            SqlConnection clientConn = new SqlConnection(clientConnectionString);

            // Create Scope Deprovisioning for Sql Server and SQL client.
            SqlSyncScopeDeprovisioning serverSqlDepro = new SqlSyncScopeDeprovisioning(serverConn);
            SqlSyncScopeDeprovisioning clientSqlDepro = new SqlSyncScopeDeprovisioning(clientConn);

            //increase time out
            serverSqlDepro.CommandTimeout = 120;
            clientSqlDepro.CommandTimeout = 120;
            // Remove the scope from SQL Server remove all synchronization objects.
            serverSqlDepro.DeprovisionScope("tableSync");
            serverSqlDepro.DeprovisionStore();

            // Remove the scope from SQL client and remove all synchronization objects.
            clientSqlDepro.DeprovisionScope("tableSync");
            clientSqlDepro.DeprovisionStore();

            // Shut down database connections.
            serverConn.Close();
            serverConn.Dispose();
            clientConn.Close();
            clientConn.Dispose();
        }
 private static void CleanUp(string scopeName,
                             string serverConnectionString,
                             string clientConnectionString)
 {
     try
     {
         using (SqlConnection serverConnection = new
                                                 SqlConnection(serverConnectionString))
         {
             using (SqlConnection clientConnection = new
                                                     SqlConnection(clientConnectionString))
             {
                 SqlSyncScopeDeprovisioning serverDeprovisioning = new
                                                                   SqlSyncScopeDeprovisioning(serverConnection);
                 SqlSyncScopeDeprovisioning clientDeprovisioning = new
                                                                   SqlSyncScopeDeprovisioning(clientConnection);
                 serverDeprovisioning.DeprovisionScope(scopeName);
                 serverDeprovisioning.DeprovisionStore();
                 clientDeprovisioning.DeprovisionScope(scopeName);
                 clientDeprovisioning.DeprovisionStore();
             }
         }
     }
     catch (Exception ex)
     {
         Common.WriteLog(System.DateTime.Now.ToString() + ": " + ex.ToString());
     }
 }
Esempio n. 7
0
        static void Main(string[] args)
        {
            SqlConnection clientConn = new SqlConnection("Data Source=WIN01-DEV02; Initial Catalog=BPMonline; Integrated Security=True");
            SqlConnection serverConn = new SqlConnection("Data Source=WIN01-DEV; Initial Catalog=Test1706; Integrated Security=True");

            SqlSyncScopeDeprovisioning serverScopeDeprovisioning = new SqlSyncScopeDeprovisioning(serverConn);
            SqlSyncScopeDeprovisioning clientScopeDeprovisioning = new SqlSyncScopeDeprovisioning(clientConn);

            using (var db = new SystemContext())
            {
                var sсhemeScopes = db.SсhemeScopes.OrderByDescending(s => s.CreatedOn).ToList();

                foreach (var sсhemeScope in sсhemeScopes)
                {
                    Console.WriteLine("Delete scope: " + sсhemeScope.Name);
                    clientScopeDeprovisioning.DeprovisionScope(sсhemeScope.Name);
                    serverScopeDeprovisioning.DeprovisionScope(sсhemeScope.Name);
                    db.SсhemeScopes.Remove(sсhemeScope);
                }

                var tables = db.MatchingTableNames.Where(m => m.InScope.Value == 1).ToList();
                foreach (var table in tables)
                {
                    table.InScope = 0;
                }

                db.SaveChanges();
            }
        }
Esempio n. 8
0
        public static void Deprovision()
        {
            // Connection to  SQL Server database
            var serverConn =
                new SqlConnection(
                    @"Data Source=KINGDEVLAP36\MSSQLSERVER12;Initial Catalog=northwind;Integrated Security=True");

            // Connection to SQL client database
            var clientConn =
                new SqlConnection(
                    @"Data Source=KINGDEVLAP36\MSSQLSERVER12;Initial Catalog=northwind-client;Integrated Security=True");

            // Create Scope Deprovisioning for Sql Server and SQL client.
            var serverSqlDepro = new SqlSyncScopeDeprovisioning(serverConn);
            var clientSqlDepro = new SqlSyncScopeDeprovisioning(clientConn);

            // Remove the scope from SQL Server remove all synchronization objects.
            serverSqlDepro.DeprovisionScope("customers");
            serverSqlDepro.DeprovisionStore();

            // Remove the scope from SQL client and remove all synchronization objects.
            clientSqlDepro.DeprovisionScope("customers");
            clientSqlDepro.DeprovisionStore();

            // Shut down database connections.
            serverConn.Close();
            serverConn.Dispose();
            clientConn.Close();
            clientConn.Dispose();
        }
Esempio n. 9
0
        /// <summary>
        /// Xóa 1 SCOPE khỏi 1 Server nếu có
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="scope_name"></param>
        /// <returns></returns>
        public static int drop_sync_scope(String connectionString, String scope_name)
        {
            SqlConnection serverConn = new SqlConnection(connectionString);

            if (!isExist(serverConn))
            {
                return(-1);
            }

            try
            {
                SqlSyncScopeDeprovisioning del = new SqlSyncScopeDeprovisioning(serverConn);
                //Delete Current Scope
                del.DeprovisionScope(scope_name);
                return(1);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return(-1);
            }
            finally
            {
                serverConn.Dispose();
            }
        }
        public void ProvisionServer(SqlConnection serverConnection = null)
        {
            var serverConn = serverConnection ?? SqlConnectionFactory.DefaultServerConnection;

            var deprovisionScope = new SqlSyncScopeDeprovisioning(serverConn);
            deprovisionScope.DeprovisionScope("FullScope");

            // define a new scope
            var scopeDesc = new DbSyncScopeDescription("FullScope");

            // add the table description to the sync scope definition
            foreach (var table in DbInfo.Tables) //TODO: view (oder JOINs) synchronisieren?
                scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable(table.Name, serverConn));

            //TODO: Server-Event feuern sobald ein Client synchronisiert

            // create a server scope provisioning object based on the ProductScope
            var serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc);

            // skipping the creation of table since table already exists on server
            serverProvision.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);

            // start the provisioning process
            if (!serverProvision.ScopeExists(scopeDesc.ScopeName))
                serverProvision.Apply();
        }
Esempio n. 11
0
        private static void DeprovisionSqlServer(SqlConnection con, string scopeName)
        {
            var scopeDeprovisioning = new SqlSyncScopeDeprovisioning(con);

            scopeDeprovisioning.ObjectSchema = prefix;
            scopeDeprovisioning.DeprovisionScope(scopeName);
        }
Esempio n. 12
0
        public override void DeProvisionDb()
        {
            SqlSyncScopeProvisioning clientProvision = CreateScopeProvision();

            if (clientProvision.ScopeExists(SyncScopeName))
            {
                SqlSyncScopeDeprovisioning clientDeprovision = CreateScopeDeProvision();
                clientDeprovision.DeprovisionScope(SyncScopeName);
            }
        }
Esempio n. 13
0
        public override void DeProvisionDb()
        {
            SqlSyncScopeProvisioning   serverProvision   = CreateScopeProvision();
            SqlSyncScopeDeprovisioning serverDeprovision = null;

            if (serverProvision.ScopeExists(SyncScopeName))
            {
                serverDeprovision = CreateScopeDeProvision();
                serverDeprovision.DeprovisionScope(SyncScopeName);
            }
            serverProvision = CreateScopeProvisionByType(SqlSyncScopeProvisioningType.Template);
            if (serverProvision.ScopeExists(SyncScopeName + "_Template"))
            {
                if (serverDeprovision == null)
                {
                    serverDeprovision = CreateScopeDeProvision();
                }
                serverDeprovision.DeprovisionScope(SyncScopeName);
            }
        }
Esempio n. 14
0
 private static void CleanUp(string scopeName, string serverConnectionString, string clientConnectionString)
 {
     using (SqlConnection serverConnection = new SqlConnection(serverConnectionString))
     {
         using (SqlConnection clientConnection = new SqlConnection(clientConnectionString))
         {
             SqlSyncScopeDeprovisioning serverDeprovisioning = new SqlSyncScopeDeprovisioning(serverConnection);
             SqlSyncScopeDeprovisioning clientDeprovisioning = new SqlSyncScopeDeprovisioning(clientConnection);
             serverDeprovisioning.DeprovisionScope(scopeName);
             serverDeprovisioning.DeprovisionStore();
             clientDeprovisioning.DeprovisionScope(scopeName);
             clientDeprovisioning.DeprovisionStore();
         }
     }
 }
Esempio n. 15
0
 private void DeprovisionMasterButton_Click(object sender, EventArgs e)
 {
     using (SqlConnection master = new SqlConnection(Settings.Default.MasterConnectionString))
     {
         try
         {
             SqlSyncScopeDeprovisioning prov = new SqlSyncScopeDeprovisioning(master);
             prov.DeprovisionScope(this.scopeNameTextBox.Text);
             MessageBox.Show(@"Database successfully deprovisioned.", @"Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (Exception exception)
         {
             MessageBox.Show(exception.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Esempio n. 16
0
        static void Main(string[] args)
        {
            // Defines the sync scope name
            const string scopeName = "UserScope";

            // Creates a connexion to the server database.
            string SqlConnString = @"Data Source='.\SQLEXPRESS';Initial Catalog=gtd;Integrated Security=True";
            SqlConnection serverConn = new SqlConnection(SqlConnString);

            // Remove the previous scope from the Sql Server database (no support for updating a scope).
            SqlSyncScopeDeprovisioning sqlDepro = new SqlSyncScopeDeprovisioning(serverConn);
            sqlDepro.DeprovisionScope(scopeName);

            // Defines a new synchronization scope named UserScope
            DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(scopeName);

            // Gets the description of the Users table from the gtd database
            DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Users", serverConn);

            // Adds the table description to the sync scope definition
            scopeDesc.Tables.Add(tableDesc);

            // Gets the description of the other tables from the gtd base and add them to the sync scope.
            DbSyncTableDescriptionCollection otherTables = new DbSyncTableDescriptionCollection();
            otherTables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Tasks", serverConn));
            otherTables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Lists", serverConn));
            otherTables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Projects", serverConn));
            //otherTables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Tasks_Lists", serverConn));
            otherTables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Tasks_Tasks", serverConn));
            otherTables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Lists_Tasks", serverConn));
            otherTables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Projects_Tasks", serverConn));
            otherTables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Projects_Lists", serverConn));
            otherTables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Projects_Lists_Tasks", serverConn));
            foreach (var table in otherTables)
            {
                scopeDesc.Tables.Add(table);
            }

            // Creates a server scope provisioning object based on the ProductScope
            SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc);

            // Skipping the creation of table since table already exists on server
            serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);

            // Starts the provisioning process
            serverProvision.Apply();
        }
Esempio n. 17
0
        private void DesaprovicionarAmbito(SqlConnection conexionSql, DbSyncScopeDescription Ambito, SqlSyncScopeProvisioning proveedorDeAmbito)
        {
            SqlSyncScopeDeprovisioning DesaprovicionadorDeAmbito = new SqlSyncScopeDeprovisioning(conexionSql);

            DesaprovicionadorDeAmbito.ObjectSchema = this.esquemaMetadataSyncFramework;
            DesaprovicionadorDeAmbito.ObjectPrefix = this.prefijoMetadataSyncFramework;
            this.loguear("Se va a eliminar el ambito " + Ambito.ScopeName + " Inicio:\t" + DateTime.Now);
            lock (this.obj)
            {
                if (proveedorDeAmbito.ScopeExists(Ambito.ScopeName))
                {
                    DesaprovicionadorDeAmbito.DeprovisionScope(Ambito.ScopeName);
                }
            }

            this.loguear("Se elimino el ambito " + Ambito.ScopeName + " fin:\t" + DateTime.Now);
        }
Esempio n. 18
0
        private static void Deprovision(SelectedConfigSections selectedConfig, bool script, DirectoryInfo workingDirectory)
        {
            try
            {
                SqlSyncScopeDeprovisioning deprov =
                    new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()));

                // Set the ObjectSchema property.
                if (!String.IsNullOrEmpty(selectedConfig.SelectedSyncScope.SchemaName))
                {
                    deprov.ObjectSchema = selectedConfig.SelectedSyncScope.SchemaName;
                }

                Log("Deprovisioning Database {0} for scope {1}...", selectedConfig.SelectedTargetDatabase.Name,
                    selectedConfig.SelectedSyncScope.Name);

                if (selectedConfig.SelectedSyncScope.IsTemplateScope)
                {
                    if (!script)
                    {
                        deprov.DeprovisionTemplate(selectedConfig.SelectedSyncScope.Name);
                    }
                    else
                    {
                        SaveScript("deprovision.sql", deprov.ScriptDeprovisionTemplate(selectedConfig.SelectedSyncScope.Name), workingDirectory);
                    }
                }
                else
                {
                    if (!script)
                    {
                        deprov.DeprovisionScope(selectedConfig.SelectedSyncScope.Name);
                    }
                    else
                    {
                        SaveScript("deprovision.sql", deprov.ScriptDeprovisionScope(selectedConfig.SelectedSyncScope.Name), workingDirectory);
                    }
                }
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(
                          "Unexpected error when executing the Deprovisioning command. See inner exception for details.", e);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// removes tracking data and tables created by Microsoft Synchronization
        /// </summary>
        public static void ClearTrackingData()
        {
            // create deprovisions
            var serverDeprovisioning = new SqlSyncScopeDeprovisioning(serverConn);
            var clientDeprovisioning = new SqlSyncScopeDeprovisioning(clientConn);

            // tell the deprovision what prefix is being used
            serverDeprovisioning.ObjectPrefix = trackingPrefix;
            clientDeprovisioning.ObjectPrefix = trackingPrefix;

            for (int i = 0; i < main.context.LocalTables.Count; i++)
            {
                // string[] registerInfo = registeredTables[i];
                // try to remove previous data
                string scope = main.context.LocalTables[i].name;
                serverDeprovisioning.DeprovisionScope(scope);
            }

            // deprovision client and server
            serverDeprovisioning.DeprovisionStore();
            clientDeprovisioning.DeprovisionStore();

            using (var connection = new SqlConnection(clientConnectionString))
            {
                // loop backwards to avoid FK conflicts
                for (int i = main.context.LocalTables.Count - 1; i >= 0; i--)
                {
                    try
                    {
                        // string[] registerInfo = registeredTables[i];
                        //// ensure that the GUID column is NOT NULL as this is used to sync records
                        string droptable = "DROP TABLE " + main.context.LocalTables[i].name + ";";
                        var    drop      = new SqlCommand(droptable, connection);
                        drop.Connection.Open();
                        drop.ExecuteNonQuery();
                        drop.Connection.Close();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }
        }
Esempio n. 20
0
 /// <summary>
 /// Deprovsions the scope from the database. 
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="scope"></param>
 /// <returns></returns>
 public static bool DeprovisonScope(SqlConnection conn, string scope)
 {
     if (conn.State == System.Data.ConnectionState.Closed)
         conn.Open();
     SqlSyncScopeDeprovisioning prov = new SqlSyncScopeDeprovisioning(conn);
     try
     {
         prov.DeprovisionScope(scope);
         DropTableGeomTrigger(conn, scope);
     }
     catch (DbSyncException ex)
     {
         ConsoleColor color = Console.ForegroundColor;
         Console.ForegroundColor = ConsoleColor.Red;
         Console.Error.WriteLine(ex.Message);
         Console.ForegroundColor = color;
         return false;
     }
     return true;
 }
Esempio n. 21
0
        public void PerformDeprovisionTable(Object obj)
        {
            ThreadState state = (ThreadState)obj;

            try
            {
                SqlSyncScopeDeprovisioning storeClientDeprovision = new SqlSyncScopeDeprovisioning(_connection);
                storeClientDeprovision.DeprovisionScope(this._tableName + this._filter);
                state._event.Set();
                state.table.Status = TableStatus.Deprovisioned;
                Log.WriteLogs(_tableName + " was deprovisioned.");
            }
            catch (Exception ex)
            {
                state._event.Set();
                Log.WriteErrorLogs(_tableName, ex);
                state.table.Status = TableStatus.ErrorDeprovision;
                Log.WriteLogs(_tableName + " has deprovision error.");
            }
            state.worker.ReportProgress(1, _tableName + " was deprovisioned.");
        }
        private void DesaprovicionarAmbito(IDbConnection conexionSql, DbSyncScopeDescription Ambito, SqlSyncScopeProvisioning proveedorDeAmbito)
        {
            SqlSyncScopeDeprovisioning DesaprovicionadorDeAmbito = new SqlSyncScopeDeprovisioning((SqlConnection)conexionSql);

            DesaprovicionadorDeAmbito.ObjectSchema = _esquemaMetadataSyncFramework;
            DesaprovicionadorDeAmbito.ObjectPrefix = _prefijoMetadataSyncFramework;

            lock (_lockAprovisionamiento)
            {
                if (proveedorDeAmbito.ScopeExists(Ambito.ScopeName))
                {
                    Loguear("Se va a eliminar el ambito " + Ambito.ScopeName);
                    DesaprovicionadorDeAmbito.DeprovisionScope(Ambito.ScopeName);
                    Loguear("Se elimino el ambito " + Ambito.ScopeName);
                }
                else
                {
                    Loguear("No se elimina el ambito " + Ambito.ScopeName + " [no existe]");
                }
            }
        }
Esempio n. 23
0
    /// <summary>
    /// Deprovsions the scope from the database.
    /// </summary>
    /// <param name="conn"></param>
    /// <param name="scope"></param>
    /// <returns></returns>
    public static bool DeprovisonScope(SqlConnection conn, string scope)
    {
        if (conn.State == System.Data.ConnectionState.Closed)
        {
            conn.Open();
        }
        SqlSyncScopeDeprovisioning prov = new SqlSyncScopeDeprovisioning(conn);

        try
        {
            prov.DeprovisionScope(scope);
            DropTableGeomTrigger(conn, scope);
        }
        catch (DbSyncException ex)
        {
            ConsoleColor color = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Error.WriteLine(ex.Message);
            Console.ForegroundColor = color;
            return(false);
        }
        return(true);
    }
Esempio n. 24
0
        public void Deprovision2()
        {
            try
            {
                SqlConnection serverConn = new SqlConnection(sServerConnection);

                // Connection to SQL client
                SqlConnection clientConn = new SqlConnection(sClientConnection);

                // Create Scope Deprovisioning for Sql Server and SQL client.
                SqlSyncScopeDeprovisioning serverSqlDepro = new SqlSyncScopeDeprovisioning(serverConn);
                SqlSyncScopeDeprovisioning clientSqlDepro = new SqlSyncScopeDeprovisioning(clientConn);

                // Remove the scope from SQL Server remove all synchronization objects.
                serverSqlDepro.DeprovisionScope(sScope);
                serverSqlDepro.DeprovisionStore();

                // Remove the scope from SQL client and remove all synchronization objects.
                clientSqlDepro.DeprovisionScope(sScope);
                clientSqlDepro.DeprovisionStore();

                // Shut down database connections.
                serverConn.Close();
                serverConn.Dispose();
                clientConn.Close();
                clientConn.Dispose();
            }
            catch (SqlException ex)
            {
            }
            catch (Microsoft.Synchronization.Data.DbVersionException ex)
            {
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 25
0
        private void DeprovisionMasterButton_Click(object sender, EventArgs e)
        {
            using (SqlConnection master = new SqlConnection(Settings.Default.MasterConnectionString))
            {
                try
                {
                    SqlSyncScopeDeprovisioning prov = new SqlSyncScopeDeprovisioning(master);
                    prov.DeprovisionScope(this.scopeNameTextBox.Text);
                    using (SqlCommand command = master.CreateCommand())
                    {
                        master.Open();
                        command.CommandText = string.Format("IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[{0}_GEOMSRID_trigger]')) DROP TRIGGER [dbo].[{0}_GEOMSRID_trigger]", TableName);
                        command.ExecuteNonQuery();
                        master.Close();
                    }

                    MessageBox.Show("Database successfully deprovisioned.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 26
0
        private void DeprovisionClientButton_Click(object sender, EventArgs e)
        {
            using (SqlConnection slave = new SqlConnection(Settings.Default.SlaveConnectionString))
            {
                try
                {
                    SqlSyncScopeDeprovisioning prov = new SqlSyncScopeDeprovisioning(slave);
                    prov.DeprovisionScope(this.scopeNameTextBox.Text);
                    using (SqlCommand command = slave.CreateCommand())
                    {
                        slave.Open();
                        command.CommandText = string.Format("IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[{0}_GEOMSRID_trigger]')) DROP TRIGGER [dbo].[{0}_GEOMSRID_trigger]", TableName);
                        command.ExecuteNonQuery();
                        slave.Close();
                    }

                    MessageBox.Show("Database successfully deprovisioned.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void DesaprovicionarAmbito(SqlConnection conexionSql, DbSyncScopeDescription Ambito, SqlSyncScopeProvisioning proveedorDeAmbito)
        {
            SqlSyncScopeDeprovisioning DesaprovicionadorDeAmbito = new SqlSyncScopeDeprovisioning(conexionSql);
            DesaprovicionadorDeAmbito.ObjectSchema = this.esquemaMetadataSyncFramework;
            DesaprovicionadorDeAmbito.ObjectPrefix = this.prefijoMetadataSyncFramework;
            this.loguear("Se va a eliminar el ambito " + Ambito.ScopeName + " Inicio:\t" + DateTime.Now);
            lock(this.obj)
            {
                if (proveedorDeAmbito.ScopeExists(Ambito.ScopeName))
                    DesaprovicionadorDeAmbito.DeprovisionScope(Ambito.ScopeName);
            }

            this.loguear("Se elimino el ambito " + Ambito.ScopeName + " fin:\t" + DateTime.Now);
        }
Esempio n. 28
0
        private static void ProcessConfigFile(ArgsParser parser)
        {
            DbSyncScopeDescription scopeDescription;
            Dictionary<string, Dictionary<string, string>> tablesToColumnMappingsInfo = new Dictionary<string, Dictionary<string, string>>();

            if (string.IsNullOrEmpty(parser.ConfigFile))
            {
                LogArgsError("Required argument /scopeconfig is not specified.");
                return;
            }
            if (!System.IO.File.Exists(parser.ConfigFile))
            {
                LogArgsError("Unable to find scopeconfig file '" + parser.ConfigFile + "'");
                return;
            }

            System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() { ExeConfigFilename = parser.ConfigFile }, ConfigurationUserLevel.None);

            Log("Reading specified config file...");
            SyncConfigurationSection syncConfig = config.GetSection(Constants.SyncConfigurationSectionName) as SyncConfigurationSection;

            // ValidateConfigFile the config and the passed in input parameters
            ValidateConfigFile(parser, syncConfig);

            // Fill in the defaults value for the parser.
            SelectedConfigSections selectedConfig = FillDefaults(parser, syncConfig);


            Log("Generating DbSyncScopeDescription for scope {0}...", selectedConfig.SelectedSyncScope.Name);
            scopeDescription = GetDbSyncScopeDescription(selectedConfig);
            tablesToColumnMappingsInfo = BuildColumnMappingInfo(selectedConfig);
            switch (parser.OperationMode)
            {

                case OperationMode.Provision:
                    try
                    {


                        SqlSyncScopeProvisioning prov = new SqlSyncScopeProvisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()),
                                            scopeDescription, selectedConfig.SelectedSyncScope.IsTemplateScope ? SqlSyncScopeProvisioningType.Template : SqlSyncScopeProvisioningType.Scope);

                        // Note: Deprovisioning does not work because of a bug in the provider when you set the ObjectSchema property to “dbo”. 
                        // The workaround is to not set the property (it internally assumes dbo in this case) so that things work on deprovisioning.
                        if (!String.IsNullOrEmpty(selectedConfig.SelectedSyncScope.SchemaName))
                        {
                            prov.ObjectSchema = selectedConfig.SelectedSyncScope.SchemaName;
                        }

                        foreach (SyncTableConfigElement tableElement in selectedConfig.SelectedSyncScope.SyncTables)
                        {
                            // Check and set the SchemaName for individual table if specified
                            if (!string.IsNullOrEmpty(tableElement.SchemaName))
                            {
                                prov.Tables[tableElement.GlobalName].ObjectSchema = tableElement.SchemaName;
                            }

                            prov.Tables[tableElement.GlobalName].FilterClause = tableElement.FilterClause;
                            foreach (FilterColumnConfigElement filterCol in tableElement.FilterColumns)
                            {
                                prov.Tables[tableElement.GlobalName].FilterColumns.Add(scopeDescription.Tables[tableElement.GlobalName].Columns[filterCol.Name]);
                            }
                            foreach (FilterParameterConfigElement filterParam in tableElement.FilterParameters)
                            {
                                CheckFilterParamTypeAndSize(filterParam);
                                prov.Tables[tableElement.GlobalName].FilterParameters.Add(new SqlParameter(filterParam.Name, (SqlDbType)Enum.Parse(typeof(SqlDbType), filterParam.SqlType, true)));
                                prov.Tables[tableElement.GlobalName].FilterParameters[filterParam.Name].Size = filterParam.DataSize;
                            }
                        }

                        // enable bulk procedures.
                        prov.SetUseBulkProceduresDefault(selectedConfig.SelectedSyncScope.EnableBulkApplyProcedures);

                        // Create a new set of enumeration stored procs per scope. 
                        // Without this multiple scopes share the same stored procedure which is not desirable.
                        prov.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.Create);

                        if (selectedConfig.SelectedSyncScope.IsTemplateScope)
                        {
                            if (!prov.TemplateExists(selectedConfig.SelectedSyncScope.Name))
                            {
                                Log("Provisioning Database {0} for template scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name);
                                prov.Apply();
                            }
                            else
                            {
                                throw new InvalidOperationException(string.Format("Database {0} already contains a template scope {1}. Please deprovision the scope and retry.", selectedConfig.SelectedTargetDatabase.Name,
                                    selectedConfig.SelectedSyncScope.Name));
                            }
                        }
                        else
                        {
                            if (!prov.ScopeExists(selectedConfig.SelectedSyncScope.Name))
                            {
                                Log("Provisioning Database {0} for scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name);
                                prov.Apply();
                            }
                            else
                            {
                                throw new InvalidOperationException(string.Format("Database {0} already contains a scope {1}. Please deprovision the scope and retry.", selectedConfig.SelectedTargetDatabase.Name,
                                    selectedConfig.SelectedSyncScope.Name));
                            }
                        }
                    }
                    catch (ConfigurationErrorsException)
                    {
                        throw;
                    }
                    catch (InvalidOperationException)
                    {
                        throw;
                    }
                    catch (Exception e)
                    {
                        throw new InvalidOperationException("Unexpected error when executing the Provisioning command. See inner exception for details.", e);
                    }
                    break;
                case OperationMode.Deprovision:
                    try
                    {
                        SqlSyncScopeDeprovisioning deprov = new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()));

                        // Set the ObjectSchema property.
                        if (!String.IsNullOrEmpty(selectedConfig.SelectedSyncScope.SchemaName))
                        {
                            deprov.ObjectSchema = selectedConfig.SelectedSyncScope.SchemaName;
                        }

                        Log("Deprovisioning Database {0} for scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name);

                        if (selectedConfig.SelectedSyncScope.IsTemplateScope)
                        {
                            deprov.DeprovisionTemplate(selectedConfig.SelectedSyncScope.Name);
                        }
                        else
                        {
                            deprov.DeprovisionScope(selectedConfig.SelectedSyncScope.Name);

                        }
                    }
                    catch (Exception e)
                    {
                        throw new InvalidOperationException("Unexpected error when executing the Deprovisioning command. See inner exception for details.", e);
                    }

                    break;
                case OperationMode.Deprovisionstore:
                    try
                    {
                        SqlSyncScopeDeprovisioning deprov = new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()));

                        Log("Deprovisioning Store Database {0} ...", selectedConfig.SelectedTargetDatabase.Name);

                        deprov.DeprovisionStore();
                    }
                    catch (Exception e)
                    {
                        throw new InvalidOperationException("Unexpected error when executing the Deprovisioning command. See inner exception for details.", e);
                    }

                    break;
                case OperationMode.Codegen:
                    Log("Generating files...");
                    EntityGenerator generator = EntityGeneratorFactory.Create(parser.CodeGenMode, selectedConfig.SelectedSyncScope.SchemaName);
                    generator.GenerateEntities(parser.GeneratedFilePrefix,
                        string.IsNullOrEmpty(parser.Namespace)
                        ? string.IsNullOrEmpty(parser.GeneratedFilePrefix) ? scopeDescription.ScopeName : parser.GeneratedFilePrefix
                        : parser.Namespace,
                        scopeDescription, tablesToColumnMappingsInfo, parser.WorkingDirectory, parser.Language, null/*serviceUri*/);
                    break;
                default:
                    break;
            }
        }
        private void refreshScope(SqlSyncScopeProvisioning Provision, DbSyncScopeDescription currentDesc, SqlConnection CON)
        {
            // start the provisioning process
            if (Provision.ScopeExists(currentDesc.ScopeName))
            {
                DbSyncScopeDescription dbDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(currentDesc.ScopeName, CON);

                MessageBox.Show(currentDesc.Tables[0].Columns[1].QuotedName + ": " + currentDesc.Tables[0].Columns[1].Type + " <" + currentDesc.Tables[0].Columns[1].Size + ">\n" +
                    dbDesc.Tables[0].Columns[1].QuotedName + ": " + dbDesc.Tables[0].Columns[1].Type + " <" + dbDesc.Tables[0].Columns[1].Size + ">"
                    );

                if (!compareDescriptions(currentDesc, dbDesc) || true)
                {
                    if (MessageBox.Show("The Scope '" + currentDesc.ScopeName + "' is out of sync with the Database!\nShould the Scope be rewritten?\nWarning:\nAll Scope-Data (Trigger etc.) will be lost!",
                        "Warning,   Scope is invalid!", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.Yes)
                    {
                        SqlSyncScopeDeprovisioning DeProvision = new SqlSyncScopeDeprovisioning(CON);
                        DeProvision.DeprovisionScope(currentDesc.ScopeName);

                    }
                }
            }
        }
Esempio n. 30
0
        private static void ProcessConfigFile(ArgsParser parser)
        {
            DbSyncScopeDescription scopeDescription;
            Dictionary <string, Dictionary <string, string> > tablesToColumnMappingsInfo = new Dictionary <string, Dictionary <string, string> >();

            if (string.IsNullOrEmpty(parser.ConfigFile))
            {
                LogArgsError("Required argument /scopeconfig is not specified.");
                return;
            }
            if (!System.IO.File.Exists(parser.ConfigFile))
            {
                LogArgsError("Unable to find scopeconfig file '" + parser.ConfigFile + "'");
                return;
            }

            System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap()
            {
                ExeConfigFilename = parser.ConfigFile
            }, ConfigurationUserLevel.None);

            Log("Reading specified config file...");
            SyncConfigurationSection syncConfig = config.GetSection(Constants.SyncConfigurationSectionName) as SyncConfigurationSection;

            // ValidateConfigFile the config and the passed in input parameters
            ValidateConfigFile(parser, syncConfig);

            // Fill in the defaults value for the parser.
            SelectedConfigSections selectedConfig = FillDefaults(parser, syncConfig);


            Log("Generating DbSyncScopeDescription for scope {0}...", selectedConfig.SelectedSyncScope.Name);
            scopeDescription           = GetDbSyncScopeDescription(selectedConfig);
            tablesToColumnMappingsInfo = BuildColumnMappingInfo(selectedConfig);
            switch (parser.OperationMode)
            {
            case OperationMode.Provision:
                try
                {
                    SqlSyncScopeProvisioning prov = new SqlSyncScopeProvisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()),
                                                                                 scopeDescription, selectedConfig.SelectedSyncScope.IsTemplateScope ? SqlSyncScopeProvisioningType.Template : SqlSyncScopeProvisioningType.Scope);

                    // Note: Deprovisioning does not work because of a bug in the provider when you set the ObjectSchema property to “dbo”.
                    // The workaround is to not set the property (it internally assumes dbo in this case) so that things work on deprovisioning.
                    if (!String.IsNullOrEmpty(selectedConfig.SelectedSyncScope.SchemaName))
                    {
                        prov.ObjectSchema = selectedConfig.SelectedSyncScope.SchemaName;
                    }

                    foreach (SyncTableConfigElement tableElement in selectedConfig.SelectedSyncScope.SyncTables)
                    {
                        // Check and set the SchemaName for individual table if specified
                        if (!string.IsNullOrEmpty(tableElement.SchemaName))
                        {
                            prov.Tables[tableElement.GlobalName].ObjectSchema = tableElement.SchemaName;
                        }

                        prov.Tables[tableElement.GlobalName].FilterClause = tableElement.FilterClause;
                        foreach (FilterColumnConfigElement filterCol in tableElement.FilterColumns)
                        {
                            prov.Tables[tableElement.GlobalName].FilterColumns.Add(scopeDescription.Tables[tableElement.GlobalName].Columns[filterCol.Name]);
                        }
                        foreach (FilterParameterConfigElement filterParam in tableElement.FilterParameters)
                        {
                            CheckFilterParamTypeAndSize(filterParam);
                            prov.Tables[tableElement.GlobalName].FilterParameters.Add(new SqlParameter(filterParam.Name, (SqlDbType)Enum.Parse(typeof(SqlDbType), filterParam.SqlType, true)));
                            prov.Tables[tableElement.GlobalName].FilterParameters[filterParam.Name].Size = filterParam.DataSize;
                        }
                    }

                    // enable bulk procedures.
                    prov.SetUseBulkProceduresDefault(selectedConfig.SelectedSyncScope.EnableBulkApplyProcedures);

                    // Create a new set of enumeration stored procs per scope.
                    // Without this multiple scopes share the same stored procedure which is not desirable.
                    prov.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.Create);

                    if (selectedConfig.SelectedSyncScope.IsTemplateScope)
                    {
                        if (!prov.TemplateExists(selectedConfig.SelectedSyncScope.Name))
                        {
                            Log("Provisioning Database {0} for template scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name);
                            prov.Apply();
                        }
                        else
                        {
                            throw new InvalidOperationException(string.Format("Database {0} already contains a template scope {1}. Please deprovision the scope and retry.", selectedConfig.SelectedTargetDatabase.Name,
                                                                              selectedConfig.SelectedSyncScope.Name));
                        }
                    }
                    else
                    {
                        if (!prov.ScopeExists(selectedConfig.SelectedSyncScope.Name))
                        {
                            Log("Provisioning Database {0} for scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name);
                            prov.Apply();
                        }
                        else
                        {
                            throw new InvalidOperationException(string.Format("Database {0} already contains a scope {1}. Please deprovision the scope and retry.", selectedConfig.SelectedTargetDatabase.Name,
                                                                              selectedConfig.SelectedSyncScope.Name));
                        }
                    }
                }
                catch (ConfigurationErrorsException)
                {
                    throw;
                }
                catch (InvalidOperationException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("Unexpected error when executing the Provisioning command. See inner exception for details.", e);
                }
                break;

            case OperationMode.Deprovision:
                try
                {
                    SqlSyncScopeDeprovisioning deprov = new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()));

                    // Set the ObjectSchema property.
                    if (!String.IsNullOrEmpty(selectedConfig.SelectedSyncScope.SchemaName))
                    {
                        deprov.ObjectSchema = selectedConfig.SelectedSyncScope.SchemaName;
                    }

                    Log("Deprovisioning Database {0} for scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name);

                    if (selectedConfig.SelectedSyncScope.IsTemplateScope)
                    {
                        deprov.DeprovisionTemplate(selectedConfig.SelectedSyncScope.Name);
                    }
                    else
                    {
                        deprov.DeprovisionScope(selectedConfig.SelectedSyncScope.Name);
                    }
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("Unexpected error when executing the Deprovisioning command. See inner exception for details.", e);
                }

                break;

            case OperationMode.Deprovisionstore:
                try
                {
                    SqlSyncScopeDeprovisioning deprov = new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()));

                    Log("Deprovisioning Store Database {0} ...", selectedConfig.SelectedTargetDatabase.Name);

                    deprov.DeprovisionStore();
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("Unexpected error when executing the Deprovisioning command. See inner exception for details.", e);
                }

                break;

            case OperationMode.Codegen:
                Log("Generating files...");
                EntityGenerator generator = EntityGeneratorFactory.Create(parser.CodeGenMode, selectedConfig.SelectedSyncScope.SchemaName);
                generator.GenerateEntities(parser.GeneratedFilePrefix,
                                           string.IsNullOrEmpty(parser.Namespace)
                        ? string.IsNullOrEmpty(parser.GeneratedFilePrefix) ? scopeDescription.ScopeName : parser.GeneratedFilePrefix
                        : parser.Namespace,
                                           scopeDescription, tablesToColumnMappingsInfo, parser.WorkingDirectory, parser.Language, null /*serviceUri*/);
                break;

            default:
                break;
            }
        }