Esempio n. 1
0
 /// <summary>
 /// Creates a new instance of the Application object.
 /// </summary>
 /// <param name="app"></param>
 public Application(DesktopApp app)
 {
     ApplicationUnderTest = app;
     StartInfo            = new ProcessStartInfo();
     StartInfo.FileName   = app.GetApplicationLocation();
     ProcessName          = app.GetProcessName();
 }
Esempio n. 2
0
        public static void Execute()
        {
            // 使用Delegate完成Observer pattern
            Console.WriteLine("Delegate Demo");
            var tempatureMonitorDelegate = new TempatureMonitorUsingDelegate();
            var desktopApp = new DesktopApp();
            var mobileApp  = new MobileApp();

            tempatureMonitorDelegate.OnTempatureChanged += desktopApp.OnTempatureChanged;
            tempatureMonitorDelegate.OnTempatureChanged += mobileApp.OnTempatureChanged;

            Console.WriteLine("溫度變化了,現在是30.5度");
            tempatureMonitorDelegate.Tempature = 30.5;

            Console.WriteLine("溫度沒變化,現在依然是30.5度");
            tempatureMonitorDelegate.Tempature = 30.5;

            Console.WriteLine("溫度變化了,現在是28.6度");
            tempatureMonitorDelegate.Tempature = 28.6;

            Console.WriteLine("mobileApp不再想觀察了");
            tempatureMonitorDelegate.OnTempatureChanged -= mobileApp.OnTempatureChanged;

            Console.WriteLine("溫度變化了,現在是27.6度");
            tempatureMonitorDelegate.Tempature = 27.6;
            Console.WriteLine();
        }
Esempio n. 3
0
        public bool NewDesktopApp(DesktopApp app)
        {
            logger.Debug("Inizio Metodo NewDesktopApp in DocsPaDb.Query_DocsPAWS.DesktopApps");
            bool retValue = true;

            try
            {
                DocsPaUtils.Query q = DocsPaUtils.InitQuery.getInstance().getQuery("I_DPA_DESKTOP_APPS");
                q.setParam("nome", app.Nome);
                q.setParam("versione", app.Versione);
                q.setParam("path", app.Path);
                q.setParam("descrizione", app.Descrizione);

                string query = q.getSQL();
                logger.Debug("NewDesktopApp: " + query);
                if (!ExecuteNonQuery(query))
                {
                    logger.Error("Errore durante l'inserimento in DPA_PASSO_DPA_EVENTO: " + query);
                    retValue = false;
                }
            }
            catch (Exception e)
            {
                logger.Error("Errore nel Metodo NewDesktopApp in DocsPaDb.Query_DocsPAWS.DesktopApps: " + e.Message);
                return(false);
            }

            logger.Debug("Fine Metodo NewDesktopApp in DocsPaDb.Query_DocsPAWS.DesktopApps");
            return(retValue);
        }
Esempio n. 4
0
        public List <DesktopApp> getDesktopApps()
        {
            List <DesktopApp> retList = new List <DesktopApp>();

            try
            {
                Query  query       = InitQuery.getInstance().getQuery("S_DPA_DESKTOP_APPS");
                string commandText = query.getSQL();
                logger.Debug(commandText);

                using (DBProvider dbProvider = new DBProvider())
                {
                    using (IDataReader reader = ExecuteReader(commandText))
                    {
                        while (reader.Read())
                        {
                            DesktopApp tempApp = new DesktopApp();
                            tempApp.Nome        = (reader.GetValue(reader.GetOrdinal("NOME")).ToString());
                            tempApp.Versione    = (reader.GetValue(reader.GetOrdinal("VERSIONE")).ToString());
                            tempApp.Path        = (reader.GetValue(reader.GetOrdinal("PATH")).ToString());
                            tempApp.Descrizione = (reader.GetValue(reader.GetOrdinal("DESCRIZIONE")).ToString());

                            retList.Add(tempApp);
                        }
                    }
                }

                return(retList);
            }
            catch (Exception ex)
            {
                logger.Debug(ex);
                throw new Exception(ex.Message);
            }
        }
