소스 검색

Resharper format

Nick Babcock 7 년 전
부모
커밋
921c2679e1
7개의 변경된 파일31개의 추가작업 그리고 31개의 파일을 삭제
  1. 5 5
      OhmGraphite/GraphiteWriter.cs
  2. 1 1
      OhmGraphite/LoggerUtils.cs
  3. 5 6
      OhmGraphite/MetricConfig.cs
  4. 2 2
      OhmGraphite/MetricTimer.cs
  5. 10 6
      OhmGraphite/Program.cs
  6. 5 5
      OhmGraphite/Sensor.cs
  7. 3 6
      OhmGraphite/SensorCollector.cs

+ 5 - 5
OhmGraphite/GraphiteWriter.cs

@@ -8,9 +8,9 @@ namespace OhmGraphite
 {
     public class GraphiteWriter
     {
+        private readonly string _localHost;
         private readonly string _remoteHost;
         private readonly int _remotePort;
-        private readonly string _localHost;
 
         public GraphiteWriter(string remoteHost, int remotePort)
         {
@@ -24,7 +24,7 @@ namespace OhmGraphite
             // We don't want to transmit metrics across multiple seconds as they
             // are being retrieved so calculate the timestamp of the signaled event
             // only once.
-            var epoch = new DateTimeOffset(reportTime).ToUnixTimeSeconds();
+            long epoch = new DateTimeOffset(reportTime).ToUnixTimeSeconds();
             using (var client = new TcpClient(_remoteHost, _remotePort))
             using (var networkStream = client.GetStream())
             using (var writer = new StreamWriter(networkStream))
@@ -48,9 +48,9 @@ namespace OhmGraphite
             // A name like "GPU Core" is turned into "gpucore". Also
             // since some names are like "cpucore#2", turn them into
             // separate metrics by replacing "#" with "."
-            var identifier = sensor.Identifier.Replace('/', '.').Substring(1);
+            string identifier = sensor.Identifier.Replace('/', '.').Substring(1);
             identifier = identifier.Remove(identifier.LastIndexOf('.'));
-            var name = sensor.Name.ToLower().Replace(" ", null).Replace('#', '.');
+            string name = sensor.Name.ToLower().Replace(" ", null).Replace('#', '.');
             return new Sensor(identifier, name, sensor.Value);
         }
 
@@ -59,4 +59,4 @@ namespace OhmGraphite
             return Invariant($"ohm.{host}.{data.Identifier}.{data.Name} {data.Value} {epoch:d}");
         }
     }
-}
+}

+ 1 - 1
OhmGraphite/LoggerUtils.cs

@@ -36,4 +36,4 @@ namespace OhmGraphite
             }
         }
     }
-}
+}

+ 5 - 6
OhmGraphite/MetricConfig.cs

@@ -1,15 +1,10 @@
 using System;
 using System.Configuration;
-using OpenHardwareMonitor.Hardware;
 
 namespace OhmGraphite
 {
     public class MetricConfig
     {
-        public string Host { get; }
-        public int Port { get; }
-        public TimeSpan Interval { get; }
-
         public MetricConfig(string host, int port, TimeSpan interval)
         {
             Host = host;
@@ -17,6 +12,10 @@ namespace OhmGraphite
             Interval = interval;
         }
 
+        public string Host { get; }
+        public int Port { get; }
+        public TimeSpan Interval { get; }
+
         public static MetricConfig ParseAppSettings()
         {
             string host = ConfigurationManager.AppSettings["host"] ?? "localhost";
@@ -34,4 +33,4 @@ namespace OhmGraphite
             return new MetricConfig(host, port, interval);
         }
     }
-}
+}

+ 2 - 2
OhmGraphite/MetricTimer.cs

@@ -9,14 +9,14 @@ namespace OhmGraphite
     public class MetricTimer
     {
         private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
+        private readonly SensorCollector _collector;
 
         private readonly Timer _timer;
-        private readonly SensorCollector _collector;
         private readonly GraphiteWriter _writer;
 
         public MetricTimer(TimeSpan interval, SensorCollector collector, GraphiteWriter writer)
         {
-            _timer = new Timer(interval.TotalMilliseconds) { AutoReset = true };
+            _timer = new Timer(interval.TotalMilliseconds) {AutoReset = true};
             _timer.Elapsed += ReportMetrics;
             _collector = collector;
             _writer = writer;

+ 10 - 6
OhmGraphite/Program.cs

@@ -4,10 +4,11 @@ using Topshelf;
 
 namespace OhmGraphite
 {
-    class Program
+    internal class Program
     {
         private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
-        static void Main(string[] args)
+
+        private static void Main(string[] args)
         {
             HostFactory.Run(x =>
             {
@@ -16,7 +17,7 @@ namespace OhmGraphite
                     // We need to know where the graphite server lives and how often
                     // to poll the hardware
                     var config = Logger.LogFunction("parse config", MetricConfig.ParseAppSettings);
-                    var seconds = config.Interval.TotalSeconds;
+                    double seconds = config.Interval.TotalSeconds;
                     Logger.Info($"Host: {config.Host} port: {config.Port} interval: {seconds}");
 
                     // We'll want to capture all available hardware metrics
@@ -34,17 +35,20 @@ namespace OhmGraphite
                     var collector = new SensorCollector(computer);
                     var writer = new GraphiteWriter(config.Host, config.Port);
 
-                    s.ConstructUsing(name => Logger.LogFunction("creating timer", () => new MetricTimer(config.Interval, collector, writer)));
+                    s.ConstructUsing(name =>
+                        Logger.LogFunction("creating timer",
+                            () => new MetricTimer(config.Interval, collector, writer)));
                     s.WhenStarted(tc => tc.Start());
                     s.WhenStopped(tc => tc.Stop());
                 });
                 x.UseNLog();
                 x.RunAsLocalSystem();
-                x.SetDescription("Extract hardware sensor data and exports it to a given host and port in a graphite compatible format");
+                x.SetDescription(
+                    "Extract hardware sensor data and exports it to a given host and port in a graphite compatible format");
                 x.SetDisplayName("Ohm Graphite");
                 x.SetServiceName("OhmGraphite");
                 x.OnException(ex => Logger.Error(ex, "OhmGraphite TopShelf encountered an error"));
             });
         }
     }
-}
+}

+ 5 - 5
OhmGraphite/Sensor.cs

@@ -2,15 +2,15 @@
 {
     public class Sensor
     {
-        public string Identifier { get; }
-        public string Name { get; }
-        public float Value { get; }
-
         public Sensor(string identifier, string name, float value)
         {
             Identifier = identifier;
             Name = name;
             Value = value;
         }
+
+        public string Identifier { get; }
+        public string Name { get; }
+        public float Value { get; }
     }
-}
+}

+ 3 - 6
OhmGraphite/SensorCollector.cs

@@ -36,10 +36,7 @@ namespace OhmGraphite
             {
                 yield return hardware;
 
-                foreach (var subHardware in hardware.SubHardware)
-                {
-                    yield return subHardware;
-                }
+                foreach (var subHardware in hardware.SubHardware) yield return subHardware;
             }
         }
 
@@ -48,7 +45,7 @@ namespace OhmGraphite
             hardware.Update();
             foreach (var sensor in hardware.Sensors)
             {
-                var id = sensor.Identifier.ToString();
+                string id = sensor.Identifier.ToString();
 
                 // Only report a value if the sensor was able to get a value
                 // as 0 is different than "didn't read". For example, are the
@@ -64,4 +61,4 @@ namespace OhmGraphite
             }
         }
     }
-}
+}