protected ScriptAbs(ScriptAbs script) { Id = script.Id; ScriptName = script.ScriptName; ScriptStatus = script.ScriptStatus; ScriptPath = script.ScriptPath; }
public static ScriptAbs GetInstance(ScriptAbs oldScript, ScriptType scriptType) { bool hasScriptTypeChanged = oldScript != null && HasScriptTypeChanged(oldScript.ScriptType, scriptType); ScriptAbs newScript = null; if (oldScript == null || hasScriptTypeChanged) { newScript = scriptType switch { ScriptType.OneOff => new ScriptOneOff(), ScriptType.Scheduled => new ScriptScheduled(), ScriptType.ListenKey => new ScriptListenKey(), _ => throw new Exception(), }; if (hasScriptTypeChanged) { newScript.Id = oldScript.Id; } } return(newScript ?? oldScript); }
public static bool HasScheduledTimeChanged(ScriptAbs script, ScriptAbs editedScript) => script.ScriptType == ScriptType.Scheduled && ((ScriptScheduled)script).ScheduledHour != ((ScriptScheduled)editedScript).ScheduledHour;