Esempio n. 5
0
        public async void EditBaseStateClick()
        {
            var             apps = new DesktopApp();
            ApplicationForm form = null;
            await Task.Run(() => {
                form            = new ApplicationForm();
                form.DataSource = apps.GetLocators();
            });

            form.ShowDialog();
        }
Esempio n. 6
0
        /// <summary>
        /// Retrieves the full path location of the Application's executable file.
        /// </summary>
        /// <param name="deskApp"></param>
        /// <returns></returns>
        public static string GetApplicationLocation(this DesktopApp deskApp)
        {
            switch (deskApp)
            {
            case DesktopApp.Calculator: return(@"C:\Windows\System32\calc.exe");

            case DesktopApp.WhiteWinFormsTestApp: return(@"C:\Automation_Data\WindowsFormsTestApplication.exe");

            default: throw new Exception("The DesktopApps enum provided is not implemented!");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the Application's Process' Name as it would appear in the task manager.
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static string GetProcessName(this DesktopApp app)
        {
            switch (app)
            {
            case DesktopApp.WhiteWinFormsTestApp: return("WindowsFormsTestApplication");

            case DesktopApp.Calculator: return("calc");

            default: throw new Exception("The Processes enum provided is not implemented!");
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Metodo che restituisce i dati relativi ad una applicazione desktop
        /// </summary>
        /// <param name="infoUtente"></param>
        /// <returns></returns>
        public static DesktopApp GetDesktopApp(string nomeApp, DocsPaVO.utente.InfoUtente infoUtente)
        {
            DesktopApp        deskApp        = null;
            List <DesktopApp> listDesktopApp = new List <DesktopApp>();

            try
            {
                DocsPaDB.Query_DocsPAWS.DesktopApps desktopApp = new DocsPaDB.Query_DocsPAWS.DesktopApps();
                listDesktopApp = desktopApp.getDesktopApps();

                deskApp = listDesktopApp.FirstOrDefault(o => o.Nome == nomeApp);
            }
            catch (Exception e)
            {
                logger.Debug("Errore in BusinessLogic.LibroFirma.LibroFirmaManager  - metodo: GetEventNotification ", e);
            }
            return(deskApp);
        }
Esempio n. 9
0
 /// <summary>
 /// Kills all instances of a Process by name.
 /// </summary>
 /// <param name="app"></param>
 /// <param name="tries"></param>
 public static void KillAllInstancesOfProcess(this DesktopApp app, int tries = 10)
 {
     for (int i = 0; i < tries; i++)
     {
         Thread.Sleep(250);
         var processes = Process.GetProcessesByName(app.GetProcessName());
         if (processes != null && processes.Length > 0)
         {
             for (int j = 0; j < processes.Length; j++)
             {
                 if (processes[j] != null)
                 {
                     processes[j].Kill();
                 }
             }
         }
     }
 }
Esempio n. 10
0
 private void RenderDesktopApp(int index, string fileName, Image Icon, FileInfo exe)
 {
     BeginInvoke((MethodInvoker) delegate
     {
         var app = new DesktopApp
         {
             BackImage    = ImageHandling.CropImage(Wallpaper.Image, Core.IndexToWallpaperArea(index, Wallpaper.Size)),
             Parent       = Wallpaper,
             Filename     = fileName,
             DesktopIndex = index,
             icon         = Icon,
             Location     = Core.IndexToLocation(index, Wallpaper.Size),
             Executable   = exe
         };
         Controls.Add(app);
         app.OnClick       += ClickedApp;
         app.OnDoubleClick += DoubleClickedApp;
         app.BringToFront();
     });
 }
Esempio n. 11
0
        private void CreateProcess(DesktopApp App)
        {
            var AppTask = new TaskbarApp
            {
                icon   = App.icon,
                active = false,
                Dock   = DockStyle.Left,
                Name   = App.Filename
            };

            ActiveTaskPanel.Controls.Add(AppTask);
            AppTask.OnClick += ClickedTaskbarApp;
            var process = new Process();

            process.StartInfo.FileName         = App.Executable.FullName;
            process.StartInfo.WorkingDirectory = App.Executable.DirectoryName;
            process.Start();
            AppTask.process = process;
            Tasks.Add(AppTask);

            startMenu.Tasks = Tasks;
        }
Esempio n. 12
0
        public object Handle(Dictionary <string, string> urlParams, string body, ref ISession session)
        {
            var request = JsonConvert.DeserializeObject <NewSessionRequestAsDict>(body);

            foreach (var kvp in request.DesiredCapabilities)
            {
                logger.Info("{0} = {1} ({2})", kvp.Key, kvp.Value, kvp.Value.GetType());
            }

            var caps = JsonConvert.DeserializeObject <NewSessionRequest>(body).DesiredCapabilities;

            IApplication app;

            switch (caps.Platform)
            {
            case Platform.Windows:
                app = new DesktopApp(this.context, caps, this.uacHandler, this.utils);
                break;

            case Platform.WindowsModern:
                app = new StoreApp(this.context, caps, this.utils);
                break;

            case Platform.WindowsPhone:
                throw new FailedCommandException("Windows Phone is not supported yet.", 33);

            default:
                throw new FailedCommandException("The platform name '{0}' is invalid.", 33);
            }

            // TODO validate capabilibites, add logs for identifying which decision path is chosen.
            if (app.IsInstalled())
            {
                if (caps.App != null)
                {
                    logger.Info(
                        "App '{0}' is already installed, and the installation package is also provided.",
                        app.DriverAppID);

                    if (app.Installer.IsBuildChanged())
                    {
                        logger.Info("Build changed. Strategy: {0}, Reset: {1}", caps.ChangeBuildStrategy, caps.ResetStrategy);

                        app.Terminate();
                        if (caps.ChangeBuildStrategy == ChangeBuildStrategy.Reinstall)
                        {
                            // reset strategy is irrelevant here
                            app.Uninstall();
                            app.Installer.Install();
                            app.BackupInitialStates(true);
                        }
                        else if (caps.ChangeBuildStrategy == ChangeBuildStrategy.Upgrade)
                        {
                            // full-reset strategy is irrelevant here
                            if (caps.ResetStrategy != ResetStrategy.No)
                            {
                                app.RestoreInitialStates();
                                app.Installer.Install();
                                app.BackupInitialStates(true);
                            }
                        }
                    }
                    else
                    {
                        logger.Info("Build not changed. Reset: {0}", caps.ResetStrategy);

                        if (caps.ResetStrategy == ResetStrategy.Fast)
                        {
                            app.Terminate();
                            app.RestoreInitialStates();
                        }
                        else if (caps.ResetStrategy == ResetStrategy.Full)
                        {
                            app.Terminate();
                            app.Uninstall();
                            app.Installer.Install();
                            app.BackupInitialStates(true);
                        }
                    }
                }
                else
                {
                    logger.Info(
                        "App '{0}' is already installed, but the installation package is not provided. Reset: {1}",
                        app.DriverAppID, caps.ResetStrategy);

                    // full-reset is irrelevant here
                    if (caps.ResetStrategy == ResetStrategy.Fast)
                    {
                        app.Terminate();
                        if (!app.BackupInitialStates(false))
                        {
                            app.RestoreInitialStates();
                        }
                    }
                }
            }
            else
            {
                if (caps.App != null)
                {
                    logger.Info(
                        "App '{0}' is not installed yet, but the installation package is provided.",
                        app.DriverAppID);

                    app.Installer.Install();
                    app.BackupInitialStates(true);
                }
                else
                {
                    logger.Info(
                        "App '{0}' is not installed yet, and the installation package is not provided. Reset: {1}",
                        app.DriverAppID, caps.ResetStrategy);

                    if (caps.Platform == Platform.Windows)
                    {
                        // full-reset is irrelevant here
                        if (caps.ResetStrategy == ResetStrategy.Fast)
                        {
                            app.Terminate();
                            app.RestoreInitialStates();
                        }
                    }
                    else
                    {
                        var msg = "'app' capability is mandatory if the target platform is not 'Windows' " +
                                  "(default) and the app under test '{0}' is not installed beforehand.";
                        throw new WinAppDriverException(string.Format(msg, app.DriverAppID));
                    }
                }
            }

            app.Activate();
            session = this.sessionManager.CreateSession(app, caps);

            // TODO turn off IME, release all modifier keys
            return(caps);
        }