Esempio n. 1
0
        public async Task <string> WaitUntilDesignerIsRunning(int frequency = 1000, int timeout = 60000)
        {
            string result    = string.Empty;
            bool   isRunning = false;

            var waitTask = Task.Run(async() =>
            {
                while (!isRunning)
                {
                    var response = await BotHttpClient.TaskHttpGetToDesigner("hi");

                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        isRunning = true;
                        var hello = response.Content.ReadAsStringAsync().Result;
                        //Console.WriteLine(hello);
                        BotHttpClient.WriteDevBotResponse(hello);
                        result = hello;
                    }

                    await Task.Delay(frequency);
                }
            });

            if (waitTask != await Task.WhenAny(waitTask,
                                               Task.Delay(timeout)))
            {
                // throw new TimeoutException();
                result = "WaitUntilDesignerIsRunnung TimeoutException";
                LogApplication.Agent.LogError(result);
            }

            return(result);
        }
Esempio n. 2
0
        public static bool AssertWFOutputCreatedByPlayer()
        {
            try
            {
                //STEP.Player #868 write local endpoint of Player
                var endPointPlayerFolder = FileEndPointManager.Project2EndPointFolder;

                var fileResult = Path.Combine(endPointPlayerFolder, EnumFiles.MyResult);

                //if there is result from player
                if (File.Exists(fileResult))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception err)
            {
                BotHttpClient.Log(err.Message, true);
                return(false);
            }
        }
Esempio n. 3
0
        public async static Task <bool> AssertPlayerTimedOut(DateTime startRun)
        {
            // Timeout
            ConfigManager config  = new ConfigManager();
            var           timeOut = Convert.ToInt32(config.GetValue("MaxTimeOutMinutes"));

            //create result file



            //STEP.Player #803 timeout
            var span = DateTime.Now - startRun;

            //TIP  if ((int)span.TotalMinutes % 30 == 0)
            if ((int)span.Seconds % 30 == 0)
            {
                var msg = $"Task is Running :{span.TotalMinutes.ToString()} minutes already.";
                Console.WriteLine(msg);
                await BotHttpClient.Log(msg);
            }

            if (span.TotalMinutes >= timeOut)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        public static void Retry()
        {
            ConfigManager config           = new ConfigManager();
            var           screenshotOnFail = config.GetValue("ScreenshotOnFail");

            if (File.Exists(screenshotOnFail))
            {
                if (RetryCount < 3)
                {
                    RetryCount += 1;
                    File.Delete(screenshotOnFail);

                    BotHttpClient.Log("RETRY FAILED RUN... Retry count is " + RetryCount.ToString(), true);

                    GlobalDef.CurrentDesigner.HandleCmd(MyCmd);
                    return;
                }
            }


            //show result to azure event...
            BotHttpClient.Log("Done WF Run... Retry count is " + RetryCount.ToString(), false);
            RetryCount = 0;
            MyCmd      = null;

            //xTODO.. create azure event here...
        }
Esempio n. 5
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
        }
Esempio n. 6
0
        string CheckChromeStarted()
        {
            string result   = string.Empty;
            var    response = BotHttpClient.TaskHttpGetToChrome("hi").Result;

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                isChromeTaskDone = true;
                var hello = response.Content.ReadAsStringAsync().Result;
                //Console.WriteLine(hello);
                BotHttpClient.WriteChromeResponse(hello);
                result = hello;
            }
            return(result);
        }
Esempio n. 7
0
        public async Task <string> WaitUntilChromeIsRunnung(int frequency = 100, int timeout = 45000)
        {
            string result = string.Empty;

            isChromeTaskDone = false;

            var waitTask = Task.Run(async() =>
            {
                while (!isChromeTaskDone)
                {
                    var response = await BotHttpClient.TaskHttpGetToChrome("hi");

                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        isChromeTaskDone = true;
                        var hello        = response.Content.ReadAsStringAsync().Result;
                        //Console.WriteLine(hello);
                        BotHttpClient.WriteChromeResponse(hello);
                        result = hello;
                    }

                    if (GlobalDef.CurrentDesigner != null && GlobalDef.CurrentDesigner.IsRunningWF == false)
                    {
                        var respond = "Cancelled Run WF.";
                        BotHttpClient.WriteChromeResponse(respond);
                        result           = respond;
                        isChromeTaskDone = true;
                    }

                    await Task.Delay(frequency);
                }
            });

            if (waitTask != await Task.WhenAny(waitTask,
                                               Task.Delay(timeout)))
            {
                // throw new TimeoutException();
                result = "WaitUntilChromeIsRunnung TimeoutException";
                LogApplication.Agent.LogError(result);
            }

            return(result);
        }
Esempio n. 8
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
        }
        //must be 1 reference only
        public static async Task <DevNoteIntegrationEvent> CreateErrorOutputWF(string errorMessage)
        {
            //STEP_.RESULT #99 CreateOutputWF
            var stringContent = File.ReadAllText(FileEndPointManager.InputWFFilePath);

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

            var result = $"ERROR:{errorMessage}"; //FileEndPointManager.ReadMyGrabValueFile();

            //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       = "101";//ErrorCodes 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);



            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);
        }
        //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);
        }