Ejemplo n.º 1
0
        private static string GetSLLauncherCommand()
        {
            var desktopPath      = string.Empty;
            var startMenuPath    = string.Empty;
            var slLauncherCmmand = string.Empty;

            using (dynamic wShell = AutomationFactory.CreateObject("WScript.Shell"))
            {
                desktopPath   = wShell.SpecialFolders("Desktop");
                startMenuPath = wShell.SpecialFolders("Programs");
            }

            using (dynamic shell = AutomationFactory.CreateObject("Shell.Application"))
            {
                dynamic desktopItems   = shell.NameSpace(desktopPath).Items();
                dynamic startMenuItems = shell.NameSpace(startMenuPath).Items();


                FindApplicationInFolder(ref slLauncherCmmand, desktopItems);

                if (string.IsNullOrEmpty(slLauncherCmmand))
                {
                    FindApplicationInFolder(ref slLauncherCmmand, startMenuItems);
                }
            }

            return(slLauncherCmmand);
        }
Ejemplo n.º 2
0
        [NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact]
        public void ThreeCriteria_ThreeElements_NoMatch_NameAutomaitonIdClassName()
        {
            // Arrange
            var hashtable = new Hashtable();

            hashtable.Add("NAME", "*aaa*");
            hashtable.Add("AUTOMATIONID", "*id*");
            hashtable.Add("CLASS", "cl*ss");

            // Act
            bool result = RealCodeCaller.GetResult_IsStepActive(
                new Hashtable[] {
                hashtable
            },
                AutomationFactory.GetUiEltCollection(
                    new[] {
                FakeFactory.GetAutomationElementExpected(ControlType.Button, "aa1aa", "auId", "clas", string.Empty),
                FakeFactory.GetAutomationElementExpected(ControlType.Button, "aa2aa3aa", "Id", "cl____s", string.Empty),
                FakeFactory.GetAutomationElementExpected(ControlType.Button, "a4a5abbb", "iDrweqrqw", @"/ss", string.Empty)
            })
                );

            // Assert
            MbUnit.Framework.Assert.AreEqual(false, result);
            Assert.Equal(false, result);
        }
