Example #1
0
        public static void UpdateTopicPeople(string topicid, List <string> relatedPeople, Controller ctrl)
        {
            var sql = "delete from auroratopicpeople where topicid = '<topicid>'";

            sql = sql.Replace("<topicid>", topicid);
            DBUtility.ExeLocalSqlNoRes(sql);

            foreach (var p in relatedPeople)
            {
                sql = "insert into auroratopicpeople(topicid,people) values(@topicid,@people)";
                var param = new Dictionary <string, string>();
                param.Add("@topicid", topicid);
                param.Add("@people", p);
                DBUtility.ExeLocalSqlNoRes(sql, param);
            }

            var pdict = CfgUtility.GetEmployeeDict(ctrl);

            foreach (var p in relatedPeople)
            {
                if (!pdict.ContainsKey(p))
                {
                    sql = "delete from auroranewpeople where people = '<people>'";
                    sql = sql.Replace("<people>", p);
                    DBUtility.ExeLocalSqlNoRes(sql);

                    sql = "insert into auroranewpeople(people) values('<people>')";
                    sql = sql.Replace("<people>", p);
                    DBUtility.ExeLocalSqlNoRes(sql);
                }
            }
        }
Example #2
0
        public SysAuthorization(Controller ctrl)
        {
            var syscfg    = CfgUtility.GetSysConfig(ctrl);
            var sUsername = syscfg["SHAREFOLDERUSER"];
            var sDomain   = syscfg["SHAREFOLDERDOMIN"];
            var sPassword = syscfg["SHAREFOLDERPWD"];

            // initialize tokens

            IntPtr pExistingTokenHandle  = new IntPtr(0);
            IntPtr pDuplicateTokenHandle = new IntPtr(0);

            try
            {
                // get handle to token
                bool bImpersonated = LogonUser(sUsername, sDomain, sPassword,

                                               LOGON32_LOGON_NEWCREDENTIALS, LOGON32_PROVIDER_DEFAULT, ref pExistingTokenHandle);
                if (true == bImpersonated)
                {
                    if (!ImpersonateLoggedOnUser(pExistingTokenHandle))
                    {
                        int nErrorCode = Marshal.GetLastWin32Error();
                        throw new Exception("ImpersonateLoggedOnUser error;Code=" + nErrorCode);
                    }
                }
                else
                {
                    int nErrorCode = Marshal.GetLastWin32Error();
                    throw new Exception("LogonUser error;Code=" + nErrorCode);
                }
            }

            finally
            {
                // close handle(s)
                if (pExistingTokenHandle != IntPtr.Zero)
                {
                    CloseHandle(pExistingTokenHandle);
                }
                if (pDuplicateTokenHandle != IntPtr.Zero)
                {
                    CloseHandle(pDuplicateTokenHandle);
                }
            }
        }
Example #3
0
        public static bool SendEmail(Controller ctrl, string title, List <string> tolist, string content, bool isHtml = true, string attachpath = null)
        {
            //if (IsDebug())
            //    return true;

            try
            {
                var syscfgdict = CfgUtility.GetSysConfig(ctrl);

                var message = new MailMessage();
                if (!string.IsNullOrEmpty(attachpath))
                {
                    var attach = new Attachment(attachpath);
                    message.Attachments.Add(attach);
                }

                message.IsBodyHtml = isHtml;
                message.From       = new MailAddress(syscfgdict["APPEMAILADRESS"]);
                foreach (var item in tolist)
                {
                    if (IsEmaileValid(item))
                    {
                        message.To.Add(item);
                    }
                }

                message.Subject = title;
                message.Body    = content.Replace("\r\n", "<br>").Replace("\r", "<br>");

                SmtpClient client = new SmtpClient();
                client.Host                  = syscfgdict["EMAILSERVER"];
                client.EnableSsl             = true;
                client.Timeout               = 60000;
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials           = new NetworkCredential(syscfgdict["APPEMAILADRESS"], syscfgdict["APPEMAILPWD"]);

                ServicePointManager.ServerCertificateValidationCallback
                    = delegate(object s, X509Certificate certificate, X509Chain chain
                               , SslPolicyErrors sslPolicyErrors) { return(true); };

                new Thread(() => {
                    try
                    {
                        client.Send(message);
                    }
                    catch (SmtpFailedRecipientsException ex)
                    {
                        logthdinfo("SmtpFailedRecipientsException exception: " + ex.Message);
                        try
                        {
                            message.To.Clear();
                            foreach (var item in tolist)
                            {
                                if (ex.Message.Contains(item))
                                {
                                    try
                                    {
                                        message.To.Add(item);
                                    }
                                    catch (Exception e) { logthdinfo("Address exception2: " + e.Message); }
                                }
                            }
                            client.Send(message);
                        }
                        catch (Exception ex1)
                        {
                            logthdinfo("nest exception1: " + ex1.Message);
                        }
                    }
                    catch (Exception ex)
                    {
                        logthdinfo("send exception: " + ex.Message);
                    }
                }).Start();
            }
            catch (Exception ex)
            {
                logthdinfo("main exception: " + ex.Message);
                return(false);
            }
            return(true);
        }