public void Insert(int resourceKindId, SyncDigestEntryInfo[] syncDigestEntryInfo, IJetTransaction jetTransaction) { IEndPointTableAdapter EndPointTableAdapter = StoreEnvironment.Resolve <IEndPointTableAdapter>(this.Context); OleDbCommand oleDbCommand = jetTransaction.CreateOleCommand(); EndPointInfo tmpEndPointInfo; string sqlQuery = string.Empty; sqlQuery = "INSERT INTO [{0}] ([tick], [ConflictPriority], [Stamp], [FKResourceKindId], [FKEndPointId]) VALUES (@tick, @ConflictPriority, @Stamp, @ResourceKindId, @EndPointId);"; oleDbCommand.CommandText = string.Format(sqlQuery, _syncDigestTable.TableName); foreach (SyncDigestEntryInfo info in syncDigestEntryInfo) { // TODO: Use prepared query tmpEndPointInfo = EndPointTableAdapter.GetOrCreate(info.EndPoint, jetTransaction); //oleDbCommand.Parameters.Clear(); oleDbCommand.Parameters.AddWithValue("@tick", info.Tick); oleDbCommand.Parameters.AddWithValue("@ConflictPriority", info.ConflictPriority); oleDbCommand.Parameters.AddWithValue("@Stamp", info.Stamp.ToString()); oleDbCommand.Parameters.AddWithValue("@ResourceKindId", resourceKindId); oleDbCommand.Parameters.AddWithValue("@EndPointId", tmpEndPointInfo.Id); oleDbCommand.ExecuteNonQuery(); } }
public bool Update(CorrelatedResSyncInfo info, IJetTransaction jetTransaction) { IEndPointTableAdapter EndPointTableAdapter = StoreEnvironment.Resolve <IEndPointTableAdapter>(this.Context); EndPointInfo EndPointInfo = EndPointTableAdapter.GetOrCreate(info.ResSyncInfo.EndPoint, jetTransaction); OleDbCommand oleDbCommand = jetTransaction.CreateOleCommand(); string sqlQuery = string.Empty; // store only correlation data if tick is set to -1 if (info.ResSyncInfo.Tick == -1) { sqlQuery = "UPDATE [{0}] SET [LocalId]=@LocalId WHERE (Uuid=@Uuid);"; oleDbCommand.CommandText = string.Format(sqlQuery, _correlatedResSyncTable.TableName); oleDbCommand.Parameters.AddWithValue("@LocalId", info.LocalId); oleDbCommand.Parameters.AddWithValue("@Uuid", info.ResSyncInfo.Uuid); } else { sqlQuery = "UPDATE [{0}] SET [tick]=@tick, [ModifiedStamp]=@ModifiedStamp, [Etag]=@Etag, [LocalId]=@LocalId , [FKEndPointId]=@EndPointId WHERE (Uuid=@Uuid);"; oleDbCommand.CommandText = string.Format(sqlQuery, _correlatedResSyncTable.TableName); oleDbCommand.Parameters.AddWithValue("@tick", info.ResSyncInfo.Tick); oleDbCommand.Parameters.AddWithValue("@ModifiedStamp", info.ResSyncInfo.ModifiedStamp.ToString()); oleDbCommand.Parameters.AddWithValue("@Etag", info.ResSyncInfo.Etag); oleDbCommand.Parameters.AddWithValue("@LocalId", info.LocalId); oleDbCommand.Parameters.AddWithValue("@EndPointId", EndPointInfo.Id); oleDbCommand.Parameters.AddWithValue("@Uuid", info.ResSyncInfo.Uuid); } return(0 != oleDbCommand.ExecuteNonQuery()); }
public SyncDigestEntryInfo Get(string resourceKind, string EndPoint) { SyncDigestEntryInfo resultInfo = null; ISyncDigestTableAdapter syncDigestTableAdapter = StoreEnvironment.Resolve <ISyncDigestTableAdapter>(_context); IResourceKindTableAdapter resourceKindTableAdapter = StoreEnvironment.Resolve <IResourceKindTableAdapter>(_context); IEndPointTableAdapter EndPointTableAdapter = StoreEnvironment.Resolve <IEndPointTableAdapter>(_context); using (IJetTransaction jetTransaction = _jetConnectionProvider.GetTransaction(false)) { ResourceKindInfo resourceKindInfo = resourceKindTableAdapter.GetOrCreate(resourceKind, jetTransaction); EndPointInfo EndPointInfo = EndPointTableAdapter.GetOrCreate(EndPoint, jetTransaction); resultInfo = syncDigestTableAdapter.Get(resourceKindInfo.Id, EndPointInfo.Id, jetTransaction); jetTransaction.Commit(); } return(resultInfo); }
public ICorrelatedResSyncInfoEnumerator GetSincetick(string resourceKind, string EndPoint, int tick) { CorrelatedResSyncInfo[] resultInfos; ICorrelatedResSyncTableAdapter correlatedResSyncTableAdapter = this.GetAdapter(resourceKind); IEndPointTableAdapter EndPointTableAdapter = StoreEnvironment.Resolve <IEndPointTableAdapter>(_context); using (IJetTransaction jetTransaction = _jetConnectionProvider.GetTransaction(false)) { EndPointInfo EndPointInfo = EndPointTableAdapter.GetOrCreate(EndPoint, jetTransaction); resultInfos = correlatedResSyncTableAdapter.GetSincetick(EndPointInfo.Id, tick, jetTransaction); jetTransaction.Commit(); } return((null != resultInfos) ? new CorrelatedResSyncInfoEnumerator(resultInfos) : new CorrelatedResSyncInfoEnumerator(new CorrelatedResSyncInfo[0])); }
private ICorrelatedResSyncTableAdapter GetAdapter(string resourceKind) { ICorrelatedResSyncTableAdapter correlatedResSyncTableAdapter; IEndPointTableAdapter EndPointTableAdapter = StoreEnvironment.Resolve <IEndPointTableAdapter>(_context); IResourceKindTableAdapter resourceKindTableAdapter = StoreEnvironment.Resolve <IResourceKindTableAdapter>(_context); Dictionary <string, ICorrelatedResSyncTableAdapter> adapters = StoreEnvironment.Resolve <Dictionary <string, ICorrelatedResSyncTableAdapter> >(_context); if (!adapters.TryGetValue(resourceKind, out correlatedResSyncTableAdapter)) { TableAdapterFactory factory = new TableAdapterFactory(_context, _jetConnectionProvider); correlatedResSyncTableAdapter = factory.CreateCorrelatedResSyncTableAdapter(resourceKind, EndPointTableAdapter, resourceKindTableAdapter); adapters.Add(resourceKind, correlatedResSyncTableAdapter); StoreEnvironment.Set <Dictionary <string, ICorrelatedResSyncTableAdapter> >(_context, adapters); } return(correlatedResSyncTableAdapter); }
internal ICorrelatedResSyncTableAdapter CreateCorrelatedResSyncTableAdapter(string resourceKind, IEndPointTableAdapter EndPointTableAdapter, IResourceKindTableAdapter resourceKindTableAdapter) { ResourceKindInfo resourceKindInfo = null; using (IJetTransaction jetTransaction = _connProvider.GetTransaction(false)) { resourceKindInfo = resourceKindTableAdapter.GetOrCreate(resourceKind, jetTransaction); jetTransaction.Commit(); } ICorrelatedResSyncTable correlatedResSyncTable = new CorrelatedResSyncTable(resourceKindInfo.Id, resourceKindTableAdapter.Table, EndPointTableAdapter.Table); using (IJetTransaction jetTransaction = _connProvider.GetTransaction(false)) { if (!JetHelpers.TableExists(correlatedResSyncTable.TableName, jetTransaction)) { correlatedResSyncTable.CreateTable(jetTransaction); jetTransaction.Commit(); } } return new CorrelatedResSyncTableAdapter(correlatedResSyncTable,_context); }
public void Insert(CorrelatedResSyncInfo info, IJetTransaction jetTransaction) { IEndPointTableAdapter EndPointTableAdapter = StoreEnvironment.Resolve <IEndPointTableAdapter>(this.Context); EndPointInfo EndPointInfo = EndPointTableAdapter.GetOrCreate(info.ResSyncInfo.EndPoint, jetTransaction); OleDbCommand oleDbCommand = jetTransaction.CreateOleCommand(); string sqlQuery = string.Empty; sqlQuery = "INSERT INTO {0} ([Uuid], [tick], [ModifiedStamp], [Etag], [LocalId], [FKEndPointId], [FKResourceKindId]) VALUES (@Uuid, @tick, @ModifiedStamp, @Etag, @LocalId, @EndPointId, @ResourceKindId);"; oleDbCommand.CommandText = string.Format(sqlQuery, _correlatedResSyncTable.TableName); oleDbCommand.Parameters.AddWithValue("@Uuid", info.ResSyncInfo.Uuid); oleDbCommand.Parameters.AddWithValue("@tick", info.ResSyncInfo.Tick); oleDbCommand.Parameters.AddWithValue("@ModifiedStamp", info.ResSyncInfo.ModifiedStamp.ToString()); oleDbCommand.Parameters.AddWithValue("@Etag", info.ResSyncInfo.Etag); oleDbCommand.Parameters.AddWithValue("@LocalId", info.LocalId); oleDbCommand.Parameters.AddWithValue("@EndPointId", EndPointInfo.Id); oleDbCommand.Parameters.AddWithValue("@ResourceKindId", _correlatedResSyncTable.ResourceKindId); oleDbCommand.ExecuteNonQuery(); }
public static void Initialize(IJetConnectionProvider connProvider, SdataContext context) { StoreEnvironmentItem item = null; lock (lockObj) { if (stat_EnvironmentItems.TryGetValue(context, out item)) { return; } item = new StoreEnvironmentItem(); item.Register <IJetConnectionProvider>(connProvider); TableAdapterFactory tableAdapterFactory = new TableAdapterFactory(context, connProvider); IResourceKindTableAdapter resourceKindTableAdapter = tableAdapterFactory.CreateResourceKindTableAdapter(); item.Register <IResourceKindTableAdapter>(resourceKindTableAdapter); IEndPointTableAdapter EndPointTableAdapter = tableAdapterFactory.CreateEndPointTableAdapter(); item.Register <IEndPointTableAdapter>(EndPointTableAdapter); item.Register <ISyncDigestTableAdapter>(tableAdapterFactory.CreateSyncDigestTableAdapter(resourceKindTableAdapter, EndPointTableAdapter)); item.Register <IAppBookmarkTableAdapter>(tableAdapterFactory.CreateAppBookmarkTableAdapter(resourceKindTableAdapter)); item.Register <ItickTableAdapter>(tableAdapterFactory.CreatetickTableAdapter(resourceKindTableAdapter)); Dictionary <string, ICorrelatedResSyncTableAdapter> correlatedResSyncTableAdapters = new Dictionary <string, ICorrelatedResSyncTableAdapter>(); item.Register <Dictionary <string, ICorrelatedResSyncTableAdapter> >(correlatedResSyncTableAdapters); Dictionary <string, ISyncResultsTableAdapter> syncResultsTableAdapters = new Dictionary <string, ISyncResultsTableAdapter>(); item.Register <Dictionary <string, ISyncResultsTableAdapter> >(syncResultsTableAdapters); //item.Register<ISyncResultsTableAdapter>(tableAdapterFactory.CreateSyncResultsTableAdapter(resourceKindTableAdapter)); stat_EnvironmentItems.Add(context, item); } }
public bool Update(int resourceKindId, SyncDigestEntryInfo syncDigestEntryInfo, IJetTransaction jetTransaction) { IEndPointTableAdapter EndPointTableAdapter = StoreEnvironment.Resolve <IEndPointTableAdapter>(this.Context); OleDbCommand oleDbCommand = jetTransaction.CreateOleCommand(); EndPointInfo tmpEndPointInfo; string sqlQuery = string.Empty; sqlQuery = "UPDATE [{0}] SET [tick]=@tick, [ConflictPriority]=@ConflictPriority, [Stamp]=@Stamp WHERE (FKResourceKindId=@ResourceKindId AND FKEndPointId=@EndPointId);"; oleDbCommand.CommandText = string.Format(sqlQuery, _syncDigestTable.TableName); // TODO: Use prepared query tmpEndPointInfo = EndPointTableAdapter.GetOrCreate(syncDigestEntryInfo.EndPoint, jetTransaction); oleDbCommand.Parameters.AddWithValue("@tick", syncDigestEntryInfo.Tick); oleDbCommand.Parameters.AddWithValue("@ConflictPriority", syncDigestEntryInfo.ConflictPriority); oleDbCommand.Parameters.AddWithValue("@Stamp", syncDigestEntryInfo.Stamp.ToString()); oleDbCommand.Parameters.AddWithValue("@ResourceKindId", resourceKindId); oleDbCommand.Parameters.AddWithValue("@EndPointId", tmpEndPointInfo.Id); int count = oleDbCommand.ExecuteNonQuery(); return(count > 0); }
internal ISyncDigestTableAdapter CreateSyncDigestTableAdapter(IResourceKindTableAdapter resourceKindTableAdapter, IEndPointTableAdapter EndPointTableAdapter) { ISyncDigestTable syncDigestTable = new SyncDigestTable(resourceKindTableAdapter.Table, EndPointTableAdapter.Table); using (IJetTransaction jetTransaction = _connProvider.GetTransaction(false)) { // create the table if (!JetHelpers.TableExists(syncDigestTable.TableName, jetTransaction)) { syncDigestTable.CreateTable(jetTransaction); jetTransaction.Commit(); } else { // update the table ITableFieldsUpdated tableFieldUpdater = syncDigestTable as ITableFieldsUpdated; if (null != tableFieldUpdater) { tableFieldUpdater.UpdateFields(jetTransaction); jetTransaction.Commit(); } } } return new SyncDigestTableAdapter(syncDigestTable, _context); }
internal ISyncDigestTableAdapter CreateSyncDigestTableAdapter(IResourceKindTableAdapter resourceKindTableAdapter, IEndPointTableAdapter EndPointTableAdapter) { ISyncDigestTable syncDigestTable = new SyncDigestTable(resourceKindTableAdapter.Table, EndPointTableAdapter.Table); using (IJetTransaction jetTransaction = _connProvider.GetTransaction(false)) { // create the table if (!JetHelpers.TableExists(syncDigestTable.TableName, jetTransaction)) { syncDigestTable.CreateTable(jetTransaction); jetTransaction.Commit(); } else { // update the table ITableFieldsUpdated tableFieldUpdater = syncDigestTable as ITableFieldsUpdated; if (null != tableFieldUpdater) { tableFieldUpdater.UpdateFields(jetTransaction); jetTransaction.Commit(); } } } return(new SyncDigestTableAdapter(syncDigestTable, _context)); }
internal ICorrelatedResSyncTableAdapter CreateCorrelatedResSyncTableAdapter(string resourceKind, IEndPointTableAdapter EndPointTableAdapter, IResourceKindTableAdapter resourceKindTableAdapter) { ResourceKindInfo resourceKindInfo = null; using (IJetTransaction jetTransaction = _connProvider.GetTransaction(false)) { resourceKindInfo = resourceKindTableAdapter.GetOrCreate(resourceKind, jetTransaction); jetTransaction.Commit(); } ICorrelatedResSyncTable correlatedResSyncTable = new CorrelatedResSyncTable(resourceKindInfo.Id, resourceKindTableAdapter.Table, EndPointTableAdapter.Table); using (IJetTransaction jetTransaction = _connProvider.GetTransaction(false)) { if (!JetHelpers.TableExists(correlatedResSyncTable.TableName, jetTransaction)) { correlatedResSyncTable.CreateTable(jetTransaction); jetTransaction.Commit(); } } return(new CorrelatedResSyncTableAdapter(correlatedResSyncTable, _context)); }