Bloom.Edit.AudioRecording.HandleStartRecording C# (CSharp) Method

HandleStartRecording() public method

public HandleStartRecording ( ApiRequest request ) : void
request Bloom.Api.ApiRequest
return void
        public void HandleStartRecording(ApiRequest request)
        {
            #if __MonoCS__
                        MessageBox.Show("Recording does not yet work on Linux", "Cannot record");
                        return;
            #else
            if(Recording)
            {
                request.Failed("Already recording");
                return;
            }

            string segmentId = request.RequiredParam("id");
            PathToCurrentAudioSegment = GetPathToSegment(segmentId);
            PathToTemporaryWav = Path.GetTempFileName();

            if (Recorder.RecordingState == RecordingState.RequestedStop)
            {
                request.Failed(LocalizationManager.GetString("EditTab.Toolbox.TalkingBook.BadState",
                    "Bloom recording is in an unusual state, possibly caused by unplugging a microphone. You will need to restart.","This is very low priority for translation."));
            }

            // If someone unplugged the microphone we were planning to use switch to another.
            // This also triggers selecting the first one initially.
            if (!RecordingDevice.Devices.Contains(RecordingDevice))
            {
                RecordingDevice = RecordingDevice.Devices.FirstOrDefault();
            }
            if (RecordingDevice == null)
            {
                ReportNoMicrophone();
                request.Failed("No Microphone");
                return ;
            }

            if(Recording)
            {
                request.Failed( "Already Recording");
                return;
            }

            if (RobustFile.Exists(PathToCurrentAudioSegment))
            {
                //Try to deal with _backPath getting locked (BL-3160)
                try
                {
                    RobustFile.Delete(_backupPath);
                }
                catch(IOException)
                {
                    _backupPath = System.IO.Path.GetTempFileName();
                }
                try
                {
                    RobustFile.Copy(PathToCurrentAudioSegment, _backupPath, true);
                }
                catch (Exception err)
                {
                    ErrorReport.NotifyUserOfProblem(err,
                        "Bloom cold not copy "+PathToCurrentAudioSegment+" to "+_backupPath+" If things remains stuck, you may need to restart your computer.");
                    request.Failed( "Problem with backup file");
                    return;
                }
                try
                {
                    RobustFile.Delete(PathToCurrentAudioSegment);
                    //DesktopAnalytics.Analytics.Track("Re-recorded a clip", ContextForAnalytics);
                }
                catch (Exception err)
                {
                    ErrorReport.NotifyUserOfProblem(err,
                        "The old copy of the recording at " + PathToCurrentAudioSegment + " is locked up, so Bloom can't record over it at the moment. If it remains stuck, you may need to restart your computer.");
                    request.Failed( "Audio file locked");
                    return;
                }
            }
            else
            {
                RobustFile.Delete(_backupPath);
                //DesktopAnalytics.Analytics.Track("Recording clip", ContextForAnalytics);
            }
            _startRecording = DateTime.Now;
            _startRecordingTimer.Start();
            request.ReplyWithText("starting record soon");
            return;
            #endif
        }