public TResponse Execute <TResponse>(IApiRequest <TResponse> request, HttpContext context = null) where TResponse : class, IApiResponse, new() { if (this != Instance) { return(Instance.Execute(request, context)); } IApiHandler handler = null; try { var type = typeof(ApiHandler <,>).MakeGenericType(request.GetType(), typeof(TResponse)); handler = this.Resolve <IApiHandler>(type) ?? throw new Exception(); } catch (Exception e) { throw new ResolveException("Resolve Error: " + e.Message); } if (handler == null) { throw new ResolveException("Handler Resolve Failed"); } if (context != null) { handler.HttpContext = context; } try { return(handler.Execute(request) as TResponse); } catch (Exception e) { throw e; } }
public TrelloApiClient(string apiKey, string apiToken) { apiHandler = new ApiHandler(new Uri("https://api.trello.com/1"), apiKey, apiToken); Boards = new BoardsClient(apiHandler); Cards = new CardsClient(apiHandler); Lists = new ListsClient(apiHandler); }
public static string Anonymize(string text, IApiHandler apiHandler) { var analyzerResult = apiHandler.Analyze(text); var anonymizerResponse = apiHandler.Anonymize(text, analyzerResult); return(anonymizerResponse.Text); }
public MainForm(ILogger <MainForm> logger, IApiHandler apiHandler, IMemoryCache cache, LoginForm loginForm) { _logger = logger; _apiHandler = apiHandler; _cache = cache; _loginForm = loginForm; InitializeComponent(); }
/// <summary> /// Initializes a new instance of the <see cref="MainSettingsWindow"/> class. /// </summary> /// <param name="apiHandler">The apiHandler<see cref="IApiHandler"/></param> /// <param name="globalTileStyle">The globalTileStyle<see cref="TileStyle"/></param> public MainSettingsWindow(IApiHandler apiHandler, TileStyle globalTileStyle) { this.InitializeComponent(); this.apiHandler = apiHandler; this.globalTileStyle = globalTileStyle; this.checkBox_Autostart.IsChecked = this.IsStartupItem(); this.InitializeColorPickers(); this.DataContext = new MainSettingsWindowViewModel(this.apiHandler.LoadedApis); }
/// <summary> /// Initializes a new instance of the <see cref="MainWindow"/> class. /// </summary> public MainWindow() { this.InitializeComponent(); this.CheckRunningProcesses(); fileHandler.OnFileHandlerError += this.FileHandler_OnFileHandlerError; this.appData = fileHandler.LoadAppData(); this.apiHandler = new MultiApiHandler(this.appData, apiLoader); this.tileHandler = new WpfTileHandler(this.apiHandler, this.appData); this.mainSettingsWindow = new MainSettingsWindow(this.apiHandler, this.appData.TileHandlerData.GlobalTileStyle); this.tileHandler.OnAppDataChanged += this.OnAppDataChanged; this.menuItem_HideAssetTiles.IsChecked = this.appData.TileHandlerData.GlobalTileStyle.Hidden; this.menuItem_LockTilePositions.IsChecked = this.appData.TileHandlerData.PositionsLocked; this.apiHandler.OnAppDataChanged += this.OnAppDataChanged; }
public NewsManager(IApiHandler apiHandler, IDbGetter dbGetter, IDbSaver dbSaver, ITagService tagService, IEntityConverter entityConverter, IVectorModelBuilder vmBuilder) { this.apiHandler = apiHandler; this.dbGetter = dbGetter; this.dbSaver = dbSaver; this.tagService = tagService; this.entityConverter = entityConverter; this.stopWordsFilter = new StopWordsFilter(); this.porterFilter = new PorterStemmerFilter(); this.vectorModelBuilder = vmBuilder; }
public void Init(TransferBaseContext context) { RouteData routeData = RouteTable.Routes.GetRouteData(context); if (routeData == null) { return; } RequestContext request = new RequestContext() { Context = context, RouteData = routeData }; IApiHandler handler = routeData.RouteHandler.GetApiHandler(request); handler.ProcessRequest(); }
/// <summary> /// Initializes a new instance of the <see cref="WpfTileHandler"/> class. /// </summary> /// <param name="apiHandler">The apiHandler<see cref="IApiHandler"/></param> /// <param name="appData">The appData<see cref="AppData"/></param> public WpfTileHandler(IApiHandler apiHandler, AppData appData) { this.apiHandler = apiHandler; this.activeAssetTiles = new List <IAssetTile>(); this.activePortfolioTiles = new List <IPortfolioTile>(); this.unattachedAssetTiles = new List <IAssetTile>(); this.appData = appData; this.random = new Random(); this.portfolioTileSettingsWindowActive = false; this.OpenLoadedAssetTiles(); this.OpenLoadedPortfolioTiles(); apiLoader.OnApiLoaderError += this.ApiLoader_OnApiLoaderError; apiHandler.OnApiLoaded += this.ApiHandler_OnApiLoaded; apiHandler.LoadApis(); }
/// <summary> /// Use reflection to scan for all available IApiHandler-implementing classes, register them as valid API /// handlers to be created by factory /// <summary> public void Initialize() { try { // Initialize list apiHandlers = new List <IApiHandler>(); // Grab all available types which implement IApiHandler foreach (Type t in Assembly.GetExecutingAssembly().GetTypes().Where(x => x.GetInterfaces().Contains(typeof(IApiHandler)))) { // Discover and instantiate all available apiHandlers IApiHandler instance = (IApiHandler)Activator.CreateInstance(t); logger.IfInfo("Discovered API: " + instance.Name + " -> " + t); this.apiHandlers.Add(instance); } } catch (Exception e) { logger.Error(e); } }
public void Init(HttpBaseContext context) { RouteData routeData = RouteTable.Routes.GetRouteData(context); if (routeData == null) { return; } RequestContext request = new RequestContext() { Context = context, RouteData = routeData }; IApiHandler handler = routeData.RouteHandler.GetApiHandler(request); handler.ProcessRequest(); Console.WriteLine(request.Context.Response.ResponseContent); }
public IResponse Execute(IRequest request, HttpContext context = null) { if (this != Instance) { return(Instance.Execute(request, context)); } IApiHandler handler = null; try { var name = request.GetType().FullName.ToLower(); if (name.EndsWith("request")) { name = name.Substring(0, name.Length - 7); } var type = ApiCache.Instance[name].BaseType; handler = this.Resolve <IApiHandler>(type); } catch (Exception e) { throw new ResolveException("Resolve Error: " + e.Message); } if (handler == null) { throw new ResolveException("Handler Resolve Failed"); } if (context != null) { handler.HttpContext = context; } try { return(handler.Execute(request)); } catch (Exception e) { throw e; } }
public Reports(IApiHandler api) { Api = api; }
public BoardsClient(IApiHandler apiHandler) : base(apiHandler) { }
public async Task StartNodeBinding(IApiHandler api, IWebSocketHandler socket) { apiHandler = api; socketHandler = socket; //apiHandler.DataNodeChanged += HandleNodeChange; try { var nodes = await apiHandler.GetNodes(); //nodes.Select(GetNodeInstance); foreach (var node in nodes.OrderBy(d => d.Name)) { GetNodeInstance(node); //Nodes.Add(realNode); } var containers = await apiHandler.GetContainers(); foreach (var cnt in containers) { var ncnt = new NodeContainer(); ncnt.Parse(cnt); Containers.Add(ncnt); } } catch (HttpRequestException ex) { App.ShowConnectionErrorMessage("Unable to fetch data over http", ex); //await App.Current.MainPage.DisplayAlert("Connection", "Unable to fetch data over http\n\r"+ex.Message, "Wait..."); ScheduleNewDataLoad(); return; //return null; } try { socket.Subscribe("homeninja/conatiners", (JsonMessage message) => { var node = message.Data as JContainer; if (node != null) { var dataCnt = node.ToObject <IEnumerable <DataNodeContainer> >(); foreach (var n in dataCnt) { GetNodeContainerInstance(n); } } }); socket.Subscribe("homeninja/nodechange", (JsonMessage message) => { var node = message.Data as JContainer; if (node != null) { var dataNodes = node.ToObject <IEnumerable <DataNode> >(); foreach (var n in dataNodes) { GetNodeInstance(n); } } }); await socket.StartListening(); } catch (WebSocketException ex) { App.ShowConnectionErrorMessage("Unable to fetch data over websocket", ex); ScheduleNewDataLoad(); } }
public void RegisterAPIHandler(IApiHandler handler) { }
public Goals(IApiHandler api) { Api = api; }
public Status(IApiHandler api) { Api = api; }
public Archives(IApiHandler api) { Api = api; }
public Greetings(IApiHandler api) { Api = api; }
public Webhooks(IApiHandler api) { Api = api; }
public ApiHandlersPool(IApiHandler apiHandler) { ApiHandler = apiHandler; }
public ListsClient(IApiHandler apiHandler) : base(apiHandler) { }
public Chat(IApiHandler api) { Api = api; }
public Tickets(IApiHandler api) { Api = api; }
public Groups(IApiHandler api) { Api = api; }
public BingSearchService(IApiHandler apiHandler) { SetField.NotNull(out this.apiHandler, nameof(apiHandler), apiHandler); }
public Agents(IApiHandler api) { Api = api; }
public CannedResponses(IApiHandler api) { Api = api; }
public Visitors(IApiHandler api) { Api = api; }
public ChartApiService(IApiHandler _apihandler) { apiHandler = _apihandler; httpClient = new HttpClient(apiHandler.GetHandler()); }
// Process API calls based on the class's HTTP URL private void ApiProcess() { // The API request wrapper UriWrapper uri = new UriWrapper(this.HttpUrl, this.HttpMethod); // The user who is accessing the API User apiUser = null; // The handler being accessed IApiHandler api = null; // No API request found? Serve web UI if (!uri.IsApiCall) { api = Injection.Kernel.Get <IApiHandlerFactory>().CreateApiHandler("web"); api.Process(uri, this, apiUser); return; } // Get client IP address string ip = ((IPEndPoint)this.Socket.Client.RemoteEndPoint).Address.ToString(); // Check for valid API action ("web" and "error" are technically valid, but can't be used in this way) if (uri.ApiAction == null || uri.ApiAction == "web" || uri.ApiAction == "error") { ErrorApiHandler errorApi = (ErrorApiHandler)Injection.Kernel.Get <IApiHandlerFactory>().CreateApiHandler("error"); errorApi.Process(uri, this, apiUser, "Invalid API call"); logger.IfInfo(String.Format("[{0}] API: {1}", ip, this.HttpUrl)); return; } // Check for session cookie authentication, unless this is a login request string sessionId = null; if (uri.ApiAction != "login") { sessionId = this.GetSessionCookie(); apiUser = Injection.Kernel.Get <IApiAuthenticate>().AuthenticateSession(sessionId); } // If no cookie, try parameter authentication if (apiUser == null) { apiUser = Injection.Kernel.Get <IApiAuthenticate>().AuthenticateUri(uri); // If user still null, failed authentication, so serve error if (apiUser == null) { ErrorApiHandler errorApi = (ErrorApiHandler)Injection.Kernel.Get <IApiHandlerFactory>().CreateApiHandler("error"); errorApi.Process(uri, this, apiUser, "Authentication failed"); logger.IfInfo(String.Format("[{0}] API: {1}", ip, this.HttpUrl)); return; } } // apiUser.SessionId will be generated on new login, so that takes precedence for new session cookie apiUser.SessionId = apiUser.SessionId ?? sessionId; this.SetSessionCookie(apiUser.SessionId); // Store user's current session object apiUser.CurrentSession = Injection.Kernel.Get <ISessionRepository>().SessionForSessionId(apiUser.SessionId); // Retrieve the requested API handler by its action IApiHandler apiHandler = Injection.Kernel.Get <IApiHandlerFactory>().CreateApiHandler(uri.ApiAction); // Check for valid API action if (apiHandler == null) { ErrorApiHandler errorApi = (ErrorApiHandler)Injection.Kernel.Get <IApiHandlerFactory>().CreateApiHandler("error"); errorApi.Process(uri, this, apiUser, "Invalid API call"); logger.IfInfo(String.Format("[{0}] API: {1}", ip, this.HttpUrl)); return; } // Log API call logger.IfInfo(String.Format("[{0}/{1}@{2}] API: {3} {4}", apiUser.UserName, apiUser.CurrentSession.ClientName, ip, this.HttpMethod, this.HttpUrl)); // Check if user has appropriate permissions for this action on this API handler if (!apiHandler.CheckPermission(apiUser, uri.Action)) { ErrorApiHandler errorApi = (ErrorApiHandler)Injection.Kernel.Get <IApiHandlerFactory>().CreateApiHandler("error"); errorApi.Process(uri, this, apiUser, "Permission denied"); return; } // Finally, process and return results apiHandler.Process(uri, this, apiUser); }
public Tags(IApiHandler api) { Api = api; }