Example #1
0
        private async void OnPlayScript()
        {
            ScriptPlaying = true;
            PlayScriptCommand.RaiseCanExecuteChanged();
            //MessageBox.Show(String.Format("Playing {0}!", SelectedEventScriptFile.FileNameWithExtension));

            EventParameterService eventParameterService = new EventParameterService();
            ProgressBarSharedView progressBar           = new ProgressBarSharedView("Downloading script from server...");

            progressBar.Show();
            //Backup current latest_test.js
            FileEndPointManager.WriteBackupFile();
            string result = await eventParameterService.DownloadScriptFromServer(SelectedEvent.Id, SelectedEventScriptFile.ParentFolder);

            progressBar.Close();

            if (result == string.Empty && _mainWindow != null)
            {
                await _mainWindow.Run(FileEndPointManager.DefaultPlayXMLFile);
            }
            else
            {
                MessageBox.Show(result, AppName, MessageBoxButton.OK, MessageBoxImage.Information);
            }

            //Restore latest_test.js
            FileEndPointManager.RestoreBackupFile();
            ScriptPlaying = false;
            PlayScriptCommand.RaiseCanExecuteChanged();
        }
Example #2
0
        //STEP.Azure #41 Handle(DevNoteIntegrationEvent @event)
        public async Task Handle(DevNoteIntegrationEvent @event)
        {
            //convert to command param
            RunWFCmdParam cmd = new RunWFCmdParam
            {
                // XamlFullPath="QRLogin",
                //username = @event.//"*****@*****.**", //default
                //password =// "Pass@word1",
                EventName       = @event.EventName,
                EventParameters = @event.EventParameters,
                GuidId          = @event.GuidId
            };


            //_HACK safe to delete
            #region ---TEST ONLY: Compiler will  automatically erase this in RELEASE mode and it will not run if Global.GlobalTestMode is not set to TestMode.Simulation
#if DEBUG
            System.Diagnostics.Debug.WriteLine("HACK-TEST -DevNoteIntegrationEvent");
            if (GlobalDef.DEBUG_MODE == EnumDEBUG_MODE.TEST)
            {
                var stringContent = JsonConvert.SerializeObject(@event);
                Console.WriteLine("Azure recievedt: " + stringContent);

                return;
            }
#endif
            #endregion //////////////END TEST



            if (!string.IsNullOrEmpty(@event.OuputResponse))
            {
                //do not trigger wf
                await BotHttpClient.Log("Confirmed to AZURE: " + @event.OuputResponse);
            }
            else
            {
                //STEP_.EVENT CreateEventInput FileEnpoint here
                await FileEndPointManager.CreateEventInput(cmd);
            }

            return;

            //xTODO call this in UIMain by filewatcher
            #region
            //package to cmd
            RunWFCmdParam cmdCarrier = new RunWFCmdParam();

            if (cmd.EventParameters == null)
            {
                cmd.EventParameters = new Dictionary <string, string>();
            }

            //TIP:  _ = await BotHttpClient.PostToDevNote(cmdCarrier);
            cmdCarrier.Payload = cmd;
            _ = await BotHttpClient.PostToDevNote(cmdCarrier);

            #endregion
        }
