AsterixDisplayAnalyser.RecForwConnection4.StartRecording C# (CSharp) Метод

StartRecording() публичный статический Метод

public static StartRecording ( bool Is_ReplayFormat, string FilePath, IPAddress Interface_Addres, IPAddress Multicast_Address, int PortNumber ) : bool
Is_ReplayFormat bool
FilePath string
Interface_Addres System.Net.IPAddress
Multicast_Address System.Net.IPAddress
PortNumber int
Результат bool
        public static bool StartRecording(bool Is_ReplayFormat, 
                                          string FilePath,              // Path and file name 
                                          IPAddress Interface_Addres,   // IP address of the interface where the data is expected
                                          IPAddress Multicast_Address,  // Multicast address of the expected data
                                          int PortNumber)
        {
            if (IsConnectionActive() == false)
            {
                // Open up a new socket with the net IP address and port number
                try
                {
                    rcv_sock = new UdpClient();
                    rcv_sock.ExclusiveAddressUse = false;
                    rcv_iep = new IPEndPoint(IPAddress.Any, PortNumber);
                    rcv_sock.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                    rcv_sock.ExclusiveAddressUse = false;
                    rcv_sock.Client.Bind(rcv_iep);
                    rcv_sock.JoinMulticastGroup(Multicast_Address, Interface_Addres);
                }
                catch
                {
                    MessageBox.Show("Not possible! Make sure given IP address/port is a valid one on your system or not already used by some other process");
                    return false;
                }

                KeepGoing = true;
                RequestStop = false;
                ListenForDataThread = new Thread(new ThreadStart(DOWork));
                ListenForDataThread.Start();
            }

            RecordingEnabled = true;
            ReplayFormatRequested = Is_ReplayFormat;
            LastDataBlockDateTime = DateTime.Now;

            // Open up the stream

            try
            {
                RecordingStream = new FileStream(FilePath, FileMode.Create);
                RecordingBinaryWriter = new BinaryWriter(RecordingStream);
            }
            catch
            {

            }

            BytesProcessed = 0;
            return true;
        }

Usage Example

