Esempio n. 1
0
        // do the update coord job
        private void UpdateCoord(ProgressDialog progressDialog, double dlat, double dlon)
        {
            try
            {
                // Iterate on selection
                int nb = 1;
                foreach (String id in _ids)
                {
                    // Is it canceled ?
                    if (_Canceled)
                    {
                        break; // Yes
                    }
                    // Update progress
                    progressDialog.Progress = nb;

                    // Get info
                    String         post_response = ""; // Not used here
                    GCNotification gcn           = _gcstuffs.GetNotificationData(id, ref post_response);
                    if (gcn != null)
                    {
                        // We update :-)
                        // WE NEED TO USE the previous post_response to get valid VIEW_STATES
                        // We build the post string
                        String post_string = GCStuffs.GeneratePostString(post_response, dlat, dlon, gcn.distance, gcn.name, gcn.data, gcn.email, gcn.checknotif);
                        String url         = "https://www.geocaching.com/notify/edit.aspx?NID=" + id;

                        // And we post
                        post_response = GCStuffs.GeneratePostRequets(url, post_string, _gcstuffs._cookieJar);
                    }

                    nb++;
                }

                // Kill progressdialog (we are in UI thread already, good)
                RunOnUiThread(() => progressDialog.Hide());

                // All right!
                if (_Canceled)
                {
                    RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Canceled), ToastLength.Short).Show());
                    // Don't go to main activity !!!
                }
                else
                {
                    RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Success), ToastLength.Short).Show());

                    // Then go back to main activity
                    GoToMainActivity(true);
                }
            }
            catch (Exception)
            {
                // Kill progressdialog (we are in UI thread already, good)
                RunOnUiThread(() => progressDialog.Hide());

                // Crap
                RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Error), ToastLength.Short).Show());
            }
        }
        // do the creation job
        private void CreateNotificationsImpl(ProgressDialog progressDialog, double dlat, double dlon, int distance, String name, List <Tuple <int, string, List <string>, int> > selectedTypes, String email)
        {
            try
            {
                // we create notifications
                // No iterate on selected type and create !
                String url           = "https://www.geocaching.com/notify/edit.aspx";
                String post_response = "";
                String post_string   = "";
                int    nb            = 1;
                bool   error         = false;
                String warning       = "";
                foreach (var tpl in selectedTypes)
                {
                    // Is it canceled ?
                    if (_Canceled)
                    {
                        break; // Yes
                    }
                    // Update progress
                    progressDialog.Progress = nb;

                    // Progress message
                    RunOnUiThread(() => progressDialog.SetMessage(this.Resources.GetString(Resource.String.LblCreateInProgress) + " - " + tpl.Item2));

                    // On demande la page par défaut pour initialiser une nouvelle demande
                    HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
                    objRequest.CookieContainer = _gcstuffs._cookieJar;                     // surtout récupérer le container de cookie qui est maintenant renseigné avec le cookie d'authentification
                    HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
                    using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))
                    {
                        post_response = responseStream.ReadToEnd();
                        responseStream.Close();
                    }
                    // On regarde si on a claqué le nombre max
                    warning = GCStuffs.CheckWarningMessage(post_response);
                    if (warning != "")
                    {
                        error = true;
                        break;
                    }

                    // Une mise à jour pour définir le type de cache
                    post_string   = GCStuffs.GeneratePostString(post_response, dlat, dlon, distance, name, tpl, email, true);
                    post_response = GCStuffs.GeneratePostRequets(url, post_string, _gcstuffs._cookieJar);

                    // Une mise à jour pour définir le type de notif
                    post_string   = GCStuffs.GeneratePostString(post_response, dlat, dlon, distance, name, tpl, email, true);
                    post_response = GCStuffs.GeneratePostRequets(url, post_string, _gcstuffs._cookieJar);

                    // Vérification de la création correcte !
                    warning = GCStuffs.CheckValidationMessage(post_response);
                    if (warning != "")
                    {
                        error = true;
                        break;
                    }

                    // On décoche le type que l'on vient de poster
                    foreach (var tc in _typecaches)
                    {
                        if (tc.Type == tpl.Item2)
                        {
                            // Found it !
                            // On le décoche
                            RunOnUiThread(() => tc.Checked = false);
                        }
                    }

                    nb++;
                }

                // Kill progressdialog (we are in UI thread already, good)
                RunOnUiThread(() => progressDialog.Hide());

                // All right!
                if (error)
                {
                    RunOnUiThread(() => Toast.MakeText(this, warning, ToastLength.Long).Show());
                    // Don't go to main activity !!!
                }
                else if (_Canceled)
                {
                    RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Canceled), ToastLength.Short).Show());
                    // Don't go to main activity !!!
                }
                else
                {
                    RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Success), ToastLength.Short).Show());

                    // Then go back to main activity
                    GoToMainActivity(true);
                }
            }
            catch (Exception ex)
            {
                // Kill progressdialog (we are in UI thread already, good)
                RunOnUiThread(() => progressDialog.Hide());

                // Crap
                RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Error) + "\n" + ex.Message, ToastLength.Long).Show());
            }
        }