Beispiel #1
0
        private static void DeprovisionSqlServer(SqlConnection con, string scopeName)
        {
            var scopeDeprovisioning = new SqlSyncScopeDeprovisioning(con);

            scopeDeprovisioning.ObjectSchema = prefix;
            scopeDeprovisioning.DeprovisionScope(scopeName);
        }
Beispiel #2
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();
            }
        }
Beispiel #4
0
        /// <summary>
        /// removes tracking data and tables created by Microsoft Synchronization
        /// </summary>
        public static void ClearClientTrackingData()
        {
            // create deprovisions
            var clientDeprovisioning = new SqlSyncScopeDeprovisioning(clientConn);

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

            // deprovision client and server
            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];
                        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);
                    }
                }
            }
        }
Beispiel #5
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();
            }
        }
 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());
     }
 }
Beispiel #7
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);
            }
        }
Beispiel #8
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();
        }
Beispiel #9
0
        /// <summary>
        /// removes tracking data and tables created by Microsoft Synchronization
        /// </summary>
        public static void ClearSingleTableData(string tableName)
        {
            // create deprovisions
            var clientDeprovisioning = new SqlSyncScopeDeprovisioning(clientConn);

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

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

            using (var connection = new SqlConnection(clientConnectionString))
            {
                try
                {
                    // string[] registerInfo = registeredTables[i];
                    string droptable = $"DROP TABLE {tableName};";
                    var    drop      = new SqlCommand(droptable, connection);
                    drop.Connection.Open();
                    drop.ExecuteNonQuery();
                    drop.Connection.Close();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
Beispiel #10
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();
            }
        }
Beispiel #11
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();
        }
Beispiel #12
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();
        }
Beispiel #14
0
        public static void DeprovisionDatabase(string pProviderConnectionString)
        {
            SqlConnection conn = new SqlConnection(pProviderConnectionString);
            SqlSyncScopeDeprovisioning deprovisionProvider = new SqlSyncScopeDeprovisioning(conn);

            deprovisionProvider.DeprovisionStore();
        }
Beispiel #15
0
        public override void DeProvisionDb()
        {
            SqlSyncScopeProvisioning clientProvision = CreateScopeProvision();

            if (clientProvision.ScopeExists(SyncScopeName))
            {
                SqlSyncScopeDeprovisioning clientDeprovision = CreateScopeDeProvision();
                clientDeprovision.DeprovisionScope(SyncScopeName);
            }
        }
Beispiel #16
0
        public void PerformDeprovisionTemplate(object obj)
        {
            try
            {
                SqlSyncScopeDeprovisioning templateDeprovision = new SqlSyncScopeDeprovisioning(_connection);
                templateDeprovision.DeprovisionTemplate(_tableName + "Filter");

                Log.WriteLogs("Template was Deprovisioned.");
            }
            catch (Exception ex)
            {
                Log.WriteErrorLogs(ex);
            }
        }
Beispiel #17
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();
         }
     }
 }
Beispiel #18
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);
         }
     }
 }
Beispiel #19
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();
        }
Beispiel #20
0
        internal void DeprovisionStore(SqlConnection connection)
        {
            try
            {
                var deprovision = new SqlSyncScopeDeprovisioning(connection);

                Log.Info("[DistributedDb] Deprovision Store Start", this);

                deprovision.DeprovisionStore();

                Log.Info("[DistributedDb] Deprovision Store End", this);
            }
            catch (Exception ex)
            {
                Log.Error("[DistributedDb] Deprovision Store Error", ex, this);
            }
        }
Beispiel #21
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);
        }
Beispiel #22
0
        public void PerformDeprovisionDatabase(object obj)
        {
            ManualResetEvent _event = (ManualResetEvent)obj;

            try
            {
                SqlSyncScopeDeprovisioning storeClientDeprovision = new SqlSyncScopeDeprovisioning(_connection);
                storeClientDeprovision.DeprovisionStore();

                Log.WriteLogs("Database was Deprovisioned.");
            }
            catch (Exception ex)
            {
                Log.WriteErrorLogs(ex);
            }
            _event.Set();
        }
Beispiel #23
0
        private void DesaprovicionarServidor(SqlConnection conexionSql)
        {
            SqlSyncScopeDeprovisioning DesaprovicionadorDeAmbito = new SqlSyncScopeDeprovisioning(conexionSql);

            DesaprovicionadorDeAmbito.ObjectSchema = this.esquemaMetadataSyncFramework;
            DesaprovicionadorDeAmbito.ObjectPrefix = this.prefijoMetadataSyncFramework;
            try
            {
                this.loguear("Se va a desaprovicionar el servidor entero " + conexionSql.Database + " Inicio:\t" + DateTime.Now);
                DesaprovicionadorDeAmbito.DeprovisionStore();
                this.loguear("Se desaprovicio el servidor entero " + conexionSql.Database + " fin:\t" + DateTime.Now);
            }
            catch (Exception e)
            {
                this.loguear(e.Message);
            }
        }
