2 using System.Collections.Generic;
4 using System.Text.RegularExpressions;
6 using System.Xml.Serialization;
7 using Seci.Definitions;
14 internal static class ConfigurationIO
35 for (
int i = 0; i < temp.Blocks.Count; ++i)
41 temp.Blocks[i].ValueFormatting = temp.Blocks[i].ValueFormatting.Replace(
'#',
'0');
44 if (!temp.
Blocks[i].SaveSettings)
46 temp.Blocks[i].UnderRunControl =
false;
47 temp.Blocks[i].LowerLimit = Double.NegativeInfinity;
48 temp.Blocks[i].UpperLimit = Double.PositiveInfinity;
49 temp.Blocks[i].RunControlValue =
"";
55 List<String> compNames =
new List<String>();
56 compNames.AddRange(temp.Components.Components);
59 for (
int i = 0; i < compNames.Count; ++i)
63 temp.Components[i] = (DeserialiseConfig(
Status.
ConfigDir + compNames[i]));
67 for (
int j = 0; j < temp.Components[i].Blocks.Count; ++j)
69 temp.Components[i].Blocks[j].OwningComponent = temp.Components[i].ConfigName;
70 if (!temp.
Components[i].Blocks[j].SaveSettings)
72 temp.Components[i].Blocks[j].UnderRunControl =
false;
73 temp.Components[i].Blocks[j].LowerLimit = Double.NegativeInfinity;
74 temp.Components[i].Blocks[j].UpperLimit = Double.PositiveInfinity;
75 temp.Components[i].Blocks[j].RunControlValue =
"";
80 temp.Blocks.AddDictionary(temp.Components[i].Blocks);
84 Seci.Managers.AlertsMgr.AddComponentBox(temp.Alerts, temp.Components[i].Alerts, compNames[i]);
87 for (
int j = 0; j < temp.Components[i].GraphDefinitions.Count; ++j)
89 temp.Components[i].GraphDefinitions[j].OwningComponent = temp.Components[i].ConfigName;
92 temp.GraphDefinitions.AddRange(temp.Components[i].GraphDefinitions);
97 throw new Exception(
"Could not load component: " + temp.
Components[i].ConfigName);
106 throw new ArgumentException(e.Message);
116 public static Configuration DeserialiseConfig(String fileName)
119 FileStream stream =
new FileStream(fileName, FileMode.Open, FileAccess.Read);
124 XmlSerializer deserialize =
new XmlSerializer(typeof(
Configuration));
131 throw new ArgumentException(e.Message);
151 public static bool OkayToSave(String configName, Boolean manager)
156 String fileName = Status.ConfigDir + configName;
159 FileInfo fi =
new FileInfo(fileName);
164 XmlDocument conf = createXmlDocFromConfig(fileName);
167 XmlNodeList nodelist = conf.SelectNodes(
"/Configuration/SavedAsManager");
169 if (nodelist.Count > 0)
172 if ((nodelist[0].InnerText ==
"true") && (manager ==
false))
183 catch (Exception err)
186 ErrorLogger.SeciError(
"OkayToSave", err);
198 public static void SaveConfig(
Configuration conf, Boolean isAutosave, String fileName)
200 FileInfo fi =
new FileInfo(fileName);
204 fi.IsReadOnly =
false;
212 FileStream stream =
new FileStream(fileName, FileMode.Create);
217 XmlSerializer serialize =
new XmlSerializer(typeof(
Configuration));
218 serialize.Serialize(stream, conf);
224 throw new ArgumentException(e.Message);
232 for (
int i = 0; i < conf.AssociatedFiles.Count; ++i)
234 conf.AssociatedFiles[i].FileData = null;
244 private static void createLocalBackup(String configName, FileInfo fi)
250 List<FileInfo> files =
new List<FileInfo>();
251 files.AddRange(di.GetFiles());
253 string versionMatch = configName.Replace(
"+",
@"\+") +
@"\.\d+$";
254 Regex r =
new Regex(versionMatch, RegexOptions.IgnoreCase);
258 foreach (FileInfo f
in files)
260 if (r.Match(f.Name).Success)
262 int tempVer = Convert.ToInt32(f.Name.Substring(f.Name.LastIndexOf(
'.') + 1));
263 if (tempVer > version)
270 fi.MoveTo(fi.FullName +
"." + (++version).ToString());
279 private static XmlDocument createXmlDocFromConfig(String fileName)
283 XmlDocument conf =
new XmlDocument();
292 throw new ArgumentException(e.Message);
Boolean Contains(String blockName)
Wrapper for standard Dictionary "Contains" All keys are lowercase.
Class for holding the standard run-time settings for SECI. A large percentage of the information held...
This class contains all the information that defines the configuration at the SECI level and contains...