/**
         * Envia la señal de inicio y termino del registro de datos. Tambien cambia dicho estado en la interfaz
         */
        private void ToggleLogger()
        {
            logKeys = !logKeys;

            if (logKeys)
            {
                LimeLogger.Start();
                btnClockToggle.Text = "Detener registro";
                lblEstado.Text      = "Estado: REGISTRANDO";

                timer.Elapsed += new ElapsedEventHandler(OnTimedSend);
                timer.Interval = Persistence.Interval; //default is 5 minutes
                timer.Start();
            }
            else
            {
                LimeLogger.Stop();
                LogManager.SendLog(login.Agent);
                btnClockToggle.Text = "Iniciar registro";
                lblEstado.Text      = "Estado: En espera";

                timer.Stop();
            }
        }
 private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
 {
     LimeLogger.Stop();
     login.Visible = true;
     this.Dispose();
 }
Esempio n. 3
0
        /**
         * Envia el registro al servidor y en caso exitoso limpiara los buffer temporales.
         */
        async public static void SendLog(Agent agent)
        {
            try
            {
                LimeLogger.StoreBuffer();

                using (var wb = new WebClient())
                {
                    var data = new NameValueCollection();
                    data["username"] = agent.Username;
                    data["password"] = agent.Password;
                    data["log"]      = LimeLogger.GetFileBufferStr();

                    var    response    = wb.UploadValues(Persistence.Host + "/AgentLogger.aspx", "POST", data);
                    string responseStr = Encoding.UTF8.GetString(response);

                    Console.WriteLine("response: " + responseStr);

                    if (responseStr == "success")
                    {
                        LimeLogger.ClearFileBuffer();
                    }
                }


                //var values = new Dictionary<string, string>
                //{
                //    { "username", agent.Username },
                //    { "password", agent.Password },
                //    { "log", LimeLogger.GetFileBufferStr() }
                //};

                //var content = new FormUrlEncodedContent(values);
                //HttpResponseMessage response = await client.PostAsync(Persistence.Host + "/AgentLogger.aspx", content);
                //string responseString = await response.Content.ReadAsStringAsync();

                //Console.WriteLine("response: " + responseString);



                //WebRequest request = WebRequest.Create(Persistence.Host + "/AgentLogger.aspx");
                //request.Method = "POST";
                //request.ContentType = "application/x-www-form-urlencoded";



                //using (var client = new WebClient())
                //{
                //    var values = new NameValueCollection();
                //    values["username"] = agent.Username;
                //    values["password"] = agent.Password;
                //    values["log"] = LimeLogger.GetFileBufferStr();

                //    var response = client.UploadValues(Persistence.Host + "/AgentLogger.aspx", values);

                //    var responseString = Encoding.Default.GetString(response);
                //    Console.WriteLine("response: " + responseString);
                //}
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine("Error sending logs");
                Console.Out.WriteLine(ex.ToString());
            }
        }