Skip to content

Commit

Permalink
Fix #339: User backup restores throws errors (disabled csharp programs)
Browse files Browse the repository at this point in the history
  • Loading branch information
genemars committed Oct 5, 2018
1 parent 489b25e commit de20703
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,12 @@ HG.WebApp.ProgramsList = HG.WebApp.ProgramsList || new function () { var $$ = th
if (propObj != null) statusProperty = propObj.Value;
}
//
if (statusProperty == 'Running') {
if (statusProperty === 'Running') {
statusColor = 'green';
} else if (statusProperty == 'Background') {
} else if (statusProperty === 'Background') {
statusColor = 'blue';
} else if (prog.IsEnabled) {
if (hasErrors)
if (hasErrors || statusProperty === 'Interrupted')
statusColor = 'red';
else
statusColor = 'yellow';
Expand Down Expand Up @@ -737,4 +737,4 @@ HG.WebApp.ProgramsList = HG.WebApp.ProgramsList || new function () { var $$ = th
});
};

};
};
2 changes: 1 addition & 1 deletion HomeGenie/Automation/Engines/CSharpAppFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static int ProgramCodeOffset
}

// TODO: move this to a config file
static readonly string[] Includes =
private static readonly string[] Includes =
{
"System",
"System.Text",
Expand Down
24 changes: 14 additions & 10 deletions HomeGenie/Automation/Engines/CSharpEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public CSharpEngine(ProgramBlock pb) : base(pb)
public bool Load()
{
var success = LoadAssembly();
if (!success)
if (!success && String.IsNullOrEmpty(ProgramBlock.ScriptErrors))
{
ProgramBlock.ScriptErrors = "Program update is required.";
ProgramBlock.ScriptErrors = "Program is not compiled.";
}
return success;
}
Expand Down Expand Up @@ -97,17 +97,19 @@ public override List<ProgramError> Compile()
}

// dispose assembly and interrupt current task (if any)
bool wasEnabled = ProgramBlock.IsEnabled;
ProgramBlock.ScriptErrors = "";
ProgramBlock.IsEnabled = false;

// clean up old assembly files
try
{
// If the file to be deleted does not exist, no exception is thrown.
File.Delete(this.AssemblyFile);
File.Delete(this.AssemblyFile + ".mdb");
File.Delete(this.AssemblyFile.Replace(".dll", ".mdb"));
File.Delete(this.AssemblyFile + ".pdb");
File.Delete(this.AssemblyFile.Replace(".dll", ".pdb"));
File.Delete(AssemblyFile);
File.Delete(AssemblyFile + ".mdb");
File.Delete(AssemblyFile.Replace(".dll", ".mdb"));
File.Delete(AssemblyFile + ".pdb");
File.Delete(AssemblyFile.Replace(".dll", ".pdb"));
}
catch (Exception ex)
{
Expand Down Expand Up @@ -196,6 +198,11 @@ public override List<ProgramError> Compile()
HomeGenieService.LogError(ee);
}

if (errors.Count == 0 && wasEnabled)
{
ProgramBlock.IsEnabled = true;
}

return errors;
}

Expand Down Expand Up @@ -265,9 +272,6 @@ private string AssemblyFile

private bool LoadAssembly()
{
if (ProgramBlock.Type.ToLower() != "csharp")
return false;

try
{
var assemblyData = File.ReadAllBytes(this.AssemblyFile);
Expand Down

0 comments on commit de20703

Please sign in to comment.