private void getDefinitionsListSynchronization() { if (this.startMobileConnection(true)) { this.setProgressInformation("Create Mobile Connection"); ObjectSyncList syncList = new ObjectSyncList(); this.setProgressValue(10); this.setProgressInformation("Read Definitions from Database"); //String sql = @"SELECT * FROM [DiversityCollection_Monitoring].[dbo].[AnalysisProjectList] (372)"; String sql = @"SELECT * FROM [" + this.InitialCatalog + "].[dbo].[AnalysisProjectList] (" + this.projectID + ")"; IList<ISerializableObject> list = repositorySerializer.Connector.LoadList(typeof(Analysis), sql); syncList.addList(list); //sql = @"SELECT AnalysisID,TaxonomicGroup FROM [DiversityCollection_Monitoring].[dbo].[AnalysisTaxonomicGroupForProject] (372)"; sql = @"SELECT AnalysisID,TaxonomicGroup,RowGUID FROM [" + this.InitialCatalog + "].[dbo].[AnalysisTaxonomicGroupForProject] (" + this.projectID + ")"; IList<AnalysisTaxonomicGroup> atgList = new List<AnalysisTaxonomicGroup>(); DbConnection connRepository = this.repositorySerializer.CreateConnection(); connRepository.Open(); DbCommand com = connRepository.CreateCommand(); com.CommandText = sql; DbDataReader reader = null; try { reader = com.ExecuteReader(); while (reader.Read()) { AnalysisTaxonomicGroup atg = new AnalysisTaxonomicGroup(); atg.AnalysisID = reader.GetInt32(0); atg.TaxonomicGroup = reader.GetString(1); atg.Rowguid = reader.GetGuid(2); atgList.Add(atg); } connRepository.Close(); } catch (Exception e) { this.setProgressInformation("Exception while updating AnalysisTaxonomicGroups"); connRepository.Close(); } foreach (AnalysisTaxonomicGroup atg in atgList) { foreach (ISerializableObject iso in list) { bool idFound = false; if (iso.GetType().Equals(typeof(Analysis))) { Analysis ana = (Analysis)iso; if (ana.AnalysisID == atg.AnalysisID) { idFound = true; } } if (idFound == true) { syncList.addObject(atg); break; } } } foreach (AnalysisTaxonomicGroup atg in atgList) { foreach (ISerializableObject iso in list) { bool idFound = false; if (iso.GetType().Equals(typeof(Analysis))) { Analysis ana = (Analysis)iso; if (ana.AnalysisID == atg.AnalysisID) { idFound = true; } } if (idFound == true) { syncList.addObject(atg); break; } } } this.setProgressValue(20); syncList.Load(typeof(Property), repositorySerializer); syncList.Load(typeof(CollEventImageType_Enum), repositorySerializer); syncList.Load(typeof(CollSpecimenImageType_Enum), repositorySerializer); syncList.Load(typeof(CollTaxonomicGroup_Enum), repositorySerializer); syncList.Load(typeof(LocalisationSystem), repositorySerializer); syncList.Load(typeof(CollCircumstances_Enum), repositorySerializer);// syncList.Load(typeof(CollUnitRelationType_Enum), repositorySerializer); //poolBuilder.Load(typeof(CollEventSeriesImageType_Enum)); syncList.Load(typeof(CollIdentificationCategory_Enum), repositorySerializer); //poolBuilder.Load(typeof(CollTypeStatus_Enum)); //__poolBuilder.Load(typeof(CollIdentificationQualifier_Enum)); //poolBuilder.Load(typeof(CollLabelTranscriptionState_Enum)); //poolBuilder.Load(typeof(CollLabelType_Enum)); //poolBuilder.Load(typeof(CollMaterialCategory_Enum)); syncList.initialize(LookupSynchronizationInformation.downloadDefinitionsList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields()); AnalyzeSyncObjectList anal = new AnalyzeSyncObjectList(syncList, repositorySerializer, mobileDBSerializer, syncDBSerializer); anal.analyzeAll(); //Im Moment ist noch kein ConflictHandling möglich (und auch nicht nötig) this.setProgressInformation("Synchronizing"); this.setProgressValue(50); //Für debugging IRestriction rs = RestrictionFactory.TypeRestriction(typeof(SyncItem)); IList<ISerializableObject> sync = syncDBSerializer.Connector.LoadList(typeof(SyncItem), rs); this.setProgressInformation("Synchronized: " + sync.Count.ToString()); anal.synchronizeAll(); this.setProgressInformation("Synchronization Complete"); this.setProgressValue(100); if (this.endMobileConnection(true)) { this.buttonGetDefinitions.Enabled = false; } } }
private void loadCollectionDefinitionsWorker(IReportDetailedProgress progress) { ObjectSyncList transferList = new ObjectSyncList(); progress.advanceProgress(5); String sql = null; IList<ISerializableObject> list = null; progress.ProgressDescriptionID = 1160; try { sql = @"SELECT * FROM [" + OptionsAccess.RepositoryOptions.InitialCatalog + "].[dbo].[AnalysisProjectList] (" + ConnectionsAccess.Profile.ProjectID + ")"; list = ConnectionsAccess.RepositoryDB.Connector.LoadList(typeof(Analysis), sql); transferList.addList(list); foreach (ISerializableObject iso in list) { Analysis ana = (Analysis)iso; IRestriction rana = RestrictionFactory.Eq(typeof(AnalysisResult), "_AnalysisID", ana.AnalysisID); IList<ISerializableObject> resultList = ConnectionsAccess.RepositoryDB.Connector.LoadList(typeof(AnalysisResult), rana); transferList.addList(resultList); } } catch (Exception e) { MessageBox.Show(e.Message); _Log.ErrorFormat("Exception while updating AnalysisTaxonomicGroups: {0}", e); ; } sql = @"SELECT AnalysisID,TaxonomicGroup,RowGUID FROM [" + OptionsAccess.RepositoryOptions.InitialCatalog + "].[dbo].[AnalysisTaxonomicGroupForProject] (" + ConnectionsAccess.Profile.ProjectID + ")"; IList<AnalysisTaxonomicGroup> atgList = new List<AnalysisTaxonomicGroup>(); IDbConnection connRepository = ConnectionsAccess.RepositoryDB.CreateConnection(); connRepository.Open(); IDbCommand com = connRepository.CreateCommand(); com.CommandText = sql; IDataReader reader = null; try { reader = com.ExecuteReader(); while (reader.Read()) { AnalysisTaxonomicGroup atg = new AnalysisTaxonomicGroup(); atg.AnalysisID = reader.GetInt32(0); atg.TaxonomicGroup = reader.GetString(1); atg.Rowguid = Guid.NewGuid(); atgList.Add(atg); } connRepository.Close(); } catch (Exception e) { MessageBox.Show(e.Message); _Log.ErrorFormat("Exception while updating AnalysisTaxonomicGroups: {0}", e); ; connRepository.Close(); } foreach (AnalysisTaxonomicGroup atg in atgList) { foreach (ISerializableObject iso in list) { if (iso.GetType().Equals(typeof(Analysis))) { Analysis ana = (Analysis)iso; if (ana.AnalysisID == atg.AnalysisID) { transferList.addObject(atg); } } } } double progressPerType = 90d / _defTypes.Count; foreach (Type t in _defTypes) { transferList.Load(t, ConnectionsAccess.RepositoryDB); progress.advanceProgress(progressPerType); } transferList.initialize(LookupSynchronizationInformation.downloadDefinitionsList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields()); List<ISerializableObject> orderedObjects = transferList.orderedObjects; progress.ProgressDescriptionID = 1161; foreach (ISerializableObject iso in orderedObjects) { try { ConnectionsAccess.MobileDB.Connector.InsertPlain(iso); } catch (Exception) { try { if (iso.GetType().Equals(typeof(AnalysisTaxonomicGroup))) { AnalysisTaxonomicGroup atg = (AnalysisTaxonomicGroup)iso; IRestriction r1 = RestrictionFactory.Eq(iso.GetType(), "_AnalysisID", atg.AnalysisID); IRestriction r2 = RestrictionFactory.Eq(iso.GetType(), "_TaxonomicGroup", atg.TaxonomicGroup); IRestriction r = RestrictionFactory.And().Add(r1).Add(r2); ISerializableObject isoStored = ConnectionsAccess.MobileDB.Connector.Load(iso.GetType(), r); atg.Rowguid = isoStored.Rowguid; } else { IRestriction r = RestrictionFactory.Eq(iso.GetType(), "_guid", iso.Rowguid); ISerializableObject isoStored = ConnectionsAccess.MobileDB.Connector.Load(iso.GetType(), r); } ConnectionsAccess.MobileDB.Connector.UpdatePlain(iso); } catch (Exception ex) { _Log.ErrorFormat("Exception while transferring [{0}]: [{1}]",iso,ex); } } } }
public void loadCollectionDefinitions(AsyncOperationInstance progress) { progress.StatusDescription = "Services_Definitions_LoadingCollectionDefinitions"; var uOptions = _owner.Settings.getOptions(); //TODO var connectionProfile = uOptions.CurrentConnection; //TODO var projectID = _owner.Profiles.ProjectID; var repSerializer = _owner.Connections.Repository; var mobSerializer = _owner.Connections.MobileDB; ObjectSyncList transferList = new ObjectSyncList(); String sql = @"SELECT * FROM [" + connectionProfile.InitialCatalog + "].[dbo].[AnalysisProjectList] (" + projectID + ")"; IList<ISerializableObject> list = repSerializer.Connector.LoadList(typeof(Analysis), sql); transferList.addList(list); foreach (ISerializableObject iso in list) { Analysis ana = (Analysis)iso; IRestriction rana = RestrictionFactory.Eq(typeof(AnalysisResult), "_AnalysisID", ana.AnalysisID); IList<ISerializableObject> resultList = repSerializer.Connector.LoadList(typeof(AnalysisResult), rana); transferList.addList(resultList); } sql = @"SELECT AnalysisID,TaxonomicGroup,RowGUID FROM [" + connectionProfile.InitialCatalog + "].[dbo].[AnalysisTaxonomicGroupForProject] (" + projectID + ")"; IList<AnalysisTaxonomicGroup> atgList = new List<AnalysisTaxonomicGroup>(); IDbConnection connRepository = repSerializer.CreateConnection(); connRepository.Open(); IDbCommand com = connRepository.CreateCommand(); com.CommandText = sql; IDataReader reader = null; try { reader = com.ExecuteReader(); while (reader.Read()) { AnalysisTaxonomicGroup atg = new AnalysisTaxonomicGroup(); atg.AnalysisID = reader.GetInt32(0); atg.TaxonomicGroup = reader.GetString(1); atg.Rowguid = Guid.NewGuid(); atgList.Add(atg); } connRepository.Close(); } catch (Exception e) { connRepository.Close(); _Log.ErrorFormat("Error loading Collection Definitions: [{0}]", e); progress.failure("Services_Definitions_Error_MissingRights",""); } foreach (AnalysisTaxonomicGroup atg in atgList) { foreach (ISerializableObject iso in list) { if (iso.GetType().Equals(typeof(Analysis))) { Analysis ana = (Analysis)iso; if (ana.AnalysisID == atg.AnalysisID) { transferList.addObject(atg); } } } } float progressPerType = 100f / _defTypes.Count; progress.IsProgressIndeterminate = false; foreach (Type t in _defTypes) { repSerializer.Progress = new ProgressInterval(progress, progressPerType, 1); transferList.Load(t, repSerializer); } transferList.initialize(LookupSynchronizationInformation.downloadDefinitionsList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields()); List<ISerializableObject> orderedObjects = transferList.orderedObjects; foreach (ISerializableObject iso in orderedObjects) { try { mobSerializer.Connector.InsertPlain(iso); } catch (Exception) { try { if (iso.GetType().Equals(typeof(AnalysisTaxonomicGroup))) { AnalysisTaxonomicGroup atg = (AnalysisTaxonomicGroup)iso; IRestriction r1 = RestrictionFactory.Eq(iso.GetType(), "_AnalysisID", atg.AnalysisID); IRestriction r2 = RestrictionFactory.Eq(iso.GetType(), "_TaxonomicGroup", atg.TaxonomicGroup); IRestriction r = RestrictionFactory.And().Add(r1).Add(r2); ISerializableObject isoStored = mobSerializer.Connector.Load(iso.GetType(), r); atg.Rowguid = isoStored.Rowguid; } else { IRestriction r = RestrictionFactory.Eq(iso.GetType(), "_guid", iso.Rowguid); ISerializableObject isoStored = mobSerializer.Connector.Load(iso.GetType(), r); } mobSerializer.Connector.UpdatePlain(iso); } catch (Exception ex) { _Log.ErrorFormat("Exception while transferring [{0}]: [{1}]", iso, ex); } } } progress.success(); }