SourceCode/PROMS/DataLoader/LoadTreeDB.cs
2006-11-14 15:58:03 +00:00

111 lines
4.3 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 Volian.CSLA.Library;
using vlnObjectLibrary;
using vlnServerLibrary;
using Org.Mentalis.Files;
using Config;
using Utils;
namespace DataLoader
{
public partial class frmLoader : Form
{
private List<Folder> vlnDataPathFolders() // was vlnDataPath
{
List<Folder> dpf = new List<Folder>();
// Get path to config file
string sCfg = Environment.GetEnvironmentVariable("veconfig");
IniReader cfg = new IniReader(sCfg);
// Get DataPath
string sDP = cfg.ReadString("menu", "DataPath");
// Split DataPath into directories
foreach (string s1 in sDP.Split(";".ToCharArray()))
{
if (s1.Length > 0)
{
string[] s2 = s1.Split(",".ToCharArray());
Folder fld = Folder.MakeFolder(sysFolder.FolderID, dbConn.DBID, s2[1], s2[0], null);
dpf.Add(fld);
}
}
return dpf;
}
private int cslaObject(vlnObject vb, int dbid, int parentid, TreeNode tn)
{
switch (vb.Type)
{
case "plant":
case "set":
Folder fld = Folder.MakeFolder(parentid, dbid, vb.Title, vb.Path, string.Empty);
tn.Tag = fld;
return fld.FolderID;
case "version":
ConfigFile cfg = new ConfigFile();
XmlDocument d = cfg.IniToXml(vb.Path + "\\proc.ini");
FolderConfig fld_cfg = new FolderConfig(d==null?"":d.InnerXml);
// translate curset.dat into xml & add to d (somehow).
string csfile = string.Format("{0}\\curset.dat",vb.Path);
if (File.Exists(csfile))
{
CurSet cs = new CurSet(csfile);
try
{
fld_cfg = cs.Convert(fld_cfg);
}
catch (Exception ex)
{
log.ErrorFormat("error in convert curset.dat, ex = {0}", ex.Message);
}
}
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();
}
DocVersion v = DocVersion.MakeDocVersion(parentid, (int)DocVersionType(vb.Path.ToLower()), thetitle, vb.Path, 0, fld_cfg == null ? null : fld_cfg.ToString());
tn.Tag = v;
return v.VersionID;
}
return 0;
}
private void MigrateChildren(vlnObject vb, vlnServer vs, int dbid, int parentid, TreeNode tn)
{
if (vb.Type != "version")
{
vb.LoadChildren(vs.GetChildren(vb.ToString()));
List<vlnObject> lv = vb.Children;
foreach (vlnObject vbc in lv)
{
TreeNode tnc = tn.Nodes.Add(vbc.Title);
int idc = cslaObject(vbc, dbid, parentid, tnc);
MigrateChildren(vbc, vs, dbid, idc, tnc);
}
}
}
}
}