using System; using System.Collections.Generic; using System.Text; using VEPROMS.CSLA.Library; 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; public ROFixer(string logpath) { _LogPath = logpath; } public TimeSpan Process() { DateTime tstart = DateTime.Now; ProcessROs(); return DateTime.Now - tstart; } private void ProcessROs() { Status = "Getting List..."; // get list of content records List myContentList = new List(); RoUsageInfoList myRoUsages = RoUsageInfoList.Get(); Dictionary roFstLookups = new Dictionary(); 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; if (!roFstLookups.ContainsKey(versionId)) { ROFstInfo myRoFst = dvi.DocVersionAssociations[0].MyROFst; roFstLookups.Add(versionId, myRoFst.GetROFSTLookup(dvi)); } ROFSTLookup myLookup = roFstLookups[versionId]; using (Content ctmp = myContentInfo.Get()) { ItemInfo ii = myContentInfo.ContentItems[0]; foreach (RoUsageInfo ru in myContentInfo.ContentRoUsages) { //ROFSTLookup.rochild rocc = myLookup.GetRoChild12(ru.ROID); //if (rocc.value == null) ROFSTLookup.rochild rocc = myLookup.GetRoChild(ru.ROID); //string myValue = rocc.value; int myType = rocc.type; string myValue = myLookup.GetTranslatedRoValue(ru.ROID, ii.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta); ctmp.FixContentText(ru, myValue, myType, null); if (ctmp.IsDirty) Console.WriteLine("{0}, {1}", myValue, ru.ROID); } if (ctmp.IsDirty) { ctmp.DTS = DateTime.Now; ctmp.Save(); ContentInfo.Refresh(ctmp); } } } } } }