using System; using System.Collections.Generic; using System.Text; using Volian.Controls.Library; using VEPROMS.CSLA.Library; using System.Text.RegularExpressions; using Volian.Base.Library; 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; } } private string _LogPath; public TransitionFixer(StepRTB myStepRTB,string logpath) { _MyStepRTB = myStepRTB; _LogPath = logpath; } public TimeSpan Process(bool checkRTF) { DateTime tstart = DateTime.Now; ProcessTransitions(checkRTF); return DateTime.Now - tstart; } private void ProcessTransitions(bool checkRTF) { 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; // Exclude items that are not connected (Dummy steps for invalid transition destinations) 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); } } } if (updatedText.EndsWith(" ")) updatedText = updatedText.Substring(0, updatedText.Length - 1); using (Content c = item.MyContent.Get()) { c.Text = updatedText; c.Save(); } if (checkRTF) { MyStepRTB.MyItemInfo = item; MyStepRTB.SaveText(true); // Force Save - This will put change bars on everything string afterText = item.MyContent.Text; // aftertext is 'newrtf' if (afterText != updatedText) myProblems.RTBProblems.Add(item.ItemID, item.MyContent.ContentID, originalText, updatedText, MyStepRTB.Rtf, afterText, item.Path); } } } if (checkRTF) { Status = "Saving problems"; string logFile = _LogPath + @"\RTBProblems.xml"; ErrorCount = myProblems.RTBProblems.Count; myProblems.Save(logFile); if (ErrorCount > 0) { System.Windows.Forms.DialogResult answer = System.Windows.Forms.MessageBox.Show( string.Format("{0} Differences found in Transition Text\r\nResults in {1}\r\n\r\nOpen Log File?", ErrorCount, logFile), "Transitions Different", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question); if(answer == System.Windows.Forms.DialogResult.Yes) System.Diagnostics.Process.Start(logFile); } } Status = "Done comparing"; } public string FixTransitionText(string Text, TransitionInfo tran) { string lookFor = string.Format(@"", tran.TranType, tran.TransitionID, "{1,2}"); string transText = tran.ResolvePathTo(); //Console.WriteLine(">>>>> FixTransitionText"); //Console.WriteLine("Text = {0}", Text); //Console.WriteLine("lookFor = {0}", lookFor); //Console.WriteLine("TransText = {0}", transText); 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; } } }