public override Serializer CreateSyncSerializer()
 {
     Serializer s = new MS_SqlCeSerializer(_DbPath);
     s.RegisterType(typeof(SyncItem));
     s.RegisterType(typeof(FieldState));
     s.Activate();
     return s;
 }
 // Stellt eine Verbindung zu einer im Pfad gebenen DB her und Registriert die Typen. Kommt eine Verbindung zu Stande wird True zurückgegeben
 private bool connectDB(String conString,ref Serializer ser, IList<Type> types)
 {
     if (conString == null)
     {
         MessageBox.Show("Select a DB First!", "No DB Selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return false;
     }
     if (File.Exists(@conString) == false)
     {
         MessageBox.Show("File Not Found! Please reselected the DB!", "No DB Selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return false;
     }
     ser = new MS_SqlCeSerializer(conString);
     ser.RegisterTypes(types);
     ser.Activate();
     return true;
 }
        public void connectToMobileDB(DBPaths paths)
        {
            int i = 0;
            try
            {
                MobileDB = new MS_SqlCeSerializer(paths.MobileDB);
                i++;//1
                MobileDB.RegisterTypes(divMobiTypes());
                i++;
                MobileDB.RegisterType(typeof(UserProfile));
                i++;
                MobileDB.Activate();
                i++;

                //mobile Tax Serializer erzeugen
                try
                {
                    MobileTaxa = new MS_SqlCeSerializer(paths.MobileTaxa);

                    i++;
                    MobileTaxa.RegisterType(typeof(TaxonNames));
                    MobileTaxa.RegisterType(typeof(PropertyNames));
                    i++;//9
                }
                catch
                {
                    MobileTaxa = null;
                }
            }
            catch (Exception mobileDBEx)
            {
                _Log.ErrorFormat("ConnectionError {0} {1}", i, mobileDBEx.Message != null ? mobileDBEx.Message : "");
                MobileDB = null;
            }
            finally
            {
                i = 0;
                if (MobileDB != null)
                {
                    State |= ConnectionState.ConnectedToMobile;
                    i = 10;
                }
                else
                {
                    State &= ~ConnectionState.ConnectedToMobile;
                    i = 20;
                }
                if (MobileTaxa != null)
                {
                    State |= ConnectionState.ConnectedToMobileTax;
                    i = i + 100;
                }
                else
                {
                    State &= ~ConnectionState.ConnectedToMobileTax;
                    i = i + 200;
                }
                if (i != 110)
                    _Log.ErrorFormat("Final Result: {0}", i);
            }
        }
        private void connectMobile()
        {
            int i = 0;
            try
            {
                MobileDB = new MS_SqlCeSerializer(localDivDBPath);
                i++;//1
                MobileDB.RegisterTypes(divMobiTypes);
                i++;
                MobileDB.RegisterType(typeof(UserProfile));
                i++;
                MobileDB.Activate();
                i++;
                //Prüfen ob ein UserProfile zum LoginNamen existiert.
                IList<UserProfile> profiles = new List<UserProfile>();
                i++;//5
                IRestriction r = RestrictionFactory.Eq(typeof(UserProfile), "_LoginName", OptionsAccess.RepositoryOptions.LastUsername);
                //IRestriction r = RestrictionFactory.Eq(typeof(UserProfile), "_LoginName", "TestEditor");
                profiles = MobileDB.Connector.LoadList<UserProfile>(r);
                i++;
                if (profiles.Count > 0)
                {
                    Profile = profiles[0];
                }
                else
                {
                    Profile = createProfile();
                }

                i++;//7

                //mobile Tax Serializer erzeugen
                try
                {
                    MobileTaxa = new MS_SqlCeSerializer(localTaxDBPath);
                    i++;
                    MobileTaxa.RegisterType(typeof(TaxonNames));
                    MobileTaxa.RegisterType(typeof(PropertyNames));
                    i++;//9
                }
                catch
                {
                    MobileTaxa = null;
                }
            }
            catch (Exception mobileDBEx)
            {
                _Log.ErrorFormat("ConnectionError {0} {1}", i, mobileDBEx.Message != null ? mobileDBEx.Message : "");
                MobileDB = null;
                Profile = null;
            }
            finally
            {
                i = 0;
                if (Profile != null)
                {
                    State |= ConnectionState.ProfilePresent;
                    State |= ConnectionState.ConnectedToMobile;
                    i = 10;
                }
                else
                {
                    State &= ~ConnectionState.ProfilePresent;
                    State &= ~ConnectionState.ConnectedToMobile;
                    i = 20;
                }
                if (MobileTaxa != null)
                {
                    State |= ConnectionState.ConnectedToMobileTax;
                    i = i + 100;
                }
                else
                {
                    State &= ~ConnectionState.ConnectedToMobileTax;
                    i = i + 200;
                }
                if (i != 110)
                    _Log.ErrorFormat("Final Result: {0}",i);
            }
        }
        private void buttonGetTaxa_Click(object sender, EventArgs e)
        {
            // Start Thread for ProgressInformation
            this.startProgressThread();
            this.setProgressValue(0);
            this.setActionInformation("Copy Mobile Database for Taxon- and PropertyNames to work directory");
            //if (activesync == true)
            //    //rapi.CopyFileFromDevice(taxPath, mobileTaxonPath, true);
            //else
            //{
                if (System.IO.File.Exists(mobileTaxonPath))
                    System.IO.File.Copy(mobileTaxonPath, taxPath, true);
                else
                {
                    FileDialog taxDialog = new OpenFileDialog();
                    taxDialog.Filter = "sdf files (*.sdf)|*.sdf"; //Im Moment wird nur das DB-Format von DiversityMobile unterstützt
                    if (taxDialog.ShowDialog() == DialogResult.OK)
                    {
                        mobileTaxonPath = taxDialog.FileName;
                        System.IO.File.Copy(mobileTaxonPath, taxPath, true);
                    }
                    else
                    {
                        this.endProgressThread(true);
                        return;
                    }
                }
            //}
            this.setProgressValue(100);
            this.setProgressInformation("Finished");

            // save current settings to XML
            try
            {
                this.writeSettingsToXML();
            }
            catch (Exception)
            {
                MessageBox.Show("XML-Write Error2!");
            }
            //Damit liegt die TaxonDatenBank im Arbeitsverzeichnis
            //Serializer erstellen
            Serializer taxonMobSerializer = new MS_SqlCeSerializer(taxPath);
            taxonMobSerializer.RegisterType(typeof(TaxonNames));
            taxonMobSerializer.RegisterType(typeof(PropertyNames));
            Serializer taxonRepSerializer = new MS_SqlServerIPSerializer(loginName, password, this.IPAddress, this.IPPort, this.TaxonNamesInitialCatalog,null);//AKtuell Datenbank mit den Definitionen
            taxonRepSerializer.RegisterType(typeof(TaxonNames));
            taxonRepSerializer.RegisterType(typeof(PropertyNames));
            DbConnection repConn = taxonRepSerializer.CreateConnection();
            SqlCeConnection mobConn = (SqlCeConnection)taxonMobSerializer.CreateConnection();
            int i;
            String[] sourceTablesFungi = { "TaxRef_LIAS_Erys_DE" };
            i = updateTaxa(sourceTablesFungi, "TaxonNamesFungi", repConn, mobConn);
            if (i > 0)
            {
                this.setProgressInformation("Fungi: " + i + " Taxa");
            }
            else
            {
                this.setProgressInformation("Fungi: no Taxa");
                System.Threading.Thread.Sleep(1000);
            }
            //MessageBox.Show("Fungi: " + i + " Taxa");
            String[] sourceTablesLichen = { "TaxRef_LIAS_Lichens_DE" };
            i = updateTaxa(sourceTablesLichen, "TaxonNamesLichen", repConn, mobConn);

            if (i > 0)
            {
                this.setProgressInformation("Lichen: " + i + " Taxa");
            }
            System.Threading.Thread.Sleep(1000);

            //MessageBox.Show("Lichen: " + i + " Taxa");
            String[] sourceTablePlants = { "TaxRef_BfN_VPlants" };
            i = updateTaxa(sourceTablePlants, "TaxonNamesPlants", repConn, mobConn);
            if (i > 0)
            {
                this.setProgressInformation("Plants: " + i + " Taxa");
            }
            System.Threading.Thread.Sleep(1000);
            String[] sourceTableInsects = { "TaxRef_UBT_Gallerreger" };
            i = updateTaxa(sourceTableInsects, "TaxonNamesInsects", repConn, mobConn);
            if (i > 0)
            {
                this.setProgressInformation("Insects: " + i + " Taxa");
            }
            System.Threading.Thread.Sleep(1000);
            //MessageBox.Show("Plants: " + i + " Taxa");

            //MessageBox.Show("Complete");
            //buttonGetTaxa.Text = "Download Complete";
            i = updateProperties("LebensraumTypen", "LebensraumTypenLfU", taxonRepSerializer, taxonMobSerializer);
            if (i > 0)
            {
                this.setProgressInformation("LebensraumTypen: " + i + " PropertyNames");
            }
            else
            System.Threading.Thread.Sleep(3000);

            i = updateProperties("Pflanzengesellschaften", "Pflanzengesellschaften", taxonRepSerializer, taxonMobSerializer);
            if (i > 0)
            {
                this.setProgressInformation("Pflanzengesellschaften: " + i + " PropertyNames");
            }
            System.Threading.Thread.Sleep(3000);

            mobConn.Close();

            this.setProgressValue(0);
            this.setActionInformation("Copy MobileTaxonNames Database from work directory");
            //Alte TaxonDatenbank überschreiben
            if (activesync == true)
                rapi.CopyFileToDevice(taxPath, mobileTaxonPath, true);
            else
                System.IO.File.Copy(taxPath, mobileTaxonPath, true);

            this.setProgressValue(100);
            this.setProgressInformation("Finished");

            this.endProgressThread(false);

            //buttonGetTaxa.Text = "Finished";
            buttonGetTaxa.Enabled = false;
        }