Exemple #1
0
 public CIVAccount()
 {
     IsActive = true;
     AlertSettings = new Alert();
     Account = new VideotronAccount();
     SendMail = false;
 }
Exemple #2
0
 public CIVAccount()
 {
     IsActive = true;
     AlertSettings = new Alert();
     Account = new VideotronAccount();
     SendMail = false;
     Id = Guid.NewGuid();
     SystrayDisplay = false;
 }
Exemple #3
0
        /// <summary>
        /// Met à jours les données d'un client avec celles disponible sur internet
        /// </summary>
        /// <param name="client"></param>
        public bool Execute(VideotronAccount client)
        {
            Success = false;

            _error = null;

            _client = client;

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

            try
            {
                GetInternetUsage();
                Success = true;
            }
            catch (Exception requestError)
            {
                DoError(requestError);
                _error = requestError;
            }

            return Success;
        }
Exemple #4
0
        /// <summary>
        /// Met à jours les données d'un client avec celles disponible sur internet
        /// </summary>
        /// <param name="client"></param>
        public bool Execute(VideotronAccount client)
        {
            Success = false;

            _error = null;

            _client = client;

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

            try
            {
                GetInternetUsage();
                Success = true;
            }
            catch (Exception requestError)
            {
                DoError(requestError);
                _error = requestError;
            }

            return(Success);
        }
Exemple #5
0
 public MailTagFactory(VideotronAccount account)
 {
     _account = account;
 }
