Example #1
0
        /// <summary>
        /// Agrega a la tabla verifications la verificacion del usuario
        /// </summary>
        /// <param name="land"></param>
        /// <param name="isAlert"></param>
        /// <returns></returns>
        public LandMini AddVerification(LandMini land, bool isAlert)
        {
            connection.Open();
            var command = connection.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "Land_AddVerification";
            //bool isAlertBool = isAlert ? 1 : 0;
            int verifications = connection.Query <int>(string.Format("EXEC Land_AddVerification {0}, {1}, {2}", land.LandId, land.Id, isAlert)).First();

            connection.Close();
            return(VerificationScoring(land, verifications));
        }
Example #2
0
        private void VerificationScoring(LandMini landMini)
        {
            if (landMini != null)
            {
                try
                {
                    //Mando los mails notificando
                    if (!string.IsNullOrEmpty(landMini.Email))
                    {
                        if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["smtp.enabled"]))
                        {
                            List <System.Net.Mail.MailMessage> messages = new List <System.Net.Mail.MailMessage>();

                            System.Net.Mail.MailAddress address     = new System.Net.Mail.MailAddress(landMini.Email);
                            System.Net.Mail.MailAddress addressFrom = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["smtp.user"], Labels.Labels.GuardiansGreenpeace);
                            System.Net.Mail.MailMessage message     = new System.Net.Mail.MailMessage();
                            message.From = addressFrom;
                            message.To.Add(address);
                            message.Subject = Labels.Labels.LandVerifications.ToString();

                            string domain = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).GetLeftPart(UriPartial.Authority);

                            string htmlTemplate = System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mail.html"));
                            message.Body = string.Format(htmlTemplate, Labels.Labels.LandVerifications2
                                                         , Labels.Labels.LandVerifications3
                                                         , string.Format("{0}/index.html?geohexcode={1}", domain, landMini.GeohexKey), Labels.Labels.LandVerifications4, Labels.Labels.LandVerifications5, Labels.Labels.LandVerifications6, landMini.Email
                                                         , Labels.Labels.LandVerifications7
                                                         , Labels.Labels.LandVerifications8, domain);
                            message.IsBodyHtml   = true;
                            message.BodyEncoding = System.Text.Encoding.UTF8;
                            message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.None;
                            messages.Add(message);

                            SendMails.Send(messages);
                        }
                    }

                    //Genero la imagen de este land
                    ImagesGeneratorTool.Run(landRepository, true, landMini.GeohexKey);

                    //Notify the land owner if logged in
                    var context = GlobalHost.ConnectionManager.GetHubContext <Hubs>();
                    context.Clients.All.LandVerified(landMini.EarthwatcherId);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Busca al primer usuario que reporto esa parcela con 30 verif, le asigna los puntos, lockea la parcela y la pasa a greenpeace.
        /// </summary>
        /// <param name="land"></param>
        /// <param name="verifications"></param>
        /// <returns></returns>
        private LandMini VerificationScoring(LandMini land, int verifications)
        {
            if (verifications >= 30) //cantidad de Verifications
            {
                //Si es el usuario de Greenpeace debería buscar el owner original
                if (land.EarthwatcherId == Configuration.GreenpeaceId)
                {
                    connection.Open();

                    int?ewId = connection.Query <int>(string.Format("EXEC Land_VerificationScoring {0}, {1}", land.LandId, Configuration.GreenpeaceId)).SingleOrDefault();
                    if (ewId != null)
                    {
                        land.EarthwatcherId = Convert.ToInt32(ewId);
                    }
                    connection.Close();
                }

                //Obtengo el mail del owner original para mandarle la notificacion por mail
                connection.Open();
                string idobjMail = connection.Query <string>(string.Format("EXEC Land_VerificationScoring_2 {0}, {1}", land.LandId, Configuration.GreenpeaceId)).SingleOrDefault();
                if (idobjMail != null)
                {
                    land.Email = idobjMail;
                }
                connection.Close();

                //Obtengo el earthwatcher para agregarle los puntos
                connection.Open();
                Earthwatcher earthwatcher = connection.Query <Earthwatcher>(string.Format("EXEC Earthwatcher_GetEarthwatcher {0}", land.EarthwatcherId)).FirstOrDefault();
                connection.Close();

                //Le asigno los 2000 puntos
                var scoreRepository = new ScoreRepository(connection.ConnectionString);
                scoreRepository.PostScore(new Score(earthwatcher.Id, ActionPoints.Action.LandVerified.ToString(), ActionPoints.Points(ActionPoints.Action.LandVerified), earthwatcher.PlayingRegion, land.LandId));

                //El owner de la parcela pasa a ser Greenpeace y la parcela se lockea
                connection.Open();
                var cmd = connection.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Land_VerificationScoring_3";
                cmd.Parameters.Add(new SqlParameter("@LandId", land.LandId));
                cmd.ExecuteNonQuery();
                connection.Close();
                return(land);
            }
            return(null);
        }
Example #4
0
        public void AddPoll(LandMini land)
        {
            client.Authenticator = new HttpBasicAuthenticator(Current.Instance.Username, Current.Instance.Password);

            var request = new RestRequest("land/addpoll", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.JsonSerializer = new JsonSerializer();
            request.AddBody(land);

            client.ExecuteAsync(request, response =>
                                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                                          PollAdded(null, null)
                                                                          ));
        }
