Commit for development environment setup
This commit is contained in:
290
PROMS/DataLoader/ROFixer.cs.bak
Normal file
290
PROMS/DataLoader/ROFixer.cs.bak
Normal file
@@ -0,0 +1,290 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using VEPROMS.CSLA.Library;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DataLoader
|
||||
{
|
||||
public delegate void ROFixerEvent(object sender, ROFixerEventArgs args);
|
||||
public class ROFixerEventArgs
|
||||
{
|
||||
private string _MyStatus;
|
||||
|
||||
public string MyStatus
|
||||
{
|
||||
get { return _MyStatus; }
|
||||
set { _MyStatus = value; }
|
||||
}
|
||||
public ROFixerEventArgs(string myStatus)
|
||||
{
|
||||
_MyStatus = myStatus;
|
||||
}
|
||||
}
|
||||
class ROFixer
|
||||
{
|
||||
public static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
public event ROFixerEvent StatusChanged;
|
||||
private void OnStatusChanged(object sender, ROFixerEventArgs args)
|
||||
{
|
||||
if (StatusChanged != null)
|
||||
StatusChanged(sender, args);
|
||||
}
|
||||
private string _Status;
|
||||
|
||||
public string Status
|
||||
{
|
||||
get { return _Status; }
|
||||
set
|
||||
{
|
||||
_Status = value;
|
||||
OnStatusChanged(this, new ROFixerEventArgs(_Status));
|
||||
}
|
||||
}
|
||||
private int _ErrorCount = 0;
|
||||
|
||||
public int ErrorCount
|
||||
{
|
||||
get { return _ErrorCount; }
|
||||
set { _ErrorCount = value; }
|
||||
}
|
||||
private string _LogPath;
|
||||
private frmLoader frmMain;
|
||||
public ROFixer(string logpath, frmLoader myfrmMain)
|
||||
{
|
||||
_LogPath = logpath;
|
||||
frmMain = myfrmMain;
|
||||
}
|
||||
public TimeSpan Process()
|
||||
{
|
||||
DateTime tstart = DateTime.Now;
|
||||
ProcessROs();
|
||||
return DateTime.Now - tstart;
|
||||
}
|
||||
public TimeSpan Process(DocVersionInfo dvi)
|
||||
{
|
||||
DateTime tstart = DateTime.Now;
|
||||
ProcessROs(dvi);
|
||||
return DateTime.Now - tstart;
|
||||
}
|
||||
public TimeSpan Process(ProcedureInfo pi)
|
||||
{
|
||||
DateTime tstart = DateTime.Now;
|
||||
ProcessROs(pi);
|
||||
return DateTime.Now - tstart;
|
||||
}
|
||||
private void ProcessROs()
|
||||
{
|
||||
Status = "Getting List...";
|
||||
RoUsageInfoList myRoUsages = RoUsageInfoList.Get();
|
||||
DoProcessROs(myRoUsages);
|
||||
}
|
||||
//private void ProcessROs(FolderInfo fi)
|
||||
//{
|
||||
// Status = "Getting List...";
|
||||
// RoUsageInfoList myRoUsages = RoUsageInfoList.GetByFolder(fi);
|
||||
// DoProcessROs(myRoUsages);
|
||||
//}
|
||||
private void ProcessROs(DocVersionInfo dvi)
|
||||
{
|
||||
Status = "Getting List...";
|
||||
RoUsageInfoList myRoUsages = RoUsageInfoList.GetByDocVersion(dvi);
|
||||
DoProcessROs(myRoUsages);
|
||||
}
|
||||
private void ProcessROs(ProcedureInfo pi)
|
||||
{
|
||||
Status = "Getting List...";
|
||||
RoUsageInfoList myRoUsages = RoUsageInfoList.GetByProcedure(pi);
|
||||
DoProcessROs(myRoUsages);
|
||||
}
|
||||
private AnnotationType _VolianCommentType = null; // Using this to flag ro value issues with byron to braidwood
|
||||
public AnnotationType VolianCommentType
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_VolianCommentType == null)
|
||||
_VolianCommentType = AnnotationType.GetByName("Volian Comment");
|
||||
if (_VolianCommentType == null)
|
||||
_VolianCommentType = AnnotationType.MakeAnnotationType("Volian Comment",null);
|
||||
return _VolianCommentType;
|
||||
}
|
||||
}
|
||||
private void DoProcessROs(RoUsageInfoList myRoUsages)
|
||||
{
|
||||
int changeCount = 0;
|
||||
// get list of content records
|
||||
List<int> myContentList = new List<int>();
|
||||
Dictionary<int, ROFSTLookup> roFstLookups = new Dictionary<int,ROFSTLookup>();
|
||||
Dictionary<int, ROFSTLookup> oldRoFstLookups = null;
|
||||
ROFstInfo oldRoFst = null;
|
||||
if (frmMain.MySettings.SelectedROFst > 0)
|
||||
{
|
||||
oldRoFst = ROFstInfo.Get(frmMain.MySettings.SelectedROFst);
|
||||
oldRoFstLookups = new Dictionary<int, ROFSTLookup>();
|
||||
}
|
||||
foreach (RoUsageInfo rou in myRoUsages)
|
||||
{
|
||||
if (!myContentList.Contains(rou.ContentID))
|
||||
{
|
||||
myContentList.Add(rou.ContentID);
|
||||
}
|
||||
}
|
||||
int i = 0;
|
||||
foreach (int cid in myContentList)
|
||||
{
|
||||
Status = string.Format("Processing {0} of {1} steps", ++i, myContentList.Count);
|
||||
ContentInfo myContentInfo = ContentInfo.Get(cid);
|
||||
DocVersionInfo dvi = myContentInfo.ContentItems[0].MyProcedure.MyDocVersion;
|
||||
int versionId = dvi.VersionID;
|
||||
ROFstInfo myRoFst = dvi.DocVersionAssociations[0].MyROFst;
|
||||
if (!roFstLookups.ContainsKey(versionId))
|
||||
{
|
||||
roFstLookups.Add(versionId, myRoFst.GetROFSTLookup(dvi));
|
||||
}
|
||||
ROFSTLookup myLookup = roFstLookups[versionId];
|
||||
if (oldRoFstLookups != null && !oldRoFstLookups.ContainsKey(versionId))
|
||||
{
|
||||
oldRoFstLookups.Add(versionId, oldRoFst.GetROFSTLookup(dvi));
|
||||
}
|
||||
ROFSTLookup oldLookup = null;
|
||||
if(oldRoFstLookups != null)
|
||||
oldLookup = oldRoFstLookups[versionId];
|
||||
using (Content ctmp = myContentInfo.Get())
|
||||
{
|
||||
ItemInfo ii = myContentInfo.ContentItems[0];
|
||||
foreach (RoUsageInfo ru in myContentInfo.ContentRoUsages)
|
||||
{
|
||||
string sameMsg = string.Empty;
|
||||
bool theSame = false;
|
||||
//if (oldLookup != null)
|
||||
// theSame = CheckIfTheSame(ii, ru.ROID, myLookup, oldLookup, dvi, ref sameMsg);
|
||||
ROFSTLookup.rochild rocc = myLookup.GetRoChild12(ru.ROID);
|
||||
if (rocc.value == null)
|
||||
rocc = myLookup.GetRoChild(ru.ROID);
|
||||
int myType = rocc.type;
|
||||
string myValue = myLookup.GetTranslatedRoValue(ru.ROID, ii.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta);
|
||||
myValue = myValue.Replace(@"\up2 \u8209?", @"\up2\u8209?");// Remove space between superscript command and non-breaking hyphen
|
||||
string fileNameOnly = null;
|
||||
if (myType == 8 && myValue.Contains("\n"))
|
||||
{
|
||||
fileNameOnly = myValue.Split("\n".ToCharArray())[0];
|
||||
myValue = myValue.Replace("\n", "");// Remove newlines in Figure data
|
||||
}
|
||||
string textB4 = ctmp.Text;
|
||||
myRoFst.ROTableUpdate += new ROFstInfoROTableUpdateEvent(myRoFst_ROTableUpdate);
|
||||
string oldval;
|
||||
switch (frmMain.MySettings.WhatROsToConvert)
|
||||
{
|
||||
case ROUpdateMode.None:
|
||||
oldval = ctmp.FixContentText(ru, myValue, myType, myRoFst, fileNameOnly);
|
||||
if(myValue == "?" && frmMain.MySettings.AnnotateWhenShowingMissingRO)
|
||||
Annotation.MakeAnnotation(ctmp.ContentItems[0].MyItem, VolianCommentType, "", string.Format("RO value ({0}) missing", ItemInfo.ConvertToDisplayText(oldval)), null);
|
||||
else if (ctmp.Text != textB4 && frmMain.MySettings.AnnotateWhenShowingDifferentRO)
|
||||
Annotation.MakeAnnotation(ctmp.ContentItems[0].MyItem, VolianCommentType, "", string.Format("Old RO value ({0}) different than new RO value({1})", ItemInfo.ConvertToDisplayText(oldval), ItemInfo.ConvertToDisplayText(myValue)), null);
|
||||
break;
|
||||
case ROUpdateMode.All:
|
||||
oldval = ctmp.ConvertROToText(ru, myValue, myType, myRoFst);
|
||||
if (frmMain.MySettings.AnnotateWhenConvertingToText)
|
||||
Annotation.MakeAnnotation(ctmp.ContentItems[0].MyItem, VolianCommentType, "", string.Format("RO value ({0}) converted to text", ItemInfo.ConvertToDisplayText(oldval)), null);
|
||||
break;
|
||||
default:
|
||||
if (myValue == "?")
|
||||
{
|
||||
oldval = ctmp.ConvertROToText(ru, myValue, myType, myRoFst);
|
||||
if (frmMain.MySettings.AnnotateWhenConvertingToText)
|
||||
Annotation.MakeAnnotation(ctmp.ContentItems[0].MyItem, VolianCommentType, "", string.Format("RO value ({0}) converted to text" + sameMsg, ItemInfo.ConvertToDisplayText(oldval)), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
oldval = ctmp.FixContentText(ru, myValue, myType, myRoFst, fileNameOnly);
|
||||
if (ctmp.Text != textB4 && frmMain.MySettings.AnnotateWhenShowingDifferentRO)
|
||||
Annotation.MakeAnnotation(ctmp.ContentItems[0].MyItem, VolianCommentType, "", string.Format("Old RO value ({0}) different than new RO value({1})" + sameMsg, ItemInfo.ConvertToDisplayText(oldval), ItemInfo.ConvertToDisplayText(myValue)), null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
myRoFst.ROTableUpdate -= new ROFstInfoROTableUpdateEvent(myRoFst_ROTableUpdate);
|
||||
if (ctmp.Text != textB4)
|
||||
{
|
||||
changeCount++;
|
||||
//Console.WriteLine("'{0}', '{1}', '{2}', '{3}'", replace(oldval, @"\u8209?", "-"), replace(myValue, @"\u8209?", "-"), ru.ROID, rocc.appid);
|
||||
frmMain.AddInfo("'{0}','{1}','{2}','{3}','R{4}','{5}','{6}'", ii.MyDocVersion.MyFolder.Name, ii.ShortPath,
|
||||
(oldval ?? "").Replace(@"\u8209?", "-").Replace("'", "''"), myValue.Replace(@"\u8209?", "-").Replace("'", "''"), ru.ROID, myLookup.GetAccPageID(ru.ROID), sameMsg);
|
||||
}
|
||||
else if (sameMsg != string.Empty && sameMsg != ", Exact Match")
|
||||
{
|
||||
frmMain.AddInfo("'{0}','{1}','{2}','{3}','R{4}','{5}','{6}'", ii.MyDocVersion.MyFolder.Name, ii.ShortPath,
|
||||
(oldval ?? "").Replace(@"\u8209?", "-").Replace("'", "''"), myValue.Replace(@"\u8209?", "-").Replace("'", "''"), ru.ROID, myLookup.GetAccPageID(ru.ROID), sameMsg);
|
||||
}
|
||||
}
|
||||
if (ctmp.IsDirty)
|
||||
{
|
||||
//ctmp.DTS = DateTime.Now;
|
||||
ctmp.Save();
|
||||
ContentInfo.Refresh(ctmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
frmMain.AddInfo("{0} RO Values Updated", changeCount);
|
||||
MessageBox.Show(String.Format("{0} RO Values Updated", changeCount), "RO Value Update Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private bool CheckIfTheSame(ItemInfo ii, string roid, ROFSTLookup myLookup, ROFSTLookup oldLookup, DocVersionInfo dvi, ref string sameMsg)
|
||||
{
|
||||
/*
|
||||
ROFSTLookup.rochild rocc = myLookup.GetRoChild12(ru.ROID);
|
||||
if (rocc.value == null)
|
||||
rocc = myLookup.GetRoChild(ru.ROID);
|
||||
int myType = rocc.type;
|
||||
*/
|
||||
ROFSTLookup.rochild roc = myLookup.GetRoChild12(roid);
|
||||
if (roc.value == null) roc = myLookup.GetRoChild(roid);
|
||||
ROFSTLookup.rochild oroc = oldLookup.GetRoChild12(roid);
|
||||
if (oroc.value == null) oroc = oldLookup.GetRoChild(roid);
|
||||
string myValue = myLookup.GetTranslatedRoValue(roid, ii.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta);
|
||||
myValue = myValue.Replace(@"\up2 \u8209?", @"\up2\u8209?");// Remove space between superscript command and non-breaking hyphen
|
||||
string oldValue = oldLookup.GetTranslatedRoValue(roid, ii.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta);
|
||||
oldValue = oldValue.Replace(@"\up2 \u8209?", @"\up2\u8209?");// Remove space between superscript command and non-breaking hyphen
|
||||
string myAccPageID = myLookup.GetAccPageID(roid);
|
||||
string oldAccPageID = oldLookup.GetAccPageID(roid);
|
||||
if (myValue == oldValue && roc.type == oroc.type && ((myAccPageID ?? "null") == (oldAccPageID ?? "null")))
|
||||
{
|
||||
sameMsg = ", Exact Match";
|
||||
return true;
|
||||
}
|
||||
if (myValue != oldValue && roc.type == oroc.type && ((myAccPageID ?? "null") == (oldAccPageID ?? "null")))
|
||||
{
|
||||
sameMsg = ", Different Value, Same RO";
|
||||
return false;
|
||||
}
|
||||
if ((myAccPageID ?? "null") != (oldAccPageID ?? "null"))
|
||||
{
|
||||
ROFSTLookup.rochild? myroc = myLookup.GetROChildByAccPageID(oldAccPageID, dvi.DocVersionConfig.RODefaults_setpointprefix), dvi.DocVersionConfig.RODefaults_graphicsprefix);
|
||||
if (myroc != null)
|
||||
{
|
||||
string myValueNew = myLookup.GetTranslatedRoValue(((ROFSTLookup.rochild)myroc).roid, ii.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta);
|
||||
if(myValueNew == oldValue)
|
||||
sameMsg = ", Same Value, Different RO";
|
||||
else
|
||||
sameMsg = ", Different Value, Different RO";
|
||||
}
|
||||
else
|
||||
sameMsg = ", Missing RO";
|
||||
return false;
|
||||
}
|
||||
sameMsg = ", Unknown";
|
||||
|
||||
//if (myLookup.GetAccPageID(roid) == oldLookup.GetAccPageID(roid))
|
||||
//{
|
||||
// sameMsg = string.Format("ROID: {0}, AccPageID: {1}, OldAccPageID: {2}", roid, myLookup.GetAccPageID(roid), oldLookup.GetAccPageID(roid));
|
||||
// return false;
|
||||
//}
|
||||
//sameMsg = "Values and AccPageIDs are different for ROID: " + roid;
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<string> myRoFst_ROTableUpdate(object sender, ROFstInfoROTableUpdateEventArgs args)
|
||||
{
|
||||
return Volian.Controls.Library.VlnFlexGrid.ROTableUpdate(sender,args);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user