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);
        }
Exemple #2
0
        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);
            }
        }