Move frmErrors when frmLoader is moved

Shutoff SpellCheck for StepRTB
Use using for temporary StepRTB
Use using for vlnFlexGrid
Added debug output to track StepRTBs and vlnFlexGrids in memory
Limit bottom margin to 0 or above
Dispose of roImage after it is done being used
Dispose of Figure after it is done being used.
Use GetJustRODB so that images are not loaded.
Added ErrorHandler if annotation is deleted after a search
Track create, dispose and finalize
Add static variable to control if SpellCheck is used
Use using for temporary StepRTB
Lazy Load SelectionStack
Clean-up on Dispose
Track create, dispose and finalize
Make MyCopyInfo Lazy Loaded
Use using for temporary StepRTB
Add Dispose method for TableCellEditor
Cleanup on Dispose
Only kill MSWord instances that are invisible
This commit is contained in:
Rich 2012-07-13 18:34:57 +00:00
parent ce21565a15
commit 7bcfafcc8b
12 changed files with 520 additions and 387 deletions

View File

@ -118,10 +118,11 @@ namespace DataLoader
string fixStpText = "";
if (IsATable(content.Type))
{
//if (ProcNumber == "EOP-ES-1.2")
// Console.WriteLine("here");
bool hasBorder = !WithoutBorder(content.Type);
fixStpText = ConvertTableToGrid(stptext, content, fmt, isROTable, hasBorder ? GridLinePattern.Single : GridLinePattern.None );
frmMain.AddInfo("Memory After Grid Convert {0}", GC.GetTotalMemory(true)); // This will force a Garbage Collection
frmMain.AddInfo("VlnFlexGrid Counts: {0}, {1}, {2}", VlnFlexGrid.CountCreated, VlnFlexGrid.CountNotDisposed, VlnFlexGrid.CountNotFinalized);
frmMain.AddInfo("StepRTB Counts: {0}, {1}, {2}", StepRTB.CountCreated, StepRTB.CountNotDisposed, StepRTB.CountNotFinalized);
int? typ = ConvertTableType(content, fmt);
if (typ != null) content.Type = typ;
else _ContentMigrationErrors.Add(content.ContentID, null);
@ -372,7 +373,9 @@ namespace DataLoader
{
//string savethis = stepText;
string strGrid = "";
VlnFlexGrid grd = new VlnFlexGrid(1, 1);
//MessageBox.Show("Before ConvertTableToGrid " + GC.GetTotalMemory(true).ToString());
using (VlnFlexGrid grd = new VlnFlexGrid(1, 1))
{
grd.IsRoTable = isROTable;
VE_Font vefont = fmt.PlantFormat.FormatData.StepDataList.Table.Font;
Font GridFont = new Font(vefont.Family, (float)vefont.Size);
@ -381,7 +384,6 @@ namespace DataLoader
grd.AutoSizeCols();
grd.AutoSizeRows();
grd.MakeRTFcells();
using (StringWriter sw = new StringWriter())
{
grd.WriteXml(sw);
@ -390,7 +392,7 @@ namespace DataLoader
strGrid = grd.GetSearchableText();
sw.Close();
}
grd.Dispose();
}
return strGrid;
}

View File

@ -16,9 +16,13 @@ namespace DataLoader
{
InitializeComponent();
_MyParent = myParent;
_MyParent.Move += new EventHandler(_MyParent_Move);
}
void _MyParent_Move(object sender, EventArgs e)
{
AdjustLocation();
}
private int _ErrorCount = 0;
public int ErrorCount
{
get { return _ErrorCount; }
@ -67,9 +71,18 @@ namespace DataLoader
}
private void frmErrors_Load(object sender, EventArgs e)
{
Rectangle rec = Screen.GetWorkingArea(this);
AdjustLocation();
}
private void AdjustLocation()
{
int maxRight = Screen.GetWorkingArea(this).Right;
if (Screen.AllScreens.Length > 1)
{
foreach (Screen sc in Screen.AllScreens)
if (sc.WorkingArea.Right > maxRight) maxRight = sc.WorkingArea.Right;
}
Top = _MyParent.Top;
Left = _MyParent.Right + Width > rec.Right ? rec.Right - Width : _MyParent.Right;
Left = _MyParent.Right + Width > maxRight ? maxRight - Width : _MyParent.Right;
}
public void Save(string path)
{

View File

@ -588,6 +588,7 @@ namespace DataLoader
_Loading = false;
MSWordToPDF.CloseWordWhenDone = false;
Format.FormatLoaded += new FormatEvent(Format_FormatLoaded);
StepRTB.DoSpellCheck = false;
}
void Format_FormatLoaded(object sender, FormatEventArgs args)
{
@ -601,7 +602,8 @@ namespace DataLoader
//List<int> cachePdfInfo = PdfInfo.CacheList;
//List<int> cacheDocVersionInfo = DocVersionInfo.CacheList;
//if (!CheckLogPath()) return;
StepRTB rtb = new StepRTB();
using (StepRTB rtb = new StepRTB())
{
TransitionFixer myFixer = new TransitionFixer(rtb, MySettings.LogFilePath);
myFixer.StatusChanged += new TransitionFixerEvent(myFixer_StatusChanged);
TimeSpan howlong = myFixer.Process(MySettings.CheckRTF);
@ -617,6 +619,7 @@ namespace DataLoader
//DocVersionInfo.RestoreCacheList(cacheDocVersionInfo);
MyInfo = CSLACache.UsageAll;
}
}
void myFixer_StatusChanged(object sender, TransitionFixerEventArgs args)
{

View File

@ -770,16 +770,15 @@ namespace VEPROMS.CSLA.Library
float oldRight = myDoc.PageSetup.RightMargin;
float oldHeight = myDoc.PageSetup.PageHeight;
float oldWidth = myDoc.PageSetup.PageWidth;
float newRight = oldWidth - (newWidth + newLeft);
if (newRight < 0) newRight = 0;
float newBottom = oldBottom - newTop;
float newRight = Math.Max(0, oldWidth - (newWidth + newLeft));
float newBottom = Math.Max(0, oldHeight - (newLength + newTop + 1));
//Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", newTop, newLeft, newLength, newWidth, oldTop, oldLeft, oldBottom, oldRight,oldHeight,oldWidth);
if (printingMode)
{
if (myDoc.PageSetup.BottomMargin != 9999999)
{
// the + 1 in the next line allows for rounding.
myDoc.PageSetup.BottomMargin = 11 * 72 - (newTop + newLength + 1);
myDoc.PageSetup.BottomMargin = newBottom;
myDoc.PageSetup.RightMargin = newRight;
myDoc.PageSetup.LeftMargin = newLeft;
myDoc.PageSetup.TopMargin = newTop;
@ -789,7 +788,7 @@ namespace VEPROMS.CSLA.Library
try
{
// the + 1 in the next line allows for rounding.
myDoc.PageSetup.BottomMargin = 11 * 72 - (newTop + newLength + 1);
myDoc.PageSetup.BottomMargin = newBottom;
myDoc.PageSetup.RightMargin = newRight;
myDoc.PageSetup.LeftMargin = newLeft;
myDoc.PageSetup.TopMargin = newTop;

View File

@ -541,15 +541,19 @@ namespace VEPROMS.CSLA.Library
byte[] ab = r.ReadBytes((int)fsIn.Length);
r.Close();
fsIn.Close();
roImg = ROImage.MakeROImage(rodb, imgname, ab, null, fi.LastWriteTimeUtc, "Migration");
Figure figure = Figure.GetByROFstID_ImageID(this.ROFstID, roImg.ImageID);
using (roImg = ROImage.MakeROImage(rodb, imgname, ab, null, fi.LastWriteTimeUtc, "Migration"))
{
using (Figure figure = Figure.GetByROFstID_ImageID(this.ROFstID, roImg.ImageID))
{
if (figure != null) return;
figure = Figure.MakeFigure(rofst, roImg, null);
Figure.MakeFigure(rofst, roImg, null).Dispose();
myAddedROImages.Add(key);
}
}
}
}
}
}
private ROImageInfo GetMyImage(Dictionary<string, ROImageInfo> myImages, string imgname, DateTime dts)
{

View File

@ -180,7 +180,7 @@ namespace VEPROMS.CSLA.Library
get
{
CanReadProperty("MyRODb", true);
if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID);
if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.GetJustRODB(_RODbID);
return _MyRODb;
}
}

