Skip to content

Commit

Permalink
fix(ScheduleFile): use the new ScheduleFile constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed Oct 17, 2023
1 parent 93d79a7 commit bf463c8
Showing 1 changed file with 11 additions and 27 deletions.
38 changes: 11 additions & 27 deletions src/Ironbug.HVAC/Schedules/IB_ScheduleFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,23 @@ public class IB_ScheduleFile : IB_Schedule
protected override Func<IB_ModelObject> 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))
Expand Down

0 comments on commit bf463c8

Please sign in to comment.