Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (listView1.CheckedItems.Count > 0 &&
                MessageBox.Show(this, "Are you sure you want to restart the selected encoders?", "Restart requested...",
                                MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                button1.Enabled = false;
                button2.Enabled = false;
                Cursor savedCursor = Cursor;
                Cursor = Cursors.WaitCursor;
                _event.WaitOne();
                _event.Reset();
                foreach (ListViewItem lvi in listView1.CheckedItems)
                {
                    if (_done)
                        break;
                    StreamingEncoder encoder = (StreamingEncoder) lvi.Tag;
                    Control oec =
                        new Control(encoder.ControlAddress, encoder.ControlPort);
                    bool success = false;

                    lvi.SubItems[3].Text = "Attempting to Restart...";
                    lvi.SubItems[2].Text = "No";
                    Application.DoEvents();
                    if (oec.Open())
                    {
                        if (oec.IsRecording)
                        {
                            lvi.SubItems[2].Text = "Yes";
                            lvi.SubItems[3].Text = "Recording will NOT be saved!";
                        }
                        Application.DoEvents();

                        Connection cn =
                            oec.Connection;
                        lvi.SubItems[3].Text = "Connected, sending command...";
                        Application.DoEvents();
                        Command retcmd = cn.SendCommandWaitForResponse(new Command("RBT", "0"));
                        if (retcmd == null)
                        {
                            lvi.SubItems[3].Text = "Received an invalid response: <null>";
                        }
                        else
                        {
                            if (retcmd.Params.Length > 0)
                            {
                                if (retcmd.Params[0].Equals("OK"))
                                {
                                    lvi.SubItems[3].Text = "Sent restart command successfully.";
                                    success = true;
                                }
                                Application.DoEvents();
                            }
                            if (!success)
                            {
                                lvi.SubItems[3].Text = "Received an invalid response: " + retcmd.RawData;
                                Application.DoEvents();
                            }
                        }
                        oec.Close();
                    }
                    else
                    {
                        lvi.SubItems[3].Text = "Could not connect...";
                    }
                    Application.DoEvents();
                }
                Cursor = savedCursor;
                _event.Set();
                button1.Enabled = true;
                button2.Enabled = true;
            }
            Application.DoEvents();
        }
Exemplo n.º 2
0
        private void UpdateEncoderList()
        {
            _event.WaitOne();
            _event.Reset();
            foreach (ListViewItem lvi in listView1.Items)
            {
                if (_done)
                    break;
                StreamingEncoder encoder = (StreamingEncoder) lvi.Tag;
                try
                {
                    Control oec =
                        new Control(encoder.ControlAddress, encoder.ControlPort);

                    lvi.SubItems[3].Text = "Connecting";
                    Application.DoEvents();
                    if (oec.Open())
                    {
                        if (oec.IsRecording)
                        {
                            lvi.SubItems[2].Text = "Yes";
                            lvi.BackColor = Color.Cornsilk;
                            Application.DoEvents();
                        }
                        else
                        {
                            lvi.SubItems[2].Text = "No";
                            lvi.BackColor = Color.White;
                            Application.DoEvents();
                        }
                        oec.Close();
                        lvi.SubItems[3].Text = "Ready...";
                        lvi.Font = new Font(lvi.Font, FontStyle.Regular);
                        Application.DoEvents();
                    }
                    else
                    {
                        IPAddress ipAddress;
                        if (encoder.ControlAddress.Split(new char[] {'.'}).Length != 3)
                        {
                            IPHostEntry hostEntry = Dns.GetHostEntry(encoder.ControlAddress);
                            ipAddress = hostEntry.AddressList[0];
                        }
                        else
                        {
                            byte[] addressBytes = ASCIIEncoding.ASCII.GetBytes(encoder.ControlAddress);
                            ipAddress = new IPAddress(addressBytes);
                        }
                        Icmp ping = new Icmp(ipAddress);
                        if (ping.Ping() > TimeSpan.FromMilliseconds(5000.0))
                        {
                            lvi.SubItems[2].Text = "???";
                            lvi.SubItems[3].Text = "Possibly disabled. Needs to be power cycled.";
                            lvi.ForeColor = Color.LightGray;
                            lvi.Font = new Font(lvi.Font, FontStyle.Bold);
                            Application.DoEvents();
                        }
                        else
                        {
                            lvi.Font = new Font(lvi.Font, FontStyle.Regular);
                            lvi.SubItems[2].Text = "Yes";
                            lvi.SubItems[3].Text = "Encoder refused connection. Usually means it is recording...";
                            lvi.BackColor = Color.Cornsilk;
                            Application.DoEvents();
                        }
                    }
                }
                catch (Exception e)
                {
                    lvi.ForeColor = Color.LightGray;
                    lvi.SubItems[3].Text = "Offline";
                }
                Application.DoEvents();
            }
            _event.Set();
            Application.DoEvents();
        }
Exemplo n.º 3
0
        bool Test()
        {
            string stest, srslt, stemp;
            bool bReturn = true;

            m_oec = new OysterEncoderController.Control(m_sServerAddress,m_iPort);

            // open a connection
            stest = "open a connection";
            if (m_oec.Open())
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);

            /*
            // list all files on the device
            stest = "list all files on the device";
            if (m_oec.RequestFileList())
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
            }
            Console.WriteLine(stest + ": " + srslt);
            */

            // generate a filename and save it
            string sFilename = System.Guid.NewGuid().ToString();

            // start a recording with generated filename
            stest = "StartRecording";
            if (m_oec.StartRecording(sFilename))
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);

            // get RunState
            stest = "get RunState";
            srslt = m_oec.RunState;
            if (srslt != null)
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);

            // get ArchiveState
            stest = "get ArchiveState";
            srslt = m_oec.ArchiveState;
            if (srslt != null)
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);

            // check IsRecording
            stest = "check IsRecording";
            if (m_oec.IsRecording)
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);

            // stop the recording
            stest = "StopRecording";
            if (m_oec.StopRecording())
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);

            /*
            // list all files on the device
            stest = "list all files on the device";
            if (m_oec.RequestFileList())
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
            }
            Console.WriteLine(stest + ": " + srslt);
            */

            // set FilePath
            stest = "set FilePath";
            stemp = @"C:\OysterMedia";
            m_oec.FilePath = stemp;
            if (m_oec.LastError == string.Empty)
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);

            // set Profile (NOT IMPLEMENTED)
            // get ArchiveState
            stest = "get ArchiveState";
            srslt = m_oec.ArchiveState;
            if (srslt != null)
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);
            // get RunState
            stest = "get RunState";
            srslt = m_oec.RunState;
            if (srslt != null)
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);
            // get FilePath
            stest = "get FilePath";
            srslt = m_oec.FilePath;
            if (srslt != null)
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);
            // get Profile
            stest = "get Profile";
            srslt = m_oec.Profile;
            if (srslt != null)
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);
            // get AllProperties
            stest = "get AllProperties";
            srslt = m_oec.AllProperties;
            if (srslt != null)
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);

            // close the connection
            stest = "close the connection";
            if (m_oec.Close())
            {
                srslt = "passed";
            }
            else
            {
                srslt = "failed";
                bReturn = false;
            }
            Console.WriteLine(stest + ": " + srslt);
            m_oec = null;
            return bReturn;
        }