Beispiel #1
0
        private void active_worker()
        {
            int           chars = 256;
            StringBuilder buff  = new StringBuilder(chars);

            while (true)
            {
                if (!Global.isRunning)
                {
                    break;
                }

                if (Global.toNavi != "")
                {
                    wActive       = Global.toNavi;
                    Global.toNavi = "";
                    backgroundWorker1.ReportProgress(10);
                    Thread.Sleep(500);
                    continue;
                }

                string f = WindowWatcher.FetchFileName();
                if (f != string.Empty && f != null)
                {
                    wActive = f;
                    backgroundWorker1.ReportProgress(10);
                }

                Thread.Sleep(500);
            }
        }
        private void OldProcessSetup()
        {
            Process pptProcess  = GetChildProcess(GetTestingSlideName());
            Process mainProcess = GetMainProcessAndCloseOthers(pptProcess);

            WindowWatcher.Setup(mainProcess, pptProcess, Constants.pptProcess);
            InitWhiteList();
        }
        /// <summary>
        /// Postpones the process startup to have better control on waiting for the process to
        /// finish starting up.
        /// </summary>
        /// <param name="process">Process that windows will eventually reside on</param>
        /// <param name="childProcess">Process to be started</param>
        private void InitWhiteList()
        {
            string fileName = GetTestingSlideName().After("\\");

            WindowWatcher.AddToWhitelist(fileName + " - Microsoft PowerPoint");
            WindowWatcher.AddToWhitelist(fileName + " - PowerPoint");
            WindowWatcher.AddToWhitelist("PowerPointLabs FT");
            WindowWatcher.AddToWhitelist("Loading...");
        }
Beispiel #4
0
 private void CopyStyle(ISyncLabController syncLab, int[,] dialogItems)
 {
     WindowWatcher.Push("Copy Format", syncLab.Copy);
     for (int i = 0; i < dialogItems.GetLength(0); i++)
     {
         syncLab.DialogSelectItem(dialogItems[i, CategoryIndexPosition], dialogItems[i, FormatItemIndexPosition]);
     }
     WindowWatcher.Pop(syncLab.DialogClickOk);
 }
        private void NewProcessSetup()
        {
            string exePath = Properties.Settings.Default.PowerPoint_path;

            if (exePath == null || exePath.Length == 0)
            {
                OldProcessSetup();
                return;
            }
            PPTProcessWrapper pptProcessWrapper =
                new PPTProcessWrapper(exePath,
                                      GetTestingSlideName(), PathUtil.GetDocTestPath());
            Process mainProcess = GetMainProcessAndCloseOthers(null);

            WindowWatcher.Setup(mainProcess, pptProcessWrapper, Constants.pptProcess);
            InitWhiteList();
        }
Beispiel #6
0
        public static void Shutdown()
        {
            GeckoPreferences.Shutdown();
            WindowWatcher.Shutdown();
            WindowMediator.Shutdown();

            PromptFactoryFactory.Shutdown();
            Xpcom.DisposeObject(ref _comGC);

            if (Xpcom.ChromeContext != null)
            {
                Xpcom.ChromeContext.Dispose();
                Xpcom.ChromeContext = null;
            }

            if (ComponentRegistrar != null)
            {
                Marshal.ReleaseComObject(ComponentRegistrar);
            }

            if (ComponentManager != null)
            {
                Marshal.ReleaseComObject(ComponentManager);
            }

            if (ServiceManager != null)
            {
                var s = GetService <nsIObserverService>("@mozilla.org/observer-service;1");
                s.NotifyObservers(null, "profile-change-net-teardown", "shutdown-persist");
                s.NotifyObservers(null, "profile-change-teardown", "shutdown-persist");
                s.NotifyObservers(null, "profile-before-change", "shutdown-persist");
                s.NotifyObservers(null, "profile-before-change2", "shutdown-persist");
                Marshal.ReleaseComObject(s);

                // NS_ShutdownXPCOM calls Release on the ServiceManager COM objects.
                // However since the ServiceManager is a __ComObject its finaliser will also call release.
                var ptr = Marshal.GetIUnknownForObject(ServiceManager);
                NS_ShutdownXPCOM(ServiceManager);
                Marshal.ReleaseComObject(ServiceManager);
            }

            _IsInitialized = false;
        }
 public void TearDown()
 {
     if (TestContext.CurrentTestOutcome != UnitTestOutcome.Passed)
     {
         if (!Directory.Exists(PathUtil.GetTestFailurePath()))
         {
             Directory.CreateDirectory(PathUtil.GetTestFailurePath());
         }
         PpOperations.SavePresentationAs(
             PathUtil.GetTestFailurePresentationPath(
                 TestContext.TestName + "_" +
                 GetTestingSlideName()));
     }
     while (PpOperations.GetNumWindows() > 0)
     {
         PpOperations.ClosePresentation();
     }
     WindowWatcher.RevalidateApp(); // to prevent next test from failing
     TeardownWindowWatching();
 }
        public void Setup()
        {
            CultureUtil.SetDefaultCulture(CultureInfo.GetCultureInfo("en-US"));
            try
            {
                App = new PowerPoint.Application();
            }
            catch (COMException)
            {
                // in case a warm-up is needed
                App = new PowerPoint.Application();
            }
            Pres = App.Presentations.Open(
                PathUtil.GetDocTestPath() + GetTestingSlideName(),
                WithWindow: MsoTriState.msoFalse);
            PpOperations = new UnitTestPpOperations(Pres, App);
            PPLClipboard.Init(PpOperations.Window, true);
            int processId = Process.GetCurrentProcess().Id;

            WindowWatcher.HeadlessSetup(processId);
        }
