Inheritance: CustomForms.DelegateForm
コード例 #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);
    }
コード例 #2
0
    static public void Main(string[] args)
    {
        int verbosity = 0;

        for (int i = 0; i < args.Length; i++)
        {
            if (args[i] == "-v")
            {
                verbosity = 1;
                if (i + 1 < args.Length)
                {
                    try { verbosity = Int32.Parse(args[i + 1]); }
                    catch {}
                }
            }
        }
        Magellan m       = new Magellan(verbosity);
        bool     exiting = false;

        while (!exiting)
        {
            string user_in = System.Console.ReadLine();
            if (user_in == "exit")
            {
                System.Console.WriteLine("stopping");
                m.ShutDown();
                exiting = true;
            }
        }
    }
コード例 #3
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());
     }
 }
コード例 #4
0
ファイル: Magellan.cs プロジェクト: CORE-POS/NewMagellan-Core
 public void SqlLog(string k, string s)
 {
     try {
         #if CORE_MYSQL
         this.mpipe.logValue(k, s);
         #endif
     } catch (Exception ex) {
         Magellan.LogMessage(ex.ToString());
     }
 }
コード例 #5
0
 public void ShutDown()
 {
     try {
         u.Stop();
         sph.ForEach(s => { s.Stop(); });
     }
     catch (Exception ex) {
         Magellan.LogMessage(ex.ToString());
         Console.WriteLine(ex);
     }
 }
コード例 #6
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);
     }
 }
コード例 #7
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());
        }
    }
コード例 #8
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());
     }
 }
コード例 #9
0
ファイル: Magellan.cs プロジェクト: 42burritos/PFC_CORE
 public static void Main(string[] args)
 {
     int verbosity = 0;
     for(int i=0;i<args.Length;i++){
         if (args[i] == "-v"){
             verbosity = 1;
             if (i+1 < args.Length){
                 try { verbosity = Int32.Parse(args[i+1]); }
                 catch{}
             }
         }
     }
     Magellan m = new Magellan(verbosity);
     bool exiting = false;
     while(!exiting){
         string user_in = System.Console.ReadLine();
         if (user_in == "exit"){
             System.Console.WriteLine("stopping");
             m.ShutDown();
             exiting = true;
         }
     }
 }
コード例 #10
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);
    }
コード例 #11
0
 override protected void OnStart(String[] args){
     SerialPortHandler[] sph = new SerialPortHandler[1];
     sph[0] = new SPH_Magellan_Scale("COM1");
     this.my_obj = new Magellan(sph);
 }
コード例 #12
0
ファイル: Magellan.cs プロジェクト: philipashlock/IS4C-NF
 public static void Main()
 {
     Magellan m = new Magellan();
     bool exiting = false;
     while(!exiting){
         string user_in = System.Console.ReadLine();
         if (user_in == "exit"){
             System.Console.WriteLine("stopping");
             m.ShutDown();
             exiting = true;
         }
     }
 }
コード例 #13
0
ファイル: MagellanWinSVC.cs プロジェクト: 42burritos/PFC_CORE
 override protected void OnStart(String[] args)
 {
     SerialPortHandler[] sph = new SerialPortHandler[1];
     sph[0]      = new SPH_Magellan_Scale("COM1");
     this.my_obj = new Magellan(sph);
 }