From cd3e0af5343a0ffab1b505bb71671736ec87c730 Mon Sep 17 00:00:00 2001 From: Rich Date: Tue, 4 Dec 2012 22:35:48 +0000 Subject: [PATCH] Added call to AddSlaveUnits method of ConfigInfo class when processing proc.ini file in Loader class Added private methods AddSlaveUnits, GetUnitNames and GetMasterDir to Loader class --- PROMS/DataLoader/LoadTreeDB.cs | 175 +++++++++++++++++++++++---------- 1 file changed, 123 insertions(+), 52 deletions(-) diff --git a/PROMS/DataLoader/LoadTreeDB.cs b/PROMS/DataLoader/LoadTreeDB.cs index 52953447..c8ebab1a 100644 --- a/PROMS/DataLoader/LoadTreeDB.cs +++ b/PROMS/DataLoader/LoadTreeDB.cs @@ -107,51 +107,52 @@ namespace DataLoader DocVersion v = GetDocVersionFromName((Folder)parfld, vb.Title); if (v == null) { - ConfigFile cfg = new ConfigFile(); + ConfigFile cfg = new ConfigFile(); + + XmlDocument d = cfg.IniToXml(vb.Path + "\\proc.ini"); + AddSlaveUnits(d, vb.Path); + //DocVersionConfig fld_cfg = new DocVersionConfig(d == null ? "" : d.InnerXml); + FolderConfig fld_cfg = (d==null)?null:new FolderConfig(d.InnerXml); + // translate curset.dat into xml & add to d (somehow). + string csfile = string.Format("{0}\\curset.dat",vb.Path); + string defPlantFmt = null; + if (File.Exists(csfile)) + { + CurSet cs = new CurSet(csfile); + try + { + if (fld_cfg == null) fld_cfg = new FolderConfig(); + fld_cfg = cs.Convert(fld_cfg); + defPlantFmt = cs.GetDefFmt(); + } + catch (Exception ex) + { + log.ErrorFormat("error in convert curset.dat, ex = {0}", ex.Message); + frmMain.AddError(ex, "error in convert curset.dat"); + } + } + // *** RHM 20120613 - Fix + // *** This was naming the DocVersion to the folder name + //string titlepath = vb.Path + "\\" + "Title"; + //FileInfo fi = new FileInfo(titlepath); + //string thetitle = vb.Title; + //if (File.Exists(titlepath)) + //{ + // StreamReader myReader = new StreamReader(titlepath); + // thetitle = myReader.ReadLine(); + // myReader.Close(); + //} + Folder tmpfld = (Folder)parfld; + FormatInfo format = null; + if (defPlantFmt != null && defPlantFmt != "") + { + format = GetFormat(defPlantFmt); + } + else + format = FormatInfo.Get(1); - XmlDocument d = cfg.IniToXml(vb.Path + "\\proc.ini"); - //DocVersionConfig fld_cfg = new DocVersionConfig(d == null ? "" : d.InnerXml); - FolderConfig fld_cfg = (d == null) ? null : new FolderConfig(d.InnerXml); - // translate curset.dat into xml & add to d (somehow). - string csfile = string.Format("{0}\\curset.dat", vb.Path); - string defPlantFmt = null; - if (File.Exists(csfile)) - { - CurSet cs = new CurSet(csfile); - try - { - if (fld_cfg == null) fld_cfg = new FolderConfig(); - fld_cfg = cs.Convert(fld_cfg); - defPlantFmt = cs.GetDefFmt(); - } - catch (Exception ex) - { - log.ErrorFormat("error in convert curset.dat, ex = {0}", ex.Message); - frmMain.AddError(ex, "error in convert curset.dat"); - } - } - // *** RHM 20120613 - Fix - // *** This was naming the DocVersion to the folder name - //string titlepath = vb.Path + "\\" + "Title"; - //FileInfo fi = new FileInfo(titlepath); - //string thetitle = vb.Title; - //if (File.Exists(titlepath)) - //{ - // StreamReader myReader = new StreamReader(titlepath); - // thetitle = myReader.ReadLine(); - // myReader.Close(); - //} - Folder tmpfld = (Folder)parfld; - FormatInfo format = null; - if (defPlantFmt != null && defPlantFmt != "") - { - format = GetFormat(defPlantFmt); - } - else - format = FormatInfo.Get(1); - - using (Format fmt = format.Get()) - v = DocVersion.MakeDocVersion(tmpfld, (int)DocVersionType(vb.Path.ToLower()), vb.Title, vb.Path.ToLower(), null, fmt, fld_cfg == null ? null : fld_cfg.ToString(), DateTime.Now, "Migration"); + using(Format fmt = format.Get()) + v = DocVersion.MakeDocVersion(tmpfld, (int)DocVersionType(vb.Path.ToLower()), vb.Title, vb.Path.ToLower(), null, fmt, fld_cfg == null ? null : fld_cfg.ToString(), DateTime.Now, "Migration"); } tn.Tag = v; MigrateDocVersion(v, false); @@ -159,6 +160,76 @@ namespace DataLoader } return 0; } + + private void AddSlaveUnits(XmlDocument d, string path) + { + string masterDir = GetMasterDir(d); + if (masterDir == null) return; + DirectoryInfo master = new DirectoryInfo(path); + if (master.Name.ToUpper() != masterDir.ToUpper()) return; + List names = GetUnitNames(d); + DirectoryInfo[] slaves = master.Parent.GetDirectories(masterDir.ToUpper().Replace(".PRC",".SL*")); + XmlDocument units = new XmlDocument(); + units.LoadXml(""); + int idx = 0; + foreach (DirectoryInfo slave in slaves) + { + FileInfo[] inis = slave.GetFiles("proc.ini"); + if (inis.Length > 0) + { + FileInfo ini = inis[0]; + ConfigFile cfg = new ConfigFile(); + XmlDocument xSlave = cfg.IniToXml(ini.FullName); + xSlave.LoadXml(xSlave.OuterXml.Replace(" GetUnitNames(XmlDocument d) + { + XmlNode zapp = d.SelectSingleNode("//Unit"); + if (zapp == null) return null; + XmlNode zmstr = zapp.Attributes.GetNamedItem("Name"); + if (zmstr == null) return null; + string[] names = zmstr.InnerText.Split(",".ToCharArray()); + return new List(names); + } + + private static string GetMasterDir(XmlDocument d) + { + XmlNode zapp = d.SelectSingleNode("//Applicability"); + if (zapp == null) return null; + XmlNode zmstr = zapp.Attributes.GetNamedItem("MasterDir"); + if (zmstr == null) return null; + return zmstr.InnerText; + } private string _OnlyThisFolder; public string OnlyThisFolder { @@ -196,17 +267,17 @@ namespace DataLoader { if (vb.Type != "version") { - vb.LoadChildren(vs.GetChildren(vb.ToString())); + vb.LoadChildren(vs.GetChildren(vb.ToString())); List lv = vb.Children; foreach (vlnObject vbc in lv) { - if (vbc.Path.ToUpper().StartsWith(OnlyThisFolder) || OnlyThisFolder.StartsWith(vbc.Path.ToUpper())) - { - TreeNode tnc = tn.Nodes.Add(vbc.Title); - object idc = cslaObject(vbc, dbConn, parent, tnc); - frmMain.Status = "Loading " + vbc.Title; - MigrateChildren(vbc, vs, dbConn, idc, tnc); - } + if (vbc.Path.ToUpper().StartsWith(OnlyThisFolder) || OnlyThisFolder.StartsWith(vbc.Path.ToUpper())) + { + TreeNode tnc = tn.Nodes.Add(vbc.Title); + object idc = cslaObject(vbc, dbConn, parent, tnc); + frmMain.Status = "Loading " + vbc.Title; + MigrateChildren(vbc, vs, dbConn, idc, tnc); + } } } frmMain.Status = " ";