Example #1
0
        public string Parse(LJPCall sendCallParameter)
        {
            string jsonMessageSerialized = "";

            string[] aParamsType = null;
            using (MemoryStream ms = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(ms))
                {
                    //Desearilizing Parameters
                    string[] aParamsSerialized = new string[sendCallParameter.Parameters.Count];
                    aParamsType = new string[sendCallParameter.Parameters.Count];

                    for (int i = 0; i < sendCallParameter.Parameters.Count; i++) //Type tpeParameterFE in oDTOLJPResponse.aParametersType)
                    {
                        DataContractJsonSerializer jsonSerializerParameter = new DataContractJsonSerializer(
                            sendCallParameter.Parameters[i].GetType());
                        jsonSerializerParameter.WriteObject(ms, sendCallParameter.Parameters[i]);//Write object in memory stream

                        ms.Position = 0;
                        string sJson = new StreamReader(ms).ReadToEnd();//read memory stream of serialized object

                        aParamsType[i]       = sendCallParameter.Parameters[i].GetType().Name;
                        aParamsSerialized[i] = sJson;//Output array
                    }

                    LJPCallMessageDTO ljpCallMessageDTO = new LJPCallMessageDTO
                    {
                        Parameters = aParamsSerialized,
                        Credential = new LJPCredentialDTO
                        {
                            Identifiers = sendCallParameter.Credential?.Identifier,
                            Roles       = sendCallParameter.Credential?.Roles,
                        }
                    };

                    ms.Position = 0;
                    DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(LJPCallMessageDTO));
                    jsonSerializer.WriteObject(ms, ljpCallMessageDTO);
                    ms.Position           = 0;
                    jsonMessageSerialized = new StreamReader(ms).ReadToEnd();
                }
            }

            return(jsonMessageSerialized);
        }