Пример #1
0
        private void checkedListBoxRecordingName_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            // Check if this item is checked
            if (e.NewValue == CheckState.Checked)
            {
                AppendDateTime DateTimeAppend = new AppendDateTime();
                string         path_and_name  = this.textBoxRecordDirectory.Text + "\\" + DateTimeAppend.ApendDateandTimeToFront(this.checkedListBoxRecordingName.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString());

                switch (this.checkedListBoxRecordingName.SelectedIndex)
                {
                case 0:
                    if (RecForwConnection1.IsRecordingEnabled() == false)
                    {
                        if (RecForwConnection1.StartRecording(!this.chkBoxReplayFormatEnabled1.Checked,
                                                              path_and_name + GetFileExtension(!this.chkBoxReplayFormatEnabled1.Checked),
                                                              IPAddress.Parse(this.listBoxLocalAddr.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString()),
                                                              IPAddress.Parse(this.listBoxIPAddress.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString()),
                                                              int.Parse(this.listBoxPort.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString())) == false)
                        {
                            this.checkedListBoxRecordingName.SetItemCheckState(this.checkedListBoxRecordingName.SelectedIndex, CheckState.Unchecked);
                        }
                        else
                        {
                            progressBar1.Visible = true;
                            this.chkBoxReplayFormatEnabled1.Enabled = false;
                        }
                    }
                    break;

                case 1:
                    if (RecForwConnection2.IsRecordingEnabled() == false)
                    {
                        if (RecForwConnection2.StartRecording(!this.chkBoxReplayFormatEnabled2.Checked,
                                                              path_and_name + GetFileExtension(!this.chkBoxReplayFormatEnabled2.Checked),
                                                              IPAddress.Parse(this.listBoxLocalAddr.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString()),
                                                              IPAddress.Parse(this.listBoxIPAddress.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString()),
                                                              int.Parse(this.listBoxPort.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString())) == false)
                        {
                            this.checkedListBoxRecordingName.SetItemCheckState(this.checkedListBoxRecordingName.SelectedIndex, CheckState.Unchecked);
                        }
                        else
                        {
                            progressBar2.Visible = true;
                            this.chkBoxReplayFormatEnabled2.Enabled = false;
                        }
                    }
                    break;

                case 2:
                    if (RecForwConnection3.IsRecordingEnabled() == false)
                    {
                        if (RecForwConnection3.StartRecording(!this.chkBoxReplayFormatEnabled3.Checked,
                                                              path_and_name + GetFileExtension(!this.chkBoxReplayFormatEnabled3.Checked),
                                                              IPAddress.Parse(this.listBoxLocalAddr.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString()),
                                                              IPAddress.Parse(this.listBoxIPAddress.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString()),
                                                              int.Parse(this.listBoxPort.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString())) == false)
                        {
                            this.checkedListBoxRecordingName.SetItemCheckState(this.checkedListBoxRecordingName.SelectedIndex, CheckState.Unchecked);
                        }
                        else
                        {
                            progressBar3.Visible = true;
                            this.chkBoxReplayFormatEnabled3.Enabled = false;
                        }
                    }
                    break;

                case 3:
                    if (RecForwConnection4.IsRecordingEnabled() == false)
                    {
                        if (RecForwConnection4.StartRecording(!this.chkBoxReplayFormatEnabled4.Checked,
                                                              path_and_name + GetFileExtension(!this.chkBoxReplayFormatEnabled4.Checked),
                                                              IPAddress.Parse(this.listBoxLocalAddr.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString()),
                                                              IPAddress.Parse(this.listBoxIPAddress.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString()),
                                                              int.Parse(this.listBoxPort.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString())) == false)
                        {
                            this.checkedListBoxRecordingName.SetItemCheckState(this.checkedListBoxRecordingName.SelectedIndex, CheckState.Unchecked);
                        }
                        else
                        {
                            progressBar4.Visible = true;
                            this.chkBoxReplayFormatEnabled4.Enabled = false;
                        }
                    }
                    break;

                case 4:
                    if (RecForwConnection5.IsRecordingEnabled() == false)
                    {
                        if (RecForwConnection5.StartRecording(!this.chkBoxReplayFormatEnabled5.Checked,
                                                              path_and_name + GetFileExtension(!this.chkBoxReplayFormatEnabled5.Checked),
                                                              IPAddress.Parse(this.listBoxLocalAddr.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString()),
                                                              IPAddress.Parse(this.listBoxIPAddress.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString()),
                                                              int.Parse(this.listBoxPort.Items[this.checkedListBoxRecordingName.SelectedIndex].ToString())) == false)
                        {
                            this.checkedListBoxRecordingName.SetItemCheckState(this.checkedListBoxRecordingName.SelectedIndex, CheckState.Unchecked);
                        }
                        else
                        {
                            progressBar5.Visible = true;
                            this.chkBoxReplayFormatEnabled5.Enabled = false;
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            else // No it is not checked
            {
                switch (this.checkedListBoxRecordingName.SelectedIndex)
                {
                case 0:
                    if (RecForwConnection1.IsRecordingEnabled() == true)
                    {
                        RecForwConnection1.StopRecording();
                        progressBar1.Visible = false;
                        this.chkBoxReplayFormatEnabled1.Enabled = true;
                    }
                    break;

                case 1:
                    if (RecForwConnection2.IsRecordingEnabled() == true)
                    {
                        RecForwConnection2.StopRecording();
                        progressBar2.Visible = false;
                        this.chkBoxReplayFormatEnabled2.Enabled = true;
                    }
                    break;

                case 2:
                    if (RecForwConnection3.IsRecordingEnabled() == true)
                    {
                        RecForwConnection3.StopRecording();
                        progressBar3.Visible = false;
                        this.chkBoxReplayFormatEnabled3.Enabled = true;
                    }
                    break;

                case 3:
                    if (RecForwConnection4.IsRecordingEnabled() == true)
                    {
                        RecForwConnection4.StopRecording();
                        progressBar4.Visible = false;
                        this.chkBoxReplayFormatEnabled4.Enabled = true;
                    }
                    break;

                case 4:
                    if (RecForwConnection5.IsRecordingEnabled() == true)
                    {
                        RecForwConnection5.StopRecording();
                        progressBar5.Visible = false;
                        this.chkBoxReplayFormatEnabled5.Enabled = true;
                    }
                    break;

                default:
                    break;
                }
            }
        }