Snapshot and sync senario
-
2012年4月4日 12:26
Hi all. I refer to an earlier post which I have read over and over again. I have a similar scenario which I am trying to figure out. http://social.microsoft.com/Forums/is/syncdevdiscussions/thread/fd23f665-02cb-4ec1-be1a-c7f6ff1ecdbf
My systems basically is a roaming system which engineers use to fill out forms on completion of a job. The system lists all related jobs to an individual (filtered scope) and has various other tables with fairly static data.
So I have set up the system already to create a snapshot of tables definitions and some data, this works well after exhaustive reading as said post above.
My question is how do I deal with populating filtered data based on when an engineer first runs the system? Do I set up the snapshot with the filtered scope upfront? I'm nearly there, just feel like holes are appearing around me.
DbSyncScopeDescription filteredScope = new DbSyncScopeDescription("filtered_Template"); DbSyncScopeDescription unfilteredScope = new DbSyncScopeDescription("UnfilteredScope"); public void Setup() { try { SetUpFilteredScope(); SetUpUnfilteredScope(); SetupSnapshot(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } public void SetUpFilteredScope() { try { // Set a friendly description of the template. filteredScope.UserComment = "Template for tblReportSheet. tblReportSheet data is filtered by Engineer Name parameter."; DbSyncTableDescription tblReport = SqlSyncDescriptionBuilder.GetDescriptionForTable("tblReportSheet", sqlAzureConn); // Add the tables from above to the scope filteredScope.Tables.Add(tblReport); SqlSyncScopeProvisioning serverTemplate = new SqlSyncScopeProvisioning(sqlAzureConn, filteredScope, SqlSyncScopeProvisioningType.Template); // Setup SQL Azure for sync SqlSyncScopeProvisioning sqlAzureProv = new SqlSyncScopeProvisioning(sqlAzureConn, filteredScope); if (!sqlAzureProv.ScopeExists(scopeName)) { // Apply the filter template provisioning. MessageBox.Show("Provisioning SQL Azure for sync " + DateTime.Now); serverTemplate.Tables["tblReportSheet"].AddFilterColumn("RS_EngineerName"); serverTemplate.Tables["tblReportSheet"].FilterClause = "[side].[RS_EngineerName] = @EngineerName"; SqlParameter param = new SqlParameter("@EngineerName", SqlDbType.NVarChar, 100); serverTemplate.Tables["tblReportSheet"].FilterParameters.Add(param); serverTemplate.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.Create); serverTemplate.Apply(); //Filtered Scope SqlSyncScopeProvisioning serverProvRetail = new SqlSyncScopeProvisioning(sqlAzureConn); serverProvRetail.PopulateFromTemplate("EngineerCalls", "filtered_Template"); serverProvRetail.Tables["tblReportSheet"].FilterParameters["@EngineerName"].Value = User.ThisUser; serverProvRetail.UserComment = "Engineer data includes only their calls."; serverProvRetail.Apply(); } //else // MessageBox.Show("SQL Azure Database server already provisioned for sync " + DateTime.Now); // Setup SQL CE for sync } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } public void SetUpUnfilteredScope() { try { DbSyncTableDescription tblUserNames = SqlSyncDescriptionBuilder.GetDescriptionForTable("tblUserNames", sqlAzureConn); // Add the tables from above to the scope unfilteredScope.Tables.Add(tblUserNames); // Setup SQL Azure for sync SqlSyncScopeProvisioning sqlAzureProv = new SqlSyncScopeProvisioning(sqlAzureConn, unfilteredScope); sqlAzureProv.PopulateFromScopeDescription(unfilteredScope); sqlAzureProv.Apply(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } public void SetupSnapshot() { //Snapshot Provisoning Helpers.SyncUtility.DeleteAndRecreateCompactDatabase(Helpers.SyncUtility.ConnSQLCeSnapshot, true); Helpers.SyncUtility.DeleteAndRecreateCompactDatabase(Helpers.SyncUtility.ConnSQLCe, false); //Add provision for filtered template to snapshot DbSyncScopeDescription clientSqlSnapshotFilterDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("EngineerCalls", sqlAzureConn); SqlCeSyncScopeProvisioning clientSqlSnapshotFilterConfig = new SqlCeSyncScopeProvisioning(sqlCeSnapshotConn, clientSqlSnapshotFilterDesc); clientSqlSnapshotFilterConfig.Apply(); //Add provision for unfiltered template to snapshot DbSyncScopeDescription clientSqlSnapshotUnfilteredDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("UnfilteredScope", sqlAzureConn); SqlCeSyncScopeProvisioning clientSqlSnapshotUnfilterConfig = new SqlCeSyncScopeProvisioning(sqlCeSnapshotConn, clientSqlSnapshotUnfilteredDesc); clientSqlSnapshotUnfilterConfig.Apply(); //Add data to table Helpers.MySyncOrchestrator MyServerSyncProvider; MyServerSyncProvider = new Helpers.MySyncOrchestrator( new SqlCeSyncProvider("UnfilteredScope", sqlCeSnapshotConn), new SqlSyncProvider("UnfilteredScope", sqlAzureConn) ); //MessageBox.Show(string.Format("ScopeName={0} ", scopeName.ToUpper())); MessageBox.Show("Starting Sync " + DateTime.Now); ShowStatistics(MyServerSyncProvider.Synchronize()); SqlCeSyncStoreSnapshotInitialization syncStoreSnapshot = new SqlCeSyncStoreSnapshotInitialization(); syncStoreSnapshot.GenerateSnapshot(sqlCeSnapshotConn, "ComfortLocal.sdf"); //Add Provision to created ComfortLocal for Filtered SqlCeSyncScopeProvisioning sqlCeProv = new SqlCeSyncScopeProvisioning(sqlCeConn, filteredScope); if (!sqlCeProv.ScopeExists("filtered_Template")) { // Apply the scope provisioning. MessageBox.Show("Provisioning SQL Filtered for sync " + DateTime.Now); sqlCeProv.Apply(); MessageBox.Show("Done Provisioning SQL Filtered for sync " + DateTime.Now); } //Add Provision to created ComfortLocal for Unfiltered SqlCeSyncScopeProvisioning sqlCeUnfilteredProv = new SqlCeSyncScopeProvisioning(sqlCeConn, unfilteredScope); if (!sqlCeUnfilteredProv.ScopeExists("UnfilteredScope")) { // Apply the scope provisioning. MessageBox.Show("Provisioning SQL Unfiltered for sync " + DateTime.Now); sqlCeProv.Apply(); MessageBox.Show("Done Provisioning SQL Unfiltered for sync " + DateTime.Now); } sqlAzureConn.Close(); sqlAzureConn.Dispose(); sqlCeConn.Close(); sqlCeConn.Dispose(); sqlCeSnapshotConn.Close(); sqlCeSnapshotConn.Dispose(); }
advanced thanks for any help. Scott
すべての返信
-
2012年4月4日 12:43モデレータ
how long does it take you to generate the snapshot? if the amount of time for generating the snapshot is roughly the same as copying the snapshot to each engineer's machine, then just generate it directly without using a snapshot.
a snapshot works best for initializing clients when the amount of time to generate it takes long (think generating snapshots in the evening so they can are ready in the morning) or if the size of the database is an issue when distributing over slow lines (think gigabyte sized DBs over slow links). its also best for distributing same copies of the same data and not user-specific.
-
2012年4月4日 12:55
Thanks JuneT. Was kind of hoping you would answer.
I distribute this system via clickonce, and based on the nature of the business I regularly update the system, so would assume the system will wipe out the current .sdf based on any changes happening. Also the engineers use mobile signal (80% of time) when running the system so would expect slow(ish) downloads.
I can see your logic though. If its packed up in the main update it will take the same amount of time as connecting to the server and downloading the data. I assumed that loading it upfront would speed distribution up. If thats not really the case then I can rule out the use of snapshots.
Thanks Scott
-
2012年4月4日 13:03モデレータif its via a slow link, downloading a pre-loaded snapshot will most likely be faster than serializing the data during sync and inserting them to the local database.
-
2012年4月4日 13:08Thanks again. So for the filtered scope. Can I just create that once the the system is distributed? If correct I'll close the question down. Scott
-
2012年4月4日 13:24モデレータ
depends on how big and how long it takes to download the filtered scope... are your user's fine with waiting for the clickonce app to get installed/updated and waiting some more to sync the filtered scope?
-
2012年4月4日 13:30
The filtered scope contains small amounts of data, but over a few tables (I am at an early part of the programming). They may have 5-10 calls but have related data in other tables.
I can't see any other way of doing this but am worried about download times. Testing will proof if its viable.
I think I will do the snapshot of static data and then process the filtered data straight after. Once they have this data then any new calls will populate through a general re sync.
-
2012年4月4日 13:45モデレータ
yup, do the testing. at least you know what you're options are and both options are not that difficult to implement either.- 回答としてマーク scottsanpedro1 2012年4月4日 13:52