Server/FormMain.cs
changeset 253 2dae7a163fff
parent 252 59ea5cb46258
child 254 181323a59047
     1.1 --- a/Server/FormMain.cs	Mon Aug 22 13:20:54 2016 +0200
     1.2 +++ b/Server/FormMain.cs	Thu Aug 25 00:42:09 2016 +0200
     1.3 @@ -131,7 +131,7 @@
     1.4          /// <summary>
     1.5          /// 
     1.6          /// </summary>
     1.7 -        RichTextBoxTextWriter iWriter;
     1.8 +        RichTextBoxTraceListener iWriter;
     1.9  
    1.10  
    1.11          /// <summary>
    1.12 @@ -172,8 +172,8 @@
    1.13              InitializeComponent();
    1.14  
    1.15              //Redirect console output
    1.16 -            iWriter = new RichTextBoxTextWriter(richTextBoxLogs);
    1.17 -            Console.SetOut(iWriter);
    1.18 +            iWriter = new RichTextBoxTraceListener(richTextBoxLogs);
    1.19 +            Trace.Listeners.Add(iWriter);
    1.20  
    1.21              //Populate device types
    1.22              PopulateDeviceTypes();
    1.23 @@ -993,9 +993,6 @@
    1.24          //This is our timer tick responsible to perform our render
    1.25          private void timer_Tick(object sender, EventArgs e)
    1.26          {
    1.27 -            //Not ideal cause this has nothing to do with display render
    1.28 -            LogsUpdate();
    1.29 -
    1.30              //Update our animations
    1.31              DateTime NewTickTime = DateTime.Now;
    1.32  
    1.33 @@ -2498,25 +2495,11 @@
    1.34          }
    1.35  
    1.36          /// <summary>
    1.37 -        /// 
    1.38 -        /// </summary>
    1.39 -        private void LogsUpdate()
    1.40 -        {
    1.41 -            if (iWriter != null)
    1.42 -            {
    1.43 -                iWriter.Flush();
    1.44 -            }
    1.45 -
    1.46 -        }
    1.47 -
    1.48 -        /// <summary>
    1.49          /// Broadcast messages to subscribers.
    1.50          /// </summary>
    1.51          /// <param name="message"></param>
    1.52          protected override void WndProc(ref Message aMessage)
    1.53          {
    1.54 -            LogsUpdate();
    1.55 -
    1.56              if (OnWndProc != null)
    1.57              {
    1.58                  OnWndProc(ref aMessage);
    1.59 @@ -2577,8 +2560,8 @@
    1.60                  }
    1.61                  catch (Exception ex)
    1.62                  {
    1.63 -                    Console.WriteLine("Exception thrown by ConnectHarmonyAsync");
    1.64 -                    Console.WriteLine(ex.ToString());
    1.65 +                    Trace.WriteLine("Exception thrown by ConnectHarmonyAsync");
    1.66 +                    Trace.WriteLine(ex.ToString());
    1.67                  }
    1.68              }
    1.69          }
    1.70 @@ -3008,35 +2991,35 @@
    1.71              Program.HarmonyClient = null;
    1.72              Program.HarmonyConfig = null;
    1.73  
    1.74 -            Console.WriteLine("Harmony: Connecting... ");
    1.75 +            Trace.WriteLine("Harmony: Connecting... ");
    1.76              Program.HarmonyClient = new HarmonyHub.Client(iTextBoxHarmonyHubAddress.Text);
    1.77              //First create our client and login
    1.78              if (File.Exists("SessionToken") && !aForceAuth)
    1.79              {
    1.80                  var sessionToken = File.ReadAllText("SessionToken");
    1.81 -                Console.WriteLine("Harmony: Reusing token: {0}", sessionToken);
    1.82 +                Trace.WriteLine("Harmony: Reusing token: {0}", sessionToken);
    1.83                  Program.HarmonyClient.Open(sessionToken);
    1.84              }
    1.85              else
    1.86              {
    1.87                  if (string.IsNullOrEmpty(iTextBoxLogitechPassword.Text))
    1.88                  {
    1.89 -                    Console.WriteLine("Harmony: Credentials missing!");
    1.90 +                    Trace.WriteLine("Harmony: Credentials missing!");
    1.91                      return;
    1.92                  }
    1.93  
    1.94 -                Console.WriteLine("Harmony: Authenticating with Logitech servers...");
    1.95 +                Trace.WriteLine("Harmony: Authenticating with Logitech servers...");
    1.96                  await Program.HarmonyClient.Open(iTextBoxLogitechUserName.Text, iTextBoxLogitechPassword.Text);
    1.97                  File.WriteAllText("SessionToken", Program.HarmonyClient.Token);
    1.98              }
    1.99  
   1.100 -            Console.WriteLine("Harmony: Fetching Harmony Hub configuration...");
   1.101 +            Trace.WriteLine("Harmony: Fetching Harmony Hub configuration...");
   1.102  
   1.103              //Fetch our config
   1.104              Program.HarmonyConfig = await Program.HarmonyClient.GetConfigAsync();
   1.105              PopulateTreeViewHarmony(Program.HarmonyConfig);
   1.106  
   1.107 -            Console.WriteLine("Harmony: Ready");
   1.108 +            Trace.WriteLine("Harmony: Ready");
   1.109  
   1.110              //Make sure harmony command actions are showing device name instead of device id
   1.111              PopulateEventsTreeView();
   1.112 @@ -3080,7 +3063,7 @@
   1.113                  HarmonyHub.Function f = tag;
   1.114                  HarmonyHub.Device d = (HarmonyHub.Device)e.Node.Parent.Parent.Tag;
   1.115  
   1.116 -                Console.WriteLine($"Harmony: Sending {f.Name} to {d.Label}...");
   1.117 +                Trace.WriteLine($"Harmony: Sending {f.Name} to {d.Label}...");
   1.118  
   1.119                  await Program.HarmonyClient.SendCommandAsync(d.Id, f.Name);
   1.120              }