Ejemplo n.º 1
0
        public void IncrementWindow(string title, int lastAction, int timeInc)
        {
            if (Windows.All(o => o.Title != title))
            {
                var timeSlot = new TimeSlot(title);
                timeSlot.PropertyChanged += TimeSlot_PropertyChanged;
                timeSlot.Seconds          = timeInc;
                Windows.Add(timeSlot);
                return;
            }

            foreach (var timeSlot in Windows.Where(timeSlot => timeSlot.Title == title))
            {
                if (lastAction < 1)
                {
                    timeSlot.Seconds += timeInc;
                    timeSlot.TransferPotentialTime();
                }
                else
                {
                    timeSlot.PotentialSeconds += timeInc;
                }

                break;
            }

            PropChanged("IncludedTime");
            PropChanged("ExcludedTime");
            PropChanged("TotalTime");
        }
Ejemplo n.º 2
0
        public void Update(WindowUpdate windowUpdate)
        {
            if (_isDisposed)
            {
                return;
            }

            lock (_listLock)
            {
                foreach (var windowInformation in windowUpdate.UpdatedWindows)
                {
                    Windows.FirstOrDefault(x => x.Handle == windowInformation.Handle)?.UpdateData(windowInformation);
                }

                foreach (var windowInformation in windowUpdate.NewWindows)
                {
                    if (Windows.All(x => x.Handle != windowInformation.Handle))
                    {
                        Windows.Add(new WindowRenderInfo(windowInformation));
                    }
                }

                foreach (var windowToRemove in Windows.Where(x => !windowUpdate.AllWindows.Contains(x.Handle)).ToList()) //ToList is important to allow removing from the list
                {
                    Windows.Remove(windowToRemove);
                }

                Windows =
                    new List <WindowRenderInfo>(windowUpdate.AllWindows.Where(
                                                    x => Windows.Any(y => y.Handle == x))
                                                .Select(x => Windows.FirstOrDefault(y => y.Handle == x)));

                /*var windowsIndex = 0;
                 * for (int i = 0; i < windowUpdate.AllWindows.Count; i++)
                 * {
                 *  var windowHandle = windowUpdate.AllWindows[i];
                 *  var existingWindow = Windows.FirstOrDefault(x => x.Handle == windowHandle);
                 *  if (existingWindow == null)
                 #if DEBUG
                 *      throw new Exception("Window does not exist");
                 #else
                 *      continue;
                 #endif
                 *
                 *  Windows.Move(Windows.IndexOf(existingWindow), windowsIndex);
                 *  windowsIndex++;
                 * }*/

                if (windowUpdate.RenderedWindow != null)
                {
                    var windowToUpdate = Windows.FirstOrDefault(x => x.Handle == windowUpdate.RenderedWindowHandle);
                    windowToUpdate?.UpdateImage(windowUpdate.RenderedWindow);
                }
            }

            _updateReceivedAutoResetEvent.Set();
        }
Ejemplo n.º 3
0
        public void IncrementWindow(string title, int lastAction, int timeInc)
        {
            //Couldn't find any existing title
            if (Windows.All(o => o.Title != title))
            {
                var timeSlot = new TimeSlot(title);
                timeSlot.PropertyChanged += TimeSlot_PropertyChanged;
                timeSlot.Seconds          = timeInc;
                Windows.Add(timeSlot);

                if (Properties.Settings.Default.Autosort)
                {
                    Windows.BubbleSort();
                }
                return;
            }

            foreach (var timeSlot in Windows.Where(timeSlot => timeSlot.Title == title))
            {
                if (lastAction < 1)
                {
                    timeSlot.Seconds += timeInc;
                    timeSlot.TransferPotentialTime();
                }
                else
                {
                    timeSlot.PotentialSeconds += timeInc;
                }

                break;
            }

            if (Properties.Settings.Default.Autosort)
            {
                Windows.BubbleSort();
            }

            PropChanged("IncludedTime");
            PropChanged("ExcludedTime");
            PropChanged("TotalTime");
            PropChanged("FilterIncluded");
        }
