Exemplo n.º 1
0
        //Envio de e-mail
        //Tipo:
        //1 = Envio de log para quem criou atualização;
        //2 = Envio de comunicado para grupo

        public static void SendMail(string toEmail, int type, GALibrary.Models.UpdateGA update, GALibrary.Models.EmailSettings emailSettings, GALibrary.Models.Parameter parameter, String aplicacao, Models.Ldap ldap)
        {
            try
            {
                string        body   = "";
                Models.UserAD userAD = GALibrary.GAAD.GetADUserData(ldap, update.User);


                if (toEmail == null)
                {
                    toEmail = userAD.Mail;
                }

                MailMessage mail = new MailMessage();

                body = SendMailBody(type, update, aplicacao, userAD.FullName);
                LinkedResource header = new LinkedResource(parameter.MailHeader);
                header.ContentId = "header";
                LinkedResource footer = new LinkedResource(parameter.MailFooter);
                footer.ContentId = "footer";


                mail.To.Add(new MailAddress(toEmail));
                AlternateView bodyImages = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html);
                bodyImages.LinkedResources.Add(header);
                bodyImages.LinkedResources.Add(footer);
                mail.AlternateViews.Add(bodyImages);


                mail.Subject    = $"GA - {aplicacao} - {update.Name}";
                mail.Body       = body;
                mail.IsBodyHtml = true;
                mail.Priority   = MailPriority.High;
                mail.From       = new MailAddress(emailSettings.From);



                SmtpClient smtp = new SmtpClient(emailSettings.Server, emailSettings.Port);

                smtp.Credentials = new NetworkCredential(emailSettings.Username, emailSettings.Password);
                smtp.EnableSsl   = false;
                smtp.Send(mail);
                smtp.Dispose();
                mail.Dispose();

                GALogs.SaveLog("Email", "email enviado com sucesso para " + toEmail, 2, parameter);
            }
            catch (Exception erro)
            {
                GALogs.SaveLog("Email", "Erro ao enviar e-mail a atualização - " + update.Name + " - " + erro, 1, parameter);
            }
        }
Exemplo n.º 2
0
        //Compacta a pasta do backup
        public static String CompressFolder(UpdateGA update, Parameter parameter)
        {
            String pathBackup = parameter.PathBackup;

            if (!pathBackup.EndsWith("\\"))
            {
                pathBackup += "\\";
            }

            pathBackup += update.Schedule.GetValueOrDefault().Date.Year.ToString().PadLeft(4, '0') + "\\" + update.Schedule.GetValueOrDefault().Date.Month.ToString().PadLeft(2, '0') + "\\" + update.Id + "\\";
            String name = "Backup.zip";

            String pathZip = pathBackup;

            if (!System.IO.Directory.Exists(pathBackup))
            {
                return(null);
            }

            if (System.IO.File.Exists(pathZip + "\\" + name))
            {
                System.IO.File.Delete(pathZip + "\\" + name);
            }

            try
            {
                Guid   guid = Guid.NewGuid();
                String arquivoTemporario = parameter.PathTemp + "\\" + guid + ".zip";
                ZipFile.CreateFromDirectory(pathZip, arquivoTemporario);
                System.IO.File.Copy(arquivoTemporario, pathZip + "backup.zip", true);
                System.IO.File.Delete(arquivoTemporario);

                foreach (String folder in System.IO.Directory.GetDirectories(pathZip))
                {
                    System.IO.Directory.Delete(folder, true);
                }

                GALogs.SaveLog("Compress", "Arquivos compactados com sucesso para o ID - " + update.Id, 2, parameter);
            }
            catch (Exception error)
            {
                GALogs.SaveLog("Compress", "Erro ao compactar arquivos para o update id - " + update.Id + " - " + error, 1, parameter);
                return(error.ToString());
            }
            return(null);
        }