예제 #1
0
        public void Load_user()
        {
            var Sync = SynchronizationContext.Current;

            #region User baru online
            hub.On <string, string>("onNewUserConnected", (id, username) =>
            {
                Sync.Post(_ =>
                {
                    ConnectedUsers.Add(new Members(username, id));

                    listOnline.DataSource = ConnectedUsers;
                }, null);
            });
            #endregion

            #region load daftar user
            hub.On <string, string>("onConnected", (Cid, id) =>
            {
                Sync.Post(_ =>
                {
                    myId = id;
                    if (Cid != null)
                    {
                        var users = Cid.Split('?');
                        foreach (var user in users)
                        {
                            var splUser = user.Split('|');
                            ConnectedUsers.Add(new Members(splUser[1], splUser[0]));

                            listOnline.DataSource = ConnectedUsers;
                        }
                    }
                }, null);
            });
            #endregion

            #region Hapus daftar user
            hub.On <string, string>("onDisconnected", (id, username) =>
            {
                Sync.Post(_ =>
                {
                    var item = ConnectedUsers.FirstOrDefault(x => x.id == id);
                    if (item != null)
                    {
                        ConnectedUsers.Remove(item);
                        listOnline.DataSource = ConnectedUsers;
                    }
                }, null);
            });
            #endregion

            hub.Invoke("Connect", textUsername.Text).Wait();
        }
예제 #2
0
        private bool SendEmailMessage(string Subject, string Body, List <string> ListEmailTO, List <string> ListEmailCC = null, List <string> ListEmailBCC = null, MailPriority Priority = MailPriority.Normal, List <string> ListAttchementPath = null, string LinkedResources = null)
        {
            try
            {
                System.Net.Mail.MailMessage objMail = new System.Net.Mail.MailMessage();
                //Set from address
                objMail.From = new MailAddress(this.SenderEmailAddress);

                // Set to addresses
                if (ListEmailTO != null)
                {
                    if (ListEmailTO.Count > 0)
                    {
                        foreach (string emailTO in ListEmailTO)
                        {
                            if (!string.IsNullOrEmpty(emailTO))
                            {
                                objMail.To.Add(new MailAddress(emailTO));
                            }
                        }
                    }
                }

                // Set CC addresses
                if (ListEmailCC != null)
                {
                    if (ListEmailCC.Count > 0)
                    {
                        foreach (string emailCC in ListEmailCC)
                        {
                            objMail.CC.Add(new MailAddress(emailCC));
                        }
                    }
                }

                // Set BCC addresses
                if (ListEmailBCC != null)
                {
                    if (ListEmailBCC.Count > 0)
                    {
                        foreach (string emailBCC in ListEmailBCC)
                        {
                            objMail.Bcc.Add(new MailAddress(emailBCC));
                        }
                    }
                }

                // Set the content
                // Set subject
                objMail.Subject = Subject;
                // Set body/message
                // objMail.Body = Body;
                AlternateView htmlMail = null;
                htmlMail = AlternateView.CreateAlternateViewFromString(Body, null, MediaTypeNames.Text.Html);

                // Set priority default is "Normal"
                objMail.Priority = Priority;

                if (!string.IsNullOrEmpty(LinkedResources))
                {
                    List <string> _LinkedResources = LinkedResources.Split(',').ToList();
                    foreach (string Cid in _LinkedResources)
                    {
                        if (!string.IsNullOrEmpty(Cid))
                        {
                            string[] _Cid      = Cid.Split('^').ToArray();
                            string   path      = System.Web.HttpContext.Current.Server.MapPath(_Cid[0]);
                            string   contentid = _Cid[1];

                            LinkedResource myimage = new LinkedResource(path);
                            myimage.ContentId = contentid;

                            // Create HTML view
                            // Set ContentId property. Value of ContentId property must be the same as
                            // the src attribute of image tag in email body.
                            htmlMail.LinkedResources.Add(myimage);
                        }
                    }
                }

                objMail.AlternateViews.Add(htmlMail);
                objMail.IsBodyHtml = true;

                // Set priority default is "Normal"
                objMail.Priority = Priority;

                // Set attachement
                if (ListAttchementPath != null)
                {
                    if (ListAttchementPath.Count > 0)
                    {
                        foreach (string path in ListAttchementPath)
                        {
                            objMail.Attachments.Add(new Attachment(path));
                        }
                    }
                }

                SmtpClient SMTPClientObj = new SmtpClient();
                SMTPClientObj.Credentials = new System.Net.NetworkCredential(this.SenderEmailAddress, this.SenderPassword);
                SMTPClientObj.Host        = this.SenderHostName;
                SMTPClientObj.Port        = this.SenderPort;
                SMTPClientObj.EnableSsl   = this.EnableSSL;
                SMTPClientObj.Send(objMail);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }