Beispiel #1
0
        private void copyPictures(ActiveSyncOptions aso)
        {
            string mobilePictureDirectory = Path.GetDirectoryName(aso.DiversityMobileDBPath) + "\\pictures";

            if (Directory.Exists(mobilePictureDirectory))
            {
                foreach (var picture in Directory.GetFiles(mobilePictureDirectory))
                {
                    copyFromDevice(OptionsAccess.getFolderPath(ApplicationFolder.Pictures) + "\\" + Path.GetFileName(picture), picture, aso.UseDevice);
                }
            }
        }
Beispiel #2
0
        public void connectToMobileDB(ActiveSyncOptions aso)
        {
            try
            {
                copyPictures(aso);
            }
            catch (Exception ex)
            {
                _Log.ErrorFormat("Picture Copy Error: {0}", ex.Message != null ? ex.Message : "");
            }

            //Lokale Kopie der Datenbanken anlegen
            localDivDBPath = OptionsAccess.getFolderPath(ApplicationFolder.CurrentTransaction) + "\\" + Path.GetFileName(aso.DiversityMobileDBPath);
            localTaxDBPath = OptionsAccess.getFolderPath(ApplicationFolder.CurrentTransaction) + "\\" + Path.GetFileName(aso.TaxonNamesDBPath);
            bool divCopySuccess = false;
            bool taxCopySuccess = false;

            try
            {
                divCopySuccess = copyFromDevice(localDivDBPath, aso.DiversityMobileDBPath, aso.UseDevice);
                if (divCopySuccess == false)
                {
                    throw new Exception();
                }
            }
            catch (Exception divEx)
            {
                _Log.ErrorFormat("Copy Failure MobileDB: {0}", divEx.Message != null ? divEx.Message : "");
            }
            try
            {
                taxCopySuccess = copyFromDevice(localTaxDBPath, aso.TaxonNamesDBPath, aso.UseDevice);
                if (taxCopySuccess == false)
                {
                    throw new Exception();
                }
            }
            catch (Exception taxEx)
            {
                _Log.ErrorFormat("Copy Failure TaxonNames: {0}", taxEx.Message != null ? taxEx.Message : "");
            }

            if (divCopySuccess && taxCopySuccess)
            {
                _Log.Info("Database working copy created.");
                connectMobile();
            }
        }
Beispiel #3
0
        private bool copyEmptyDBs()
        {
            bool   successSoFar = true;
            string dbDir        = OptionsAccess.getFolderPath(ApplicationFolder.EmptyDatabases);
            string emptyMobile  = dbDir + "\\" + defaultMobileDB;
            string emptyTaxa    = dbDir + "\\" + defaultTaxonDB;

            string currentTransactionDir = OptionsAccess.getFolderPath(ApplicationFolder.CurrentTransaction);

            localDivDBPath = currentTransactionDir + "\\clean_" + defaultMobileDB;
            localTaxDBPath = currentTransactionDir + "\\clean_" + defaultTaxonDB;

            if (!File.Exists(emptyMobile))
            {
                _Log.Error("Empty Mobile DB missing!");
                successSoFar = false;
            }

            if (!File.Exists(emptyTaxa))
            {
                _Log.Error("Empty Taxon DB missing!");
                successSoFar = false;
            }

            if (successSoFar)
            {
                try
                {
                    File.Copy(emptyTaxa, localTaxDBPath, true);
                    File.Copy(emptyMobile, localDivDBPath, true);
                }
                catch (IOException io)
                {
                    _Log.ErrorFormat("Error while copying empty databases: {0}", io);
                    successSoFar = false;
                }
            }
            return(successSoFar);
        }
Beispiel #4
0
        public void writeBackChanges()
        {
            if (SyncStatus.Instance.isDirty())
            {
                _Log.Info("Writing back changes");
                copyToDevice(localDivDBPath, OptionsAccess.ActiveSyncOptions.DiversityMobileDBPath, OptionsAccess.ActiveSyncOptions.UseDevice);
                copyToDevice(localTaxDBPath, OptionsAccess.ActiveSyncOptions.TaxonNamesDBPath, OptionsAccess.ActiveSyncOptions.UseDevice);

                string mobileMapsPath = Path.GetDirectoryName(OptionsAccess.ActiveSyncOptions.DiversityMobileDBPath) + "\\maps";
                string localMapsPath  = OptionsAccess.getFolderPath(ApplicationFolder.Maps);
                if (!Directory.Exists(mobileMapsPath))
                {
                    Directory.CreateDirectory(mobileMapsPath);
                }
                if (Directory.Exists(localMapsPath) && Directory.Exists(mobileMapsPath))
                {
                    bool useAS = OptionsAccess.ActiveSyncOptions.UseDevice;
                    foreach (var file in Directory.GetFiles(localMapsPath, "*.png"))
                    {
                        var xmlFile  = file.Replace(".png", ".xml");
                        var pngLPath = file;
                        var pngMPath = file.Replace(localMapsPath, mobileMapsPath);
                        var xmlLPath = xmlFile;
                        var xmlMPath = xmlFile.Replace(localMapsPath, mobileMapsPath);
                        if (File.Exists(xmlLPath))
                        {
                            copyToDevice(pngLPath, pngMPath, useAS);
                            copyToDevice(xmlLPath, xmlMPath, useAS);
                        }
                    }
                }
            }
            else
            {
                _Log.Info("Not writing back changes: unchanged.");
            }
        }
Beispiel #5
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;
            }
        }