예제 #1
0
            private void configureUploadANSL()
            {
                var syncList = new ObjectSyncList();

                foreach (Type t in uploadTypes())
                {
                    syncList.Load(t, _mobileDB);
                }
                syncList.initialize(LookupSynchronizationInformation.getFieldDataList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields());
                var snsb = new SNSBPictureTransfer(_userNo, _projectID, _mobileDB, ApplicationPathManager.getFolderPath(ApplicationFolder.Pictures));

                _ansl = new AnalyzeSyncObjectList(syncList, _mobileDB, _repository, _sync, snsb);
            }
 private void configureUploadANSL()
 {
     var syncList = new ObjectSyncList();
     foreach (Type t in uploadTypes())
     {
         syncList.Load(t, _mobileDB);
     }
     syncList.initialize(LookupSynchronizationInformation.getFieldDataList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields());
     var snsb = new SNSBPictureTransfer(_userNo, _projectID, _mobileDB, ApplicationPathManager.getFolderPath(ApplicationFolder.Pictures));
     _ansl = new AnalyzeSyncObjectList(syncList, _mobileDB, _repository, _sync, snsb);
 }
            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();
            }
        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);
                    }
                }
            }
        }
예제 #5
0
        private void InsertButton_Click(object sender, EventArgs e)
        {
            ObjectSyncList syncList    = new ObjectSyncList();
            List <Type>    uploadTypes = new List <Type>();

            //uploadTypes.Add(typeof(Analysis));//ANalysen müssen aufgrund der referenzen gesondert behandelt werden.
            uploadTypes.Add(typeof(CollectionEventSeries));
            uploadTypes.Add(typeof(CollectionAgent));
            uploadTypes.Add(typeof(CollectionEvent));
            uploadTypes.Add(typeof(CollectionEventLocalisation));
            uploadTypes.Add(typeof(CollectionEventProperty));
            uploadTypes.Add(typeof(CollectionProject));
            uploadTypes.Add(typeof(CollectionSpecimen));
            uploadTypes.Add(typeof(Identification));
            uploadTypes.Add(typeof(IdentificationUnit));
            //uploadTypes.Add(typeof(IdentificationUnitAnalysis));
            //uploadTypes.Add(typeof(IdentificationUnitGeoAnalysis));
            //Bis hier: Korrepondiert zu DBVersion 31
            foreach (Type t in uploadTypes)
            {
                syncList.Load(t, mobileDBSerializer);
            }
            syncList.initialize(LookupSynchronizationInformation.getFieldDataList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields());
            AnalyzeSyncObjectList ansl = new AnalyzeSyncObjectList(syncList, mobileDBSerializer, repositorySerializer, syncDBSerializer);

            ansl.analyzeAll();
            //Alles außer InsertState auf ignore setzen
            List <ListContainer> conflicted;
            List <ListContainer> conflictResolved;
            List <ListContainer> synchronized;
            List <ListContainer> insert;
            List <ListContainer> update;
            List <ListContainer> ignore;
            List <ListContainer> delete;
            List <ListContainer> premature;

            conflicted       = ansl.getObjectsOfState(SyncStates_Enum.ConflictState);
            conflictResolved = ansl.getObjectsOfState(SyncStates_Enum.ConflictResolvedState);
            synchronized     = ansl.getObjectsOfState(SyncStates_Enum.SynchronizedState);
            insert           = ansl.getObjectsOfState(SyncStates_Enum.InsertState);
            update           = ansl.getObjectsOfState(SyncStates_Enum.UpdateState);
            ignore           = ansl.getObjectsOfState(SyncStates_Enum.IgnoreState);
            delete           = ansl.getObjectsOfState(SyncStates_Enum.DeletedState);
            premature        = ansl.getObjectsOfState(SyncStates_Enum.PrematureState);
            MessageBox.Show("Warning: Only InsertState is allowed at the moment. All other states will be set to IgnoreState");
            System.Threading.Thread.Sleep(1000);
            MessageBox.Show("Inserting");

            foreach (ListContainer lc in conflicted)
            {
                lc.State = SyncStates_Enum.IgnoreState;
            }
            foreach (ListContainer lc in conflictResolved)
            {
                lc.State = SyncStates_Enum.IgnoreState;
            }
            foreach (ListContainer lc in synchronized)
            {
                lc.State = SyncStates_Enum.IgnoreState;    //Exception throwen?
            }
            foreach (ListContainer lc in update)
            {
                lc.State = SyncStates_Enum.IgnoreState;
            }
            foreach (ListContainer lc in delete)
            {
                lc.State = SyncStates_Enum.IgnoreState;
            }
            foreach (ListContainer lc in premature)
            {
                lc.State = SyncStates_Enum.IgnoreState;    //Exception throwen?
            }
            ansl.synchronizeAll();
            MessageBox.Show("Finished");
        }
