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 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 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 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 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; 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 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); }
public CachedEndpointTableAdapter(IEndpointTableAdapter endpointTableAdapter) { _tableAdapter = endpointTableAdapter; }
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)); }
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); }