protected void _btnAddJob_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(_cmbSourceFiles.Text)) { return; } if (string.IsNullOrEmpty(_cmbConversionProfile.Text)) { return; } MultimediaData multimediaData = new MultimediaData(_cmbSourceFiles.Text, _outputFilesUrl, File.ReadAllBytes(_cmbConversionProfile.SelectedItem.Value), _cmbConversionProfile.SelectedItem.Text); // Add new job. AddJobRequest AddJobRequest = new AddJobRequest(); AddJobRequest.UserToken = _hiddenFieldClientMetadata.Value; AddJobRequest.JobMetadata = MultimediaData.SerializeToString(multimediaData); AddJobRequest.JobType = "Multimedia"; AddJobResponse addJobResponse = _jobService.AddJob(AddJobRequest); GetJobInformationRequest getJobInfoRequest = new GetJobInformationRequest(); getJobInfoRequest.ID = addJobResponse.Id; GetJobInformationResponse getJobInfoResponse = _jobService.GetJobInformation(getJobInfoRequest); AddJobToGridView(getJobInfoResponse.JobInformation); GetClientJobs(); }
private void ConvertFile(MultimediaData multimediaData) { try { //Set up the conversion control and start the conversion convertCtrl = new ConvertCtrl(true); if (!File.Exists(multimediaData.SourceFile)) { SetFailureStatus(_jobId, (int)RasterExceptionCode.FileNotFound, Leadtools.RasterException.GetCodeMessage(RasterExceptionCode.FileNotFound), null); return; } convertCtrl.TargetFile = String.Empty; convertCtrl.SourceFile = multimediaData.SourceFile; // MultimediaData.ConversionSettings contains all of the predefined conversion settings (format, compression, etc). using (MemoryStream memoryStream = new MemoryStream(multimediaData.ConversionSettings)) convertCtrl.LoadSettingsFromStream(memoryStream, ConvertSettings.All); convertCtrl.TargetFile = BuildOutputFile(multimediaData, convertCtrl.TargetFormat); convertCtrl.StartConvert(); while (convertCtrl.State != ConvertState.Stopped) { //Pump messages so progress is updated System.Windows.Forms.Application.DoEvents(); Thread.Sleep(1); } if (conversionAborted) { //if job was already aborted, no need to continue. return; } //Job complete. Check if an error occured during conversion if (convertCtrl.ConvertError != 0) { throw new Exception(convertCtrl.ConvertError.ToString()); } //conversion success. Set completed status unless job was aborted //Update metadata since it contains the updated targetfile multimediaData.TargetFile = convertCtrl.TargetFile; if (UpdatePercentage(_jobId, 100, String.Empty)) { SetCompletedStatus(_jobId, MultimediaData.SerializeToString(multimediaData)); } else { AbortJob(); } } catch (COMException ex) { SetFailureStatus(_jobId, ex.ErrorCode, ex.Message, null); } catch (Exception ex) { SetFailureStatus(_jobId, 0, ex.Message, null); } finally { if (convertCtrl != null) { convertCtrl.Dispose(); } } }
private void _btnMMAddJob_Click(object sender, EventArgs e) { //Validate conversion profile if (_cmbMMConversionProfile.SelectedIndex == -1) { MessageBox.Show("You must select a conversion profile", "Invalid Profile"); return; } try { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Multiselect = true; ofd.Filter = "Video Files (*.avi;*.mpg;*.mpeg;*.mxf;*.mkv;*.ogg;*.wmv.*.asf;*.qt;*.mov;*.m2v;*.m1v;*.ts;*.m2ts;*.mp4;*.3gp;*.flv;*.f4v;video_ts.ifo;*.LBL)|*.avi;*.mpg;*.mpeg;*.mxf;*.mkv;*.ogg;*.wmv.*.asf;*.qt;*.mov;*.m2v;*.m1v;*.ts;*.m2ts;*.mp4;*.3gp;*.flv;*.f4v;video_ts.ifo;*.LBL|Audio files (*.wav;*.wma;*.ogg;*.mpa;*.mp2;*.mp3;*.mxf;*.mkv;*.au;*.aif;*.aiff;*.snd;*.aac)|*.wav;*.wma;*.ogg;*.mpa;*.mp2;*.mp3;*.mxf;*.mkv;*.au;*.aif;*.aiff;*.snd;*.aac|MPEG Files (*.mpg;*.mpeg;*.m2v;*.m1v;*.ts;*.m2ts)|*.mpg;*.mpeg;*.m2v;*.m1v;*.ts;*.m2ts|MXF Files (*.mxf)|*.mxf|MKV Files (*.mkv)|*.mkv|Windows Media Files (*.asf;*.wma;*.wmv)|*.asf;*.wma;*.wmv|DVD Files (video_ts.ifo)|video_ts.ifo|All Files (*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { List <AddJobRequest> addJobRequestList = new List <AddJobRequest>(ofd.FileNames.Length); foreach (string file in ofd.FileNames) { //Create output directory. string outputDirectory = Path.Combine(Path.GetDirectoryName(file), "Dashboard Output"); if (!Directory.Exists(outputDirectory)) { try { Directory.CreateDirectory(outputDirectory); } catch { outputDirectory = Path.GetDirectoryName(file); } } //Create job metadata MultimediaData multimediaData = new MultimediaData(file, outputDirectory, File.ReadAllBytes((string)_cmbMMConversionProfile.SelectedValue), _cmbMMConversionProfile.Text); AddJobRequest addJobRequest = new AddJobRequest(); addJobRequest.UserToken = _userName; addJobRequest.JobMetadata = MultimediaData.SerializeToString(multimediaData); addJobRequest.JobType = "Multimedia"; addJobRequestList.Add(addJobRequest); } using (JobServiceClient jobService = new JobServiceClient()) { //Add jobs as a batch jobService.Endpoint.Address = new System.ServiceModel.EndpointAddress(string.Format("{0}/JobService.svc", _wcfAddress)); AddJobsRequest addJobsRequest = new AddJobsRequest(); addJobsRequest.AddRange(addJobRequestList); jobService.AddJobs(addJobsRequest); } MessageBox.Show("Job added successfully", "Success"); GetClientJobs(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }