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
|
private static void parseJsFile(FilePath filePath, Boolean isPathSupp, StreamWriter logwriter, List<string> newlines)
{
try
{
if (System.IO.File.Exists(filePath.pathfilename))
{
using (System.IO.StreamReader file = new System.IO.StreamReader(filePath.pathfilename, System.Text.Encoding.UTF8))
{
try
{
// Extraction du contenu XML présent dans le csh.js :
// gXMLBuffer ="<?xml version=\"1.0\" encoding=\"utf-8\" ?><csh-info><item ...
String xmlBuffer = file.ReadToEnd();
xmlBuffer = xmlBuffer.Remove(0, 13);
xmlBuffer = xmlBuffer.Remove(xmlBuffer.Length-2, 2);
xmlBuffer = xmlBuffer.Replace("\\\"", "\"");
//System.IO.File.WriteAllText(@"c:\temp\test.xml", xmlBuffer);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlBuffer);
XmlNode root = xmlDoc.DocumentElement;
XmlNodeList nodeList = root.SelectNodes("/csh-info/item");
foreach (XmlNode node in nodeList)
{
/*exemple de ligne traitée
<item topicurl="Utilisateurs_Acces/GroupesdeTravail.htm" mapnum="400000063" mapid="GroupesdeTravail"/>
*/
string newline;
if (isPathSupp)
{
newline = node.Attributes["mapnum"].Value + ";" + filePath.pathSuppname + @"/topic.htm#t=" + node.Attributes["topicurl"].Value;
}
else
{
newline = node.Attributes["mapnum"].Value + ";topic.htm#t=" + node.Attributes["topicurl"].Value;
}
if (!string.IsNullOrEmpty(newline))
{
int indexLine = -1;
if (newlines.Count > 0)
indexLine = newlines.FindIndex(newline.Contains);
if (indexLine < 0)
newlines.Add(newline);
}
}
}
catch (Exception ex)
{
logwriter.WriteLine("Erreur lors de la lecture du fichier: " + filePath.pathfilename);
logwriter.WriteLine(ex.Message);
}
}
}
}
catch (Exception ex)
{
logwriter.WriteLine("Impossible de lire le fichier: " + filePath.pathfilename);
throw new Exception("Erreur lors de la lecture du fichier, " + filePath.pathfilename + " : " + ex.Message);
}
} |