SourceCode/PROMS/DataLoader/TransitionFixer.cs
2010-03-25 14:32:38 +00:00

134 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using Volian.Controls.Library;
using VEPROMS.CSLA.Library;
using System.Text.RegularExpressions;
namespace DataLoader
{
public delegate void TransitionFixerEvent(object sender, TransitionFixerEventArgs args);
public class TransitionFixerEventArgs
{
private string _MyStatus;
public string MyStatus
{
get { return _MyStatus; }
set { _MyStatus = value; }
}
public TransitionFixerEventArgs(string myStatus)
{
_MyStatus = myStatus;
}
}
class TransitionFixer
{
public event TransitionFixerEvent StatusChanged;
private void OnStatusChanged(object sender, TransitionFixerEventArgs args)
{
if (StatusChanged != null)
StatusChanged(sender, args);
}
private string _Status;
public string Status
{
get { return _Status; }
set
{
_Status = value;
OnStatusChanged(this, new TransitionFixerEventArgs(_Status));
}
}
private int _ErrorCount = 0;
public int ErrorCount
{
get { return _ErrorCount; }
set { _ErrorCount = value; }
}
private StepRTB _MyStepRTB;
public StepRTB MyStepRTB
{
get { return _MyStepRTB; }
}
public TransitionFixer(StepRTB myStepRTB)
{
_MyStepRTB = myStepRTB;
}
public TimeSpan Process()
{
DateTime tstart = DateTime.Now;
ProcessTransitions();
return DateTime.Now - tstart;
}
private void ProcessTransitions()
{
Status = "Getting List...";
// Loop through all Items and check before and after text
ItemInfoList myList = ItemInfoList.Get();
ConversionRTBProblems myProblems = new ConversionRTBProblems();
int i = 0;
foreach (ItemInfo item in myList)
{
Status = string.Format("Processing {0} of {1} steps", ++i, myList.Count);
MyStepRTB.ViewRTB = false;
string originalText = item.MyContent.Text;
string updatedText = item.MyContent.Text;
if (item.ItemID == 1850)
Console.WriteLine("HERE");
if (item.ItemDocVersionCount != 0 || item.MyPrevious != null || item.MyParent != null)
{
if (item.MyContent.ContentTransitionCount > 0)
{
//updatedText = Volian.Controls.Library.DisplayText.StaticRemoveRtfStyles(updatedText, item);
foreach (TransitionInfo tran in item.MyContent.ContentTransitions)
{
try
{
updatedText = FixTransitionText(updatedText, tran);
}
catch (Exception ex)
{
Console.WriteLine("{0} {1}", ex.GetType().Name, ex.Message);
}
}
}
MyStepRTB.MyItemInfo = item;
MyStepRTB.SaveText();
string afterText = item.MyContent.Text;
if (updatedText != afterText)//|| newStripped != afterText)
myProblems.RTBProblems.Add(item.ItemID, item.MyContent.ContentID, originalText, updatedText, MyStepRTB.Rtf, afterText, item.Path);
}
else
{
Console.WriteLine("here");
}
}
Status = "Saving problems";
ErrorCount = myProblems.RTBProblems.Count;
myProblems.Save(@"C:\temp\RTBProblems.xml");
Status = "Done comparing";
}
public string FixTransitionText(string Text, TransitionInfo tran)
{
string transText = tran.ResolvePathTo();
string lookFor = string.Format(@"<START\]\\v0 ([^#]*?)\\v #Link:Transition[^:]*?:{0} {1}( [0-9]*){2}\[END>", tran.TranType, tran.TransitionID, "{1,2}");
Match m = Regex.Match(Text, lookFor);
if (m != null && m.Groups.Count > 1)
{
System.Text.RegularExpressions.Group g = m.Groups[1];
if (g.ToString() != transText)
Text = Text.Substring(0, g.Index) + transText + Text.Substring(g.Index + g.Length);
}
else
Console.WriteLine("Transition not Found");
return Text;
}
}
}