public static SmtpClient GetSmtpClientInstance(ISession session)
        {
            SmtpClient smtp = new SmtpClient(
                ManagedConfiguration.GetValue(session, "SnCore.Mail.Server", "localhost"),
                int.Parse(ManagedConfiguration.GetValue(session, "SnCore.Mail.Port", "25")));

            smtp.DeliveryMethod = (SmtpDeliveryMethod)Enum.Parse(typeof(SmtpDeliveryMethod),
                                                                 ManagedConfiguration.GetValue(session, "SnCore.Mail.Delivery", "Network"));
            smtp.PickupDirectoryLocation = ManagedConfiguration.GetValue(
                session, "SnCore.Mail.PickupDirectoryLocation", string.Empty);

            string smtpusername = ManagedConfiguration.GetValue(
                session, "SnCore.Mail.Username", string.Empty);

            string smtppassword = ManagedConfiguration.GetValue(
                session, "SnCore.Mail.Password", string.Empty);

            if (!string.IsNullOrEmpty(smtpusername))
            {
                smtp.Credentials = new NetworkCredential(smtpusername, smtppassword);
            }
            else
            {
                smtp.UseDefaultCredentials = true;
            }

            return(smtp);
        }
示例#2
0
        public static TransitCounter FindByUri(ISession session, string pageviewfilename, int id, ManagedSecurityContext sec)
        {
            string uri = string.Format("{0}/{1}?id={2}",
                                       ManagedConfiguration.GetValue(session, "SnCore.WebSite.Url", "http://localhost/SnCore"),
                                       pageviewfilename, id);

            return(ManagedCounter.FindByUri(session, uri, sec));
        }
示例#3
0
        public static Uri GetBaseUri(ISession session)
        {
            string baseuri = ManagedConfiguration.GetValue(session, "SnCore.WebSite.Url", "http://localhost/SnCoreWeb");

            if (!baseuri.EndsWith("/"))
            {
                baseuri = baseuri + "/";
            }
            return(new Uri(baseuri));
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        public override int CreateOrUpdate(TransitAccountPlaceRequest t_instance, ManagedSecurityContext sec)
        {
            if (t_instance.Id == 0)
            {
                AccountPlace e_place = (AccountPlace)Session.CreateCriteria(typeof(AccountPlace))
                                       .Add(Expression.Eq("Account.Id", t_instance.AccountId))
                                       .Add(Expression.Eq("Place.Id", t_instance.PlaceId))
                                       .UniqueResult();

                if (e_place != null)
                {
                    throw new Exception(string.Format("You are already {0} of this place.",
                                                      Renderer.Render(e_place.Type.Name)));
                }

                AccountPlaceRequest e_placerequest = (AccountPlaceRequest)Session.CreateCriteria(typeof(AccountPlaceRequest))
                                                     .Add(Expression.Eq("Account.Id", t_instance.AccountId))
                                                     .Add(Expression.Eq("Place.Id", t_instance.PlaceId))
                                                     .UniqueResult();

                if (e_placerequest != null)
                {
                    throw new Exception(string.Format("You have already requested to be {0} of this place. Please be patient.",
                                                      Renderer.Render(e_placerequest.Type.Name)));
                }
            }

            int id = base.CreateOrUpdate(t_instance, sec);

            Session.Flush();

            ManagedSiteConnector.SendAccountEmailMessageUriAsAdmin(
                Session,
                new MailAddress(ManagedConfiguration.GetValue(Session, "SnCore.Admin.EmailAddress", "*****@*****.**"),
                                ManagedConfiguration.GetValue(Session, "SnCore.Admin.Name", "Admin")).ToString(),
                string.Format("EmailAccountPlaceRequest.aspx?id={0}", id));

            foreach (AccountPlace place in Collection <AccountPlace> .GetSafeCollection(mInstance.Place.AccountPlaces))
            {
                if (place.Type.CanWrite)
                {
                    ManagedAccount acct = new ManagedAccount(Session, place.Account);
                    ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(
                        Session, acct,
                        string.Format("EmailAccountPlaceRequest.aspx?id={0}", id));
                }
            }

            return(id);
        }
示例#7
0
        public string GetQuery(ISession session)
        {
            StringBuilder s_query = new StringBuilder();

            s_query.AppendLine("SELECT {Bug.*} FROM Bug {Bug}");

            if (!string.IsNullOrEmpty(SearchQuery))
            {
                int maxsearchresults = ManagedConfiguration.GetValue(session, "SnCore.MaxSearchResults", 128);
                s_query.AppendFormat("\nINNER JOIN FREETEXTTABLE(Bug, ([Subject], [Details]), " +
                                     "'{0}', {1}) AS ft ON Bug.Bug_Id = ft.[KEY] ",
                                     Renderer.SqlEncode(SearchQuery), maxsearchresults);
            }

            s_query.AppendFormat(" WHERE Bug.Project_Id = {0}", ProjectId);

            if (!Resolved)
            {
                s_query.AppendFormat(" AND NOT Bug.Status_Id = {0}", ManagedBugStatus.FindId(session, "Resolved"));
            }

            if (!Closed)
            {
                s_query.AppendFormat(" AND NOT Bug.Status_Id = {0}", ManagedBugStatus.FindId(session, "Closed"));
            }

            if (!Open)
            {
                s_query.AppendFormat(" AND NOT Bug.Status_Id = {0}", ManagedBugStatus.FindId(session, "Open"));
                s_query.AppendFormat(" AND NOT Bug.Status_Id = {0}", ManagedBugStatus.FindId(session, "Reopened"));
            }

            if (string.IsNullOrEmpty(SearchQuery) && !string.IsNullOrEmpty(SortExpression))
            {
                s_query.AppendFormat(" ORDER BY Bug.{0} {1}",
                                     Renderer.SqlEncode(SortExpression),
                                     (SortDirection == TransitSortDirection.Ascending) ? "ASC" : "DESC");
            }

            return(s_query.ToString());
        }
示例#8
0
        public HttpWebRequest GetFeedHttpRequest()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mInstance.FeedUrl);

            System.Net.ServicePointManager.Expect100Continue = false;
            request.UserAgent = ManagedConfiguration.GetValue(Session, "SnCore.Web.UserAgent", "SnCore/1.0");
            request.Accept    = "*/*";
            request.Timeout   = 60 * 1000;
            request.KeepAlive = false;
            request.MaximumAutomaticRedirections = 5;

            if (!string.IsNullOrEmpty(mInstance.Username))
            {
                request.Credentials = new NetworkCredential(
                    mInstance.Username,
                    mInstance.Password,
                    null);
            }

            return(request);
        }
        public static MailMessage GetMessageInstance(ISession session, AccountEmailMessage instance)
        {
            MailMessage message = new MailMessage();

            message.Headers.Add("x-mimeole", string.Format("Produced By {0} {1}",
                                                           ManagedSystem.Title, ManagedSystem.ProductVersion));
            message.Headers.Add("Content-class", "urn:content-classes:message");
            message.IsBodyHtml = true;
            Encoding iso8859 = Encoding.GetEncoding(28591);

            message.BodyEncoding = iso8859;
            message.Body         = instance.Body;
            message.ReplyTo      = new MailAddress(instance.MailFrom);
            message.From         = new MailAddress(
                ManagedConfiguration.GetValue(session, "SnCore.Admin.EmailAddress", "*****@*****.**"),
                ManagedConfiguration.GetValue(session, "SnCore.Admin.Name", "Admin")
                );
            message.To.Add(new MailAddress(instance.MailTo));
            message.Subject = instance.Subject;
            return(message);
        }
