Example #1
0
        public void openConnection()
        {
            string conectionString = "Data Source=" + this.ip + this.serverInstance + this.port + ";" +
                                     "Initial Catalog=" + this.nameDataBase + ";" +
                                     "User ID=" + this.username + ";" +
                                     "Password="******"Data Source=" + this.serverInstance + ";" +
             *          "Initial Catalog=" + this.nameDataBase + ";" +
             *          "Integrated Security=true;";*/

            this.con = new SqlConnection(conectionString);

            try
            {
                this.con.Open();
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                string message = e.Message;
                message = message.Replace("'", "");
                string queryToLog2 = "insert into SystemLogs (Description,ErrorDate, IntegrationId) values('Class SqlServer: " + message + "','" + DateTime.Now + "'," + this.integration.integrationId + ")";
                integration.insertLog(queryToLog2);
            }
        }
        public void sendMail(string smtpUser, string smtpPassword, string smtpServer, string smtpPort, string from, string destination, string subject, string body, string Attachment, string pathLog, Integration integration)
        {
            try
            {
                MailMessage mail = new MailMessage(from, destination, subject, body);
                SmtpClient  smtp = new SmtpClient();

                Attachment data  = new Attachment(Attachment, MediaTypeNames.Application.Octet);
                Attachment data2 = new Attachment(pathLog, MediaTypeNames.Application.Octet);

                mail.Attachments.Add(data);
                mail.Attachments.Add(data2);

                smtp.Host        = smtpServer;
                smtp.Port        = Convert.ToInt32(smtpPort);
                smtp.Credentials = new NetworkCredential(smtpUser, smtpPassword);

                smtp.EnableSsl = true;
                smtp.Send(mail);
            }
            catch (System.ArgumentException e)
            {
                string message = e.Message;
                message = message.Replace("'", "");
                string queryToLog2 = "insert into SystemLogs (Description,ErrorDate, IntegrationId) values('Class Send Mails: " + message + "','" + DateTime.Now + "'," + integration.integrationId + ")";
                integration.insertLog(queryToLog2);
            }
            catch (System.IO.IOException e)
            {
                string message = e.Message;
                message = message.Replace("'", "");
                string queryToLog2 = "insert into SystemLogs (Description,ErrorDate, IntegrationId) values('Class Send Mails: " + message + "','" + DateTime.Now + "'," + integration.integrationId + ")";
                integration.insertLog(queryToLog2);
            }
        }
 public void openConnection()
 {
     try
     {
         connection.Open();
     }
     catch (MySqlException e)
     {
         string message = e.Message;
         message = message.Replace("'", "");
         string query = "insert into SystemLogs (Description,ErrorDate, IntegrationId) values('Class Mysql: " + message + "','" + DateTime.Now + "'," + this.integration.integrationId + ")";
         integration.insertLog(query);
     }
 }
        public string writeFileinFlatFile(string resultQuery, string locationToSave, string nameIntegration, Integration integration)
        {
            string nameFile = nameIntegration + "-" + returnDatetimeNow() + ".txt";
            string path     = locationToSave + "/" + nameFile;

            try
            {
                FileStream fs = new FileStream(path, FileMode.Append);
                using (StreamWriter file = new StreamWriter(fs, Encoding.UTF8))
                {
                    string[] resultParse = resultQuery.Split('%');

                    for (int i = 0; i < resultParse.Length; i++)
                    {
                        file.WriteLine(resultParse[i]);
                    }

                    file.Close();
                }
            }
            catch (DirectoryNotFoundException e)
            {
                string message = e.Message;
                message = message.Replace("'", "");
                string query = "insert into SystemLogs (Description,ErrorDate, IntegrationId) values('Class WriteFile: " + message + "','" + DateTime.Now + "'," + integration.integrationId + ")";
                integration.insertLog(query);
            }

            return(path + "|" + nameFile);
        }
        public string Read(string pathLog, int integrationId, Integration integration)
        {
            try
            {
                StreamReader file = new StreamReader(pathLog);

                string line  = "";
                string line2 = "";

                // Read the file and display it line by line.

                while ((line = file.ReadLine()) != null)
                {
                    line2 += line + "%";
                }

                line2 = line2.Replace("'", "");
                string[] ContentFile = line2.Split('%');

                if (ContentFile[1].Equals("200"))
                {
                    return(ReturnSuccessStatus(integrationId, file, ContentFile));
                }

                else
                {
                    return(ReturnErrorStatus(integrationId, file, line2));
                }
            }
            catch (System.IO.IOException e)
            {
                string message = e.Message;
                message = message.Replace("'", "");
                string queryToLog = "insert into SystemLogs (Description,ErrorDate, IntegrationId) values('Class SqlServer: " + message + "','" + DateTime.Now + "'," + integration.integrationId + ")";
                integration.insertLog(queryToLog);
                return("");
            }
        }
Example #6
0
        public void IntegrationWithCurl(string parameter, Integration integration)
        {
            try
            {
                //Indicamos que deseamos inicializar el proceso cmd.exe junto a un comando de arranque.
                //(/C, le indicamos al proceso cmd que deseamos que cuando termine la tarea asignada se cierre el proceso).
                System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + parameter);

                //Indica que el proceso no despliegue una pantalla negra (El proceso se ejecuta en background)
                procStartInfo.CreateNoWindow = true;
                //Esconder la ventana
                procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                //Inicializa el proceso
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo = procStartInfo;
                proc.Start();
            }
            catch (System.ComponentModel.Win32Exception e)
            {
                string query = "insert into SystemLogs (Description,ErrorDate, IntegrationId) values('Class Curl: " + e.Message + "','" + DateTime.Now + "'," + integration.integrationId + ")";
                integration.insertLog(query);
            }
        }