public IEnumerable <Translation> GetAll() { var translations = _keyValueCache.Get(CacheKey); if (translations == null) { _keyValueCache.Add(CacheKey, _session.Query <Translation>().ToList()); } return(_keyValueCache.Get(CacheKey)); }
public Process GetProcessFromWindowHandle(IntPtr handle) { const string applicationFrameHostName = "ApplicationFrameHost"; var process = windowProcessCache.Get(handle); if (process != default && process.ProcessName != applicationFrameHostName) { return(process); } windowNativeApi.GetWindowThreadProcessId(handle, out var processId); if (processId == CurrentProcessInformation.CurrentProcess.Id) { return(CurrentProcessInformation.CurrentProcess); } process = Process.GetProcessById((int)processId); if (process.ProcessName == applicationFrameHostName) { process = GetProcessFromUniversalWindowsApplication(handle, process); } windowProcessCache.Set(handle, process); return(process); }
private async Task <string> GetQueryData(string fileName) { if (_cache != null) { var queryStr = await _cache.Get(fileName); if (queryStr != null) { return(queryStr); } } // Get the full query file as provided by the configuration var fullPath = Path.Combine(_rootQueriesDir, $"{fileName}.sql"); if (!File.Exists(fullPath)) { // Lookup in the current path if not found in the root path: var relativePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fullPath); if (!File.Exists(relativePath)) { throw new FileNotFoundException($"DatabaseWrapper - Query file not found: {fullPath}. Relative lookup failed as well: {relativePath}"); } fullPath = relativePath; } byte[] buffer = null; using (var fs = File.OpenRead(fullPath)) { buffer = new byte[fs.Length]; await fs.ReadAsync(buffer, 0, buffer.Length); } var contents = Encoding.UTF8.GetString(buffer); if (_cache != null) { await _cache.Set(fileName, contents); } return(contents); }
public Process GetProcessFromWindowHandle(IntPtr handle) { var process = windowProcessCache.Get(handle); if (process != default) { return(process); } windowNativeApi.GetWindowThreadProcessId(handle, out var processId); if (processId == CurrentProcessInformation.CurrentProcess.Id) { return(CurrentProcessInformation.CurrentProcess); } process = Process.GetProcessById((int)processId); windowProcessCache.Set(handle, process); return(process); }
public async Task <IDataSource> GetDataSourceAsync() { var activeWindowHandle = activeWindowService.ActiveWindowHandle; var activeWindowTitle = activeWindowService.GetWindowTitleFromWindowHandle(activeWindowHandle); var process = activeWindowService.GetProcessFromWindowHandle(activeWindowHandle); var processName = process.ProcessName + ".exe"; var iconBytesBig = dataSourceIconCacheLarge.Get(activeWindowHandle); if (iconBytesBig == null) { var windowIconBig = await GetWindowIconAsync(process, activeWindowHandle); iconBytesBig = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIconBig); dataSourceIconCacheLarge.Set(activeWindowHandle, iconBytesBig); } var iconBytesSmall = dataSourceIconCacheSmall.Get(activeWindowHandle); if (iconBytesSmall == null) { var windowIconSmall = await GetWindowIconAsync(process, activeWindowHandle, false); iconBytesSmall = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIconSmall); dataSourceIconCacheSmall.Set(activeWindowHandle, iconBytesSmall); } var dataSource = new DataSource( iconBytesBig, iconBytesSmall, activeWindowTitle, processName); return(dataSource); }
public IDataSource GetDataSource() { lock (this) { var activeWindowHandle = activeWindowService.ActiveWindowHandle; var processName = activeWindowService. GetProcessFromWindowHandle(activeWindowHandle) .ProcessName + ".exe"; var iconBytesBig = dataSourceIconCacheLarge.Get(activeWindowHandle); if (iconBytesBig == null) { var windowIconBig = GetWindowIcon(activeWindowHandle); iconBytesBig = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIconBig); dataSourceIconCacheLarge.Set(activeWindowHandle, iconBytesBig); } var iconBytesSmall = dataSourceIconCacheSmall.Get(activeWindowHandle); if (iconBytesSmall == null) { var windowIconSmall = GetWindowIcon(activeWindowHandle, false); iconBytesSmall = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIconSmall); dataSourceIconCacheSmall.Set(activeWindowHandle, iconBytesSmall); } var dataSource = new DataSource( iconBytesBig, iconBytesSmall, activeWindowService.GetWindowTitleFromWindowHandle(activeWindowHandle), processName); return(dataSource); } }