public UpdateDeviceState( IScriptInterpreter scriptInterpreter, ILogger logger) { this.scriptInterpreter = scriptInterpreter; this.log = logger; this.setupDone = false; }
private void Initialize() { Logger.Log("GameSystem: Starting GameSystem"); IsInitialized = true; AssetManager = new AssetManager(); AudioController = new AudioController(); TextController = new TextController(); TextHistory = new TextHistory(); try { AssetManager.CompileIfNeeded(); Logger.Log("GameSystem: Starting ScriptInterpreter"); Type type = Type.GetType(ScriptInterpreterName); if (type == null) { throw new Exception("Cannot find class " + ScriptInterpreterName + " through reflection!"); } ScriptSystem = (Activator.CreateInstance(type) as IScriptInterpreter); if (ScriptSystem == null) { throw new Exception("Failed to instantiate ScriptSystem!"); } ScriptSystem.Initialize(this); } catch (Exception arg) { Logger.LogError($"Unable to load Script Interpreter of type {ScriptInterpreterName}!\r\n{arg}"); throw; IL_00d0 :; } IsRunning = true; GameState = GameState.Normal; curStateObj = new StateNormal(); IGameState obj = curStateObj; inputHandler = obj.InputHandler; MessageBoxVisible = false; if (!PlayerPrefs.HasKey("width")) { PlayerPrefs.SetInt("width", 640); } if (!PlayerPrefs.HasKey("height")) { PlayerPrefs.SetInt("height", 480); } if (PlayerPrefs.GetInt("width") < 640) { PlayerPrefs.SetInt("width", 640); } if (PlayerPrefs.GetInt("height") < 480) { PlayerPrefs.SetInt("height", 480); } if ((Screen.width < 640 || Screen.height < 480) && !Screen.fullScreen) { Screen.SetResolution(640, 480, fullscreen: false); } }
public UpdateDeviceState( IScriptInterpreter scriptInterpreter, ILogger logger, IInstance instance) { this.scriptInterpreter = scriptInterpreter; this.log = logger; this.instance = instance; }
public Connect( IDevices devices, IScriptInterpreter scriptInterpreter, ILogger logger) { this.log = logger; this.scriptInterpreter = scriptInterpreter; this.devices = devices; }
public Disconnect( IScriptInterpreter scriptInterpreter, ILogger logger, IInstance instance) { this.scriptInterpreter = scriptInterpreter; this.log = logger; this.instance = instance; }
public DeviceMethods( Azure.Devices.Client.DeviceClient client, ILogger logger, IScriptInterpreter scriptInterpreter) { this.client = client; this.log = logger; this.scriptInterpreter = scriptInterpreter; this.deviceId = string.Empty; }
public UpdateDeviceState( ITimer timer, IScriptInterpreter scriptInterpreter, ILogger logger) { this.timer = timer; this.scriptInterpreter = scriptInterpreter; this.log = logger; this.timer.Setup(this.Run); }
public DeviceMethods( IDeviceClientWrapper client, ILogger logger, IScriptInterpreter scriptInterpreter) { this.client = client; this.log = logger; this.scriptInterpreter = scriptInterpreter; this.deviceId = string.Empty; this.isRegistered = false; }
public Connect( ITimer timer, IDevices devices, ILogger logger, IScriptInterpreter scriptInterpreter) { this.timer = timer; this.log = logger; this.devices = devices; this.scriptInterpreter = scriptInterpreter; this.timer.Setup(this.Run); }
public async Task RegisterMethodsAsync( IDeviceClientWrapper client, string deviceId, IDictionary <string, Script> methods, ISmartDictionary deviceState, ISmartDictionary deviceProperties, IScriptInterpreter scriptInterpreter) { if (methods == null) { return; } if (this.isRegistered) { this.log.Error("Application error, each device must have a separate instance"); throw new Exception("Application error, each device must have a separate instance of " + this.GetType().FullName); } if (!this.methodsEnabled) { this.isRegistered = true; this.log.Debug("Skipping methods registration, methods are disabled in the global configuration."); return; } this.deviceId = deviceId; this.cloudToDeviceMethods = methods; this.deviceState = deviceState; this.deviceProperties = deviceProperties; this.log.Debug("Setting up methods for device.", () => new { this.deviceId, methodsCount = this.cloudToDeviceMethods.Count }); // walk this list and add a method handler for each method specified foreach (var item in this.cloudToDeviceMethods) { this.log.Debug("Setting up method for device.", () => new { item.Key, this.deviceId }); await client.SetMethodHandlerAsync(item.Key, this.ExecuteMethodAsync, scriptInterpreter); this.log.Debug("Method for device setup successfully", () => new { this.deviceId, methodName = item.Key }); } this.isRegistered = true; }
public DeviceStateActor( UpdateDeviceState updateDeviceStateLogic, IScriptInterpreter scriptInterpreter, ILogger logger, IInstance instance) { this.updateDeviceStateLogic = updateDeviceStateLogic; this.ScriptInterpreter = scriptInterpreter; this.log = logger; this.instance = instance; this.status = ActorStatus.None; this.simulationErrorsCount = 0; }
/// <summary> /// Get a client for the device /// </summary> public IDeviceClient GetClient(Device device, IoTHubProtocol protocol, IScriptInterpreter scriptInterpreter) { this.SetupHub(); var sdkClient = this.GetDeviceSdkClient(device, protocol); var methods = new DeviceMethods(sdkClient, this.log, scriptInterpreter); return(new DeviceClient( device.Id, protocol, sdkClient, methods, this.log)); }
// Get a client for the device public IDeviceClient GetClient(Device device, IoTHubProtocol protocol, IScriptInterpreter scriptInterpreter) { this.instance.InitRequired(); var sdkClient = this.GetDeviceSdkClient(device, protocol); var methods = new DeviceMethods(sdkClient, this.log, this.diagnosticsLogger, scriptInterpreter); return(new DeviceClient( device.Id, protocol, sdkClient, methods, this.log)); }
public async Task RegisterMethodsForDeviceAsync( IDictionary <string, Script> methods, ISmartDictionary deviceState, ISmartDictionary deviceProperties, IScriptInterpreter scriptInterpreter) { this.log.Debug("Attempting to register device methods", () => new { this.deviceId }); await this.deviceMethods.RegisterMethodsAsync( this.client, this.deviceId, methods, deviceState, deviceProperties, scriptInterpreter); }
public void InjectConsoleCommands(IScriptInterpreter interpreter) { interpreter.SetFunction("out", new ManicDigger.Action <object>(Print)); interpreter.SetFunction("materials", new ManicDigger.Action(PrintMaterials)); interpreter.SetFunction("materials_between", new ManicDigger.Action <double, double>(PrintMaterials)); interpreter.SetFunction("find_material", new ManicDigger.Action <string>(FindMaterial)); interpreter.SetFunction("position", new ManicDigger.Action(PrintPosition)); interpreter.SetFunction("get_position", new ManicDigger.Func <Vector3i>(GetPosition)); interpreter.SetVariable("turtle", Turtle); interpreter.SetFunction("set_block", new ManicDigger.Action <double, double, double, double>(SetBlock)); interpreter.SetFunction("get_block", new ManicDigger.Func <double, double, double, int>(GetBlock)); interpreter.SetFunction("get_height", new ManicDigger.Func <double, double, double>(GetHeight)); interpreter.SetFunction("get_mapsize", new ManicDigger.Func <int[]>(GetMapSize)); interpreter.SetFunction("set_chunk", new ManicDigger.Action <double, double, double, ushort[]>(SetChunk)); interpreter.SetFunction("set_chunks", new ManicDigger.Action <Dictionary <Xyz, ushort[]> >(SetChunks)); interpreter.SetFunction("set_chunks_offset", new ManicDigger.Action <double, double, double, Dictionary <Xyz, ushort[]> >(SetChunks)); interpreter.SetFunction("get_chunk", new ManicDigger.Func <double, double, double, ushort[]>(GetChunk)); interpreter.SetFunction("get_chunks_from_database", new ManicDigger.Func <double, double, double, double, double, double, string, Dictionary <Xyz, ushort[]> >(GetChunksFromDatabase)); interpreter.SetFunction("copy_chunks_to_database", new ManicDigger.Action <double, double, double, double, double, double, string>(CopyChunksToDatabase)); interpreter.SetFunction("delete_chunk", new ManicDigger.Action <double, double, double>(DeleteChunk)); interpreter.SetFunction("delete_chunk_range", new ManicDigger.Action <double, double, double, double, double, double>(DeleteChunkRange)); interpreter.SetFunction("backup_database", new ManicDigger.Action <string>(BackupDatabase)); interpreter.SetFunction("clear", new ManicDigger.Action(Clear)); }
public void Register(string extension, IScriptInterpreter interpreter) { _interpreters[extension] = interpreter; interpreter.Initialize(_scriptsDirectory); }
private void MethodExecution(MethodRequest methodRequest, IScriptInterpreter scriptInterpreter) { try { this.log.Debug("Executing method with json payload.", () => new { this.deviceId, methodName = methodRequest.Name, methodRequest.DataAsJson }); var scriptContext = new Dictionary <string, object> { ["currentTime"] = DateTimeOffset.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:sszzz"), ["deviceId"] = this.deviceId, // TODO: add "deviceModel" so that the method scripts can use it like the "state" scripts // https://github.com/Azure/device-simulation-dotnet/issues/91 //["deviceModel"] = this.device. }; if (methodRequest.DataAsJson != "null") { this.AddPayloadToContext(methodRequest.DataAsJson, scriptContext); } this.log.Debug("Executing method for device", () => new { this.deviceId, methodName = methodRequest.Name, this.deviceState }); // ignore the return state - state updates are handled by callbacks from the script scriptInterpreter.Invoke( this.cloudToDeviceMethods[methodRequest.Name], scriptContext, this.deviceState, this.deviceProperties); this.log.Debug("Executed method for device", () => new { this.deviceId, methodRequest.Name, this.deviceState, this.deviceProperties }); } catch (Exception e) { var msg = "Error while executing method for device"; this.log.Error(msg, () => new { this.deviceId, methodName = methodRequest.Name, methodRequest.DataAsJson, e }); this.diagnosticsLogger.LogServiceError(msg, new { this.deviceId, methodName = methodRequest.Name, methodRequest.DataAsJson, e.Message }); } }
void SetUpScriptAndInterpreter() { _script = new MockSingleScript(); _interpreter = new ScriptInterpreter( _mockFnRoutinesCaller.Object, _mockGlobalVariableManager.Object, _mockValueStack.Object); }
protected SObject ParseAndGo(string scriptText) { interpreter = langBase.Parser.Parse(scriptText); return(Go()); }
public PlayableContentTab(IScriptInterpreter interpreter, IQueryProcessor processor) { _interpreter = interpreter; _processor = processor; }
public TransactionValidator(IBlockChainStore blockChainStore, ISmartContractStore smartContractStore, IScriptInterpreter scriptInterpreter) { _blockChainStore = blockChainStore; _smartContractStore = smartContractStore; _scriptInterpreter = scriptInterpreter; }