private teDBParameter ParameterAusJsonLesen(string pfadMitUdl, string dbVerbindungsName) { teDBParameter dbParameter = new teDBParameter(); string json = ""; using (StreamReader r = new StreamReader(pfadMitUdl)) { json = r.ReadToEnd(); } JObject myJson = JObject.Parse(json); JArray myArray = (JArray)myJson["Verbindungen"]; int anzahl = myArray.Count; for (int index = 0; index < anzahl; index++) { if ((string)myJson["Verbindungen"][index]["Verbindungsname"] == dbVerbindungsName) { dbParameter.Verbindungsname = dbVerbindungsName; dbParameter.Benutzername = (string)myJson["Verbindungen"][index]["Benutzername"]; dbParameter.Passwort = (string)myJson["Verbindungen"][index]["Passwort"]; dbParameter.PersistSecurityInfo = myJson["Verbindungen"][index]["PersistSecurityInfo"].ToString(); dbParameter.Provider = (string)myJson["Verbindungen"][index]["Provider"]; dbParameter.Server = (string)myJson["Verbindungen"][index]["Server"]; dbParameter.Datenbank = (string)myJson["Verbindungen"][index]["Datenbank"]; dbParameter.Integratedsecrurity = (string)myJson["Verbindungen"][index]["Integratedsecrurity"]; } } return(dbParameter); }
public bool convertToUdl(teDBParameter dbParameter) { bool conSuccesful = false; if (dbParameter != null) { try { StringBuilder builder = new StringBuilder(); builder.AppendLine("[oledb]"); builder.AppendLine("; Everything after this line is an OLE DB initstring"); builder.Append("Provider=").Append(dbParameter.Provider); builder.Append(";Password="******";Persist Security Info=").Append(dbParameter.PersistSecurityInfo); builder.Append(";User ID=").Append(dbParameter.Benutzername); builder.Append("; Initial Catalog=").Append(dbParameter.Datenbank); builder.Append(";Data Source=").Append(dbParameter.Server); string fileName = string.Format(@"D:\Projekte\Projekte_Eigene\_HB\teHB\ini\ConverttoUdl_{0}.udl", dbParameter.Verbindungsname); using (StreamWriter writer = new StreamWriter(fileName, true, Encoding.Unicode)) { writer.Write(builder.ToString()); } conSuccesful = true; } catch (Exception ex) { conSuccesful = false; } } return(conSuccesful); }
private teDBParameter ParameterAusUdlLesen(string pfad) { teDBParameter dBParameter = new teDBParameter(); string dateiInhalt = ""; using (StreamReader sr = new StreamReader(pfad)) { dateiInhalt = sr.ReadToEnd(); } string[] eintraege = dateiInhalt.Split(new [] { ";", Environment.NewLine }, StringSplitOptions.None); foreach (var eintrag in eintraege) { if (dBParameter.Datenbank == "" || dBParameter.Datenbank == null) { dBParameter.Datenbank = leseUdlWert(eintrag, "initial catalog="); } if (dBParameter.Server == "" || dBParameter.Server == null) { dBParameter.Server = leseUdlWert(eintrag, "data source="); } if (dBParameter.Provider == "" || dBParameter.Provider == null) { dBParameter.Provider = leseUdlWert(eintrag, "provider="); } if (dBParameter.PersistSecurityInfo == "" || dBParameter.PersistSecurityInfo == null) { dBParameter.PersistSecurityInfo = leseUdlWert(eintrag, "Persist Security Info="); } if (dBParameter.Integratedsecrurity == "" || dBParameter.Integratedsecrurity == null) { dBParameter.Integratedsecrurity = leseUdlWert(eintrag, "Integrated Security="); } if (dBParameter.Benutzername == "" || dBParameter.Benutzername == null) { dBParameter.Benutzername = leseUdlWert(eintrag, "User ID="); } if (dBParameter.Passwort == "" || dBParameter.Passwort == null) { dBParameter.Passwort = leseUdlWert(eintrag, "Password="); } } return(dBParameter); }
private void getNode(XmlNode node, string dbVerbindungsName, ref teDBParameter dbParameter) { bool istVerbindung = true; switch (node.NodeType) { case XmlNodeType.Element: if (node.Attributes != null) { foreach (XmlAttribute attr in node.Attributes) { if (attr.Name == "Verbindungsname" && attr.Value == dbVerbindungsName) { istVerbindung = true; break; } else { istVerbindung = false; break; } } if (node.HasChildNodes && istVerbindung) { foreach (XmlNode child in node.ChildNodes) { if (child.NodeType != XmlNodeType.Text) { setValueDbParameter(child, ref dbParameter); getNode(child, dbVerbindungsName, ref dbParameter); } } } } break; case XmlNodeType.Text: var temp = node.Value; break; default: break; } }
private teDBParameter ParameterAusUdlLesen(string pfadMitUdl, string dbVerbindungsName) { teDBParameter dbParameter = new teDBParameter(); XmlDocument document = new XmlDocument(); document.Load(pfadMitUdl); XmlNode root = document.DocumentElement; XmlNodeList nodeList = root.ChildNodes; foreach (XmlNode node in nodeList) { getNode(node, dbVerbindungsName, ref dbParameter); } return(dbParameter); }
public teDBParameter readFromJson(string dateiName, string dbVerbindungsName) { teDBParameter conParameter = null; string pfad = teDB_.teDB_.Instance._VerbindungsVerzeichnis; string endung = string.Format("{0}{1}", dateiName, teExtension.EnumUtils <teDBEnum.Dateiendung> .GetDescription(teDBEnum.Dateiendung.JSON)); string pfadMitUdl = Path.Combine(pfad, endung); if (File.Exists(pfadMitUdl)) { conParameter = ParameterAusJsonLesen(pfadMitUdl, dbVerbindungsName); } else { throw new FileNotFoundException("Json - Datei nicht gefunden.", pfadMitUdl); } return(conParameter); }
public bool convertToXml(teDBParameter dbParameter) { bool conSuccesful = false; if (dbParameter != null) { try { string fileName = string.Format(@"D:\Projekte\Projekte_Eigene\_HB\teHB\ini\ConverttoXml_{0}.xml", dbParameter.Verbindungsname); using (XmlWriter writer = XmlWriter.Create(fileName)) { writer.WriteStartDocument(); writer.WriteStartElement("Foo"); writer.WriteStartElement("Verbindung"); writer.WriteAttributeString("Verbindungsname", dbParameter.Verbindungsname); writer.WriteElementString("Verbindungsname", dbParameter.Verbindungsname); writer.WriteElementString("Benutzername", dbParameter.Benutzername); writer.WriteElementString("Passwort", dbParameter.Passwort); writer.WriteElementString("Datenbank", dbParameter.Datenbank); writer.WriteElementString("Server", dbParameter.Server); writer.WriteElementString("PersistSecurityInfo", dbParameter.PersistSecurityInfo); writer.WriteElementString("Provider", dbParameter.Provider); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); } conSuccesful = true; } catch (Exception ex) { conSuccesful = false; } } return(conSuccesful); }
public bool convetToJson(teDBParameter dBParameter) { bool conSuccesful = false; DataSet dataSet = new DataSet("dataSet"); dataSet.Namespace = "NetFrameWork"; DataTable table = new DataTable("Verbindungen"); DataColumn Verbindungsname = new DataColumn("Verbindungsname"); DataColumn Benutzername = new DataColumn("Benutzername"); DataColumn Passwort = new DataColumn("Passwort"); DataColumn Datenbank = new DataColumn("Datenbank"); DataColumn Server = new DataColumn("Server"); DataColumn Integratedsecrurity = new DataColumn("Integratedsecrurity"); DataColumn Provider = new DataColumn("Provider"); DataColumn PersistSecurityInfo = new DataColumn("PersistSecurityInfo"); table.Columns.Add(Verbindungsname); table.Columns.Add(Benutzername); table.Columns.Add(Passwort); table.Columns.Add(Datenbank); table.Columns.Add(Server); table.Columns.Add(Integratedsecrurity); table.Columns.Add(Provider); table.Columns.Add(PersistSecurityInfo); dataSet.Tables.Add(table); for (int i = 0; i < 1; i++) { DataRow newRow = table.NewRow(); newRow["Verbindungsname"] = dBParameter.Verbindungsname; newRow["Benutzername"] = dBParameter.Benutzername; newRow["Passwort"] = dBParameter.Passwort; newRow["Datenbank"] = dBParameter.Server; newRow["Server"] = dBParameter.Integratedsecrurity; newRow["Integratedsecrurity"] = dBParameter.Provider; newRow["Provider"] = dBParameter.Provider; newRow["PersistSecurityInfo"] = dBParameter.PersistSecurityInfo; table.Rows.Add(newRow); } dataSet.AcceptChanges(); string jsodn = JsonConvert.SerializeObject(dataSet, Formatting.Indented); Console.WriteLine(jsodn); JsonHelper.Parameter.JsonDbParameter jsonDb = new JsonHelper.Parameter.JsonDbParameter(); jsonDb.Verbindungsname = dBParameter.Verbindungsname; jsonDb.Benutzername = dBParameter.Benutzername; jsonDb.Passwort = dBParameter.Passwort; jsonDb.Datenbank = dBParameter.Datenbank; jsonDb.Server = dBParameter.Server; jsonDb.Integratedsecrurity = dBParameter.Integratedsecrurity; jsonDb.Provider = dBParameter.Provider; jsonDb.PersistSecurityInfo = dBParameter.PersistSecurityInfo; JsonHelper.Parameter.JsonList list = new JsonHelper.Parameter.JsonList(); list.Verbindungen = new List <JsonHelper.Parameter.JsonDbParameter>(); list.Verbindungen.Add(jsonDb); string lstJson = JsonConvert.SerializeObject(list, Formatting.None); Console.WriteLine(lstJson); if (dBParameter != null) { try { string fileName = string.Format(@"D:\Projekte\Projekte_Eigene\_HB\teHB\ini\ConverttoJson_{0}.json", dBParameter.Verbindungsname); using (StreamWriter writer = new StreamWriter(fileName, true)) { writer.WriteLine(lstJson); } //using (StreamWriter writer = File.CreateText(fileName)) //{ // JsonSerializer serializer = new JsonSerializer(); // serializer.Serialize(writer, lstJson); //} } catch (Exception ex) { conSuccesful = false; } } return(conSuccesful); }
private void setValueDbParameter(XmlNode node, ref teDBParameter dbParameter) { for (int index = 0; index < 8; index++) { if (dbParameter.Datenbank == "" || dbParameter.Datenbank == null) { if (node.Name == "Datenbank") { dbParameter.Datenbank = node.InnerText; } } if (dbParameter.Server == "" || dbParameter.Server == null) { if (node.Name == "Server") { dbParameter.Server = node.InnerText; } } if (dbParameter.Provider == "" || dbParameter.Provider == null) { if (node.Name == "Provider") { dbParameter.Provider = node.InnerText; } } if (dbParameter.PersistSecurityInfo == "" || dbParameter.PersistSecurityInfo == null) { if (node.Name == "PersistSecurityInfo") { dbParameter.PersistSecurityInfo = node.InnerText; } } if (dbParameter.Integratedsecrurity == "" || dbParameter.Integratedsecrurity == null) { if (node.Name == "Integratedsecrurity") { dbParameter.Integratedsecrurity = node.InnerText; } } if (dbParameter.Benutzername == "" || dbParameter.Benutzername == null) { if (node.Name == "Benutzername") { dbParameter.Benutzername = node.InnerText; } } if (dbParameter.Passwort == "" || dbParameter.Passwort == null) { if (node.Name == "Passwort") { dbParameter.Passwort = node.InnerText; } } } }