1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
DateTime startTime = DateTime.Now;
Console.WriteLine("\n\rFunction Scan starts at " + startTime.ToString("HH:mm:ss") + "...");
ConcurrentStack<XDocument> listeXml = new ConcurrentStack<XDocument>();
XDocument xml =
new XDocument(
new XElement("item", new XAttribute("name", ""), new XAttribute("isDir", "1"))
);
listeXml.Push(xml);
if (CifsFunctions.ListFiles3(@"\\192.168.6.152\360store\FOOK\SOURCE\TestArchive\ARCHIVE 1", @"\\192.168.6.152\360store\FOOK\SOURCE", "spark", "spark", "", listeXml, NbItemsPerRequest))
{
Console.WriteLine("File list retrieved in " + DateTime.Now.Subtract(startTime).ToString(@"hh\:mm\:ss"));
for (int i = listeXml.Count - 1; i >= 0; i--)
{
int Nb = listeXml.ToArray()[i].Root.Descendants("item").Where(x => (string)x.Attribute("isDir") == "1").Count() - 1;
int Nb2 = listeXml.ToArray()[i].Root.Descendants("item").Where(x => (string)x.Attribute("isDir") == "0").Count();
Console.WriteLine("Nb Directories = " + Nb.ToString() + " / Nb Files = " + Nb2.ToString());
}
}
return true;
}
public static bool ListFiles3(string DirPath, string RootPath, string WinLogin, string WinPassword, string Domain, ConcurrentStack<XDocument> liste, int NbItemsPerItem)
{
bool bFail = false;
string errMsg = "";
int errorCode = 0;
bool bConnected = Directory.Exists(DirPath);
if (!bConnected)
{
if (CifsFunctions.ConnectToSharedFolder(Domain, DirPath, WinLogin, WinPassword, out errorCode, out errMsg))
{
bConnected = Directory.Exists(DirPath);
}
}
if (bConnected)
{
myParameterObject o = new myParameterObject(0);
if (!RecursiveScan3(DirPath, RootPath + @"\", liste, NbItemsPerItem, o, null, liste.Count - 1))
{
bFail = true;
}
}
else
{
bFail = true;
}
return (!bFail);
}
private static XElement GenerateNodeFromPath4(XDocument doc, XElement ParentElt, string itemPath, string itemName, bool isDir, long size)
{
XElement ParentEltReturned = null;
if (ParentElt == null)
{
string[] items = itemPath.Split(Delimiter);
ParentElt = doc.Root;
XElement elt;
for (int i = 0; i < items.Length - 1; i++)
{
elt = ElementExists2(ParentElt, items[i], "", true);
if (elt == null)
{
XElement el = new XElement("item");
el.SetAttributeValue("name", items[i]);
el.SetAttributeValue("isDir", "1");
ParentElt.Add(el);
ParentElt = el;
}
else
{
ParentElt = elt;
}
}
}
ParentEltReturned = ParentElt;
if (isDir)
{
XElement el = new XElement("item");
el.SetAttributeValue("name", itemName);
el.SetAttributeValue("isDir", "1");
ParentElt.Add(el);
ParentEltReturned = el;
}
else
{
string filenameWithoutExt;
string fileExt;
int idx = itemName.LastIndexOf('.');
if (idx >= 0)
{
filenameWithoutExt = itemName.Substring(0, idx);
fileExt = itemName.Substring(idx + 1);
}
else
{
filenameWithoutExt = itemName;
fileExt = "";
}
XElement el = new XElement("item");
el.SetAttributeValue("ext", fileExt);
el.SetAttributeValue("name", filenameWithoutExt);
el.SetAttributeValue("isDir", "0");
if (size >= 0)
el.SetAttributeValue("size", size);
ParentElt.Add(el);
}
return ParentEltReturned;
} |
Partager