Example #3
0
        public async Task Run(string filepath)
        {
            //STEP.Player #850 reset results.txt
            GlobalPlayer.ResetResult();
            var selectedJSXML = openFileDialog2.FileName = filepath;

            CloseCodeCeptJsWindow();

            //todo: make this LIstbox not gridview error on ui when using grid
            // ActivateGroupBox(groupBoxRec);
            //  groupBoxRec.Visible = true;

            //STEP_.Player #802 load defaultXML
            Open_File(selectedJSXML);

            string ext = Path.GetExtension(selectedJSXML);

            if (ext.ToLower() == ".js")
            {
                //update latest_test.js
                //STEP_.Player #803 get extension variables
                var runCmd = FileEndPointManager.ReadInputWFCmdJsonFile();

                var externalParam  = runCmd.EventParameters;
                var internalResult = BotHttpClient.DevNoteGetParameters(runCmd.EventName).Content;//.ReadAsStringAsync();

                var internalParam = JsonConvert.DeserializeObject <Dictionary <string, string> >(internalResult);

                var script = File.ReadAllText(openFileDialog1.FileName);

                if (internalParam != null && externalParam != null)
                {
                    //STEP_.Player #804 CrossBreed the parameters
                    Dictionary <string, string> crossBreed = new Dictionary <string, string>();
                    foreach (var external in externalParam)
                    {
                        //internalParam-(arg.MappedTo_Input_X, arg.PropertyName.lower());
                        //ExternalParam---------------------------(PropertyName.tolower(), value); this is the external dictionary  crossed
                        //results to ---(arg.MappedTo_Input_X,value)
                        if (internalParam.ContainsValue(external.Key.ToLower()))
                        {
                            var internalP = internalParam.First(p => p.Value == external.Key.ToLower());
                            crossBreed.Add(internalP.Key, external.Value);
                        }
                    }
                    //STEP_.Player #803 insert variables
                    Interpreter it = new Interpreter();
                    //STEP.Player #804 Insert Variables
                    var selectedContent = it.InsertVariables(openFileDialog1.FileName, crossBreed).ToString();

                    script = selectedContent;
                    BotHttpClient.UpdateMainUI("InsertVariables " + Environment.NewLine + crossBreed.ToArray().ToString());
                }
                //  var selectedContent = File.ReadAllText(selectedJSXML);
                var dir = LogApplication.Agent.GetCurrentDir();
                dir = dir.Replace("file:\\", string.Empty);
                string drive       = Path.GetPathRoot(dir);
                string driveLetter = drive.First().ToString();

                var codeceptjsFolder = string.Format("{0}\\CodeceptJs\\Project2", dir);  //@"D:\_ROBOtFRAMeWORK\CodeceptsJs\Project1\";
                var codeceptTestPath = Path.Combine(codeceptjsFolder, "latest_test.js");

                if (File.Exists(codeceptTestPath))
                {
                    File.Delete(codeceptTestPath);
                }

                File.WriteAllText(codeceptTestPath, script);
                //play
                // dgActions.DataSource = actionSource;
                // dgActions.Refresh(); // Make sure this comes first
                //  dgActions.Parent.Refresh(); // Make sure this comes second
                //  flowMain.Refresh();
            }

            //STEP.Player #803 run _test.js using bat file
            RunCondeceptjsDefault();

            var started = DateTime.Now;

            //Application.DoEvents();
            TaskWaiter.Conditions cond = new TaskWaiter.Conditions("Wait_CondceptJS_Console");
            await cond.WaitUntil(() => (DateTime.Now - started).TotalSeconds > 5)
            .ContinueWith(x =>
            {
                WindowsHelper.FollowConsole(CmdExeForCodecept);
            });

            //STEP.Player #855 //check result
            //wait for output
            //todo HERE...

            //var cond1 = new TaskWaiter.Conditions("wait_for_result.txt");
            //await cond1.WaitUntil(() => AutoPlayPolicy.AssertPlayerResultExist(started) == true, 1000).ContinueWith(x =>
            //{
            //    //setStatus(string.Format("Retried {0} times", MyRetry), EnumPlayStatus.Success);
            //    //Task.Delay(1000);
            //    //IsAutoPlaying = false;

            //    //Stop();

            //    //var result =  await AutoPlay();
            //    BotHttpClient.Log("Done.. Play codecept.");

            //    //step# 12 done EnumTaskStatus.DoneCodeCept
            //    //IsAutoplayDone = EnumTaskStatus.DoneCodeCept;


            //    //MyPayload.IsSuccess = true;
            //    //MyPayload.IsRespond = true;

            //    //step# 12.4 finished status
            //    //IsAutoplayDone = EnumTaskStatus.Finished;

            //    //not here.. yet it will retry
            //    // GlobalPlayer.CreateWFOutput("none");
            //});

            //check result
            //STEP_.Player screenshot ERROR
            //if (GlobalPlayer.IsFailedResult)
            //{
            //    return false;// continue to retry
            //}
            //else
            //    return true; //no need to retry
        }