Beispiel #9
0
        public void FT_LimitOpenPanesTest()
        {
            WindowWatcher.AddToWhitelist("Presentation1 - PowerPoint");
            WindowWatcher.AddToWhitelist("Presentation1 - Microsoft PowerPoint");
            // start clean
            StartWithNumWindows(2);

            // opening <= 2 panes should work as per normal
            Open(Pane.ColorsLabPane);
            Open(Pane.SyncPane);
            SwitchToWindow(2);

            // Check if old pane is removed
            SwitchToWindow(1);
            Open(Pane.PositionsPane);
            SwitchToWindow(2);

            // Test panes across windows
            Open(Pane.ELearningLabTaskpane);
            Open(Pane.CustomShapePane);
            Open(Pane.PositionsPane);
            SwitchToWindow(1);
        }
Beispiel #10
0
        public void FT_QuickPropertyTest()
        {
            PpOperations.SelectSlide(4);

            Microsoft.Office.Interop.PowerPoint.Shape shape = PpOperations.SelectShape("ffs")[1];

            int x = PpOperations.PointsToScreenPixelsX(shape.Left + shape.Width / 2);
            int y = PpOperations.PointsToScreenPixelsY(shape.Top + shape.Height / 2);

            WindowWatcher.AddToWhitelist("Format Shape");
            MouseUtil.SendMouseDoubleClick(x, y);
            ThreadUtil.WaitFor(2000);

            if (PpOperations.IsOffice2010())
            {
                // AKA property handle
                IntPtr formatObjHandle = NativeUtil.FindWindow("NUIDialog", "Format Shape");
                Assert.AreNotEqual(IntPtr.Zero, formatObjHandle, "Failed to find Property handle.");

                NativeUtil.SendMessage(formatObjHandle, 0x10 /*WM_CLOSE*/, IntPtr.Zero, IntPtr.Zero);
            }
            else // for Office 2013 or higher
            {
                // Spy++ helps to look into the handles
                IntPtr pptHandle = NativeUtil.FindWindow("PPTFrameClass", null);
                Assert.AreNotEqual(IntPtr.Zero, pptHandle, "Failed to find PowerPoint handle.");

                IntPtr dockRightHandle =
                    NativeUtil.FindWindowEx(pptHandle, IntPtr.Zero, "MsoCommandBarDock", "MsoDockRight");
                Assert.AreNotEqual(IntPtr.Zero, dockRightHandle, "Failed to find Dock Right handle.");

                // AKA property handle
                IntPtr formatObjHandle =
                    NativeUtil.FindWindowEx(dockRightHandle, IntPtr.Zero, "MsoCommandBar", "Format Object");
                Assert.AreNotEqual(IntPtr.Zero, formatObjHandle, "Failed to find Property handle.");
            }
        }
