public IJSResponse GetDeviceInPort(IJSRequest request) { IPlatformInfo platform = this.CoreInstance.Platforms[request.GetParameter("platform")]; int port = int.Parse(request.GetParameter("port")); return new JSResponse(request, this.CoreInstance.Get<IControllerPortsDatabase>().GetDeviceInPort(platform, port)); }
public IJSResponse SetPreference(IJSRequest request) { IPlatformInfo platform = this.CoreInstance.Platforms[request.GetParameter("platform")]; string preference = request.GetParameter("preference"); string value = request.GetParameter("value"); switch (preference) { case "emulator": if (this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>().ContainsKey(value)) { this.CoreInstance.Get<IPlatformPreferenceDatabase>().SetEmulator(platform, value); return new JSResponse(request, "Emulator set to {value}", true); //return emulator that was set } throw new ArgumentException("Emulator Not Found", new KeyNotFoundException()); case "scraper": if (this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>().ContainsKey(value)) { this.CoreInstance.Get<IPlatformPreferenceDatabase>().SetScraper(platform, value); return new JSResponse(request, $"Scraper set to {value}", true); //return scraper that was set } throw new ArgumentException("Scraper Not Found", new KeyNotFoundException()); default: throw new ArgumentException("Unknown preference type"); } }
public IJSResponse SetGameVideo(IJSRequest request) { string cacheKey = request.GetParameter("id"); Uri imageUri = new Uri(request.GetParameter("url")); IGameMediaCache gameCache = new GameMediaCache(cacheKey); gameCache.SetBoxartBack(imageUri); return new JSResponse(request, $"{gameCache.CacheKey}/{gameCache.GameVideoFileName}"); }
public IJSResponse GetFlagDefaultValue(IJSRequest request) { string emulator = request.GetParameter("emulator"); string key = request.GetParameter("key"); IEmulatorBridge bridge = this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>()[emulator]; IConfigurationFlag flag = bridge.ConfigurationFlags[key]; return new JSResponse(request, bridge.ConfigurationFlagStore.GetDefaultValue(flag.Key, flag.Type)); }
public IJSResponse GetFlagDefaultValues(IJSRequest request) { string emulator = request.GetParameter("emulator"); string key = request.GetParameter("key"); IEmulatorBridge bridge = this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>()[emulator]; IDictionary<string, dynamic> flags = bridge.ConfigurationFlags.ToDictionary(flag => flag.Value.Key, flag => bridge.ConfigurationFlagStore.GetDefaultValue(flag.Value.Key, flag.Value.Type)); return new JSResponse(request, flags); }
public IJSResponse GetDeviceInPorts(IJSRequest request) { IPlatformInfo platform = this.CoreInstance.Platforms[request.GetParameter("platform")]; string[] ports = new string[9]; for(int i = 1; i <= 8; i++){ ports[i] = this.CoreInstance.Get<IControllerPortsDatabase>().GetDeviceInPort(platform, i); } return new JSResponse(request, ports); }
public IJSResponse GetAllGamesSorted(IJSRequest request) { IList<IGameInfo> games = this.CoreInstance.Get<IGameDatabase>().GetAllGames(); IDictionary<string, List<IGameInfo>> sortedGames = this.CoreInstance.Platforms.ToDictionary(platform => platform.Key, platform => new List<IGameInfo>()); foreach (IGameInfo game in games.Where(game => sortedGames.ContainsKey(game.PlatformID))) { sortedGames[game.PlatformID].Add(game); } foreach (List<IGameInfo> gameInfos in sortedGames.Values) { gameInfos.Sort((x, y) => string.CompareOrdinal(x.Name, y.Name)); } return new JSResponse(request, sortedGames); }
private static string ProcessJSONP(dynamic output, bool success, IJSRequest request) { string json = JsonConvert.SerializeObject(new Dictionary<string, object> { {"request", request}, {"payload", output}, {"success", success}, {"type", "methodresponse"} }); if (request.MethodParameters.ContainsKey("jsoncallback")) { json = request.MethodParameters["jsoncallback"] + $"({json});"; } return json; }
public IJSResponse AddGameInfo(IJSRequest request) { string gameinfo_pre = request.GetParameter("gameinfo"); IGameInfo game = GameInfo.FromJson(JsonConvert.DeserializeObject(gameinfo_pre)); var gamePreAddEvent = new GamePreAddEventArgs(this.CoreInstance, game, this.CoreInstance.Get<IGameDatabase>()); SnowflakeEventManager.EventSource.RaiseEvent(gamePreAddEvent); if (!gamePreAddEvent.Cancel) { game = gamePreAddEvent.GameInfo; this.CoreInstance.Get<IGameDatabase>().AddGame(game); var gameAddEvent = new GameAddEventArgs(this.CoreInstance, game, this.CoreInstance.Get<IGameDatabase>()); SnowflakeEventManager.EventSource.RaiseEvent(gameAddEvent); } return new JSResponse(request, game, true); }
public string CallMethod(IJSRequest request) { var callMethodEvent = new AjaxRequestReceivedEventArgs(this.CoreInstance, request); SnowflakeEventManager.EventSource.RaiseEvent(callMethodEvent); request = callMethodEvent.ReceivedRequest; AjaxResponseSendingEventArgs sendResultEvent; try { IJSResponse result; IJSMethod jsMethod = this.GlobalNamespace[request.NameSpace].JavascriptMethods[request.MethodName]; foreach (AjaxMethodParameterAttribute attr in jsMethod.MethodInfo.GetCustomAttributes<AjaxMethodParameterAttribute>() .Where(attr => attr.Required) .Where(attr => !(request.MethodParameters.Keys.Contains(attr.ParameterName)))) { result = new JSResponse(request, JSResponse.GetErrorResponse($"missing required param {attr.ParameterName}"), false); sendResultEvent = new AjaxResponseSendingEventArgs(this.CoreInstance, result); SnowflakeEventManager.EventSource.RaiseEvent(sendResultEvent); return sendResultEvent.SendingResponse.GetJson(); } result = jsMethod.Method.Invoke(request); sendResultEvent = new AjaxResponseSendingEventArgs(this.CoreInstance, result); SnowflakeEventManager.EventSource.RaiseEvent(sendResultEvent); return sendResultEvent.SendingResponse.GetJson(); } catch (KeyNotFoundException) { var result = new JSResponse(request, JSResponse.GetErrorResponse($"method {request.MethodName} not found in namespace {request.NameSpace}"), false); sendResultEvent = new AjaxResponseSendingEventArgs(this.CoreInstance, result); SnowflakeEventManager.EventSource.RaiseEvent(sendResultEvent); return sendResultEvent.SendingResponse.GetJson(); } catch (Exception e) { var result = new JSResponse(request, e, false); sendResultEvent = new AjaxResponseSendingEventArgs(this.CoreInstance, result); SnowflakeEventManager.EventSource.RaiseEvent(sendResultEvent); return sendResultEvent.SendingResponse.GetJson(); } }
public IJSResponse GetAllAjaxMethods(IJSRequest request) { List<object> ajaxMethods = new List<object>(); foreach (KeyValuePair<string, IBaseAjaxNamespace> ajaxNamespace in this.CoreInstance.Get<IAjaxManager>().GlobalNamespace) { foreach (KeyValuePair<string, IJSMethod> jsMethod in ajaxNamespace.Value.JavascriptMethods) { dynamic methodInfo = new ExpandoObject(); methodInfo.Namespace = ajaxNamespace.Key; methodInfo.MethodName = jsMethod.Key; methodInfo.Parameters = jsMethod.Value.MethodInfo.GetCustomAttributes<AjaxMethodParameterAttribute>() .Select(attr => new Dictionary<string, object> { {"ParameterName", attr.ParameterName}, {"ParameterType", Enum.GetName(typeof(AjaxMethodParameterType), attr.ParameterType)}, {"Required", attr.Required} }); ajaxMethods.Add(methodInfo); } } return new JSResponse(request, ajaxMethods); }
public IJSResponse SetGamepadAbstraction(IJSRequest request) { string deviceName = request.GetParameter("device"); string _profileType = request.GetParameter("profiletype"); IGamepadAbstraction gamepadAbstraction; try { gamepadAbstraction = this.CoreInstance.Get<IGamepadAbstractionDatabase>()[deviceName]; } catch { ControllerProfileType profileType; gamepadAbstraction = Enum.TryParse(_profileType, true, out profileType) ? new GamepadAbstraction(deviceName, profileType) : new GamepadAbstraction(deviceName, ControllerProfileType.GAMEPAD_PROFILE); } IDictionary<string, string> changes = JsonConvert.DeserializeObject<Dictionary<string, string>>(request.GetParameter("inputconfig")); foreach (KeyValuePair<string, string> change in changes) { gamepadAbstraction[change.Key] = change.Value; } this.CoreInstance.Get<IGamepadAbstractionDatabase>()[deviceName] = gamepadAbstraction; return new JSResponse(request, this.CoreInstance.Get<IGamepadAbstractionDatabase>()[deviceName]); }
public IJSResponse GetAllGames(IJSRequest request) { return new JSResponse(request, this.CoreInstance.Get<IGameDatabase>().GetAllGames()); }
public IJSResponse StartGame(IJSRequest request) { string emulator = request.GetParameter("emulator"); string id = request.GetParameter("id"); IEmulatorBridge bridge = this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>()[emulator]; IGameInfo gameInfo = this.CoreInstance.Get<IGameDatabase>().GetGameByUUID(id); var gameStartEvent = new GameStartEventArgs(this.CoreInstance, gameInfo, bridge.EmulatorAssembly, bridge); SnowflakeEventManager.EventSource.RaiseEvent(gameStartEvent); if (!gameStartEvent.Cancel) { gameStartEvent.GameEmulatorBridge.StartRom(gameStartEvent.GameInfo); } return new JSResponse(request, gameInfo); }
public IJSResponse SetFlagValues(IJSRequest request) { string emulator = request.GetParameter("emulator"); string id = request.GetParameter("id"); string values_pre = request.GetParameter("values"); IDictionary<string, string> values = JsonConvert.DeserializeObject<IDictionary<string, string>>(values_pre); IEmulatorBridge bridge = this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>()[emulator]; IGameInfo game = this.CoreInstance.Get<IGameDatabase>().GetGameByUUID(id); foreach (KeyValuePair<string, string> value in values) { IConfigurationFlag flag = bridge.ConfigurationFlags[value.Key]; dynamic castedValue = bridge.ConfigurationFlagStore.GetDefaultValue(flag.Key, flag.Type); switch (flag.Type) { case ConfigurationFlagTypes.BOOLEAN_FLAG: castedValue = bool.Parse(value.Value); break; case ConfigurationFlagTypes.INTEGER_FLAG: castedValue = int.Parse(value.Value); break; case ConfigurationFlagTypes.SELECT_FLAG: castedValue = int.Parse(value.Value); break; } bridge.ConfigurationFlagStore.SetValue(game, flag.Key, castedValue, flag.Type); } IDictionary<string, dynamic> flags = bridge.ConfigurationFlags.ToDictionary(flag => flag.Value.Key, flag => bridge.ConfigurationFlagStore.GetValue(game, flag.Value.Key, flag.Value.Type)); return new JSResponse(request, flags); }
public IJSResponse GetFlagValue(IJSRequest request) { string emulator = request.GetParameter("emulator"); string id = request.GetParameter("id"); string key = request.GetParameter("key"); IEmulatorBridge bridge = this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>()[emulator]; IGameInfo game = this.CoreInstance.Get<IGameDatabase>().GetGameByUUID(id); IConfigurationFlag flag = bridge.ConfigurationFlags[key]; return new JSResponse(request, bridge.ConfigurationFlagStore.GetValue(game, flag.Key, flag.Type)); }
public IJSResponse GetGameInfo(IJSRequest request) { string resultid = request.GetParameter("resultid"); string platform = request.GetParameter("platform"); string filename = request.GetParameter("filename"); return new JSResponse(request, new ScrapeService(this.CoreInstance.Platforms[platform], this.CoreInstance).GetGameInfo(resultid, filename)); }
public IJSResponse GetGame(IJSRequest request) { string id = request.GetParameter("id"); return new JSResponse(request, this.CoreInstance.Get<IGameDatabase>().GetGameByUUID(id)); }
public IJSResponse GetFlagValues(IJSRequest request) { string emulator = request.GetParameter("emulator"); string id = request.GetParameter("id"); IEmulatorBridge bridge = this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>()[emulator]; IGameInfo game = this.CoreInstance.Get<IGameDatabase>().GetGameByUUID(id); IDictionary<string, dynamic> flags = bridge.ConfigurationFlags.ToDictionary(flag => flag.Value.Key, flag => bridge.ConfigurationFlagStore.GetValue(game, flag.Value.Key, flag.Value.Type)); return new JSResponse(request, flags); }
public IJSResponse GetInputDevices(IJSRequest request) { return new JSResponse(request, this.CoreInstance.Get<IInputManager>().GetGamepads()); }
public IJSResponse GetGameResultsUsingScraper(IJSRequest request) { string filename = request.GetParameter("filename"); string platform = request.GetParameter("platform"); string scraperId = request.GetParameter("scraper"); return new JSResponse(request, new ScrapeService(this.CoreInstance.Platforms[platform], scraperId, this.CoreInstance).GetGameResults(filename)); }
public IJSResponse SendEmulatorPrompt(IJSRequest request) { return new JSResponse(request, null); }
public IJSResponse GetFlags(IJSRequest request) { string emulator = request.GetParameter("emulator"); IEmulatorBridge bridge = this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>()[emulator]; return new JSResponse(request, bridge.ConfigurationFlags); }
public IJSResponse GetGamesByPlatform(IJSRequest request) { string platform = request.GetParameter("platform"); return new JSResponse(request, this.CoreInstance.Get<IGameDatabase>().GetGamesByPlatform(platform)); }
private async Task<string> ProcessRequest(IJSRequest args) { return await this.coreInstance.Get<IAjaxManager>().CallMethodAsync(args); }
public IJSResponse HaltRunningGames(IJSRequest request) { foreach (IEmulatorBridge emulator in this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>().Values) { emulator.ShutdownEmulator(); } return new JSResponse(request, null); }
public IJSResponse ShutdownCore(IJSRequest request) { return new JSResponse(request, null); }
public IJSResponse SearchGames(IJSRequest request) { //todo implement this with a searching algo return new JSResponse(request, null); }
public IJSResponse GetCoreVersionString(IJSRequest request) { return new JSResponse(request, null); }
public IJSResponse SetFlagValue(IJSRequest request) { string emulator = request.GetParameter("emulator"); string id = request.GetParameter("id"); string key = request.GetParameter("key"); string value = request.GetParameter("value"); IEmulatorBridge bridge = this.CoreInstance.Get<IPluginManager>().Plugins<IEmulatorBridge>()[emulator]; IGameInfo game = this.CoreInstance.Get<IGameDatabase>().GetGameByUUID(id); IConfigurationFlag flag = bridge.ConfigurationFlags[key]; dynamic castedValue = bridge.ConfigurationFlagStore.GetDefaultValue(flag.Key, flag.Type); switch (flag.Type) { case ConfigurationFlagTypes.BOOLEAN_FLAG: castedValue = bool.Parse(value); break; case ConfigurationFlagTypes.INTEGER_FLAG: castedValue = int.Parse(value); break; case ConfigurationFlagTypes.SELECT_FLAG: castedValue = int.Parse(value); break; } bridge.ConfigurationFlagStore.SetValue(game, flag.Key, castedValue, flag.Type); return new JSResponse(request, bridge.ConfigurationFlagStore.GetValue(game, flag.Key, flag.Type)); }