DataLoader changes during development
This commit is contained in:
@@ -20,43 +20,147 @@ using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Volian.CSLA.Library;
|
||||
using VEPROMS.CSLA.Library;
|
||||
|
||||
namespace DataLoader
|
||||
{
|
||||
public partial class frmLoader : Form
|
||||
public partial class Loader
|
||||
{
|
||||
private int AddTrans(int fromId, DataRow dr)
|
||||
private string AddTrans(Content fromCon, DataRow dr, DataRow dr2)
|
||||
{
|
||||
//TODO: ZTransitions tr.Oldto = dr["OLDTO"].ToString();
|
||||
string thekey = dr["TONUMBER"].ToString() + "|" + dr["TOSEQUENCE"].ToString();
|
||||
string dti = dr["DTI"].ToString().PadRight(18, ' ');
|
||||
string userid = dti.Substring(13, 5).Trim();
|
||||
int itype = 0;
|
||||
ConfigInfo ci = null;
|
||||
// The transition type was stored as a character & also, when read in thru
|
||||
// ado.net may have been converted into unicode. So in order to get the
|
||||
// correct type, first, use the TextConvert to eliminate the conversion done
|
||||
// by ado.net. Then convert to a number. The 'anding of 0x80' flags that it
|
||||
// is a formatted transition (i.e. this was done for byron/braidwood to
|
||||
// show the transition with a page number or not). The 'anding of 0x7f' gets
|
||||
// the actual number when subtracted from 0x30 (the value of the 0 character).
|
||||
try
|
||||
{
|
||||
char typech = TextConvert.ConvertSeq(dr["TYPE"].ToString())[0];
|
||||
int tmpitype = Convert.ToInt32(typech);
|
||||
if ((tmpitype & 0x80) > 0)
|
||||
{
|
||||
ci = new ConfigInfo(null);
|
||||
ci.AddItem("Transition", "Formatted", "True");
|
||||
}
|
||||
itype = (tmpitype&0x7F) - 0x30;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("Error converting transition type");
|
||||
log.ErrorFormat("type from database = {0}", dr["TYPE"].ToString());
|
||||
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
|
||||
itype = -1;
|
||||
}
|
||||
DateTime dts = GetDTS(MakeDate(dti.Substring(0, 8).Trim()), dti.Substring(8, 5).Trim());
|
||||
// if it's in the dictionary of structure elements already migrated, just use this
|
||||
// structure id, or if it's in the dictionary of structure elements that have
|
||||
// not been migrated but a record was created from this code, use it. Otherwise
|
||||
// create a new structure record and use its id, its data will be updated later.
|
||||
// a structure record.
|
||||
int toid;
|
||||
if (dicTrans_StrDone.ContainsKey(thekey))
|
||||
toid = dicTrans_StrDone[thekey];
|
||||
Item toItem = null;
|
||||
Item toItem2 = null;
|
||||
if (dicTrans_ItemDone.ContainsKey(thekey))
|
||||
{
|
||||
toItem = dicTrans_ItemDone[thekey];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dicTrans_StrIds.ContainsKey(thekey))
|
||||
toid = dicTrans_StrIds[thekey];
|
||||
if (dicTrans_ItemIds.ContainsKey(thekey))
|
||||
{
|
||||
toItem = dicTrans_ItemIds[thekey];
|
||||
}
|
||||
else
|
||||
{
|
||||
Structure str = Structure.MakeStructure(0, 0, 0, 0);
|
||||
toid = str.StructureID;
|
||||
dicTrans_StrIds.Add(thekey, toid);
|
||||
// note that parent is null right now - it will be filled in later.
|
||||
//toItem = Item.MakeItem(null, fromCon, DateTime.Now, "Migration");
|
||||
toItem = Item.New(null, TransDummyCont, DateTime.Now, "Migration");
|
||||
dicTrans_ItemIds.Add(thekey, toItem);
|
||||
}
|
||||
}
|
||||
Transition tr = Transition.MakeTransition(fromId, toid, System.Convert.ToInt32(dr["TYPE"].ToString()),0,0,0,0,dts,userid);
|
||||
return tr.TransitionId;
|
||||
|
||||
// if there is data in dr2, it means that it is a range transition. Get its item
|
||||
// data too.
|
||||
toItem2 = toItem;
|
||||
if (dr2 != null)
|
||||
{
|
||||
string thekey2 = dr2["TONUMBER"].ToString() + "|" + dr2["TOSEQUENCE"].ToString();
|
||||
if (dicTrans_ItemDone.ContainsKey(thekey2))
|
||||
{
|
||||
toItem2 = dicTrans_ItemDone[thekey2];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dicTrans_ItemIds.ContainsKey(thekey2))
|
||||
{
|
||||
toItem2 = dicTrans_ItemIds[thekey2];
|
||||
}
|
||||
else
|
||||
{
|
||||
toItem2 = Item.MakeItem(null, TransDummyCont, DateTime.Now, "Migration");
|
||||
dicTrans_ItemIds.Add(thekey2, toItem2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (userid == null || userid == "") userid = "Migration";
|
||||
Transition tr = null;
|
||||
try
|
||||
{
|
||||
tr = Transition.New(fromCon, toItem, toItem2, itype, ci!=null?ci.ToString():null, dts, userid);
|
||||
tr.MyZTransition.Oldto = dr["OLDTO"].ToString();
|
||||
if (!tr.IsSavable) ErrorRpt.ErrorReport(tr);
|
||||
tr.Save();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("Error addition transition record");
|
||||
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
|
||||
}
|
||||
StringBuilder trtxt = new StringBuilder();
|
||||
|
||||
// the following is pre RTB link code, i.e. <token>{tranid {type toid (rangeid}}
|
||||
trtxt.Append("\\v TRAN\\v0 (Resolved Transition Text)\\v ");
|
||||
|
||||
trtxt.Append(tr.TranType.ToString());
|
||||
trtxt.Append(" ");
|
||||
trtxt.Append(tr.TransitionID.ToString());
|
||||
trtxt.Append(" ");
|
||||
trtxt.Append(tr.ToID.ToString());
|
||||
if (toItem.ItemID == toItem2.ItemID)
|
||||
trtxt.Append("\\v0 ");
|
||||
else
|
||||
{
|
||||
trtxt.Append(" ");
|
||||
trtxt.Append(tr.RangeID.ToString());
|
||||
trtxt.Append("\\v0 ");
|
||||
}
|
||||
//trtxt.Append("{");
|
||||
//trtxt.Append(tr.TransitionID.ToString());
|
||||
//trtxt.Append("{");
|
||||
//trtxt.Append(tr.TranType.ToString());
|
||||
//trtxt.Append(" ");
|
||||
//trtxt.Append(tr.ToID.ToString());
|
||||
//if (toItem.ItemID == toItem2.ItemID)
|
||||
// trtxt.Append("}}");
|
||||
//else
|
||||
//{
|
||||
// trtxt.Append(" ");
|
||||
// trtxt.Append(tr.RangeID.ToString());
|
||||
// trtxt.Append("}}");
|
||||
//}
|
||||
|
||||
return trtxt.ToString();
|
||||
}
|
||||
|
||||
private string MigrateTrans(OleDbConnection cn, string textm, string seqcvt, int structId)
|
||||
private string MigrateTrans(OleDbConnection cn, string textm, string seqcvt, Content content)
|
||||
{
|
||||
StringBuilder trtxt = new StringBuilder();
|
||||
int instance = 0;
|
||||
@@ -95,17 +199,30 @@ namespace DataLoader
|
||||
// we have too many tokens and not enough usage records - report an error...
|
||||
if (instance >= dt.Rows.Count)
|
||||
{
|
||||
log.ErrorFormat("Error - ran out of usage records for step, check data ");
|
||||
log.ErrorFormat("Error - ran out of transition records for step, check data ");
|
||||
log.ErrorFormat("from number = {0} oldstepsequence = {1}", ProcNumber, seqcvt);
|
||||
}
|
||||
else
|
||||
{
|
||||
DataRow dr = dt.Rows[instance];
|
||||
int trid = AddTrans(structId, dr);
|
||||
|
||||
// if type is 2 or 3, this is a range transition, need to get the next
|
||||
// record too
|
||||
bool trange = false;
|
||||
if (dr["Type"].ToString() == "2" || dr["Type"].ToString() == "3")
|
||||
trange = true;
|
||||
|
||||
string rectxt = null;
|
||||
if (trange)
|
||||
{
|
||||
instance++;
|
||||
DataRow dr2 = dt.Rows[instance];
|
||||
rectxt = AddTrans(content, dr, dr2);
|
||||
}
|
||||
else
|
||||
rectxt = AddTrans(content, dr, null);
|
||||
trtxt.Append(textm[tok]);
|
||||
trtxt.Append("{{");
|
||||
trtxt.Append(trid.ToString());
|
||||
trtxt.Append("}}");
|
||||
trtxt.Append(rectxt);
|
||||
}
|
||||
instance++;
|
||||
beg = tok + 1;
|
||||
@@ -121,18 +238,25 @@ namespace DataLoader
|
||||
trtxt.Append(textm.Substring(beg, textm.Length - beg));
|
||||
if (dt.Rows.Count > instance + 1)
|
||||
{
|
||||
log.ErrorFormat("Error - extra usage records for step, check data ");
|
||||
log.ErrorFormat("Error - extra transition records for step, check data ");
|
||||
log.ErrorFormat("from number = {0} oldstepsequence = {1}", ProcNumber, seqcvt);
|
||||
}
|
||||
return trtxt.ToString();
|
||||
}
|
||||
private void ShowMissingTransitions()
|
||||
{
|
||||
log.Info("Missing Transitions");
|
||||
foreach (string s in dicTrans_StrIds.Keys)
|
||||
log.Info("Missing Transitions from Dictionary");
|
||||
foreach (string s in dicTrans_ItemIds.Keys)
|
||||
{
|
||||
log.InfoFormat("{0} - {1}", s, dicTrans_StrIds[s]);
|
||||
log.InfoFormat("{0} - {1}", s, dicTrans_ItemIds[s]);
|
||||
}
|
||||
|
||||
log.Info("Bad transitions to 'dummy' content");
|
||||
foreach (ContentItem itm in TransDummyCont.ContentItems)
|
||||
{
|
||||
log.InfoFormat("ItemID = {0}", itm.ItemID);
|
||||
}
|
||||
|
||||
log.Info("End of Missing Transitions");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user