Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nameof instead of magic strings (GUI, Packager, Tests projects) #2145

Merged
merged 2 commits into from Aug 23, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -127,7 +127,7 @@ internal async Task RunAsync(string walletName, bool mixAll, bool keepMixAlive)
}
finally
{
Logger.LogInfo($"Daemon stopped.");
Logger.LogInfo($"{nameof(Daemon)} stopped.");
}
}

@@ -245,7 +245,7 @@ public SendTabViewModel(WalletViewModel walletViewModel, bool isTransactionBuild
Label = Label.Trim(',', ' ').Trim();
if (!IsMax && string.IsNullOrWhiteSpace(Label))
{
SetWarningMessage("Label is required.");
SetWarningMessage($"{nameof(Label)} is required.");
return;
}

@@ -278,7 +278,7 @@ public SendTabViewModel(WalletViewModel walletViewModel, bool isTransactionBuild
{
if (!Money.TryParse(AmountText, out Money amount) || amount == Money.Zero)
{
SetWarningMessage($"Invalid amount.");
SetWarningMessage("Invalid amount.");
return;
}

@@ -139,15 +139,15 @@ public async Task InitializeNoWalletAsync()

Config = new Config(Path.Combine(DataDir, "Config.json"));
await Config.LoadOrCreateDefaultFileAsync();
Logger.LogInfo<Config>("Config is successfully initialized.");
Logger.LogInfo<Config>($"{nameof(Config)} is successfully initialized.");

#endregion ConfigInitialization

BitcoinStore = new BitcoinStore();
var bstoreInitTask = BitcoinStore.InitializeAsync(Path.Combine(DataDir, "BitcoinStore"), Network);
var bstoreInitTask = BitcoinStore.InitializeAsync(Path.Combine(DataDir, $"{nameof(BitcoinStore)}"), Network);

This comment has been minimized.

Copy link
@nopara73

nopara73 Aug 23, 2019

Collaborator

Don't nameof filepath.

var hwiInitTask = HwiProcessManager.InitializeAsync(DataDir, Network);
var addressManagerFolderPath = Path.Combine(DataDir, "AddressManager");
AddressManagerFilePath = Path.Combine(addressManagerFolderPath, $"AddressManager{Network}.dat");
var addressManagerFolderPath = Path.Combine(DataDir, $"{nameof(AddressManager)}");

This comment has been minimized.

Copy link
@nopara73

nopara73 Aug 23, 2019

Collaborator

Don't nameof filepath.

AddressManagerFilePath = Path.Combine(addressManagerFolderPath, $"{nameof(AddressManager)}{Network}.dat");

This comment has been minimized.

Copy link
@nopara73

nopara73 Aug 23, 2019

Collaborator

Don't nameof filepath.

var addrManTask = InitializeAddressManagerBehaviorAsync();

var blocksFolderPath = Path.Combine(DataDir, $"Blocks{Network}");
@@ -308,7 +308,7 @@ private async Task<AddressManagerBehavior> InitializeAddressManagerBehaviorAsync
if (Network == Network.RegTest)
{
AddressManager = new AddressManager();
Logger.LogInfo<AddressManager>($"Fake {nameof(AddressManager)} is initialized on the RegTest.");
Logger.LogInfo<AddressManager>($"Fake {nameof(AddressManager)} is initialized on the {Network.RegTest}.");
This conversation was marked as resolved by yahiheb

This comment has been minimized.

Copy link
@lontivero

lontivero Aug 22, 2019

Collaborator

nameof is missing so, ToString is invoked.

}
else
{
@@ -431,9 +431,9 @@ public async Task InitializeWalletServiceAsync(KeyManager keyManager)
ChaumianClient.Start();
Logger.LogInfo("Start Chaumian CoinJoin service...");

Logger.LogInfo("Starting WalletService...");
Logger.LogInfo($"Starting {nameof(WalletService)}...");
await WalletService.InitializeAsync(token);
Logger.LogInfo("WalletService started.");
Logger.LogInfo($"{nameof(WalletService)} started.");

token.ThrowIfCancellationRequested();
WalletService.Coins.CollectionChanged += Coins_CollectionChanged;
@@ -67,7 +67,7 @@ private void InitializeComponent()
{
Global.InitializeUiConfig(uiConfig);
Application.Current.Resources.AddOrReplace(Global.UiConfigResourceKey, Global.UiConfig);
Logging.Logger.LogInfo<UiConfig>("UiConfig is successfully initialized.");
Logging.Logger.LogInfo<UiConfig>($"{Global.UiConfig} is successfully initialized.");
This conversation was marked as resolved by yahiheb

This comment has been minimized.

Copy link
@benthecarman

benthecarman Aug 22, 2019

Collaborator

There is no nameof here, is that correct?


if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@@ -160,7 +160,7 @@ private async Task ClosingAsync()
Global.UiConfig.Width = Width;
Global.UiConfig.Height = Height;
await Global.UiConfig.ToFileAsync();
Logging.Logger.LogInfo<UiConfig>("UiConfig is saved.");
Logging.Logger.LogInfo<UiConfig>($"{Global.UiConfig} is saved.");
This conversation was marked as resolved by yahiheb

This comment has been minimized.

Copy link
@benthecarman

benthecarman Aug 22, 2019

Collaborator

There is no nameof here, is that correct?

}

Hide();
@@ -82,12 +82,12 @@ private static async Task Main(string[] args)

private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
Logger.LogWarning(e?.Exception, "UnobservedTaskException");
Logger.LogWarning(e?.Exception, $"{nameof(TaskScheduler.UnobservedTaskException)}");
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Logger.LogWarning(e?.ExceptionObject as Exception, "UnhandledException");
Logger.LogWarning(e?.ExceptionObject as Exception, $"{nameof(AppDomain.CurrentDomain.UnhandledException)}");
}

private static AppBuilder BuildAvaloniaApp()
@@ -14,8 +14,8 @@ public static class NSubsysUtil
/// </summary>
public static bool ProcessFile(string exeFilePath)
{
Console.WriteLine("NSubsys: Subsystem Changer for Windows PE files.");
Console.WriteLine($"NSubsys: Target EXE {exeFilePath}.");
Console.WriteLine($"{nameof(NSubsys)}: Subsystem Changer for Windows PE files.");
Console.WriteLine($"{nameof(NSubsys)}: Target EXE {exeFilePath}.");
using (var peFile = new PeUtility(exeFilePath))
{
SubSystemType subsysVal;
@@ -27,12 +27,12 @@ public static bool ProcessFile(string exeFilePath)
switch (subsysVal)
{
case PeUtility.SubSystemType.ImageSubSystemWindowsGui:
Console.WriteLine("NSubsys: Executable file is already a Win32 App!");
Console.WriteLine($"{nameof(NSubsys)}: Executable file is already a Win32 App!");
return true;

case PeUtility.SubSystemType.ImageSubSystemWindowsCui:
Console.WriteLine("NSubsys: Console app detected...");
Console.WriteLine("NSubsys: Converting...");
Console.WriteLine($"{nameof(NSubsys)}: Console app detected...");
Console.WriteLine($"{nameof(NSubsys)}: Converting...");

var subsysSetting = BitConverter.GetBytes((ushort)SubSystemType.ImageSubSystemWindowsGui);

@@ -45,18 +45,18 @@ public static bool ProcessFile(string exeFilePath)
{
peFile.Stream.Seek(subsysOffset, SeekOrigin.Begin);
peFile.Stream.Write(subsysSetting, 0, subsysSetting.Length);
Console.WriteLine("NSubsys: Conversion Complete...");
Console.WriteLine($"{nameof(NSubsys)}: Conversion Complete...");
}
else
{
Console.WriteLine("NSubsys: Can't write changes!");
Console.WriteLine("NSubsys: Conversion Failed...");
Console.WriteLine($"{nameof(NSubsys)}: Can't write changes!");
Console.WriteLine($"{nameof(NSubsys)}: Conversion Failed...");
}

return true;

default:
Console.WriteLine($"NSubsys: Unsupported subsystem number: {subsysVal}.");
Console.WriteLine($"{nameof(NSubsys)}: Unsupported subsystem number: {subsysVal}.");
return false;
}
}
@@ -50,8 +50,8 @@ public async Task TestServicesAsync(string networkString)
throw new NotSupportedException($"{nameof(Network)} not supported: {network}.");
}

var addressManagerFolderPath = Path.Combine(Global.Instance.DataDir, "AddressManager");
var addressManagerFilePath = Path.Combine(addressManagerFolderPath, $"AddressManager{network}.dat");
var addressManagerFolderPath = Path.Combine(Global.Instance.DataDir, $"{nameof(AddressManager)}");

This comment has been minimized.

Copy link
@nopara73

nopara73 Aug 23, 2019

Collaborator

Don't nameof filepath.

var addressManagerFilePath = Path.Combine(addressManagerFolderPath, $"{nameof(AddressManager)}{network}.dat");

This comment has been minimized.

Copy link
@nopara73

nopara73 Aug 23, 2019

Collaborator

Don't nameof filepath.

var blocksFolderPath = Path.Combine(Global.Instance.DataDir, "Blocks", network.ToString());
var connectionParameters = new NodeConnectionParameters();
AddressManager addressManager = null;
@@ -111,7 +111,7 @@ public async Task TestServicesAsync(string networkString)
{
if (times > 4200) // 7 minutes
{
throw new TimeoutException($"Connection test timed out.");
throw new TimeoutException("Connection test timed out.");
}
await Task.Delay(100);
times++;
@@ -861,9 +861,9 @@ public async Task SendTestsAsync()
Assert.Contains(res.Transaction.Transaction.Outputs, x => x.Value == activeOutput.Amount);
Logger.LogInfo<RegTests>($"Change Output: {changeOutput.Amount.ToString(false, true)} {changeOutput.ScriptPubKey.GetDestinationAddress(network)}");
}
Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");

@@ -897,9 +897,9 @@ public async Task SendTestsAsync()
Assert.Equal(receive, activeOutput.ScriptPubKey);
Assert.Equal(amountToSend - res.Fee, activeOutput.Amount);
Assert.Contains(res.Transaction.Transaction.Outputs, x => x.Value == changeOutput.Amount);
Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"Change Output: {changeOutput.Amount.ToString(false, true)} {changeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -930,9 +930,9 @@ public async Task SendTestsAsync()
Assert.Equal(receive, activeOutput.ScriptPubKey);
Assert.Equal(amountToSend, activeOutput.Amount);
Assert.Contains(res.Transaction.Transaction.Outputs, x => x.Value == changeOutput.Amount);
Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"Change Output: {changeOutput.Amount.ToString(false, true)} {changeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -963,9 +963,9 @@ public async Task SendTestsAsync()
Assert.Equal(receive, activeOutput.ScriptPubKey);
Assert.Equal(amountToSend, activeOutput.Amount);
Assert.Contains(res.Transaction.Transaction.Outputs, x => x.Value == changeOutput.Amount);
Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"Change Output: {changeOutput.Amount.ToString(false, true)} {changeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -996,9 +996,9 @@ public async Task SendTestsAsync()
Assert.Equal(receive, activeOutput.ScriptPubKey);
Assert.Equal(amountToSend, activeOutput.Amount);
Assert.Contains(res.Transaction.Transaction.Outputs, x => x.Value == changeOutput.Amount);
Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"Change Output: {changeOutput.Amount.ToString(false, true)} {changeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -1061,9 +1061,9 @@ public async Task SendTestsAsync()
Assert.Equal(res.SpentCoins.Count(), res.Transaction.Transaction.Inputs.Count);

Assert.Equal(receive, activeOutput.ScriptPubKey);
Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");

@@ -1137,9 +1137,9 @@ public async Task SendTestsAsync()
Assert.Empty(res.OuterWalletOutputs);

Assert.Equal(receive, activeOutput.ScriptPubKey);
Logger.LogDebug<RegTests>($"Fee: {res.Fee}");
Logger.LogDebug<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
Logger.LogDebug<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
Logger.LogDebug<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
Logger.LogDebug<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
Logger.LogDebug<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogDebug<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogDebug<RegTests>($"TxId: {res.Transaction.GetHash()}");

@@ -3302,7 +3302,7 @@ public async Task CcjClientTestsAsync()
await Task.Delay(1000);
if (times > 21)
{
throw new TimeoutException("State.GetAllWaitingCoins() always empty.");
throw new TimeoutException($"{nameof(chaumianClient1.State)}.{nameof(chaumianClient1.State.GetAllWaitingCoins)}() always empty.");
}
times++;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.