internal void SendRequest(MATUrlBuilder.URLInfo urlInfo)
        {
            this.currentUrlInfo = urlInfo;
            string url = urlInfo.url + "&sdk_retry_attempt=" + urlInfo.retryAttempt;
            //string url = "https://877.debug.engine.mobileapptracking.com/junk"; //For debugging purposes

            /*request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // Write the request Asynchronously
            using (var stream = await Task.Factory.FromAsync<Stream>(request.BeginGetRequestStream,
                                                                     request.EndGetRequestStream, null))
            {
                //create some json string
                string json = "{ \"my\" : \"json\" }";

                // convert json to byte array
                byte[] jsonAsBytes = Encoding.UTF8.GetBytes(json);

                // Write the bytes to the stream
                await stream.WriteAsync(jsonAsBytes, 0, jsonAsBytes.Length);
            }*/

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.BeginGetResponse(GetUrlCallback, request);
        }
        // Add a url to event queue to send later
        internal void AddToQueue(MATUrlBuilder.URLInfo url)
        {
            lock (syncLock)
            {
                if (queueThread == null || !queueThread.IsAlive)
                {
                    queueThread = new Thread(delegate() //Start on separate thread to avoid UI slowdown
                    {
                        List <MATUrlBuilder.URLInfo> eventQueue;
                        // Get existing event queue or create new one
                        if (IsolatedStorageSettings.ApplicationSettings.Contains(SETTINGS_MATEVENTQUEUE_KEY) &&
                            IsolatedStorageSettings.ApplicationSettings[SETTINGS_MATEVENTQUEUE_KEY].GetType() == typeof(List <MATUrlBuilder.URLInfo>))
                        {
                            eventQueue = (List <MATUrlBuilder.URLInfo>)IsolatedStorageSettings.ApplicationSettings[SETTINGS_MATEVENTQUEUE_KEY];
                        }
                        else // No existing queue, create
                        {
                            IsolatedStorageSettings.ApplicationSettings.Remove(SETTINGS_MATEVENTQUEUE_KEY);
                            eventQueue = new List <MATUrlBuilder.URLInfo>();
                        }

                        eventQueue.Add(url);
                        SaveLocalSetting(SETTINGS_MATEVENTQUEUE_KEY, eventQueue);
                    });
                    queueThread.Start();
                }
            }
        }
        internal void SendRequest(MATUrlBuilder.URLInfo urlInfo)
        {
            this.currentUrlInfo = urlInfo;
            string url = urlInfo.url + "&sdk_retry_attempt=" + urlInfo.retryAttempt;
            //string url = "https://877.debug.engine.mobileapptracking.com/junk"; //For debugging purposes

            /*request.Method = "POST";
             * request.ContentType = "application/x-www-form-urlencoded";
             *
             * // Write the request Asynchronously
             * using (var stream = await Task.Factory.FromAsync<Stream>(request.BeginGetRequestStream,
             *                                                       request.EndGetRequestStream, null))
             * {
             *  //create some json string
             *  string json = "{ \"my\" : \"json\" }";
             *
             *  // convert json to byte array
             *  byte[] jsonAsBytes = Encoding.UTF8.GetBytes(json);
             *
             *  // Write the bytes to the stream
             *  await stream.WriteAsync(jsonAsBytes, 0, jsonAsBytes.Length);
             * }*/

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

            request.BeginGetResponse(GetUrlCallback, request);
        }
        internal void ProcessTrackingRequest(string action, string eventName, double revenue, string currency, string refId, List <MATEventItem> eventItems, Parameters copy)
        {
            lock (syncLock)
            {
                if (queueThread == null || !queueThread.IsAlive)
                {
                    queueThread = new Thread(delegate() //Start on separate thread to avoid slowdown
                    {
                        DumpQueue();                    //Clear anything from the last dump
                        List <MATUrlBuilder.URLInfo> eventQueue;
                        // Get existing event queue or create new one
                        if (IsolatedStorageSettings.ApplicationSettings.Contains(SETTINGS_MATEVENTQUEUE_KEY) &&
                            IsolatedStorageSettings.ApplicationSettings[SETTINGS_MATEVENTQUEUE_KEY].GetType() == typeof(List <MATUrlBuilder.URLInfo>))
                        {
                            eventQueue = (List <MATUrlBuilder.URLInfo>)IsolatedStorageSettings.ApplicationSettings[SETTINGS_MATEVENTQUEUE_KEY];
                        }
                        else // No existing queue, create
                        {
                            IsolatedStorageSettings.ApplicationSettings.Remove(SETTINGS_MATEVENTQUEUE_KEY);
                            eventQueue = new List <MATUrlBuilder.URLInfo>();
                        }

                        MATUrlBuilder.URLInfo url = MATUrlBuilder.BuildUrl(action, eventName, revenue, currency, refId, eventItems, copy);
                        eventQueue.Add(url);
                        SaveLocalSetting(SETTINGS_MATEVENTQUEUE_KEY, eventQueue);

                        if (parameters.matResponse != null)
                        {
                            parameters.matResponse.EnqueuedActionWithRefId(refId);
                        }

                        DumpQueue();
                    });
                    queueThread.Start();
                }
            }
        }