/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); if (String.IsNullOrEmpty(ImagePath)) { ImagePath = DEFAULT_IMAGE_PATH; } ImagePath = ImagePath.TrimEnd('/') + "/"; if (String.IsNullOrEmpty(CSSPath)) { CSSPath = DEFAULT_CSS_PATH; } CSSPath = CSSPath.TrimEnd('/') + "/"; if (String.IsNullOrEmpty(ScriptPath)) { ScriptPath = DEFAULT_JS_PATH; } ScriptPath = ScriptPath.TrimEnd('/') + "/"; _status = UploadManager.Instance.Status; UploadManager.Instance.Status = null; }
public void Run(ScriptPath[] srcs) { int maxtasks=TAPApp.MaxTasks; TAPApp.VLog(3,"Max. {0} {1}.",maxtasks,maxtasks==1?"task":"parallel tasks"); int k=0; bool single=srcs.Length==1; do { bool waiting=k!=srcs.Length; int running=CountRunningTasks(); if(!waiting && running==0) TAPParser.EndTotal(); ReapHead(); if(waiting) { running=CountRunningTasks(); while(running<maxtasks) { if(k!=srcs.Length) { AddTask(srcs[k],single); ++k; ++running; } else { break; } } } if(Tasks.Count==0) break; TaskDone.WaitOne(); } while(true); TAPApp.DLog(3,"TaskMgr done."); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (ScriptFilename != null) { hashCode = hashCode * 59 + ScriptFilename.GetHashCode(); } if (ScriptDisplay != null) { hashCode = hashCode * 59 + ScriptDisplay.GetHashCode(); } if (ScriptPath != null) { hashCode = hashCode * 59 + ScriptPath.GetHashCode(); } if (ScriptPlatform != null) { hashCode = hashCode * 59 + ScriptPlatform.GetHashCode(); } if (Interval != null) { hashCode = hashCode * 59 + Interval.GetHashCode(); } if (Jmxdomain != null) { hashCode = hashCode * 59 + Jmxdomain.GetHashCode(); } return(hashCode); } }
void AddTask(ScriptPath sp,bool single) { TAPApp.DLog(3,"Add task {0}",sp); var task=new Task(TaskDone,Client,sp,single); if(Tasks.Count==0) task.Head=true; task.Run(); Tasks.Enqueue(task); }
/// <summary> /// Implement the ICloneable interface /// </summary> /// <returns></returns> public object Clone() { WSHScript clone = new WSHScript(); clone.Name = Name.Clone() as string; clone.ScriptPath = ScriptPath.Clone() as string; clone.Parameters = Parameters.Clone() as string; clone.Timeout = Timeout; return(clone); }
/// <summary> /// Receives our own property change events to update IsValid. /// </summary> void StandaloneTargetView_PropertyChanged(object sender, PropertyChangedEventArgs e) { Debug.Assert(sender == this); if (e.PropertyName != "IsValid") { IsValid = ScriptPath.IndexOfAny(Path.GetInvalidPathChars()) == -1 && WorkingDirectory.IndexOfAny(Path.GetInvalidPathChars()) == -1 && (Path.IsPathRooted(ScriptPath) || Path.IsPathRooted(WorkingDirectory)) && File.Exists(Path.Combine(WorkingDirectory, ScriptPath)) && (WorkingDirectory == string.Empty || Directory.Exists(WorkingDirectory)) && (File.Exists(InterpreterPath)); } }
/// <summary> /// Renames the project (and its directory if renameDirectory is true). /// </summary> public void Rename(string newName, bool renameDirectory) { if (renameDirectory) { // Rename the project directory string newProjectPath = Path.Combine(Path.GetDirectoryName(ProjectPath), newName); if (Directory.Exists(ProjectPath + "_TEMP")) // The "_TEMP" suffix exists only when the directory name just changed letter cases { Directory.Move(ProjectPath + "_TEMP", newProjectPath); } else { Directory.Move(ProjectPath, newProjectPath); } EnginePath = Path.Combine(newProjectPath, EnginePath.Remove(0, ProjectPath.Length + 1)); // Change ScriptPath / LevelsPath values of the project if they were inside the ProjectPath folder if (ScriptPath.StartsWith(ProjectPath)) { ScriptPath = Path.Combine(newProjectPath, ScriptPath.Remove(0, ProjectPath.Length + 1)); } if (LevelsPath.StartsWith(ProjectPath)) { LevelsPath = Path.Combine(newProjectPath, LevelsPath.Remove(0, ProjectPath.Length + 1)); } List <ProjectLevel> cachedLevelList = new List <ProjectLevel>(); cachedLevelList.AddRange(Levels); // Remove all internal levels from the project's list to update all .prj2 files with new paths Levels.Clear(); // Restore external levels, because we don't update them foreach (ProjectLevel projectLevel in cachedLevelList) { if (Path.GetDirectoryName(projectLevel.FolderPath).ToLower() != LevelsPath.ToLower()) { Levels.Add(projectLevel); } } ProjectPath = newProjectPath; } Name = newName; }
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { var inputParams = Parameters ?? new List<InArgument<string>>(); if (inputParams.Count > 10) throw new ArgumentException("Only 10 parameters are allowed."); var fileInfo = new FileInfo(ScriptPath.Get(context)); var fullName = fileInfo.FullName; var functionName = FunctionName.Get(context); if (!fileInfo.Exists) throw new ArgumentException($"'{fullName}' does not exist."); if (string.Compare(fileInfo.Extension, ".ahk", true) != 0) throw new ArgumentException($"'{fileInfo.Extension}' is not a valid AutoHotKey file type."); var paramList = inputParams.Select(x => x.Get(context)).ToList(); var tcs = new TaskCompletionSource<string>(state); var cts = new CancellationTokenSource(); context.UserState = cts; var task = Task.Factory.StartNew(() => { Engine = new AutoHotkeyExecutor(); if (string.IsNullOrWhiteSpace(functionName)) { return Engine.ExecuteRaw(fileInfo); } else { Engine.Load(fullName); if (!Engine.FunctionExists(functionName)) throw new ArgumentException($"The function '{functionName}' does not exist in the provided file: '{fullName}'."); return Engine.ExecuteFunction(functionName, paramList.ToArray()); } }, cts.Token); task.ContinueWith(t => { if (t.IsFaulted) tcs.TrySetException(t.Exception.InnerExceptions); else if (t.IsCanceled) tcs.TrySetCanceled(); if (callback != null) callback(tcs.Task); tcs.TrySetResult(t.Result); }); return tcs.Task; }
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { var scriptPath = ScriptPath.Get(context); if (Path.GetExtension(scriptPath) != ".ps1") { throw new ArgumentException($"'{Path.GetExtension(scriptPath)}' is not a valid PowerShell file type."); } var parameters = Parameters.Select(x => new KeyValuePair <string, object>(x.Key, x.Value.Get(context))).ToList(); var psExec = new PowerShellExecutor(); context.UserState = psExec; return(psExec.ExecuteScript(scriptPath, parameters, callback, state)); }
/// <summary> /// Replaces "$(ProjectDirectory)" with the project's .trproj folder path. /// <para>This is used to make projects inside TombIDE easier to read for the software.</para> /// </summary> public void DecodeProjectPaths(string trprojFilePath) { ProjectPath = Path.GetDirectoryName(trprojFilePath); if (!string.IsNullOrEmpty(LaunchFilePath)) { LaunchFilePath = Path.Combine(ProjectPath, LaunchFilePath.Replace(@"$(ProjectDirectory)\", string.Empty)); } string engineDirectory = Path.Combine(ProjectPath, "Engine"); if (Directory.Exists(engineDirectory)) { foreach (string file in Directory.GetFiles(engineDirectory, "*.exe", SearchOption.TopDirectoryOnly)) { if (((GameVersion == TRVersion.Game.TR4 || GameVersion == TRVersion.Game.TRNG) && Path.GetFileName(file).ToLower() == "tomb4.exe") || (GameVersion == TRVersion.Game.TR5Main && Path.GetFileName(file).ToLower() == "pctomb5.exe")) { EnginePath = engineDirectory; break; } } } // If the /Engine/ directory doesn't exist or no valid .exe file was found in that directory if (string.IsNullOrEmpty(EnginePath)) { EnginePath = ProjectPath; } if (ScriptPath.StartsWith("$(ProjectDirectory)")) { ScriptPath = ScriptPath.Replace("$(ProjectDirectory)", ProjectPath); } if (LevelsPath.StartsWith("$(ProjectDirectory)")) { LevelsPath = LevelsPath.Replace("$(ProjectDirectory)", ProjectPath); } foreach (ProjectLevel level in Levels) { if (level.FolderPath.StartsWith("$(ProjectDirectory)")) { level.FolderPath = level.FolderPath.Replace("$(ProjectDirectory)", ProjectPath); } } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); _settings = UploadConfigurationSection.GetConfig(); if (String.IsNullOrEmpty(ImagePath)) { ImagePath = _settings == null ? DEFAULT_IMAGE_PATH : _settings.ImagePath; } ImagePath = ImagePath.TrimEnd('/') + "/"; if (String.IsNullOrEmpty(CSSPath)) { CSSPath = _settings == null ? DEFAULT_CSS_PATH : _settings.CSSPath; } CSSPath = CSSPath.TrimEnd('/') + "/"; if (String.IsNullOrEmpty(ScriptPath)) { ScriptPath = _settings == null ? DEFAULT_JS_PATH : _settings.ScriptPath; } if (String.IsNullOrEmpty(ProgressUrl)) { ProgressUrl = _settings == null ? DEFAULT_PROGRESS_URL : _settings.ProgressUrl; } if (_settings != null) { AllowedFileExtensions = _settings.AllowedFileExtensions; ShowCancelButton = _settings.ShowCancelButton; ShowProgressBar = _settings.ShowProgressBar; EnableManualProcessing = _settings.EnableManualProcessing; } ScriptPath = ScriptPath.TrimEnd('/') + "/"; if (UploadManager.Instance.ModuleInstalled) { _status = UploadManager.Instance.Status; UploadManager.Instance.Status = null; } }
////////////////////////////////////////////////////////////////////////// private void UpdateScriptPathNode(TreeNode ParentNode, ScriptPath Path) { Path.Scripts.Sort(new Script.ScriptFilenameComparer()); int NodeIndex = 0; foreach (Script Scr in Path.Scripts) { string NodeName = System.IO.Path.GetFileName(Scr.Filename); TreeNode Node = null; while (Node == null && NodeIndex < ParentNode.Nodes.Count) { Node = ParentNode.Nodes[NodeIndex]; if (Node.Tag != Scr) { if (string.Compare(Node.Text, NodeName) < 0) { ParentNode.Nodes.RemoveAt(NodeIndex); Node = null; } else { Node = null; break; } } else { NodeIndex++; } } if (Node == null) { Node = ParentNode.Nodes.Insert(NodeIndex, NodeName); Node.Tag = Scr; NodeIndex++; } Node.ImageIndex = Node.SelectedImageIndex = ScriptStateToImage(Scr); UpdateScriptNode(Node, Scr); } for (int i = NodeIndex; i < ParentNode.Nodes.Count; i++) { ParentNode.Nodes.RemoveAt(NodeIndex); } }
/// <summary> /// Returns true if ComAdobeGraniteMonitoringImplScriptConfigImplProperties instances are equal /// </summary> /// <param name="other">Instance of ComAdobeGraniteMonitoringImplScriptConfigImplProperties to be compared</param> /// <returns>Boolean</returns> public bool Equals(ComAdobeGraniteMonitoringImplScriptConfigImplProperties other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( ScriptFilename == other.ScriptFilename || ScriptFilename != null && ScriptFilename.Equals(other.ScriptFilename) ) && ( ScriptDisplay == other.ScriptDisplay || ScriptDisplay != null && ScriptDisplay.Equals(other.ScriptDisplay) ) && ( ScriptPath == other.ScriptPath || ScriptPath != null && ScriptPath.Equals(other.ScriptPath) ) && ( ScriptPlatform == other.ScriptPlatform || ScriptPlatform != null && ScriptPlatform.Equals(other.ScriptPlatform) ) && ( Interval == other.Interval || Interval != null && Interval.Equals(other.Interval) ) && ( Jmxdomain == other.Jmxdomain || Jmxdomain != null && Jmxdomain.Equals(other.Jmxdomain) )); }
static ConfigHelper() { string scriptRoot = ConfigurationManager.AppSettings[_scriptRootSettingKey]; if (scriptRoot != null) { scriptRoot = scriptRoot.Trim(); } if (string.IsNullOrEmpty(scriptRoot)) { throw new SettingsPropertyNotFoundException(_scriptRootSettingKey); } if (scriptRoot.StartsWith("~")) { scriptRoot = WebServer.MapPath(scriptRoot); } _scriptPath = new ScriptPath(scriptRoot); }
protected virtual void WriteSteps(CustomFileWriter writer) { // using (writer.WriteBlock("- task: DownloadBuildArtifacts@0")) // { // // writer.WriteLine("displayName: Download Artifacts"); // using (writer.WriteBlock("inputs:")) // { // writer.WriteLine($"artifactName: {Name}"); // writer.WriteLine($"downloadPath: {Path.SingleQuote()}"); // } // } using (writer.WriteBlock("- task: PowerShell@2")) { var arguments = $"{InvokedTargets.JoinSpace()} --skip"; if (PartitionName != null) { arguments += $" --{ParameterService.GetParameterDashedName(PartitionName)} $(System.JobPositionInPhase)"; } using (writer.WriteBlock("inputs:")) { writer.WriteLine($"filePath: {ScriptPath.SingleQuote()}"); writer.WriteLine($"arguments: {arguments.SingleQuote()}"); } } PublishArtifacts.ForEach(x => { using (writer.WriteBlock("- task: PublishBuildArtifacts@1")) { using (writer.WriteBlock("inputs:")) { writer.WriteLine($"artifactName: {x}"); writer.WriteLine($"pathtoPublish: {StringExtensions.SingleQuote(x)}"); } } }); }
/// <summary> /// Replaces the project's .trproj folder path with "$(ProjectDirectory)". /// <para>This is used before saving .trproj files to avoid having "hardcoded" paths.</para> /// </summary> public void EncodeProjectPaths() { LaunchFilePath = Path.Combine("$(ProjectDirectory)", Path.GetFileName(LaunchFilePath)); if (ScriptPath.StartsWith(ProjectPath)) { ScriptPath = ScriptPath.Replace(ProjectPath, "$(ProjectDirectory)"); } if (LevelsPath.StartsWith(ProjectPath)) { LevelsPath = LevelsPath.Replace(ProjectPath, "$(ProjectDirectory)"); } foreach (ProjectLevel level in Levels) { if (level.FolderPath.StartsWith(ProjectPath)) { level.FolderPath = level.FolderPath.Replace(ProjectPath, "$(ProjectDirectory)"); } } }
private static void FromLua(Context context, string scriptPath = null) { var state = new Lua(); state.LoadCLRPackage(); var path = new ScriptPath(scriptPath); var en = Environment.NewLine; var script = $"function user_script()\n{File.ReadAllText(path.Value)}\nend"; Output.DarkMagenta("THE SCRIPT"); Output.DarkMagenta("---------------------"); Output.Cyan(script); state.DoString("import ('LuaDecisionTree', 'LuaDecisionTree.Decisions')"); state.DoString(script); var result = state.DoString(@" status, res = pcall(user_script) return res "); var item = result != null ? result[0] : null; if (item is ILeaf algo) { var res = algo.Interpret(context); Output.Magenta($"Result is: {(res.IsGood ? "Good" : "Bad")} - {res.Message}"); } else { Output.Magenta($"Result is of type: {(item == null ? "NULL" : result[0].GetType().Name)}"); if (result != null && result.Length > 0 && result[0] is LuaScriptException ex) { Output.Red(ex.Message); } } }
public override bool IsViable() { return(ScriptPath.Try(File.Exists)); }
/// <summary> /// Upload all the files in the workspace for the current project /// </summary> void UploadWorkspace(DirectoryReference TempDir) { // Path to the scripts to be uploaded FileReference ScriptPathsFileName = FileReference.Combine(UnrealBuildTool.EngineDirectory, "Build", "Rsync", "RsyncEngineScripts.txt"); // Read the list of scripts to be uploaded List <string> ScriptPaths = new List <string>(); foreach (string Line in FileReference.ReadAllLines(ScriptPathsFileName)) { string FileToUpload = Line.Trim(); if (FileToUpload.Length > 0 && FileToUpload[0] != ';') { ScriptPaths.Add(FileToUpload); } } // Fixup the line endings List <FileReference> TargetFiles = new List <FileReference>(); foreach (string ScriptPath in ScriptPaths) { FileReference SourceFile = FileReference.Combine(UnrealBuildTool.EngineDirectory, ScriptPath.TrimStart('/')); if (!FileReference.Exists(SourceFile)) { throw new BuildException("Missing script required for remote upload: {0}", SourceFile); } FileReference TargetFile = FileReference.Combine(TempDir, SourceFile.MakeRelativeTo(UnrealBuildTool.EngineDirectory)); if (!FileReference.Exists(TargetFile) || FileReference.GetLastWriteTimeUtc(TargetFile) < FileReference.GetLastWriteTimeUtc(SourceFile)) { DirectoryReference.CreateDirectory(TargetFile.Directory); string ScriptText = FileReference.ReadAllText(SourceFile); FileReference.WriteAllText(TargetFile, ScriptText.Replace("\r\n", "\n")); } TargetFiles.Add(TargetFile); } // Write a file that protects all the scripts from being overridden by the standard engine filters FileReference ScriptUploadList = FileReference.Combine(TempDir, "RsyncEngineScripts-Upload.txt"); using (StreamWriter Writer = new StreamWriter(ScriptUploadList.FullName)) { foreach (string ScriptPath in ScriptPaths) { for (int SlashIdx = ScriptPath.IndexOf('/', 1); SlashIdx != -1; SlashIdx = ScriptPath.IndexOf('/', SlashIdx + 1)) { Writer.WriteLine("+ {0}", ScriptPath.Substring(0, SlashIdx)); } Writer.WriteLine("+ {0}", ScriptPath); } Writer.WriteLine("protect *"); } // Write a file that protects all the scripts from being overridden by the standard engine filters FileReference ScriptProtectList = FileReference.Combine(TempDir, "RsyncEngineScripts-Protect.txt"); using (StreamWriter Writer = new StreamWriter(ScriptProtectList.FullName)) { foreach (string ScriptPath in ScriptPaths) { Writer.WriteLine("protect {0}", ScriptPath); } } // Upload these files to the remote List <FileReference> FilterLocations = new List <FileReference>(); FilterLocations.Add(ScriptUploadList); UploadDirectory(TempDir, GetRemotePath(UnrealBuildTool.EngineDirectory), FilterLocations); // Upload the engine files List <FileReference> EngineFilters = new List <FileReference>(); EngineFilters.Add(ScriptProtectList); EngineFilters.Add(FileReference.Combine(UnrealBuildTool.EngineDirectory, "Build", "Rsync", "RsyncEngine.txt")); UploadDirectory(UnrealBuildTool.EngineDirectory, GetRemotePath(UnrealBuildTool.EngineDirectory), EngineFilters); // Upload the project files if (ProjectFile != null && !ProjectFile.IsUnderDirectory(UnrealBuildTool.EngineDirectory)) { List <FileReference> ProjectFilters = new List <FileReference>(); FileReference CustomProjectFilter = FileReference.Combine(ProjectFile.Directory, "Build", "Rsync", "RsyncProject.txt"); if (FileReference.Exists(CustomProjectFilter)) { ProjectFilters.Add(CustomProjectFilter); } ProjectFilters.Add(FileReference.Combine(UnrealBuildTool.EngineDirectory, "Build", "Rsync", "RsyncProject.txt")); UploadDirectory(ProjectFile.Directory, GetRemotePath(ProjectFile.Directory), ProjectFilters); } }
static string TapFromSource(ScriptPath s) { string rel=s.GetRelativePart(); rel=rel.Replace(Path.DirectorySeparatorChar,'_'); return Path.Combine(TAPApp.Subject,ExtEx.Replace(rel,m=> string.Concat("taps.",m.Groups[1].Value.Replace(".","")),1)); }
public Task(AutoResetEvent done,TaskMgrClient client,ScriptPath path,bool single) { Done=done; Client=client; ScriptPath=path; Single=single; }
string Compile(ScriptPath spath,bool tapwasupdated) { string path=spath.Path; if(!File.Exists(path)) { throw new FileNotFoundException("source file not found",path); } string outpath=TapFromSource(spath); string pdbpath=PdbFromTap(outpath); string[] sa=GetSubjectAssemblies(); // this includes tap.exe copied with CopyMe TAPApp.VLog(3,"subject assemblies:"+string.Join(",",sa.ToArray())); if(!tapwasupdated && !TAPApp.IsOutdated(outpath,path) && !TAPApp.IsOutdated(pdbpath,path) && !IsOutdated(outpath,sa)) { TAPApp.VLog(2,outpath+" is up to date"); return outpath; } TAPApp.VLog(3,"building {0}",outpath); using(CodeDomProvider prov=new CSharpCodeProvider(new Dictionary<string,string>{ {"CompilerVersion","v3.5"}})) { // maybe make configurable in a <system.codedom><compilers>... var cp=new CompilerParameters(); cp.GenerateExecutable=true; cp.IncludeDebugInformation=true; cp.OutputAssembly=outpath; //cp.CompilerOptions+=String.Concat("/d:DEBUG /lib:\"",GetMyImagePath(),"\""); #if __MonoCS__ cp.CompilerOptions+="/d:DEBUG /nowarn:169"; #else cp.CompilerOptions+=string.Concat("/d:DEBUG /pdb:",pdbpath); #endif cp.ReferencedAssemblies.Add("System.dll"); cp.ReferencedAssemblies.Add("System.Core.dll"); cp.ReferencedAssemblies.AddRange(sa); cp.ReferencedAssemblies.AddRange(TAPApp.Refs.ToArray()); CompilerResults cr=prov.CompileAssemblyFromFile(cp,new []{path}); bool errors=cr.Errors.Count>0; if(errors) TAPApp.ELog("Errors building"); if(errors || TAPApp.Verbose>1) { foreach(string i in cr.Output) { TAPApp.Log(i); } } if(!errors) { return cr.PathToAssembly; } return null; } }
////////////////////////////////////////////////////////////////////////// public void RefreshScripts(Script[] Scripts) { List <ScriptPath> Paths = new List <ScriptPath>(); foreach (Script Scr in Scripts) { if (Scr.Parent != null) { continue; } ScriptPath Path = new ScriptPath(System.IO.Path.GetDirectoryName(Scr.Filename.ToLower())); int Index = Paths.BinarySearch(Path); if (Index < 0) { Paths.Add(Path); Paths.Sort(); } else { Path = Paths[Index]; } Path.Scripts.Add(Scr); } TreeScripts.BeginUpdate(); int NodeIndex = 0; foreach (ScriptPath Path in Paths) { TreeNode Node = null; while (Node == null && NodeIndex < TreeScripts.Nodes.Count) { Node = TreeScripts.Nodes[NodeIndex]; if (Node.Text != Path.Path) { if (string.Compare(Node.Text, Path.Path) < 0) { TreeScripts.Nodes.RemoveAt(NodeIndex); Node = null; } else { Node = null; break; } } else { NodeIndex++; } } if (Node == null) { Node = TreeScripts.Nodes.Insert(NodeIndex, Path.Path); Node.ImageIndex = 1; Node.SelectedImageIndex = 0; NodeIndex++; } UpdateScriptPathNode(Node, Path); } for (int i = NodeIndex; i < TreeScripts.Nodes.Count; i++) { TreeScripts.Nodes.RemoveAt(NodeIndex); } TreeScripts.EndUpdate(); Watch.Refresh(); GridWatch.Refresh(); }