示例#10
0
 public static string GetAdminEmailAddress(ISession session)
 {
     return(new MailAddress(ManagedConfiguration.GetValue(
                                session, "SnCore.Admin.EmailAddress", "*****@*****.**"), ManagedConfiguration.GetValue(
                                session, "SnCore.Admin.Name", "Admin")).ToString());
 }
示例#11
0
        public int UpdateImages(ManagedSecurityContext sec)
        {
            GetACL().Check(sec, DataOperation.Update);

            int result   = 0;
            Uri basehref = null;

            Uri.TryCreate(mInstance.LinkUrl, UriKind.Absolute, out basehref);

            IList items = Session.CreateCriteria(typeof(AccountFeedItem))
                          .Add(Expression.Eq("AccountFeed.Id", mInstance.Id))
                          .List();

            foreach (AccountFeedItem item in items)
            {
                IList <HtmlImage> images = null;

                try
                {
                    images = HtmlImageExtractor.Extract(item.Description, basehref);
                }
                catch
                {
                    continue;
                }

                TimeSpan tsDistribution = new TimeSpan(0, 30, 0);

                foreach (HtmlImage image in images)
                {
                    AccountFeedItemImg x_img = null;

                    // images may appear only once, repeating images don't get updated
                    // nor images linked from multiple feeds or feed items

                    x_img = (AccountFeedItemImg)Session.CreateCriteria(typeof(AccountFeedItemImg))
                            .Add(Expression.Eq("Url", image.Src)).UniqueResult();

                    if (x_img != null)
                    {
                        // image already exists
                        continue;
                    }

                    x_img                 = new AccountFeedItemImg();
                    x_img.Created         = item.Created.Subtract(tsDistribution); // shuffle images
                    tsDistribution        = tsDistribution.Add(new TimeSpan(0, 30, 0));
                    x_img.Modified        = DateTime.UtcNow;
                    x_img.AccountFeedItem = item;
                    x_img.Description     = image.Alt;
                    x_img.Interesting     = false;
                    x_img.Url             = image.Src;

                    // fetch the image to get its size
                    try
                    {
                        WebClient client = new WebClient();
                        client.Headers["Accept"]     = "*/*";
                        client.Headers["User-Agent"] = ManagedConfiguration.GetValue(Session, "SnCore.Web.UserAgent", "SnCore/1.0");
                        byte[] data = client.DownloadData(x_img.Url);
                        if (data == null)
                        {
                            throw new Exception("Missing file data.");
                        }
                        ThumbnailBitmap bitmap = new ThumbnailBitmap(data);
                        x_img.Thumbnail = bitmap.Thumbnail;
                        x_img.Visible   = mInstance.PublishImgs;

                        // hide images smaller than the thumbnail size
                        if (bitmap.FullSize.Height < ThumbnailBitmap.s_ThumbnailSize.Height ||
                            bitmap.FullSize.Width < ThumbnailBitmap.s_ThumbnailSize.Width)
                        {
                            x_img.Visible = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        x_img.LastError = ex.Message;
                        x_img.Visible   = false;
                    }

                    Session.Save(x_img);
                    result++;
                }
            }

            return(result);
        }
示例#12
0
        public string ToVCalendarString(ManagedSecurityContext sec)
        {
            GetACL().Check(sec, DataOperation.Retreive);

            StringBuilder b = new StringBuilder();

            b.AppendLine("BEGIN:VCALENDAR");
            b.AppendLine("PRODID:-//Vestris Inc.//SnCore 1.0 MIME//EN");
            b.AppendLine("VERSION:2.0");
            b.AppendLine("METHOD:PUBLISH");
            b.AppendLine("BEGIN:VEVENT");
            b.AppendLine(string.Format("DTSTAMP:{0}", DateTime.UtcNow.ToString(@"yyyyMMdd\THHmmss\Z")));
            b.AppendLine(string.Format("UID:{0}", Id.ToString()));

            StringBuilder fb = new StringBuilder();

            if (!mInstance.Schedule.Endless)
            {
                fb.Append((mInstance.Schedule.EndOccurrences > 0)
                    ? string.Format("COUNT={0};", mInstance.Schedule.EndOccurrences)
                    : string.Format("UNTIL={0};", mInstance.Schedule.EndDateTime.ToString(@"yyyyMMdd\THHmmss\Z")));
            }

            if (mInstance.Schedule.AllDay)
            {
                b.AppendLine(string.Format("DTSTART;VALUE=DATE:{0}", mInstance.Schedule.StartDateTime.ToString(@"yyyyMMdd")));
                b.AppendLine(string.Format("DTEND;VALUE=DATE:{0}", mInstance.Schedule.EndDateTime.AddDays(1).ToString(@"yyyyMMdd")));
            }
            else
            {
                b.AppendLine(string.Format("DTSTART:{0}", mInstance.Schedule.StartDateTime.ToString(@"yyyyMMdd\THHmmss\Z")));
                b.AppendLine(string.Format("DTEND:{0}", mInstance.Schedule.EndDateTime.ToString(@"yyyyMMdd\THHmmss\Z")));
            }

            switch ((RecurrencePattern)mInstance.Schedule.RecurrencePattern)
            {
            case RecurrencePattern.None:
                break;

            case RecurrencePattern.Daily_EveryNDays:
                b.Append("RRULE:FREQ=DAILY;");
                b.Append(fb.ToString());
                b.AppendLine(string.Format("INTERVAL={0}", mInstance.Schedule.DailyEveryNDays));
                break;

            case RecurrencePattern.Daily_EveryWeekday:
                b.AppendFormat("RRULE:FREQ=DAILY;");
                b.Append(fb.ToString());
                b.AppendLine("INTERVAL=1;BYDAY=MO,TU,WE,TH,FR;WKST=SU");
                break;

            case RecurrencePattern.Weekly:
                b.AppendFormat("RRULE:FREQ=WEEKLY;");
                b.Append(fb.ToString());
                b.Append(string.Format("INTERVAL={0};", mInstance.Schedule.WeeklyEveryNWeeks));
                StringBuilder wb = new StringBuilder();
                for (int i = 0; i < 7; i++)
                {
                    if ((mInstance.Schedule.WeeklyDaysOfWeek & (short)Math.Pow(2, i)) > 0)
                    {
                        if (wb.Length > 0)
                        {
                            wb.Append(",");
                        }
                        wb.Append(((DayOfWeek)i).ToString().Substring(0, 2).ToUpper());
                    }
                }
                b.Append("BYDAY=");
                b.Append(wb.ToString());
                b.AppendLine(";WKST=SU");
                break;

            case RecurrencePattern.Monthly_DayNOfEveryNMonths:
                b.Append("RRULE:FREQ=MONTHLY;");
                b.Append(fb.ToString());
                b.AppendLine(string.Format("INTERVAL={1};BYMONTHDAY={0};WKST=SU",
                                           mInstance.Schedule.MonthlyDay, mInstance.Schedule.MonthlyMonth));
                break;

            case RecurrencePattern.Monthly_NthWeekDayOfEveryNMonth:
                // first thursday of every 2 months: RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=TH;BYSETPOS=1;WKST=SU
                // first day of every 2 months: RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYSETPOS=1;WKST=SU
                // second day of every 2 months: RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYSETPOS=2;WKST=SU
                // second weekday of every 2 months: RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=2;WKST=SU
                // last monday of every 2 months: RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=MO;BYSETPOS=-1;WKST=SU
                b.Append("RRULE:FREQ=MONTHLY;");
                b.Append(fb.ToString());
                b.Append(string.Format("INTERVAL={0};", mInstance.Schedule.MonthlyExMonth));
                switch ((DayName)mInstance.Schedule.MonthlyExDayName)
                {
                case DayName.day:
                    b.Append("BYDAY=SU,MO,TU,WE,TH,FR,SA;");
                    break;

                case DayName.weekday:
                    b.Append("BYDAY=MO,TU,WE,TH,FR;");
                    break;

                case DayName.weekendday:
                    b.Append("BYDAY=SU,SA;");
                    break;

                default:
                    b.Append(string.Format("BYDAY={0};", ((DayOfWeek)mInstance.Schedule.MonthlyExDayName)
                                           .ToString().Substring(0, 2).ToUpper()));
                    break;
                }
                b.Append(string.Format("BYSETPOS={0};", mInstance.Schedule.MonthlyExDayIndex));
                b.AppendLine("WKST=SU");
                break;

            case RecurrencePattern.Yearly_DayNOfMonth:
                // every april 23 RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTHDAY=23;BYMONTH=4;WKST=SU
                b.Append("RRULE:FREQ=YEARLY;INTERVAL=1;");
                b.Append(fb.ToString());
                b.AppendFormat("BYMONTHDAY={0};", mInstance.Schedule.YearlyDay);
                b.AppendFormat("BYMONTH={0};", mInstance.Schedule.YearlyMonth);
                b.AppendLine("WKST=SU");
                break;

            case RecurrencePattern.Yearly_NthWeekDayOfMonth:
                // every first sunday of every fifth month RRULE:FREQ=YEARLY;COUNT=10;INTERVAL=1;BYDAY=SU;BYMONTH=5;BYSETPOS=1;WKST=SU
                b.Append("RRULE:FREQ=YEARLY;INTERVAL=1;");
                b.Append(fb.ToString());
                switch ((DayName)mInstance.Schedule.YearlyExDayName)
                {
                case DayName.day:
                    b.Append("BYDAY=SU,MO,TU,WE,TH,FR,SA;");
                    break;

                case DayName.weekday:
                    b.Append("BYDAY=MO,TU,WE,TH,FR;");
                    break;

                case DayName.weekendday:
                    b.Append("BYDAY=SU,SA;");
                    break;

                default:
                    b.Append(string.Format("BYDAY={0};", ((DayOfWeek)mInstance.Schedule.MonthlyExDayName)
                                           .ToString().Substring(0, 2).ToUpper()));
                    break;
                }
                b.AppendFormat("BYSETPOS={0};", mInstance.Schedule.YearlyExDayIndex);
                b.AppendFormat("BYMONTH={0};", mInstance.Schedule.YearlyExMonth);
                b.AppendLine("WKST=SU");
                break;
            }

            b.AppendLine(string.Format("LOCATION;ENCODING=QUOTED-PRINTABLE:{0}", QuotedPrintable.Encode(mInstance.Place.Name)));
            b.AppendLine(string.Format("SUMMARY;ENCODING=QUOTED-PRINTABLE:{0}", QuotedPrintable.Encode(mInstance.Name)));
            b.AppendLine(string.Format("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:{0}",
                                       QuotedPrintable.Encode(
                                           string.Format("{0}\r\n{1}/AccountEventView.aspx?id={2}",
                                                         Renderer.RemoveHtml(mInstance.Description),
                                                         ManagedConfiguration.GetValue(Session, "SnCore.WebSite.Url", "http://localhost/SnCore"),
                                                         mInstance.Id))));
            b.AppendLine("PRIORITY:3");
            if (!string.IsNullOrEmpty(mInstance.Email))
            {
                b.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", mInstance.Email));
            }
            b.AppendLine("END:VEVENT");
            b.AppendLine("END:VCALENDAR");
            return(b.ToString());
        }