/// <summary> /// AJAX handler to reply a JSON containing the events for /// EventCalendarAggregator placeholder and SimpleCalendar control /// </summary> /// <param name="context"></param> public void ProcessInternalRequest(DateTime start, DateTime end, HttpContext context) { bool showFile = PageUtils.getFromForm("showFile", false); // Basic rule: event calendar shows files, simple calendar does not CmsLanguage lang = CmsLanguage.GetFromHaystack(PageUtils.getFromForm("lang", "en"), CmsConfig.Languages); List <EventCalendarDb.EventCalendarDetailsData> list = new EventCalendarDb().fetchDetailsDataByRange(start, end, lang); List <EventCalendarDb.EventCalendarCategoryData> eventCategories = new EventCalendarDb().fetchCategoryList(); List <FullCalendarEvent> eventsToOutput = new List <FullCalendarEvent>(); foreach (EventCalendarDb.EventCalendarDetailsData c in list) { eventsToOutput.Add(new FullCalendarEvent(c, eventCategories)); if (!showFile) { continue; } CmsPage eventPage = CmsContext.getPageById(c.PageId); List <FileLibraryDetailsData> fileList = new FileLibraryDb().fetchDetailsData(lang, eventPage); foreach (FileLibraryDetailsData f in fileList) { if (userHasAuthority(f)) { eventsToOutput.Add(new FullCalendarEvent(c, f, eventCategories)); } } } string json = JsonWriter.Serialize(eventsToOutput.ToArray()); context.Response.Write(json); }
} // saveUpdatedPageFilesData private PageFilesItemData getItemDataFromDataRow(DataRow dr) { PageFilesItemData item = new PageFilesItemData(); item.Id = Convert.ToInt32(dr["PageFileItemId"]); item.Filename = dr["Filename"].ToString(); item.Title = dr["Title"].ToString(); item.Author = dr["Author"].ToString(); item.Abstract = dr["Abstract"].ToString(); item.FileSize = Convert.ToInt64(dr["FileSize"]); item.lastModified = Convert.ToDateTime(dr["LastModified"]); item.CreatorUsername = dr["CreatorUsername"].ToString(); item.DetailsPageId = Convert.ToInt32(dr["PageId"]); item.Identifier = Convert.ToInt32(dr["Identifier"]); string langCode = dr["langShortCode"].ToString(); item.Lang = CmsLanguage.GetFromHaystack(langCode, CmsConfig.Languages); return(item); } // ItemDataFromDataRow
/// <summary> /// if the language is not found, returns the Invalid language (that has .isInvalidLanguage set to TRUE) /// </summary> /// <param name="fi"></param> /// <returns></returns> private CmsLanguage getLanguageFromIndex(IndexableFileInfo fi) { return(CmsLanguage.GetFromHaystack(fi.SectionName, CmsConfig.Languages)); }
public void ProcessRequest(HttpContext context) { DateTime start = DateTime.MinValue; DateTime end = DateTime.MinValue; try { int startAddSeconds = PageUtils.getFromForm("start", Int32.MinValue); int endAddSeconds = PageUtils.getFromForm("end", Int32.MinValue); if (startAddSeconds < 0) { start = new DateTime(DateTime.Now.Year, 1, 1); } else { start = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(startAddSeconds); } if (endAddSeconds < 0) { end = new DateTime(DateTime.Now.Year, 1, 1).AddYears(1); } else { end = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(endAddSeconds); } if (end < start) { end = start.AddYears(1); } } catch { return; } bool showFile = PageUtils.getFromForm("showFile", false); // Basic rule: event calendar shows files, simple calendar does not CmsLanguage lang = CmsLanguage.GetFromHaystack(PageUtils.getFromForm("lang", "en"), CmsConfig.Languages); List <EventCalendarDb.EventCalendarDetailsData> list = new EventCalendarDb().fetchDetailsDataByRange(start, end, lang); iCalendar iCal = new iCalendar(); foreach (EventCalendarDb.EventCalendarDetailsData srcEvent in list) { // Create the event, and add it to the iCalendar Event evt = iCal.Create <Event>(); // Set information about the event evt.Start = new iCalDateTime(srcEvent.StartDateTime); evt.End = new iCalDateTime(srcEvent.EndDateTime); // This also sets the duration evt.Description = srcEvent.Description; // evt.Location = "Event location"; CmsPage srcEventPage = CmsContext.getPageById(srcEvent.PageId); evt.Summary = srcEventPage.getTitle(lang); Uri url = new Uri(srcEventPage.getUrl(CmsUrlFormat.FullIncludingProtocolAndDomainName, lang), UriKind.Absolute); evt.Url = url; evt.UID = srcEvent.PageId + "_" + srcEvent.Lang.shortCode + "_" + srcEvent.Identifier; } // Serialize (save) the iCalendar System.Text.Encoding outputEncoding = iCalOutputEncoding.Instance; context.Response.Clear(); context.Response.ContentEncoding = outputEncoding; context.Response.ContentType = "text/calendar"; iCalendarSerializer serializer = new iCalendarSerializer(); serializer.Serialize(iCal, context.Response.OutputStream, outputEncoding); }