133 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			133 lines
		
	
	
		
			5.2 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;
 | |
| using vlnObjectLibrary;
 | |
| using vlnServerLibrary;
 | |
| using Org.Mentalis.Files;
 | |
| using Config;
 | |
| using Utils;
 | |
| 
 | |
| namespace DataLoader
 | |
| {
 | |
| 	public partial class Loader
 | |
| 	{
 | |
| 		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, dbConn, s2[1], s2[0], FolderName(s2[0]), null, null, DateTime.Now, "Migration");
 | |
|                     dpf.Add(fld);
 | |
| 				}
 | |
| 			}
 | |
| 			return dpf;
 | |
| 		}
 | |
| 		private string FolderName(string Path)
 | |
| 		{
 | |
| 			int ind = Path.LastIndexOf("\\");
 | |
| 			if (ind == Path.Length-1 || ind < 0) return Path;
 | |
| 			return Path.Substring(ind + 1);
 | |
| 		}
 | |
|         private object cslaObject(vlnObject vb, Connection dbConn, Object parfld, TreeNode tn)
 | |
|         {
 | |
|             switch (vb.Type)
 | |
|             {
 | |
|                 case "plant":
 | |
|                 case "set":
 | |
| 					Folder fld = Folder.MakeFolder((Folder)parfld, dbConn, vb.Title, vb.Path, FolderName(vb.Path), null, null, DateTime.Now, "Migration");
 | |
|                     tn.Tag = fld;
 | |
|                     return (object) fld;
 | |
|                 case "version":
 | |
|                     ConfigFile cfg = new ConfigFile();
 | |
|                     
 | |
|                     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);
 | |
|                         }
 | |
|                     }
 | |
|                     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;
 | |
|                     Format format = null;
 | |
|                     if (defPlantFmt != null && defPlantFmt != "") 
 | |
| 					{
 | |
| 						format = GetFormat(defPlantFmt);
 | |
| 					}
 | |
| 					else
 | |
| 						format = Format.Get(1);
 | |
| 					DocVersion v = DocVersion.MakeDocVersion(tmpfld, (int)DocVersionType(vb.Path.ToLower()), thetitle, vb.Path.ToLower(), null, format, fld_cfg == null ? null : fld_cfg.ToString(), DateTime.Now, "Migration");
 | |
|                     tn.Tag = v;
 | |
| 						//TODO: load procedure set
 | |
| 						  MigrateDocVersion(v, false);
 | |
| 						  return (object)v;
 | |
|             }
 | |
|             return 0;
 | |
|         }
 | |
|         private void MigrateChildren(vlnObject vb, vlnServer vs, Connection dbConn, Object parent, 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);
 | |
|                     object idc = cslaObject(vbc, dbConn, parent, tnc);
 | |
| 					frmMain.Status = "Loading " + vbc.Title;
 | |
|                     MigrateChildren(vbc, vs, dbConn, idc, tnc);
 | |
|                 }
 | |
|             }
 | |
| 			frmMain.Status = " ";
 | |
|         }
 | |
| 	}
 | |
| } | 
