|
Dear folks,
I have many folders to compare but I don't know how I can make a comparison between them without lacking for memory usage.
I explain :
I have two servers with around 10TB of data each. I use "xcopy" command (on Windows-DOS) for making the copy incrementaly.
The first server have datas changing everytime but the other is just for mirroring. Sometimes I need to check if every folders between the two servers are the same (just the folder). I used IEnumerable/List<>... to do the work but consume CPU usage or memory usage.
The structure of the folders are the same so what I need is to compare each structure only.
If anybody have an idea (with a sample code or just the algorithm or pseudo-code) I should appreciate it.
Many thanks to you all.
|
|
|
|
|
Hi,
so could you post what you have already? First thought of me was to use threads, this will speed up the execution (maybe).
Regards
Sebastian
|
|
|
|
|
Thanks for your prompt reply but i think i found another idea. That's getting the list of the first server and try to find it into the second server. If the folder exist, do not care, otherwise log the foldername.fullpath.
for example, suppose i have this :
S1 : c:\rootfolder_S1\folder1\folder2\folder3
S2 : c:\rootfolder_S2\folder1\folder2\folder3
beginning from c:\rootfolder
- get list of folders for one level i got : folder1
- used Path.GetFileNameWithoutExtension(dir) and got : folder1
- use the Path.Combine(S2, foldername) and got : c:\rootfolder_S2\folder1
It's ok and very nice algorithm. But my problem, now, is how can i use this if recursing folders in S1. Using Path.GetFileNameWithoutExtension(dir) will get only the last name of the folder and if combining with S2, will got error or something else.
What i'm going to try is check the size of S1 (rootfolder only), and then use the substring(index) before combining with S2, but how can i get the size or lenght of S1. S1 : c:\rootfolder -> should have 13 characters.
This is my sample code :
static void Main(string[] args)
{
CombinePaths(args[0], args[1]);
}
private static void CombinePaths(string p1, string p2)
{
string[] dirs = Directory.GetDirectories(p1);
foreach (string dir in dirs)
{
try
{
int index = dir.LastIndexOf("\\") + 1;
string foldername = dir.Substring(index);
string combination = Path.Combine(p2, foldername);
if (!Directory.Exists(combination))
{
Console.WriteLine(dir);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine(Path.GetFileNameWithoutExtension(dir));
}
}
this is what i have for now. I'll reply back if found how to have the number of the character of the source string.
Maybe not yet very clear my code but think it is still a draft code.
See you later.
|
|
|
|
|
So finally here is my final code which is what i expect to have (no lack of memory usage nor cpu usage) :
static void Main(string[] args) {
CombinePaths(args[0], args[1]);
}
private static void CombinePaths(string S, string D) {
int indexRoot = S.Length + 1;
var stack = new Stack<string>();
stack.Push(S);
while (stack.Count > 0) {
string dir = stack.Pop();
try {
foreach (string sd in Directory.GetDirectories(dir)) {
stack.Push(sd);
string foldername = sd.Substring(indexRoot);
string combination = Path.Combine(D, foldername);
if (!Directory.Exists(combination))
{
Console.WriteLine(sd);
}
}
}
catch (UnauthorizedAccessException e)
{
Log.Add(e.Message);
}
}
}
The principle is this : the program iterate all directories inside the root folder, then parse the length to the subdirectories that it combine with the destination server, to finally check if the folder just listed from the source server exist in the destination server. (I think it some kind of "dir /s" in DOS Command). It is what i expect to have during 9 days but i still need help to optimize my apps.
As I've just count now, some of my root folder contains 2,000,000 - 3,000,000 folders inside. So I do not want to iterate all of this but i need to stop at level ten (10) or twenty (20), means i need to specify a deep level of iteration but i don't know how to make it by using this stack<> techniques.
Any suggestions are welcome. Thanks for all!
|
|
|
|
|
I am drawing a custom graph in c# openGL.
When I load the program the the Y axis lables draws (it is draw as txt) but everything else, the box representing the bars on the graph and the axis dont draw until you resize the window normally going from full screen down to a smaller window then the graph draws properly.
Does anyone have any ideas why this might be or have had a similar problem.
thanks.
|
|
|
|
|
I'm not an expert on OpenGL, but usually when something dosn't work untill the form/window is resized it might be a problem with initializing all the variables.
For starters you can try calling the OnSize event hendler manually when the window is first shown. If this makes things better you can have a look at what's happening inside the method and find the missing initialization.
|
|
|
|
|
Is it possible to make a explicit casting using a variable?
I'm passig a boxed object, and it's Type, as arguments. Inside the method I would like to unbox and use the content
private void myMethod ( Object boxedObject, Type dataType)
{
....
... = (dataType)boxedObject;
....
}
I know it doesn't compile this way. By the moment i'm using this kind of code:
switch (dataType.ToString())
{
case "int":
... = (int)boxedObject;
case "string"
... = (string)boxedObject;
...
}
But... is there a way to make something similar to "(dataType)boxedObjec)" that doesn't need using 'if' or 'case' for every dataType?
Thanks!
|
|
|
|
|
You can probably do it via reflection, but what are you going to do with it then?
If (for example) "as" worked that way, so you could do " = boxedObject as dataType;" what are you going to assign it to? Other than another object?
You can't pass it to another method, because any type you haven't covered will either no compile or will throw an exception.
You can't use it's properties, as you can't be sure it has those properties (other than ToString and the other really basic ones).
What are you trying to do, that you need this?
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
'as' works the same way than normal casting... Doesn't work...
What I want is compare the given value with data values from a dataset. So I first get the needed column DataType, and then I compare whith the properly unboxed value. The basic code would be:
public int SeekRow (string colName, object value)
{
Type dataType = myDataSet.MyTable.Columns[colName].DataType;
for (row=0; ...)
{
if (myDataSet.myTable[row][ColName]==(dataType)value)
{
return row;
}
}
return -1;
}
If I can't, I must use a lot of untidy 'if' ot 'case'...
|
|
|
|
|
I know "as" doesn't work - that's why I said 'If (for example) "as" worked that way' rather than 'Use "as" - it will do what you want'
I can't help thinking you are overdoing this a little, but...
Do you really need to know what the datatype is? Since your are returning only the row number rather than the value, either compare it directly
myDataSet.myTable[row][ColName] == value or use ToString and compare that way.
myDataSet.myTable[row][ColName].ToString() == value.ToString() Otherwise you have to be sure that all the objects you may pass the routine implement the == operator...
I would still think about why I was doing this in this (rather odd) way in the first place.
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
This is the temporal solution I have implemented, converting ToString. As you say, otherwise I should be sure to implement "==" operator for every object.
Thanks for your reply!
|
|
|
|
|
Assuming that you are not actually passing objects in, you might be able to use generics here:
public int SeekRow<T>(string colName, T value)
{
for (row = 0; ...)
{
if ((T)myDataSet.myTable[row][ColName] == value)
{
return row;
}
}
return -1;
}
int row1 = SeekRow("Age", 25);
int row2 = SeekRow("Name", "John Doe");
|
|
|
|
|
Nice!
I didn't know that. Just becouse I am returning to c# programmin after... 6 years without programming at all!! And I have only installed .NET Framework 1, do I wasn't aware of Generics.
I will try!
Thanks!
|
|
|
|
|
If you want to use generics, you will need at least .NET 2.0 (might as well just get 3.5 since it's the newest and contains 2.0)
|
|
|
|
|
System.Convert.ChangeType ? The only useful member of Convert.
|
|
|
|
|
Hi Guys,
I am creating a custom component for sending emails( due to project requirements).
I am using telnet commands for sending mails.
I want to execute the inbuilt authentication method provided by system.net.mail.smtpclient class and authenticate my stream.
Please help.
Thanks in advance.
Ankit
|
|
|
|
|
Hi,
and did you already tried to do this by reflection? Did you get an error or exception?
Regards
Sebastian
|
|
|
|
|
I am new to c#.
I am looking for a code snippet that will help me out.
Regards,
Ankit
|
|
|
|
|
So did I get you right, you want to create a stream outside of SmtpClient and authenticate the stream with the private method of SmtpClient? So does the method signature accepts a stream? If yes, it could propably work, if not then you have to use the SmtpClient class or authenticate by your own.
Could you provide the method signature so that it is possible to write some code around...
Regards
Sebastian
|
|
|
|
|
You got me right there..
But I am afraid I don't know if any such method exists...
Regards,
Ankit
|
|
|
|
|
To check if such a method exists you could use a reflector, like .NET reflector...
http://www.red-gate.com/products/reflector/[^]
Locate the SmtpClient-class within System.dll and check the existing methods. But the best way would be either implementing the authentication by yourself or using the SmtpClient-class.
Regards
Sebastian
|
|
|
|
|
Thanks,
I already tried reflector without luck.
And i have managed to code an authentication mechanism usign "Auth login" command.
But there might be other set of authentication command which i dont know.So i am just worried.
Thanks for the quick replies anyway.
Regards,
Ankit
|
|
|
|
|
|
Thanks again,
I just ran reflector again on the system.net.mail dll and found out a AuthCommand class and one smtpauthenticaiton module class.
Any code snippet will still be helpful.
Regards,
Ankit
|
|
|
|
|
i have listview with mutltiple column...nw i want to iterate only items of first column.hw can this be done?
|
|
|
|