Example #5
0
 private void NotificateUsers(LandMini newLand, int earthwatcherId)
 {
     if (newLand != null && newLand.IsUsed)
     {
         try
         {
             //Comunico a los usuarios conectados si es que la nueva land es de un usuario existente
             var context = GlobalHost.ConnectionManager.GetHubContext <Hubs>();
             context.Clients.All.LandChanged(newLand.GeohexKey, earthwatcherId);
             logger.Info("Paso bien por el NotificateUsers");
         }
         catch (Exception ex)
         {
             logger.Error("Ocurrio una excepcion en el Notificate Users. Message: {0},  StackTrace:{1}", ex.Message, ex.StackTrace);
         }
     }
 }
Example #6
0
 public HttpResponseMessage Deconfirm(LandMini land, HttpRequestMessage <LandMini> request)
 {
     try
     {
         LandMini landMini = landRepository.AddVerification(land, true);
         VerificationScoring(landMini);
         return(new HttpResponseMessage {
             StatusCode = HttpStatusCode.OK
         });
     }
     catch (Exception ex)
     {
         return(new HttpResponseMessage {
             StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = ex.Message
         });
     }
 }
Example #7
0
 public HttpResponseMessage Confirm(LandMini land, HttpRequestMessage <LandMini> request)
 {
     try
     {
         LandMini landMini = landRepository.AddVerification(land, false); //TODO: revisar que no llegue nulo
         VerificationScoring(landMini);
         return(new HttpResponseMessage {
             StatusCode = HttpStatusCode.OK
         });
     }
     catch (Exception ex)
     {
         return(new HttpResponseMessage {
             StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = ex.Message
         });
     }
 }
Example #8
0
 public HttpResponseMessage AddPoll(LandMini land, HttpRequestMessage <LandMini> request)
 {
     try
     {
         landRepository.AddPoll(land);
         return(new HttpResponseMessage()
         {
             StatusCode = HttpStatusCode.Created
         });
     }
     catch (Exception ex)
     {
         return(new HttpResponseMessage()
         {
             StatusCode = HttpStatusCode.InternalServerError, ReasonPhrase = ex.Message
         });
     }
 }
Example #9
0
        public void Confirm(Land land, ConfirmationSort confirmationSort, string username, string password)
        {
            client.Authenticator = new HttpBasicAuthenticator(username, password);
            var landMini = new LandMini {
                LandId = land.Id, EarthwatcherId = land.EarthwatcherId.Value, Id = Current.Instance.Earthwatcher.Id, GeohexKey = land.GeohexKey
            };
            var request = new RestRequest("land/" + confirmationSort.ToString().ToLower(), Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.JsonSerializer = new JsonSerializer();

            request.AddBody(landMini);
            client.ExecuteAsync(request, response =>
                                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                                          ConfirmationAdded(confirmationSort, null)
                                                                          ));
        }
Example #10
0
        private void ActionButton_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;

            if (button == null)
            {
                return;
            }

            if (button.Name == "ButtonDontKnow")
            {
                LoadNextImage();
            }
            else
            {
                LandMini land = new LandMini {
                    GeohexKey = code, EarthwatcherId = Current.Instance.Earthwatcher.Id, IsUsed = button.Name == "ButtonYes" ? true : false
                };
                landRequests.AddPoll(land);
            }
        }
Example #11
0
        public void UpdateWinner(int earthWatcherId, int posId, string nickName)
        {
            client.Authenticator = new HttpBasicAuthenticator(Current.Instance.Username, Current.Instance.Password);
            var request = new RestRequest("jaguarpositions/updateWinner", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };
            LandMini earthwatcher = new LandMini {
                EarthwatcherId = earthWatcherId, LandId = posId, Email = nickName
            };

            request.JsonSerializer = new JsonSerializer();
            request.AddBody(earthwatcher);

            client.ExecuteAsync(request, response =>
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    Console.WriteLine("Ocurrio un error en la comunicación");     //TODO: tirar cartel al usuario.
                }
            });
        }
Example #12
0
        public HttpResponseMessage Update(LandMini landMini, HttpRequestMessage <LandMini> request)
        {
            try
            {
                jaguarRepository.Update(landMini.EarthwatcherId, landMini.LandId);

                var context = GlobalHost.ConnectionManager.GetHubContext <Hubs>();
                context.Clients.All.JaguarFound(landMini.Email, landMini.EarthwatcherId);

                return(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.InternalServerError, ReasonPhrase = ex.Message
                });
            }
        }
Example #13
0
 /// <summary>
 /// Guarda en la tabla PollResults el resultado de la poll
 /// </summary>
 /// <param name="land"></param>
 public void AddPoll(LandMini land)
 {
     try
     {
         connection.Open();
         var command = connection.CreateCommand();
         command.CommandType = CommandType.StoredProcedure;
         command.CommandText = "Land_AddPoll";
         command.Parameters.Add(new SqlParameter("@GeohexKey", land.GeohexKey));
         command.Parameters.Add(new SqlParameter("@EarthwatcherId", land.EarthwatcherId));
         command.Parameters.Add(new SqlParameter("@IsUsed", land.IsUsed ? 1 : 0));
         command.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         connection.Close();
     }
 }