Skip to content

Commit

Permalink
IDE code cleanup run
Browse files Browse the repository at this point in the history
  • Loading branch information
Nat Van Gulck authored and Nat Van Gulck committed Nov 11, 2023
1 parent 10f5315 commit a78ff86
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 81 deletions.
8 changes: 3 additions & 5 deletions PBIXInspectorCLI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using PBIXInspectorLibrary;
using PBIXInspectorLibrary.Output;
using PBIXInspectorWinLibrary;
using PBIXInspectorWinLibrary.Drawing;
using PBIXInspectorWinLibrary.Utils;

internal partial class Program
{
private static Args _parsedArgs = null;

private static void Main(string[] args)
{
{
#if DEBUG
Console.WriteLine("Attach debugger to process? Press any key to continue.");
Console.ReadLine();
Expand All @@ -20,7 +18,7 @@ private static void Main(string[] args)
_parsedArgs = ArgsUtils.ParseArgs(args);

Welcome();

PBIXInspectorWinLibrary.Main.WinMessageIssued += Main_MessageIssued;
PBIXInspectorWinLibrary.Main.Run(_parsedArgs);

Expand Down Expand Up @@ -76,7 +74,7 @@ private static String FormatConsoleMessage(MessageTypeEnum messageType, string m
string template = _parsedArgs.ADOOutput ? Constants.ADOLogIssueTemplate : "{0}";
string msgType = _parsedArgs.ADOOutput ? messageType.ToString().ToLower() : messageType.ToString();
string msgSeparator = _parsedArgs.ADOOutput ? "" : ": ";
string messageTypeFormat = string.Format(template,msgType);
string messageTypeFormat = string.Format(template, msgType);

return string.Concat(messageTypeFormat, msgSeparator, message);
}
Expand Down
2 changes: 1 addition & 1 deletion PBIXInspectorLibrary/CustomRules/CountRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CountRule : Json.Logic.Rule

public CountRule(Json.Logic.Rule input)
{
Input = input;
Input = input;
}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions PBIXInspectorLibrary/CustomRules/DrillVariableRule.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Json.Logic;
using Json.Pointer;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Json.Pointer;
using System.Net.Http.Headers;

namespace PBIXInspectorLibrary.CustomRules;

Expand Down Expand Up @@ -67,7 +66,7 @@ internal DrillVariableRule(Json.Logic.Rule path, Json.Logic.Rule defaultValue)
{
//remove single quotes from beginning and end of string if any.
string strVal;
if (val.ToString()!.StartsWith("'") && val.ToString()!.EndsWith("'"))
if (val.ToString()!.StartsWith("'") && val.ToString()!.EndsWith("'"))
{
strVal = val.ToString()!.Substring(1, val.ToString()!.Length - 2);
}
Expand Down
2 changes: 1 addition & 1 deletion PBIXInspectorLibrary/CustomRules/RectangleOverlap.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Json.Logic;
using System.Drawing;
using System.Text.Json.Nodes;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

namespace PBIXInspectorLibrary.CustomRules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PBIXInspectorLibrary.Exceptions
namespace PBIXInspectorLibrary.Exceptions
{
internal class PbiFileEntryNotFoundException : Exception
{
Expand Down
40 changes: 19 additions & 21 deletions PBIXInspectorLibrary/Inspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PBIXInspectorLibrary.Output;
using System.Linq.Expressions;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;

namespace PBIXInspectorLibrary
Expand Down Expand Up @@ -39,7 +37,7 @@ public Inspector(string pbiFilePath, InspectionRules inspectionRules) : base(pbi
this._inspectionRules = inspectionRules;
AddCustomRulesToRegistry();
}

/// <summary>
///
/// </summary>
Expand All @@ -49,7 +47,7 @@ public Inspector(string pbiFilePath, string rulesFilePath) : base(pbiFilePath, r
{
this._pbiFilePath = pbiFilePath;
this._rulesFilePath = rulesFilePath;

try
{
var inspectionRules = this.DeserialiseRules<InspectionRules>(rulesFilePath);
Expand Down Expand Up @@ -83,19 +81,19 @@ private PbiFile InitPbiFile(string pbiFilePath)
//}
//else
//{
switch (PbiFile.PBIFileType(pbiFilePath))
{
case PbiFile.PBIFileTypeEnum.PBIX:
return new PbixFile(pbiFilePath);
break;
case PbiFile.PBIFileTypeEnum.PBIP:
return new PbipFile(pbiFilePath);
break;
case PbiFile.PBIFileTypeEnum.PBIPReport:
return new PbipReportFile(pbiFilePath);
default:
throw new PBIXInspectorException(string.Format("Could not determine the extension of PBI file with path \"{0}\".", pbiFilePath));
}
switch (PbiFile.PBIFileType(pbiFilePath))
{
case PbiFile.PBIFileTypeEnum.PBIX:
return new PbixFile(pbiFilePath);
break;
case PbiFile.PBIFileTypeEnum.PBIP:
return new PbipFile(pbiFilePath);
break;
case PbiFile.PBIFileTypeEnum.PBIPReport:
return new PbipReportFile(pbiFilePath);
default:
throw new PBIXInspectorException(string.Format("Could not determine the extension of PBI file with path \"{0}\".", pbiFilePath));
}
//}
}

Expand Down Expand Up @@ -135,7 +133,7 @@ public IEnumerable<TestResult> Inspect()
{
string pbiEntryPath;

switch (pbiFile.FileType)
switch (pbiFile.FileType)
{
case PbiFile.PBIFileTypeEnum.PBIX:
pbiEntryPath = entry.PbixEntryPath;
Expand Down Expand Up @@ -211,7 +209,7 @@ public IEnumerable<TestResult> Inspect()

var forEachDisplayName = !string.IsNullOrEmpty(rule.ForEachPathDisplayName) ? ExecuteTokensPath((JObject?)forEachToken, rule.Name, rule.ForEachPathDisplayName, rule.PathErrorWhenNoMatch) : null;
var strForEachDisplayName = forEachDisplayName != null ? forEachDisplayName[0].ToString() : string.Empty;

try
{
var tokens = ExecuteTokensPath(forEachToken, rule.Name, rule.Path, rule.PathErrorWhenNoMatch);
Expand Down Expand Up @@ -289,7 +287,7 @@ public IEnumerable<TestResult> Inspect()
}
}

return testResults;
return testResults;
}

private MessageTypeEnum ConvertRuleLogType(string ruleLogType)
Expand Down Expand Up @@ -516,7 +514,7 @@ private JsonArray ConvertToJsonArray(List<JToken>? tokens)
{
if (item.Value is JsonValue)
{

var value = item.Value.AsValue().Stringify();
//TODO: enable navigation to parent path
//while (value.StartsWith("."))
Expand Down
2 changes: 1 addition & 1 deletion PBIXInspectorLibrary/MessageIssuedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public MessageIssuedEventArgs(string message, MessageTypeEnum messageType)

public string Message { get; private set; }
public MessageTypeEnum MessageType { get; private set; }
public bool DialogOKResponse { get; set;}
public bool DialogOKResponse { get; set; }
}

public enum MessageTypeEnum
Expand Down
9 changes: 1 addition & 8 deletions PBIXInspectorLibrary/PbiFile.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PBIXInspectorLibrary
namespace PBIXInspectorLibrary
{
internal abstract class PbiFile : IDisposable
{
Expand Down
9 changes: 4 additions & 5 deletions PBIXInspectorLibrary/PbixFile.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Data;
using System.IO.Compression;
using System.IO.Compression;

namespace PBIXInspectorLibrary
{
internal class PbixFile : PbiFile, IDisposable
{

private ZipArchive _za = null;

Check warning on line 8 in PBIXInspectorLibrary/PbixFile.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.
private bool disposedValue;

Expand Down Expand Up @@ -63,7 +62,7 @@ protected virtual void Dispose(bool disposing)
}
}


// TODO: set large fields to null
disposedValue = true;
}
Expand All @@ -76,6 +75,6 @@ public override void Dispose()
GC.SuppressFinalize(this);
}


}
}
14 changes: 7 additions & 7 deletions PBIXInspectorTests/CLIArgsUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ public void TestCLIArgsUtilsDefaults()

parsedArgs = ArgsUtils.ParseArgs(args);

Assert.IsTrue(parsedArgs.CONSOLEOutput
&& !parsedArgs.Verbose
&& parsedArgs.DeleteOutputDirOnExit
Assert.IsTrue(parsedArgs.CONSOLEOutput
&& !parsedArgs.Verbose
&& parsedArgs.DeleteOutputDirOnExit
&& !string.IsNullOrEmpty(parsedArgs.OutputDirPath)
&& !parsedArgs.HTMLOutput
&& !parsedArgs.JSONOutput
&& !parsedArgs.HTMLOutput
&& !parsedArgs.JSONOutput
&& !parsedArgs.PNGOutput);
}

Expand Down Expand Up @@ -262,8 +262,8 @@ public void TestCLIArgsUtilsSuccess_VerboseOptionFalse2()
Assert.True(parsedArgs.PBIFilePath.Equals("pbipPath", StringComparison.OrdinalIgnoreCase) && parsedArgs.RulesFilePath.Equals("rulesPath", StringComparison.OrdinalIgnoreCase) && !parsedArgs.Verbose);
}


}
}

#pragma warning restore CS8602
#pragma warning restore CS8602
4 changes: 2 additions & 2 deletions PBIXInspectorTests/CustomRulesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json.Nodes;
using PBIXInspectorLibrary.CustomRules;
using PBIXInspectorLibrary.CustomRules;
using System.Text.Json.Nodes;

namespace PBIXInspectorTests
{
Expand Down
3 changes: 1 addition & 2 deletions PBIXInspectorTests/ImageUtilsTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using PBIXInspectorLibrary.Output;
using PBIXInspectorWinLibrary.Drawing;
using PBIXInspectorWinLibrary.Utils;

namespace PBIXInspectorTests
{
Expand All @@ -11,7 +10,7 @@ internal class ImageUtilsTest
public void ConvertBitmapToBase64Test()
{
var bitmapPath = string.Empty;

ArgumentException ex = Assert.Throws<ArgumentException>(
() => ImageUtils.ConvertBitmapToBase64(bitmapPath));
}
Expand Down
2 changes: 1 addition & 1 deletion PBIXInspectorTests/JsonAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.

using System.Text.Json.Nodes;
using Json.More;
using System.Text.Json.Nodes;

namespace PBIXInspectorTests
{
Expand Down
5 changes: 2 additions & 3 deletions PBIXInspectorWinLibrary/Drawing/ImageUtils.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Drawing;
using PBIXInspectorLibrary.Output;
using System.Drawing;
using System.Text.Json.Nodes;
using PBIXInspectorLibrary;
using PBIXInspectorLibrary.Output;

namespace PBIXInspectorWinLibrary.Drawing
{
Expand Down
5 changes: 2 additions & 3 deletions PBIXInspectorWinLibrary/Drawing/ReportPage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Drawing;
using System.Drawing.Imaging;
using static PBIXInspectorWinLibrary.Drawing.ReportPage;

#pragma warning disable CA1416 // Validate platform compatibility
namespace PBIXInspectorWinLibrary.Drawing
Expand Down Expand Up @@ -77,11 +76,11 @@ public void Draw()
}

g.DrawRectangle(pen, rect);

var iconSize = (from s in iconSizes where s <= Math.Max(rect.Width, rect.Height) / 2 orderby s descending select s).FirstOrDefault();
using (Icon ico = new(ICONPATH, iconSize, iconSize))
{
if (!vc.Pass) { g.DrawIcon(ico, rect.X + VISOFFSET + (rect.Width - iconSize) / 2, rect.Y + VISOFFSET +(rect.Height - iconSize) / 2); };
if (!vc.Pass) { g.DrawIcon(ico, rect.X + VISOFFSET + (rect.Width - iconSize) / 2, rect.Y + VISOFFSET + (rect.Height - iconSize) / 2); };

}

Expand Down
8 changes: 4 additions & 4 deletions PBIXInspectorWinLibrary/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using PBIXInspectorLibrary.Output;
using PBIXInspectorLibrary;
using PBIXInspectorLibrary;
using PBIXInspectorLibrary.Output;
using PBIXInspectorWinLibrary.Drawing;
using PBIXInspectorWinLibrary.Utils;
using System.Text.Json;
Expand Down Expand Up @@ -104,8 +104,8 @@ public static void Run(Args args)
if (!_args.ADOOutput && (_args.PNGOutput || _args.HTMLOutput))
{
_fieldMapInsp = new Inspector(_args.PBIFilePath, Constants.ReportPageFieldMapFilePath);
_fieldMapResults = _fieldMapInsp.Inspect();
_fieldMapResults = _fieldMapInsp.Inspect();

var outputPNGDirPath = Path.Combine(_args.OutputDirPath, Constants.PNGOutputDir);

if (Directory.Exists(outputPNGDirPath))
Expand Down
6 changes: 3 additions & 3 deletions PBIXInspectorWinLibrary/Utils/Args.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public string OutputPath
}
else
{
OutputDirPath = Path.Combine(Path.GetTempPath(), String.Concat(Constants.DefaultVisOpsFolder, Guid.NewGuid().ToString())) ;
DeleteOutputDirOnExit = true;
OutputDirPath = Path.Combine(Path.GetTempPath(), String.Concat(Constants.DefaultVisOpsFolder, Guid.NewGuid().ToString()));
DeleteOutputDirOnExit = true;
}
}
}
Expand Down Expand Up @@ -53,7 +53,7 @@ public string FormatsString

public bool PNGOutput { get; private set; }

public bool HTMLOutput { get; private set; }
public bool HTMLOutput { get; private set; }

public bool JSONOutput { get; private set; }

Expand Down
8 changes: 4 additions & 4 deletions PBIXInspectorWinLibrary/Utils/ArgsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static Args ParseArgs(string[] args)
const string TRUE = "true";
const string FALSE = "false";
string[] validOptions = { PBIX, PBIP, PBIPREPORT, RULES, OUTPUT, FORMATS, VERBOSE };

int index = 0;
int maxindex = args.Length - 2;
var dic = new Dictionary<string, string>();
Expand Down Expand Up @@ -41,13 +41,13 @@ public static Args ParseArgs(string[] args)
var verboseString = dic.ContainsKey(VERBOSE) ? dic[VERBOSE] : FALSE;
var formatsString = dic.ContainsKey(FORMATS) ? dic[FORMATS] : string.Empty;

return new Args { PBIFilePath = pbiFilePath, RulesFilePath = rulesPath, OutputPath = outputPath, FormatsString = formatsString, VerboseString = verboseString};
return new Args { PBIFilePath = pbiFilePath, RulesFilePath = rulesPath, OutputPath = outputPath, FormatsString = formatsString, VerboseString = verboseString };
}

public static string? ResolvePbiFilePathInput(string pbiFilePath)
{
var resolvedPath = !string.IsNullOrEmpty(pbiFilePath) && pbiFilePath.ToLower().EndsWith(Constants.PBIPReportJsonFileName)
? Path.GetDirectoryName(pbiFilePath)
var resolvedPath = !string.IsNullOrEmpty(pbiFilePath) && pbiFilePath.ToLower().EndsWith(Constants.PBIPReportJsonFileName)
? Path.GetDirectoryName(pbiFilePath)
: pbiFilePath;

return resolvedPath;
Expand Down

0 comments on commit a78ff86

Please sign in to comment.