Beispiel #11
0
        public static void Shutdown()
        {
            GeckoPreferences.Shutdown();
            WindowWatcher.Shutdown();
            WindowMediator.Shutdown();

            PromptFactoryFactory.Shutdown();
            Xpcom.DisposeObject(ref _comGC);

            if (Xpcom.ChromeContext != null)
            {
                Xpcom.ChromeContext.Dispose();
                Xpcom.ChromeContext = null;
            }

            if (ComponentRegistrar != null)
            {
                Marshal.ReleaseComObject(ComponentRegistrar);
            }

            if (ComponentManager != null)
            {
                Marshal.ReleaseComObject(ComponentManager);
            }

            if (ServiceManager != null)
            {
                // NS_ShutdownXPCOM calls Release on the ServiceManager COM objects.
                // However since the ServiceManager is a __ComObject its finaliser will also call release.
                var ptr = Marshal.GetIUnknownForObject(ServiceManager);
                NS_ShutdownXPCOM(ServiceManager);
                Marshal.ReleaseComObject(ServiceManager);
            }

            _IsInitialized = false;
        }
Beispiel #12
0
        private static bool Launch(Account account, LaunchMode mode, FileInfo fi)
        {
            string username = Util.Users.GetUserName(account.Settings.WindowsAccount);
            Account _active = GetActiveAccount(username);
            if (_active != null)
            {
                //the user's account is already in use, however, if the same dat file is being used, it doesn't matter
                if (_active.Settings.DatFile != account.Settings.DatFile)
                    throw new UserAlreadyActiveException(username);
            }

            switch (mode)
            {
                case LaunchMode.Update:
                    account.SetState(AccountState.Updating, true);
                    break;
                case LaunchMode.UpdateVisible:
                    account.SetState(AccountState.UpdatingVisible, true);
                    break;
                default:
                    account.SetState(AccountState.Launching, true);
                    break;
            }

            byte retries = 0;

            do
            {
                try
                {
                    DatManager.Activate(account.Settings);
                    break;
                }
                catch (DatManager.UserAccountNotInitializedException e)
                {
                    if (retries++ > 0)
                    {
                        throw e;
                    }

                    var password = Security.Credentials.GetPassword(username);
                    if (password == null)
                        throw new BadUsernameOrPasswordException();
                    try
                    {
                        Util.ProcessUtil.InitializeAccount(username, password);
                    }
                    catch { }
                }
            }
            while (true);

            if (mode == LaunchMode.Launch && !account.Settings.DatFile.IsInitialized)
            {
                throw new DatFileNotInitialized();
            }

            KillMutex();

            var startInfo = GetProcessStartInfo(account.Settings, mode, fi);
            var isWindowed = IsWindowed(account.Settings);

            retries = 0;

            do
            {
                Process gw2 = account.Process.Launch(startInfo);
                lastLaunch = new QueuedLaunch(account, mode);

                if (AccountProcessChanged != null)
                    AccountProcessChanged(account.Settings, gw2);

                if (!gw2.WaitForExit(2000))
                {
                    if (mode == LaunchMode.Launch || mode == LaunchMode.LaunchSingle)
                        account.SetState(AccountState.Active, true, gw2);

                    if (!gw2.HasExited)
                    {
                        lock (unknownProcesses)
                        {
                            activeProcesses++;
                            OnActiveProcessCountChanged();
                        }

                        if (mode == LaunchMode.LaunchSingle)
                        {
                            account.Settings.DatFile.IsInitialized = true;
                        }

                        if (!IsUpdate(mode))
                        {
                            if (isWindowed)
                            {
                                WindowWatcher watcher = new WindowWatcher(account, gw2);
                                watcher.WindowChanged += OnWatchedWindowChanged;
                            }

                            if (AccountLaunched != null)
                                AccountLaunched(account.Settings);

                            EventHandler<Account> onExit = null;
                            onExit = delegate(object o, Account a)
                            {
                                a.Exited -= onExit;
                                if (AccountExited != null)
                                    AccountExited(a.Settings);
                            };
                            lock (queueExit)
                            {
                                if (account.State == AccountState.Active)
                                    account.Exited += onExit;
                            }
                        }
                    }

                    return true;
                }
                else
                {
                    double duration = gw2.ExitTime.Subtract(gw2.StartTime).TotalSeconds;
                    bool isUpdate = IsUpdate(mode);

                    if (isUpdate || duration < 1) //(IsUpdate(mode) && duration < 0.5 || !IsUpdate(mode) && duration < 1)
                    {
                        //GW2 was likely closed due to another copy running, or the client is being updated

                        Thread.Sleep(500);

                        Task t = taskScan;
                        if (t != null)
                        {
                            try
                            {
                                t.Wait();
                            }
                            catch { }
                        }

                        if (isUpdate)
                        {
                            return true;
                        }
                        else if (account.Process.Process != null)
                        {
                            //was handled by taskScan
                            //assuming GW2 closed itself, restarted and that process was attached
                            return true;
                        }
                        else
                        {
                            //don't try to restart the process if the queue has been killed
                            if (cancelQueue != null && cancelQueue.IsCancellationRequested)
                                break;

                            //assuming GW2 failed to open due to another instance running
                            //try to kill any other accounts prior to trying administrative access
                            if (!KillMutex())
                            {
                                retries++;

                                try
                                {
                                    //try killing the mutex using admin rights
                                    if (retries == 1)
                                    {
                                        Util.ProcessUtil.KillMutexWindow(fi.FullName);
                                    }
                                    else if (retries == 2)
                                    {
                                        Util.ProcessUtil.KillMutexWindowByProcessName(fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length));
                                    }
                                }
                                catch
                                {
                                    //failed or cancelled
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        //AccountStateChanged handled by process exit
                        return true;
                    }
                }
            }
            while (retries < 3);

            account.SetState(AccountState.None, true);

            return false;
        }
Beispiel #13
0
        private static void Scan(FileInfo fi)
        {
            int startTime = Environment.TickCount;
            Process[] ps = Process.GetProcessesByName(fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length));

            foreach (Process p in ps)
            {
                try
                {
                    string path = null,
                           commandLine = null,
                           query = string.Format("SELECT ExecutablePath, CommandLine FROM Win32_Process WHERE ProcessId={0}", p.Id);

                    using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
                    {
                        using (ManagementObjectCollection results = searcher.Get())
                        {
                            foreach (ManagementObject o in results)
                            {
                                path = o["ExecutablePath"] as string;
                                commandLine = o["CommandLine"] as string;
                                break;
                            }
                        }
                    }

                    if (string.Equals(path, fi.FullName, StringComparison.OrdinalIgnoreCase))
                    {
                        bool isUnknown = false;

                        lock (accounts)
                        {
                            Account account = LinkedProcess.GetAccount(p);

                            if (account == null)
                            {
                                int uqid = -1;

                                try
                                {
                                    //string commandLine = GetProcessCommandLine(p);
                                    if (commandLine != null)
                                        uqid = GetUIDFromCommandLine(commandLine);
                                }
                                catch { }

                                if (uqid == -1)
                                {
                                    isUnknown = true;
                                }
                                else
                                {
                                    ushort uid = (ushort)uqid;

                                    if (!accounts.TryGetValue(uid, out account))
                                    {
                                        if (Settings.Accounts.Contains(uid))
                                        {
                                            account = new Account(Settings.Accounts[uid].Value);
                                            account.Process.Changed += LinkedProcess_Changed;
                                            accounts.Add(account.Settings.UID, account);

                                            //this program was exited before the account was
                                            //- assuming this process should trigger the exit event
                                            EventHandler<Account> onExit = null;
                                            onExit = delegate(object o, Account a)
                                            {
                                                a.Exited -= onExit;
                                                if (AccountExited != null)
                                                    AccountExited(a.Settings);
                                            };
                                            account.Exited += onExit;
                                        }
                                    }

                                    if (account != null)
                                    {
                                        if (!account.IsActive)
                                            account.SetState(AccountState.Active, true, p);

                                        account.Process.Attach(p);

                                        if (IsWindowed(account.Settings))
                                        {
                                            WindowWatcher watcher = new WindowWatcher(account, p);
                                            watcher.WindowChanged += OnWatchedWindowChanged;
                                        }
                                    }
                                    else
                                    {
                                        isUnknown = true;
                                    }
                                }
                            }
                        }

                        if (isUnknown)
                        {
                            lock (unknownProcesses)
                            {
                                if (!unknownProcesses.ContainsKey(p.Id))
                                {
                                    unknownProcesses.Add(p.Id,p);
                                    if (taskWatchUnknowns == null || taskWatchUnknowns.IsCompleted)
                                        taskWatchUnknowns = Task.Factory.StartNew(DoWatch);
                                }
                                else
                                {
                                    p.Dispose();
                                }
                            }
                        }
                    }
                    else
                        p.Dispose();
                }
                catch (Exception e)
                {
                    p.Dispose();
                }
            }

            OnScanComplete(startTime);

            lock (unknownProcesses)
            {
                ushort activeProcesses = (ushort)(LinkedProcess.GetActiveCount() + unknownProcesses.Count);
                if (Launcher.activeProcesses != activeProcesses)
                {
                    Launcher.activeProcesses = activeProcesses;
                    OnActiveProcessCountChanged();
                }
            }
        }
 private void TeardownWindowWatching()
 {
     WindowWatcher.Teardown();
     WindowStackManager.Teardown();
 }