Ejemplo n.º 1
0
        private void Control_Load(object sender, EventArgs e)
        {
            LoadJson();
            foreach (var site in jsonTestSite)
            {
                cboxSite.Items.Add(site);
            }
            cboxSite.ValueMember   = "id";
            cboxSite.DisplayMember = "desc";


            int number = Device.InstalledCount;

            // initialize cboxCamera
            for (int ind = 0; ind < number; ind++)
            {
                cboxCamera.Items.Add($"Azure Kinect {ind+1}");
            }

            if (Environment.OSVersion.Version.Major >= 6)
            {
                LoadWasapiDevicesCombo();
            }
            else
            {
                throw new Exception("Too old operating system, please update!");
            }

            timer1.Enabled            = true;
            TickNumInSpaceCheckPeriod = HzDriveSpaceCheck * 1000 / timer1.Interval;
            lblRemainingDiskTime.Text = $"{ DriveSpaceManager.GetInstance().GetMinutesByAvailabeSpace() }";
        }
Ejemplo n.º 2
0
 public static DriveSpaceManager GetInstance()
 {
     if (singleton == null)
     {
         singleton = new DriveSpaceManager();
     }
     return(singleton);
 }
Ejemplo n.º 3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (Globals.getInstance().isRecording)
            {
                // update the recording time label
                var span = DateTime.Now - dtStartRecordingTime;
                lblRecordingTime.Text = span.ToString(@"hh\:mm\:ss");
            }
            else
            {
                lblRecordingTime.Text = "00:00:00";
            }

            if (Globals.getInstance().viewerRecorderPairs.Count == 0)
            {
                btnRecord.Enabled = false;
                btnTune.Enabled   = false;
            }
            else
            {
                if (Globals.getInstance().hasStoppedRecordingButFlushing)
                {
                    btnRecord.Enabled = false;
                    btnTune.Enabled   = false;
                }
                else
                {
                    if (isTuned)
                    {
                        btnRecord.Enabled = true;
                    }
                    else
                    {
                        btnRecord.Enabled = false;
                    }
                    if (Globals.getInstance().isRecording)
                    {
                        btnTune.Enabled = false;
                    }
                    else
                    {
                        btnTune.Enabled = true;
                    }
                }
            }

            if (Globals.getInstance().isRecording)
            {
                lblRemainingDiskTime.Text = $"{ DriveSpaceManager.GetInstance().GetMinutesByAvailabeSpace() }";
                TickCountForSpaceCheck++;
                if (TickCountForSpaceCheck > TickNumInSpaceCheckPeriod)
                {
                    TickCountForSpaceCheck = 0;
                    if (DriveSpaceManager.GetInstance().ShouldStopRecording)
                    {
                        btnRecord.PerformClick();
                        MessageBox.Show("Free disk space is too small. The system has to stop recording automatically now. Please clean the disk first and then start recording again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    if (DriveSpaceManager.GetInstance().ShouldWarnWhenRecording&& !HasPromptedLimitedFreeDisk)
                    {
                        HasPromptedLimitedFreeDisk = true;
                        MessageBox.Show("Free disk space is nearly used up. You may need to stop recording shortly?", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                HasPromptedLimitedFreeDisk = false;
            }
        }
Ejemplo n.º 4
0
        private async void btnRecord_Click(object sender, EventArgs e)
        {
            if (!Globals.getInstance().isRecording)
            {
                DriveSpaceManager.GetInstance().NumOfkinect = Globals.getInstance().viewerRecorderPairs.Count;
                if (DriveSpaceManager.GetInstance().ShouldStopRecording)
                {
                    MessageBox.Show("Free disk space is too small. Please clean it first and then start recording again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (DriveSpaceManager.GetInstance().ShouldWarnWhenRecording)
                {
                    var result = MessageBox.Show("Free disk space is nearly used up. Are you sure you want to start recording now?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }
                else if (DriveSpaceManager.GetInstance().ShouldWarnBeforeRecording)
                {
                    var result = MessageBox.Show($"You can only record for around {DriveSpaceManager.GetInstance().GetMinutesByAvailabeSpace()} minutes due to limited free space in the disk drive. Are you sure you want to start recording now?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }

                if (siteID.Length < 1)
                {
                    MessageBox.Show("Please specify the testing site before recording.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // prepare the file-saving directory
                String folderName    = DateTime.Now.ToString("yyyyMMddHHmmss");
                String fullDirectory = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "Kinect", folderName);
                // create the folder
                try {
                    Directory.CreateDirectory(fullDirectory);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // initialize the recorder
                foreach (var viewerRecorderPair in Globals.getInstance().viewerRecorderPairs)
                {
                    viewerRecorderPair.Value.InitializeRecorder(fullDirectory, siteID);
                    viewerRecorderPair.Value.StartRecord();
                }

                // UI management
                lblRecordingTime.ForeColor = Color.Red;
                btnRecord.Text             = "Stop Recording";
                btnPreview.Enabled         = false;
                Globals.getInstance().isRecording = true;
                dtStartRecordingTime = DateTime.Now;

                TonePlayer.GetInstance().PlayBeep(2000, 500, WaveFormType.SquareWave, 32000);
            }
            else
            {
                var result = MessageBox.Show("Sure to stop recording?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (result == DialogResult.No)
                {
                    return;
                }
                Globals.getInstance().isRecording = false;
                List <Task> tasks = new List <Task>();
                foreach (var viewerRecorderPair in Globals.getInstance().viewerRecorderPairs)
                {
                    tasks.Add(Task.Run(() =>
                    {
                        viewerRecorderPair.Value.StopRecord();
                    }));
                }
                Globals.getInstance().hasStoppedRecordingButFlushing = true;
                await Task.WhenAll(tasks);

                Globals.getInstance().hasStoppedRecordingButFlushing = false;
                lblRecordingTime.ForeColor = Color.Gray;
                btnRecord.Text             = "Record";
                btnPreview.Enabled         = true;
            }
        }