public void connectToRepository(RepositoryOptions ro, string user, string password) { if (string.IsNullOrEmpty(ro.InitialCatalog) || string.IsNullOrEmpty(ro.IPAddress) || string.IsNullOrEmpty(ro.IPPort) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(ro.TaxonNamesInitialCatalog)) return; //RepositoryOptions aktualisieren? if (ro.SqlAuthentification) { if (ro.LastUsername != user) { ro.LastUsername = user; OptionsAccess.RepositoryOptions = ro; } } else { if (ro.LastUsername != Environment.UserName) { ro.LastUsername = Environment.UserName; OptionsAccess.RepositoryOptions = ro; } } StringBuilder praef=new StringBuilder(); praef.Append("[").Append(ro.InitialCatalog).Append("].[dbo]."); String praefix = praef.ToString(); StringBuilder taxPraef = new StringBuilder(); taxPraef.Append("[").Append(ro.TaxonNamesInitialCatalog).Append("].[dbo]."); String taxonPraefix = taxPraef.ToString(); StringBuilder syncPraef = new StringBuilder(); syncPraef.Append("[").Append("Synchronisation_Test").Append("]."); String syncPraefix = syncPraef.ToString(); if(ro.SqlAuthentification) { RepositoryDB = new MS_SqlServerIPSerializer(ro.LastUsername, password ,ro.IPAddress, ro.IPPort, ro.InitialCatalog, praefix); RepositoryDefinitions = new MS_SqlServerIPSerializer(ro.LastUsername, password, ro.IPAddress, ro.IPPort, ro.TaxonNamesInitialCatalog,taxonPraefix); Synchronization = new MS_SqlServerIPSerializer(ro.LastUsername, password, ro.IPAddress, ro.IPPort, syncDBCatalog,syncPraefix); } else { RepositoryDB = new MS_SqlServerWASerializier(ro.IPAddress+","+ro.IPPort, ro.InitialCatalog,praefix); RepositoryDefinitions = new MS_SqlServerWASerializier(ro.IPAddress + "," + ro.IPPort, ro.TaxonNamesInitialCatalog,taxonPraefix); Synchronization = new MS_SqlServerWASerializier(ro.IPAddress + "," + ro.IPPort, syncDBCatalog,syncPraefix); } //Verbindung zum Repository herstellen connectRepositoryDB(); connectSynchronization(ro); connectRepositoryDefinitions(); }
public void connectRepositorySqlAuth(ConnectionProfile repo, string user, string password) { if (repo != null) { if (user != null && password != null) { _userName = user; Repository = new MS_SqlServerIPSerializer(user, password, repo.IPAddress, repo.Port, repo.InitialCatalog, string.Format(REPOSITORY_PREFIX, repo.InitialCatalog)); Definitions = new MS_SqlServerIPSerializer(user, password, repo.IPAddress, repo.Port, repo.TaxonNamesInitialCatalog, string.Format(REPOSITORY_PREFIX, repo.TaxonNamesInitialCatalog)); Synchronization = new MS_SqlServerIPSerializer(user, password, repo.IPAddress, repo.Port, SYNCDB_CATALOG, string.Format(SYNCDB_PREFIX, SYNCDB_CATALOG)); connectRepository(repo); } else _Log.Info("Login Credentials incomplete"); } else _Log.Info("No Connection Configured"); }
private void buttonConnectRepository_Click(object sender, EventArgs e) { try { SerRepository = new MS_SqlServerIPSerializer(@textBoxUser.Text, @textBoxPassword.Text, @textBoxIP.Text, @textBoxPort.Text, @textBoxDBName.Text); SerRepository.RegisterType(typeof(TaxonNames)); SerRepository.Activate(); ConnRepository = SerRepository.CreateConnection(); buttonConnectRepository.Text = "Connected"; buttonConnectRepository.BackColor = Color.Yellow; repositoryConnection = true; } catch (Exception f) { MessageBox.Show("An error according to Your Values has occured", "Check Values", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } startcheck(); }
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; }