コード例 #1
0
        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();
        }
コード例 #2
0
        private void _menuItemOpenConvertedFile_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow selectedJob in _dgvJobs.SelectedRows)
            {
                try
                {
                    if (selectedJob.Cells[JobProcessorConstants.Database.StatusColumn].Value != DBNull.Value &&
                        String.Compare((string)selectedJob.Cells[JobProcessorConstants.Database.StatusColumn].Value, JobStatus.Completed.ToString(), true) == 0)
                    {
                        string jobType     = selectedJob.Cells[JobProcessorConstants.Database.JobTypeColumn].Value != DBNull.Value ? (string)selectedJob.Cells[JobProcessorConstants.Database.JobTypeColumn].Value : String.Empty;
                        string jobMetadata = selectedJob.Cells[JobProcessorConstants.Database.JobMetadataColumn].Value != DBNull.Value ? (string)selectedJob.Cells[JobProcessorConstants.Database.JobMetadataColumn].Value : String.Empty;

                        if (String.Compare(jobType, "OCR", true) == 0)
                        {
                            StartProcess(OcrData.DeserializeFromString(jobMetadata).DocumentFileName);
                        }
                        else if (String.Compare(jobType, "Multimedia", true) == 0)
                        {
                            StartProcess(MultimediaData.DeserializeFromString(jobMetadata).TargetFile);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
        }
コード例 #3
0
ファイル: MyMultimediaJob.cs プロジェクト: sakpung/webstudy
        string BuildOutputFile(MultimediaData multimediaData, TargetFormatType targetFormat)
        {
            //Format the target file like <output directory>\<source filename>_<source file extension>_<Guid>.<new extension>
            string ext = Path.GetExtension(multimediaData.SourceFile);

            if (!string.IsNullOrEmpty(ext))
            {
                ext = ext.Replace(".", "");
            }

            if (!string.IsNullOrEmpty(ext))
            {
                ext = "_" + ext;
            }
            else
            {
                ext = string.Empty;
            }

            string name = Path.GetFileNameWithoutExtension(multimediaData.SourceFile);

            name = string.Format(
                "{0}{1}_{2}.{3}",
                name, ext, Guid.NewGuid(), GetExtension(targetFormat));

            string fullPath = string.Empty;

            // If the TargetFile is a file, this is a full path (from a previous conversion). In this case need, we to get the directory name and append the new file name.
            // We cannot check the file itself because it may no longer exist so we use the extension in the path to indicate if it is a file
            if (String.IsNullOrEmpty(Path.GetExtension(multimediaData.TargetFile)))
            {
                fullPath = multimediaData.TargetFile; //path is a directory
            }
            else
            {
                fullPath = Path.GetDirectoryName(multimediaData.TargetFile);//This is a file
            }
            if (!Directory.Exists(fullPath))
            {
                Directory.CreateDirectory(fullPath);
            }

            return(Path.Combine(fullPath, name));
        }
コード例 #4
0
ファイル: MyMultimediaJob.cs プロジェクト: sakpung/webstudy
        /***************************************************************************/
        /* This function will convert multimedia files based on the settings specified in MultimediaData.ConversionSettings*/
        /***************************************************************************/
        public override void OnJobReceived(string id, string clientMetadata, string jobMetadata, string jobType, int progressRate)
        {
            _jobId            = id;
            conversionAborted = false;
            AutoResetEvent finishedEvent = new AutoResetEvent(false);

            try
            {
                // Check if we have valid job information and job metadata
                if (String.IsNullOrEmpty(jobMetadata))
                {
                    SetFailureStatus(_jobId, (int)RasterExceptionCode.InvalidParameter, Leadtools.RasterException.GetCodeMessage(RasterExceptionCode.InvalidParameter), null);
                    return;
                }

                //Deserialize the jobMetadata so we can get the MultimediaData
                MultimediaData multimediaData = MultimediaData.DeserializeFromString(jobMetadata);
                _reportStatusInterval = progressRate * SECONDS_TO_MILLISECONDS_FACTOR;

                using (Timer updateStatusTimer = new Timer(new TimerCallback(UpdateStatusProc), multimediaData, 0, _reportStatusInterval))
                {
                    ConvertFile(multimediaData);
                }
            }
            catch (COMException ex)
            {
                SetFailureStatus(id, ex.ErrorCode, ex.Message, null);
            }
            catch (Exception ex)
            {
                SetFailureStatus(id, 0, ex.Message, null);
            }
            finally
            {
                finishedEvent.Close();
            }
        }
コード例 #5
0
ファイル: MyMultimediaJob.cs プロジェクト: sakpung/webstudy
        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();
                }
            }
        }