Beispiel #24
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);
            }
        }
Beispiel #25
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);
                    }
                }
            }
        }
        private void DesaprovicionarServidor(IDbConnection sqlConnection)
        {
            SqlSyncScopeDeprovisioning DesaprovicionadorDeAmbito = new SqlSyncScopeDeprovisioning((SqlConnection)sqlConnection)
            {
                ObjectSchema = _esquemaMetadataSyncFramework,
                ObjectPrefix = _prefijoMetadataSyncFramework
            };

            try
            {
                Loguear("Se va a desaprovicionar el servidor entero " + sqlConnection.Database);
                DesaprovicionadorDeAmbito.DeprovisionStore();
                Loguear("Se desaproviciono el servidor entero " + sqlConnection.Database);
            }
            catch (Exception e)
            {
                Loguear(e.Message);
            }
        }
Beispiel #27
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;
 }
Beispiel #28
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);
            }
        }
        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]");
                }
            }
        }
Beispiel #30
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.");
        }
Beispiel #31
0
        private void removeScopeToolStripMenuItem_Click(object sender, EventArgs e)
        {
#if (DEBUG)
            SqlConnection clientConn = new SqlConnection(Program.str_debug_clientConn);
#else
            SqlConnection clientConn = new SqlConnection(Program.str_release_clientConn);
#endif
            SqlConnection serverConn = new SqlConnection(Program.str_serverConn);
            SqlSyncScopeDeprovisioning objDeprovisioning1 = new SqlSyncScopeDeprovisioning(serverConn);
            objDeprovisioning1.DeprovisionStore();

            SqlSyncScopeDeprovisioning objDeprovisioning2 = new SqlSyncScopeDeprovisioning(clientConn);
            objDeprovisioning2.DeprovisionStore();

            DialogResult result = DotNetPerls.BetterDialog.ShowDialog(
                "Trans2Summa3060",                                          //titleString
                "Client and Server Successfully DeProvisioned.",            //bigString
                null,                                                       //smallString
                null,                                                       //leftButton
                "OK",                                                       //rightButton
                global::Trans2Summa3060.Properties.Resources.Message_info); //iconSet
        }
Beispiel #32
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);
    }
Beispiel #33
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)
            {
            }
        }
Beispiel #34
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);
                }
            }
        }
Beispiel #35
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);
                }
            }
        }
Beispiel #36
0
        private static void DeprovisionStore(SelectedConfigSections selectedConfig, bool script, DirectoryInfo workingDirectory)
        {
            try
            {
                SqlSyncScopeDeprovisioning deprov =
                    new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()));

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

                if (!script)
                {
                    deprov.DeprovisionStore();
                }
                else
                {
                    SaveScript("deprovisionstore.sql", deprov.ScriptDeprovisionStore(), workingDirectory);
                }
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(
                          "Unexpected error when executing the Deprovisioning command. See inner exception for details.", e);
            }
        }
Beispiel #37
0
 public static void ServerDeprovision()
 {
     SqlSyncScopeDeprovisioning clientSqlCeDepro = new SqlSyncScopeDeprovisioning(serverConn);
     clientSqlCeDepro.DeprovisionStore();
 }
        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);

                    }
                }
            }
        }
Beispiel #39
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 DesaprovicionarServidor(SqlConnection conexionSql )
 {
     SqlSyncScopeDeprovisioning DesaprovicionadorDeAmbito = new SqlSyncScopeDeprovisioning(conexionSql);
     DesaprovicionadorDeAmbito.ObjectSchema = this.esquemaMetadataSyncFramework;
     DesaprovicionadorDeAmbito.ObjectPrefix = this.prefijoMetadataSyncFramework;
     try
     {
         this.loguear("Se va a desaprovicionar el servidor entero " + conexionSql.Database + " Inicio:\t" + DateTime.Now);
         DesaprovicionadorDeAmbito.DeprovisionStore();
         this.loguear("Se desaprovicio el servidor entero " + conexionSql.Database + " fin:\t" + DateTime.Now);
     }
     catch (Exception e)
     {
         this.loguear(e.Message);
     }
 }
        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);
        }