Пример #1
0
        public static List <string> GetKeywordPhraseArray(string keywords)
        {
            string        remainingKeywords, keyword;
            List <string> result = new List <string>();

            //' do a keyword/phrase split
            remainingKeywords = VB.trim(keywords);
            for (; remainingKeywords != "";)
            {
                remainingKeywords = VB.trim(remainingKeywords) + " ";
                if (VB.left(remainingKeywords, 1) == "\"")                      //' strip off quote
                {
                    remainingKeywords = VB.mid(remainingKeywords, 2);
                    //' look for end quote
                    int endQuotePos;
                    endQuotePos = VB.instr(remainingKeywords, "\"");
                    if (endQuotePos > 0)
                    {
                        //' take this token
                        keyword = VB.left(remainingKeywords, endQuotePos - 1);
                        //' remove these from the keywords To Process
                        remainingKeywords = VB.mid(remainingKeywords, endQuotePos + 1);
                    }
                    else
                    {
                        //' no end quote so just assume end
                        keyword           = remainingKeywords;
                        remainingKeywords = "";
                    }
                }
                else
                {
                    //' does not start with a quote, so take first word
                    int endWordPos;
                    endWordPos = VB.instr(remainingKeywords, " ");
                    //' take this token
                    keyword = VB.left(remainingKeywords, endWordPos - 1);
                    //' remove these from the keywords To Process
                    remainingKeywords = VB.mid(remainingKeywords, endWordPos + 1);
                }                //end if

                keyword = VB.trim(keyword);
                if (keyword != "")
                {
                    result.Add(keyword);
                }        //end if
            }            //loop
            return(result);
        }
Пример #2
0
 public static int CalcPageCount(int numResults, int itemsPerPage)
 {
     return(VB.fix((numResults - 1) / itemsPerPage) + 1);
 }
Пример #3
0
        public bool SendEmail(string subject, string msg, string messagePlainText, string options, string toEmail, string toName, string fromEmail, string fromName, string attachments, string replyToEmail)
        {
            bool result = true;

            msg = VB.replace(msg, "@", "&#64;");            // encode any email addresses to fool spiders - 20110404 JN Added

            MailMessage message = new System.Net.Mail.MailMessage();

            // Set destinations for the e-mail message.
            if (toEmail.Contains(";"))
            {
                string[] toAddresses = toEmail.Split(';');
                foreach (string address in toAddresses)
                {
                    message.To.Add(new MailAddress(address));
                }
            }
            else
            {
                MailAddress to = new MailAddress(toEmail, toName);
                message.To.Add(to);
            }
            // override email address for dev server
            if (IsEmailOverride)
            {
                message.To.Clear();
                message.To.Add(new MailAddress(EmailOverrideAddress));
            }

            // Specify the e-mail sender.
            // Create a mailing address that includes a UTF8 character
            // in the display name.
            MailAddress from = new MailAddress(fromEmail, fromName, System.Text.Encoding.UTF8);

            message.From = from;
            // Specify the message content.
#if DOTNET4
            message.ReplyToList.Add(new MailAddress(replyToEmail));
#else
            message.ReplyTo = new MailAddress(replyToEmail);
#endif
            message.Body = msg;             //"This is a test e-mail message sent by an application. ";
            // Include some non-ASCII characters in body and subject.
            string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
            //message.Body += Environment.NewLine + someArrows;
            message.BodyEncoding    = System.Text.Encoding.UTF8;
            message.Subject         = subject;    //"test message 1" + someArrows;
            message.SubjectEncoding = System.Text.Encoding.UTF8;
            // Set the method that is called back when the send operation ends.
            //client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);

            if (options.ToLower().IndexOf("html") != -1)
            {
                message.IsBodyHtml = true;
            }
            if (messagePlainText.IsNotBlank())
            {
                //if same, create a non-html version of the msg by removing tags
                //messagePlainText=Fmt.StripTags(msg); //dont strip - too slow 20110411JN
                message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(messagePlainText, null, "text/plain"));
            }

            message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(msg, null, "text/html"));
            // The userState can be any object that allows your callback
            // method to identify this send operation.
            // For this example, the userToken is a string constant.
            //string userState = "test message1";

            if (attachments.IsNotBlank())
            {
                if (attachments.IndexOf(";") == -1)                //20110404 JN Fixed
                {
                    string     file = attachments;
                    Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
                    // Add time stamp information for the file.
                    ContentDisposition disposition = data.ContentDisposition;
                    disposition.CreationDate     = System.IO.File.GetCreationTime(file);
                    disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
                    disposition.ReadDate         = System.IO.File.GetLastAccessTime(file);
                    // Add the file attachment to this e-mail message.
                    message.Attachments.Add(data);
                    //data.Dispose();
                }
                else
                {
                    string[] files = attachments.Split(new Char[] { ';' });                    //20110404 JN Fixed
                    foreach (string file in files)
                    {
                        Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
                        // Add time stamp information for the file.
                        ContentDisposition disposition = data.ContentDisposition;
                        disposition.CreationDate     = System.IO.File.GetCreationTime(file);
                        disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
                        disposition.ReadDate         = System.IO.File.GetLastAccessTime(file);
                        // Add the file attachment to this e-mail message.
                        message.Attachments.Add(data);
                    }
                }
            }
            //string file = "";
            // Create	the file attachment for this e-mail message.
            //Send the message.
            //SmtpClient client = new SmtpClient(server);
            // Add credentials if the SMTP server requires them.
            //client.Credentials = CredentialCache.DefaultNetworkCredentials;
            SmtpClient client = GetServerSmtpClient();
            try {
                //Send the message.
                client.Send(message);
                // Display the values in the ContentDisposition for the attachment.
                //ContentDisposition cd = data.ContentDisposition;
                //Console.WriteLine("Content disposition");
                //Console.WriteLine(cd.ToString());
                //Console.WriteLine("File {0}", cd.FileName);
                //Console.WriteLine("Size {0}", cd.Size);
                //Console.WriteLine("Creation {0}", cd.CreationDate);
                //Console.WriteLine("Modification {0}", cd.ModificationDate);
                //Console.WriteLine("Read {0}", cd.ReadDate);
                //Console.WriteLine("Inline {0}", cd.Inline);
                //Console.WriteLine("Parameters: {0}", cd.Parameters.Count);
                //foreach(DictionaryEntry d in cd.Parameters)
                //{
                //	Console.WriteLine("{0} = {1}", d.Key, d.Value);
                //}


                //client.SendAsync(message, userState);			 // see client.SendCompleted above
                //client.Send(message);

                //client.SendAsyncCancel();	     // see client.SendCompleted above
                // Clean up.
            } catch (Exception e) {
                string serverType = Util.ServerIs();
                string authuser   = ConfigurationManager.AppSettings.Get("EmailAuthUser" + serverType);
                string authpass   = ConfigurationManager.AppSettings.Get("EmailAuthPassword" + serverType);
                this.errorResult = "Error -em2: [" + e.Message + "] usr[" + authuser + "] Host[" + client.Host + "] from[" + message.From + "]to[" + toEmail + "] [" + e.Message + "]";
                throw new Exception(errorResult);
            }
            message.Dispose();
            return(result);
        }