Exemple #1
0
    // log unhandled exception before app dies
    static void LastRites(object sender, UnhandledExceptionEventArgs args)
    {
        Exception ex = (Exception)args.ExceptionObject;

        Magellan.LogMessage(ex.ToString());
        Environment.Exit(1);
    }
Exemple #2
0
 private void MonitorSerialPorts()
 {
     try {
         var valid = sph.Where(s => s != null);
         valid.ToList().ForEach(s => { s.SPH_Thread.Start(); });
     } catch (Exception ex) {
         Magellan.LogMessage(ex.ToString());
     }
 }
 public void SqlLog(string k, string s)
 {
     try {
         #if CORE_MYSQL
         this.mpipe.logValue(k, s);
         #endif
     } catch (Exception ex) {
         Magellan.LogMessage(ex.ToString());
     }
 }
Exemple #4
0
 public void ShutDown()
 {
     try {
         u.Stop();
         sph.ForEach(s => { s.Stop(); });
     }
     catch (Exception ex) {
         Magellan.LogMessage(ex.ToString());
         Console.WriteLine(ex);
     }
 }
Exemple #5
0
 private void UdpListen()
 {
     try {
         u = new UDPMsgBox(9450, this.asyncUDP);
         u.SetParent(this);
         u.My_Thread.Start();
     } catch (Exception ex) {
         Magellan.LogMessage(ex.ToString());
         Console.WriteLine("Failed to start UDP server");
         Console.WriteLine(ex);
     }
 }
Exemple #6
0
    public void MsgSend(string msg)
    {
        try {
            if (full_udp)
            {
                byte[] body = System.Text.Encoding.UTF8.GetBytes(msg);
                getClient().Send(body, body.Length);
            }
            else if (mq_available && mq_enabled)
            {
                #if CORE_RABBIT
                byte[] body = System.Text.Encoding.UTF8.GetBytes(msg);
                rabbit_channel.BasicPublish("", "core-pos", null, body);
                #endif
            }
            else
            {
                lock (msgLock) {
                    string filename    = System.Guid.NewGuid().ToString();
                    string my_location = AppDomain.CurrentDomain.BaseDirectory;
                    char   sep         = Path.DirectorySeparatorChar;

                    /**
                     * Depending on msg rate I may replace "1" with a bigger value
                     * as long as the counter resets at least once per 65k messages
                     * there shouldn't be sequence issues. But real world disk I/O
                     * may be trivial with a serial message source
                     */
                    if (msgCount % 1 == 0 && Directory.GetFiles(my_location + sep + "ss-output/").Length == 0)
                    {
                        msgCount = 0;
                    }
                    filename = msgCount.ToString("D5") + filename;
                    msgCount++;

                    TextWriter sw = new StreamWriter(my_location + sep + "ss-output/" + sep + "tmp" + sep + filename);
                    sw = TextWriter.Synchronized(sw);
                    sw.WriteLine(msg);
                    sw.Close();
                    File.Move(my_location + sep + "ss-output/" + sep + "tmp" + sep + filename,
                              my_location + sep + "ss-output/" + sep + filename);
                }
            }
        } catch (Exception ex) {
            Magellan.LogMessage(ex.ToString());
        }
    }
Exemple #7
0
 public void MsgRecv(string msg)
 {
     try {
         if (msg == "exit")
         {
             this.ShutDown();
         }
         else if (msg == "die!")
         {
             new Thread(() => this.ShutDown()).Start();
             Thread.Sleep(500);
             Environment.Exit(0);
         }
         else if (msg == "full_udp")
         {
             full_udp = true;
         }
         else if (msg == "mq_up" && mq_available)
         {
             mq_enabled = true;
         }
         else if (msg == "mq_down")
         {
             mq_enabled = false;
         }
         else if (msg == "status")
         {
             byte[] body = System.Text.Encoding.ASCII.GetBytes(Status());
             getClient().Send(body, body.Length);
         }
         else
         {
             sph.ForEach(s => { s.HandleMsg(msg); });
         }
     } catch (Exception ex) {
         Magellan.LogMessage(ex.ToString());
     }
 }
Exemple #8
0
    private List <MagellanConfigPair> JsonConfig()
    {
        string my_location             = AppDomain.CurrentDomain.BaseDirectory;
        char   sep                     = Path.DirectorySeparatorChar;
        string ini_file                = my_location + sep + ".." + sep + ".." + sep + ".." + sep + "ini.json";
        List <MagellanConfigPair> conf = new List <MagellanConfigPair>();

        if (!File.Exists(ini_file))
        {
            return(conf);
        }

        string ini_json = File.ReadAllText(ini_file);

        try {
            JObject o = JObject.Parse(ini_json);
            // filter list to valid entries
            var valid = o["NewMagellanPorts"].Where(p => p["port"] != null && p["module"] != null);
            // map entries to ConfigPair objects
            var pairs = valid.Select(p => new MagellanConfigPair()
            {
                port = (string)p["port"], module = (string)p["module"], settings = p.ToObject <Dictionary <string, string> >()
            });
            conf = pairs.ToList();

            // print errors for invalid entries
            o["NewMagellanPorts"].Where(p => p["port"] == null).ToList().ForEach(p => {
                Console.WriteLine("Missing the \"port\" setting. JSON:");
                Console.WriteLine(p);
            });

            // print errors for invalid entries
            o["NewMagellanPorts"].Where(p => p["module"] == null).ToList().ForEach(p => {
                Console.WriteLine("Missing the \"module\" setting. JSON:");
                Console.WriteLine(p);
            });
        } catch (NullReferenceException) {
            // probably means no NewMagellanPorts key in ini.json
            // not a fatal problem
        } catch (Exception ex) {
            // unexpected exception
            Magellan.LogMessage(ex.ToString());
            Console.WriteLine(ex);
        }
        try {
            JObject o  = JObject.Parse(ini_json);
            var     ua = (bool)o["asyncUDP"];
            this.asyncUDP = ua;
        } catch (Exception) {}
        try {
            JObject o   = JObject.Parse(ini_json);
            var     drb = (bool)o["disableRBA"];
            this.disableRBA = drb;
        } catch (Exception) {}
        try {
            JObject o   = JObject.Parse(ini_json);
            var     dbt = (bool)o["disableButtons"];
            this.disableButtons = dbt;
        } catch (Exception) {}
        try {
            JObject o  = JObject.Parse(ini_json);
            var     lx = (bool)o["logXML"];
            this.logXML = lx;
        } catch (Exception) {}

        return(conf);
    }