private void SetSynced(SyncJn sync, DatabaseType type) { if (type.Equals(DatabaseType.LOCAL)) { SynchronisationDatabaseEntities5 db = new SynchronisationDatabaseEntities5(); try { Sync_jn localSyncEntry = (from syncJn in db.Sync_jn where syncJn.jn_id.Equals(sync.JnId.Value) select syncJn).Single <Sync_jn>(); db.Sync_jn.Remove(localSyncEntry); db.SaveChanges(); } catch (Exception e) { string message = "Error updating local database: " + e.Message; Logger.Error(message); AddErrorLog(message); } return; } Logger.Info("Setting Entry with ID " + sync.JnId + " synced in " + type); DatabaseClientFactory.GetClient(type).ExecuteQuery("update sync_jn set jn_synced = " + 1 + " where jn_id = " + sync.JnId, null); }
private void SyncEntry(SyncJn sync, Table obj, List <ColumnProperty> updateColumnProperties, DatabaseType from, DatabaseType to) { switch (sync.JnOperation) { case "INSERT": try { DataRow row; if (obj.GetType().Equals(typeof(HauspaketAttributZuord))) { row = GetSingleDataRowForMultiPk(sync.JnChangesetJson, sync.JnTable, "hauspaket_id", "wert_id", from); } else { row = GetSingleDataRow(sync.JnPk, sync.JnTable, obj.GetPrimaryKeyColumn(), from); } DatabaseClientFactory.GetClient(to).ExecuteQuery(obj.GetInsertString(row, to), null); } catch (Exception e) { string message = "Error inserting " + obj.GetTableName() + " from " + from + ": " + e.Message + " on JN ID: " + sync.JnId; Logger.Error(message); AddErrorLog(message); } break; case "UPDATE": try { DataRow row; if (obj.GetType().Equals(typeof(HauspaketAttributZuord))) { row = GetSingleDataRowForMultiPk(sync.JnChangesetJson, sync.JnTable, "hauspaket_id", "wert_id", from); } else { row = GetSingleDataRow(sync.JnPk, sync.JnTable, obj.GetPrimaryKeyColumn(), from); } string query = obj.GetUpdateString(); ColumnProperty last = updateColumnProperties.Last(); foreach (ColumnProperty columnProperty in updateColumnProperties) { query = Table.AddUpdateParam(query, columnProperty.ColumnName, row[columnProperty.index], to, columnProperty.dataType, columnProperty.Equals(last)); } if (obj.GetType().Equals(typeof(HauspaketAttributZuord))) { string[] parts = sync.JnChangesetJson.Split(';'); Nullable <int> pk1 = new Nullable <int>(Int32.Parse(parts[2])); Nullable <int> pk2 = new Nullable <int>(Int32.Parse(parts[3])); query = query + " where hauspaket_id = " + pk1.Value + " and wert_id = " + pk2; } else { query = query + " where " + obj.GetWherePk(sync.JnPk.Value); } DatabaseClientFactory.GetClient(to).ExecuteQuery(query, null); } catch (Exception e) { string message = "Error updating " + obj.GetTableName() + " from " + from + ": " + e.Message + " on JN ID: " + sync.JnId; Logger.Error(message); AddErrorLog(message); } break; case "DELETE": try { if (obj.GetType().Equals(typeof(HauspaketAttributZuord))) { string[] parts = sync.JnChangesetJson.Split(';'); Nullable <int> pk1 = new Nullable <int>(Int32.Parse(parts[0])); Nullable <int> pk2 = new Nullable <int>(Int32.Parse(parts[1])); DatabaseClientFactory.GetClient(to).ExecuteQuery("delete from hauspaket_attribut_zuord where hauspaket_id = " + pk1 + " and wert_id = " + pk2, null); } else { DatabaseClientFactory.GetClient(to).ExecuteQuery(obj.getDeleteString(sync.JnPk.Value), null); } } catch (Exception e) { string message = "Error deleting " + obj.GetTableName() + " from " + from + ": " + e.Message + " on JN ID: " + sync.JnId; Logger.Error(message); AddErrorLog(message); } break; } SetSynced(sync, from); }