/// <summary>
        /// return an index page according to the inputs
        /// </summary>
        /// <returns></returns>
        public ActionResult IndexWithInputs()
        {
            dynamic obj = GetJsonObject(Request.InputStream);

            // retrieve the quant
            QuantizationFactorsArray quantArray = JsonHelper.RetrieveQuantsArray(obj.Params.QuantizationFactorsArray);
            EntropyAlgorithm         algorithm  = JsonHelper.CastTo <EntropyAlgorithm>(obj.Params.EntropyAlgorithm);


            _viewModel = new RFXDecodeViewModel();
            // Updates parameters
            ((RFXDecodeViewModel)_viewModel).ProvideParam(quantArray, algorithm);
            Triplet <string> triplet = JsonHelper.RetrieveTriplet(obj.Inputs);

            ((RFXDecodeViewModel)_viewModel).ProvidePanelInputs(triplet.ToArray());

            var envValues = new Dictionary <string, object>()
            {
                { ModelKey, _viewModel },
                { isModelValid, true }
            };

            SaveToSession(envValues);

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        public async Task <IActionResult> IndexWithInputs()
        {
            try
            {
                using (var bodyStream = new StreamReader(Request.Body))
                {
                    var bodyText = await bodyStream.ReadToEndAsync();

                    dynamic obj = JsonConvert.DeserializeObject(bodyText);

                    // retrieve the quant
                    QuantizationFactorsArray quantArray = JsonHelper.RetrieveQuantsArray(obj.Params.QuantizationFactorsArray);
                    EntropyAlgorithm         algorithm  = JsonHelper.CastTo <EntropyAlgorithm>(obj.Params.EntropyAlgorithm);

                    _viewModel = new RFXDecodeViewModel();
                    // Updates parameters
                    ((RFXDecodeViewModel)_viewModel).ProvideParam(quantArray, algorithm);
                    Triplet <string> triplet = JsonHelper.RetrieveTriplet(obj.Inputs);
                    ((RFXDecodeViewModel)_viewModel).ProvidePanelInputs(triplet.ToArray());

                    var envValues = new Dictionary <string, object>()
                    {
                        { ModelKey, _viewModel },
                        { isModelValid, true }
                    };

                    SaveToSession(envValues);
                }
                return(Json(ReturnResult <string> .Success("Success")));
            }
            catch (Exception ex)
            {
                return(Json(ReturnResult <string> .Fail(ex.Message)));
            }
        }
        public virtual ActionResult Recompute([FromBody] RecomputeRequest request)
        {
            // gets the action with the same name as the argument
            var action = _codecAction.SubActions.FirstOrDefault(c => c.Name.Equals(request.Action));

            // if action not found
            if (action == null)
            {
                return(Json(ReturnResult <string> .Fail("Action not found")));
            }

            // retrieve the quant
            var quantArray = JsonHelper.RetrieveQuantsArray(request.Params.QuantizationFactorsArray);

            foreach (var _action in _codecAction.SubActions)
            {
                _action.Parameters[Constants.PARAM_NAME_QUANT_FACTORS_ARRAY] = quantArray;
                _action.Parameters[Constants.PARAM_NAME_ENTROPY_ALGORITHM]   = JsonHelper.CastTo <EntropyAlgorithm>(request.Params.EntropyAlgorithm);
            }

            // retrive tiles from Inputs
            var tileList = new List <Tile>();

            foreach (var tileJson in request.Inputs)
            {
                Triplet <string> triplet    = JsonHelper.RetrieveTriplet(tileJson);
                string           dataFormat = request.Params.UseDataFormat;
                Tile             tile       = null;
                if (dataFormat.Equals(Constants.DataFormat.HEX))
                {
                    tile = Tile.FromStrings(triplet, new HexTileSerializer());
                }
                else
                {
                    tile = Tile.FromStrings(triplet, new IntegerTileSerializer());
                }
                if (dataFormat.Equals(Constants.DataFormat.FixedPoint_11_5))
                {
                    tile.RightShift(5);
                }
                if (dataFormat.Equals(Constants.DataFormat.FixedPoint_12_4))
                {
                    tile.RightShift(4);
                }

                tileList.Add(tile);
            }

            var result = action.DoAction(tileList.FirstOrDefault());

            // recompute the following steps and update
            bool following = false;
            Tile input     = result;

            foreach (var act in _codecAction.SubActions)
            {
                if (following)
                {
                    result = act.DoAction(input);
                    input  = result;
                }
                else
                {
                    if (act.Name.Equals(request.Action))
                    {
                        following = true;
                    }
                }
            }

            return(Json(ReturnResult <string> .Success("Success")));
        }
        public override ActionResult Recompute()
        {
            // TODO: Add parameters obtain into a function
            dynamic obj = GetJsonObject(Request.InputStream);

            string name = JsonHelper.CastTo <string>(obj.Action);

            // gets the action with the same name as the argument
            var action = _codecAction.SubActions.SingleOrDefault(c => c.Name.Equals(name));

            // if action not found
            if (action == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            // retrieve the quant
            var quantArray = JsonHelper.RetrieveQuantsArray(obj.Params.QuantizationFactorsArray);

            _codecAction.Parameters[Constants.PARAM_NAME_QUANT_FACTORS_ARRAY] = quantArray;

            // retrive the progressive quants
            var progQuantList = new List <QuantizationFactorsArray>();

            foreach (var layer in obj.Params.ProgQuantizationArray)
            {
                var layerQuants = JsonHelper.RetrieveQuantsArray(layer);
                progQuantList.Add(layerQuants);
            }
            var progQuantarray = new ProgressiveQuantizationFactors
            {
                ProgQuants = progQuantList
            };

            _codecAction.Parameters[Constants.PARAM_NAME_PROGRESSIVE_QUANT_LIST] = progQuantarray;

            _codecAction.Parameters[Constants.PARAM_NAME_ENTROPY_ALGORITHM]      = JsonHelper.CastTo <EntropyAlgorithm>(obj.Params.EntropyAlgorithm);
            _codecAction.Parameters[Constants.PARAM_NAME_USE_REDUCE_EXTRAPOLATE] = JsonHelper.CastTo <UseReduceExtrapolate>(obj.Params.UseReduceExtrapolate);

            // TODO: error handle
            var   preFramePath = (string)Session[PreviousFrameImage];
            Frame preFrame     = Utility.GetPreviousFrame(preFramePath, _codecAction.Parameters);

            ICodecAction diffing = _codecAction.SubActions.SingleOrDefault(c => c.Name.Equals(Constants.PENCODE_NAME_SUBBANDDIFFING));

            diffing.Parameters[Constants.PARAM_NAME_PREVIOUS_FRAME] = preFrame;

            // retrive tiles from Inputs
            var tileList = new List <Tile>();

            foreach (var tileJson in obj.Inputs)
            {
                Triplet <string> triplet = JsonHelper.RetrieveTriplet(tileJson);

                string dataFormat = obj.Params.UseDataFormat;
                Tile   tile       = null;
                if (dataFormat.Equals(Constants.DataFormat.HEX))
                {
                    tile = Tile.FromStrings(triplet, new HexTileSerializer());
                }
                else
                {
                    tile = Tile.FromStrings(triplet, new IntegerTileSerializer());
                }
                if (dataFormat.Equals(Constants.DataFormat.FixedPoint_11_5))
                {
                    tile.RightShift(5);
                }
                if (dataFormat.Equals(Constants.DataFormat.FixedPoint_12_4))
                {
                    tile.RightShift(4);
                }

                tileList.Add(tile);
            }

            var result = action.DoAction(tileList.ToArray());

            // recompute the following steps and update
            bool following = false;

            Tile[] input = result;
            foreach (var act in _codecAction.SubActions)
            {
                if (following)
                {
                    result = act.DoAction(input);
                    input  = result;
                }
                else
                {
                    if (act.Name.Equals(name))
                    {
                        following = true;
                    }
                }
            }

            // TODO: recompute the following steps and update

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        public override ActionResult Recompute()
        {
            dynamic obj = CodecBaseController.GetJsonObject(Request.InputStream);

            int layer = JsonHelper.CastTo <int>(obj.Layer);

            ICodecAction _rfxDecode = GetDecoderWithParameters(obj);

            string name = JsonHelper.CastTo <string>(obj.Action);

            // gets the action with the same name as the argument
            var action = _rfxDecode.SubActions.SingleOrDefault(c => c.Name.Equals(name));

            // if action not found
            if (action == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            // retrive tiles from Inputs
            var tileList = new List <Tile>();

            foreach (var tileJson in obj.Inputs)
            {
                Triplet <string> triplet = JsonHelper.RetrieveTriplet(tileJson);

                string dataFormat = obj.Params.UseDataFormat;
                Tile   tile       = null;
                if (dataFormat.Equals(Constants.DataFormat.HEX))
                {
                    tile = Tile.FromStrings(triplet, new HexTileSerializer());
                }
                else
                {
                    tile = Tile.FromStrings(triplet, new IntegerTileSerializer());
                }
                if (dataFormat.Equals(Constants.DataFormat.FixedPoint_11_5))
                {
                    tile.RightShift(5);
                }
                if (dataFormat.Equals(Constants.DataFormat.FixedPoint_12_4))
                {
                    tile.RightShift(4);
                }

                tileList.Add(tile);
            }

            // hand over parameters
            foreach (var key in _rfxDecode.Parameters.Keys)
            {
                action.Parameters[key] = _rfxDecode.Parameters[key];
            }

            var result = action.DoAction(tileList.ToArray());

            // recompute the following steps and update
            bool following = false;

            Tile[] input = result;
            foreach (var act in _rfxDecode.SubActions)
            {
                if (following)
                {
                    // hand over parameters
                    foreach (var key in _rfxDecode.Parameters.Keys)
                    {
                        act.Parameters[key] = _rfxDecode.Parameters[key];
                    }
                    result = act.DoAction(input);
                    input  = result;
                }
                else
                {
                    if (act.Name.Equals(name))
                    {
                        following = true;
                    }
                }
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }