Created
April 6, 2012 22:04
-
-
Save TimHeckel/2323392 to your computer and use it in GitHub Desktop.
Possible implementation of dynamic hubs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Define contracts something like this: | |
public interface ISlateApplicationProvider : IHubDescriptorProvider, IMethodDescriptorProvider | |
{ | |
IList<AppHub> Apps { get; set; } | |
} | |
protected class AppHub | |
{ | |
public string Name { get; set; } | |
public HubDescriptor Descriptor { get; set; } | |
public IEnumerable<MethodDescriptor> Methods { get; set; } | |
} | |
//And then implement something like this: | |
public class SlateApplicationProvider : ISlateApplicationProvider | |
{ | |
private List<AppHub> _apps; | |
public List<AppHub> Apps | |
{ | |
get | |
{ | |
//need to populate my app list from my database and then probably cache it here... | |
_apps.Add(new AppHub() { Name = "Slate", Descriptor = new HubDescriptor() { Name = "Slate", Type = typeof(IHub) }, Methods = new List<MethodDescriptor>() }); | |
return _apps; | |
} | |
set | |
{ | |
_apps = value; | |
} | |
} | |
public IList<HubDescriptor> GetHubs() | |
{ | |
return Apps.Select(h => h.Descriptor).ToList(); | |
} | |
public bool TryGetHub(string hubName, out HubDescriptor descriptor) | |
{ | |
descriptor = Apps.First(h => h.Name == hubName).Descriptor; | |
return true; | |
} | |
public IEnumerable<MethodDescriptor> GetMethods(HubDescriptor hub) | |
{ | |
return Apps.First(h => h.Name == hub.Name).Methods; | |
} | |
public bool TryGetMethod(HubDescriptor hub, string method, out MethodDescriptor descriptor, params Newtonsoft.Json.Linq.JToken[] parameters) | |
{ | |
descriptor = Apps.First(h => h.Name == hub.Name).Methods.First(m => m.Name == method); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment