private void addSqlBtn_Click(object sender, EventArgs e)
        {
            sqlCreationWizard = new NewSqlPeerCreationWizard();

            if (sqlCreationWizard.ShowDialog(this) == DialogResult.OK)
            {
                string existingPeerName;
                if (IsDatabaseUsedByExistingPeer(sqlCreationWizard.ServerName, sqlCreationWizard.DatabaseName, out existingPeerName))
                {
                    MessageBox.Show(string.Format("The database [{0}] in server [{1}] is already used by sync peer [{2}]. Please pick a different database name instead.",
                                                  sqlCreationWizard.DatabaseName, sqlCreationWizard.ServerName, existingPeerName),
                                    "Error in creation SQL database", MessageBoxButtons.OK);
                    return;
                }

                SqlDatabase peer = new SqlDatabase();
                peer.ConnectionString       = sqlCreationWizard.PeerDbConnectionString;
                peer.MasterConnectionString = sqlCreationWizard.MasterConnectionString;
                peer.ServerName             = sqlCreationWizard.ServerName;
                peer.DBName = sqlCreationWizard.DatabaseName;

                try
                {
                    SynchronizationHelper.CheckAndCreateSQLDatabase(peer);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error in creating SQL database", MessageBoxButtons.OK);
                    return;
                }

                //Provide our client a unique name
                peer.Name = SyncUtils.PeerNamePrefix + (peersMapping.Keys.Count + 2);

                //Add this client info to our mapping so it can be retrieved
                peersMapping.Add(peer.Name, peer);

                //Create a SqlCeSyncProvider for the new client that is being added
                SqlSyncProvider peerProvider = synchronizationHelper.ConfigureSqlSyncProvider(peer.Connection);

                providersCollection.Add(peer.Name, peerProvider);

                //Now add a new tab to the peer tabs
                TabPage tab = new TabPage(peer.Name);
                tab.Tag = peer;
                TablesViewControl control = new TablesViewControl(peer.Name);
                control.Name = "TablesViewCtrl";
                control.Dock = DockStyle.Fill;
                tab.Controls.Add(control);
                this.peerTabsControl.TabPages.Add(tab);

                //Add the client name to the list of providers available for synchronization
                this.srcProviderComboBox.Items.Add(peer.Name);
                this.destProviderComboBox.Items.Add(peer.Name);
                this.destProviderComboBox.SelectedIndex = destProviderComboBox.Items.Count - 1;

                this.synchronizeBtn.Enabled = this.providersCollection.Count > 1;
            }
        }
Esempio n. 2
0
        private void CESharingForm_Shown(object sender, EventArgs e)
        {
            //Create a new helper class that we will use to configure our providers
            synchronizationHelper = new SynchronizationHelper(this);

            //Read Server host name and configure the Server side DbSyncProvider
            RefreshServerProvider();

            //Read and display values for current peer selected in the tab page
            ReadTableValuesForSelectedTab();

            //Disable the synchronize button till CE clients are added
            this.synchronizeBtn.Enabled = this.providersCollection.Count > 1;
        }
        private void SqlSharingForm_Shown(object sender, EventArgs e)
        {
            this.textPeer1Machine.Text = Environment.MachineName;

            //Create a new helper class that we will use to configure our providers
            synchronizationHelper = new SynchronizationHelper(this, this.textPeer1Machine.Text);

            //Read Server host name and configure the Server side SqlSyncProvider
            RefreshFirstProvider();

            //Read and display values for current peer selected in the tab page
            ReadTableValuesForSelectedTab();

            //Disable the synchronize button till new SQL Server peers are added
            this.synchronizeBtn.Enabled = this.providersCollection.Count > 1;
        }
Esempio n. 4
0
        private void addCEBtn_Click(object sender, EventArgs e)
        {
            ceCreationWizard = new NewCEClientCreationWizard();
            //Create a new client
            CEDatabase client = new CEDatabase();

            if (ceCreationWizard.ShowDialog(this) == DialogResult.OK)
            {
                //Creation mode is based on the option the user picked in the new ce creation wizard
                client.CreationMode = (ceCreationWizard.fullInitRadioBtn.Checked) ? CEDatabaseCreationMode.FullInitialization : CEDatabaseCreationMode.SnapshotInitialization;

                //Database location is based on mode.
                switch (client.CreationMode)
                {
                case CEDatabaseCreationMode.FullInitialization:
                    client.Location = ceCreationWizard.fullInitDbLocation.Text;
                    try
                    {
                        SynchronizationHelper.CheckAndCreateCEDatabase(client);
                    }
                    catch (Exception e1)
                    {
                        MessageBox.Show(e1.ToString(), "Error in creating CE database", MessageBoxButtons.OK);
                        return;
                    }
                    break;

                case CEDatabaseCreationMode.SnapshotInitialization:
                    client.Location = ceCreationWizard.snapshotDestLocation.Text;

                    //Export the source SDF file first.
                    ExportClientDatabase(new SqlCeConnection("Data Source=\"" + ceCreationWizard.snapshotSrcLocation.Text + "\""), client.Location);

                    break;
                }
                //Provide our client a unique name
                client.Name = "Client " + (clientsMapping.Keys.Count + 1);

                //Add this client info to our mapping so it can be retrieved
                clientsMapping.Add(client.Name, client);

                //Create a SqlCeSyncProvider for the new client that is being added
                SqlCeSyncProvider clientProvider = synchronizationHelper.ConfigureCESyncProvider(client.Connection);

                providersCollection.Add(client.Name, clientProvider);

                //Now add a new tab to the peer tabs
                TabPage tab = new TabPage(client.Name);
                tab.Padding = new Padding(8);
                tab.Tag     = client;
                TablesViewControl control = new TablesViewControl(client.Name);
                control.Name = "TablesViewCtrl";
                control.Dock = DockStyle.Fill;
                tab.Controls.Add(control);
                this.peerTabsControl.TabPages.Add(tab);
                tab.BackColor = Color.Transparent;
                tab.UseVisualStyleBackColor = true;

                // Add the name of the file to the bottom
                Label labelFileName = new Label();
                labelFileName.Text    = "SqlCe Filename: " + ceCreationWizard.fullInitDbLocation.Text;
                labelFileName.Dock    = DockStyle.Bottom;
                labelFileName.Padding = new System.Windows.Forms.Padding(4);
                tab.Controls.Add(labelFileName);

                //Add the client name to the list of providers available for synchronization
                this.srcProviderComboBox.Items.Add(client.Name);
                this.destProviderComboBox.Items.Add(client.Name);
                this.destProviderComboBox.SelectedIndex = destProviderComboBox.Items.Count - 1;

                this.synchronizeBtn.Enabled = this.providersCollection.Count > 1;
            }
        }