protected override void Execute(CodeActivityContext context) { try { string inputFilePath = InputFilePath.Get(context); string outputFilePath = OutputFilePath.Get(context); string key = Key.Get(context); Encoding keyEncoding = KeyEncoding.Get(context); if (string.IsNullOrWhiteSpace(inputFilePath)) { throw new ArgumentNullException(Resources.InputFilePathDisplayName); } if (string.IsNullOrWhiteSpace(outputFilePath)) { throw new ArgumentNullException(Resources.OutputFilePathDisplayName); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(Resources.Key); } if (keyEncoding == null) { throw new ArgumentNullException(Resources.Encoding); } if (!File.Exists(inputFilePath)) { throw new ArgumentException(Resources.FileDoesNotExistsException, Resources.InputFilePathDisplayName); } // Because we use File.WriteAllText below, we don't need to delete the file now. if (File.Exists(outputFilePath) && !Overwrite) { throw new ArgumentException(Resources.FileAlreadyExistsException, Resources.OutputFilePathDisplayName); } byte[] encrypted = File.ReadAllBytes(inputFilePath); byte[] decrypted = null; try { decrypted = CryptographyHelper.DecryptData(Algorithm, encrypted, keyEncoding.GetBytes(key)); } catch (CryptographicException ex) { throw new InvalidOperationException(Resources.GenericCryptographicException, ex); } // This overwrites the file if it already exists. File.WriteAllBytes(outputFilePath, decrypted); } catch (Exception ex) { Trace.TraceError(ex.ToString()); if (!ContinueOnError.Get(context)) { throw; } } }
protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken) { // Inputs var timeout = TimeoutMS.Get(context); var imagefilepath = ImageFilePath.Get(context); var outputfilepath = OutputFilePath.Get(context); if (!File.Exists(imagefilepath)) { throw new FileNotFoundException(Resources.GenerateWallpaperWithImageFile_ImageFilePath_DisplayName); } if (!Directory.Exists(Path.GetDirectoryName(imagefilepath))) { throw new ArgumentException(string.Format(Resources.ValidationValueFullPath_Error, Resources.GenerateWallpaperWithImageFile_ImageFilePath_DisplayName)); } if (!Directory.Exists(Path.GetDirectoryName(outputfilepath))) { throw new ArgumentException(string.Format(Resources.ValidationValueFullPath_Error, Resources.GenerateWallpaperWithImageFile_OutputFilePath_DisplayName)); } // Set a timeout on the execution var task = ExecuteWithTimeout(context, cancellationToken); if (await Task.WhenAny(task, Task.Delay(timeout, cancellationToken)) != task) { throw new TimeoutException(Resources.Timeout_Error); } // Outputs return((ctx) => { Result.Set(ctx, task.Result); }); }
/// <summary> /// Checks whether the binary output paths are appropriate for the distribution /// level of its direct module dependencies /// </summary> public bool CheckRestrictedFolders(DirectoryReference ProjectDir, Dictionary <UEBuildModule, Dictionary <RestrictedFolder, DirectoryReference> > ModuleRestrictedFolderCache) { // Find all the modules we depend on Dictionary <UEBuildModule, UEBuildModule> ModuleReferencedBy = new Dictionary <UEBuildModule, UEBuildModule>(); FindModuleReferences(ModuleReferencedBy); // Loop through each of the output binaries and check them separately bool bResult = true; foreach (FileReference OutputFilePath in OutputFilePaths) { // Find the base directory for this binary DirectoryReference BaseDir; if (OutputFilePath.IsUnderDirectory(UnrealBuildTool.EngineDirectory)) { BaseDir = UnrealBuildTool.EngineDirectory; } else if (ProjectDir != null && OutputFilePath.IsUnderDirectory(ProjectDir)) { BaseDir = ProjectDir; } else { continue; } // Find the restricted folders under the base directory List <RestrictedFolder> BinaryFolders = RestrictedFolders.FindRestrictedFolders(BaseDir, OutputFilePath.Directory); // Check all the dependent modules foreach (UEBuildModule Module in ModuleReferencedBy.Keys) { // Find the restricted folders for this module Dictionary <RestrictedFolder, DirectoryReference> ModuleRestrictedFolders; if (!ModuleRestrictedFolderCache.TryGetValue(Module, out ModuleRestrictedFolders)) { ModuleRestrictedFolders = Module.FindRestrictedFolderReferences(ProjectDir); ModuleRestrictedFolderCache.Add(Module, ModuleRestrictedFolders); } // Write errors for any missing paths in the output files foreach (KeyValuePair <RestrictedFolder, DirectoryReference> Pair in ModuleRestrictedFolders) { if (!BinaryFolders.Contains(Pair.Key)) { List <string> ReferenceChain = new List <string>(); for (UEBuildModule ReferencedModule = Module; ReferencedModule != null; ReferencedModule = ModuleReferencedBy[ReferencedModule]) { ReferenceChain.Insert(0, ReferencedModule.Name); } Log.TraceError("ERROR: Output binary \"{0}\" is not in a {1} folder, but references \"{2}\" via {3}.", OutputFilePath, Pair.Key.ToString(), Pair.Value, String.Join(" -> ", ReferenceChain)); bResult = false; } } } } return(bResult); }
internal static string CreateArgumentString(InputFilePath inputArgument, OutputFilePath outputArgument, params IArgument[] arguments) { var input = inputArgument.ToStringRepresentation(); var output = outputArgument.ToStringRepresentation(); var stringArgs = arguments.Select(a => a.ToStringRepresentation()).ToArray(); return(input + " " + string.Join(" ", stringArgs) + " " + output); }
public async Task <int> Convert(string input, string output, params IArgument[] arguments) { var inputArg = new InputFilePath(input); var outputArg = new OutputFilePath(output); var args = ArgumentHelper.CreateArgumentString(inputArg, outputArg, arguments); return(await Convert(args)); }
public override int GetHashCode() { unchecked { int hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (DicomFilePath != null ? DicomFilePath.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (int)Status; hashCode = (hashCode * 397) ^ (OutputFilePath != null ? OutputFilePath.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (StatusMessage != null ? StatusMessage.GetHashCode() : 0); return(hashCode); } }
private async Task <bool> ExecuteWithTimeout(AsyncCodeActivityContext context, CancellationToken cancellationToken = default) { var text = Text.Get(context); var fontsize = FontSize.Get(context); var fontname = FontName.Get(context); var outputfilepath = OutputFilePath.Get(context); return(await Task.FromResult(new WallpaperGenerater().GenerateWallPaperFromSolidColor(BackGroundColor, TextColor, text, fontsize, fontname, outputfilepath))); }
public void Validate() { if (!File.Exists(InputFilePath)) { throw new ArgumentException("Input file does not exist"); } if (OutputFilePath.EndsWith('/') || OutputFilePath.EndsWith('\\')) { throw new ArgumentException("Output file must be a file path not directory."); } if (ColumnsToMask.Count() == 0) { throw new ArgumentException("Column cannot be empty."); } }
private void CreateOutputDirectoryIfNotExists() { if (OutputFilePath == null || OutputPipeDescriptor != null) { return; } try { if (!Directory.Exists(Path.GetDirectoryName(OutputFilePath.Unescape()))) { Directory.CreateDirectory(Path.GetDirectoryName(OutputFilePath.Unescape())); } } catch (System.IO.IOException e) { } }
/// <summary> /// Called to allow the binary to modify the link environment of a different binary containing /// a module that depends on a module in this binary. /// </summary> /// <param name="DependentLinkEnvironment">The link environment of the dependency</param> public void SetupDependentLinkEnvironment(LinkEnvironment DependentLinkEnvironment) { // Cache the list of libraries in the dependent link environment between calls. We typically run this code path many times for each module. if (DependentLinkLibraries == null) { DependentLinkLibraries = new List <string>(); foreach (FileReference OutputFilePath in OutputFilePaths) { FileReference LibraryFileName; if (Type == UEBuildBinaryType.StaticLibrary || DependentLinkEnvironment.Platform == CppPlatform.Mac || DependentLinkEnvironment.Platform == CppPlatform.Linux) { LibraryFileName = OutputFilePath; } else { LibraryFileName = FileReference.Combine(IntermediateDirectory, OutputFilePath.GetFileNameWithoutExtension() + ".lib"); } DependentLinkLibraries.Add(LibraryFileName.FullName); } } DependentLinkEnvironment.AdditionalLibraries.AddRange(DependentLinkLibraries); }
/// <summary> /// Called to allow the binary to modify the link environment of a different binary containing /// a module that depends on a module in this binary. /// </summary> /// <param name="DependentLinkEnvironment">The link environment of the dependency</param> public override void SetupDependentLinkEnvironment(LinkEnvironment DependentLinkEnvironment) { // Cache the list of libraries in the dependent link environment between calls. We typically run this code path many times for each module. if (DependentLinkLibraries == null) { DependentLinkLibraries = new List <string>(); foreach (FileReference OutputFilePath in Config.OutputFilePaths) { FileReference LibraryFileName; if (Config.Type == UEBuildBinaryType.StaticLibrary || DependentLinkEnvironment.Config.Platform == CPPTargetPlatform.Mac || DependentLinkEnvironment.Config.Platform == CPPTargetPlatform.Linux) { LibraryFileName = OutputFilePath; } else { LibraryFileName = FileReference.Combine(Config.IntermediateDirectory, OutputFilePath.GetFileNameWithoutExtension() + ".lib"); } DependentLinkLibraries.Add(LibraryFileName.FullName); } } DependentLinkEnvironment.Config.AdditionalLibraries.AddRange(DependentLinkLibraries); // If we're linking against static library containing the launch module on windows, we need to add the compiled resource separately. We can't link it through the static library. if (Config.Type == UEBuildBinaryType.StaticLibrary && Modules.Any(x => x.Name == "Launch") && (Target.Platform == UnrealTargetPlatform.Win32 || Target.Platform == UnrealTargetPlatform.Win64)) { FileReference ResourceFileRef = FileReference.Combine(Config.IntermediateDirectory, "Launch", "PCLaunch.rc.res"); DependentLinkEnvironment.InputFiles.Add(FileItem.GetItemByFileReference(ResourceFileRef)); } }
private static void ProcessArguments(string[] args) { InputFilePath = args[0]; string pathWithoutFile = Path.GetDirectoryName(InputFilePath); string fileWithoutPath = Path.GetFileName(InputFilePath); bool hasThreeSizes = false; if (string.IsNullOrEmpty(pathWithoutFile)) { pathWithoutFile = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); } else if (!Directory.Exists(pathWithoutFile)) { Directory.CreateDirectory(pathWithoutFile); } InputFilePath = pathWithoutFile + "//" + fileWithoutPath; OutputFilePath = args.Last(); if (!Directory.Exists(OutputFilePath) && !File.Exists(OutputFilePath)) { OutputFilePath = pathWithoutFile + "\\" + OutputFilePath; if (!File.Exists(OutputFilePath)) { File.Create(OutputFilePath); } } if (!OutputFilePath.EndsWith(".csv")) { OutputFilePath += ".csv"; } ContainerWidth = Int32.Parse(args[1]); ContainerHeight = Int32.Parse(args[2]); int tmpDepth; if (Int32.TryParse(args[3], out tmpDepth)) { ContainerDepth = tmpDepth; hasThreeSizes = true; } Properties = new AlgorithmProperties(); if (hasThreeSizes) { if (args.Count() > 5 && arguments.Contains(args[4])) { RecognizePair(args[4], args[5]); } if (args.Count() > 7 && arguments.Contains(args[6])) { RecognizePair(args[6], args[7]); } if (args.Count() > 9 && arguments.Contains(args[8])) { RecognizePair(args[8], args[9]); } if (args.Count() > 11 && arguments.Contains(args[10])) { RecognizePair(args[10], args[11]); } } else { if (args.Count() > 4 && arguments.Contains(args[3])) { RecognizePair(args[3], args[4]); } if (args.Count() > 6 && arguments.Contains(args[5])) { RecognizePair(args[5], args[6]); } if (args.Count() > 8 && arguments.Contains(args[7])) { RecognizePair(args[7], args[8]); } if (args.Count() > 10 && arguments.Contains(args[9])) { RecognizePair(args[9], args[10]); } } }
public void ConstructorShouldPass(string inputFilePath, string outputFilePath) { OutputFilePath path = new OutputFilePath(inputFilePath); Assert.That(path.Value, Is.EqualTo(outputFilePath)); }