コード例 #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);
 }
コード例 #2
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 };
     }
 }
コード例 #3
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 };
     }
 }
コード例 #4
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 };
     }
 }
コード例 #5
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)
                    ));
        }
コード例 #6
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.
                    }
                });
        }
コード例 #7
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 };
            }
        }
コード例 #8
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();
     }
 }
コード例 #9
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);
            }
        }
コード例 #10
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);
         }
     }
 }
コード例 #11
0
        public LandMini AddVerification(LandMini land, bool isAlert)
        {
        //    connection.Open();
        //    var command = connection.CreateCommand();
        //    command.CommandType = CommandType.StoredProcedure;
        //    int verifications = connection.Query<int>(string.Format("EXEC Land_AddVerification {0}, {1}, {2} ", land.LandId, land.Id, isAlert ? 1 : 0)).First();
        //    connection.Close();
        //    return VerificationScoring(land, verifications);
            connection.Open();
            var sql = string.Format(@"IF NOT EXISTS (select Earthwatcher from Verifications where land = {0} and earthwatcher = {1} and IsAlert = {2})
	                                    BEGIN
		                                    Delete From Verifications where land = {0} and earthwatcher = {1}
		                                    INSERT INTO Verifications (Land, Earthwatcher, IsAlert)
		                                    VALUES ({0}, {1}, {2})
		                                    Select count(Land) From Verifications Where land = {0}
	                                    END
                                    ELSE
                                        BEGIN
	                                        SELECT 0
                                    END

                                    Declare @Alert int = (select COUNT(IsAlert) as Alert from Verifications where IsDeleted = 0 and IsAlert = 1 and Land = {0})
                                    Declare @Ok int = (select COUNT(IsAlert) as Ok from Verifications where IsDeleted = 0 and IsAlert = 0 and Land = {0})
                                    Declare @ActualOwner int = (select top 1 Earthwatcher from EarthwatcherLands where Land = {0})
                                    Declare @OwnerVerification int = (select isAlert from Verifications where IsDeleted = 0 and Earthwatcher = @ActualOwner)
		
                                    update Land 
                                    set LandStatus = case when @Alert > @Ok then 4
					                                      when @Ok > @Alert then 3
					                                      when @ActualOwner != 17 and @OwnerVerification = 1 then 4 
					                                      when @ActualOwner != 17 and @OwnerVerification = 0 then 3 end
                                    where Id = {0}
                                    ", land.LandId, land.Id, isAlert ? 1 : 0);
            int verifications = connection.Query<int>(sql).First();
            connection.Close();
            return VerificationScoring(land, verifications);
        }
コード例 #12
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;
        }
コード例 #13
0
        private LandMini VerificationScoring(LandMini land, int verifications) //Busca al primer usuario que reporto esa parcela con 30 verif, le asigna los puntos, lockea la parcela y la pasa a greenpeace.
        {
            if (verifications >= 30) //cambiar 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();

                //Le asigno los 2000 puntos
                var scoreRepository = new ScoreRepository(connection.ConnectionString);
                scoreRepository.PostScore(new Score { Action = ActionPoints.Action.LandVerified.ToString(), LandId = land.LandId, EarthwatcherId = land.EarthwatcherId, Points = ActionPoints.Points(ActionPoints.Action.LandVerified), Published = DateTime.UtcNow });

                //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;
        }
コード例 #14
0
 public void AddPoll(LandMini land)  //Guarda en la tabla PollResults el resultado de la poll
 {
     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();
     connection.Close();
 }
コード例 #15
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;
                }
            }
        }
コード例 #16
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)
            ));
        }
コード例 #17
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"], "Guardianes - Greenpeace");
                            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                            message.From = addressFrom;
                            message.To.Add(address);
                            message.Subject = "Llegaste a las 30 verificaciones en tu parcela";

                            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, "Felicitaciones, otros 30 guardianes han verificado el reporte de tu parcela." 
                                , @"A partir de ahora Greenpeace verificará la validez del reporte!"
                                , string.Format("{0}/index.html?geohexcode={1}", domain, landMini.GeohexKey), "Click acá para seguir cuidando el bosque", "Cuidar el Bosque", "Este mensaje se envío a", landMini.Email
                                , ". Si no quieres recibir más notificaciones en un futuro podés acceder al Panel de Control del usuario y deshabilitar la opción de recibir notificaciones."
                                , "Greenpeace Argentina. Todos los derechos reservados.", 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;
                }
            }
        }