예제 #1
0
        private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            // If we're running around with plugins and reflection, the last Exception is often a TargetInvocationException that isn't helpful at all,
            // but the next InnerException is
            var ex = e.Exception;

            if (ex != null && ex.GetType() == typeof(TargetInvocationException) && ex.InnerException != null)
            {
                ex = ex.InnerException;
            }

            // Now we'll use two possible ways to show this Exception. First - and coolest by far - is a Error entry in the logviewer.
            // But this requires the logviewer to work, which could get difficult while startup
            if (AwesomeViewerStolenFromTheInternet.ReadyToShowErrorMessages)
            {
                AwesomeViewerStolenFromTheInternet.LogException(ex);
                e.Handled = true;
            }

            else
            {
                // Then we'll just add all the error messages to one nice report
                var errMsg = "";
                var inner  = ex;
                while (inner != null)
                {
                    errMsg += ex.Message + Environment.NewLine;
                    inner   = inner.InnerException;
                }

                // And post it in a MessageBox - "Ok" says "go on", "Cancel" says exit the program. The latter is useful when you got
                // something that spams Exceptions.
                e.Handled = MessageBox.Show(ex.Message, "Error", MessageBoxButton.OKCancel, MessageBoxImage.Error) == MessageBoxResult.OK;
            }
        }
예제 #2
0
        private void MessageReceived(TimestampedBytes data)
        {
            // The plugin did send us a Message, how nice :)
            // It will be raw data and needs to be decoded by the type (first byte)
            // Using the acPlugins4net library we can directly receive a PluginMessage
            var msg = AcMessageParser.Parse(data);

            AwesomeViewerStolenFromTheInternet.Log(msg);

            // if there is a Request, we'll have to send the corresponding answer.
            if (msg.Type == ACSProtocol.MessageType.ACSP_GET_CAR_INFO)
            {
                var request  = msg as RequestCarInfo;
                var response = CarInfoConfiguration.GetMessage(request.CarId);
                UDPServer.TrySend(response.ToBinary());
            }

            /*
             * // Currently we only have two very simple messages, so we're do it here:
             * try
             * {
             *  using (var br = new BinaryReader(new MemoryStream(data)))
             * {
             *  var msgType = (ACSProtocol.MessageType)br.ReadByte();
             *  switch (msgType)
             *  {
             *      case ACSProtocol.MessageType.ACSP_GET_CAR_INFO:
             *          {
             *              // The plugin asks for the car_info of car_id X
             *              var requested_car_id = br.ReadByte();
             *
             *              // Then it expects a single answer
             *              var carInfoMsg = new MsgCarInfo() { CarId = requested_car_id, CarModel = "bmw_e300", CarSkin = "anthrazit", DriverName = "Minolin", DriverTeam = "Team", DriverGuid = "2468274569", IsConnected = true };
             *              UDPServer.TrySend(carInfoMsg);
             *          }
             *          break;
             *      case ACSProtocol.MessageType.ACSP_REALTIMEPOS_INTERVAL:
             *          {
             *          }
             *          break;
             *      default:
             *          throw new Exception("Unknown/unexpected incoming message type '" + msgType + "'");
             *  }
             * }
             *  }
             * catch(Exception ex)
             * {
             *  System.Windows.MessageBox.Show(ex.Message);
             * }*/
        }
예제 #3
0
        public void SendMessage(PluginMessage msg)
        {
            var success = UDPServer.TrySend(msg.ToBinary());

            AwesomeViewerStolenFromTheInternet.Log(msg);
        }
예제 #4
0
 private void OnError(Exception ex)
 {
     AwesomeViewerStolenFromTheInternet.LogException(ex);
     Console.WriteLine("Error: " + ex.Message);
 }