OMEconomy.OMBase.CommunicationHelpers.SerializeDictionary C# (CSharp) Method

SerializeDictionary() public method

public SerializeDictionary ( string>.Dictionary data ) : String
data string>.Dictionary
return String
        public String SerializeDictionary(Dictionary<string, string> data)
        {
            string value = String.Empty;
            if(data.Count == 0)
            {
                return value;
            }

            foreach (KeyValuePair<string, string> pair in data)
            {
                value += pair.Key + "=" + pair.Value + "&";
            }
            return value.Remove(value.Length - 1);
        }

Usage Example

Ejemplo n.º 1
0
        public static Dictionary <string, string> DoRequest(string url, Dictionary <string, string> postParameters)
        {
            string postData = postParameters == null ? "" : CommunicationHelpers.SerializeDictionary(postParameters);
            String str      = String.Empty;

            #region // Debug
#if DEBUG
            m_log.Debug("[OMECONOMY] Request: " + url + "?" + postData);
#endif
            #endregion

            try
            {
#if INSOMNIA
                ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); };
#endif

                str = SynchronousRestFormsRequester.MakeRequest("POST", url, postData, 20000);

                #region // Debug
#if DEBUG
                string meth = "";
                if ((postParameters != null) && !postParameters.TryGetValue("method", out meth))
                {
                    meth = "";
                }
                m_log.DebugFormat("[OMECONOMY] Response {0}: {1}", meth, str.Trim());
#endif
                #endregion

                Dictionary <string, string> returnValue = JsonMapper.ToObject <Dictionary <string, string> >(str);
                return(returnValue != null ? returnValue : new Dictionary <string, string>());
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[OMECONOMY]: Could not parse response Exception: {0} - {1}", e.Message, e.StackTrace);
                return(null);
            }
        }