diff --git a/PROMS/Baseline/Baseline.csproj b/PROMS/Baseline/Baseline.csproj index 1834a6ec..4a239e50 100644 --- a/PROMS/Baseline/Baseline.csproj +++ b/PROMS/Baseline/Baseline.csproj @@ -67,6 +67,7 @@ frmSettings.cs + diff --git a/PROMS/Baseline/GlobalSuppressions.cs b/PROMS/Baseline/GlobalSuppressions.cs new file mode 100644 index 00000000..046248af --- /dev/null +++ b/PROMS/Baseline/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Not modifying Naming Styles")] diff --git a/PROMS/Baseline/Program.cs b/PROMS/Baseline/Program.cs index 9cc8eb91..64810cc9 100644 --- a/PROMS/Baseline/Program.cs +++ b/PROMS/Baseline/Program.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; namespace Baseline diff --git a/PROMS/Baseline/frmBaseline.cs b/PROMS/Baseline/frmBaseline.cs index 8551661e..d404ac9b 100644 --- a/PROMS/Baseline/frmBaseline.cs +++ b/PROMS/Baseline/frmBaseline.cs @@ -43,12 +43,9 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; -using System.Drawing; using System.Linq; using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; -using System.Collections.Specialized; using System.IO; using System.Text.RegularExpressions; using System.Xml.Serialization; @@ -73,13 +70,8 @@ namespace Baseline } public partial class frmBaseline : Form { - private IgnoreLines _MyIgnore = new IgnoreLines(); - public IgnoreLines MyIgnore - { - get { return _MyIgnore; } - set { _MyIgnore = value; } - } - private LastWas myLast = LastWas.Search; + public IgnoreLines MyIgnore { get; set; } = new IgnoreLines(); + private LastWas myLast = LastWas.Search; private Settings MySettings; public string MyStatus { @@ -151,9 +143,11 @@ namespace Baseline this.WindowState = Properties.Settings.Default.WidnowState; if(Properties.Settings.Default.Ignore != null && Properties.Settings.Default.Ignore != "") MyIgnore = IgnoreLines.Get(Properties.Settings.Default.Ignore); - MySettings= new Settings(); - MySettings.IgnoreLines = new BindingList(); - splitContainer1.SplitterDistance = Properties.Settings.Default.Split1; + MySettings = new Settings + { + IgnoreLines = new BindingList() + }; + splitContainer1.SplitterDistance = Properties.Settings.Default.Split1; splitContainer2.SplitterDistance = Properties.Settings.Default.Split2; splitContainer3.SplitterDistance = Properties.Settings.Default.Split3; if (Properties.Settings.Default.MRU1 != null && Properties.Settings.Default.MRU1.Count > 0) @@ -240,28 +234,27 @@ namespace Baseline lbProcedures.Items.Clear(); lbResults1.Items.Clear(); lbResults2.Items.Clear(); - FindFile ff = lbDifferent.SelectedItem as FindFile; - if (ff != null) - { - // Fill Procedure or Result ListBoxes - switch (myLast) - { - case LastWas.Pagination: - CompareContent(ff.File1, ff.File2);// Compare DebugPagination - break; - case LastWas.Baseline: - CompareContent3(ff.File1, ff.File2);// Compare DebugMeta - break; - case LastWas.Search: - ShowSearchResults(ff.File1, ff.File2);// Perform search on DebugMeta - break; - default: - CompareContent(ff.File1, ff.File2);//Default DebugPagination - break; - } - //CompareOneFile(ff.File1, ff.File2); - } - } + if (lbDifferent.SelectedItem is FindFile ff) + { + // Fill Procedure or Result ListBoxes + switch (myLast) + { + case LastWas.Pagination: + CompareContent(ff.File1, ff.File2);// Compare DebugPagination + break; + case LastWas.Baseline: + CompareContent3(ff.File1, ff.File2);// Compare DebugMeta + break; + case LastWas.Search: + ShowSearchResults(ff.File1, ff.File2);// Perform search on DebugMeta + break; + default: + CompareContent(ff.File1, ff.File2);//Default DebugPagination + break; + } + //CompareOneFile(ff.File1, ff.File2); + } + } Procedures MyProcs1; Procedures MyProcs2; /// @@ -361,13 +354,6 @@ namespace Baseline lines1 = list1.AsEnumerable();// Convert back to Enumerable to work with LINQ return lines1; } - private string GetProcNum(string line) - { - string retval = line.Substring(3, line.IndexOf(" | ") - 3); - if (retval.Contains("_")) - retval = retval.Substring(0, retval.IndexOf("_") - 1); - return retval; - } /// /// Include lines for Procedure or Page or Search is true /// Account for Case Insensitive CheckBox @@ -450,8 +436,8 @@ namespace Baseline private void lbResults1_SelectedIndexChanged(object sender, EventArgs e) { string line=null; - if (lbResults1.SelectedItem is string) - line = (string)lbResults1.SelectedItem; + if (lbResults1.SelectedItem is string v) + line = v; Line myLine = lbResults1.SelectedItem as Line; switch (myLast) { @@ -472,8 +458,8 @@ namespace Baseline { string line=null; - if(lbResults2.SelectedItem is string) - line = (string)lbResults2.SelectedItem; + if(lbResults2.SelectedItem is string v) + line = v; Line myLine = lbResults2.SelectedItem as Line; switch (myLast) @@ -515,16 +501,10 @@ namespace Baseline /// private string ParseOutProcedureNumberFromLine(string txt) { - // old logic was looking for the first occurence of ".S" in the txt string as the ending point of the procedure nuumber - // Beaver Valley has a procedure number "1.SBGEN" in which the old logic would not work - // 1.SBGEN.SC. ==> short path of attachment section "C" - // 1.SBGEN.SC..S1. ==> short path of Step 1 in attachment section "C" - string rtnstr = null; - int lidx = -1; - // if the item is to a high levels step or sub-step the short path as "..S" for each part of the step - // so look for the last occurence of ".." which will be the end of the section information - lidx = txt.LastIndexOf(".."); - if (lidx > 0) + // if the item is to a high levels step or sub-step the short path as "..S" for each part of the step + // so look for the last occurence of ".." which will be the end of the section information + int lidx = txt.LastIndexOf(".."); + if (lidx > 0) { lidx = txt.LastIndexOf(".S", lidx); // this will position us to the end of the procedure number } @@ -532,9 +512,13 @@ namespace Baseline { lidx = txt.LastIndexOf(".S"); // this will position us to the end of the procedure number if there was no step information } - // B2018-113 - Replace slashes and backslashes with underscores just as PROMS does when creating a PDF file. - rtnstr = txt.Substring(8, lidx - 8).Replace("/", "_").Replace("\\", "_"); - return rtnstr; + // old logic was looking for the first occurence of ".S" in the txt string as the ending point of the procedure nuumber + // Beaver Valley has a procedure number "1.SBGEN" in which the old logic would not work + // 1.SBGEN.SC. ==> short path of attachment section "C" + // 1.SBGEN.SC..S1. ==> short path of Step 1 in attachment section "C" + // B2018-113 - Replace slashes and backslashes with underscores just as PROMS does when creating a PDF file. + string rtnstr = txt.Substring(8, lidx - 8).Replace("/", "_").Replace("\\", "_"); + return rtnstr; } string exePath; @@ -616,10 +600,10 @@ namespace Baseline progname = @"C:\Program Files (x86)\IDM Computer Solutions\UltraCompare\UC.exe"; System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(progname, string.Format(@" -t ""{0}"" ""{1}""", compareFile, baseFile)); - System.Diagnostics.Process prc = System.Diagnostics.Process.Start(psi); - } + _ = System.Diagnostics.Process.Start(psi); + } - private ProcessLocationQueue myQueue= new ProcessLocationQueue(); + private readonly ProcessLocationQueue myQueue= new ProcessLocationQueue(); private Timer queueTimer = null; /// /// Move a Process to a specific screen location - This is done with a timer so @@ -632,9 +616,11 @@ namespace Baseline { if (queueTimer == null) { - queueTimer = new Timer(); - queueTimer.Enabled = false; - queueTimer.Tick += queueTimer_Tick; + queueTimer = new Timer + { + Enabled = false + }; + queueTimer.Tick += queueTimer_Tick; queueTimer.Interval = 1000; } myQueue.Add(proc, x, y); @@ -669,8 +655,8 @@ namespace Baseline string procPatern = string.Format("*{0}*.pdf", proc == string.Empty ? "noProcNumber" : proc); int pagenum = myLine.MyPage.Number; FindFile ff = lbDifferent.SelectedItem as FindFile; - string PDFfileName = null; - if (list == 1) + string PDFfileName; + if (list == 1) { FileInfo fi1 = new FileInfo(ff.File1); PDFfileName = GetPFDFileAndPath(fi1, procPatern); @@ -701,11 +687,13 @@ namespace Baseline return; } } - // open the PDF and jump to the page number - System.Diagnostics.ProcessStartInfo psi1 = new System.Diagnostics.ProcessStartInfo(exePath, string.Format("/A \"page={0}\" \"{1}\" ", pagenum,PDFfileName)); - psi1.UseShellExecute = false; - System.Diagnostics.Process p1 = System.Diagnostics.Process.Start(psi1); - } + // open the PDF and jump to the page number + System.Diagnostics.ProcessStartInfo psi1 = new System.Diagnostics.ProcessStartInfo(exePath, string.Format("/A \"page={0}\" \"{1}\" ", pagenum, PDFfileName)) + { + UseShellExecute = false + }; + _ = System.Diagnostics.Process.Start(psi1); + } /// /// Perform Debug Meta file comparison for all of the folders within the automated testing folders /// @@ -785,11 +773,10 @@ namespace Baseline } private void lbProcedures_SelectedIndexChanged(object sender, EventArgs e) { - //Initialize Results List Box - Procedure myProc = lbProcedures.SelectedItem as Procedure; - if (myProc == null) return; // clicked on the white space (blank line) in the list of different procedures - //TODO: May need to consider if there are duplicate procedure numers and titles - Procedure myProc1 = MyProcs1.Find(x => x.Number == myProc.Number && x.Title == myProc.Title); + //Initialize Results List Box + if (!(lbProcedures.SelectedItem is Procedure myProc)) return; // clicked on the white space (blank line) in the list of different procedures + //TODO: May need to consider if there are duplicate procedure numers and titles + Procedure myProc1 = MyProcs1.Find(x => x.Number == myProc.Number && x.Title == myProc.Title); // Build the results ListBox for the left window lbResults1.Items.Clear(); if (myProc1 != null) @@ -836,28 +823,13 @@ namespace Baseline }; public class Settings { - private BindingList _IgnoreLines; - public BindingList IgnoreLines - { - get { return _IgnoreLines; } - set { _IgnoreLines = value; } - } - } + public BindingList IgnoreLines { get; set; } + } public partial class FindFile { - private string _File1; - public string File1 - { - get { return _File1; } - set { _File1 = value; } - } - private string _File2; - public string File2 - { - get { return _File2; } - set { _File2 = value; } - } - public FindFile(string file1, string file2) + public string File1 { get; set; } + public string File2 { get; set; } + public FindFile(string file1, string file2) { File1 = file1; File2 = file2; @@ -865,19 +837,16 @@ namespace Baseline } public partial class FindFiles : List { - private string _FileName; - public string FileName - { - get { return _FileName; } - } - /// - /// Build list of DocVersion Folders with differences - /// - /// Base path - /// Compare path - /// filename - /// Ignore list - public FindFiles(string path1, string path2, string fileName,IgnoreLines myIgnore) + private readonly string _FileName; + public string FileName => _FileName; + /// + /// Build list of DocVersion Folders with differences + /// + /// Base path + /// Compare path + /// filename + /// Ignore list + public FindFiles(string path1, string path2, string fileName,IgnoreLines myIgnore) { DirectoryInfo di1 = new DirectoryInfo(path1); DirectoryInfo di2 = new DirectoryInfo(path2); @@ -1103,34 +1072,16 @@ namespace Baseline // Text - the line of text public partial class Procedure { - private string _Number; - public string Number + public string Number { get; set; } + public string Title { get; set; } + public Pages MyPages { get; set; } = new Pages(); + public Procedure(string number, string title) { - get { return _Number; } - set { _Number = value; } + Number = number; + Title = title; } - private string _Title; - public string Title - { - get { return _Title; } - set { _Title = value; } - } - private Pages _MyPages = new Pages(); - public Pages MyPages - { - get { return _MyPages; } - set { _MyPages = value; } - } - public Procedure(string number, string title) - { - _Number = number; - _Title = title; - } - public override string ToString() - { - return string.Format("{0} - {1}", Number, Title); - } - } + public override string ToString() => string.Format("{0} - {1}", Number, Title); + } public partial class Procedures : List { // Sample data for a Procedure Number line @@ -1161,77 +1112,34 @@ namespace Baseline } public partial class Page { - private int _Number; - public int Number - { - get { return _Number; } - set { _Number = value; } - } - private Lines _MyLines = new Lines(); + public int Number { get; set; } - public Lines MyLines - { - get { return _MyLines; } - set { _MyLines = value; } - } - public Page(int number) - { - _Number = number; - } - public override string ToString() - { - return string.Format("Page {0}", Number); - } - } + public Lines MyLines { get; set; } = new Lines(); + public Page(int number) => Number = number; + public override string ToString() => string.Format("Page {0}", Number); + } public partial class Pages : List { - public void Add(int number) - { - Add(new Page(number)); - } - } + public void Add(int number) => Add(new Page(number)); + } public partial class Line { - private Procedure _MyProc; - public Procedure MyProc + public Procedure MyProc { get; set; } + public Page MyPage { get; set; } + public string Text { get; set; } + public Line(string text) => Text = text; + public Line(string text, Procedure myProc, Page myPage) { - get { return _MyProc; } - set { _MyProc = value; } + Text = text; + MyProc = myProc; + MyPage = myPage; } - private Page _MyPage; - public Page MyPage - { - get { return _MyPage; } - set { _MyPage = value; } - } - private string _Text; - public string Text - { - get { return _Text; } - set { _Text = value; } - } - public Line(string text) - { - _Text = text; - } - public Line(string text, Procedure myProc, Page myPage) - { - _Text = text; - _MyProc = myProc; - _MyPage = myPage; - } - public override string ToString() - { - return Text; - } - } + public override string ToString() => Text; + } public partial class Lines : List { - public void Add(string text) - { - Add(new Line(text)); - } - } + public void Add(string text) => Add(new Line(text)); + } [Serializable] public partial class IgnoreLine { @@ -1269,21 +1177,12 @@ namespace Baseline public IgnoreLines() { } - public void Add(string text, Relation searchType, bool active) - { - Add(new IgnoreLine(text, searchType, active)); - } - // Convert IgnoreLines to string (XML) - public override string ToString() - { - return GenericSerializer.StringSerialize(this); - } - // Convert string to IgnoreLines - public static IgnoreLines Get(string xml) - { - return GenericSerializer.StringDeserialize(xml); - } - } + public void Add(string text, Relation searchType, bool active) => Add(new IgnoreLine(text, searchType, active)); + // Convert IgnoreLines to string (XML) + public override string ToString() => GenericSerializer.StringSerialize(this); + // Convert string to IgnoreLines + public static IgnoreLines Get(string xml) => GenericSerializer.StringDeserialize(xml); + } /// /// This is a simple serializer that takes a class and converts it to and from string (XML) /// @@ -1311,7 +1210,7 @@ namespace Baseline string ss = s.Replace("encoding=\"utf-16\"", ""); XmlSerializer xs = new XmlSerializer(typeof(T)); UTF8Encoding enc = new UTF8Encoding(); - Byte[] arrBytData = enc.GetBytes(ss); + byte[] arrBytData = enc.GetBytes(ss); using (MemoryStream ms = new MemoryStream(arrBytData)) { t = (T)xs.Deserialize(ms); @@ -1325,12 +1224,9 @@ namespace Baseline public class NonXsiTextWriter : XmlTextWriter { public NonXsiTextWriter(TextWriter w) : base(w) { } - public NonXsiTextWriter(Stream w, Encoding encoding) - : base(w, encoding) - { - this.Formatting = Formatting.Indented; - } - public NonXsiTextWriter(string filename, Encoding encoding) : base(filename, encoding) { } + public NonXsiTextWriter(Stream w, Encoding encoding) + : base(w, encoding) => Formatting = Formatting.Indented; + public NonXsiTextWriter(string filename, Encoding encoding) : base(filename, encoding) { } bool _skip = false; public override void WriteStartAttribute(string prefix, string localName, string ns) { @@ -1372,32 +1268,16 @@ namespace Baseline public const short SWP_NOZORDER = 0X4; public const int SWP_SHOWWINDOW = 0x0040; - private System.Diagnostics.Process _Process; - - public System.Diagnostics.Process Process - { - get { return _Process; } - set { _Process = value; } - } - private int _X; - public int X - { - get { return _X; } - set { _X = value; } - } - private int _Y; - public int Y - { - get { return _Y; } - set { _Y = value; } - } - public ProcessLocation(System.Diagnostics.Process process, int x, int y) + public System.Diagnostics.Process Process { get; set; } + public int X { get; set; } + public int Y { get; set; } + public ProcessLocation(System.Diagnostics.Process process, int x, int y) { Process = process; X = x; Y = y; } - private static Boolean FoxitSettingInfo = true; + private static bool FoxitSettingInfo = true; /// /// MoveIt() moves the window containing the PDF viewer to the right so the two pdf viewer windows will not overlap. @@ -1418,11 +1298,8 @@ namespace Baseline } public class ProcessLocationQueue: Queue { - public void Add(System.Diagnostics.Process process, int x, int y) - { - Enqueue(new ProcessLocation(process,x,y)); - } - public void ProcessNext() + public void Add(System.Diagnostics.Process process, int x, int y) => Enqueue(new ProcessLocation(process, x, y)); + public void ProcessNext() { ProcessLocation pl = Dequeue(); pl.MoveIt(); diff --git a/PROMS/Baseline/frmSettings.cs b/PROMS/Baseline/frmSettings.cs index 361fe543..0a0cddfe 100644 --- a/PROMS/Baseline/frmSettings.cs +++ b/PROMS/Baseline/frmSettings.cs @@ -1,11 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace Baseline @@ -19,17 +12,7 @@ namespace Baseline set { _MyIgnore = value; dgv.DataSource=null; - //dgvcSearchType.ValueType = typeof(Relation); - //dgvcSearchType.ValueMember = "Value"; - //dgvcSearchType.DisplayMember = "Display"; - //dgvcSearchType.DataSource = new Relation[] { Relation.Contains, Relation.StartsWith, Relation.EndsWith, Relation.Regex } - //.Select(x => new { Display = x.ToString(), Value = x }) - //.ToList(); dgv.DataSource=value; - //dgvcSearchType.DataSource = - //new List((Relation[]) Enum.GetValues(typeof(Relation))) - //.Select(x => new { Display=x.ToString(), Value=(int)x }) - //.ToList();; } } public frmSettings(IgnoreLines myIgnore) @@ -46,19 +29,16 @@ namespace Baseline col.ValueType = typeof(Relation); } - private void dgv_DataError(object sender, DataGridViewDataErrorEventArgs e) + private void dgv_DataError(object sender, DataGridViewDataErrorEventArgs e) => Console.WriteLine("Here"); + private void btnOK_Click(object sender, EventArgs e) { - Console.WriteLine("Here"); - } - private void btnOK_Click(object sender, EventArgs e) - { - this.DialogResult = System.Windows.Forms.DialogResult.OK; - this.Close(); + DialogResult = System.Windows.Forms.DialogResult.OK; + Close(); } private void btnCancel_Click(object sender, EventArgs e) { - this.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.Close(); + DialogResult = System.Windows.Forms.DialogResult.Cancel; + Close(); } } } diff --git a/PROMS/Volian.Base.Library/BigNum.cs b/PROMS/Volian.Base.Library/BigNum.cs index 1567917a..eb133fce 100644 --- a/PROMS/Volian.Base.Library/BigNum.cs +++ b/PROMS/Volian.Base.Library/BigNum.cs @@ -6,7 +6,6 @@ using System.Xml.Serialization; namespace Volian.Base.Library { [Serializable()] - //[XmlRoot("BigNum")] public class BigNum { #region fields @@ -22,19 +21,10 @@ namespace Volian.Base.Library public BigNum() { } - public BigNum(int value) - { - SetFlag(value); - } - public BigNum(string values) - { - SetFlags(values); - } - public BigNum(ICollection values) - { - SetFlags(values); - } - public override string ToString() + public BigNum(int value) => SetFlag(value); + public BigNum(string values) => SetFlags(values); + public BigNum(ICollection values) => SetFlags(values); + public override string ToString() { return FlagList; } @@ -58,10 +48,6 @@ namespace Volian.Base.Library } #endregion #region methods - //public override string ToString() - //{ - // return GenericSerializer.StringSerialize(this); - //} public bool Includes(BigNum other) { List mine = GetFlags(); @@ -82,12 +68,6 @@ namespace Volian.Base.Library public List GetFlags() { List myints = new List(); - //if (MyValue.Count == 0)//1 && MyValue.ContainsKey(0) && MyValue[0] == 0) - //{ - // myints.Add(-1); - //} - //else - //{ foreach (uint key in MyValue.Keys) { ulong y = MyValue[key]; @@ -97,18 +77,10 @@ namespace Volian.Base.Library myints.Add((int)(i + (key * 64))); } } - //} return myints; } public void SetFlag(int flag) { - //if (flag == -1) - //{ - // MyValue = new SortedDictionary(); - // //MyValue.Add(0, 0); - //} - //else - //{ uint offset = (uint)(flag / 64); ulong x = one << (flag % 64); if (MyValue.ContainsKey(offset)) @@ -122,15 +94,10 @@ namespace Volian.Base.Library foreach (int f in flags) SetFlag(f); } - public static BigNum MakeBigNum(string numbers) - { - if (numbers == "-1") - return null; - return new BigNum(numbers); - } - #endregion - #region properties - [XmlAttribute] + public static BigNum MakeBigNum(string numbers) => numbers == "-1" ? null : new BigNum(numbers); + #endregion + #region properties + [XmlAttribute] public string FlagList { get diff --git a/PROMS/Volian.Base.Library/ByteArrayCompare.cs b/PROMS/Volian.Base.Library/ByteArrayCompare.cs index bd833e4a..e85ba376 100644 --- a/PROMS/Volian.Base.Library/ByteArrayCompare.cs +++ b/PROMS/Volian.Base.Library/ByteArrayCompare.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Volian.Base.Library +namespace Volian.Base.Library { public static class ByteArrayCompare { diff --git a/PROMS/Volian.Base.Library/DebugPrint.cs b/PROMS/Volian.Base.Library/DebugPrint.cs index bd0e4b44..8e870a37 100644 --- a/PROMS/Volian.Base.Library/DebugPrint.cs +++ b/PROMS/Volian.Base.Library/DebugPrint.cs @@ -1,17 +1,12 @@ using System; -using System.Collections.Generic; -using System.Text; using System.IO; namespace Volian.Base.Library { public class DebugPrint:IDisposable { - public void Dispose() - { - Close(); - } - private StreamWriter _MyStreamWriter = null; + public void Dispose() => Close(); + private StreamWriter _MyStreamWriter = null; public StreamWriter MyStreamWriter { get { return _MyStreamWriter; } @@ -25,11 +20,8 @@ namespace Volian.Base.Library _MyStreamWriter = value; } } - public bool IsOpen - { - get { return MyStreamWriter != null; } - } - private string _FileName = null; + public bool IsOpen => MyStreamWriter != null; + private string _FileName = null; public string FileName { get { return _FileName; } @@ -40,22 +32,15 @@ namespace Volian.Base.Library MyFileInfo = new FileInfo(value); } } - private FileInfo _MyFileInfo; - public FileInfo MyFileInfo - { - get { return _MyFileInfo; } - set { _MyFileInfo = value; } - } - public void Open(string fileName) + + public FileInfo MyFileInfo { get; set; } + public void Open(string fileName) { FileName = fileName; MyStreamWriter = MyFileInfo.CreateText(); } - public void Close() - { - MyStreamWriter = null; - } - public void Write(string format, params object[] args) + public void Close() => MyStreamWriter = null; + public void Write(string format, params object[] args) { if (IsOpen) MyStreamWriter.Write(format, args); } @@ -73,98 +58,62 @@ namespace Volian.Base.Library } public static class DebugPagination { - private static int _TotalPages = 0; - public static int TotalPages - { - get { return _TotalPages; } - set { _TotalPages = value; } - } - private static DebugPrint _MyDebugPrint = new DebugPrint(); - public static void Open(string fileName) - { _MyDebugPrint.Open(fileName); } - public static void Close() + public static int TotalPages { get; set; } = 0; + private static readonly DebugPrint _MyDebugPrint = new DebugPrint(); + public static void Open(string fileName) => _MyDebugPrint.Open(fileName); + public static void Close() { WriteLine("{0} Total Pages", TotalPages); _MyDebugPrint.Close(); } - public static void Write(string format, params object[] args) - { _MyDebugPrint.Write(format, args); } - public static void WriteLine(string format, params object[] args) - { _MyDebugPrint.WriteLine(format, args); } - public static void Show() - { _MyDebugPrint.Show(); } - public static bool IsOpen - { get { return _MyDebugPrint.IsOpen; } } - } + public static void Write(string format, params object[] args) => _MyDebugPrint.Write(format, args); + public static void WriteLine(string format, params object[] args) => _MyDebugPrint.WriteLine(format, args); + public static void Show() => _MyDebugPrint.Show(); + public static bool IsOpen => _MyDebugPrint.IsOpen; + } public static class DebugText { - private static DebugPrint _MyDebugPrint = new DebugPrint(); - public static void Open(string fileName) - { _MyDebugPrint.Open(fileName); } - public static void Close() - { _MyDebugPrint.Close(); } - public static void Write(string format, params object[] args) - { _MyDebugPrint.Write(format, args); } - public static void WriteLine(string format, params object[] args) - { _MyDebugPrint.WriteLine(format, args); } - public static void Show() - { _MyDebugPrint.Show(); } - public static bool IsOpen - { get { return _MyDebugPrint.IsOpen; } } - } + private static readonly DebugPrint _MyDebugPrint = new DebugPrint(); + public static void Open(string fileName) => _MyDebugPrint.Open(fileName); + public static void Close() => _MyDebugPrint.Close(); + public static void Write(string format, params object[] args) => _MyDebugPrint.Write(format, args); + public static void WriteLine(string format, params object[] args) => _MyDebugPrint.WriteLine(format, args); + public static void Show() => _MyDebugPrint.Show(); + public static bool IsOpen => _MyDebugPrint.IsOpen; + } public static class DebugProfile { private static DebugPrint _MyDebugPrint = new DebugPrint(); - public static void Open(string fileName) - { _MyDebugPrint.Open(fileName); } - public static void Close() + public static void Open(string fileName) => _MyDebugPrint.Open(fileName); + public static void Close() { _MyDebugPrint.Close(); _MyDebugPrint = null; } - public static void Write(string format, params object[] args) - { _MyDebugPrint.Write(format, args); } - public static void WriteLine(string format, params object[] args) - { _MyDebugPrint.WriteLine(format, args); } - public static void Show() - { _MyDebugPrint.Show(); } - public static bool IsOpen - { get { return _MyDebugPrint.IsOpen; } } - } + public static void Write(string format, params object[] args) => _MyDebugPrint.Write(format, args); + public static void WriteLine(string format, params object[] args) => _MyDebugPrint.WriteLine(format, args); + public static void Show() => _MyDebugPrint.Show(); + public static bool IsOpen => _MyDebugPrint.IsOpen; + } public static class DebugDBTrack { private static DebugPrint _MyDebugPrint = new DebugPrint(); - public static void Open(string fileName) - { _MyDebugPrint.Open(fileName); } - public static void Close() + public static void Open(string fileName) => _MyDebugPrint.Open(fileName); + public static void Close() { _MyDebugPrint.Close(); _MyDebugPrint = null; } - public static void Write(string format, params object[] args) - { _MyDebugPrint.Write(format, args); } - public static void WriteLine(string format, params object[] args) - { _MyDebugPrint.WriteLine(format, args); } - public static void Show() - { _MyDebugPrint.Show(); } - public static bool IsOpen - { get { return _MyDebugPrint.IsOpen; } } - } + public static void Write(string format, params object[] args) => _MyDebugPrint.Write(format, args); + public static void WriteLine(string format, params object[] args) => _MyDebugPrint.WriteLine(format, args); + public static void Show() => _MyDebugPrint.Show(); + public static bool IsOpen => _MyDebugPrint.IsOpen; + } // C2018-004 create meta file for baseline compares public static class BaselineMetaFile { - private static DebugPrint _MyDebugPrint = new DebugPrint(); - public static void Open(string fileName) - { _MyDebugPrint.Open(fileName); } - public static void Close() - { _MyDebugPrint.Close(); } - public static void Write(string format, params object[] args) - { _MyDebugPrint.Write(format, args); } - public static void WriteLine(string format, params object[] args) - { _MyDebugPrint.WriteLine(format, args); } - public static void Show() - { _MyDebugPrint.Show(); } - public static bool IsOpen - { get { return _MyDebugPrint.IsOpen; } } - private static bool _IncludeWordSecText = true; - public static bool IncludeWordSecText - { - get { return BaselineMetaFile._IncludeWordSecText; } - set { BaselineMetaFile._IncludeWordSecText = value; } - } - } + private static readonly DebugPrint _MyDebugPrint = new DebugPrint(); + public static void Open(string fileName) => _MyDebugPrint.Open(fileName); + public static void Close() => _MyDebugPrint.Close(); + public static void Write(string format, params object[] args) => _MyDebugPrint.Write(format, args); + public static void WriteLine(string format, params object[] args) => _MyDebugPrint.WriteLine(format, args); + public static void Show() => _MyDebugPrint.Show(); + public static bool IsOpen => _MyDebugPrint.IsOpen; + + public static bool IncludeWordSecText { get; set; } = true; + } } diff --git a/PROMS/Volian.Base.Library/ExeInfo.cs b/PROMS/Volian.Base.Library/ExeInfo.cs index 5d0e6eeb..ad4cd42c 100644 --- a/PROMS/Volian.Base.Library/ExeInfo.cs +++ b/PROMS/Volian.Base.Library/ExeInfo.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.IO; using System.Linq; @@ -10,21 +8,17 @@ namespace Volian.Base.Library { #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - public static string GetROEditorPath() - { - string roapp = PROMSExecutableFolderPath() + @"\ROEDITOR.EXE"; - return roapp; - } + #endregion + public static string GetROEditorPath() => $@"{PROMSExecutableFolderPath()}\ROEDITOR.EXE"; - // returns the path to the executable folder - public static string PROMSExecutableFolderPath() + // returns the path to the executable folder + public static string PROMSExecutableFolderPath() { string pathPROMSexe = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); if (pathPROMSexe[7] == ':') // either a local drive or a mapped network drive pathPROMSexe = pathPROMSexe.Substring(6); else - pathPROMSexe = @"\" + pathPROMSexe.Substring(5); // non-mapped network drive - need to add extra back slash in front + pathPROMSexe = $@"\{pathPROMSexe.Substring(5)}"; // non-mapped network drive - need to add extra back slash in front return pathPROMSexe; } @@ -34,7 +28,7 @@ namespace Volian.Base.Library try { // Build the path to the PROMSFixes.sql file located in the PROMS exe folder - string pathPROMSFixes = PROMSExecutableFolderPath() + @"\PROMSFixes.sql"; + string pathPROMSFixes = $@"{PROMSExecutableFolderPath()}\PROMSFixes.sql"; // open the PROMSFixes.sql file and grab the line of text containing the PROMSFixes RevDate // using Linq to open and read the PROMSFixes file diff --git a/PROMS/Volian.Base.Library/FlagEnumEditor.cs b/PROMS/Volian.Base.Library/FlagEnumEditor.cs index 0caf5736..4aef313b 100644 --- a/PROMS/Volian.Base.Library/FlagEnumEditor.cs +++ b/PROMS/Volian.Base.Library/FlagEnumEditor.cs @@ -1,8 +1,5 @@ using System; -using System.Collections; using System.ComponentModel; -using System.Drawing; -using System.Data; using System.Windows.Forms; using System.Drawing.Design; using System.Windows.Forms.Design; @@ -13,7 +10,6 @@ namespace Volian.Base.Library public class FlagCheckedListBox : CheckedListBox { - private System.ComponentModel.Container components = null; public FlagCheckedListBox() { @@ -21,16 +17,6 @@ namespace Volian.Base.Library InitializeComponent(); } - protected override void Dispose(bool disposing) - { - if (disposing) - { - if (components != null) - components.Dispose(); - } - base.Dispose(disposing); - } - #region Component Designer generated code private void InitializeComponent() { @@ -124,7 +110,7 @@ namespace Volian.Base.Library // If the item has been unchecked, remove its bits from the sum if (cs == CheckState.Unchecked) - sum = sum & (~composite.value); + sum &= (~composite.value); // If the item has been checked, combine its bits with the sum else sum |= composite.value; @@ -207,27 +193,15 @@ namespace Volian.Base.Library caption = c; } - public override string ToString() - { - return caption; - } + public override string ToString() => caption; - // Returns true if the value corresponds to a single bit being set - public bool IsFlag - { - get - { - return ((value & (value - 1)) == 0); - } - } + // Returns true if the value corresponds to a single bit being set + public bool IsFlag => (value & (value - 1)) == 0; - // Returns true if this value is a member of the composite bit value - public bool IsMemberFlag(FlagCheckedListBoxItem composite) - { - return (IsFlag && ((value & composite.value) == value)); - } + // Returns true if this value is a member of the composite bit value + public bool IsMemberFlag(FlagCheckedListBoxItem composite) => IsFlag && ((value & composite.value) == value); - public uint value; + public uint value; public string caption; } @@ -236,13 +210,15 @@ namespace Volian.Base.Library public class FlagEnumUIEditor : UITypeEditor { // The checklistbox - private FlagCheckedListBox flagEnumCB; + private readonly FlagCheckedListBox flagEnumCB; public FlagEnumUIEditor() { - flagEnumCB = new FlagCheckedListBox(); - flagEnumCB.BorderStyle = BorderStyle.None; - } + flagEnumCB = new FlagCheckedListBox + { + BorderStyle = BorderStyle.None + }; + } public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { @@ -266,12 +242,9 @@ namespace Volian.Base.Library return null; } - public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) - { - return UITypeEditorEditStyle.DropDown; - } + public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) => UITypeEditorEditStyle.DropDown; - } + } } diff --git a/PROMS/Volian.Base.Library/FrmPopupStatusMessage.cs b/PROMS/Volian.Base.Library/FrmPopupStatusMessage.cs index 4894102e..0fd70ca0 100644 --- a/PROMS/Volian.Base.Library/FrmPopupStatusMessage.cs +++ b/PROMS/Volian.Base.Library/FrmPopupStatusMessage.cs @@ -1,12 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.Windows.Forms; namespace Volian.Base.Library { diff --git a/PROMS/Volian.Base.Library/GenericSerializer.cs b/PROMS/Volian.Base.Library/GenericSerializer.cs index 107b293d..8678da13 100644 --- a/PROMS/Volian.Base.Library/GenericSerializer.cs +++ b/PROMS/Volian.Base.Library/GenericSerializer.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Text; using System.IO; using System.Xml; @@ -17,7 +16,6 @@ namespace Volian.Base.Library using (MemoryStream ms = new MemoryStream()) { xs.Serialize(new NonXsiTextWriter(ms, Encoding.Unicode), t); - //xs.Serialize(ms, t); ms.Position = 0; StreamReader sr = new StreamReader(ms); strOutput = sr.ReadToEnd(); @@ -38,26 +36,6 @@ namespace Volian.Base.Library } return t; } - //public static void WriteFile(T t, string fileName) - //{ - // string strOutput = string.Empty; - // XmlSerializer xs = new XmlSerializer(typeof(T)); - // using (FileStream fs = new FileStream(fileName, FileMode.Create)) - // { - // xs.Serialize(new NonXsiTextWriter(fs, Encoding.UTF8), t); - // fs.Close(); - // } - //} - //public static T ReadFile(string fileName) - //{ - // T t; - // XmlSerializer xs = new XmlSerializer(typeof(T)); - // using (FileStream fs = new FileStream(fileName, FileMode.Open)) - // { - // t = (T)xs.Deserialize(fs); - // } - // return t; - //} } public class NonXsiTextWriter : XmlTextWriter { @@ -79,8 +57,6 @@ namespace Volian.Base.Library } if (localName == "xlink_href") base.WriteStartAttribute(prefix, "xlink:href", ns); - //else if (localName == "encoding") - // _skip = true; else base.WriteStartAttribute(prefix, localName, ns); } diff --git a/PROMS/Volian.Base.Library/GlobalSuppressions.cs b/PROMS/Volian.Base.Library/GlobalSuppressions.cs new file mode 100644 index 00000000..046248af --- /dev/null +++ b/PROMS/Volian.Base.Library/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Not modifying Naming Styles")] diff --git a/PROMS/Volian.Base.Library/PropGridCollEditor.cs b/PROMS/Volian.Base.Library/PropGridCollEditor.cs index d582b2a4..0f7fe125 100644 --- a/PROMS/Volian.Base.Library/PropGridCollEditor.cs +++ b/PROMS/Volian.Base.Library/PropGridCollEditor.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Text; -using System.ComponentModel; using System.ComponentModel.Design; using System.Windows.Forms; using System.Reflection; @@ -17,10 +13,10 @@ namespace Volian.Base.Library // PropertyValueChanged event args... public delegate void MyPropertyValueChangedEventHandler(object sender, PropertyValueChangedEventArgs e); public static event MyPropertyValueChangedEventHandler MyPropertyValueChanged; - private bool AllowAddDel = false; // flags whether the Add/Delete buttons should be displayed: + private readonly bool AllowAddDel = false; // flags whether the Add/Delete buttons should be displayed: // Inherit the default constructor from the standard // Collection Editor... - private Type _origType; + private readonly Type _origType; public PropGridCollEditor(Type type) : base(type) { @@ -29,11 +25,8 @@ namespace Volian.Base.Library if (type.Name == "ReplaceStrData") AllowAddDel = true; // Defaults to not having the 'Add' & 'Remove' buttons. } - protected override Type CreateCollectionItemType() - { - return base.CreateCollectionItemType(); - } - private Button resetbtn = null; + protected override Type CreateCollectionItemType() => base.CreateCollectionItemType(); + private Button resetbtn = null; // Override this method in order to access the containing user controls // from the default Collection Editor form or to add new ones... protected override CollectionForm CreateCollectionForm() @@ -49,30 +42,31 @@ namespace Volian.Base.Library if (!AllowAddDel) { - // add a reset button and put next to ok button: - resetbtn = new Button(); - resetbtn.Text = "Reset"; - resetbtn.Location = new System.Drawing.Point(okbtn.Location.X - 20, okbtn.Location.Y); - resetbtn.Width = 250; - resetbtn.Visible = true; - resetbtn.Enabled = false; // only enabled on data change - resetbtn.Click += resetbtn_Click; + // add a reset button and put next to ok button: + resetbtn = new Button + { + Text = "Reset", + Location = new System.Drawing.Point(okbtn.Location.X - 20, okbtn.Location.Y), + Width = 250, + Visible = true, + Enabled = false // only enabled on data change + }; + resetbtn.Click += resetbtn_Click; okbtn.Parent.Controls.Add(resetbtn); } SetMembersLabel(collectionForm); - TableLayoutPanel tlpLayout = frmCollectionEditorForm.Controls[0] as TableLayoutPanel; - if (tlpLayout != null) - { - // Get a reference to the inner PropertyGrid and hook an event handler to it. - if (tlpLayout.Controls[5] is PropertyGrid) - { - propertyGrid = tlpLayout.Controls[5] as PropertyGrid; - propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged); - propertyGrid.SelectedGridItemChanged += PG_SelectedGridItemChanged; - } - } + if (frmCollectionEditorForm.Controls[0] is TableLayoutPanel tlpLayout) + { + // Get a reference to the inner PropertyGrid and hook an event handler to it. + if (tlpLayout.Controls[5] is PropertyGrid) + { + propertyGrid = tlpLayout.Controls[5] as PropertyGrid; + propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged); + propertyGrid.SelectedGridItemChanged += PG_SelectedGridItemChanged; + } + } - return collectionForm; + return collectionForm; } // when the reset button is clicked the data will be reset to the data from the original format file. Note that if @@ -93,28 +87,15 @@ namespace Volian.Base.Library else if (SelectedGridField.Contains("Active CheckOff")) ResetValue(propertyGrid.SelectedGridItem.Parent.Parent.Value, "Active"); } - private void ShowReflection(Object data) - { - if (data == null) return; - //Object data = new A(); - FieldInfo[] fields = data.GetType().GetFields(BindingFlags.Public | - BindingFlags.NonPublic | - BindingFlags.Instance); - String str = ""; - foreach (FieldInfo f in fields) - { - str += f.Name + " = " + f.GetValue(data) + "\r\n"; - } - Console.WriteLine("reflection = {0}", str); - } - PropertyGrid propertyGrid = null; + + PropertyGrid propertyGrid = null; private string SelectedGridField = ""; // The following method is used to enable and set text on the 'Reset' button. When a grid item is selected, if it has // UCF data, then put the original value as part of the button text & enable it: void PG_SelectedGridItemChanged(object sender, SelectedGridItemChangedEventArgs e) { if (resetbtn == null) return; - if (propertyGrid != null) Console.WriteLine(LabelPath(propertyGrid.SelectedGridItem)); // PG.SelectedGridItem.Label + " : " + PG.SelectedGridItem.Value; + if (propertyGrid != null) Console.WriteLine(LabelPath(propertyGrid.SelectedGridItem)); // see if data has changed, and if so, enable the Reset button. bool enabled = false; resetbtn.Text = "Reset"; @@ -124,7 +105,7 @@ namespace Volian.Base.Library string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Value, "WindowsFont"); if (origForButton != null) { - resetbtn.Text = "Reset to " + origForButton; + resetbtn.Text = $"Reset to {origForButton}"; enabled = true; } } @@ -133,7 +114,7 @@ namespace Volian.Base.Library string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Value, "LeftMargin"); if (origForButton != null) { - resetbtn.Text = "Reset to " + origForButton; + resetbtn.Text = $"Reset to {origForButton}"; enabled = true; } } @@ -142,7 +123,7 @@ namespace Volian.Base.Library string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Value, "PageLength"); if (origForButton != null) { - resetbtn.Text = "Reset to " + origForButton; + resetbtn.Text = $"Reset to {origForButton}"; enabled = true; } } @@ -151,7 +132,7 @@ namespace Volian.Base.Library string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Parent.Value, "Active"); if (origForButton != null) { - resetbtn.Text = "Reset to " + origForButton; + resetbtn.Text = $"Reset to {origForButton}"; enabled = true; } } @@ -160,7 +141,7 @@ namespace Volian.Base.Library string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Parent.Value, "Active"); if (origForButton != null) { - resetbtn.Text = "Reset to " + origForButton; + resetbtn.Text = $"Reset to {origForButton}"; enabled = true; } } @@ -182,8 +163,8 @@ namespace Volian.Base.Library // field to compare the 2 to see if a change was made, i.e. UCF data exists. foreach (FieldInfo f in fields) { - if (f.Name == "_" + fieldName) fldVal = f; - if (f.Name == "_Orig" + fieldName) fldOrig = f; + if (f.Name == $"_{fieldName}") fldVal = f; + if (f.Name == $"_Orig{fieldName}") fldOrig = f; } if (fldVal != null && fldOrig != null) { @@ -200,8 +181,8 @@ namespace Volian.Base.Library if (orig != newv) return retval; else return null; } - catch (Exception ex) - { + catch (Exception) + { return null; } } @@ -218,8 +199,8 @@ namespace Volian.Base.Library BindingFlags.Instance); foreach (FieldInfo f in fields) { - if (f.Name == "_" + fieldName) fldVal = f; - if (f.Name == "_Orig" + fieldName) fldOrig = f; + if (f.Name == $"_{fieldName}") fldVal = f; + if (f.Name == $"_Orig{fieldName}") fldOrig = f; } if (fldVal != null && fldOrig != null) { @@ -227,14 +208,11 @@ namespace Volian.Base.Library propertyGrid.Refresh(); } } - // Remove this on release, and any uses of it. - private string LabelPath(GridItem gi) - { - return (gi.Parent == null ? "" : LabelPath(gi.Parent) + ":" + gi.Label); - } + // Remove this on release, and any uses of it. + private string LabelPath(GridItem gi) => gi.Parent == null ? "" : $"{LabelPath(gi.Parent)}:{gi.Label}"; - // set the 'members' label to better reflect what is displayed: - private bool SetMembersLabel(Control myControl) + // set the 'members' label to better reflect what is displayed: + private bool SetMembersLabel(Control myControl) { if (myControl is Label && myControl.Text.ToUpper().Contains("MEMBER")) { @@ -291,11 +269,8 @@ namespace Volian.Base.Library void propertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e) { - // Fire our customized collection event... - if (PropGridCollEditor.MyPropertyValueChanged != null) - { - PropGridCollEditor.MyPropertyValueChanged(this, e); - } - } + // Fire our customized collection event... + PropGridCollEditor.MyPropertyValueChanged?.Invoke(this, e); + } } } diff --git a/PROMS/Volian.Base.Library/RTBAPI.cs b/PROMS/Volian.Base.Library/RTBAPI.cs index c88aecf9..3efccb5e 100644 --- a/PROMS/Volian.Base.Library/RTBAPI.cs +++ b/PROMS/Volian.Base.Library/RTBAPI.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; using System.ComponentModel; -using Volian.Base.Library; namespace Volian.Base.Library { @@ -451,11 +448,6 @@ namespace Volian.Base.Library } #endregion #region Structures - //struct CharRange - //{ - // public int cpMin; - // public int cpMax; - //} [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)] public struct CharFormat2 { @@ -483,17 +475,11 @@ namespace Volian.Base.Library } public class CharFormatTwo { - public CharFormatTwo(CharFormat2 cf) - { - _CharFormat2 = cf; - } - private CharFormat2 _CharFormat2; - [Browsable(false)] - public CharFormat2 CharFormat2 - { - get { return _CharFormat2; } - } - [Browsable(false)] + public CharFormatTwo(CharFormat2 cf) => _CharFormat2 = cf; + private CharFormat2 _CharFormat2; + [Browsable(false)] + public CharFormat2 CharFormat2 => _CharFormat2; + [Browsable(false)] public int cbSize { get { return _CharFormat2.cbSize; } @@ -521,15 +507,9 @@ namespace Volian.Base.Library get { return _CharFormat2.yOffset; } set { _CharFormat2.yOffset = value; } } - private Color Int2Color(int color) - { - return Color.FromArgb(color % 256, (color / 256) % 256, color / (256 * 256)); - } - private int Color2Int(Color color) - { - return color.R + (color.G * 256) + (color.B * 256 * 256); - } - public Color crTextColor + private Color Int2Color(int color) => Color.FromArgb(color % 256, (color / 256) % 256, color / (256 * 256)); + private int Color2Int(Color color) => color.R + (color.G * 256) + (color.B * 256 * 256); + public Color crTextColor { get { return Int2Color(_CharFormat2.crTextColor); } set { _CharFormat2.crTextColor = Color2Int(value); } @@ -637,15 +617,9 @@ namespace Volian.Base.Library public class ParaFormatTwo { private ParaFormat2 _ParaFormat2; - public ParaFormatTwo(ParaFormat2 pf) - { - _ParaFormat2 = pf; - } - public ParaFormat2 ParaFormat2 - { - get { return _ParaFormat2; } - } - public int cbSize + public ParaFormatTwo(ParaFormat2 pf) => _ParaFormat2 = pf; + public ParaFormat2 ParaFormat2 => _ParaFormat2; + public int cbSize { get { return _ParaFormat2.cbSize; } set { _ParaFormat2.cbSize = value; } @@ -767,19 +741,11 @@ namespace Volian.Base.Library set { _ParaFormat2.wBorders = value; } } } - #endregion - #region Static Methods - public static bool HasVertScroll(Control ctl) - { - int dwstyle = GetWindowLong(ctl.Handle, GWL_STYLE); - return (dwstyle & WS_VSCROLL) != 0; - } - public static bool HasHorzScroll(Control ctl) - { - int dwstyle = GetWindowLong(ctl.Handle, GWL_STYLE); - return (dwstyle & WS_HSCROLL) != 0; - } - public static void SetScrollLocation(RichTextBox richTextBox, Point point) + #endregion + #region Static Methods + public static bool HasVertScroll(Control ctl) => (GetWindowLong(ctl.Handle, GWL_STYLE) & WS_VSCROLL) != 0; + public static bool HasHorzScroll(Control ctl) => (GetWindowLong(ctl.Handle, GWL_STYLE) & WS_HSCROLL) != 0; + public static void SetScrollLocation(RichTextBox richTextBox, Point point) { if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_SETSCROLLPOS, 0, ref point) == 0) throw new Win32Exception(); @@ -815,7 +781,6 @@ namespace Volian.Base.Library ParaFormat2 pf2 = pft.ParaFormat2; if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_SETPARAFORMAT, 0, ref pf2) == 0) { - //if(Marshal.GetLastWin32Error()!=0) throw new Win32Exception(); } } @@ -849,15 +814,6 @@ namespace Volian.Base.Library } } - public static void SetHighlightColor(RichTextBox richTextBox, RTBSelection selection, Color color) - { - CharFormatTwo cft = GetCharFormat(richTextBox, selection); - cft.crBackColor = color; - cft.dwEffects = 0; - cft.dwMask = 0; - cft.dwMask |= CharFormatMasks.CFM_BACKCOLOR; - SetCharFormat(richTextBox, selection, cft); - } public static void SetSpaceBefore(RichTextBox richTextBox, int spaceBefore) { ParaFormatTwo pft = GetParaFormat(richTextBox); @@ -875,236 +831,6 @@ namespace Volian.Base.Library pft.dySpaceBefore = spaceBefore * 1440 / dpi; SetParaFormat(richTextBox, pft); } - //developed for equation editor interface work, but ended up not needing it. Kept it in - // case it is needed in the future. - //public static void SetSpaceAfter(RichTextBox richTextBox, int spaceAfter) - //{ - // ParaFormatTwo pft = GetParaFormat(richTextBox); - // pft.dwMask = 0; - // pft.dwMask |= ParaFormatMasks.PFM_SPACEAFTER; - // // get the monitor's resolution in DPI and use it to set the linespacing value for - // // the richtextbox. Note that without this, the Arial Unicode font made the appearance of - // // almost double linespacing. Using PFS_Exact makes it appear as regular single spacing. - // Graphics g = richTextBox.CreateGraphics(); - // int dpi = Convert.ToInt32((g.DpiX + g.DpiY) / 2); - // g.Dispose(); - // // dyLineSpacing is Spacing between lines. the PFS_EXACT sets line spacing as the spacing from one - // //line to the next, in twips - thus the 1440. - - // pft.dySpaceAfter = spaceAfter * 1440 / dpi; - // SetParaFormat(richTextBox, pft); - //} - public static void SetLineSpacing(RichTextBox richTextBox, ParaSpacing type) - { - ParaFormatTwo pft = GetParaFormat(richTextBox); - pft.bLineSpacingRule = type; - pft.dwMask = 0; - pft.dwMask |= ParaFormatMasks.PFM_LINESPACING; - pft.dwMask |= ParaFormatMasks.PFM_SPACEAFTER; - - // get the monitor's resolution in DPI and use it to set the linespacing value for - // the richtextbox. Note that without this, the Arial Unicode font made the appearance of - // almost double linespacing. Using PFS_Exact makes it appear as regular single spacing. - Graphics g = richTextBox.CreateGraphics(); - int dpi = Convert.ToInt32((g.DpiX + g.DpiY) / 2); - g.Dispose(); - // dyLineSpacing is Spacing between lines. the PFS_EXACT sets line spacing as the spacing from one - //line to the next, in twips - thus the 1440. - - pft.dyLineSpacing = Convert.ToInt32(.5 + richTextBox.Font.GetHeight(dpi)) * 1440 / dpi; - SetParaFormat(richTextBox, pft); - } - public static E_FontStyle GetFontStyle(RichTextBox richTextBox) - { - E_FontStyle fs = E_FontStyle.FS_NONE; - CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); - if (((cft.dwMask & CharFormatMasks.CFM_BOLD) == CharFormatMasks.CFM_BOLD) && - ((cft.dwEffects & CharFormatEffects.CFE_BOLD) == CharFormatEffects.CFE_BOLD)) fs |= E_FontStyle.FS_BOLD; - if (((cft.dwMask & CharFormatMasks.CFM_UNDERLINE) == CharFormatMasks.CFM_UNDERLINE) && - ((cft.dwEffects & CharFormatEffects.CFE_UNDERLINE) == CharFormatEffects.CFE_UNDERLINE)) fs |= E_FontStyle.FS_UNDERLINE; - if (((cft.dwMask & CharFormatMasks.CFM_ITALIC) == CharFormatMasks.CFM_ITALIC) && - ((cft.dwEffects & CharFormatEffects.CFE_ITALIC) == CharFormatEffects.CFE_ITALIC)) fs |= E_FontStyle.FS_ITALIC; - if (richTextBox.SelectionCharOffset == -2) fs |= E_FontStyle.FS_SUBSCRIPT; - if (richTextBox.SelectionCharOffset == 2) fs |= E_FontStyle.FS_SUPERSCRIPT; - return fs; - } - public static void SetFontStyle(RichTextBox richTextBox, E_FontStyle fs) - { - CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); - if ((fs & E_FontStyle.FS_BOLD) == E_FontStyle.FS_BOLD) - { - cft.dwEffects |= CharFormatEffects.CFE_BOLD; - cft.dwMask |= CharFormatMasks.CFM_BOLD; - } - if ((fs & E_FontStyle.FS_UNDERLINE) == E_FontStyle.FS_UNDERLINE) - { - cft.dwEffects |= CharFormatEffects.CFE_UNDERLINE; - cft.dwMask |= CharFormatMasks.CFM_UNDERLINE; - } - if ((fs & E_FontStyle.FS_ITALIC) == E_FontStyle.FS_ITALIC) - { - cft.dwEffects |= CharFormatEffects.CFE_ITALIC; - cft.dwMask |= CharFormatMasks.CFM_ITALIC; - } - if ((fs & E_FontStyle.FS_SUBSCRIPT) == E_FontStyle.FS_SUBSCRIPT) - { - richTextBox.SelectionCharOffset = -2; - } - if ((fs & E_FontStyle.FS_SUPERSCRIPT) == E_FontStyle.FS_SUPERSCRIPT) - { - richTextBox.SelectionCharOffset = 2; - } - SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft); - } - public static bool IsSuperScript(RichTextBox richTextBox) - { - return (richTextBox.SelectionCharOffset>0); - } - public static bool IsSubScript(RichTextBox richTextBox) - { - return (richTextBox.SelectionCharOffset < 0); - } - public static void ToggleSubscript(bool bSet, RichTextBox richTextBox, RTBSelection selection) - { - if (bSet) - richTextBox.SelectionCharOffset = -2; - else - richTextBox.SelectionCharOffset = 0; - } - public static void ToggleSuperscript(bool bSet, RichTextBox richTextBox, RTBSelection selection) - { - if (bSet) - richTextBox.SelectionCharOffset = 2; - else - richTextBox.SelectionCharOffset = 0; - } - public static bool IsBold(RichTextBox richTextBox) - { - CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); - return (((cft.dwMask & CharFormatMasks.CFM_BOLD) == CharFormatMasks.CFM_BOLD) && - ((cft.dwEffects & CharFormatEffects.CFE_BOLD) == CharFormatEffects.CFE_BOLD)); - } - public static void ToggleBold(bool bSet, RichTextBox richTextBox, RTBSelection selection) - { - CharFormatTwo cft = GetCharFormat(richTextBox, selection); - if (bSet) - { - cft.dwEffects = CharFormatEffects.CFE_BOLD; - cft.dwMask = CharFormatMasks.CFM_BOLD; - } - else - { - cft.dwEffects = CharFormatEffects.CFE_NONE; - cft.dwMask = CharFormatMasks.CFM_BOLD; - } - SetCharFormat(richTextBox, selection, cft); - } - public static bool IsUnderline(RichTextBox richTextBox) - { - CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); - return (((cft.dwMask & CharFormatMasks.CFM_UNDERLINE) == CharFormatMasks.CFM_UNDERLINE) && - ((cft.dwEffects & CharFormatEffects.CFE_UNDERLINE) == CharFormatEffects.CFE_UNDERLINE)); - } - public static void ToggleUnderline(bool bSet, RichTextBox richTextBox, RTBSelection selection) - { - CharFormatTwo cft = GetCharFormat(richTextBox, selection); - if (bSet) - { - cft.dwEffects = CharFormatEffects.CFE_UNDERLINE; - cft.dwMask = CharFormatMasks.CFM_UNDERLINE; - } - else - { - cft.dwEffects = CharFormatEffects.CFE_NONE; - cft.dwMask = CharFormatMasks.CFM_UNDERLINE; - } - SetCharFormat(richTextBox, selection, cft); - } - public static bool IsItalic(RichTextBox richTextBox) - { - CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); - return (((cft.dwMask & CharFormatMasks.CFM_ITALIC) == CharFormatMasks.CFM_ITALIC) && - ((cft.dwEffects & CharFormatEffects.CFE_ITALIC) == CharFormatEffects.CFE_ITALIC)); - } - public static void ToggleItalic(bool bSet, RichTextBox richTextBox, RTBSelection selection) - { - CharFormatTwo cft = GetCharFormat(richTextBox, selection); - if (bSet) - { - cft.dwEffects = CharFormatEffects.CFE_ITALIC; - cft.dwMask = CharFormatMasks.CFM_ITALIC; - } - else - { - cft.dwEffects = CharFormatEffects.CFE_NONE; - cft.dwMask = CharFormatMasks.CFM_ITALIC; - } - SetCharFormat(richTextBox, selection, cft); - } - //public static bool IsLink(RichTextBox richTextBox) - //{ - // CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); - // return ((cft.dwEffects & CharFormatEffects.CFE_PROTECTED) == CharFormatEffects.CFE_PROTECTED); - //} - //public static void ToggleLink(bool bSet, RichTextBox richTextBox, RTBSelection selection) - //{ - // CharFormatTwo cft = GetCharFormat(richTextBox, selection); - // if (bSet) - // { - // cft.dwEffects |= CharFormatEffects.CFE_LINK; - // cft.dwMask |= CharFormatMasks.CFM_LINK; - // } - // else - // { - // cft.dwEffects &= ~RTBAPI.CharFormatEffects.CFE_LINK; - // } - // SetCharFormat(richTextBox, selection, cft); - //} - //public static void UnProtect(RichTextBox richTextBox) //, string type, string text, string link) - //{ - // //richTextBox.DetectUrls = false; - // CharFormatTwo cft = GetCharFormat(richTextBox, RTBAPI.RTBSelection.SCF_SELECTION); ; - // //int position = richTextBox.SelectionStart = richTextBox.TextLength; - // //richTextBox.SelectionLength = 0; - // //richTextBox.SelectedRtf = @"{\rtf1\ansi " + text + @"\v #" + link + @"\v0}"; - // //richTextBox.SelectedRtf = "{" + string.Format(@"\rtf1\ansi\protect\v {0}\v0 {1}\v #{2}", type, text, link) + "}"; - // //richTextBox.Select(position, type.Length + text.Length + link.Length + 1); - // cft.dwMask = RTBAPI.CharFormatMasks.CFM_PROTECTED; - // cft.dwEffects = 0; - // // The lines below can be used to allow link text to be edited - // //charFormat.dwMask = RTBAPI.CharFormatMasks.CFM_LINK; - // //charFormat.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK; - // SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft); - // //rtbRTF.SetSelectionLink(true); - // //richTextBox.SelectionStart = richTextBox.TextLength; - // //richTextBox.SelectionLength = 0; - //} - //public static void Protect(RichTextBox richTextBox) //, string type, string text, string link) - //{ - // CharFormatTwo cft = GetCharFormat(richTextBox, RTBAPI.RTBSelection.SCF_SELECTION); ; - // cft.dwMask = CharFormatMasks.CFM_PROTECTED; - // cft.dwEffects = CharFormatEffects.CFE_PROTECTED; - // SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft); - //} - //public static void SetLink(RichTextBox richTextBox, string type, string text, string link) - //{ - // richTextBox.DetectUrls = false; - // CharFormatTwo cft = GetCharFormat(richTextBox, RTBAPI.RTBSelection.SCF_SELECTION); ; - // int position = richTextBox.SelectionStart = richTextBox.TextLength; - // richTextBox.SelectionLength = 0; - // //richTextBox.SelectedRtf = @"{\rtf1\ansi " + text + @"\v #" + link + @"\v0}"; - // richTextBox.SelectedRtf = "{" + string.Format(@"\rtf1\ansi\protect\v {0}\v0 {1}\v #{2}", type, text, link) + "}"; - // richTextBox.Select(position, type.Length + text.Length + link.Length + 1); - // cft.dwMask = RTBAPI.CharFormatMasks.CFM_LINK | RTBAPI.CharFormatMasks.CFM_PROTECTED; - // cft.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK | RTBAPI.CharFormatEffects.CFE_PROTECTED; - // // The lines below can be used to allow link text to be edited - // //charFormat.dwMask = RTBAPI.CharFormatMasks.CFM_LINK; - // //charFormat.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK; - // SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft); - // //rtbRTF.SetSelectionLink(true); - // richTextBox.SelectionStart = richTextBox.TextLength; - // richTextBox.SelectionLength = 0; - //} #endregion } } diff --git a/PROMS/Volian.Base.Library/RtfTools.cs b/PROMS/Volian.Base.Library/RtfTools.cs index 5a2feeb9..9c2fe30f 100644 --- a/PROMS/Volian.Base.Library/RtfTools.cs +++ b/PROMS/Volian.Base.Library/RtfTools.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; using System.Text.RegularExpressions; namespace Volian.Base.Library diff --git a/PROMS/Volian.Base.Library/TmpFile.cs b/PROMS/Volian.Base.Library/TmpFile.cs index 821d75ce..a6e1b997 100644 --- a/PROMS/Volian.Base.Library/TmpFile.cs +++ b/PROMS/Volian.Base.Library/TmpFile.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.IO; using System.Text.RegularExpressions; @@ -8,19 +6,9 @@ namespace Volian.Base.Library { public static class TmpFile { - public static string CreateFileName(string procNumber, string sectNumber, string sectTitle) - { - return FixFileName(procNumber + "_" + ((sectNumber ?? "") != "" ? sectNumber : sectTitle)); - } - public static string CreateFileName(string procNumber) - { - return FixFileName(procNumber); - } - public static string FixFileName(string name) - { - return Regex.Replace(name, "[ .,/]", "_") + ".pdf"; - } - public static void RemoveAllTmps() + public static string CreateFileName(string procNumber) => FixFileName(procNumber); + public static string FixFileName(string name) => $"{Regex.Replace(name, "[ .,/]", "_")}.pdf"; + public static void RemoveAllTmps() { RemoveTmpPDFs(); RemoveTmpDocs(); @@ -41,7 +29,7 @@ namespace Volian.Base.Library if (fi.LastAccessTime.Ticks < (DateTime.Now.Ticks - TimeSpan.TicksPerHour)) fi.Delete(); } - catch (Exception ex) + catch (Exception) { continue; // if an error, go onto next file. } @@ -70,7 +58,7 @@ namespace Volian.Base.Library if(fi.LastWriteTimeUtc < DateTime.Now.AddDays(-2.0)) fi.Delete(); } - catch (Exception ex) + catch (Exception) { continue; // if an error, go onto next file. } @@ -90,7 +78,7 @@ namespace Volian.Base.Library // it may be open from another process. fi.Delete(); } - catch (Exception ex) + catch (Exception) { continue; // if an error, go onto next file. } diff --git a/PROMS/Volian.Base.Library/ValidFileName.cs b/PROMS/Volian.Base.Library/ValidFileName.cs index 62b25e99..d477d3d1 100644 --- a/PROMS/Volian.Base.Library/ValidFileName.cs +++ b/PROMS/Volian.Base.Library/ValidFileName.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Text; -using System.Threading.Tasks; namespace Volian.Base.Library { diff --git a/PROMS/Volian.Base.Library/VlnItextSharpFont.cs b/PROMS/Volian.Base.Library/VlnItextSharpFont.cs index 9efcb2cb..87cf60c0 100644 --- a/PROMS/Volian.Base.Library/VlnItextSharpFont.cs +++ b/PROMS/Volian.Base.Library/VlnItextSharpFont.cs @@ -1,11 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using iTextSharp.text.factories; using Microsoft.Win32; -using System.Text.RegularExpressions; using System.IO; using iTextSharp.text; @@ -53,7 +47,7 @@ namespace Volian.Base.Library _MyLog.WarnFormat("PROMS Font Folder = {0}", _PromsFontDir); // C2019-028 Add info in the error log } } - int profileDepth1 = ProfileTimer.Push(">>>> RegisterDirectory " + _PromsFontDir); + int profileDepth1 = ProfileTimer.Push($">>>> RegisterDirectory {_PromsFontDir}"); //_MyLog.DebugFormat("Register this Font Folder = {0}", _PromsFontDir); // debug iTextSharp.text.FontFactory.RegisterDirectory(_PromsFontDir); ProfileTimer.Pop(profileDepth1); @@ -70,7 +64,7 @@ namespace Volian.Base.Library _MyLog.WarnFormat("Problem with Font {0} in {1}", fontName, _PromsFontDir); if (_PromsFontDir != FontFind.FontDir) { - int profileDepth2 = ProfileTimer.Push(">>>> RegisterDirectory " + FontFind.FontDir); + int profileDepth2 = ProfileTimer.Push($">>>> RegisterDirectory {FontFind.FontDir}"); //_MyLog.DebugFormat("Register this Font Folder = {0}", FontFind.FontDir); // debug iTextSharp.text.FontFactory.RegisterDirectory(FontFind.FontDir); ProfileTimer.Pop(profileDepth2); @@ -109,14 +103,13 @@ namespace Volian.Base.Library } ProfileTimer.Pop(profileDepth); } - private static RegistryKey _FontKey = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows NT").OpenSubKey("CurrentVersion").OpenSubKey("Fonts"); - public static RegistryKey FontKey - { get { return _FontKey; } } - /// - /// Try to register a particular font, if it fails register the entire font folder - /// - /// FontName - Used to find a font file. - public static void RegisterFont(string fontName) + private static readonly RegistryKey _FontKey = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows NT").OpenSubKey("CurrentVersion").OpenSubKey("Fonts"); + public static RegistryKey FontKey => _FontKey; + /// + /// Try to register a particular font, if it fails register the entire font folder + /// + /// FontName - Used to find a font file. + public static void RegisterFont(string fontName) { if (!FontFactory.IsRegistered(fontName)) { @@ -128,7 +121,7 @@ namespace Volian.Base.Library try // B2019-118 Add error handling for FontFacory.Register (Windows Registry contains a node that // points to a file that no longer exists { - FontFactory.Register(fontFile.Contains("\\") ? fontFile : FontFind.FontDir + "\\" + fontFile); + FontFactory.Register(fontFile.Contains("\\") ? fontFile : $"{FontFind.FontDir}\\{fontFile}"); } catch (Exception ex) // catch any exception and add the error to the error log. { diff --git a/PROMS/Volian.Base.Library/VlnSettings.cs b/PROMS/Volian.Base.Library/VlnSettings.cs index 25d4aeaa..9e7a2352 100644 --- a/PROMS/Volian.Base.Library/VlnSettings.cs +++ b/PROMS/Volian.Base.Library/VlnSettings.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.IO; using System.Configuration; using System.Reflection; @@ -17,25 +15,11 @@ namespace Volian.Base.Library // // For DataLoader, this is set via the Debug checkbox on the form. private static bool WasLoaded = false; - private static bool _DoUpdateRO = true; - public static bool DoUpdateRO - { - get { return VlnSettings._DoUpdateRO; } - set { VlnSettings._DoUpdateRO = value; } - } - private static bool _DebugPagination = false; - public static bool DebugPagination - { - get { return VlnSettings._DebugPagination; } - set { VlnSettings._DebugPagination = value; } - } - private static bool _DebugText = false; - public static bool DebugText - { - get { return VlnSettings._DebugText; } - set { VlnSettings._DebugText = value; } - } - private static bool _DebugMode = false; + + public static bool DoUpdateRO { get; set; } = true; + public static bool DebugPagination { get; set; } = false; + public static bool DebugText { get; set; } = false; + private static bool _DebugMode = false; public static bool DebugMode { get @@ -135,8 +119,7 @@ namespace Volian.Base.Library { if (parameter.ToUpper().StartsWith("/" + commandName.ToUpper() + "=")) { - float result = def; - if (float.TryParse(parameter.Substring(commandName.Length + 2), out result)) + if (float.TryParse(parameter.Substring(commandName.Length + 2), out float result)) return result; else return def; @@ -182,7 +165,7 @@ namespace Volian.Base.Library // This will create a Temp\VE-PROMS folder in the LocalSettings Folder. //XP - C:\Documents and Settings\{user}\Local Settings\Application Data\Temp\VEPROMS //Vista - C:\Users\{user}\AppData\Local\Temp\VEPROMS - _TemporaryFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Temp"; + _TemporaryFolder = $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\Temp"; if (!Directory.Exists(TemporaryFolder)) Directory.CreateDirectory(TemporaryFolder); _TemporaryFolder += @"\VEPROMS"; if (!Directory.Exists(TemporaryFolder)) Directory.CreateDirectory(TemporaryFolder); @@ -190,26 +173,11 @@ namespace Volian.Base.Library return _TemporaryFolder; } } - private static string _UserID=Environment.UserName.ToUpper(); - public static string UserID - { - get { return VlnSettings._UserID; } - set { VlnSettings._UserID = value; } - } - private static bool _StepTypeToolTip = false; - public static bool StepTypeToolTip - { - get { return VlnSettings._StepTypeToolTip; } - set { VlnSettings._StepTypeToolTip = value; } - } - // C2029-025 Show or hide replace words. Can highlight replace words in editor. - private static bool _cbShwRplWrdsColor = false; - public static bool cbShwRplWrdsColor - { - get { return VlnSettings._cbShwRplWrdsColor; } - set { VlnSettings._cbShwRplWrdsColor = value; } - } - private static string _ReleaseMode = null; + + public static string UserID { get; set; } = Environment.UserName.ToUpper(); + public static bool StepTypeToolTip { get; set; } = false; + public static bool cbShwRplWrdsColor { get; set; } = false; + private static string _ReleaseMode = null; public static string ReleaseMode { get diff --git a/PROMS/Volian.Base.Library/VlnTimer.cs b/PROMS/Volian.Base.Library/VlnTimer.cs index bfdd5e19..5b840098 100644 --- a/PROMS/Volian.Base.Library/VlnTimer.cs +++ b/PROMS/Volian.Base.Library/VlnTimer.cs @@ -1,26 +1,15 @@ using System; using System.Collections.Generic; -using System.Text; namespace Volian.Base.Library { public class VlnTimer { - private DateTime _LastTime = DateTime.Now; - public DateTime LastTime + public DateTime LastTime { get; set; } = DateTime.Now; + public string LastProcess { get; set; } = "Initialize"; + public string ActiveProcess { - get { return _LastTime; } - set { _LastTime = value; } - } - private string _LastProcess = "Initialize"; - public string LastProcess - { - get { return _LastProcess; } - set { _LastProcess = value; } - } - public string ActiveProcess - { - get { return _LastProcess; } + get { return LastProcess; } set { DateTime tNow = DateTime.Now; @@ -33,13 +22,9 @@ namespace Volian.Base.Library LastProcess = value; } } - Dictionary _ElapsedTimes = new Dictionary(); - public Dictionary ElapsedTimes - { - get { return _ElapsedTimes; } - set { _ElapsedTimes = value; } - } - public void ShowElapsedTimes() + + public Dictionary ElapsedTimes { get; set; } = new Dictionary(); + public void ShowElapsedTimes() { ActiveProcess = "fini"; Console.WriteLine("'Process'\t'Elapsed'"); @@ -54,27 +39,16 @@ namespace Volian.Base.Library } public static class ProfileTimer { - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private static Stack _MyStack = new Stack(); +#pragma warning disable S6669 + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); +#pragma warning restore S6669 - public static Stack MyStack - { - get { return _MyStack; } - set { _MyStack = value; } - } - private static DateTime _StartTime = DateTime.Now; - public static DateTime StartTime - { - get { return _StartTime; } - set { _StartTime = value; } - } - delegate int DoPushTrack(string start); + public static Stack MyStack { get; set; } = new Stack(); + public static DateTime StartTime { get; set; } = DateTime.Now; + delegate int DoPushTrack(string start); private static DoPushTrack myDoPush = new DoPushTrack(IgnorePush); - public static int Push(string start) - { - return DoPush(start); - } - private static int DoPush(string start) + public static int Push(string start) => DoPush(start); + private static int DoPush(string start) { MyStack.Push(Start); Start = start; @@ -87,39 +61,23 @@ namespace Volian.Base.Library } delegate int DoPopTrack(int depth); private static DoPopTrack myDoPop = new DoPopTrack(IgnorePop); - public static int Pop(int depth) - { - return DoPop(depth); - } - private static int DoPop(int depth) + public static int Pop(int depth) => DoPop(depth); + private static int DoPop(int depth) { if (MyStack.Count != depth) _MyLog.WarnFormat("Profile Stack Issues\r\n {0}, Depth is {1}, Depth should be {2}", Start,MyStack.Count,depth); Start = MyStack.Pop(); return MyStack.Count; } - private static int IgnorePop(int depth) - { - return 0; - } - public static int Depth - { - get - { - return MyStack.Count; - } - } - private static Dictionary _TimerTable = new Dictionary(); - public static Dictionary TimerTable - { - get { return ProfileTimer._TimerTable; } - set { ProfileTimer._TimerTable = value; } - } - delegate void DoTrack(string module); + private static int IgnorePop(int depth) => 0; + public static int Depth => MyStack.Count; + + public static Dictionary TimerTable { get; set; } = new Dictionary(); + delegate void DoTrack(string module); private static DoTrack myDoTrack = new DoTrack(IgnoreModule); public static void TurnOnTracking(string filename) { - DebugProfile.Open(VlnSettings.TemporaryFolder + "\\" + filename); + DebugProfile.Open($"{VlnSettings.TemporaryFolder}\\{filename}"); myDoTrack = new DoTrack(TrackModule); myDoPush = new DoPushTrack(DoPush); myDoPop = new DoPopTrack(DoPop); @@ -145,13 +103,10 @@ namespace Volian.Base.Library //Console.WriteLine("{0},'{1}'", TimeSpan.FromTicks(dtNext.Ticks - LastTime.Ticks).TotalSeconds, Description); AddTimerInfo(_Start, dtNext.Ticks - LastTime.Ticks); _Start = module; - _LastTime = dtNext; + LastTime = dtNext; } - private static void IgnoreModule(string module) - { - _Start = module; - } - private static void AddTimerInfo(string description, long ticks) + private static void IgnoreModule(string module) => _Start = module; + private static void AddTimerInfo(string description, long ticks) { if (TimerTable.ContainsKey(description)) TimerTable[description] += ticks; @@ -205,16 +160,12 @@ namespace Volian.Base.Library } public static void Reset() { - _TimerTable = new Dictionary(); + TimerTable = new Dictionary(); _Start = "Start"; - _LastTime = DateTime.Now; - _MyStack = new Stack(); + LastTime = DateTime.Now; + MyStack = new Stack(); } - private static DateTime _LastTime = DateTime.Now; - public static DateTime LastTime - { - get { return _LastTime; } - set { _LastTime = value; } - } - } + + public static DateTime LastTime { get; set; } = DateTime.Now; + } } diff --git a/PROMS/Volian.Base.Library/Volian.Base.Library.csproj b/PROMS/Volian.Base.Library/Volian.Base.Library.csproj index 525629a6..dc0e17c4 100644 --- a/PROMS/Volian.Base.Library/Volian.Base.Library.csproj +++ b/PROMS/Volian.Base.Library/Volian.Base.Library.csproj @@ -104,6 +104,7 @@ FrmPopupStatusMessage.cs + diff --git a/PROMS/Volian.Base.Library/VolianTimer.cs b/PROMS/Volian.Base.Library/VolianTimer.cs index 636aa63c..da5389af 100644 --- a/PROMS/Volian.Base.Library/VolianTimer.cs +++ b/PROMS/Volian.Base.Library/VolianTimer.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; -using System.Threading.Tasks; namespace Volian.Base.Library { @@ -12,57 +10,40 @@ namespace Volian.Base.Library /// public class VolianTimer { - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - static List _Timers = new List(); - /// - /// User defined name - should be as specific as possible - /// Include Method Name, File Name and Line Number - /// - private string _Name; - public string Name - { - get { return _Name; } - set { _Name = value; } - } - /// - /// Set on open - /// - private DateTime _Start; - public DateTime Start - { - get { return _Start; } - set { _Start = value; } - } - /// - /// Calculate on Close - /// - private long _Ticks; - public long Ticks - { - get { return _Ticks; } - set { _Ticks = value; } - } - /// - /// Number of times open/close has been run - /// - private int _Count; - public int Count - { - get { return _Count; } - set { _Count = value; } - } - /// - /// Constructor - /// - public VolianTimer() +#pragma warning disable S6669 + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); +#pragma warning restore S6669 + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] + static List _Timers = new List(); + + public string Name { get; set; } + public DateTime Start { get; set; } + public long Ticks { get; set; } + public int Count { get; set; } + /// + /// Constructor + /// + public VolianTimer() { Count = 0; Ticks = 0; } - /// - /// Command Line Parameter /Timing turns timing on - /// - private static bool? _TimingsOn = null; + /// + /// Constructor with Module and line number + /// + /// Method Name, File Name + /// Code Line Number + public VolianTimer(string module, int line) + { + Count = 0; + Ticks = 0; + Name = string.Format("{0}:{1}", module, line); + if (TimingsOn) _Timers.Add(this); + } + /// + /// Command Line Parameter /Timing turns timing on + /// + private static bool? _TimingsOn = null; public static bool TimingsOn { get @@ -73,18 +54,6 @@ namespace Volian.Base.Library } } /// - /// Constructor with Module and line number - /// - /// Method Name, File Name - /// Code Line Number - public VolianTimer(string module, int line) - { - Count = 0; - Ticks = 0; - Name = string.Format("{0}:{1}", module, line); - if(TimingsOn) _Timers.Add(this); - } - /// /// Start Timer /// public void Open() diff --git a/PROMS/Volian.Base.Library/vlnFont.cs b/PROMS/Volian.Base.Library/vlnFont.cs index 4c97b6c6..8677ddb6 100644 --- a/PROMS/Volian.Base.Library/vlnFont.cs +++ b/PROMS/Volian.Base.Library/vlnFont.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Drawing; +using System.Drawing; using System.Drawing.Text; using System.Windows.Forms; @@ -11,7 +7,7 @@ namespace Volian.Base.Library public static class vlnFont { private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private static InstalledFontCollection _MyFontCollection = new InstalledFontCollection(); + private static readonly InstalledFontCollection _MyFontCollection = new InstalledFontCollection(); private static string _ProportionalSymbolFont = null; // C2017-036 Look for suitable proportional font that will support the symbol characters used in PROMS // Microsoft removed Arial Unicode MS starting with Word16 (office 365 containing that version of Word) diff --git a/PROMS/Volian.Base.Library/vlnStackTrace.cs b/PROMS/Volian.Base.Library/vlnStackTrace.cs index 84ce7a99..bf951d67 100644 --- a/PROMS/Volian.Base.Library/vlnStackTrace.cs +++ b/PROMS/Volian.Base.Library/vlnStackTrace.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Runtime.InteropServices; @@ -9,31 +8,9 @@ namespace Volian.Base.Library // This provides a more robust stack trace than what visual studio offers public static class vlnStackTrace { - public static string GetStack(string str, params object[] objects) - { - return string.Format(str, objects) + StackToString(); - } - public static void ShowStack(string str, params object[] objects) - { - Console.WriteLine(string.Format(str, objects) + StackToString()); - } - public static string GetStack() - { - return StackToString(); - } - public static string GetStack(bool showSame) - { - return StackToString(showSame); - } - public static void ShowStack() - { - Console.WriteLine(StackToString()); - } - public static string StackToString() - { - return StackToString(true); - } - private static string StackToString(bool showSame) + public static string GetStack(bool showSame) => StackToString(showSame); + public static string StackToString() => StackToString(true); + private static string StackToString(bool showSame) { StringBuilder sb = new StringBuilder(); StackTrace st = new StackTrace(true); @@ -71,22 +48,6 @@ namespace Volian.Base.Library } return sb.ToString(); } - public static void ShowStackLocal(string str, params object[] objects) - { - Console.WriteLine(string.Format(str, objects) + StackToStringLocal(2,10)); - } - public static void ShowStackFirstLocal(string str) - { - Console.WriteLine(str + "\r\n" + StackToStringLocal(3, 0)); - } - public static void ShowStackLocal(string str,int start) - { - Console.WriteLine(str + "\r\n" + StackToStringLocal(start,1)); - } - public static void ShowStackLocal(int start, int limit, string str, params object[] objects) - { - Console.WriteLine(string.Format(str, objects) + StackToStringLocal(start, limit)); - } public static string StackToStringLocal(int start, int limit) { StringBuilder sb = new StringBuilder(); @@ -118,36 +79,12 @@ namespace Volian.Base.Library return sb.ToString(); return "No Local Method"; } - public static string CalledFrom - { - get - { - StackTrace st = new StackTrace(true); - StackFrame[] sfs = st.GetFrames(); - int count = 0; - foreach (StackFrame sf in sfs) - { - if (sf.GetFileLineNumber() != 0) // Only look at Local Methods - { - count++; - if (count > 4) // The fourth entry should be the Calling Method - { - string sType = sf.GetMethod().ReflectedType.Name; - string sMethod = sf.GetMethod().Name; - return string.Format("{0}.{1}[{2}]", sType, sMethod, sf.GetFileLineNumber()); - } - } - } - return "No Local Method"; - } - } public static string CalledFromCSLA { get { StackTrace st = new StackTrace(true); StackFrame[] sfs = st.GetFrames(); - int count = 0; string lastWasCSLA = null; foreach (StackFrame sf in sfs) { @@ -187,71 +124,5 @@ namespace Volian.Base.Library if (stackFrame1.GetILOffset() != stackFrame2.GetILOffset()) return false; return true; } - public static bool ScrollInStack() - { - StackTrace st = new StackTrace(true); - StackFrame[] sfs = st.GetFrames(); - bool retval = false; - foreach (StackFrame sf in sfs) - { - string sMethod = sf.GetMethod().Name; - string sNamespace = sf.GetMethod().ReflectedType.Namespace; - string sType = sf.GetMethod().ReflectedType.Name; - if (sMethod.ToUpper().Contains("SCROLL") || sType.ToUpper().Contains("SCROLL")) - { - retval = true; - Console.WriteLine("{0}.{1}.{2}", sNamespace, sType, sMethod); - } - } - return retval; - } - /// - /// This will clear the Output window when run in the Development Environment - /// Add EnvDTE and EnvDTE80 to references from .NET - /// - public static void ClearOutputWindow() - { -#if (DEBUG) - try - { - EnvDTE80.DTE2 dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.8.0"); - dte2.ToolWindows.OutputWindow.ActivePane.Clear(); - } - catch (Exception ex) - { - Console.WriteLine("ClearOutputWindow {0} - {1}\r\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace); - } -#endif - } } - public static class HWndCounter - { - [DllImport("kernel32.dll")] - private static extern IntPtr GetCurrentProcess(); - - [DllImport("user32.dll")] - private static extern uint GetGuiResources(IntPtr hProcess, uint uiFlags); - - private enum ResourceType - { - Gdi = 0, - User = 1 - } - public static void GetWindowHandlesForCurrentProcess(IntPtr hWnd) - { - GetWindowHandlesForCurrentProcess(hWnd, ""); - } - private static uint lastUserObject = 0; - public static void GetWindowHandlesForCurrentProcess(IntPtr hWnd, string str, params object[] objects) - { - IntPtr processHandle = GetCurrentProcess(); - uint gdiObjects = GetGuiResources(processHandle, (uint)ResourceType.Gdi); - uint userObjects = GetGuiResources(processHandle, (uint)ResourceType.User); - if (lastUserObject != userObjects) - Console.WriteLine("winhandle count = {0} GDIObjs {1} UserObjs {2} dif {3} {4}", gdiObjects + userObjects, gdiObjects, userObjects,(int)userObjects - (int)lastUserObject, string.Format(str, objects)); - lastUserObject = userObjects; - //return Convert.ToInt32(gdiObjects + userObjects); - } - } - } diff --git a/PROMS/Volian.Controls.Library/DSOTabPanel.cs b/PROMS/Volian.Controls.Library/DSOTabPanel.cs index cd8f412a..c558e671 100644 --- a/PROMS/Volian.Controls.Library/DSOTabPanel.cs +++ b/PROMS/Volian.Controls.Library/DSOTabPanel.cs @@ -205,7 +205,7 @@ namespace Volian.Controls.Library System.IO.FileStream fs = MyDSOFile.MyFile.Create(); fs.Write(myDoc.DocContent, 0, myDoc.DocContent.Length); fs.Close(); - MyDSOFile.SaveFile(0, "", _ItemInfo, false, StatusChanged); // B2017-219 save the restored document to database + MyDSOFile.SaveFile("", _ItemInfo, false, StatusChanged); // B2017-219 save the restored document to database this._MyEdWord = null; // B2017-219 Set MyEdWord to null - we will check for this in the calling functions return; } @@ -216,7 +216,7 @@ namespace Volian.Controls.Library { System.IO.FileStream fs = MyDSOFile.MyFile.Create(); fs.Close(); - MyDSOFile.SaveFile(0, "", _ItemInfo, false, StatusChanged); // B2017-219 save the blank document to database + MyDSOFile.SaveFile("", _ItemInfo, false, StatusChanged); // B2017-219 save the blank document to database MessageBox.Show("Reverting to Blank Document", "Error in MS Word section", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this._MyEdWord = null; // B2017-219 Set MyEdWord to null - we will check for this in the calling functions @@ -357,7 +357,7 @@ namespace Volian.Controls.Library if (ans == DialogResult.No) cvtLibDoc = true; } } - MyDSOFile.SaveFile(doc.Length, doc.Ascii, MyDisplayTabItem.MyItemInfo, cvtLibDoc, StatusChanged); + MyDSOFile.SaveFile(doc.Ascii, MyDisplayTabItem.MyItemInfo, cvtLibDoc, StatusChanged); if (cvtLibDoc) { MyDisplayTabItem.Text = MyDisplayTabItem.MyItemInfo.TabTitle;