Example #4
0
        static void Main(string[] args)
        {
            //SetProcessDPIAware();

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

            //exception handler
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //if the exe was passed a filename argument then run the script
            if (args.Length > 0)
            {
                string filePath = args[0];


                if (!System.IO.File.Exists(filePath))
                {
                    using (System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog("Application"))
                    {
                        eventLog.Source = "Application";
                        eventLog.WriteEntry("An attempt was made to run a taskt script file from '" + filePath + "' but the file was not found.  Please verify that the file exists at the path indicated.", System.Diagnostics.EventLogEntryType.Error, 101, 1);
                    }

                    Application.Exit();
                    return;
                }

                Application.Run(new UI.Forms.frmScriptEngine(filePath, null, null, true));
            }
            else
            {
                //clean up updater
                var updaterExecutableDestination = Application.StartupPath + "\\taskt-updater.exe";

                if (System.IO.File.Exists(updaterExecutableDestination))
                {
                    System.IO.File.Delete(updaterExecutableDestination);
                }

                SplashForm = new UI.Forms.Supplemental.frmSplash();
                SplashForm.Show();

                Application.DoEvents();

                string baseAddress = "http://*****:*****@"     

  _                          _  
 | \  _     |\ |  _ _|_  _  |C| 
 |_/ (/_ \/ | \| (_) |_ (/_ `-' 
                               
";


                    Console.WriteLine(banner);

                    //STEP_.INIT CONFIGURATION
                    FileEndPointManager.SyncCustomConfig();
                    FileEndPointManager.SyncLogConfig();
                    FileEndPointManager.SyncDatabaseConfig();


                    Application.Run(new UI.Forms.frmScriptBuilder());
                }
            }
        }
        //must be 1 reference only
        //only used by OutputManager!!
        public static async Task <DevNoteIntegrationEvent> CreateOutputWF()
        {
            //STEP_.RESULT #99 CreateOutputWF
            var stringContent = File.ReadAllText(FileEndPointManager.InputWFFilePath);

            var cmd     = ReadInputWFCmdJsonFile();
            var payload = cmd; //(RunWFCmdParam)cmd.Payload;

            var result = FileEndPointManager.ReadMyResultValueFile();



            //TIP# Configure AutoMapper
            var config = new MapperConfiguration(cfg => cfg.CreateMap <RunWFCmdParam, DevNoteIntegrationEvent>());
            var mapper = config.CreateMapper();
            // Perform mapping
            var @event = mapper.Map <RunWFCmdParam, DevNoteIntegrationEvent>(cmd);

            @event.GuidId          = cmd.GuidId;
            @event.EventParameters = cmd.EventParameters;
            @event.EventName       = cmd.EventName;
            @event.OuputResponse   = result;
            @event.RetryCount      = cmd.RetryCount;
            @event.ErrorCode       = cmd.ErrorCode;
            @event.ReferenceId     = cmd.ReferenceId;

            @event.MessageId  = cmd.GuidId;
            @event.IsResponse = true;


            stringContent = JsonConvert.SerializeObject(@event);



            // var stringContent = JsonConvert.SerializeObject(cmd); //new StringContent(JsonConvert.SerializeObject(cmd), Encoding.UTF8, "application/json");
            var file = Path.Combine(FileEndPointManager.MyWaitOneDirectory, EnumFiles.WFOutput);



            //_HACK safe to delete
            #region ---TEST ONLY: Compiler will  automatically erase this in RELEASE mode and it will not run if Global.GlobalTestMode is not set to TestMode.Simulation
#if OVERRIDE || DEBUG
            //System.Diagnostics.Debug.WriteLine("HACK-TEST -");
            //await BotHttpClient.Log("FileEndPointManager.MyWaitOneDirectory:" + FileEndPointManager.MyWaitOneDirectory);
            //await BotHttpClient.Log("OuputResponse:" + result);
#endif
            #endregion //////////////END TEST



            await BotHttpClient.Log("OuputValue:" + result);

            File.WriteAllText(file, stringContent);

            if (!string.IsNullOrEmpty(cmd.EventFilePath))
            {
                try
                {
                    if (File.Exists(cmd.EventFilePath))
                    {
                        File.Delete(cmd.EventFilePath);
                    }
                }
                catch (Exception err)
                {
                    await BotHttpClient.Log(err.Message, true);
                }
            }

            //STEP_.RESULT #6 save to OUTCOME
            var fName = Path.GetFileName(cmd.EventFilePath);
            fName = fName.Replace(EnumFiles.WFInput, EnumFiles.WFOutput);

            file = Path.Combine(FileEndPointManager.MyOutcomeFolder, fName);
            File.WriteAllText(file, stringContent);

            await BotHttpClient.Log("EventOutputStatus: " + Environment.NewLine + stringContent);


            //var fileIn = Path.Combine(FileEndPointManager.MyWaitOneDirectory, EnumFiles.WFInput);
            //if (File.Exists(fileIn))
            //    File.Delete(fileIn);
            ClearInputWF();

            //delete Eventfile
            if (!string.IsNullOrEmpty(cmd.EventFilePath))
            {
                try
                {
                    if (File.Exists(cmd.EventFilePath))
                    {
                        File.Delete(cmd.EventFilePath);
                    }
                }
                catch (Exception err)
                {
                    await BotHttpClient.Log(err.Message, true);
                }
            }

            return(@event);
        }