예제 #6
0
        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);
                    }
                }
            }
        }
예제 #7
0
        private void uploadFieldDataWorker(IReportDetailedProgress actor)
        {
            if (ConnectionsAccess.Instance.State.CheckForFlags(Diversity_Synchronization.ConnectionsAccess.ConnectionState.DatabasesConnected))
            {
                actor.IsProgressIndeterminate = true;
                actor.ProgressDescriptionID   = 1141;

                ObjectSyncList syncList    = new ObjectSyncList();
                List <Type>    uploadTypes = new List <Type>();
                uploadTypes.Add(typeof(CollectionAgent));
                uploadTypes.Add(typeof(CollectionEvent));
                uploadTypes.Add(typeof(CollectionEventImage));
                uploadTypes.Add(typeof(CollectionEventLocalisation));
                uploadTypes.Add(typeof(CollectionEventProperty));
                uploadTypes.Add(typeof(CollectionSpecimen));
                uploadTypes.Add(typeof(CollectionSpecimenImage));
                uploadTypes.Add(typeof(Identification));
                uploadTypes.Add(typeof(IdentificationUnit));
                uploadTypes.Add(typeof(IdentificationUnitAnalysis));
                uploadTypes.Add(typeof(IdentificationUnitGeoAnalysis));
                uploadTypes.Add(typeof(CollectionEventSeries));
                uploadTypes.Add(typeof(CollectionProject));
                //Bis hier: Korrepondiert zu DBVersion 31
                foreach (Type t in uploadTypes)
                {
                    syncList.Load(t, ConnectionsAccess.MobileDB);
                }

                syncList.initialize(LookupSynchronizationInformation.getFieldDataList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields());
                String userNumber = (ConnectionsAccess.Profile.AgentURI == null)?"":ConnectionsAccess.Profile.AgentURI.Replace(@"http://id.snsb.info/Agents/", "");
                if (userNumber == "")
                {
                    //TODO Empty User No
                }


                SNSBPictureTransfer snsb = new SNSBPictureTransfer(userNumber, (int)ConnectionsAccess.Profile.ProjectID, ConnectionsAccess.MobileDB, OptionsAccess.getFolderPath(ApplicationFolder.Pictures));

                AnalyzeSyncObjectList ansl = new AnalyzeSyncObjectList(syncList, ConnectionsAccess.MobileDB, ConnectionsAccess.RepositoryDB, ConnectionsAccess.Synchronization, snsb);
                ansl.analyzeAll();


                //Alles außer InsertState auf ignore setzen
                List <ListContainer> conflicted;
                List <ListContainer> conflictResolved;
                List <ListContainer> synchronized;
                List <ListContainer> insert;
                List <ListContainer> update;
                List <ListContainer> ignore;
                List <ListContainer> delete;
                List <ListContainer> premature;
                conflicted       = ansl.getObjectsOfState(SyncStates_Enum.ConflictState);
                conflictResolved = ansl.getObjectsOfState(SyncStates_Enum.ConflictResolvedState);
                synchronized     = ansl.getObjectsOfState(SyncStates_Enum.SynchronizedState);
                insert           = ansl.getObjectsOfState(SyncStates_Enum.InsertState);
                update           = ansl.getObjectsOfState(SyncStates_Enum.UpdateState);
                ignore           = ansl.getObjectsOfState(SyncStates_Enum.IgnoreState);
                delete           = ansl.getObjectsOfState(SyncStates_Enum.DeletedState);
                premature        = ansl.getObjectsOfState(SyncStates_Enum.PrematureState);
                //ProgressDescription = "Warning: Only InsertState is allowed at the moment. All other states will be set to IgnoreState";
                System.Threading.Thread.Sleep(1000);

                foreach (ListContainer lc in conflicted)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in conflictResolved)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in synchronized)
                {
                    lc.State = SyncStates_Enum.IgnoreState;//Exception throwen?
                }
                foreach (ListContainer lc in update)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in delete)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in premature)
                {
                    lc.State = SyncStates_Enum.IgnoreState;//Exception throwen?
                }
                ansl.synchronizeAll();

                SyncStatus.Instance.Sync |= SyncStatus.SyncState.FieldDataUpload;
            }
        }
        private void uploadFieldDataWorker(IReportDetailedProgress actor)
        {
            if (ConnectionsAccess.Instance.State.CheckForFlags(Diversity_Synchronization.ConnectionsAccess.ConnectionState.DatabasesConnected))
            {
                actor.IsProgressIndeterminate = true;
                actor.ProgressDescriptionID = 1141;

                ObjectSyncList syncList = new ObjectSyncList();
                List<Type> uploadTypes = new List<Type>();
                uploadTypes.Add(typeof(CollectionAgent));
                uploadTypes.Add(typeof(CollectionEvent));
                uploadTypes.Add(typeof(CollectionEventImage));
                uploadTypes.Add(typeof(CollectionEventLocalisation));
                uploadTypes.Add(typeof(CollectionEventProperty));
                uploadTypes.Add(typeof(CollectionSpecimen));
                uploadTypes.Add(typeof(CollectionSpecimenImage));
                uploadTypes.Add(typeof(Identification));
                uploadTypes.Add(typeof(IdentificationUnit));
                uploadTypes.Add(typeof(IdentificationUnitAnalysis));
                uploadTypes.Add(typeof(IdentificationUnitGeoAnalysis));
                uploadTypes.Add(typeof(CollectionEventSeries));
                uploadTypes.Add(typeof(CollectionProject));
                //Bis hier: Korrepondiert zu DBVersion 31
                foreach (Type t in uploadTypes)
                {
                    syncList.Load(t, ConnectionsAccess.MobileDB);
                }

                syncList.initialize(LookupSynchronizationInformation.getFieldDataList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields());
                String userNumber =(ConnectionsAccess.Profile.AgentURI==null)?"":ConnectionsAccess.Profile.AgentURI.Replace(@"http://id.snsb.info/Agents/", "");
                if (userNumber == "")
                {
                    //TODO Empty User No
                }

                SNSBPictureTransfer snsb = new SNSBPictureTransfer(userNumber,(int) ConnectionsAccess.Profile.ProjectID, ConnectionsAccess.MobileDB,OptionsAccess.getFolderPath(ApplicationFolder.Pictures));

                AnalyzeSyncObjectList ansl = new AnalyzeSyncObjectList(syncList, ConnectionsAccess.MobileDB, ConnectionsAccess.RepositoryDB, ConnectionsAccess.Synchronization,snsb);
                ansl.analyzeAll();

                //Alles außer InsertState auf ignore setzen
                List<ListContainer> conflicted;
                List<ListContainer> conflictResolved;
                List<ListContainer> synchronized;
                List<ListContainer> insert;
                List<ListContainer> update;
                List<ListContainer> ignore;
                List<ListContainer> delete;
                List<ListContainer> premature;
                conflicted = ansl.getObjectsOfState(SyncStates_Enum.ConflictState);
                conflictResolved = ansl.getObjectsOfState(SyncStates_Enum.ConflictResolvedState);
                synchronized = ansl.getObjectsOfState(SyncStates_Enum.SynchronizedState);
                insert = ansl.getObjectsOfState(SyncStates_Enum.InsertState);
                update = ansl.getObjectsOfState(SyncStates_Enum.UpdateState);
                ignore = ansl.getObjectsOfState(SyncStates_Enum.IgnoreState);
                delete = ansl.getObjectsOfState(SyncStates_Enum.DeletedState);
                premature = ansl.getObjectsOfState(SyncStates_Enum.PrematureState);
                //ProgressDescription = "Warning: Only InsertState is allowed at the moment. All other states will be set to IgnoreState";
                System.Threading.Thread.Sleep(1000);

                foreach (ListContainer lc in conflicted)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in conflictResolved)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in synchronized)
                {
                    lc.State = SyncStates_Enum.IgnoreState;//Exception throwen?
                }
                foreach (ListContainer lc in update)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in delete)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in premature)
                {
                    lc.State = SyncStates_Enum.IgnoreState;//Exception throwen?
                }
                ansl.synchronizeAll();

                SyncStatus.Instance.Sync |= SyncStatus.SyncState.FieldDataUpload;
            }
        }
        private void InsertButton_Click(object sender, EventArgs e)
        {
            ObjectSyncList syncList = new ObjectSyncList();
                List<Type> uploadTypes = new List<Type>();
                //uploadTypes.Add(typeof(Analysis));//ANalysen müssen aufgrund der referenzen gesondert behandelt werden.
                uploadTypes.Add(typeof(CollectionEventSeries));
                uploadTypes.Add(typeof(CollectionAgent));
                uploadTypes.Add(typeof(CollectionEvent));
                uploadTypes.Add(typeof(CollectionEventLocalisation));
                uploadTypes.Add(typeof(CollectionEventProperty));
                uploadTypes.Add(typeof(CollectionProject));
                uploadTypes.Add(typeof(CollectionSpecimen));
                uploadTypes.Add(typeof(Identification));
                uploadTypes.Add(typeof(IdentificationUnit));
                //uploadTypes.Add(typeof(IdentificationUnitAnalysis));
                //uploadTypes.Add(typeof(IdentificationUnitGeoAnalysis));
                //Bis hier: Korrepondiert zu DBVersion 31
                foreach (Type t in uploadTypes)
                {
                    syncList.Load(t, mobileDBSerializer);
                }
                syncList.initialize(LookupSynchronizationInformation.getFieldDataList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields());
                AnalyzeSyncObjectList ansl = new AnalyzeSyncObjectList(syncList, mobileDBSerializer, repositorySerializer, syncDBSerializer);
                ansl.analyzeAll();
                //Alles außer InsertState auf ignore setzen
                List<ListContainer> conflicted;
                List<ListContainer> conflictResolved;
                List<ListContainer> synchronized;
                List<ListContainer> insert;
                List<ListContainer> update;
                List<ListContainer> ignore;
                List<ListContainer> delete;
                List<ListContainer> premature;
                conflicted = ansl.getObjectsOfState(SyncStates_Enum.ConflictState);
                conflictResolved = ansl.getObjectsOfState(SyncStates_Enum.ConflictResolvedState);
                synchronized = ansl.getObjectsOfState(SyncStates_Enum.SynchronizedState);
                insert = ansl.getObjectsOfState(SyncStates_Enum.InsertState);
                update = ansl.getObjectsOfState(SyncStates_Enum.UpdateState);
                ignore = ansl.getObjectsOfState(SyncStates_Enum.IgnoreState);
                delete = ansl.getObjectsOfState(SyncStates_Enum.DeletedState);
                premature = ansl.getObjectsOfState(SyncStates_Enum.PrematureState);
                MessageBox.Show("Warning: Only InsertState is allowed at the moment. All other states will be set to IgnoreState");
                System.Threading.Thread.Sleep(1000);
                MessageBox.Show("Inserting");

                foreach (ListContainer lc in conflicted)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in conflictResolved)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in synchronized)
                {
                    lc.State = SyncStates_Enum.IgnoreState;//Exception throwen?
                }
                foreach (ListContainer lc in update)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in delete)
                {
                    lc.State = SyncStates_Enum.IgnoreState;
                }
                foreach (ListContainer lc in premature)
                {
                    lc.State = SyncStates_Enum.IgnoreState;//Exception throwen?
                }
                ansl.synchronizeAll();
                MessageBox.Show("Finished");
        }
예제 #10
0
        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;
                }
            }
        }
            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();
            }