diff --git a/src/Ironbug.HVAC/Schedules/IB_ScheduleFile.cs b/src/Ironbug.HVAC/Schedules/IB_ScheduleFile.cs index d5be346f..db2e4f2f 100644 --- a/src/Ironbug.HVAC/Schedules/IB_ScheduleFile.cs +++ b/src/Ironbug.HVAC/Schedules/IB_ScheduleFile.cs @@ -14,39 +14,23 @@ public class IB_ScheduleFile : IB_Schedule protected override Func IB_InitSelf => () => new IB_ScheduleFile(this._filePath); - private static ScheduleFile InitMethod(Model model, string path) { - var tempFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "Ironbug", "files"); - if (File.Exists(path)) - { - //Copy to temp folder - var targetFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetFileName(path)); - File.Copy(path, targetFile, true); - } - - // Check if temp folder exist in current workflow paths - var workflow = model.workflowJSON(); - var Paths = workflow.absoluteFilePaths().Select(_=>_.__str__()); - if (!Paths.Contains(tempFolder)) - { - workflow.addFilePath(OpenStudioUtilitiesCore.toPath(tempFolder)); - } + + if (!File.Exists(path)) + throw new ArgumentException($"Invalid file path for ScheduleFile! \n{path}"); - var extFile = ExternalFile.getExternalFile(model, path); + var tempFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "Ironbug", "files"); + Directory.CreateDirectory(tempFolder); - var paths = model.workflowJSON().filePaths()[0].__str__(); + //Copy to temp folder + var targetFile = System.IO.Path.Combine(tempFolder, System.IO.Path.GetFileName(path)); + File.Copy(path, targetFile, true); - if (extFile.is_initialized()) - { - var obj = new ScheduleFile(extFile.get()); - return obj; - } - - throw new ArgumentException($"Invalid file path for ScheduleFile! \n{path}\n{workflow.oswDir().__str__()}"); + var obj = new ScheduleFile(model, OpenStudioUtilitiesCore.toPath(targetFile)); + return obj; } - - + private IB_ScheduleFile() : base(null) { } public IB_ScheduleFile(string filePath) : base(InitMethod(new Model(), filePath))