|
I want to in C# be able:
1. create a text file
2. save it
3. Make a change to the text file
4. Save only the changes, which can be merged back into the original file.
This is basically a poor mans version control system in C#.
I have found examples of how to compare two files byte by byte. I am hoping someone has seen an efficient way to save the changes before I start rolling my own.
Thanks,
Darren
|
|
|
|
|
|
There are a lot of interfaces in .Net ,
how and when should we use these interfaces ?
IContainer , IDisposable , IComponent are some of them that I've seen around..
Could you explain me ?
And give some advice ..
Thanks a lot..
|
|
|
|
|
Interfaces is a method to provide polymorphism without having to implement multiple inheritance.
An interface is a description of a subset of properties and methods of an object. If an object is declared to implement an interface, then it must provide all the properties and methods of that interface.
A good example of the usefullness of interfaces is IDisposable. Let's say that you got a list of objects. The objects are all of different types, but you know that some of those objects needs to release their internal resources when you're done using them. Here is how you could do it:
foreach (IDisposable disposableObject in listOfVariousClassInstances)
{
disposableObject.Dispose();
}
In the example above, you don't care if the object at hand is a Brush, BinaryWriter or a Cursor, you simply narrows the object to an IDisposable and invokes the one and only method available: Dispose().
When to create an interface: If you expect that your class hierarchy contains classes that share common methods and properties, you will of course use inheritance:
public class Base
{
protected int i;
public int I
{
get:
{
return i;
}
}
}
public class A: Base
{
protected int j;
public int J
{
get:
{
return j;
}
}
}
public class B: Base
{
protected int k;
public int K
{
get:
{
return k;
}
}
}
But suppose that you want class B to be a list of objects too. All that functionality could be easily provided by extending class System.Collections.ArrayList, but then you can't inherit from class Base. You know that other classes in your hierarchy will refer to B.I, so you now have the choice to either reinvent the functionality of ArrayList, or create a common interface for your classes.
In this case, it seems that your classes aren't that related, which in itself begs for an interface solution, but it's quite clear, that it should be easier to copy/paste the I property to all of your classes, than to reinvent ArrayList:
public interface IBase
{
int I
{
get;
}
}
public class A: IBase
{
protected int j;
protected int i;
public int I
{
get:
{
return i;
}
}
public int J
{
get:
{
return j;
}
}
}
public class B: ArrayList, IBase
{
protected int k;
protected int i;
public int I
{
get:
{
return i;
}
}
public int K
{
get:
{
return k;
}
}
}
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
Thanks a lot for the examples and the explanations.
|
|
|
|
|
jan larsen wrote:
foreach (IDisposable disposableObject in listOfVariousClassInstances)
{
disposableObject.Dispose();
}
That won't work if at least one item from listOfVariousClassInstances will NOT implement IDisposable, right? I guess you know it, bt I think that rookie may not know... so I say it
foreach loop does type casting for every item in collection, so it will raise exception if some item from listOfVariousClassInstances collection can't by casted to IDisposable.
correct me if I am wrong... As I do
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
well "that rookie" knows about it...
and I didnt like the kind of the way you pointing me..
I'm sorry, but you should be more polite...
|
|
|
|
|
Bahadir Cambel wrote:
well "that rookie" knows about it...
OK. Don't call me only ignorant* but pesimistic ignorant from now. My theory is better say something obvious again than forget to say something critical.
Bahadir Cambel wrote:
I'm sorry, but you should be more polite..
you mean "that rookie" ? Sorry than.. I am so stupid I cannot remember who was author of original post as I see only post I am replying to... so I had to use something else than your name... well i could use "s/he" ... *click* another lesson learnt
At the top of the things, I always had problems (nope, I never... others have problem wit me ) to be polite... and I am not going to change myself in this way much... sorry man that's the way I am.
David
*that's another, long story
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
ok , the critical thing is not critical for me right now, and when I consider the example , it enlightened me a lot..So I didnt intend to write or answer about the IDispose..
I wont talk about about the politeness , thats your choice , and if you like the way ppl threaten to you , than everything is fine..
Whatever, I know your are trying to help ppl , the way you do..it is ok for me...
Bahadir
|
|
|
|
|
well, one more try... was it that "rookie" thing?
my problem can be that I DONT see anything rude in that post
Bahadir Cambel wrote:
and if you like the way ppl threaten to you
actually I don't. Most people don't like when i say what I think.. bt saying something else is something I detest.
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Ah, yes, there is that. But all that will be corrected when we get generics...
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
true. Did you find my post unpolite? was "rookie" bad?
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Well, if he truly was a rookie, it wasn't bad. But he could be a very good C programmer that is about to learn OOP, in that case, he would probably find rookie a bit insulting
I was a consultant in a .NET project a couple of years ago (a very bold decision from a big company to use the brand new technology), where more than half of the staff were new to OOP, and they certainly weren't at home with GC.
I used a lot of hours reeding out resource leaks by inserting dispose() invocations and encapsulating functionality inside using(...) blocks.
I even had to expose my ears to statements like: "Hey, look what Bob did!, isn't it clever?, now we can use this code in blah blah blah", the guy was talking about 'bob' having implemented a class for Gods sake!
But I never considered them rookies, at many points, some of them were much more experienced programmers, than I was.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
jan larsen wrote:
But he could be a very good C programmer that is about to learn OOP, in that case, he would probably find rookie a bit insulting
Oh yeah... I was thinking in contex of what he is learing... bt no one can know what I am thinking unless I write it down - my fault. I understand now...
thx
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Hi
I have done a c# program which reads a schema file and automatically inserts data's according to the datatypes. Now I have another xml file which has original values in it. So while my program is raeading a schema file, if there is field which is same field name of an original values cxml file. my program should read the values of the the original values xml file of that field and insert into the resultant one.
i AM TRYING AS SUCH
ie,
I have used switch ..case in my program
[b]switch(dColmn.DataType.ToString())
{
case "System.String":
if(dColmn.ColumnName.Equals("billto_name"))
{
XmlTextReader xtr = new XmlTextReader("D:\\billtoname.xml");
oValues[i] = ((xtr.NodeType == XmlNodeType.Element) & (xtr.Name == "billto_name"));
}
else
oValues[i] = (string) "Castle Hampers" + j;
break;[/b]
Note:
//***** billto_name is the field which exists in both the schema and original values xml file.//
// j is a for loop for about 0 to 200
the if statemnt given inside is the one I am trying . But when run , the data's inside are shown as "false".
santhosh
|
|
|
|
|
hi,
I wrote you long and detailed response, bt I hit some mouse combo or what and lost it before I post it
so:
don't even try [b] there are <b> and better <code> for marking code snippets in post
johnsanthosh wrote:
XmlTextReader xtr = new XmlTextReader("D:\\billtoname.xml");
shouldn't be inside loop.. you don't have to create it again and again... inefficient. And it's even mistake here!
Plus you don't call xtr.Read()
You must call XmlTextReader.Read() method in order to advance to next node in XML stream... that's why it gets wrong there...
hope it help I rush to post it I don't want to screw again
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Hi
Thank you for your response.
Can U please give a some more detailed note about it.
As its very urgent for me to do.
pls
santhosh
|
|
|
|
|
sorry for late response as I am +6 time zone so you ca count what time it was for me
<br />
if(dColmn.ColumnName.Equals("billto_name"))<br />
{<br />
XmlTextReader xtr = new XmlTextReader("D:\\billtoname.xml");<br />
oValues[i] = ((xtr.NodeType == XmlNodeType.Element) && (xtr.Name == "billto_name"));<br />
<br />
}<br />
You must call XmlTextReader.Read()[^] to move to another node in XML stream (File, in this case). Since you don't do it, xtr.NodeType & xtr.Name are null (IMO)...
(btw there should be && not bitwise & operator)
As I reread you post, I must ask why there is loop from 1 to 200 or so...
If I understand you have xml file with schema, xml file with values and you are trying to create one more file with...? or? now I don't know
At least you know now how to read XML files with XmlTextReader...
tell me more about what exactly you want to do and I'll (or somebody else) will hopefully tell you how to do it...
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Hi
First of thank you for replying.
I have to read any schema file, and according to their datatype, it should load values for about 200 into a new xml file.
ie, a rough xml(first file -resulatant file)
<name>john1
<salary>8100
<name>john2
<salary>8200
<name>john3
<salary>8300
<name>john4
<salary>8400
like so on.. for about 200 values.
Now I have another xml file which has same "name" field all meaningful values for about 50.
(second xml file)
<name>john milton
<name>stephen
<name>george
<name>thomas
<name>paul like so on for about 50 data's.
Now coming to my program, when it reads the schema, and when the schema file has the field"name" then it should read the second file and insert the data's from second file into the first xml (resultant file) for that particular field.
This is my requirement.
and this is my coding done, after running this program i find the values for the particular field are changed to false.
private void button2_Click(object sender, System.EventArgs e)
{
dataSet1.ReadXmlSchema(txtSchema.Text);
foreach (DataTable dTbl in dataSet1.Tables)
{
for(int j = 0; j <= 20; j++)
{
object[] oValues = new object[dTbl.Columns.Count];
int i = 0;
foreach (DataColumn dColmn in dTbl.Columns)
{
switch(dColmn.DataType.ToString())
{
case "System.String":
if(dColmn.ColumnName.Equals("billto_name"))
{
XmlTextReader xtr = new XmlTextReader("C:\\CDEV\\testdatagenerator\\meelu.xml");
oValues[i] = ((xtr.NodeType == XmlNodeType.Element) && (xtr.Name == "billto_name"));
}
else
{
oValues[i] = (string) "sachin" + j;
}
break;
}
i = i+1;
}
dTbl.Rows.Add(oValues);
}
}
dataSet1.WriteXml(txtXml.Text,XmlWriteMode.WriteSchema );
}
santhosh
|
|
|
|
|
sorry
I had given tags for the above program so, it is not in clear xml format.
for first xml file
ie john1,john2,.... comes for a field "name" tag(element)
and 8100,8200,8300..etxc comes for "slary" tag(element)
second xml file
ie, john milton, stephen,george, thomas,paul all comes for a field " name" tag(element)
so now i have insert the data's form second xml file and load those values to the same field of first xml file.
santhosh
|
|
|
|
|
Is there a way to 'lock' an entire folder, not just a file in side? I read this: http://www.codeproject.com/csharp/CryptoSafe.asp[^] and it lays out the info very well, but is there a way to adapt it to do an entire folder so that it cant be opened?
|
|
|
|
|
The only way you're going to accomplish anything like this is to Crpto every file in the folder. There is no way to do the same for the folder itself.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
this will be difficult as some files will be very large ( 500mb or bigger). I and speed is very important.
|
|
|
|
|
Like I said, it's not possible to do it on the folder itself. In order to accomplish something like this, you'd have to replace the NFTS File System with your own implementation.
Since security is an issue, look into using the security system that's built into Windows and/or whatever network your using to control access to these resources. That's what it's there for...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
Like I said, it's not possible to do it on the folder itself. In order to accomplish something like this, you'd have to replace the NFTS File System with your own implementation.
Maybe I missed the point here but I though this thread is about encrypting all files in a folder and that is actually supported by NTFS.
Best regards
Dennis
|
|
|
|
|