Ejemplo n.º 1
0
        public void Export(IList <EncodeJobWithMetadata> jobs)
        {
            string initialFileName = "Queue";

            string exportFileName = this.fileService.GetFileNameSave(
                Config.RememberPreviousFiles ? Config.LastPresetExportFolder : null,
                MainRes.ExportQueueFilePickerText,
                FileUtilities.CleanFileName(initialFileName + ".vjqueue"),
                "vjqueue",
                CommonRes.QueueFileFilter + "|*.vjqueue");

            if (exportFileName != null)
            {
                if (Config.RememberPreviousFiles)
                {
                    Config.LastPresetExportFolder = Path.GetDirectoryName(exportFileName);
                }

                if (EncodeJobStorage.SaveQueueToFile(jobs, exportFileName))
                {
                    this.messageBoxService.Show(
                        string.Format(MainRes.QueueExportSuccessMessage, exportFileName),
                        CommonRes.Success,
                        System.Windows.MessageBoxButton.OK);
                }
            }
        }
        public async Task <string> GenerateUnitTestFileAsync(
            ProjectItemSummary selectedFile,
            EnvDTE.Project targetProject,
            TestFramework testFramework,
            MockFramework mockFramework)
        {
            string sourceProjectDirectory = Path.GetDirectoryName(selectedFile.ProjectFilePath);
            string selectedFileDirectory  = Path.GetDirectoryName(selectedFile.FilePath);

            if (sourceProjectDirectory == null || selectedFileDirectory == null || !selectedFileDirectory.StartsWith(sourceProjectDirectory, StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException("Error with selected file paths.");
            }

            string relativePath = this.GetRelativePath(selectedFile);

            TestGenerationContext context = await this.CollectTestGenerationContextAsync(selectedFile, targetProject, testFramework, mockFramework);

            string unitTestContents = this.GenerateUnitTestContents(context);

            string testFolder = Path.Combine(Path.GetDirectoryName(targetProject.FullName), relativePath);

            string testFileNameBase = StringUtilities.ReplaceTokens(
                this.Settings.FileNameTemplate,
                (tokenName, propertyIndex, builder) =>
            {
                if (WriteGlobalToken(tokenName, builder, context))
                {
                    return;
                }

                WriteTokenPassthrough(tokenName, builder);
            });

            testFileNameBase = FileUtilities.CleanFileName(testFileNameBase);

            string testPath = Path.Combine(testFolder, testFileNameBase + ".cs");

            if (File.Exists(testPath))
            {
                throw new InvalidOperationException("Test file already exists.");
            }

            if (!Directory.Exists(testFolder))
            {
                Directory.CreateDirectory(testFolder);
            }

            File.WriteAllText(testPath, unitTestContents);

            return(testPath);
        }
Ejemplo n.º 3
0
        public void ExportPreset(Preset preset)
        {
            var exportPreset = new Preset
            {
                EncodingProfile = preset.EncodingProfile.Clone(),
                IsBuiltIn       = false,
                IsModified      = false,
                IsQueue         = false,
                Name            = preset.Name
            };

            string initialFileName = exportPreset.Name;

            if (preset.IsModified)
            {
                initialFileName += "_Modified";
            }

            string exportFileName = this.fileService.GetFileNameSave(
                Config.RememberPreviousFiles ? Config.LastPresetExportFolder : null,
                MainRes.ExportPresetFilePickerText,
                FileUtilities.CleanFileName(initialFileName + ".vjpreset"),
                "vjpreset",
                CommonRes.PresetFileFilter + "|*.vjpreset");

            if (exportFileName != null)
            {
                if (Config.RememberPreviousFiles)
                {
                    Config.LastPresetExportFolder = Path.GetDirectoryName(exportFileName);
                }

                if (PresetStorage.SavePresetToFile(exportPreset, exportFileName))
                {
                    this.messageBoxService.Show(
                        string.Format(MainRes.PresetExportSuccessMessage, exportFileName),
                        CommonRes.Success,
                        System.Windows.MessageBoxButton.OK);
                }
            }
        }
Ejemplo n.º 4
0
 public string BuildOutputFileName(
     string sourcePath,
     string sourceName,
     int title,
     TimeSpan titleDuration,
     VideoRangeType rangeType,
     int startChapter,
     int endChapter,
     int totalChapters,
     TimeSpan startTime,
     TimeSpan endTime,
     int startFrame,
     int endFrame,
     string nameFormatOverride,
     bool multipleTitlesOnSource,
     Picker picker)
 {
     return(FileUtilities.CleanFileName(
                ReplaceArguments(sourcePath, sourceName, title, titleDuration, rangeType, startChapter, endChapter, totalChapters, startTime, endTime, startFrame, endFrame, nameFormatOverride, multipleTitlesOnSource, picker),
                allowBackslashes: true));
 }
Ejemplo n.º 5
0
        private static string GetJobDescriptionFromSourcePath(string sourcePath)
        {
            try
            {
                string fileNameCleaned;
                if (FileUtilities.IsDirectory(sourcePath))
                {
                    var info = new DirectoryInfo(sourcePath);
                    fileNameCleaned = FileUtilities.CleanFileName(info.Name);
                }
                else
                {
                    fileNameCleaned = Path.GetFileNameWithoutExtension(sourcePath);
                }

                return("Scan " + fileNameCleaned);
            }
            catch (Exception)
            {
                return("Scan");
            }
        }
Ejemplo n.º 6
0
        public string BuildOutputFileName(
            string sourcePath,
            string sourceName,
            int title,
            TimeSpan titleDuration,
            VideoRangeType rangeType,
            int startChapter,
            int endChapter,
            int totalChapters,
            TimeSpan startTime,
            TimeSpan endTime,
            int startFrame,
            int endFrame,
            string nameFormatOverride,
            bool multipleTitlesOnSource,
            Picker picker)
        {
            string fileName;

            if (picker == null)
            {
                picker = this.PickersService.SelectedPicker.Picker;
            }

            if (Config.AutoNameCustomFormat || !string.IsNullOrWhiteSpace(nameFormatOverride) || picker.NameFormatOverrideEnabled)
            {
                string rangeString = string.Empty;
                switch (rangeType)
                {
                case VideoRangeType.Chapters:
                    if (startChapter == endChapter)
                    {
                        rangeString = startChapter.ToString();
                    }
                    else
                    {
                        rangeString = startChapter + "-" + endChapter;
                    }

                    break;

                case VideoRangeType.Seconds:
                    rangeString = startTime.ToFileName() + "-" + endTime.ToFileName();
                    break;

                case VideoRangeType.Frames:
                    rangeString = startFrame + "-" + endFrame;
                    break;
                }

                if (!string.IsNullOrWhiteSpace(nameFormatOverride))
                {
                    fileName = nameFormatOverride;
                }
                else if (picker.NameFormatOverrideEnabled)
                {
                    fileName = picker.NameFormatOverride;
                }
                else
                {
                    fileName = Config.AutoNameCustomFormatString;
                }

                fileName = fileName.Replace("{source}", sourceName);
                fileName = ReplaceTitles(fileName, title);
                fileName = fileName.Replace("{range}", rangeString);

                fileName = fileName.Replace("{titleduration}", titleDuration.ToFileName());

                // {chapters} is deprecated in favor of {range} but we replace here for backwards compatibility.
                fileName = fileName.Replace("{chapters}", rangeString);

                fileName = fileName.Replace("{preset}", this.PresetsService.SelectedPreset.Preset.Name);
                fileName = ReplaceParents(fileName, sourcePath);

                DateTime now = DateTime.Now;
                if (fileName.Contains("{date}"))
                {
                    fileName = fileName.Replace("{date}", now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
                }

                if (fileName.Contains("{time}"))
                {
                    fileName = fileName.Replace("{time}", string.Format("{0:d2}.{1:d2}.{2:d2}", now.Hour, now.Minute, now.Second));
                }

                if (fileName.Contains("{quality}"))
                {
                    VCProfile profile = this.PresetsService.SelectedPreset.Preset.EncodingProfile;
                    double    quality = 0;
                    switch (profile.VideoEncodeRateType)
                    {
                    case VCVideoEncodeRateType.ConstantQuality:
                        quality = profile.Quality;
                        break;

                    case VCVideoEncodeRateType.AverageBitrate:
                        quality = profile.VideoBitrate;
                        break;

                    case VCVideoEncodeRateType.TargetSize:
                        quality = profile.TargetSize;
                        break;

                    default:
                        break;
                    }

                    fileName = fileName.Replace("{quality}", quality.ToString());
                }
            }
            else
            {
                string titleSection = string.Empty;
                if (multipleTitlesOnSource)
                {
                    titleSection = " - Title " + title;
                }

                string rangeSection = string.Empty;
                switch (rangeType)
                {
                case VideoRangeType.Chapters:
                    if (startChapter > 1 || endChapter < totalChapters)
                    {
                        if (startChapter == endChapter)
                        {
                            rangeSection = " - Chapter " + startChapter;
                        }
                        else
                        {
                            rangeSection = " - Chapters " + startChapter + "-" + endChapter;
                        }
                    }

                    break;

                case VideoRangeType.Seconds:
                    if (startTime > TimeSpan.Zero || (endTime < titleDuration && (titleDuration - endTime >= TimeSpan.FromSeconds(1) || endTime.Milliseconds != 0)))
                    {
                        rangeSection = " - " + startTime.ToFileName() + "-" + endTime.ToFileName();
                    }

                    break;

                case VideoRangeType.Frames:
                    rangeSection = " - Frames " + startFrame + "-" + endFrame;
                    break;
                }

                fileName = sourceName + titleSection + rangeSection;
            }

            return(FileUtilities.CleanFileName(fileName, allowBackslashes: true));
        }
Ejemplo n.º 7
0
        public void FileNameCleaning()
        {
            var result = FileUtilities.CleanFileName("helo / man * ( ) %@!");

            Assert.IsFalse(string.IsNullOrEmpty(result));
        }