Beispiel #1
0
        protected IHttpActionResult CallAsyncMacroGetResult(string actionId, bool closeSession = true)
        {
            // Get values from X-HopexSession
            IEnumerable <string> hopexSessionHeader;
            HopexSessionInfo     hopexSessionInfo;

            if (!Request.Headers.TryGetValues("X-HopexSession", out hopexSessionHeader) || !HopexServiceHelper.TryGetHopexSessionInfo(hopexSessionHeader.FirstOrDefault(), out hopexSessionInfo))
            {
                var message = "Parameter \"X-HopexSession\" must be set in the header of your request.";
                Logger.Debug(message);
                return(BadRequest(message));
            }

            // Get the existing Hopex session
            var hopexService = HopexServiceHelper.GetMwasService(hopexSessionInfo.MwasUrl, hopexSessionInfo.HopexSessionToken);

            // Call the execution result of the macro in async mode
            var asyncMacroResult = hopexService.CallAsyncMacroGetResult(actionId);

            // Return status if action is not finished
            if (asyncMacroResult.Status == "InProgress")
            {
                return(Ok(asyncMacroResult.Status));
            }

            // Close the Hopex session
            if (closeSession)
            {
                hopexService.CloseUpdateSession();
            }

            // Return the macro result
            return(Ok(asyncMacroResult.Status == "Terminate" ? asyncMacroResult.Result : JsonConvert.SerializeObject(asyncMacroResult)));
        }