Exemple #1
0
 private void bgwUDPListener_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         int listenPort = Properties.Settings.Default.Port;
         listening = true;
         listener  = new UdpClient(listenPort);
         //listener.Client.ReceiveTimeout = 1000;
         IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
         string     received_data;
         byte[]     receive_byte_array;
         try
         {
             while (listening)
             {
                 receive_byte_array = listener.Receive(ref groupEP);
                 received_data      = Encoding.ASCII.GetString(receive_byte_array, 0, receive_byte_array.Length);
                 BakeryLog newlog = AddLog(received_data);
                 bgwUDPListener.ReportProgress(0, newlog);
             }
             listener.Close();
         }
         catch (Exception ex)
         {
             Debug.WriteLine(ex.Message);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         Debug.WriteLine(ex.InnerException.Message);
     }
 }
Exemple #2
0
        private void WriteLogs(BakeryLog newlog)
        {
            try
            {
                string basefolder = Properties.Settings.Default.LogFolder;
                string logfolder  = String.Format("{0}\\{1}", basefolder, newlog.shortname);
                string logfile    = string.Format("{0}\\{1}.log", logfolder, newlog.id);

                if (!Directory.Exists(basefolder))
                {
                    Directory.CreateDirectory(basefolder);
                }

                if (!Directory.Exists(logfolder))
                {
                    Directory.CreateDirectory(logfolder);
                }

                using (StreamWriter sw = new StreamWriter(logfile, true))
                {
                    sw.WriteLine(String.Format("{0},{1}", newlog.datetime, newlog.log));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.InnerException.Message);
            }
        }
Exemple #3
0
        private BakeryLog AddLog(string logdata)
        {
            string[]  s      = logdata.Split('|');
            BakeryLog newlog = new BakeryLog(s[0], Convert.ToDateTime(s[1]), s[2], s[3]);

            Logs.Add(newlog);
            if (writelogs)
            {
                WriteLogs(newlog);
            }
            return(newlog);
        }
Exemple #4
0
 public ModelEventArgs(BakeryLog l)
 {
     newlog = l;
 }
Exemple #5
0
        private void bgwUDPListener_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            BakeryLog nl = (BakeryLog)e.UserState;

            this.newlog.Invoke(this, new ModelEventArgs(nl));
        }