Esempio n. 1
0
        public static DevNoteIntegrationEvent ReadOuputWFCmdJsonFile()
        {
            var @event = new DevNoteIntegrationEvent();

            if (File.Exists(OutputWFFilePath))
            {
                var json = File.ReadAllText(OutputWFFilePath);
                @event = JsonConvert.DeserializeObject <DevNoteIntegrationEvent>(json);
            }

            return(@event);
        }
Esempio n. 2
0
        public static async Task <HttpResponseMessage> PostToAzure(DevNoteIntegrationEvent devEvent, string controller = "Event")
        {
            //STEP_.EVENT PostToAzure
            //int basePort = DefaultApiPort.ChromePort;
            int targetPort = DefaultApiPort.AzureSenderPort;

            //string baseAddress = string.Format("http://localhost:{0}/", basePort);
            //    [Route("api/[controller]")]
            //http://localhost:5500/api/event
            string targetAddress = string.Format("http://localhost:{0}/api/{1}", targetPort, controller);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(targetAddress);

                try
                {
                    var stringContent = new StringContent(JsonConvert.SerializeObject(devEvent), Encoding.UTF8, "application/json");

                    //step# 13.2

                    var response = await client.PostAsync("", stringContent);

                    response.EnsureSuccessStatusCode();

                    //var responseContent = await response.Content.ReadAsStringAsync();

                    //dynamic json = JsonConvert.DeserializeObject(responseContent);
                    //dynamic r = json.result;

                    // result = r.someproperty.ToString().Equals("resultdata");
                    //return r;
                    return(response);
                }
                catch (Exception err)
                {
                    LogApplication.Agent.LogError(err);
                }

                return(null);
            }
        }
Esempio n. 3
0
        //must be 1 reference only
        public static async Task CreateOutputWF()
        {
            //STEP_.RESULT #99 CreateOutputWF
            var stringContent = File.ReadAllText(FileEndPointManager.InputWFFilePath);

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

            var result = FileEndPointManager.ReadMyGrabValueFile();

            var @event = new DevNoteIntegrationEvent
            {
                GuidId          = cmd.GuidId,
                EventParameters = cmd.EventParameters,
                EventName       = cmd.EventName,
                OuputResponse   = result,
                RetryCount      = payload.RetryCount,
                ErrorCode       = payload.ErrorCode
            };

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