/// <summary> /// Interprets the file discovery status. /// </summary> /// <param name="fileDiscoveryStatus">The file discovery status.</param> /// <returns></returns> public Message InterpretFileDiscoveryStatus(FileDiscoveryStatus fileDiscoveryStatus) { FileDiscoveryInfo fileDiscoveryInfo = fileDiscoveryStatus.AditionalData as FileDiscoveryInfo; return(new Message { Color = ConsoleOutputColor.Gray, Text = $@"Found file: { fileDiscoveryInfo.FileName }" }); }
/// <summary> /// Interprets the scripting status. /// </summary> /// <param name="scriptingStatus">The scripting status.</param> /// <returns></returns> public Message InterpretScriptingStatus(ScriptingStatus scriptingStatus) { FileDiscoveryInfo fileDiscoveryInfo = scriptingStatus.AditionalData as FileDiscoveryInfo; return(new Message { Color = ConsoleOutputColor.Blue, Text = $"[{ fileDiscoveryInfo.FileName }]: Finished compiling file." }); }
/// <summary> /// Executes the scripts asynchronously. /// </summary> /// <param name="scriptFileDiscoveryInfo">The script files discovery information.</param> /// <returns></returns> public async Task ExecuteScriptAsync(FileDiscoveryInfo scriptFileDiscoveryInfo) { Script script = await this.scriptLoaderService.LoadScript(scriptFileDiscoveryInfo.FullFileName).ConfigureAwait(false); this.NotifyObservers(ScriptingStatusDescription.BeginScriptExecute, script.GetScriptExecuteInfo()); try { await CSharpScript.EvaluateAsync(script.Content).ConfigureAwait(false); this.NotifyObservers(ScriptingStatusDescription.SuccessScriptExecute, script.GetScriptExecuteInfo()); } catch (Exception ex) { ScriptExecuteInfo otherErrorScriptExecuteInfo = script.GetScriptExecuteInfo(); otherErrorScriptExecuteInfo.ThrownException = ex; this.NotifyObservers(ScriptingStatusDescription.FailScriptExecute, otherErrorScriptExecuteInfo); } this.NotifyObservers(ScriptingStatusDescription.FinalizeScriptExecute, script.GetScriptExecuteInfo()); }
/// <summary> /// Discovers the files. /// </summary> /// <param name="directoryInfo">The directory information.</param> /// <returns></returns> private IEnumerable <FileDiscoveryInfo> DiscoverFiles(DirectoryInfo directoryInfo) { IEnumerable <FileDiscoveryInfo> fileDiscoveryInfos = new List <FileDiscoveryInfo>(0); IEnumerable <FileInfo> files = directoryInfo.EnumerateFiles(this.fileSearchPattern); List <FileDiscoveryInfo> currentFileDiscoveryInfos = new List <FileDiscoveryInfo>(0); // Discover files. foreach (var file in files) { var fileDiscoveryInfo = new FileDiscoveryInfo { FullFileName = file.FullName, FileName = file.Name }; currentFileDiscoveryInfos.Add(fileDiscoveryInfo); this.NotifyObservers(FileDiscoveryStatusDescription.FoundFile, fileDiscoveryInfo); } // Concat file paths to return if any. if (currentFileDiscoveryInfos.Any()) { fileDiscoveryInfos = fileDiscoveryInfos.Concat(currentFileDiscoveryInfos); } IEnumerable <DirectoryInfo> subdirectories = directoryInfo.EnumerateDirectories(); // Invoke discovery on subdirectories. foreach (var subdirectory in subdirectories) { IEnumerable <FileDiscoveryInfo> subdirectoryFileDiscoveryInfos = this.DiscoverFiles(subdirectory); fileDiscoveryInfos = fileDiscoveryInfos.Concat(subdirectoryFileDiscoveryInfos); } return(fileDiscoveryInfos); }