public static IScript CreateScript(ScriptTypes type) { IScript newScript; switch (type) { case ScriptTypes.Roslyn: newScript = new RoslynScript(); break; case ScriptTypes.Lua: default: newScript = new LuaScript(); break; } return newScript; }
public static IScript GetScript(byte[] scriptBytes, ScriptTypes scriptType) { IScript script = null; if (scriptBytes != null) { switch (scriptType) { case ScriptTypes.Lua: script = new LuaScript(scriptBytes); break; case ScriptTypes.Roslyn: script = new RoslynScript(scriptBytes); break; default: break; } } return script; }
private async void saveScript_Click(object sender, EventArgs e) { if (!IsEmpty(scriptIdValue.Text) && !IsEmpty(scriptValue.Text) && !ScriptError) { byte[] scriptBytes = System.Text.Encoding.ASCII.GetBytes(scriptValue.Text); BsonBinaryData scriptArray = new BsonBinaryData(scriptBytes); Triggers.Script newScript = new LuaScript() { ID = scriptIdValue.Text, ScriptByteArray = scriptBytes, ScriptType = (ScriptTypes)Enum.Parse(typeof(ScriptTypes), scriptTypeValue.SelectedItem.ToString()) }; var collection = MongoUtils.MongoData.GetCollection<Triggers.Script>("Scripts", (string)scriptTypesValue.SelectedItem); await collection.ReplaceOneAsync<Triggers.Script>(s => s.ID == scriptIdValue.Text, newScript, new UpdateOptions { IsUpsert = true }); scriptValidatedValue.Visible = false; } else if (ScriptError) { DisplayErrorBox("Script file contains errors. Test script before saving."); } }
public static IScript GetScript(string scriptID, string scriptCollection) { IScript script = null; MongoCollection collection = MongoUtils.MongoData.GetCollection("Scripts", scriptCollection); BsonDocument doc = collection.FindOneAs<BsonDocument>(Query.EQ("_id", scriptID)); if (doc != null && doc["Bytes"].AsBsonBinaryData != null) { ScriptTypes scriptType = (ScriptTypes)Enum.Parse(typeof (ScriptTypes), doc["Type"].ToString()); switch (scriptType) { case ScriptTypes.Lua: script = new LuaScript((byte[])doc["Bytes"].AsBsonBinaryData); break; case ScriptTypes.Roslyn: script = new RoslynScript((byte[])doc["Bytes"].AsBsonBinaryData); break; default: break; } } return script; }