Ejemplo n.º 4
0
        public void UpdateWindows(WindowUpdate windowUpdate, byte[] data, int index)
        {
            lock (_windowsLock)
            {
                foreach (var updatedWindow in windowUpdate.UpdatedWindows)
                {
                    Windows.FirstOrDefault(x => x.Handle == updatedWindow.Handle)?.UpdateData(updatedWindow);
                }

                foreach (var newWindow in windowUpdate.NewWindows)
                {
                    if (Windows.All(x => x.Handle != newWindow.Handle))
                    {
                        Windows.Add(new RenderWindow(newWindow));
                    }
                }

                var windowsToRemove = Windows.Where(x => !windowUpdate.AllWindows.Contains(x.Handle)).ToList();
                foreach (var removedWindow in windowsToRemove)
                {
                    Windows.Remove(removedWindow);
                    removedWindow.Dispose();
                }

                if (data.Length != index)
                {
                    Windows.FirstOrDefault(x => x.Handle == windowUpdate.RenderedWindowHandle)?
                    .UpdateImage(data, index, (uint)(data.Length - index));
                }

                //order windows
                Windows =
                    Windows.OrderBy(
                        x => windowUpdate.AllWindows.IndexOf(windowUpdate.AllWindows.FirstOrDefault(y => x.Handle == y)))
                    .ToList();
                RenderApplications();
            }

            WindowsUpdated?.Invoke(this, EventArgs.Empty);
        }
Ejemplo n.º 5
0
        public void Update(WindowPackage windowUpdate)
        {
            if (_isDisposed)
            {
                return;
            }

            lock (_listLock)
            {
                foreach (var windowInformation in windowUpdate.Windows)
                {
                    Windows.FirstOrDefault(x => x.Handle == windowInformation.Handle)?.UpdateData(windowInformation);
                }

                foreach (var windowInformation in windowUpdate.Windows)
                {
                    if (Windows.All(x => x.Handle != windowInformation.Handle))
                    {
                        Windows.Add(new WindowRenderInfo(windowInformation));
                    }
                }

                foreach (var windowToRemove in Windows.Where(x => windowUpdate.Windows.All(y => y.Handle != x.Handle)).ToList()) //ToList is important to allow removing from the list
                {
                    Windows.Remove(windowToRemove);
                }

                if (windowUpdate.WindowData != null)
                {
                    var windowToUpdate = Windows.FirstOrDefault(x => x.Handle == windowUpdate.WindowHandle);
                    windowToUpdate?.UpdateImage(windowUpdate.WindowData);
                }
            }

            _updateReceivedAutoResetEvent.Set();
        }
Ejemplo n.º 6
0
        private void RenderApplications()
        {
            if (Windows.Count == 0 || Windows.All(x => x.Image == null))
            {
                ApplicationsBitmap = null;
                return;
            }

            var imageX = Windows.Min(x => x.X);
            var imageY = Windows.Min(x => x.Y);

            var height = 0;
            var width  = 0;

            IntPtr backBuffer       = IntPtr.Zero;
            int    backBufferStride = 0;

            var renderWindowInfos = new List <WindowRenderInfo>();

            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
            {
                height = Windows.Max(x => x.Y + x.Image?.PixelHeight ?? 0) - imageY;
                width  = Windows.Max(x => x.X + x.Image?.PixelWidth ?? 0) - imageX;

                if (ApplicationsBitmap == null || _applicationsBitmapHeight != height || _applicationsBitmapWidth != width)
                {
                    ApplicationsBitmap        = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr32, null);
                    _applicationsBitmapHeight = height;
                    _applicationsBitmapWidth  = width;
                }

                ApplicationsBitmap.Lock();
                backBuffer       = ApplicationsBitmap.BackBuffer;
                backBufferStride = ApplicationsBitmap.BackBufferStride;

                foreach (var window in Windows)
                {
                    if (window.Image == null)
                    {
                        continue;
                    }

                    renderWindowInfos.Add(new WindowRenderInfo(window));
                }
            })).Wait();

            //important: always update, regardless if the image size was changed
            _applicationBitmapLeft = imageX;
            _applicationBitmapTop  = imageY;

            var pixelSize   = 4;
            var imageLength = backBufferStride * _applicationsBitmapHeight;

            CoreMemoryApi.memset(backBuffer, 0, (UIntPtr)imageLength);

            unsafe
            {
                var applicationImagePtr = (byte *)backBuffer;

                foreach (var renderWindowInfo in renderWindowInfos)
                {
                    var windowX = renderWindowInfo.RenderWindow.X - imageX;
                    var windowY = renderWindowInfo.RenderWindow.Y - imageY;

                    fixed(byte *bufferPtr = renderWindowInfo.Buffer)
                    for (int j = 0; j < renderWindowInfo.Height; j++)
                    {
                        var positionImage = (windowY + j) * backBufferStride + windowX * pixelSize;

                        CoreMemoryApi.memcpy(applicationImagePtr + positionImage,
                                             bufferPtr + j * renderWindowInfo.Stride,
                                             (UIntPtr)renderWindowInfo.Stride);
                    }
                }
            }

            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
            {
                ApplicationsBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
                ApplicationsBitmap.Unlock();
            })).Wait();
        }