コード例 #6
0
        private void BindGrid(int rowcount, JobServiceReference.JobInformation jobInformation)
        {
            if (jobInformation == null)
            {
                return;
            }

            //Only show multimedia jobs in this demo
            if (String.Compare(jobInformation.JobType, "Multimedia", true) != 0)
            {
                return;
            }

            MultimediaData multimediaData = MultimediaData.DeserializeFromString(jobInformation.Metadata.JobMetadata);
            string         inputFileName  = multimediaData.SourceFile.Length > 0 ? Path.GetFileName(multimediaData.SourceFile) : String.Empty;
            string         outputFileName = jobInformation.Status == JobStatus.Completed && multimediaData.TargetFile.Length > 0 ? Path.GetFileName(multimediaData.TargetFile) : String.Empty;

            DataColumn[] dataColums = new DataColumn[]
            {
                new DataColumn("Job ID", typeof(string)),
                new DataColumn("Status", typeof(string)),
                new DataColumn("Worker", typeof(string)),
                new DataColumn("Percentage", typeof(int)),
                new DataColumn("Added Data/Time", Nullable.GetUnderlyingType(typeof(Nullable <DateTime>))),
                new DataColumn("Completed Data/Time", Nullable.GetUnderlyingType(typeof(Nullable <DateTime>))),
                new DataColumn("Error ID", typeof(int)),
                new DataColumn("Error Message", typeof(string)),
                new DataColumn("Input File", typeof(string)),
                new DataColumn("Output File", typeof(string)),
                new DataColumn("Full Path", typeof(string)),
                new DataColumn("Target Format", typeof(string)),
            };

            DataTable dt = new DataTable();

            dt.Columns.AddRange(dataColums);

            DataRow dr;

            if (ViewState["CurrentData"] != null)
            {
                for (int i = 0; i < rowcount; i++)
                {
                    dt = (DataTable)ViewState["CurrentData"];
                    if (dt.Rows.Count > 0)
                    {
                        dr    = dt.NewRow();
                        dr[0] = dt.Rows[i][0].ToString();
                        dr[1] = dt.Rows[i][1].ToString();
                        dr[2] = dt.Rows[i][2].ToString();
                        dr[3] = dt.Rows[i][3].ToString();
                        if (dt.Rows[i][3] != null)
                        {
                            dr[4] = dt.Rows[i][4];
                        }
                        else
                        {
                            dr[4] = DBNull.Value;
                        }

                        if (dt.Rows[i][4] != null)
                        {
                            dr[5] = dt.Rows[i][5];
                        }
                        else
                        {
                            dr[5] = DBNull.Value;
                        }
                        dr[6]  = dt.Rows[i][6].ToString();
                        dr[7]  = dt.Rows[i][7].ToString();
                        dr[8]  = dt.Rows[i][8].ToString();
                        dr[9]  = dt.Rows[i][9].ToString();
                        dr[10] = dt.Rows[i][10].ToString();
                        dr[11] = dt.Rows[i][11].ToString();
                    }
                }
                if (jobInformation != null)
                {
                    dr    = dt.NewRow();
                    dr[0] = jobInformation.ID;
                    dr[1] = jobInformation.Status;
                    dr[2] = jobInformation.Worker;
                    dr[3] = jobInformation.Percentage;
                    if (jobInformation.AddedTime != null)
                    {
                        dr[4] = jobInformation.AddedTime;
                    }
                    else
                    {
                        dr[4] = DBNull.Value;
                    }

                    if (jobInformation.CompletedTime != null)
                    {
                        dr[5] = jobInformation.CompletedTime;
                    }
                    else
                    {
                        dr[5] = DBNull.Value;
                    }
                    dr[6]  = jobInformation.FailureInformation.FailedErrorID;
                    dr[7]  = jobInformation.FailureInformation.FailedMessage;
                    dr[8]  = inputFileName;
                    dr[9]  = outputFileName;
                    dr[10] = _outputFilesName + outputFileName;
                    dr[11] = multimediaData.ProfileName;
                    dt.Rows.Add(dr);
                }
            }
            else
            {
                if (jobInformation != null)
                {
                    dr    = dt.NewRow();
                    dr[0] = jobInformation.ID;
                    dr[1] = jobInformation.Status;
                    dr[2] = jobInformation.Worker;
                    dr[3] = jobInformation.Percentage;
                    if (jobInformation.AddedTime != null)
                    {
                        dr[4] = jobInformation.AddedTime;
                    }
                    else
                    {
                        dr[4] = DBNull.Value;
                    }

                    if (jobInformation.CompletedTime != null)
                    {
                        dr[5] = jobInformation.CompletedTime;
                    }
                    else
                    {
                        dr[5] = DBNull.Value;
                    }
                    dr[6]  = jobInformation.FailureInformation.FailedErrorID;
                    dr[7]  = jobInformation.FailureInformation.FailedMessage;
                    dr[8]  = inputFileName;
                    dr[9]  = outputFileName;
                    dr[10] = _outputFilesName + outputFileName;
                    dr[11] = multimediaData.ProfileName;
                    dt.Rows.Add(dr);
                }
            }

            // If ViewState has a data then use the value as the DataSource
            if (ViewState["CurrentData"] != null)
            {
                _gridViewClientJobs.DataSource = (DataTable)ViewState["CurrentData"];
                _gridViewClientJobs.DataBind();
            }
            else
            {
                // Bind GridView with the initial data associated in the DataTable
                _gridViewClientJobs.DataSource = dt;
                _gridViewClientJobs.DataBind();
            }
            // Store the DataTable in ViewState to retain the values
            ViewState["CurrentData"] = dt;
        }
コード例 #7
0
        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");
            }
        }