Exemple #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("EditTextEQ");
            string baseUrl = Environment.GetEnvironmentVariable("e1-baseUrl");
            var    e1      = new AIS.Server(baseUrl, log);

            e1.AuthRequest.username = Environment.GetEnvironmentVariable("e1-username");
            e1.AuthRequest.password = Environment.GetEnvironmentVariable("e1-password");

            string numb = req.Query["numb"];
            int    seq  = int.Parse(req.Query["seq"]);
            string text = req.Query["text"];
            var    mo   = new GT1701 <AIS.MoUpdateText>(numb, seq, text);

            try
            {
                var rs = await e1.RequestAsync(mo.Request);

                return(new OkObjectResult(rs));
            }
            catch (Exception e)
            {
                return(new BadRequestObjectResult(e.Message));
            }
        }
Exemple #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("GetTextEQ");
            string baseUrl = Environment.GetEnvironmentVariable("e1-baseUrl");
            var    e1      = new AIS.Server(baseUrl, log);

            e1.AuthRequest.username = Environment.GetEnvironmentVariable("e1-username");
            e1.AuthRequest.password = Environment.GetEnvironmentVariable("e1-password");

            string numb = req.Query["numb"];
            var    mo   = new GT1701 <AIS.MoGetText>(numb, true);

            try
            {
                var rs = await e1.RequestAsync(mo.Request);

                var t = rs.textAttachments.FirstOrDefault(a => a.itemName.Equals(NAME));
                if (t != null)
                {
                    try
                    {
                        var adds = System.Text.RegularExpressions.Regex.Unescape(t.text).Split('\n')
                                   .Select(s => JsonSerializer.Deserialize <Address>(s))
                                   .ToList();
                        Address last = null;
                        foreach (var l in adds)
                        {
                            if (last != null)
                            {
                                l.distance = calculate(last.latitude, last.longitude, l.latitude, l.longitude, 'K');
                            }
                            last = l;
                        }
                        return(new OkObjectResult(new { t.sequence, adds }));
                    }
                    catch (Exception) { }
                }
                return(new OkObjectResult(null));
            }
            catch (Exception e)
            {
                return(new BadRequestObjectResult(e.Message));
            }
        }
Exemple #3
0
            public override async Task <Unit> Handle(TextAttachmentAction aAction, CancellationToken aCancellationToken)
            {
                try
                {
                    switch (aAction.Type)
                    {
                    case TextAttachmentAction.Types.GET:
                        var get = new GT1701 <AIS.MoGetText>(aAction.NUMB.ToString(), true);
                        var ats = await E1.RequestAsync(get.Request);

                        State.TextAttachments = ats.textAttachments;
                        State.ErrorMessage    = ats.error;
                        break;

                    case TextAttachmentAction.Types.ADD:
                        var add   = new GT1701 <AIS.MoAddText>(aAction.NUMB.ToString(), aAction.Name, aAction.Text);
                        var addRs = await E1.RequestAsync(add.Request);

                        State.ErrorMessage = addRs.error;
                        break;

                    case TextAttachmentAction.Types.EDIT:
                        var edit   = new GT1701 <AIS.MoUpdateText>(aAction.NUMB.ToString(), aAction.Sequence, aAction.Text);
                        var editRs = await E1.RequestAsync(edit.Request);

                        State.ErrorMessage = editRs.error;
                        break;
                    }
                }
                catch (AIS.HttpWebException e)
                {
                    State.ErrorMessage = e.ErrorResponse.message ?? e.Message;
                }
                catch (Exception e)
                {
                    State.ErrorMessage = e.Message;
                }

                var handler = State.Changed;

                handler?.Invoke(State, null);

                return(Unit.Value);
            }
Exemple #4
0
            public override async Task <Unit> Handle(EQListAction aAction, CancellationToken aCancellationToken)
            {
                State.ErrorMessage = string.Empty;
                try
                {
                    var rs = await E1.RequestAsync <W1701A.Response>(new W1701A.Request());

                    State.EQList = rs.fs_P1701_W1701A.data.gridData.rowset;
                    foreach (var r in State.EQList)
                    {
                        var mo   = new GT1701 <AIS.MoGetText>(r.z_NUMB_377.ToString(), true);
                        var mots = await E1.RequestAsync(mo.Request);

                        var t = mots.textAttachments.FirstOrDefault(a => a.itemName.Equals(NAME));
                        if (t != null)
                        {
                            try
                            {
                                r.Locations = Regex.Unescape(t.text).Split('\n')
                                              .Select(s => JsonSerializer.Deserialize <Address>(s))
                                              .ToList();
                            }
                            catch (Exception) { }
                        }
                    }
                }
                catch (AIS.HttpWebException e)
                {
                    State.ErrorMessage = e.ErrorResponse.message ?? e.Message;
                }
                catch (Exception e)
                {
                    State.ErrorMessage = e.Message;
                }

                var handler = State.Changed;

                handler?.Invoke(State, null);

                return(Unit.Value);
            }
Exemple #5
0
            public override async Task <Unit> Handle(RefreshLocationAction aAction, CancellationToken aCancellationToken)
            {
                State.ErrorMessage = string.Empty;
                try
                {
                    var mo   = new GT1701 <AIS.MoGetText>(aAction.NUMB.ToString(), true);
                    var mots = await E1.RequestAsync(mo.Request);

                    var t = mots.textAttachments.FirstOrDefault(a => a.itemName.Equals(NAME));
                    if (t != null)
                    {
                        var row = State.EQList.First(r => r.z_NUMB_377.Equals(aAction.NUMB));
                        row.Locations = Regex.Unescape(t.text).Split('\n')
                                        .Select(s => JsonSerializer.Deserialize <Address>(s))
                                        .ToList();
                    }
                }
                catch (Exception) { }

                return(Unit.Value);
            }