Exemple #1
0
        public static string GetHttpContent(Uri uri, ContentPageParameters parameters)
        {
            string content = string.Empty;

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

            if (parameters != null)
            {
                if (parameters.AuthCookie != null)
                {
                    request.CookieContainer = new CookieContainer();
                    request.CookieContainer.Add(uri, parameters.AuthCookie);
                }

                if (parameters.IfModifiedSince.HasValue)
                {
                    request.IfModifiedSince = parameters.IfModifiedSince.Value;
                }

                request.UserAgent = parameters.UserAgent;
                request.Accept    = "*/*";
                request.KeepAlive = false;
            }

            WebResponse response = request.GetResponse();

            using (StreamReader sr = new StreamReader(response.GetResponseStream()))
            {
                content = sr.ReadToEnd();
                sr.Close();
            }

            return(content);
        }
Exemple #2
0
        public static string GetHttpContent(Uri uri, ContentPageParameters parameters)
        {
            string content = string.Empty;

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

            if (parameters != null)
            {
                if (parameters.AuthCookie != null)
                {
                    request.CookieContainer = new CookieContainer();
                    request.CookieContainer.Add(uri, parameters.AuthCookie);
                }

                if (parameters.IfModifiedSince.HasValue)
                {
                    request.IfModifiedSince = parameters.IfModifiedSince.Value;
                }

                request.UserAgent = parameters.UserAgent;
                request.Accept = "*/*";
                request.KeepAlive = false;
            }

            WebResponse response = request.GetResponse();
            using (StreamReader sr = new StreamReader(response.GetResponseStream()))
            {
                content = sr.ReadToEnd();
                sr.Close();
            }

            return content;
        }
 public static string GetContentAsUser(ISession session, int user_id, string relativeuri)
 {
     ContentPageParameters p = new ContentPageParameters();
     p.UserAgent = ManagedConfiguration.GetValue(session, "SnCore.Web.UserAgent", "SnCore/1.0");
     p.AuthCookie = GetUserAuthCookie(session, user_id);
     p.BaseUri = GetBaseUri(session);
     p.HasOnline = false;
     Uri pageuri = new Uri(p.BaseUri, relativeuri);
     return ContentPage.GetContent(pageuri, p);
 }
 public static string GetContentAsAdmin(ISession session, string relativeuri)
 {
     Uri baseuri = GetBaseUri(session);
     Uri pageuri = new Uri(baseuri, relativeuri);
     ContentPageParameters p = new ContentPageParameters();
     p.UserAgent = ManagedConfiguration.GetValue(session, "SnCore.Web.UserAgent", "SnCore/1.0");
     p.AuthCookie = GetAdminAuthCookie(session);
     p.BaseUri = baseuri;
     p.HasOnline = false;
     return ContentPage.GetContent(pageuri, p);
 }
Exemple #5
0
 public string GetContent()
 {
     Uri uri = new Uri(Request.Url, Url);
     string baseuri = SessionManager.WebsiteUrl;
     if (!baseuri.EndsWith("/")) baseuri = baseuri + "/";
     ContentPageParameters p = new ContentPageParameters();
     p.BaseUri = new Uri(baseuri);
     p.HasOnline = true;
     p.Note = inputNote.Text;
     p.UserAgent = SessionManager.GetCachedConfiguration("SnCore.Web.UserAgent", "SnCore/1.0");
     return ContentPage.GetContent(uri, p);
 }
Exemple #6
0
        public static string GetContent(Uri uri, ContentPageParameters parameters)
        {
            string content = GetHttpContent(uri, parameters);

            string[] expressions =
            {
                @"\<!-- NOEMAIL-START --\>.*?\<!-- NOEMAIL-END --\>",
                @"\<script.*?\<\/script\>",
                @"\<style.*?\<\/style\>",
                @"\<link.*?\<\/link\>",
                @"\<link.*?\/\>",
                @"href=""javascript:[0-9a-zA-Z$\._\';,\ =\(\)\[\]]*""",
                @".?onclick=""[0-9a-zA-Z\._\';,\ =\(\)\[\]]*""",
            };

            foreach (string r in expressions)
            {
                content = Regex.Replace(content, r, string.Empty,
                                        RegexOptions.IgnoreCase | RegexOptions.Singleline);
            }

            content = HtmlAbsoluteLinksWriter.Rewrite(content, parameters != null ? parameters.BaseUri : null);

            StringBuilder scontent = new StringBuilder(content);

            if (parameters != null && parameters.HasOnline)
            {
                scontent.Insert(0, string.Format("<p style=\"margin: 10px; font-size: 8pt;\">Do not hit 'reply' to this email! <a href=\"{0}\">Can't see message? click here for online version &#187;&#187;</a></p>\n", uri.ToString()));
            }

            // insert additional note
            if (parameters != null && !string.IsNullOrEmpty(parameters.Note))
            {
                scontent.Insert(0, string.Format("<p style=\"margin: 10px;\">{0}</p>\n", Renderer.Render(parameters.Note)));
            }

            // hack: insert stylesheet
            scontent.Insert(0, GetCss(parameters != null ? parameters.BaseUri : null));
            return(scontent.ToString());
        }
