Example #1
0
        public void CompareGetHandles()
        {
            TraceFile.SetName("CompareGetHandles");
            var list1 = new List <IntPtr>();
            var list2 = new List <IntPtr>();

            var intPtrComparer = new IntPtrComparer();

            list1.AddRange(Win32Window.GetHandles());
            list2.AddRange(Win32Window.GetHandles2());

            list1.Sort(intPtrComparer);
            list2.Sort(intPtrComparer);

            TraceFile
            .Get("CompareGetHandles-List1")
            .Each(list1, (trace, handle) => trace.OutLine(handle.ToRepr()))
            .Close()
            ;
            TraceFile
            .Get("CompareGetHandles-List2")
            .Each(list2, (trace, handle) => trace.OutLine(handle.ToRepr()))
            .Close()
            ;

            CollectionAssert.AreEqual(list1, list2);
        }
Example #2
0
        protected override void InitServicesPost()
        {
            base.InitServicesPost();
            TraceFile.SetName("Fenester.Exe.InteractiveTest");
            int count = 0;

            Action testAction = () =>
            {
                this.LogLine("  Shortcut called ({0})", count);
                count++;
            };
            Action desktopAction = () =>
            {
                foreach (var screen in ScreenOsService.Use.GetScreens())
                {
                    this.LogLine("Screen [{0}][{1}] [{2}]", screen.Id, screen.Name, screen.Rectangle.Canonical);
                }
            };
            Action enumerateWindowsOperationAsync = async() =>
            {
                using (var markdownTraceFile = TraceFile.Get("windows", "md").SetIncludeTimestamp(false))
                {
                    var windows = (await WindowOsService.Use.GetWindows()).Where(window => window.OsVisibility != Visibility.None);
                    this.LogLine("    **** Windows : Start");
                    markdownTraceFile.OutLine("| Title | Position | OS Visibility | Category | Class |");
                    markdownTraceFile.OutLine("| --- | --- | --- | --- | --- |");
                    foreach (var window in windows)
                    {
                        if (window.Rectangle != null && window.Rectangle.Size.Height != 0 && window.Rectangle.Size.Width != 0 && window.Title != null)
                        {
                            markdownTraceFile.OutLine("| {0} | {1} | {2} | {3} | {4} |", window?.Title?.Replace("\\", "\\\\"), window.Rectangle.Canonical, window.OsVisibility, window.Category, window?.Class?.Replace("\\", "\\\\"));
                            this.LogLine("      => {2} [{0}] ({1}) {3} [{4}]", window.Title, window.Rectangle.Canonical, window.OsVisibility, window.Category, window.Class);
                        }
                    }
                    this.LogLine("    **** Windows : Stop");
                }
            };
            Action focusWindowAction = async() =>
            {
                var window = await GetWindow();

                if (window != null)
                {
                    this.LogLine("Focusing {0} ({1})", window.Title, window.Rectangle.Canonical);
                    await WindowOsService.Use.FocusWindow(window);
                }
                else
                {
                    this.LogLine("No window to focus");
                }
            };
            Action <int, int, int, int> moveWindowAction = async(int width, int height, int left, int top) =>
            {
                var window = await GetWindow();

                if (window != null)
                {
                    this.LogLine("Move+Resize {0} ({1})", window.Title, window.Rectangle.Canonical);
                    await WindowOsService.Use.Move(window, new Rectangle(width, height, left, top));
                }
                else
                {
                    this.LogLine("No window to move");
                }
            };

            this.LogLine("Start main call");
            RegisterAction("S", KeyModifier.Alt, "Quit", () => RunService.Use.Stop());
            RegisterAction("N", KeyModifier.Alt, "Test", testAction);
            RegisterAction("E", KeyModifier.Alt, "EnumerateWindows", () => enumerateWindowsOperationAsync());
            RegisterAction("D", KeyModifier.Alt, "Desktop", desktopAction);
            RegisterAction("F", KeyModifier.Alt, "Focus Window", focusWindowAction);
            RegisterAction("M", KeyModifier.Alt, "Move Window", () => moveWindowAction(500, 800, 50, 50));
            RegisterAction("P", KeyModifier.Alt, "Move Window 2", () => moveWindowAction(800, 500, 300, 500));
            this.LogLine("Stop main call");
        }