View File

@ -12,6 +12,7 @@ namespace Volian.Controls.Library
{
public partial class AnnotationDetails : UserControl
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Properties
private bool _LoadingAnnotation = false;
private bool _LoadingGrid = false;
@ -266,10 +267,17 @@ namespace Volian.Controls.Library
break;
}
}
try
{
dgAnnotations.Rows[row].Selected = true;
if (!_LoadingGrid && (dgAnnotations.FirstDisplayedScrollingRowIndex != -1))
dgAnnotations.FirstDisplayedScrollingRowIndex = row;
}
catch (Exception ex)
{
_MyLog.InfoFormat("Trying to open an annotation which has been removed");
}
}
}
}

View File

@ -28,6 +28,25 @@ namespace Volian.Controls.Library
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private bool _Finalized = false;
~StepRTB()
{
if (!_Finalized) _CountFinalized++;
_Finalized = true;
}
#region Events
public event StepRTBRoEvent RoInsert;
public void OnRoInsert(object sender, StepRTBRoEventArgs args)
@ -542,7 +561,6 @@ namespace Volian.Controls.Library
SetUpStepRTB();
AddEventHandlers();
this.BorderStyleChanged += new EventHandler(StepRTB_BorderStyleChanged);
}
protected override void OnMouseWheel(MouseEventArgs e)
{
@ -646,6 +664,7 @@ namespace Volian.Controls.Library
private void SetUpStepRTB()
{
DetectUrls = false;
if(DoSpellCheck)
C1SpellChecker2.SetActiveSpellChecking(this, true);
this.Height = 10; // initialize the height to 10, the default height was too big for the cells in grid tables
BorderStyle = System.Windows.Forms.BorderStyle.None;
@ -1704,7 +1723,8 @@ namespace Volian.Controls.Library
private string GetSelectedDisplayableText()
{
StepRTB srtb = new StepRTB();
using (StepRTB srtb = new StepRTB())
{
srtb.Rtf = this.SelectedRtf.Replace(@"\u8209?", "-");
string rtnstr = "";
string ctxt = srtb.Text;//this.SelectedText;
@ -1736,6 +1756,7 @@ namespace Volian.Controls.Library
rtnstr += ctxt.Substring(idx);
return rtnstr;
}
}
private bool IsControlChar = false;
private bool _SendBackSpace = false;
@ -2158,14 +2179,25 @@ namespace Volian.Controls.Library
#endregion
#endregion
#region SelectionStack
Stack<SelectionData> _SelectionStack = new Stack<SelectionData>();
Stack<SelectionData> _SelectionStack = null;
public Stack<SelectionData> SelectionStack
{
get
{
if (_SelectionStack == null)
_SelectionStack = new Stack<SelectionData>();
return _SelectionStack;
}
}
public void PushSelection()
{
_SelectionStack.Push(new SelectionData(this));
SelectionStack.Push(new SelectionData(this));
}
public void PopSelection()
{
SelectionData selection = _SelectionStack.Pop();
SelectionData selection = SelectionStack.Pop();
if (SelectionStack.Count == 0)
_SelectionStack = null;
Select(selection.SelectionStart, selection.SelectionLength);
}
public class SelectionData
@ -2299,7 +2331,8 @@ namespace Volian.Controls.Library
private RichTextBoxFinds _FindOptions = RichTextBoxFinds.None;
public bool FindText(string str, bool caseSensitive, bool matchWholeWord, bool reverse)
{
StepRTB savRTF = new StepRTB();
using (StepRTB savRTF = new StepRTB())
{
int startpos = SelectionStart + SelectionLength;
savRTF.Text = this.Text;
@ -2353,6 +2386,7 @@ namespace Volian.Controls.Library
}
return true;
}
}
private int FindStart()
{
foreach (LinkLocation ll in _LinkLocations)
@ -2784,6 +2818,12 @@ namespace Volian.Controls.Library
}
#endregion
#region SpellChecker
private static bool _DoSpellCheck = true;
public static bool DoSpellCheck
{
get { return StepRTB._DoSpellCheck; }
set { StepRTB._DoSpellCheck = value; }
}
// We made the Spell Checker method a static so that all of the StepRTB boxes will bare the same instance of the dictionary.
// This allow all the StepRTB's to automatically update when a new word is added.
private static C1.Win.C1SpellChecker.C1SpellChecker _C1SpellChecker2;

View File

@ -1,3 +1,4 @@
using System;
namespace Volian.Controls.Library
{
partial class StepRTB
@ -13,11 +14,16 @@ namespace Volian.Controls.Library
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (_Disposed) return;
_CountDisposed++;
_Disposed = true;
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
if(!_Finalized)
GC.ReRegisterForFinalize(this); // Make sure that StepRTB is finalized
}
#region Component Designer generated code

View File

@ -1,3 +1,5 @@
using System;
namespace Volian.Controls.Library
{
partial class VlnFlexGrid
@ -13,13 +15,19 @@ namespace Volian.Controls.Library
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (_Disposed) return;
_CountDisposed++;
_Disposed = true;
_MyBorders = null;
_SpellChecker = null;
_tableCellEditor = null;
if (disposing && (components != null))
{
_SpellChecker.Dispose();
_tableCellEditor.Dispose();
components.Dispose();
}
base.Dispose(disposing);
if(!_Finalized)
GC.ReRegisterForFinalize(this);
}
#region Component Designer generated code

View File

@ -25,8 +25,26 @@ namespace Volian.Controls.Library
public partial class VlnFlexGrid : C1.Win.C1FlexGrid.C1FlexGrid
{
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private bool _Finalized = false;
~VlnFlexGrid()
{
if(!_Finalized) _CountFinalized++;
_Finalized = true;
}
private C1SpellChecker _SpellChecker;
public C1SpellChecker SpellChecker
{
get { return _SpellChecker; }
@ -185,7 +203,16 @@ namespace Volian.Controls.Library
return string.Empty;
return xd.SelectSingleNode("C1FlexGrid/MergedRanges").InnerXml;
}
public static GridCopyInfo MyCopyInfo = new GridCopyInfo();
private static GridCopyInfo _MyCopyInfo;
public static GridCopyInfo MyCopyInfo
{
get
{
if (_MyCopyInfo == null)
_MyCopyInfo = new GridCopyInfo();
return _MyCopyInfo;
}
}
private Color _DefaultCellBackgroundcolor;
public Color DefaultCellBackgroundcolor
@ -648,7 +675,8 @@ namespace Volian.Controls.Library
int blankColSpace = curColWidth;
for (int r = 0; r < Rows.Count; r++)
{
StepRTB srtb = new StepRTB();
using (StepRTB srtb = new StepRTB())
{
CellRange cr = GetMergedRange(r, Col);
srtb.Rtf = GetCellRTFString(cr.r1, cr.c1);
if (Col >= cr.c1 && Col <= cr.c2)
@ -666,6 +694,7 @@ namespace Volian.Controls.Library
blankColSpace = Math.Min(blankColSpace, Math.Max(0, cellWidth - srtb.Width));
}
}
}
//Console.WriteLine("BlankRowSpace {0}", blankRowSpace);
return blankColSpace;
}
@ -1386,7 +1415,8 @@ namespace Volian.Controls.Library
{
// only used in test program
CellRange cr = this.Selection;
StepRTB srtb = new StepRTB();
using (StepRTB srtb = new StepRTB())
{
srtb.Rtf = this.GetCellRTFString(cr.r1, cr.c1);
srtb.SelectAll();
@ -1396,10 +1426,12 @@ namespace Volian.Controls.Library
srtb.SelectionAlignment = (HorizontalAlignment)align;
this.PutCellRTFString(cr.r1, cr.c1, srtb.Rtf);
}
}
public void RTFTextAlignment(CellRange cr, HorizontalAlignment ha)
{
StepRTB srtb = new StepRTB();
using (StepRTB srtb = new StepRTB())
{
for (int rw = cr.r1; rw <= cr.r2; rw++)
for (int cl = cr.c1; cl <= cr.c2; cl++)
{
@ -1409,6 +1441,7 @@ namespace Volian.Controls.Library
this.PutCellRTFString(rw, cl, srtb.Rtf);
}
}
}
public void SetTableBorder(C1.Win.C1FlexGrid.Util.BaseControls.BorderStyleEnum border)
@ -1578,7 +1611,8 @@ namespace Volian.Controls.Library
public void ConvertTextCellToRTF(int r, int c)
{
StepRTB trtb = new StepRTB();
using (StepRTB trtb = new StepRTB())
{
string tstr = null;
bool dummyCharWidth = false;
bool AllowWidthShrink = false;
@ -1702,9 +1736,11 @@ namespace Volian.Controls.Library
// }
//}
}
}
private void AdjustCellHeightWidth(int r, int c)
{
StepRTB trtb = new StepRTB();
using (StepRTB trtb = new StepRTB())
{
string tstr = null;
bool dummyCharWidth = false;
bool AllowWidthShrink = false;
@ -1736,6 +1772,7 @@ namespace Volian.Controls.Library
// Now adjust the Height and Width in the defined merge ranges
AdjustMergeRangeHeightWidth(r, c, trtb, tstr, AllowWidthShrink);
}
}
private void AdjustMergeRangeHeightWidth(int r, int c, StepRTB trtb, string tstr, bool AllowWidthShrink)
{
@ -2045,12 +2082,14 @@ namespace Volian.Controls.Library
// find the needed cell width
if (Col == cr.c1)
{
StepRTB srtb = new StepRTB();
using (StepRTB srtb = new StepRTB())
{
srtb.Rtf = GetCellRTFString(cr.r1, cr.c1);
srtb.AdjustWidthForContent();
curColWidth = Math.Max(curColWidth, srtb.Width + 3);
}
}
}
return curColWidth;
}
@ -2230,7 +2269,8 @@ namespace Volian.Controls.Library
string rtfText = GetDataDisplay(r, c);
if (rtfText.StartsWith(@"{\rtf"))
{
RTF _rtf = new RTF();
using (StepRTB _rtf = new StepRTB())
{
_rtf.Width = Cols[c].Width;
_rtf.Rtf = rtfText;
CellRange cr = GetCellRange(r, c);
@ -2238,6 +2278,7 @@ namespace Volian.Controls.Library
}
}
}
}
#endregion //Cell Text
@ -4156,13 +4197,15 @@ namespace Volian.Controls.Library
{
foreach (CellRange cr in MySelection)
{
StepRTB rtb = new StepRTB();
using (StepRTB rtb = new StepRTB())
{
rtb.Rtf = GetCellRTFString(cr.r1, cr.c1);
rtb.SelectAll();
rtb.SelectionFont = new Font(rtb.SelectionFont, FontStyle.Bold);
this[cr.r1, cr.c1] = rtb.Rtf;
}
}
}
public void ShowMySelection()
{
@ -4205,7 +4248,10 @@ namespace Volian.Controls.Library
public enum GridCopyOption { Row, Column, Selection };
#region RTF Class for Cell rendering
class RTF : StepRTB //RichTextBox
/// <summary>
/// RTF Should only be used if the contents of the richtextbox are to be converted to an image.
/// </summary>
class RTF : StepRTB
{
// messages used by RichEd20.dll
internal const int
@ -4351,7 +4397,10 @@ namespace Volian.Controls.Library
this.Leave += new EventHandler(_editor_Leave);
//this.HeightChanged += new StepRTBEvent(_HeightChanged);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
// start editing: move to cell and activate
public void StartEditing(int row, int col)
{

View File

@ -118,9 +118,10 @@ namespace Volian.MSWord
{
foreach (System.Diagnostics.Process proc in wordProcesses)
{
// TODO: Determine if Word is Visible
// Determine if Word is Visible
// If it is let it run
// otherwise Kill it.
if(proc.MainWindowTitle=="")
proc.Kill();
}
_MyWordApp = null;