Exemple #7
0
        public static string GetContent(Uri uri, ContentPageParameters parameters)
        {
            string content = GetHttpContent(uri, parameters);

            string[] expressions = 
            { 
                @"\<!-- NOEMAIL-START --\>.*?\<!-- NOEMAIL-END --\>",
                @"\<script.*?\<\/script\>",
                @"\<style.*?\<\/style\>",
                @"\<link.*?\<\/link\>",
                @"\<link.*?\/\>",
                @"href=""javascript:[0-9a-zA-Z$\._\';,\ =\(\)\[\]]*""",
                @".?onclick=""[0-9a-zA-Z\._\';,\ =\(\)\[\]]*""",
            };

            foreach (string r in expressions)
            {
                content = Regex.Replace(content, r, string.Empty,
                    RegexOptions.IgnoreCase | RegexOptions.Singleline);
            }

            content = HtmlAbsoluteLinksWriter.Rewrite(content, parameters != null ? parameters.BaseUri : null);

            StringBuilder scontent = new StringBuilder(content);

            if (parameters != null && parameters.HasOnline)
            {
                scontent.Insert(0, string.Format("<p style=\"margin: 10px; font-size: 8pt;\">Do not hit 'reply' to this email! <a href=\"{0}\">Can't see message? click here for online version &#187;&#187;</a></p>\n", uri.ToString()));
            }

            // insert additional note
            if (parameters != null && ! string.IsNullOrEmpty(parameters.Note))
            {
                scontent.Insert(0, string.Format("<p style=\"margin: 10px;\">{0}</p>\n", Renderer.Render(parameters.Note)));
            }

            // hack: insert stylesheet
            scontent.Insert(0, GetCss(parameters != null ? parameters.BaseUri : null));
            return scontent.ToString();
        }
 public void linkFetch_Click(object sender, EventArgs e)
 {
     try
     {
         ContentPageParameters p = new ContentPageParameters();
         p.UserAgent = SessionManager.GetCachedConfiguration("SnCore.Web.UserAgent", "SnCore/1.0");
         Uri pageuri = new Uri(inputUrl.Text);
         string content = ContentPage.GetHttpContent(pageuri, p);
         HtmlPageInfo info = HtmlPageInfoExtractor.Extract(content);
         if (string.IsNullOrEmpty(info.Title))
         {
             TransitPlace place = SessionManager.GetInstance<TransitPlace, int>(
                 PlaceId, SessionManager.PlaceService.GetPlaceById);
             info.Title = place.Name;
         }
         inputName.Text = info.Title.Trim();
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("Error retreiving {0}\n{1}",
             inputUrl.Text, ex.Message));
     }
 }
        public void RunMarketingCampaign(ISession session, ManagedSecurityContext sec)
        {
            IList campaigns = session.CreateCriteria(typeof(Campaign))
                .Add(Expression.Eq("Active", true))
                .List();

            foreach (Campaign campaign in campaigns)
            {
                if (IsStopping)
                    break;

                IList recepients = session.CreateCriteria(typeof(CampaignAccountRecepient))
                    .Add(Expression.Eq("Sent", false))
                    .Add(Expression.Eq("Campaign.Id", campaign.Id))
                    .List();

                if (recepients.Count == 0)
                {
                    campaign.Active = false;
                    session.Save(campaign);
                    continue;
                }

                string baseuri = ManagedConfiguration.GetValue(session, "SnCore.WebSite.Url", "http://localhost/SnCore");
                if (!baseuri.EndsWith("/")) baseuri = baseuri + "/";
                ContentPageParameters parameters = new ContentPageParameters();
                parameters.UserAgent = ManagedConfiguration.GetValue(session, "SnCore.Web.UserAgent", "SnCore/1.0");
                parameters.BaseUri = new Uri(baseuri);
                string content = ContentPage.GetContent(new Uri(campaign.Url), parameters);

                foreach (CampaignAccountRecepient recepient in recepients)
                {
                    if (IsStopping)
                        break;

                    try
                    {
                        ManagedAccount m_recepient = new ManagedAccount(session, recepient.Account);

                        string mailto;
                        if (!m_recepient.TryGetVerifiedEmailAddress(out mailto, sec))
                            throw new Exception("No verified e-mail address.");

                        m_recepient.SendAccountEmailMessage(
                            campaign.SenderEmailAddress, mailto,
                            campaign.Name, content, true);

                        recepient.LastError = string.Empty;
                    }
                    catch (ThreadAbortException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        recepient.LastError = ex.Message;
                    }
                    finally
                    {
                        recepient.Modified = DateTime.UtcNow;
                        recepient.Sent = true;
                        session.Save(recepient);
                        session.Flush();
                    }

                    Thread.Sleep(100);
                }

                Thread.Sleep(1000 * InterruptInterval);
            }
        }