Skip to content

Commit

Permalink
Merge pull request #85 from RonnChyran/scraper-ajax-fix
Browse files Browse the repository at this point in the history
StandardAjax: Fix System namespace file
  • Loading branch information
chyyran committed Feb 23, 2015
2 parents 35335e3 + d1581c4 commit 9908607
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions Snowflake.StandardAjax/StandardAjax.System.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Dynamic;
using System.Reflection;
using Snowflake.Ajax;
using Snowflake.Service;

Expand All @@ -13,27 +15,49 @@ public partial class StandardAjax
[AjaxMethod(MethodPrefix = "System")]
public IJSResponse GetEmulatorBridges(IJSRequest request)
{
return new JSResponse(request, this.CoreInstance.PluginManager.LoadedEmulators);
IDictionary<string, IDictionary<string, dynamic>> response = this.CoreInstance.PluginManager.LoadedEmulators.ToDictionary
(
emulatorBridge => emulatorBridge.Key,
emulatorBridge => emulatorBridge.Value.PluginInfo
);
return new JSResponse(request, response);
}

[AjaxMethod(MethodPrefix = "System")]
[AjaxMethodParameter(ParameterName = "platform", ParameterType = AjaxMethodParameterType.StringParameter)]
public IJSResponse GetEmulatorBridgesByPlatform(IJSRequest request)
{
return new JSResponse(request, this.CoreInstance.PluginManager.LoadedEmulators.Where(bridge => bridge.Value.SupportedPlatforms.Contains(request.GetParameter("platform"))));
IDictionary<string, IDictionary<string, dynamic>> response = this.CoreInstance.PluginManager.LoadedEmulators
.Where(bridge => bridge.Value.SupportedPlatforms.Contains(request.GetParameter("platform"))).ToDictionary
(
emulatorBridge => emulatorBridge.Key,
emulatorBridge => emulatorBridge.Value.PluginInfo
);
return new JSResponse(request, response);
}

[AjaxMethod(MethodPrefix = "System")]
public IJSResponse GetScrapers(IJSRequest request)
{
return new JSResponse(request, this.CoreInstance.PluginManager.LoadedScrapers);
IDictionary<string, IDictionary<string, dynamic>> response = this.CoreInstance.PluginManager.LoadedScrapers.ToDictionary
(
scrapers => scrapers.Key,
scrapers => scrapers.Value.PluginInfo
);
return new JSResponse(request, response);
}

[AjaxMethod(MethodPrefix = "System")]
[AjaxMethodParameter(ParameterName = "platform", ParameterType = AjaxMethodParameterType.StringParameter)]
public IJSResponse GetScrapersByPlatform(IJSRequest request)
{
return new JSResponse(request, this.CoreInstance.PluginManager.LoadedScrapers.Where(scraper => scraper.Value.SupportedPlatforms.Contains(request.GetParameter("platform"))));
IDictionary<string, IDictionary<string, dynamic>> response = this.CoreInstance.PluginManager.LoadedScrapers
.Where(scraper => scraper.Value.SupportedPlatforms.Contains(request.GetParameter("platform"))).ToDictionary
(
scraper => scraper.Key,
scraper => scraper.Value.PluginInfo
);
return new JSResponse(request, response);
}

[AjaxMethod(MethodPrefix = "System")]
Expand All @@ -46,7 +70,25 @@ public IJSResponse GetAllPlugins(IJSRequest request)
[AjaxMethod(MethodPrefix = "System")]
public IJSResponse GetAllAjaxMethods(IJSRequest request)
{
return new JSResponse(request, this.CoreInstance.AjaxManager.GlobalNamespace.ToDictionary(ajax => ajax.Key, ajax => ajax.Value.JavascriptMethods));
List<object> ajaxMethods = new List<object>();

foreach (KeyValuePair<string, IBaseAjaxNamespace> ajaxNamespace in this.CoreInstance.AjaxManager.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);
}

[AjaxMethod(MethodPrefix = "System")]
Expand Down

0 comments on commit 9908607

Please sign in to comment.