|
The program has multiple executables/services executing in different locations. I was trying to come up with a simplistic way for the application users (our sister locations) to use single XML config files for connections, and others for application settings. So if a site wanted to encrypt their connection info and/or program settings using their own encryption methodologies, it would give them the freedom to (vs say using an encrypted connection string in an App.config file).
This would also let users choose to use a single file for all of the services/executables or use individual connection information files stored separately.
Trying to avoid the redundancy in creating multiple separate config files, and instead use modular XML elements to store this information anywhere the admin chooses (by piping them via webservices, filesystem, database decrypt, etc.)
Does that help? Am I tying to implement these things in a terrible way?
|
|
|
|
|
The concept is fine, I don't see a need for having your nodes in any place in the file. Having a defined schema will certainly make the configuration more maintainable. Again, look at web/app config files as an example.
You can always search for a node using XPath using the syntax "//[node name]", however, if this is a new app and using .NET 3.5 I'd use XElment or XDocument and Linq to XML.
only two letters away from being an asset
|
|
|
|
|
You are correct in using XPath. After seeing your and Christian Graus's comments, a simple XPath query expression definitely seems the way to go.
Thanks a ton for pointing me in the right direction (and not using my own crock pot coding to implement something that is already implemented.)
Thanks again!
|
|
|
|
|
private static XmlNode FindNode(string nodename, XmlNode node)
{
if (node.Name == nodename)
return node;
if (node.HasChildNodes)
foreach (XmlNode childNode in node.ChildNodes)
{
XmlNode returnNode = FindNode(nodename, childNode);
if (returnNode != null) return returnNode;
}
return null;
}
|
|
|
|
|
LnocaSteve wrote: I am using recursion instead of an XPath query because I wanted the configuration section nodes "<schema> in this case" to be able to be placed in any XML file
That is insane. The Xpath //myNode/myChild will find those two nodes anywhere in the file. Use that syntax.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
AWSOME! You are absolutely correct. My recursion method is just stupid compared to the power of XPath! /bow
XPathDocument doc = new XPathDocument(filename);
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr = nav.Compile("//Schema/SqlConnection");
XPathNodeIterator iterator = nav.Select(expr);
XPathNavigator sqlConnection;
while (iterator.MoveNext())
sqlConnection = iterator.Current.Clone();
(just a quick crude code example, I'll refine and post the full solution shortly)
I never used XPath queries in the past. I didn't know they were so powerful. Recursion is always such a resource hog.
I haven't started researching yet, but do you know of any significant drawbacks of using XPath queries, off the top of your head?
Again, Thanks!
|
|
|
|
|
This is a much easier way using XPath expression queries.
internal class Program
{
private const string FILENAME = "Testfile.xml";
private static readonly string[] SectionNames = new[] { "Schema" };
private static readonly string[] ConfigItems = new[] { "SqlConnection", "Output" };
private static void OutputNavigatorData(XPathNavigator navigator)
{
Console.WriteLine(navigator.Name);
if (navigator.MoveToFirstAttribute())
{
Console.WriteLine(" - " + navigator.Name + " : " + navigator.Value);
while (navigator.MoveToNextAttribute())
{
Console.WriteLine(" - " + navigator.Name + " : " + navigator.Value);
}
}
}
private static void Main(string[] args)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(FILENAME);
XPathDocument doc = new XPathDocument(FILENAME);
XPathNavigator nav = doc.CreateNavigator();
foreach (var sSectionName in SectionNames)
{
foreach (var sConfigItem in ConfigItems)
{
XPathExpression expression = nav.Compile("//" + sSectionName + "/" + sConfigItem);
XPathNodeIterator iterator = nav.Select(expression);
while (iterator.MoveNext())
{
OutputNavigatorData(iterator.Current);
}
}
}
}
}
|
|
|
|
|
Hello i have altered my method of displaying my data since my last post and instead of a listview i am now using a datagrid as i thought it would be easier to use for what i want.
I now am stuck in terms of i do not have a clue how i am going to display the rest of the data from my table?
What i need to have is when the user clicks on a row of data e.g. 'client' all records are show in the tabbed page area?
(the picture will help to explain bettter)
Picture :
I have used a dataset to show the data when client is clicked but i dont think i can use that same dataset as it only retrieves four recods.
How can i have the four records displayed on one side of the page and then when highlighted display all infomation about the client in the seperat tabbed area?
My Code so far which displays client (when clicked) and contractor (when clicked)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace Deroche_Consultants
{
public partial class main_screen : Form
{
string dataCategory = null;
DataSet myDataSet;
public main_screen()
{
InitializeComponent();
}
private void client_pic_Click(object sender, EventArgs e)
{
ClientDataLoad();
}
private void client_label_Click(object sender, EventArgs e)
{
ClientDataLoad();
}
private void client_buttonBox_Click(object sender, EventArgs e)
{
ClientDataLoad();
}
private void ClientDataLoad()
{
string connectionString = "Data Source=localhost" + "; Database=_consultants" + "; User ID=root" + "; Password=password;";
MySqlConnection MySqlConn = new MySqlConnection(connectionString);
string strSQL = ("SELECT company_id, company_name, contact_fname, contact_sname, employee_count FROM client");
MySqlCommand mysqlCommand = new MySqlCommand(strSQL, MySqlConn);
MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(mysqlCommand);
try
{
MySqlConn.Open();
DataSet myDataSet = new DataSet();
myDataSet.Clear();
myDataAdapter.Fill(myDataSet, "client");
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = myDataSet.Tables[0];
MySqlConn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Data Load Error "+ex.Message.ToString(),
"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
MySqlConn.Close();
}
}
private void job_pic_Click(object sender, EventArgs e)
{
}
private void job_label_Click(object sender, EventArgs e)
{
}
private void job_boxButtons_Click(object sender, EventArgs e)
{
}
private void contractor_pic_Click(object sender, EventArgs e)
{
ContractorDataLoad();
}
private void contractor_label_Click(object sender, EventArgs e)
{
ContractorDataLoad();
}
private void contractor_boxButton_Click(object sender, EventArgs e)
{
ContractorDataLoad();
}
private void ContractorDataLoad()
{
string connectionString = "Data Source=localhost" + "; Database=_consultants" + "; User ID=root" + "; Password=password;";
MySqlConnection MySqlConn = new MySqlConnection(connectionString);
string strSQL = ("SELECT contractor_id, forename, surname, availability, daily_cost FROM contractor");
MySqlCommand mysqlCommand = new MySqlCommand(strSQL, MySqlConn);
MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(mysqlCommand);
try
{
MySqlConn.Open();
DataSet myDataSet = new DataSet();
myDataSet.Clear();
myDataAdapter.Fill(myDataSet, "contractor");
myDataAdapter.Fill(myDataSet);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = myDataSet.Tables[0];
MySqlConn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Data Load Error "+ex.Message.ToString(),
"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
MySqlConn.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
Form2 addclient = new Form2();
addclient.Show();
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
Thanks in advance,
C~Rose
modified on Wednesday, December 31, 2008 4:36 AM
|
|
|
|
|
|
Also you need to split your app.
Shove all the DB connection stuff into another class so the connection is built only once and is local to the DB class.
Create a method for each of your load requirements that return a table (this is exactly the same code as you are using except it returns table[0])
This will start you on a better designed app that will be MUCH more readable and supportable.
Consider using stored procs instead of SQL strings (arguments for/against this are endless).
If, as Mark suggest, you want a parent child then you can move both tables into a dataset, create the relations and bind the dataset to the DGV.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello yer at the moment the code is all in one big chunk.... How doi go about shoving all the db connection stuff into a class so it is only built once
is this ok?:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace _Consultants
{
class connectionStringClass
{
private void connectionString ()
{
string connectionString = "Data Source=localhost" + "; Database=_consultants" + "; User ID=root" + "; Password=password;";
MySqlConnection MySqlConn = new MySqlConnection(connectionString);
MySqlCommand mysqlCommand = new MySqlCommand(MySqlConn);
}
}
}
and then in the "main screen" class refer to it as a normal method right? like
connectionStringClass ();
|
|
|
|
|
I am testing a dll by including it in a project.
In that project I have a App.config file where there is a sharedListeners tag with one or more custom listener.
Test is success in the case.
==============================
I am testing that dll in another project where there is a configuration file but name is not App.config instead name is xxxx.yyyy.config.
Test fail in this case. No log file generated from custom listener. Exact code inside both config file only name is different. Changing name to App.config works fine but this is not an option for me.
How can I configure the application, so that it will take the parameter from config file even though name is not App.config.
Any idea will be greately appreciated
|
|
|
|
|
Usually when you deploy the application, the app.config becomes xyz.exe.config where xyz.exe is the application executable name.
One more thing app.config should be in the same directory where the executable located.
|
|
|
|
|
I am attempting to write my first custom component which requires a custom collection.
So far I have:
using System;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.ComponentModel.Design;
using System.Drawing.Design;
namespace MultiColumnComboBox
{
public partial class MultiColumnComboBox : ComboBox
{
public MultiColumnComboBox()
{
InitializeComponent();
}
}
[Editor(typeof(ColumnCollectionEditor),UITypeEditor)]
public ColumnCollection Columns
{
get { return Columns; }
set { Columns = value; }
}
public class Column
{
#region private variables
private bool _autoColumnWidth = false;
#endregion
#region public properties
public bool AutoColumnWidth
{
get { return _autoColumnWidth; }
set { _autoColumnWidth = value; }
}
#endregion
}
public class ColumnCollection : CollectionBase
{
public Column this[int index]
{
get { return (Column)List[index]; }
}
public void Add(Column column)
{
List.Add(column);
}
public void Remove(Column column)
{
List.Remove(column);
}
}
public class ColumnCollectionEditor : CollectionEditor
{
public ColumnCollectionEditor(Type type)
: base(type)
{
}
protected override string GetDisplayText(object value)
{
Column item = new Column();
item = (Column)value;
return base.GetDisplayText(string.Format("{0}", item.AutoColumnWidth));
}
}
}
The compiler does not like the section:
[Editor(typeof(ColumnCollectionEditor),UITypeEditor)]
public ColumnCollection Columns
{
get { return Columns; }
set { Columns = value; }
}
it highlights the ColumnCollection reference, but I don't understand why. Can an experienced C# coder please point me in the right direction of where I am failing?
It's hard being a simpleton
|
|
|
|
|
kanchoette wrote: The compiler does not like the section
it highlights the ColumnCollection reference
What is the error you get at compilation?
|
|
|
|
|
I get
"Expected class, delegate, enum, interface, or struct" and the ColumnCollection reference is highlighted (red wiggly line)
|
|
|
|
|
It's been awhile since I last worked with editors but if I recall correctly, you should use typeuf on the second parameter also. And when using two types, the second parameter is used for the base class so perhaps something like:
[Editor(typeof(ColumnCollectionEditor), typeof(CollectionEditor))]
Does that help or change the error in anyway?
|
|
|
|
|
Unfortuantely I get the same error. Many thanks for trying to help me though - much appreciated.
I know it's going to end up being something really dumb. Just wish I knew just what .. Grrrr .....
|
|
|
|
|
One more observation. If I'm reading correctly, the custom editor class is a nested class inside the MultiColumnComboBox. If so, what if you try to move the editor class outside directly under the namespace (along with the column class) or use MultiColumnComboBox.ColumnCollectionEditor syntax.
|
|
|
|
|
Dear All,
I am developing small application using c# where it could only send and recieve single attachment with body text.
I am using System.Net.Mail namespace to send my msgs, I can send msg and attachments using the classes located in this namespace.
i find some references to use EAGetMail.dll to recieve msgs with attachment, sure i used EAGetMail.dll, but i can recieve my email with attachment with the extenstion of .eml where i specify for it, "based on reference".
now i dont want to open my msgs with other applications, i wd like to open it my c# application which i am developing.
Your cooperation is really appreciated.
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
Ok, so what is your question?
|
|
|
|
|
[code]
EAGetMail.MailClient mClient=new EAGetMail.MailClient("TryIt");
EAGetMail.MailServer sClient=new MailServer("mail.domain.com","user name","password", ServerProtocol.Pop3);
mClient.Connect(sClient);
MailInfo[] mInfo=mClient.GetMailInfos();
int count=mInfo.Length;
for (int i=0; i<count;> {
MailInfo info=mInfo[i];
Mail m=mClient.GetMail(info);
m.SaveAs(String.Format("c:\\{0}.xal", i), true);
}
[/code]
if u just pay attention, i am saving all my emails with the extension of ".xal".
now i dont know how to open this file in my own c# app. like the one which MS OUTOOK opens.
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
Abdul Rahman Hamidy wrote: now i dont know how to open this file in my own c# app. like the one which MS OUTOOK opens.
With code, I guess. File.ReadAllText will do it to get the text, although storing the files at the root of c is obviously retarded. I'd use a database.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Yeah i can read the text from the file, but how about attachments, i have to show name of attachments in my application may be in a label.
now the problem is how to understand that there is an attachment with the email.
regarding saving file, its temporary i am going to save to database using stream.
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
Hello fellow developers,
I have written an application to find and replace just about anything. It even has a nice web interface and keeps everything stored in a SQL Server DB.
I have no problem finding what I am looking for, the issue comes when I replace a hard coded string inside of an EXE or DLL.
For simplicity sake I just grab the whole file as bytes, use Encoding to get me a string, and use a RegEx to Find / Replace what I am searching for. I then take the string with the values replaced and use Encoding to switch it back to bytes and overwrite the file.
This works fine on text, but DLLs and EXEs appear to have been corrupted. I get the following error when I try to execute the EXE or and executable that references a DLL I have replaced the strings inside of.
Here is a copy of the Exception, 'ConfigurationManagement.Controllers' is the DLL I changed:
System.BadImageFormatException was unhandled
Message: Could not load file or assembly 'ConfigurationManagement.Controllers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The module was expected to contain an assembly manifest.
I am assuming I am writing the file incorrectly and by adding new bytes to it, that there is some internal data inside the DLL or EXE that does not match its file size and locations anymore.
Does anyone know how to correctly edit the strings inside of a binary file?
Kind Regards,
Ryan
|
|
|
|