SourceCode/PROMS/DataLoader/LoadConfig.cs
Rich 7d1f4f4200 Added RevDate and ReviewDate properties to FixItem class
Added applicability and procedureset elements to ConfigFile class when
processing proc.ini file
Added masterdir attribute to ConfigFile class when processing proc.ini file
Replaced direct call to database with CSLA Command object in ClearData method of Loader class
2012-12-04 22:35:07 +00:00

243 lines
8.4 KiB
C#

// ========================================================================
// Copyright 2006 - Volian Enterprises, Inc. All rights reserved.
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
// ------------------------------------------------------------------------
// $Workfile: $ $Revision: $
// $Author: $ $Date: $
//
// $History: $
// ========================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Xml;
using System.IO;
using System.Text;
using VEPROMS.CSLA.Library;
namespace Config
{
public class ConfigFile
{
#region Log4Net
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region MigrateStrings
// the following lists are used for storing the element and attribute names
// for migrating of ini & cfg files. The names stored in these lists are
// those that should be migrated. If not in this list, the data (either element
// or attribute name) is prefaced with a 'z'. At some point in the future, those
// names with a 'z' will be removed.
public List<string> listIni_EleName = new List<string>();
public List<string> listIni_AttrName = new List<string>();
private void SetIniEleName()
{
// veproms.ini
listIni_EleName.Add("graphics");
listIni_EleName.Add("color");
listIni_EleName.Add("print");
listIni_EleName.Add("startup");
listIni_EleName.Add("data integrity");
listIni_EleName.Add("wordprocessor");
listIni_EleName.Add("procedurelisttabstops");
// proc.ini
listIni_EleName.Add("rodefaults");
listIni_EleName.Add("display");
listIni_EleName.Add("backgrounddefaults");
listIni_EleName.Add("unit");
listIni_EleName.Add("applicability");
listIni_EleName.Add("procedureset");
// roapp.ini
listIni_EleName.Add("roapp");
// <user>.cfg
listIni_EleName.Add("spelldictionary");
// listIni_EleName.Add("wordprocessor"); - already in here.
}
private void SetIniAttrName()
{
//veproms.ini
listIni_AttrName.Add("defaultext");
listIni_AttrName.Add("ro");
listIni_AttrName.Add("editbackground");
listIni_AttrName.Add("black");
listIni_AttrName.Add("blue");
listIni_AttrName.Add("green");
listIni_AttrName.Add("cyan");
listIni_AttrName.Add("red");
listIni_AttrName.Add("magenta");
listIni_AttrName.Add("brown");
listIni_AttrName.Add("lightgray");
listIni_AttrName.Add("darkgray");
listIni_AttrName.Add("ligthblue");
listIni_AttrName.Add("lightgreen");
listIni_AttrName.Add("lightcyan");
listIni_AttrName.Add("lightred");
listIni_AttrName.Add("lightmagenta");
listIni_AttrName.Add("yellow");
listIni_AttrName.Add("white");
listIni_AttrName.Add("underlinewidth");
listIni_AttrName.Add("verticalOffset");
listIni_AttrName.Add("strokewidth");
listIni_AttrName.Add("strokewidthbold");
listIni_AttrName.Add("messageboxtitle");
listIni_AttrName.Add("messagefile");
listIni_AttrName.Add("enableindexcheck");
listIni_AttrName.Add("wordwrap");
listIni_AttrName.Add("procedurenumbertab");
listIni_AttrName.Add("proceduretitletab");
// proc.ini
listIni_AttrName.Add("setpoint");
listIni_AttrName.Add("graphics");
listIni_AttrName.Add("ropath");
listIni_AttrName.Add("display");
listIni_AttrName.Add("sectiontitle");
listIni_AttrName.Add("sectionnumber");
listIni_AttrName.Add("number");
listIni_AttrName.Add("othernumber");
listIni_AttrName.Add("name");
listIni_AttrName.Add("othername");
listIni_AttrName.Add("text");
listIni_AttrName.Add("othertext");
listIni_AttrName.Add("id");
listIni_AttrName.Add("otherid");
listIni_AttrName.Add("procedurenumber");
listIni_AttrName.Add("masterdir");
// roapp.ini
listIni_AttrName.Add("extention"); // NOTE MIS-SPELLING was in 16-bit program!
// <user>.cfg
listIni_AttrName.Add("custom");
listIni_AttrName.Add("page");
listIni_AttrName.Add("toolbar");
listIni_AttrName.Add("paragraph");
listIni_AttrName.Add("ruler");
listIni_AttrName.Add("userphone1");
listIni_AttrName.Add("userphone2");
listIni_AttrName.Add("userloc1");
listIni_AttrName.Add("userloc2");
}
#endregion
#region LoadDataCode
public ConfigFile()
{
}
public void LoadUsrCfg(User user, string vepromspath)
{
string cfgpath = vepromspath + "\\config";
if (!Directory.Exists(cfgpath))
{
log.Info("No user cfgs found in config directory - did not migrate any user cfgs");
return;
}
DirectoryInfo di = new DirectoryInfo(cfgpath);
FileInfo[] fis = di.GetFiles("*.cfg");
foreach (FileInfo fi in fis)
{
string cfgname = fi.Name.Substring(0, fi.Name.IndexOf("."));
if (cfgname.ToUpper() == user.UserID.ToUpper())
{
// Get Users table fields by reading the cfg file into a buffer & looking
// for the UserNetworkId and UserName fields.
StreamReader myReader = new StreamReader(fi.FullName);
string sLine;
string UserLogin = null;
string UserName = null;
int indx = -1;
while ((sLine = myReader.ReadLine()) != null && (UserLogin == null || UserName == null))
{
if (sLine.Length > 0 && sLine.Substring(0, 1) != ";")
{
if ((indx = sLine.ToLower().IndexOf("usernetworkid")) >= 0)
{
indx = sLine.IndexOf("=", indx + 13);
UserLogin = sLine.Substring(indx + 1, sLine.Length - indx - 1).Trim();
}
else if ((indx = sLine.ToLower().IndexOf("username")) >= 0)
{
indx = sLine.IndexOf("=", indx + 8);
UserName = sLine.Substring(indx + 1, sLine.Length - indx - 1).Trim();
}
}
}
myReader.Close();
// get the xml to set the config field
XmlDocument d = IniToXml(fi.FullName);
user.Config = d == null ? null : d.InnerXml;
user.UserLogin = UserLogin;
user.UserName = UserName;
user.CFGName = cfgname;
break;
}
}
}
public XmlDocument LoadSystemIni(string vepromspath)
{
string inipath = vepromspath + "\\veproms.ini";
if (!File.Exists(inipath))
{
log.InfoFormat("Did not migrate {0} - file not found", inipath);
return null;
}
XmlDocument d = IniToXml(inipath);
// see if default image file extension was set, if not make it TIF
XmlNode gr = d.SelectSingleNode("//Graphics");
XmlNode ext = null;
if (gr != null) ext = gr.SelectSingleNode("@defaultext");
if (ext == null)
{
// if the graphics node doesn't exist, make it.
if (gr == null)
{
gr = d.CreateElement("Graphics");
d.DocumentElement.AppendChild(gr);
}
XmlAttribute xa = d.CreateAttribute("defaultext");
xa.Value = "TIF";
gr.Attributes.Append(xa);
}
return d;
}
public XmlDocument LoadRoAppIni(string ropath)
{
string inipath = ropath + "\\roapp.ini";
// not an error if it does not exist - just return null.
if (!File.Exists(inipath)) return null;
XmlDocument d = IniToXml(inipath);
return d;
}
public XmlDocument IniToXml(string path)
{
FileInfo fi = new FileInfo(path);
if (fi.Exists)
{
PrivateProfile ppCfg;
if (listIni_AttrName == null || listIni_AttrName.Count == 0) SetIniAttrName();
if (listIni_EleName == null || listIni_EleName.Count == 0) SetIniEleName();
ppCfg = new PrivateProfile(path, listIni_EleName, listIni_AttrName);
return ppCfg.XML();
}
return null;
}
#endregion
}
}