コード例 #1
0
ファイル: FormSyncItem.cs プロジェクト: 0anion0/IBN
        public bool ThrUpdateSyncStatisticStatus(SyncStatistics syncStats)
        {
            bool retVal = true;

            if (this.InvokeRequired)
            {
                Func <SyncStatistics, bool> func = this.ThrUpdateSyncStatisticStatus;
                retVal = (bool)this.Invoke(func, syncStats);
            }
            else
            {
                if (syncStats != null)
                {
                    this.statusStrip1.Text = String.Format(Resources.FormSyncMenuStatusStrip_Pattern,
                                                           syncStats.UploadChangesApplied,
                                                           syncStats.UploadChangesFailed,
                                                           syncStats.UploadChangesTotal,
                                                           syncStats.DownloadChangesApplied,
                                                           syncStats.DownloadChangesFailed,
                                                           syncStats.DownloadChangesTotal);
                }
            }

            return(retVal);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: acharal/spsync
 private static void PrintStats(SyncStatistics stats)
 {
     Console.WriteLine("Sync started at " + stats.SyncStartTime + " and completed at " + stats.SyncCompleteTime);
     Console.WriteLine("Download Changes Applied: " + stats.DownloadChangesApplied);
     Console.WriteLine("Download Changes Failed : " + stats.DownloadChangesFailed);
     Console.WriteLine("Upload Changes Applied  : " + stats.UploadChangesApplied);
     Console.WriteLine("Upload Changes Failed   : " + stats.UploadChangesFailed);
     Console.WriteLine("Total Changes Downloaded: " + stats.TotalChangesDownloaded);
     Console.WriteLine("Total Changes Uploaded  : " + stats.TotalChangesUploaded);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: acharal/spsync
 private static void PrintStats(SyncStatistics stats)
 {
     Console.WriteLine("Sync started at " + stats.SyncStartTime + " and completed at " + stats.SyncCompleteTime);
     Console.WriteLine("Download Changes Applied: " + stats.DownloadChangesApplied);
     Console.WriteLine("Download Changes Failed : " + stats.DownloadChangesFailed);
     Console.WriteLine("Upload Changes Applied  : " + stats.UploadChangesApplied);
     Console.WriteLine("Upload Changes Failed   : " + stats.UploadChangesFailed);
     Console.WriteLine("Total Changes Downloaded: " + stats.TotalChangesDownloaded);
     Console.WriteLine("Total Changes Uploaded  : " + stats.TotalChangesUploaded);
 }
コード例 #4
0
        static void Main(string[] args)
        {
            //The Utility class handles all functionality that is not
            //directly related to synchronization, such as holding
            //connection string information and making changes to the
            //server and client databases.
            Utility util = new Utility();

            //The SampleStats class handles information from the SyncStatistics
            //object that the Synchronize method returns.
            SampleStats sampleStats = new SampleStats();

            //Request a password for the client database, and delete
            //and re-create the database. The client synchronization
            //provider also enables you to create the client database
            //if it does not exist.
            util.SetClientPassword();
            util.RecreateClientDatabase();

            //Specify which server and database to connect to.
            util.SetServerAndDb("localhost", "SyncSamplesDb_ChangeTracking");

            //Initial synchronization. Instantiate the SyncAgent
            //and call Synchronize.
            SampleSyncAgent sampleSyncAgent = new SampleSyncAgent();
            SyncStatistics  syncStatistics  = sampleSyncAgent.Synchronize();

            sampleStats.DisplayStats(syncStatistics, "initial");

            //Make changes on the server and client.
            util.MakeDataChangesOnServer("Customer");
            util.MakeDataChangesOnClient("Customer");

            //Subsequent synchronization.
            syncStatistics = sampleSyncAgent.Synchronize();
            sampleStats.DisplayStats(syncStatistics, "subsequent");

            //Make conflicting changes on the server and client.
            util.MakeConflictingChangesOnClientAndServer();

            //Subsequent synchronization.
            syncStatistics = sampleSyncAgent.Synchronize();
            sampleStats.DisplayStats(syncStatistics, "subsequent");

            //Return server data back to its original state.
            util.CleanUpServer();

            //Exit.
            Console.Write("\nPress Enter to close the window.");
            Console.ReadLine();
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: acharal/spsync
        private void button1_Click(object sender, EventArgs e)
        {
            SpSync.Data.Server.SpServerSyncProvider prov = new SpSync.Data.Server.SpServerSyncProvider();
            prov.ServiceCredentials = new System.Net.NetworkCredential("nangelc1it", "p@n@th@s13", "VIANEX");
            prov.BatchSize          = 100;
            SyncServerInfo info = prov.GetServerInfo(null);

            Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider client = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider("Data Source=test.sdf", true);
            Microsoft.Synchronization.SyncAgent agent = new Microsoft.Synchronization.SyncAgent(client, prov);
            //agent.Configuration.SyncTables.Add("Doctors", SyncDirection.Bidirectional);
            agent.Configuration.SyncTables.Add("Accounts", SyncDirection.DownloadOnly);
            //agent.Configuration.SyncTables.Add("Contacts", SyncDirection.DownloadOnly);
            agent.SessionProgress += new EventHandler <Microsoft.Synchronization.SessionProgressEventArgs>(agent_SessionProgress);
            agent.StateChanged    += new EventHandler <Microsoft.Synchronization.SessionStateChangedEventArgs>(agent_StateChanged);
            SyncStatistics stats = agent.Synchronize();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            //The Utility class handles all functionality that is not
            //directly related to synchronization, such as holding connection
            //string information and making changes to the server and client databases.
            Utility util = new Utility();

            //The SampleStats class handles information from the SyncStatistics
            //object that the Synchronize method returns.
            SampleStats sampleStats = new SampleStats();

            //Request a password for the client database, and delete
            //and re-create the database. The client synchronization
            //provider also enables you to create the client database
            //if it does not exist.
            util.SetClientPassword();
            util.RecreateClientDatabase();

            //Initial synchronization. Instantiate the SyncAgent
            //and call Synchronize.
            SampleSyncAgent sampleSyncAgent = new SampleSyncAgent();
            SyncStatistics  syncStatistics  = sampleSyncAgent.Synchronize();

            sampleStats.DisplayStats(syncStatistics, "initial");

            //Make a change at the client that fails when it is
            //applied at the server.
            util.MakeFailingChangesOnClient();

            //Make changes at the client and server that conflict
            //when they are synchronized.
            util.MakeConflictingChangesOnClientAndServer();

            //Subsequent synchronization.
            syncStatistics = sampleSyncAgent.Synchronize();
            sampleStats.DisplayStats(syncStatistics, "subsequent");

            //Return server data back to its original state.
            //Comment out this line if you want to view the
            //state of the data after all conflicts are resolved.
            util.CleanUpServer();

            //Exit.
            Console.Write("\nPress Enter to close the window.");
            Console.ReadLine();
        }
コード例 #7
0
        public void DisplayStats(SyncStatistics syncStatistics, string syncType)
        {
            Console.WriteLine(String.Empty);
            if (syncType == "initial")
            {
                Console.WriteLine("****** Initial Synchronization ******");
            }
            else if (syncType == "subsequent")
            {
                Console.WriteLine("***** Subsequent Synchronization ****");
            }

            Console.WriteLine("Start Time: " + syncStatistics.SyncStartTime);
            Console.WriteLine("Total Changes Downloaded: " + syncStatistics.TotalChangesDownloaded);
            Console.WriteLine("Complete Time: " + syncStatistics.SyncCompleteTime);
            Console.WriteLine(String.Empty);
        }
コード例 #8
0
        static void Main(string[] args)
        {
            //The Utility class handles all functionality that is not
            //directly related to synchronization, such as holding connection
            //string information and making changes to the server and client databases.
            Utility util = new Utility();

            //The SampleStats class handles information from the SyncStatistics
            //object that the Synchronize method returns.
            SampleStats sampleStats = new SampleStats();

            //Request a password for the client database, and delete
            //and re-create the database. The client synchronization
            //provider also enables you to create the client database
            //if it does not exist.
            util.SetClientPassword();
            util.RecreateClientDatabase();

            //Create the Customer table on the client by using SQL. We add
            //a SalesNotes column that will not be synchronized.
            //When we create the Customer SyncTable, we specify that
            //Synchronization Services should use an existing table.
            util.CreateTableOnClient();

            //Initial synchronization. Instantiate the SyncAgent
            //and call Synchronize.
            SampleSyncAgent sampleSyncAgent = new SampleSyncAgent();
            SyncStatistics  syncStatistics  = sampleSyncAgent.Synchronize();

            sampleStats.DisplayStats(syncStatistics, "initial");

            //Make changes on the server and client.
            util.MakeDataChangesOnServer("Customer");
            util.MakeDataChangesOnClient("Customer");

            //Subsequent synchronization.
            syncStatistics = sampleSyncAgent.Synchronize();
            sampleStats.DisplayStats(syncStatistics, "subsequent");

            //Return the server data back to its original state.
            util.CleanUpServer();

            //Exit.
            Console.Write("\nPress Enter to close the window.");
            Console.ReadLine();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: acharal/spsync
        static void Main(string[] args)
        {
            System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.ConsoleTraceListener());
            SpSync.Data.Server.SpServerSyncProvider prov = new SpSync.Data.Server.SpServerSyncProvider();
            prov.ServiceCredentials = new System.Net.NetworkCredential("nangelc1it", "p@n@th@s13", "VIANEX");
            prov.BatchSize          = 500;
            SyncServerInfo info = prov.GetServerInfo(null);

            Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider client = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider(Settings.Default.testConnectionString, true);
            Microsoft.Synchronization.SyncAgent agent = new Microsoft.Synchronization.SyncAgent(client, prov);
            //agent.Configuration.SyncTables.Add("Doctors", SyncDirection.Bidirectional);
            agent.Configuration.SyncTables.Add("Accounts", SyncDirection.DownloadOnly);
            agent.Configuration.SyncTables.Add("Contacts", SyncDirection.DownloadOnly);
            agent.SessionProgress += new EventHandler <Microsoft.Synchronization.SessionProgressEventArgs>(agent_SessionProgress);
            agent.StateChanged    += new EventHandler <Microsoft.Synchronization.SessionStateChangedEventArgs>(agent_StateChanged);
            SyncStatistics stats = agent.Synchronize();

            PrintStats(stats);
            Console.Read();
        }
コード例 #10
0
        static void Main(string[] args)
        {
            //The Utility class handles all functionality that is not
            //directly related to synchronization, such as holding connection
            //string information and making changes to the server database.
            Utility util = new Utility();

            //The SampleStats class handles information from the SyncStatistics
            //object that the Synchronize method returns.
            SampleStats sampleStats = new SampleStats();

            //Delete and re-create the database. The client synchronization
            //provider also enables you to create the client database
            //if it does not exist.
            util.SetClientPassword();
            util.RecreateClientDatabase();

            //Initial synchronization. Instantiate the SyncAgent
            //and call Synchronize.
            //<snippetOCS_CS_Basic_Synchronize>
            SampleSyncAgent sampleSyncAgent = new SampleSyncAgent();
            SyncStatistics  syncStatistics  = sampleSyncAgent.Synchronize();

            //</snippetOCS_CS_Basic_Synchronize>
            sampleStats.DisplayStats(syncStatistics, "initial");

            //Make changes on the server.
            util.MakeDataChangesOnServer();

            //Subsequent synchronization.
            syncStatistics = sampleSyncAgent.Synchronize();
            sampleStats.DisplayStats(syncStatistics, "subsequent");

            //Return server data back to its original state.
            util.CleanUpServer();

            //Exit.
            Console.Write("\nPress Enter to close the window.");
            Console.ReadLine();
        }
コード例 #11
0
        public void Can_Sync_Single_Insert_On_Client_Roundtrip_With_Server()
        {
            var sampleStats     = new SampleStats();
            var crmConnString   = GetCrmServiceProvider().ConnectionProvider.OrganisationServiceConnectionString;
            var sampleSyncAgent = new TestDynamicsCrmSyncAgent(SqlCompactDatabaseConnectionString, crmConnString);

            SyncStatistics syncStatistics = sampleSyncAgent.Synchronize();

            sampleStats.DisplayStats(syncStatistics, "initial");

            // get number of existing records.
            // assert that the client only has one record and that the server only has 1 record.
            int existingCount = 0;

            using (var clientConn = new SqlCeConnection(SqlCompactDatabaseConnectionString))
            {
                clientConn.Open();
                using (var sqlCeCommand = clientConn.CreateCommand())
                {
                    sqlCeCommand.CommandText = string.Format("SELECT COUNT({0}) FROM {1}", TestDynamicsCrmServerSyncProvider.IdAttributeName, TestDynamicsCrmServerSyncProvider.TestEntityName);
                    existingCount            = (int)sqlCeCommand.ExecuteScalar();
                    // Assert.That(rowCount, Is.EqualTo(1), string.Format("Only 1 record was synchronised however {0} records ended up in the client database!", rowCount));
                }
                clientConn.Close();
            }


            //Make changes on the client.
            // We will insert into the same columns on the client that the server sync provider includes in its server insert statement,
            // with exception of the sync client id field (thats only provided during a sync)

            var columnsForClientInsert = TestDynamicsCrmServerSyncProvider.InsertColumns.ToList();
            var syncClientIdColumn     = columnsForClientInsert.First(c => c.AttributeName == SyncColumnInfo.CreatedBySyncClientIdAttributeName);

            columnsForClientInsert.Remove(syncClientIdColumn);
            sampleSyncAgent.ClientSyncProvider.InsertTestRecord(1, columnsForClientInsert);

            //Now sync the new record on the client to the server.
            syncStatistics = sampleSyncAgent.Synchronize();
            sampleStats.DisplayStats(syncStatistics, "second");

            // Verfiy new record is added on server.
            Assert.That(syncStatistics.DownloadChangesFailed, Is.EqualTo(0), "There were failed downloads during the sync.");
            Assert.That(syncStatistics.UploadChangesFailed, Is.EqualTo(0), "There were failed uploads during the sync.");
            var service = new CrmServiceProvider(new ExplicitConnectionStringProviderWithFallbackToConfig(), new CrmClientCredentialsProvider());

            using (var orgService = service.GetOrganisationService() as OrganizationServiceContext)
            {
                var entity = (from a in orgService.CreateQuery(TestDynamicsCrmServerSyncProvider.TestEntityName) orderby a["createdon"] descending select a).FirstOrDefault();
                Assert.That(entity, Is.Not.Null);
                var clientId = entity.Attributes[SyncColumnInfo.CreatedBySyncClientIdAttributeName];
                Assert.That(clientId, Is.EqualTo(SelectIncrementalCreatesCommand.SyncClientId), "A record was inserted during synchronisation, however it did not have a client id set.");

                // verify all the other fields are set.
                foreach (var col in columnsForClientInsert)
                {
                    var testAttribute = entity.Attributes[col.AttributeName];
                    Assert.That(testAttribute, Is.Not.Null, "A record was inserted during synchronisation, however it did not have a value for the attribute:  " + col.AttributeName);
                    Assert.That(testAttribute.ToString(), Is.Not.EqualTo(""), "The attribute " + col.AttributeName + " had a value inserted to the client but was then synced to the server, and was blank on the server after the sync finished.");
                }
            }

            // Now sync one more time and verify that the new reocrd that has been applied to the server does not come back as an insert on the client again!
            // The server updates the record as its saved to the server so it should come back as an update with the server generated values set on the record.
            syncStatistics = sampleSyncAgent.Synchronize();
            sampleStats.DisplayStats(syncStatistics, "third");

            // assert that the client only has one record and that the server only has 1 record.
            using (var clientConn = new SqlCeConnection(SqlCompactDatabaseConnectionString))
            {
                clientConn.Open();
                using (var sqlCeCommand = clientConn.CreateCommand())
                {
                    sqlCeCommand.CommandText = string.Format("SELECT COUNT({0}) FROM {1}", TestDynamicsCrmServerSyncProvider.IdAttributeName, TestDynamicsCrmServerSyncProvider.TestEntityName);
                    var rowCount = (int)sqlCeCommand.ExecuteScalar();
                    Assert.That(rowCount, Is.EqualTo(existingCount + 1), string.Format("Only 1 new record was created, however after a few synchronisations, {0} new records ended up in the client database!", rowCount - existingCount));
                }
                clientConn.Close();
            }
        }
コード例 #12
0
        static void Main(string[] args)
        {
            //The Utility class handles all functionality that is not
            //directly related to synchronization, such as holding connection
            //string information and making changes to the server database.
            Utility util = new Utility();

            //The SampleStats class handles information from the SyncStatistics
            //object that the Synchronize method returns.
            SampleStats sampleStats = new SampleStats();

            //Delete and re-create the database. The client synchronization
            //provider also enables you to create the client database
            //if it does not exist.
            util.SetClientPassword();
            util.RecreateClientDatabase();

            //Write to the console which tracing levels are enabled. The app.config
            //file specifies a value of 3 for the SyncTracer switch, which corresponds
            //to Info. Therefore, Error, Warning, and Info return True, and Verbose
            //returns False.
            Console.WriteLine("");
            //<snippetOCS_CS_Tracing_LevelsEnabled>
            Console.WriteLine("** Tracing Levels Enabled for this Application **");
            Console.WriteLine("Error: " + SyncTracer.IsErrorEnabled().ToString());
            Console.WriteLine("Warning: " + SyncTracer.IsWarningEnabled().ToString());
            Console.WriteLine("Info: " + SyncTracer.IsInfoEnabled().ToString());
            Console.WriteLine("Verbose: " + SyncTracer.IsVerboseEnabled().ToString());
            //</snippetOCS_CS_Tracing_LevelsEnabled>

            //Initial synchronization. Instantiate the SyncAgent
            //and call Synchronize.
            //<snippetOCS_CS_Tracing_Synchronize>
            SampleSyncAgent sampleSyncAgent = new SampleSyncAgent();
            SyncStatistics  syncStatistics  = sampleSyncAgent.Synchronize();

            //</snippetOCS_CS_Tracing_Synchronize>
            sampleStats.DisplayStats(syncStatistics, "initial");

            //Make a change at the client that fails when it is
            //applied at the server. The constraint violation
            //is automatically written to the trace file as a warning.
            util.MakeFailingChangesOnClient();

            //Make changes at the client and server that conflict
            //when they are synchronized. The conflicts are written
            //to the trace file in the SampleServerSyncProvider_ApplyChangeFailed
            //event handler.
            util.MakeConflictingChangesOnClientAndServer();

            //Subsequent synchronization.
            syncStatistics = sampleSyncAgent.Synchronize();
            sampleStats.DisplayStats(syncStatistics, "subsequent");

            //Return server data back to its original state.
            util.CleanUpServer();

            //Exit.
            Console.Write("\nPress Enter to close the window.");
            Console.ReadLine();
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: jervie29/sqldatasync
        public void DisplayStats(SyncStatistics syncStatistics, string syncType)
        {
            Console.WriteLine(String.Empty);
            if (syncType == "initial")
            {
                Console.WriteLine("****** Initial Synchronization ******");
            }
            else if (syncType == "subsequent")
            {
                Console.WriteLine("***** Subsequent Synchronization ****");
            }

            Console.WriteLine("Start Time: " + syncStatistics.SyncStartTime);
            Console.WriteLine("Total Changes Uploaded: " + syncStatistics.TotalChangesUploaded);
            Console.WriteLine("Total Changes Downloaded: " + syncStatistics.TotalChangesDownloaded);
            Console.WriteLine("Complete Time: " + syncStatistics.SyncCompleteTime);
            Console.WriteLine(String.Empty);
        }