Exemple #1
0
        private void postImageAsData(String url, byte[] data, Action <String, Exception> callback)
        {
            // Generate post objects
            Dictionary <string, object> postParameters = new Dictionary <string, object>();

            postParameters.Add("Filename", "file.jpg");
            postParameters.Add("Fileformat", "jpg");
            postParameters.Add("Filedata", new MultipartFormData.FileParameter(data, "file.jpg", "image/jpeg"));

            // Create request and receive response
            string postURL   = url;
            string userAgent = "Someone";

            MultipartFormData.MultipartFormDataPost(postURL, userAgent, postParameters, (webResponse, ex) =>
            {
                if (webResponse != null && ex == null)
                {
                    StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                    string fullResponse         = responseReader.ReadToEnd();
                    if (callback != null)
                    {
                        callback(fullResponse, null);
                    }
                }
                else
                if (callback != null)
                {
                    callback(null, ex);
                }
            });
        }
Exemple #2
0
        private String postImageAsData(String url, byte[] data)
        {
            // Generate post objects
            Dictionary <string, object> postParameters = new Dictionary <string, object>();

            postParameters.Add("Filename", "file.jpg");
            postParameters.Add("Fileformat", "jpg");
            postParameters.Add("Filedata", new MultipartFormData.FileParameter(data, "file.jpg", "image/jpeg"));

            // Create request and receive response
            string          postURL     = url;
            string          userAgent   = "Someone";
            HttpWebResponse webResponse = MultipartFormData.MultipartFormDataPost(postURL, userAgent, postParameters);

            // Process response
            StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
            string       fullResponse   = responseReader.ReadToEnd();

            return(fullResponse);
        }
Exemple #3
0
        public static Dictionary <Netmera.BasePush.PushChannel, NetmeraPushDetail> sendPushMessage(String url, Dictionary <string, object> postParameters)
        {
            string userAgent = "Someone";

            StringBuilder strBuild = new StringBuilder(url);

            strBuild.Append("&").Append(NetmeraConstants.Netmera_SDK_Params).Append(NetmeraConstants.Netmera_SDK_Value);
            strBuild.Append("&").Append(NetmeraConstants.Netmera_SDKVERSION_Params).Append(NetmeraConstants.Netmera_SDKVERSION_Value);

            HttpWebResponse response = MultipartFormData.MultipartFormDataPost(url, userAgent, postParameters);

            if (response != null)
            {
                int statusCode = (int)response.StatusCode;

                if (statusCode == 200)
                {
                    Stream responseStream = response.GetResponseStream();
                    if (responseStream != null)
                    {
                        StreamReader responseStreamReader = new StreamReader(responseStream);
                        string       responseStr          = responseStreamReader.ReadToEnd();

                        JObject json = JObject.Parse(responseStr);
                        if (json.Value <int>("code") == 1000)
                        {
                            json = json.Value <JObject>("result");

                            Dictionary <Netmera.BasePush.PushChannel, NetmeraPushDetail> result = new Dictionary <Netmera.BasePush.PushChannel, NetmeraPushDetail>();

                            if (json[NetmeraConstants.Netmera_Push_Type_Android] != null)
                            {
                                NetmeraPushDetail androidDetail = new NetmeraPushDetail();
                                JObject           androidJson   = json.Value <JObject>(NetmeraConstants.Netmera_Push_Type_Android);
                                if (androidJson.Value <int>("code") == 1000)
                                {
                                    androidDetail = parsePushResponse(androidJson);
                                }
                                else
                                {
                                    String error = androidJson.Value <String>("message");
                                    androidDetail.setError(error);
                                }
                                result.Add(Netmera.BasePush.PushChannel.android, androidDetail);
                            }
                            if (json[NetmeraConstants.Netmera_Push_Type_Ios] != null)
                            {
                                NetmeraPushDetail iosDetail = new NetmeraPushDetail();
                                JObject           iosJson   = json.Value <JObject>(NetmeraConstants.Netmera_Push_Type_Ios);
                                if (iosJson.Value <int>("code") == 1000)
                                {
                                    iosDetail = parsePushResponse(iosJson);
                                }
                                else
                                {
                                    String error = iosJson.Value <String>("message");
                                    iosDetail.setError(error);
                                }
                                result.Add(Netmera.BasePush.PushChannel.ios, iosDetail);
                            }
                            if (json[NetmeraConstants.Netmera_Push_Type_Wp] != null)
                            {
                                NetmeraPushDetail wpDetail = new NetmeraPushDetail();
                                JObject           wpJson   = json.Value <JObject>(NetmeraConstants.Netmera_Push_Type_Wp);
                                if (wpJson.Value <int>("code") == 1000)
                                {
                                    wpDetail = parsePushResponse(wpJson);
                                }
                                else
                                {
                                    String error = wpJson.Value <String>("message");
                                    wpDetail.setError(error);
                                }
                                result.Add(Netmera.BasePush.PushChannel.wp, wpDetail);
                            }
                            return(result);
                        }
                        else
                        {
                            String error = json.Value <String>("message");
                            throw new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_ERROR, error);
                        }
                    }
                    else
                    {
                        throw new NetmeraException(NetmeraException.ErrorCode.EC_NULL_EXCEPTION, "Response entity is null while sending notification to devices");
                    }
                }
                else
                {
                    throw new NetmeraException(NetmeraException.ErrorCode.EC_HTTP_PROTOCOL_EXCEPTION, "Http exception occurred while sending notification to android devices");
                }
            }
            else
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_NULL_EXCEPTION, "Response is null while sending notification to android devices");
            }
        }