public ProgramInsertViewModel() { InsertProgram = ReactiveCommand.CreateFromTask <Unit, IExternalProgram>(async(_) => { IExternalProgram program = null; Console.WriteLine("========== insert program =========="); Console.WriteLine($"Program Label = {ProgramLabel}"); Console.WriteLine($"Program File = {ExecutionProgramFile}"); Console.WriteLine($"Program RootFolder = {RootDirectory}"); Console.WriteLine($"Copy to local = {CopyToLocal}"); Console.WriteLine("===================================="); // 1. Check exists file CancellationTokenSource cts = new CancellationTokenSource(); Console.WriteLine(@"add program start"); var targetFile = await FileService.SearchAsync(RootDirectory, ExecutionProgramFile, cts.Token); Console.WriteLine(@"file search complete"); if (!string.IsNullOrEmpty(targetFile)) { var info = new FileInfo(targetFile); string filePath; if (CopyToLocal) { // try to copy file var dirName = Path.GetFileNameWithoutExtension(ExecutionProgramFile); var applicationDir = $"{Environment.CurrentDirectory}\\{FileService.RootApplicationDirectory}{dirName}\\"; FileService.DirectoryCopy(info.DirectoryName, applicationDir, true); filePath = $"{applicationDir}\\{ExecutionProgramFile}"; program = new ExternalNetworkProgram(ProgramLabel) { ExecuteDirectory = applicationDir, }; } else { var f = new FileInfo(targetFile); filePath = targetFile; program = new ExternalLocalProgram(ProgramLabel) { ExecuteDirectory = f.DirectoryName }; } program.PathToSearch = RootDirectory; program.File = filePath; } return(program); }); }
public void UpdateMatchedApplication(IExternalProgram program, string orgFile) { try { var fileInfo = new FileInfo(orgFile); FileService.DirectoryCopy(fileInfo.DirectoryName, program.ExecuteDirectory, true); } catch { } }
public static IExternalProgram ParseElementToExternalProgram(XElement element) { IExternalProgram program = null; var e = element.Element("Type"); if (e != null) { var value = e.Value; try { Type type = Type.GetType(value); program = CreateProgram(type); } catch { return(null); } } if (program != null) { e = element.Element("Label"); if (e != null) { program.Label = e.Value; } e = element.Element("File"); if (e != null) { program.File = e.Value; } e = element.Element("ExecuteDirectory"); if (e != null) { program.ExecuteDirectory = e.Value; } e = element.Element("PathToSearch"); if (e != null) { program.PathToSearch = e.Value; } e = element.Element("NumOfRuns"); if (e != null) { program.NumOfRuns = int.Parse(e.Value); } } return(program); }
public static XElement ParseExternalProgramToElement(IExternalProgram program) { XElement element = new XElement("Program"); var type = program.GetType().ToString(); element.Add(new XElement("Type", type)); element.Add(new XElement("Label", program.Label)); element.Add(new XElement("File", program.File)); element.Add(new XElement("ExecuteDirectory", program.ExecuteDirectory)); element.Add(new XElement("PathToSearch", program.PathToSearch)); element.Add(new XElement("NumOfRuns", program.NumOfRuns)); return(element); }
public async Task <string> UpdateCheck(IExternalProgram app, CancellationToken token) { string searchPattern = Path.GetFileName(app.File); return(await FileService.SearchAsync(app.PathToSearch, searchPattern, token) .ContinueWith(t => { if (string.IsNullOrEmpty(t.Result)) { return string.Empty; } var searchedFile = t.Result; var appFileInfo = new FileInfo(app.File); var searchedFileInfo = new FileInfo(searchedFile); if (appFileInfo.LastWriteTime < searchedFileInfo.LastWriteTime) { return searchedFile; } return string.Empty; }, token)); }