Ejemplo n.º 3
0
        private static bool GetOutlook()
        {
            try
            {
                // If GetObject throws an exception, then Outlook is
                // either not running or is not available.
                outlook = AutomationFactory.GetObject("Outlook.Application");
                return(true);
            }
            catch
            {
                try
                {
                    // Start Outlook and display the Inbox, but minimize
                    // it to avoid hiding the running application.

                    outlook = AutomationFactory.CreateObject("Outlook.Application");
                    outlook.Session.GetDefaultFolder(6).Display();
                    // 6 = Inbox
                    outlook.ActiveWindow.WindowState = 1;
                    // minimized
                    return(true);
                }
                catch
                {
                    // Outlook is unavailable.
                    return(false);
                }
            }
        }
        partial void CreateWordDocPrinter_Execute()
        {
            if (AutomationFactory.IsAvailable)
            {
                try
                {
                    //Copy the word template file to 'My Documents'
                    SaveTemplateToMyDocuments();
                    string path = Environment.GetFolderPath(
                        Environment.SpecialFolder.MyDocuments) + @"\LetterTemplate.dotx";

                    using (dynamic wordApp =
                               AutomationFactory.CreateObject("Word.Application"))
                    {
                        dynamic wordDoc = wordApp.Documents.Open(
                            path);
                        wordDoc.Bookmarks("DepartmentName").Range.InsertAfter(
                            Department.DepartmentName);
                        wordApp.PrintOut();
                        wordDoc.Close(0);
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("Failed to create letter.", ex);
                }
            }
        }
Ejemplo n.º 5
0
        private static void Main(string[] args)
        {
            // 20131114
            AutomationFactory.Init();

            // 20121003
            SpyModes currentMode = SpyModes.uIAutomationSpy;

            if (null != args && 0 < args.Length)
            {
                switch (Convert.ToInt32(args[0].Trim()))
                {
                case (int)SpyModes.uIAutomationSpy:
                    currentMode = SpyModes.uIAutomationSpy;
                    break;

                case (int)SpyModes.seleniumSpy:
                    currentMode = SpyModes.seleniumSpy;
                    break;
//                    default:
//
//                        break;
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new SpyForm(currentMode));
        }
Ejemplo n.º 6
0
        private void DownloadPDFScript()
        {
            WebClient a = new WebClient();

            a.OpenReadAsync(new Uri(DownloadPDFScriptFileNameString, UriKind.Relative));
            a.OpenReadCompleted += (object sender1, OpenReadCompletedEventArgs e1) =>
            {
                StreamReader reader      = new StreamReader(e1.Result);
                string       VBSContents = reader.ReadToEnd();
                reader.Close();

                if (AutomationFactory.IsAvailable)
                {
                    using (dynamic fso = AutomationFactory.CreateObject("Scripting.FileSystemObject"))
                    {
                        if (!fso.FolderExists(TempFolderPathString))
                        {
                            fso.CreateFolder(TempFolderPathString);
                        }
                        dynamic txtFile = fso.CreateTextFile(TempFolderPathString + DownloadPDFScriptFileNameString);
                        txtFile.WriteLine(VBSContents);
                        txtFile.close();
                    }
                }
            };
        }
        private void Init()
        {
            try
            {
                if (App.Current.InstallState != InstallState.Installed)
                {
                    updateDetailLogLabel("\nAlt-Click to install to local machine");
                }

                if (AutomationFactory.IsAvailable)
                {
                    using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
                    {
                        shell.Run("screenshot.jar -e", 0);
                    }
                }
                else
                {
                    updateDetailLogLabel("\nUnable to launch, please run java -jar screenshot.jar -d for device and java -jar screenshot.jar -e for emulator");
                }

                SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                args.RemoteEndPoint = remoteEndPoint;
                args.Completed     += new EventHandler <SocketAsyncEventArgs>(OnConnect);
                socket.ConnectAsync(args);
            }
            catch (Exception exp)
            {
                updateDetailLogLabel("\n" + exp.Message);
            }
        }
Ejemplo n.º 8
0
        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            // Code below will throw System.UnauthorizedAccessException
            //using (StreamWriter writer = File.CreateText("C:\\Temp.txt"))
            //{
            //    writer.WriteLine("Some text");
            //}

            if (AutomationFactory.IsAvailable)
            {
                // Interesting, I can simply try to dispose a dynamic object without checking whether it has implemented IDisposible:)
                using (dynamic fso = AutomationFactory.CreateObject("Scripting.FileSystemObject"))
                {
                    if (!fso.FolderExists(folderPath))
                    {
                        fso.CreateFolder(folderPath);
                    }
                    dynamic txtFile = fso.CreateTextFile(filePath);
                    txtFile.WriteLine("Some text...");
                    txtFile.close();
                }

                ShowManipulationResult(filePath + " was created..");
            }
        }
 public static void EjecutaEXE(string ruta)
 {
     using (dynamic shell = AutomationFactory.CreateObject("WScript.shell"))
     {
         shell.Run(@ruta);
     }
 }
Ejemplo n.º 10
0
        public void SetUp()
        {
            UnitTestingHelper.PrepareUnitTestDataStore();

            // 20140227
            AutomationFactory.InitUnitTests();
        }
Ejemplo n.º 11
0
 private void InitCardObj()
 {
     if (obj == null)
     {
         obj = AutomationFactory.CreateObject("HJIC.HJICCtrl.1");
     }
 }
Ejemplo n.º 12
0
 public UpperBathroomConfiguration(
     CCToolsDeviceService ccToolsBoardService,
     IDeviceRegistryService deviceService,
     ISchedulerService schedulerService,
     IAreaRegistryService areaService,
     ISettingsService settingsService,
     AutomationFactory automationFactory,
     ActuatorFactory actuatorFactory,
     SensorFactory sensorFactory,
     IMessageBrokerService messageBroker,
     IDeviceMessageBrokerService deviceMessageBrokerService,
     ILogService logService)
 {
     _messageBroker = messageBroker;
     _deviceMessageBrokerService = deviceMessageBrokerService;
     _logService          = logService;
     _ccToolsBoardService = ccToolsBoardService ?? throw new ArgumentNullException(nameof(ccToolsBoardService));
     _deviceService       = deviceService ?? throw new ArgumentNullException(nameof(deviceService));
     _schedulerService    = schedulerService ?? throw new ArgumentNullException(nameof(schedulerService));
     _areaService         = areaService ?? throw new ArgumentNullException(nameof(areaService));
     _settingsService     = settingsService ?? throw new ArgumentNullException(nameof(settingsService));
     _automationFactory   = automationFactory ?? throw new ArgumentNullException(nameof(automationFactory));
     _actuatorFactory     = actuatorFactory ?? throw new ArgumentNullException(nameof(actuatorFactory));
     _sensorFactory       = sensorFactory ?? throw new ArgumentNullException(nameof(sensorFactory));
     _messageBroker       = messageBroker ?? throw new ArgumentNullException(nameof(sensorFactory));
 }
Ejemplo n.º 13
0
 public BJICCard(bool isInit)
 {
     if (isInit)
     {
         obj = AutomationFactory.CreateObject("YLIC.YLICCtrl.1");
     }
 }
Ejemplo n.º 14
0
        protected override void BeginProcessing()
        {
            var command =
                AutomationFactory.GetCommand <GetDesktopCommand>(this);

            command.Execute();
        }
Ejemplo n.º 15
0
        public static void OpenWindow(string url, int width = 1100, int height = 600)
        {
            string host = Application.Current.Host.Source.Host;
            int    port = Application.Current.Host.Source.Port;
            Uri    uri  = new Uri(String.Format("http://{0}:{1}/{2}", host, port, url));

            if (!Application.Current.IsRunningOutOfBrowser)
            {
                System.Windows.Browser.HtmlPopupWindowOptions options = new System.Windows.Browser.HtmlPopupWindowOptions();
                options.Resizeable  = true;
                options.Width       = width;
                options.Height      = height;
                options.Menubar     = true;
                options.Directories = true;
                options.Toolbar     = true;
                options.Status      = true;
                System.Windows.Browser.HtmlPage.PopupWindow(uri, "_blank", options);
                //System.Windows.Browser.HtmlPage.Window.Navigate(uri);
            }
            else
            {
                //WebBrowserBridge.OpenURL(uri, "_blank");
                using (var shell = AutomationFactory.CreateObject("WScript.Shell")) {
                    shell.Run("iexplore.exe " + uri.AbsoluteUri);
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Processes the pipeline.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (!CheckAndPrepareInput(this))
            {
                return;
            }

//            foreach (IUiElement inputObject in InputObject) {
//
//                try {
//                    var resultElement = inputObject.InvokeContextMenu(this, X, Y);
//                    // return the context menu window
//                    WriteObject(this, resultElement);
//                } catch {
//                    WriteError(
//                        this,
//                        "Failed to invoke context menu on this element",
//                        "couldNotClick",
//                        ErrorCategory.InvalidResult,
//                        true);
//                }
//
//            }

            var command =
                AutomationFactory.GetCommand <InvokeControlContextMenuCommand>(this);

            command.Execute();
        }
Ejemplo n.º 17
0
        //Listing 11-9. Opening files in their default applications
        partial void OpenFileFromDatabase_Execute()
        {
            try
            {
                if ((AutomationFactory.IsAvailable))
                {
                    //this is where we'll save the file
                    string fullFilePath = System.IO.Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                        IssueDocument.DocumentName);

                    byte[] fileData = IssueDocument.IssueFile.ToArray();

                    if ((fileData != null))
                    {
                        using (FileStream fs =
                                   new FileStream(
                                       fullFilePath, FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            fs.Write(fileData, 0, fileData.Length);
                            fs.Close();
                        }
                    }

                    dynamic shell = AutomationFactory.CreateObject("Shell.Application");
                    shell.ShellExecute(fullFilePath);
                }
            }
            catch (Exception ex)
            {
                this.ShowMessageBox(ex.ToString());
            }
        }
Ejemplo n.º 18
0
 public void addKey(string key)
 {
     using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
     {
         shell.RegWrite(keyPath + "key", key, "REG_SZ");
     }
     registered = getRegKey().checkKey();
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Processes the pipeline.
        /// </summary>
        protected override void ProcessRecord()
        {
            CheckCmdletParameters();

            var command = AutomationFactory.GetCommand <GetWindowCommand>(this);

            command.Execute();
        }
Ejemplo n.º 20
0
 public static void InitForPowerShell()
 {
     AutomationFactory.InitUnitTests();
     Preferences.UseElementsPatternObjectModel = true;
     Preferences.UseElementsSearchObjectModel  = true;
     Preferences.UseElementsCurrent            = true;
     Preferences.UseElementsCached             = false;
 }
Ejemplo n.º 21
0
        public StoreroomConfiguration(
            IAreaService areaService,
            SynonymService synonymService,
            IDeviceService deviceService,
            CCToolsBoardService ccToolsBoardService,
            ITimerService timerService,
            ITwitterClientService twitterClientService,
            AutomationFactory automationFactory,
            ActuatorFactory actuatorFactory,
            SensorFactory sensorFactory)
        {
            if (areaService == null)
            {
                throw new ArgumentNullException(nameof(areaService));
            }
            if (synonymService == null)
            {
                throw new ArgumentNullException(nameof(synonymService));
            }
            if (deviceService == null)
            {
                throw new ArgumentNullException(nameof(deviceService));
            }
            if (ccToolsBoardService == null)
            {
                throw new ArgumentNullException(nameof(ccToolsBoardService));
            }
            if (timerService == null)
            {
                throw new ArgumentNullException(nameof(timerService));
            }
            if (twitterClientService == null)
            {
                throw new ArgumentNullException(nameof(twitterClientService));
            }
            if (automationFactory == null)
            {
                throw new ArgumentNullException(nameof(automationFactory));
            }
            if (actuatorFactory == null)
            {
                throw new ArgumentNullException(nameof(actuatorFactory));
            }
            if (sensorFactory == null)
            {
                throw new ArgumentNullException(nameof(sensorFactory));
            }

            _areaService          = areaService;
            _synonymService       = synonymService;
            _deviceService        = deviceService;
            _ccToolsBoardService  = ccToolsBoardService;
            _timerService         = timerService;
            _twitterClientService = twitterClientService;
            _automationFactory    = automationFactory;
            _actuatorFactory      = actuatorFactory;
            _sensorFactory        = sensorFactory;
        }
Ejemplo n.º 22
0
        public UpperBathroomConfiguration(
            CCToolsBoardService ccToolsBoardService,
            IDeviceService deviceService,
            ISchedulerService schedulerService,
            IAreaService areaService,
            ISettingsService settingsService,
            SynonymService synonymService,
            AutomationFactory automationFactory,
            ActuatorFactory actuatorFactory,
            SensorFactory sensorFactory)
        {
            if (ccToolsBoardService == null)
            {
                throw new ArgumentNullException(nameof(ccToolsBoardService));
            }
            if (deviceService == null)
            {
                throw new ArgumentNullException(nameof(deviceService));
            }
            if (schedulerService == null)
            {
                throw new ArgumentNullException(nameof(schedulerService));
            }
            if (areaService == null)
            {
                throw new ArgumentNullException(nameof(areaService));
            }
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }
            if (synonymService == null)
            {
                throw new ArgumentNullException(nameof(synonymService));
            }
            if (automationFactory == null)
            {
                throw new ArgumentNullException(nameof(automationFactory));
            }
            if (actuatorFactory == null)
            {
                throw new ArgumentNullException(nameof(actuatorFactory));
            }
            if (sensorFactory == null)
            {
                throw new ArgumentNullException(nameof(sensorFactory));
            }

            _ccToolsBoardService = ccToolsBoardService;
            _deviceService       = deviceService;
            _schedulerService    = schedulerService;
            _areaService         = areaService;
            _settingsService     = settingsService;
            _synonymService      = synonymService;
            _automationFactory   = automationFactory;
            _actuatorFactory     = actuatorFactory;
            _sensorFactory       = sensorFactory;
        }
Ejemplo n.º 23
0
        protected override void BeginProcessing()
        {
            // UiaHelper.ShowBanner(Message);

            var command =
                AutomationFactory.GetCommand <ShowBannerCommand>(this);

            command.Execute();
        }
Ejemplo n.º 24
0
        private static void StartRelevantAutomationHandlers(HubEvent evt)
        {
            // Get a reference to the automation
            var automations = AutomationFactory.GetAutomations(evt, _hub);

            foreach (IAutomation automation in automations)
            {
                // If this automation is already running, cancel all running instances
                _taskManager.CancelRunningInstances(automation.GetType(), evt.DeviceId);

                // Start a task to handle the automation and a CancellationToken Source
                // so we can cancel it later.
                CancellationTokenSource cts        = new CancellationTokenSource();
                Func <Task>             handleTask = async() =>
                {
                    var startedTime = DateTime.Now;
                    Console.WriteLine($"{DateTime.Now} {automation} event: {evt.DescriptionText}");

                    using (var operation = _telemetryClient.StartOperation <RequestTelemetry>(automation.ToString()))
                    {
                        _telemetryClient.TrackEvent("Automation Started", evt.GetDictionary());

                        try
                        {
                            // This runs the Handle method on the automation class
                            await automation.Handle(cts.Token);
                        }
                        catch (TaskCanceledException)
                        {
                            TimeSpan executionTime = DateTime.Now - startedTime;
                            _telemetryClient.TrackEvent($"Automation Cancelled",
                                                        new Dictionary <string, string>()
                            {
                                { "WaitTime", executionTime.TotalSeconds.ToString() },
                            });
                            Console.WriteLine($"{DateTime.Now} {automation} event from {startedTime} cancelled.");
                        }
                        catch (Exception ex)
                        {
                            operation.Telemetry.Success = false;
                            _telemetryClient.TrackException(ex);
                            Console.WriteLine($"{DateTime.Now} {automation} {ex} {ex.Message}");
                        }
                    }
                };

                // Ready... go handle it!
                Task work = Task.Run(handleTask, cts.Token);

                // Hold on to the task and its cancellation token source for later.
                _taskManager.Track(work, cts, automation.GetType(), evt.DeviceId);
            }

            // Let's take this opportunity to get rid of any completed tasks.
            _taskManager.RemoveCompletedTasks();
        }
Ejemplo n.º 25
0
 private void btnClose_Click(object sender, RoutedEventArgs e)
 {
     if (AutomationFactory.IsAvailable)
     {
         using (var wScript = AutomationFactory.CreateObject("WScript.Shell"))
         {
             wScript.Run(@"cmd /k taskkill /IM sllauncher.exe & exit", 0);
         }
     }
 }
Ejemplo n.º 26
0
 void fe_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
         {
             shell.SendKeys("{TAB}");
         }
     }
 }
Ejemplo n.º 27
0
 private void cmdRunProcess_Click(object sender, RoutedEventArgs e)
 {
     if (TestForComSupport())
     {
         using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
         {
             shell.Run("calc.exe");
         }
     }
 }
        public override void Execute()
        {
            var cmdlet = (ConvertToUiaSearchCriteriaCommand)Cmdlet;

            var converter = AutomationFactory.GetObject <ElementToSearchCriteriaConverter>();

//            foreach (IUiElement element in cmdlet.InputObject) {
//                WriteObject(this, ConvertElementToSearchCriteria(element));
//            }
        }
Ejemplo n.º 29
0
 public override void Open()
 {
     if (!string.IsNullOrEmpty(FileName))
     {
         using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
         {
             shell.Run(FileName);
         }
     }
 }
        private void btnExcel_Click(object sender, RoutedEventArgs e)
        {
            //Abrir o Excel

            dynamic excel;

            //Criando uma novo aplicação Excel
            excel = AutomationFactory.CreateObject("Excel.Application");
            //Deixando a aplicação visível
            excel.Visible = true;
            // Criando um novo arquivo para a aplicação
            // Lembrando que um workbook é um conjunto de planilhas
            dynamic workbook = excel.workbooks;

            workbook.Add();
            // Pega a planilha que acabamos de criar
            dynamic sheet = excel.ActiveSheet;

            // Criando o título
            sheet.Cells[1, 1].Value = "Exporta Cubo";
            // Fonte negrito
            sheet.Cells[1, 1].Font.Bold = true;
            // Mesclando as celulas
            sheet.Range("A1:C1").Merge();
            // Centralizando o alinhamento horizontal
            sheet.Range("A1:C1").HorizontalAlignment = -4108;
            // Criando as colunas (lembrando as celulas das planilhas começam com o índice 1
            for (int coluna = 1; coluna <= dgCliente.Columns.Count; coluna++)
            {
                sheet.Cells[3, coluna].Value     = dgCliente.Columns[coluna - 1].Header;
                sheet.Cells[3, coluna].Font.Bold = true;
                // Cor do Interior: Cinza
                sheet.Cells[3, coluna].Interior.Color = 14540253;
            }

            // Criando as linhas
            int linha = 4;

            foreach (AprReprCursoDisc apr in dgCliente.ItemsSource)
            {
                sheet.Cells[linha, 1].Value = apr.Curso;
                sheet.Cells[linha, 2].Value = apr.Disciplina;
                sheet.Cells[linha, 3].Value = apr.Ano;
                sheet.cells[linha, 4].value = apr.Aprovados;
                sheet.cells[linha, 5].value = apr.Reprovados;

                // Se o indice da linha for par, a cor será verde
                // caso contrário a cor será azul
                sheet.Cells[linha, 1].Interior.Color         =
                    sheet.Cells[linha, 2].Interior.Color     =
                        sheet.Cells[linha, 3].Interior.Color = (linha % 2 == 0) ? 13434828 : 16772300;

                linha++;
            }
        }