Skip to content

Commit

Permalink
Migrate to <PackageReference> and new .csproj format.
Browse files Browse the repository at this point in the history
This is step 1 in a .NET Core migraton, doing pieces first. However, building from the command line is far more of a pain than it should be. Uploading the current state as a checkpoint for what a user runs into in the real world.

Challenege: make the simplest build.bat or build.ps1 that builds this project from the CLI. Hopefully with a maximum of only the VS 2017 build tools installed (*not* a full Visual Studio install, which is unreasnable for most build servers).

For the .bat/ps1 file:
A user should be able:
1. Install VS 2017 build tools
2. Pull code
3. Run build.bat/ps1
  • Loading branch information
NickCraver committed Aug 3, 2017
1 parent c15b408 commit 7ccf72f
Show file tree
Hide file tree
Showing 226 changed files with 578 additions and 173,253 deletions.
4 changes: 0 additions & 4 deletions Build.bat

This file was deleted.

3 changes: 1 addition & 2 deletions Opserver.Core/Current.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public static void LogException(Exception exception, string key = null)
{
if (!ShouldLog(key)) return;

var deserializationException = exception as DeserializationException;
if (deserializationException != null)
if (exception is DeserializationException deserializationException)
{
exception.AddLoggedData("Snippet-After", deserializationException.SnippetAfterError)
.AddLoggedData("Position", deserializationException.Position.ToString())
Expand Down
3 changes: 1 addition & 2 deletions Opserver.Core/Data/CloudFlare/CloudFlareAPI.Zones.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public partial class CloudFlareAPI

public CloudFlareZone GetZoneFromUrl(string url)
{
Uri uri;
return !Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri) ? null : GetZoneFromHost(uri.Host);
return !Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out Uri uri) ? null : GetZoneFromHost(uri.Host);
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions Opserver.Core/Data/CloudFlare/DataCenters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public static IEnumerable<string> GetMasked(List<IPAddress> addresses)
{
foreach (var ip in addresses)
{
string masked;
if (_cached.TryGetValue(ip, out masked)) yield return masked;
if (_cached.TryGetValue(ip, out string masked)) yield return masked;
else yield return _cached[ip] = GetMasked(ip);
}
}
Expand Down
3 changes: 1 addition & 2 deletions Opserver.Core/Data/Dashboard/HardwareSummary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public int? Label
if (Bank == null) return null;
if (Name.Length > Bank.Length)
{
int position;
if (int.TryParse(Name.Substring(Bank.Length), out position))
if (int.TryParse(Name.Substring(Bank.Length), out int position))
{
_label = position;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public async Task<List<Node>> GetAllNodesAsync()
if (h.Name == "unspecified")
continue;

Version kernelVersion;
// Note: we can't follow this pattern, we'll need to refresh existing nodes
// not wholesale replace on poll
var n = new Node
Expand All @@ -61,7 +60,7 @@ public async Task<List<Node>> GetAllNodesAsync()
ServiceTag = h.SerialNumber,
MachineType = h.OS?.Caption,
MachineOSVersion = h.OS?.Version,
KernelVersion = Version.TryParse(h.OS?.Version, out kernelVersion) ? kernelVersion : null,
KernelVersion = Version.TryParse(h.OS?.Version, out Version kernelVersion) ? kernelVersion : null,

Interfaces = h.Interfaces?.Select(hi => new Interface
{
Expand All @@ -74,8 +73,7 @@ public async Task<List<Node>> GetAllNodesAsync()
PhysicalAddress = hi.Value.MAC,
IPs = hi.Value?.IPAddresses?.Select(ip =>
{
IPNet result;
return IPNet.TryParse(ip, out result) ? result : null;
return IPNet.TryParse(ip, out IPNet result) ? result : null;
}).Where(ip => ip != null).ToList() ?? new List<IPNet>(),
LastSync = hi.Value.StatsLastUpdated,
InBps = hi.Value.Inbps,
Expand Down
3 changes: 1 addition & 2 deletions Opserver.Core/Data/Dashboard/Providers/OrionDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ Join Interfaces i

foreach (var m in result)
{
IPNet net;
if (IPNet.TryParse(m.IPAddress, m.SubnetMask, out net))
if (IPNet.TryParse(m.IPAddress, m.SubnetMask, out IPNet net))
{
m.IPNet = net;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ FROM Win32_NetworkAdapter
{
var teamName = data.Team;

Interface teamInterface;
if (teamNamesToInterfaces.TryGetValue(teamName, out teamInterface))
if (teamNamesToInterfaces.TryGetValue(teamName, out Interface teamInterface))
{
var adapterName = data.Name;
var memberInterface = Interfaces.Find(x => x.Name == adapterName);
Expand All @@ -240,8 +239,7 @@ FROM WIn32_NetworkAdapterConfiguration
{
foreach (var data in await q.GetDynamicResultAsync().ConfigureAwait(false))
{
Interface i;
if (indexMap.TryGetValue(data.InterfaceIndex, out i))
if (indexMap.TryGetValue(data.InterfaceIndex, out Interface i))
{
i.DHCPEnabled = data.DHCPEnabled;
var ips = data.IPAddress as string[];
Expand All @@ -255,9 +253,7 @@ FROM WIn32_NetworkAdapterConfiguration

for (var j = 0; j < (ips?.Length).GetValueOrDefault(0); j++)
{
IPNet net;
int cidr;
if (int.TryParse(subnets[j], out cidr) && IPNet.TryParse(ips[j], cidr, out net))
if (int.TryParse(subnets[j], out int cidr) && IPNet.TryParse(ips[j], cidr, out IPNet net))
{
i.IPs.Add(net);
}
Expand Down
6 changes: 1 addition & 5 deletions Opserver.Core/Data/Dashboard/Providers/WmiDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ private IEnumerable<WmiNode> InitNodeList(IList<string> nodeNames)
return nodesList;
}

private WmiNode GetWmiNodeById(string id)
{
WmiNode n;
return _wmiNodeLookup.TryGetValue(id, out n) ? n : null;
}
private WmiNode GetWmiNodeById(string id) => _wmiNodeLookup.TryGetValue(id, out WmiNode n) ? n : null;

public override int MinSecondsBetweenPolls => 10;

Expand Down
3 changes: 1 addition & 2 deletions Opserver.Core/Data/Elastic/ElasticCluster.Aliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public string GetIndexAliasedName(string index)
if (Aliases.Data?.Aliases == null)
return index;

List<string> aliases;
return Aliases.Data.Aliases.TryGetValue(index, out aliases)
return Aliases.Data.Aliases.TryGetValue(index, out List<string> aliases)
? aliases[0].IsNullOrEmptyReturn(index)
: index;
}
Expand Down
6 changes: 2 additions & 4 deletions Opserver.Core/Data/Elastic/ElasticCluster.KnownNodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public class ElasticNode

public ElasticNode(string hostAndPort)
{
Uri uri;
if (Uri.TryCreate(hostAndPort, UriKind.Absolute, out uri))
if (Uri.TryCreate(hostAndPort, UriKind.Absolute, out Uri uri))
{
Url = uri.ToString();
Host = uri.Host;
Expand All @@ -45,8 +44,7 @@ public ElasticNode(string hostAndPort)
if (parts.Length == 2)
{
Host = parts[0];
int port;
if (int.TryParse(parts[1], out port))
if (int.TryParse(parts[1], out int port))
{
Port = port;
}
Expand Down
6 changes: 2 additions & 4 deletions Opserver.Core/Data/Elastic/ElasticCluster.Nodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public partial class ElasticCluster
{
foreach (var s in stats.Nodes)
{
NodeInfo node;
if (result.RawNodes.TryGetValue(s.Key, out node))
if (result.RawNodes.TryGetValue(s.Key, out NodeInfo node))
{
node.Stats = s.Value;
}
Expand Down Expand Up @@ -87,8 +86,7 @@ public class NodeInfo : IMonitorStatus

private string GetAttribute(string key)
{
string val;
return Attributes != null && Attributes.TryGetValue(key, out val) ? val : null;
return Attributes != null && Attributes.TryGetValue(key, out string val) ? val : null;
}

public string GUID { get; internal set; }
Expand Down
6 changes: 3 additions & 3 deletions Opserver.Core/Data/HAProxy/HAProxyAdmin.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using EnumsNET;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using UnconstrainedMelody;

namespace StackExchange.Opserver.Data.HAProxy
{
Expand Down Expand Up @@ -97,7 +97,7 @@ private static async Task<bool> PostAction(Proxy p, Server server, Action action
var responseBytes = await wc.UploadValuesTaskAsync(instance.Url, new NameValueCollection
{
["s"] = server.Name,
["action"] = action.GetDescription(),
["action"] = action.AsString(EnumFormat.Description),
["b"] = p.Name
}).ConfigureAwait(false);
var response = Encoding.UTF8.GetString(responseBytes);
Expand Down
6 changes: 3 additions & 3 deletions Opserver.Core/Data/HAProxy/Item.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using EnumsNET;
using System;
using System.Text.RegularExpressions;
using UnconstrainedMelody;

namespace StackExchange.Opserver.Data.HAProxy
{
Expand Down Expand Up @@ -467,7 +467,7 @@ public virtual MonitorStatus MonitorStatus
}
}

public string MonitorStatusReason => MonitorStatus == MonitorStatus.Good ? null : ProxyName + " Status: " + ProxyServerStatus.GetDescription();
public string MonitorStatusReason => MonitorStatus == MonitorStatus.Good ? null : ProxyName + " Status: " + ProxyServerStatus.AsString(EnumFormat.Description);

public bool IsChecked => Status != "no check";
public bool IsActive => Active == 1;
Expand Down
3 changes: 1 addition & 2 deletions Opserver.Core/Data/HAProxy/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ public string NiceName
get
{
if (_niceName != null) return _niceName;
string result;
return _niceName = Current.Settings.HAProxy.Aliases.TryGetValue(Name, out result)
return _niceName = Current.Settings.HAProxy.Aliases.TryGetValue(Name, out string result)
? result
: Name;
}
Expand Down
15 changes: 5 additions & 10 deletions Opserver.Core/Data/IPNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,13 @@ public static IPNet Parse(string ipOrCidr)
var parts = ipOrCidr.Split(StringSplits.ForwardSlash);
if (parts.Length == 2)
{
int cidr;
if (int.TryParse(parts[1], out cidr))
if (int.TryParse(parts[1], out int cidr))
{
return Parse(parts[0], cidr);
}
throw new IPNetParseException("Error parsing CIDR from IP: '{0}'", parts[1]);
}
IPAddress ip;
if (IPAddress.TryParse(parts[0], out ip))
if (IPAddress.TryParse(parts[0], out IPAddress ip))
{
return new IPNet(ip, null);
}
Expand All @@ -117,8 +115,7 @@ public static bool TryParse(string ip, int cidr, out IPNet net)

public static IPNet Parse(string ip, int cidr)
{
IPAddress ipAddr;
if (IPAddress.TryParse(ip, out ipAddr))
if (IPAddress.TryParse(ip, out IPAddress ipAddr))
{
var bits = GetBitLength(ipAddr.AddressFamily);
var subnet = IPAddressFromCIDR(bits, cidr);
Expand All @@ -135,11 +132,9 @@ public static bool TryParse(string ip, string subnet, out IPNet net)

public static IPNet Parse(string ip, string subnet)
{
IPAddress ipAddr;
if (IPAddress.TryParse(ip, out ipAddr))
if (IPAddress.TryParse(ip, out IPAddress ipAddr))
{
IPAddress subnetAddr;
if (IPAddress.TryParse(subnet, out subnetAddr))
if (IPAddress.TryParse(subnet, out IPAddress subnetAddr))
{
if (!TinyIPAddress.FromIPAddress(subnetAddr).Value.IsValidSubnet)
throw new IPNetParseException("Error parsing subnet mask Address from IP: '" + subnet + "' is not a valid subnet");
Expand Down
4 changes: 2 additions & 2 deletions Opserver.Core/Data/Pagerduty/PagerDutyAPI.Incidents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.Serialization;
using System.Threading.Tasks;
using Jil;
using UnconstrainedMelody;
using EnumsNET;

namespace StackExchange.Opserver.Data.PagerDuty
{
Expand Down Expand Up @@ -110,7 +110,7 @@ public MonitorStatus MonitorStatus
}
}

public string MonitorStatusReason => "Status is " + Status.GetDescription();
public string MonitorStatusReason => "Status is " + Status.AsString(EnumFormat.Description);
}

public class Acknowledgement
Expand Down
6 changes: 2 additions & 4 deletions Opserver.Core/Data/Redis/RedisAnalyzer.Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ public RedisMemoryAnalysis(RedisConnectionInfo connectionInfo, int database)

ConnectionInfo = connectionInfo;
Database = database;
List<KeyMatcher> matchers;
if (!RedisAnalyzer.KeyMatchers.TryGetValue(connectionInfo, out matchers))
if (!RedisAnalyzer.KeyMatchers.TryGetValue(connectionInfo, out List<KeyMatcher> matchers))
{
ErrorMessage = "Could not find regexes defined for " + connectionInfo;
return;
Expand All @@ -210,8 +209,7 @@ internal void TallyDebugLine(string key, string debugLine)
if (debugLine == null) return;

var match = _debugObjectSize.Match(debugLine);
long size;
if (!match.Success || !long.TryParse(match.Groups[1].Value, NumberStyles.Any, CultureInfo.InvariantCulture, out size)) return;
if (!match.Success || !long.TryParse(match.Groups[1].Value, NumberStyles.Any, CultureInfo.InvariantCulture, out long size)) return;

var matcher = GetKeyMatcher(key);
var keySize = Encoding.UTF8.GetByteCount(key);
Expand Down
10 changes: 4 additions & 6 deletions Opserver.Core/Data/Redis/RedisInfo.Parsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ public static RedisInfo FromInfoString(string infoStr)
if (line.StartsWith("#"))
{
var sectionName = line.Replace("# ", "");
PropertyInfo currentSectionProp;
if (_sectionMappings.TryGetValue(sectionName, out currentSectionProp))
if (_sectionMappings.TryGetValue(sectionName, out PropertyInfo currentSectionProp))
{
currentSection = (RedisInfoSection) currentSectionProp.GetValue(info);
currentSection = (RedisInfoSection)currentSectionProp.GetValue(info);
}
else
{
currentSection = new RedisInfoSection {Name = sectionName, IsUnrecognized = true};
currentSection = new RedisInfoSection { Name = sectionName, IsUnrecognized = true };
info.UnrecognizedSections = info.UnrecognizedSections ?? new List<RedisInfoSection>();
info.UnrecognizedSections.Add(currentSection);
}
Expand All @@ -77,8 +76,7 @@ public static RedisInfo FromInfoString(string infoStr)
if (currentSection.IsUnrecognized)
continue;

PropertyInfo propertyInfo;
var prop = _propertyMappings[currentSection.GetType()].TryGetValue(key, out propertyInfo) ? propertyInfo : null;
var prop = _propertyMappings[currentSection.GetType()].TryGetValue(key, out PropertyInfo propertyInfo) ? propertyInfo : null;
if (prop == null)
{
currentSection.MapUnrecognizedLine(key, value);
Expand Down
3 changes: 1 addition & 2 deletions Opserver.Core/Data/Redis/RedisInstance.Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public static RedisInstance Get(string connectionString)
{
var parts = connectionString.Split(StringSplits.Colon);
if (parts.Length != 2) return null;
int port;
if (int.TryParse(parts[1], out port)) return Get(parts[0], port);
if (int.TryParse(parts[1], out int port)) return Get(parts[0], port);
}
else
{
Expand Down
17 changes: 5 additions & 12 deletions Opserver.Core/Data/Redis/RedisInstance.SlowLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@ public partial class RedisInstance
/// <remarks>
/// For setup instructions call <see cref="SetSlowLogThreshold"/> and <see cref="SetSlowLogMaxLength"/> or see: http://redis.io/commands/slowlog
/// </remarks>
public bool IsSlowLogEnabled
{
get
{
string configVal;
int numVal;
return Config.Data != null
&& Config.Data.TryGetValue(ConfigParamSlowLogThreshold, out configVal)
&& int.TryParse(configVal, out numVal)
&& numVal > 0;
}
}
public bool IsSlowLogEnabled =>
Config.Data != null
&& Config.Data.TryGetValue(ConfigParamSlowLogThreshold, out string configVal)
&& int.TryParse(configVal, out int numVal)
&& numVal > 0;

private Cache<List<CommandTrace>> _slowLog;
public Cache<List<CommandTrace>> SlowLog =>
Expand Down
3 changes: 1 addition & 2 deletions Opserver.Core/Data/Redis/RedisInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public RedisInstance(RedisConnectionInfo connectionInfo) : base(connectionInfo.H

public string GetServerName(string hostOrIp)
{
IPAddress addr;
if (Current.Settings.Dashboard.Enabled && IPAddress.TryParse(hostOrIp, out addr))
if (Current.Settings.Dashboard.Enabled && IPAddress.TryParse(hostOrIp, out IPAddress addr))
{
var nodes = DashboardModule.GetNodesByIP(addr).ToList();
if (nodes.Count == 1) return nodes[0].PrettyName;
Expand Down
Loading

0 comments on commit 7ccf72f

Please sign in to comment.