2 using System.Collections.Generic;
6 using System.Xml.XPath;
9 using System.Text.RegularExpressions;
11 namespace SeciControls
16 public string Title {
get;
private set; }
17 public string Start {
get;
private set; }
19 public string Uamps {
get;
private set; }
20 public string Mev {
get;
private set; }
21 public string Users {
get;
private set; }
22 public string RB {
get;
private set; }
24 public Entry(String run, String title, String start, String duration, String uamps, String mev, String users, String rb)
44 entries =
new List<Entry>();
47 XmlDocument mainXml =
new XmlDocument();
48 mainXml.Load(journalDir +
"\\" + mainFileName);
50 XmlNodeList nodelist = mainXml.SelectNodes(
"/journal/file");
57 Double currentCycle = 0;
58 String currentCycleFileName =
"";
61 for (
int i = 0; i < nodelist.Count; ++i)
64 String filename = nodelist[i].Attributes[
"name"].Value.ToString();
67 String[] vals = Regex.Split(filename,
@"[_\.]");
72 if (Double.TryParse(vals[1] +
"." + vals[2], out cycleNumber) && cycleNumber > currentCycle)
74 currentCycleFileName = journalDir +
"\\" + filename;
79 if (nodelist.Count == 1)
82 currentCycleFileName = journalDir +
"\\" + filename;
87 if (currentCycleFileName !=
"")
89 FileInfo fi =
new FileInfo(currentCycleFileName);
93 throw new FileNotFoundException(
"The cycle journal file does not exist");
108 XmlDocument cycleXml =
new XmlDocument();
112 FileStream inStream =
new FileStream(currentCycleFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
113 StreamReader sr =
new StreamReader(inStream, Encoding.GetEncoding(
"Windows-1252"));
118 XmlNamespaceManager nsMgr =
new XmlNamespaceManager(cycleXml.NameTable);
119 nsMgr.AddNamespace(
"nx",
"http://definition.nexusformat.org/schema/3.0");
124 for (
int i = cycleXml.ChildNodes[1].ChildNodes.Count - 1; i >= 0; --i)
126 String title = cycleXml.ChildNodes[1].ChildNodes[i].SelectSingleNode(
"nx:title", nsMgr).InnerText.ToString().Trim();
127 String username = cycleXml.ChildNodes[1].ChildNodes[i].SelectSingleNode(
"nx:user_name", nsMgr).InnerText.ToString().Trim();
128 String runnumber = cycleXml.ChildNodes[1].ChildNodes[i].SelectSingleNode(
"nx:run_number", nsMgr).InnerText.ToString().Trim();
129 String start = cycleXml.ChildNodes[1].ChildNodes[i].SelectSingleNode(
"nx:start_time", nsMgr).InnerText.ToString().Trim().Replace(
'T',
' ');
130 String duration = cycleXml.ChildNodes[1].ChildNodes[i].SelectSingleNode(
"nx:duration", nsMgr).InnerText.ToString().Trim();
131 String uamps = cycleXml.ChildNodes[1].ChildNodes[i].SelectSingleNode(
"nx:proton_charge", nsMgr).InnerText.ToString().Trim();
132 String mev = cycleXml.ChildNodes[1].ChildNodes[i].SelectSingleNode(
"nx:total_mevents", nsMgr).InnerText.ToString().Trim();
133 String rb = cycleXml.ChildNodes[1].ChildNodes[i].SelectSingleNode(
"nx:experiment_identifier", nsMgr).InnerText.ToString().Trim();
137 if (Int32.TryParse(duration, out secs))
139 duration =
new TimeSpan(0, 0, secs).ToString();
143 duration =
"UNSPECIFIED";
146 entries.Add(
new Entry(runnumber, title, start, duration, uamps, mev, username, rb));
Entry(String run, String title, String start, String duration, String uamps, String mev, String users, String rb)