Exemplo n.º 1
0
        /// <summary>
        /// Filter events in loaded VCalendar based on provided filtering options
        /// </summary>
        /// <param name="filter"></param>
        public void Filter(FilteringOptions filter)
        {
            if (filter.PredictEventDuration)
                this.PredictEventDuration(filter.RemoveEventDurationFromTitle);

            if (filter.HideAllDayEvents)
                this.HideAllDayEvents(); // should be called before shortenig events

            IList<string> projectsToSkip = filter.ProjectsToSkip;
            if (projectsToSkip.Count > 0)
            {
                this.SkipEventsFromProjects(projectsToSkip);
            }

            if (filter.ShortenEvents)
                this.ShortenEvents();

            if (!String.IsNullOrEmpty(filter.HideEventsContainingThisString))
                this.HideEventsContainingString(filter.HideEventsContainingThisString);

            if (filter.ShortenEventsLongerThanThisMinutes > 0 && filter.ShortenEventsLongerThanToThisMinutes > 0)
                this.ShortenEvents(filter.ShortenEventsLongerThanThisMinutes, filter.ShortenEventsLongerThanToThisMinutes);

            if (filter.HideEventsShorterThanMinutes > 0)
                this.HideEventsShorterThanMinutes(filter.HideEventsShorterThanMinutes);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses parameters provided by user in QueryString, downloads calendar, filters events based on known rules
        /// </summary>
        /// <returns></returns>
        public ActionResult Filter()
        {
            using (WebClient webClient = new WebClient())
            {
                try
                {
                    // parse request parameters and validate requested action
                    FilteringOptions options = new FilteringOptions(Request.QueryString);
                    if (options.CalendarUrl == null)
                        throw new ArgumentException("calendarUrl parameter was not provided by the user");

                    if (!((options.CalendarUrl.Scheme.ToLowerInvariant() == "https") || (options.CalendarUrl.Scheme.ToLowerInvariant() == "http")))
                        throw new HttpException(400, "Specified protocol was not recognized. Url should begin with 'http' or 'https'.");

                    // download the source iCalendar file content
                    webClient.Encoding = Encoding.UTF8;
                    string icalContent = webClient.DownloadString(options.CalendarUrl);

                    // parse iCalendar and filter according to user-defined options
                    EventManager eventManager = new EventManager(icalContent);
                    eventManager.Filter(options);

                    // return filtered calendar as a response in iCalendar format
                    string icalResponse = eventManager.GetIcal();
                    return Content(icalResponse);
                }
                catch (ArgumentException ae)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest, ae.Message);
                }
                catch (UriFormatException)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Specified URL was not valid.");
                }
                catch (WebException)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Specified resource could not have been accessed.");
                }
                catch (PDIParserException)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Requested file is not a valid iCalendar file.");
                }
                catch (Exception)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Application exception");
                }
            }
        }