Exemple #6
0
        /// <summary>
        /// Envoi un courriel en format HTML
        /// </summary>
        /// <param name="tagFormater">L'objet de conversion des tags initialiser avec un compte</param>
        /// <param name="smtp">La configuration du serveur SMTP</param>
        /// <param name="recipients">La liste des récipients</param>
        /// <param name="subject">Le sujet du courriel</param>
        /// <param name="templateFile">Le modèle à utiliser pour le courriel</param>
        /// <param name="img">L'image du graphique</param>
        public void SendMailHTML(MailTagFormater tagFormater,
                                 SmtpSettings smtp,
                                 string recipients,
                                 string subject,
                                 string templateFile,
                                 VideotronAccount account)
        {
            // Les templates personnalisé sont plus fort que ceux de base (notion d'override)
            // Si le template n'existe pas, on prend le premier de la liste
            if (MailTemplates.FirstOrDefault(p => p.Name == templateFile) == null)
                templateFile = MailTemplates.FirstOrDefault().Name;

            subject = tagFormater.Convert(subject);

            StringBuilder template = new StringBuilder(tagFormater.Convert(MailTemplates.FirstOrDefault(p => p.Name == templateFile).GetContent()));

            SmtpClient client = new SmtpClient(smtp.Host, smtp.Port);
            client.Credentials = new NetworkCredential(smtp.Username, smtp.Password);

            MailMessage message = new MailMessage();

            message.From = new MailAddress(smtp.SenderMail, smtp.Sender, System.Text.Encoding.UTF8);

            foreach (string address in recipients.Split(';'))
                message.To.Add(new MailAddress(address));

            message.Subject = subject;

            switch (MailTemplates.FirstOrDefault(p => p.Name == templateFile).Encoding)
            {
                case MailTemplate.MailTemplateEncodingType.ASCII:
                    message.SubjectEncoding = System.Text.Encoding.ASCII;
                    message.BodyEncoding = System.Text.Encoding.ASCII;
                    break;
                case MailTemplate.MailTemplateEncodingType.ISO8859:
                    message.SubjectEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
                    message.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
                    break;
                default:
                    message.SubjectEncoding = System.Text.Encoding.UTF8;
                    message.BodyEncoding = System.Text.Encoding.UTF8;
                    break;
            }

            // Modèle HTML
            if (MailTemplates.FirstOrDefault(p => p.Name == templateFile).IsHTML)
            {
                message.IsBodyHtml = true;
                AlternateView htmlView;

                // Embebbed image
                List<string> embeddedImageFile = new List<string>();
                Match embeddedImage;
                string addedImage;
                do
                {
                    embeddedImage = Regex.Match(template.ToString(), "src=\"(?<src>[^cid]+)\"", RegexOptions.IgnoreCase);

                    if (embeddedImage.Success)
                    {
                        addedImage = System.IO.Path.Combine(MailTemplates.FirstOrDefault(p => p.Name == templateFile).Folder,
                                                            embeddedImage.Groups["src"].Value);
                        if (!File.Exists(addedImage))
                            throw new FileNotFoundException(addedImage);

                        embeddedImageFile.Add(addedImage);
                        template.Replace(String.Format("{0}", embeddedImage.Groups["src"].Value), String.Format("cid:img{0}", embeddedImageFile.Count));
                    }
                }
                while (embeddedImage.Success);

                // Insertion du graphique
                // Il faudrait le mettre dans MailTagFormater, mais c'est compliqué, pas le temps
                List<Tuple<int, int>> graphSize = new List<Tuple<int, int>>();
                Match match = Regex.Match(template.ToString(), @"\[GRAPH(\((?<param>[^\)]*)?\))?\]", RegexOptions.IgnoreCase);
                int graphCount = 0;
                int delta = 0;
                while (match.Success)
                {
                    int width = 430;
                    int height = 230;

                    Match paramMatch = Regex.Match(match.Groups["param"].Value,
                                                   @"(?<method>[a-z]{3,})=(?<param>[^,]+)",
                                                   RegexOptions.IgnoreCase);
                    while (paramMatch.Success)
                    {
                        if (paramMatch.Groups["method"].Value.ToUpper() == "WIDTH")
                            width = Convert.ToInt32(paramMatch.Groups["param"].Value);
                        else if (paramMatch.Groups["method"].Value.ToUpper() == "HEIGHT")
                            height = Convert.ToInt32(paramMatch.Groups["param"].Value);
                        paramMatch = paramMatch.NextMatch();
                    }

                    graphSize.Add(new Tuple<int, int>(width, height));

                    template.Remove(match.Index + delta, match.Length);
                    string newValue = String.Format("<img src=\"cid:graph_{0}\" width=\"{1}\" height=\"{2}\" />",
                                                    graphCount,
                                                    width,
                                                    height);
                    template.Insert(match.Index + delta, newValue);

                    if (match.Length > newValue.Length)
                        delta -= match.Length - newValue.Length;
                    else if (match.Length < newValue.Length)
                        delta += newValue.Length - match.Length;

                    graphCount++;
                    match = match.NextMatch();
                }

                htmlView = AlternateView.CreateAlternateViewFromString(template.ToString(), System.Text.Encoding.UTF8, "text/html");
                for (int i = 0; i < graphSize.Count; i++)
                {
                    System.Drawing.Image img;
                    MemoryStream memoryGraph = new MemoryStream();
                    GraphFactory graphFactory = new GraphFactory();
                    ZedGraphControl graph = graphFactory.Generate(account.Username,
                                                    new Period(account.PeriodStart, account.PeriodEnd),
                                                    graphSize[i].Item1, graphSize[i].Item2);

                    img = graph.GetImage();
                    img.Save(memoryGraph, System.Drawing.Imaging.ImageFormat.Jpeg);
                    memoryGraph.Position = 0;

                    htmlView.LinkedResources.Add(new LinkedResource(memoryGraph,
                                                                    MediaTypeNames.Image.Jpeg) {
                                                 ContentId = String.Format("graph_{0}", i),
                                                 TransferEncoding = TransferEncoding.Base64 });
                }

                for (int i = 0; i < embeddedImageFile.Count; i++)
                {
                    if (Regex.Match(embeddedImageFile[i], "(jpg|jpeg)$", RegexOptions.IgnoreCase).Success)
                        htmlView.LinkedResources.Add(new LinkedResource(embeddedImageFile[i], MediaTypeNames.Image.Jpeg) { ContentId = String.Format("img{0}", i + 1), TransferEncoding = TransferEncoding.Base64 });
                    else if (Regex.Match(embeddedImageFile[i], "gif$", RegexOptions.IgnoreCase).Success)
                        htmlView.LinkedResources.Add(new LinkedResource(embeddedImageFile[i], MediaTypeNames.Image.Gif) { ContentId = String.Format("img{0}", i + 1), TransferEncoding = TransferEncoding.Base64 });
                    else if (Regex.Match(embeddedImageFile[i], "tiff$", RegexOptions.IgnoreCase).Success)
                        htmlView.LinkedResources.Add(new LinkedResource(embeddedImageFile[i], MediaTypeNames.Image.Tiff) { ContentId = String.Format("img{0}", i + 1), TransferEncoding = TransferEncoding.Base64 });
                    else
                        htmlView.LinkedResources.Add(new LinkedResource(embeddedImageFile[i]) { ContentId = String.Format("img{0}", i + 1), TransferEncoding = TransferEncoding.Base64 });
                }

                message.AlternateViews.Add(htmlView);
            }

            // Plain/Text
            else
            {
                message.Body = template.ToString();
            }
            client.Send(message);
            message.Dispose();
        }
Exemple #7
0
 public UsagePieChart(VideotronAccount account, Color combinedColor, Color combinedRemainingColor)
 {
     _account = account;
     _combinedColor = combinedColor;
     _combinedRemainingColor = combinedRemainingColor;
 }