private void DoMenuProcessGeneric()
        {
            List<IAsset> SelectedAssets = ReturnSelectedAssets();

            if (SelectedAssets.Count == 0)
            {
                MessageBox.Show("No asset was selected");
                return;
            }

            if (SelectedAssets.FirstOrDefault() == null)
            {
                MessageBox.Show("No asset was selected");
                return;
            }

            string taskname = Constants.NameconvProcessorname + " processing of " + Constants.NameconvInputasset;

            MultipleProcessor form = new MultipleProcessor(_context)
            {
                EncodingProcessorsList = _context.MediaProcessors.ToList().OrderBy(p => p.Vendor).ThenBy(p => p.Name).ThenBy(p => new Version(p.Version)).ToList(),
                EncodingJobName = Constants.NameconvProcessorname + " processing of " + Constants.NameconvInputasset,
                EncodingOutputAssetName = Constants.NameconvInputasset + " - " + Constants.NameconvProcessorname + " processed",
                SelectedAssets = SelectedAssets,
                VisibleAssets = dataGridViewAssetsV.assets,
                EncodingCreationMode = TaskJobCreationMode.SingleJobForAllInputAssets
            };

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var gentasks = form.GetGenericTasks;

                if (form.EncodingCreationMode == TaskJobCreationMode.OneJobPerInputAsset || form.EncodingCreationMode == TaskJobCreationMode.OneJobPerVisibleAsset)
                // a job for each input asset
                {
                    if (form.EncodingCreationMode == TaskJobCreationMode.OneJobPerVisibleAsset)
                    {
                        SelectedAssets = dataGridViewAssetsV.assets.ToList();
                    }

                    foreach (IAsset asset in SelectedAssets)
                    {
                        string jobnameloc = form.EncodingJobName.Replace(Constants.NameconvInputasset, asset.Name).Replace(Constants.NameconvProcessorname, gentasks.Count > 1 ? "multi processors" : gentasks.FirstOrDefault().Processor.Name); ;
                        IJob job = _context.Jobs.Create(jobnameloc, form.JobPriority);

                        foreach (var usertask in gentasks)
                        // let's create all tasks and output assets
                        {

                            string assetname = string.Empty;
                            switch (usertask.InputAssetType)
                            {
                                case TypeInputAssetGeneric.InputJobAssets:
                                    assetname = asset.Name;
                                    break;
                                case TypeInputAssetGeneric.SpecificAssetID:
                                    assetname = AssetInfo.GetAsset(usertask.InputAsset, _context).Name;
                                    break;
                                case TypeInputAssetGeneric.TaskOutputAsset:
                                    assetname = "output of task#" + usertask.InputAsset;
                                    break;
                            }
                            string tasknameloc = taskname.Replace(Constants.NameconvInputasset, assetname).Replace(Constants.NameconvProcessorname, usertask.Processor.Name);
                            ITask task = job.Tasks.AddNew(
                                  tasknameloc,
                                 usertask.Processor,
                                 usertask.ProcessorConfiguration,
                                 usertask.TaskOptions.TasksOptionsSetting// form.JobOptions.TasksOptionsSetting
                                 );
                            task.Priority = usertask.TaskOptions.Priority;

                            string outputassetnameloc = form.EncodingOutputAssetName.Replace(Constants.NameconvInputasset, assetname).Replace(Constants.NameconvProcessorname, usertask.Processor.Name);
                            task.OutputAssets.AddNew(outputassetnameloc, usertask.TaskOptions.StorageSelected, usertask.TaskOptions.OutputAssetsCreationOptions);
                        }
                        // let(s branch the input assets
                        foreach (var usertask in gentasks)
                        {
                            switch (usertask.InputAssetType)
                            {
                                case TypeInputAssetGeneric.InputJobAssets:
                                    job.Tasks[gentasks.IndexOf(usertask)].InputAssets.Add(asset);
                                    break;
                                case TypeInputAssetGeneric.SpecificAssetID:
                                    job.Tasks[gentasks.IndexOf(usertask)].InputAssets.Add(AssetInfo.GetAsset(usertask.InputAsset, _context));
                                    break;
                                case TypeInputAssetGeneric.TaskOutputAsset:
                                    var oasset = job.Tasks[Convert.ToInt16(usertask.InputAsset)].OutputAssets;
                                    job.Tasks[gentasks.IndexOf(usertask)].InputAssets.AddRange(oasset);
                                    break;
                            }
                        }

                        TextBoxLogWriteLine("Submitting encoding job '{0}'", jobnameloc);
                        // Submit the job and wait until it is completed. 
                        try
                        {
                            job.Submit();
                        }
                        catch (Exception e)
                        {
                            // Add useful information to the exception
                            if (SelectedAssets.Count < 5)
                            {
                                MessageBox.Show(string.Format("There has been a problem when submitting the job '{0}'", jobnameloc) + Constants.endline + Constants.endline + Program.GetErrorMessage(e), "Job Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            TextBoxLogWriteLine("There has been a problem when submitting the job {0}.", jobnameloc, true);
                            TextBoxLogWriteLine(e);
                            return;
                        }
                        dataGridViewJobsV.DoJobProgress(job);
                    }
                }
                else if (form.EncodingCreationMode == TaskJobCreationMode.SingleJobForAllInputAssets) // Create one job for all inp
                {
                    string inputasssetname = SelectedAssets.Count == 1 ? SelectedAssets.FirstOrDefault().Name : "multiple assets";
                    string jobnameloc = form.EncodingJobName.Replace(Constants.NameconvInputasset, inputasssetname).Replace(Constants.NameconvProcessorname, gentasks.Count > 1 ? "multi processors" : gentasks.FirstOrDefault().Processor.Name); ;

                    IJob job = _context.Jobs.Create(jobnameloc, form.JobPriority);

                    foreach (var usertask in gentasks)
                    // let's create all tasks and output assets
                    {
                        string assetname = string.Empty;
                        switch (usertask.InputAssetType)
                        {
                            case TypeInputAssetGeneric.InputJobAssets:
                                assetname = inputasssetname;
                                break;
                            case TypeInputAssetGeneric.SpecificAssetID:
                                assetname = AssetInfo.GetAsset(usertask.InputAsset, _context).Name;
                                break;
                            case TypeInputAssetGeneric.TaskOutputAsset:
                                assetname = "output of task#" + usertask.InputAsset;
                                break;
                        }
                        string tasknameloc = taskname.Replace(Constants.NameconvInputasset, assetname).Replace(Constants.NameconvProcessorname, usertask.Processor.Name);

                        ITask task = job.Tasks.AddNew(
                            tasknameloc,
                           usertask.Processor,
                           usertask.ProcessorConfiguration,
                           usertask.TaskOptions.TasksOptionsSetting
                           );

                        task.Priority = usertask.TaskOptions.Priority;
                        string outputassetnameloc = form.EncodingOutputAssetName.Replace(Constants.NameconvInputasset, assetname).Replace(Constants.NameconvProcessorname, usertask.Processor.Name);
                        task.OutputAssets.AddNew(outputassetnameloc, usertask.TaskOptions.StorageSelected, usertask.TaskOptions.OutputAssetsCreationOptions);
                    }
                    // let(s branch the input assets
                    foreach (var usertask in gentasks)
                    {
                        switch (usertask.InputAssetType)
                        {
                            case TypeInputAssetGeneric.InputJobAssets:
                                job.Tasks[gentasks.IndexOf(usertask)].InputAssets.AddRange(SelectedAssets);
                                break;
                            case TypeInputAssetGeneric.SpecificAssetID:
                                job.Tasks[gentasks.IndexOf(usertask)].InputAssets.Add(AssetInfo.GetAsset(usertask.InputAsset, _context));
                                break;
                            case TypeInputAssetGeneric.TaskOutputAsset:
                                var oasset = job.Tasks[Convert.ToInt16(usertask.InputAsset) - 1].OutputAssets;
                                job.Tasks[gentasks.IndexOf(usertask)].InputAssets.AddRange(oasset);
                                break;
                        }
                    }

                    TextBoxLogWriteLine("Submitting encoding job '{0}'", jobnameloc);
                    // Submit the job and wait until it is completed. 
                    try
                    {
                        job.Submit();
                    }
                    catch (Exception e)
                    {
                        // Add useful information to the exception
                        MessageBox.Show(string.Format("There has been a problem when submitting the job '{0}'", jobnameloc) + Constants.endline + Constants.endline + Program.GetErrorMessage(e), "Job Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        TextBoxLogWriteLine("There has been a problem when submitting the job {0}.", jobnameloc, true);
                        TextBoxLogWriteLine(e);
                        return;
                    }
                    dataGridViewJobsV.DoJobProgress(job);

                }
                DotabControlMainSwitch(Constants.TabJobs);
                DoRefreshGridJobV(false);
            }
        }
        private void DoJobResubmit()
        {
            List<IJob> SelectedJobs = ReturnSelectedJobs();

            if (SelectedJobs.Count == 0)
            {
                MessageBox.Show("No job was selected");
                return;
            }
            else if (SelectedJobs.Count > 1)
            {
                MessageBox.Show("Please select one job only");
                return;
            }

            if (SelectedJobs.FirstOrDefault() == null)
            {
                MessageBox.Show("No job was selected");
                return;
            }
            IJob myJob = SelectedJobs.FirstOrDefault();

            if (myJob.Tasks.Count != 1)
            {
                MessageBox.Show("This feature works only with a job that contains a single task");
                return;
            }

            if (myJob.InputMediaAssets == null)
            {
                MessageBox.Show("No input assets !");
                return;
            }

            string taskname = myJob.Tasks.FirstOrDefault().Name;

            MultipleProcessor form = new MultipleProcessor(_context, myJob)
            {
                Text = "Job re-submission",
                EncodingProcessorsList = _context.MediaProcessors.ToList().OrderBy(p => p.Vendor).ThenBy(p => p.Name).ThenBy(p => new Version(p.Version)).ToList(),
                EncodingJobName = string.Format("{0} (resubmitted on {1})", myJob.Name, DateTime.Now.ToString()),
                EncodingOutputAssetName = string.Format("{0} (resubmitted on {1})", myJob.OutputMediaAssets.FirstOrDefault().Name, DateTime.Now.ToString()),
                SingleTaskOptions = new JobOptionsVar
                {
                    Priority = myJob.Tasks.FirstOrDefault().Priority,
                    OutputAssetsCreationOptions = myJob.Tasks.FirstOrDefault().OutputAssets.FirstOrDefault().Options,
                    StorageSelected = myJob.Tasks.FirstOrDefault().OutputAssets.FirstOrDefault().StorageAccountName,
                    TasksOptionsSetting = myJob.Tasks.FirstOrDefault().Options
                },
                EncodingCreationMode = TaskJobCreationMode.SingleJobForAllInputAssets,
                JobPriority = myJob.Priority
            };

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string inputasssetname = SelectedJobs.FirstOrDefault().InputMediaAssets.Count == 1 ? SelectedJobs.FirstOrDefault().InputMediaAssets.FirstOrDefault().Name : "multiple assets";
                string jobnameloc = form.EncodingJobName.Replace(Constants.NameconvInputasset, inputasssetname).Replace(Constants.NameconvProcessorname, form.SingleEncodingProcessorSelected.Name); ;

                IJob job = _context.Jobs.Create(jobnameloc, form.JobPriority);

                string tasknameloc = taskname.Replace(Constants.NameconvInputasset, inputasssetname).Replace(Constants.NameconvProcessorname, form.SingleEncodingProcessorSelected.Name);

                ITask task = job.Tasks.AddNew(
                            tasknameloc,
                           form.SingleEncodingProcessorSelected,
                           form.SingleEncodingConfiguration,
                           form.SingleTaskOptions.TasksOptionsSetting
                           );
                task.Priority = form.SingleTaskOptions.Priority;

                // Specify the graph asset to be encoded, followed by the input video asset to be used
                task.InputAssets.AddRange(myJob.InputMediaAssets.ToList());
                string outputassetnameloc = form.EncodingOutputAssetName.Replace(Constants.NameconvInputasset, inputasssetname).Replace(Constants.NameconvProcessorname, form.SingleEncodingProcessorSelected.Name);
                task.OutputAssets.AddNew(outputassetnameloc, form.SingleTaskOptions.StorageSelected, form.SingleTaskOptions.OutputAssetsCreationOptions);

                TextBoxLogWriteLine("Submitting encoding job '{0}'", jobnameloc);
                // Submit the job and wait until it is completed. 
                try
                {
                    job.Submit();
                }
                catch (Exception e)
                {
                    // Add useful information to the exception
                    MessageBox.Show(string.Format("There has been a problem when submitting the job '{0}'", jobnameloc) + Constants.endline + Constants.endline + Program.GetErrorMessage(e), "Job Error", MessageBoxButtons.OK, MessageBoxIcon.Error); TextBoxLogWriteLine("There has been a problem when submitting the job '{0}'", jobnameloc, true);
                    TextBoxLogWriteLine(e);
                    return;
                }
                dataGridViewJobsV.DoJobProgress(job);

                DoRefreshGridJobV(false);
            }
        }