/// <summary> /// Gets CalDAV items. /// </summary> /// <param name="itemPath">Relative path requested.</param> /// <param name="context">Instance of <see cref="DavContext"/> class.</param> /// <returns>Object implementing various calendar items or null if no object corresponding to path is found.</returns> public static async Task <IHierarchyItemAsync> GetCalDavItemAsync(DavContext context, string itemPath) { // If this is [DAVLocation]/calendars - return folder that contains all calendars. if (itemPath.Equals(CalendarsRootFolder.CalendarsRootFolderPath.Trim('/'), System.StringComparison.InvariantCultureIgnoreCase)) { return(new CalendarsRootFolder(context)); } string[] segments = itemPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); // If URL ends with .ics - return calendar file, which contains event or to-do. if (itemPath.EndsWith(CalendarFile.Extension, System.StringComparison.InvariantCultureIgnoreCase)) { string uid = EncodeUtil.DecodeUrlPart(Path.GetFileNameWithoutExtension(segments.Last())); return((await CalendarFile.LoadByUidsAsync(context, new[] { uid }, PropsToLoad.All)).FirstOrDefault()); } // If this is [DAVLocation]/calendars/[CalendarFolderId]/ return calendar. if (itemPath.StartsWith(CalendarsRootFolder.CalendarsRootFolderPath.Trim('/'), System.StringComparison.InvariantCultureIgnoreCase)) { Guid calendarFolderId; if (Guid.TryParse(EncodeUtil.DecodeUrlPart(segments.Last()), out calendarFolderId)) { return(await CalendarFolder.LoadByIdAsync(context, calendarFolderId)); } } return(null); }
public void Save(CALDAVContext mDb, CalendarFile calendarFile) { this.ValidateModel(); // assuming all events come with a UID // Create Event for the file var calendarToDo = calendarFile.CalendarToDo.Where(a => a.ToDoId == this.FileUid()).SingleOrDefault(); if (calendarToDo == null) { calendarToDo = new CalendarToDo(); calendarToDo.FolderId = calendarFile.FolderId; calendarToDo.CalendarFileId = calendarFile.CalendarFileId; calendarToDo.ToDoId = this.FileUid(); mDb.CalendarToDo.Add(calendarToDo); } //calendarToDo.Class = this.Class; calendarToDo.Completed = this.Completed; calendarToDo.DateTimeStamp = this.DTSTAMP; calendarToDo.Due = this.Due; calendarToDo.Modified = this.LastModified; calendarToDo.Priority = this.Priority; calendarToDo.Sequence = this.Sequence; calendarToDo.Start = this.Start; //calendarToDo.Status = this.Status; calendarToDo.Summary = this.Summary; }
/// <summary> /// Returns a list of calendar files that correspont to the specified list of item paths. /// </summary> /// <remarks> /// <para> /// This method is called by the Engine during <b>calendar-multiget</b> call. /// </para> /// <para> /// For each item from the <b>pathList</b> parameter return an item that corresponds to path or <b>null</b> if the item is not found. /// </para> /// </remarks> /// <param name="pathList">Calendar files path list.</param> /// <param name="propNames"> /// Properties requested by the client. You can use this as a hint about what properties will be called by /// the Engine for each item that are returned from this method. /// </param> /// <returns>List of calendar files. Returns <b>null</b> for any item that is not found.</returns> public async Task <IEnumerable <ICalendarFileAsync> > MultiGetAsync(IEnumerable <string> pathList, IEnumerable <PropertyName> propNames) { // Get list of UIDs from path list. IEnumerable <string> uids = pathList.Select(a => System.IO.Path.GetFileNameWithoutExtension(a)); return(await CalendarFile.LoadByUidsAsync(Context, uids, PropsToLoad.All)); }
public void Delete(CALDAVContext mDb, CalendarFile calendarFile) { var calendarEvent = calendarFile.CalendarEvent.Where(a => a.EventId == this.FileUid()).SingleOrDefault(); if (calendarEvent != null) { mDb.CalendarEvent.Remove(calendarEvent); } }
public void Delete(CALDAVContext mDb, CalendarFile calendarFile) { var calendarToDo = calendarFile.CalendarToDo.Where(a => a.ToDoId == this.FileUid()).SingleOrDefault(); if (calendarToDo != null) { mDb.CalendarToDo.Remove(calendarToDo); } }
protected void Page_Load(object sender, EventArgs e) { var calFile = new CalendarFile("My Event", new DateTime(2016, 3, 30, 5), new DateTime(2016, 3, 30, 6)); calFile.Location = "Conf Room 36/2021"; calFile.Description = "Review meeting"; calFile.Status = CalendarFile.CfStatus.Busy; calFile.allDayEvent = false; Response.AddHeader("content-disposition", "attachment; filename=PTO%20Request.ics"); Response.ContentType = "text/x-vCalendar"; Response.Write(calFile.ToString()); }
public void Serialize(CalendarFile calendarFile, string outFilePath, bool overwrite = true) { // make sure that overwriting works as expected if (!overwrite && File.Exists(outFilePath)) { throw new InvalidOperationException("Cannot overwrite already existing file! Please make sure that overwriting is permitted!"); } // create a new output file stream using (var outStream = new FileStream(outFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.Write)) { // write the bytes to the output file Serialize(calendarFile, outStream); } }
/// <summary> /// Retrieves children of this folder. /// </summary> /// <param name="propNames">List of properties to retrieve with the children. They will be queried by the engine later.</param> /// <param name="offset">The number of children to skip before returning the remaining items. Start listing from from next item.</param> /// <param name="nResults">The number of items to return.</param> /// <param name="orderProps">List of order properties requested by the client.</param> /// <returns>Children of the folder.</returns> public async Task <PageResults> GetChildrenAsync(IList <PropertyName> propNames, long?offset, long?nResults, IList <OrderProperty> orderProps) { // Here we enumerate all events and to-dos contained in this calendar. // You can filter children items in this implementation and // return only items that you want to be available for this // particular user. // Typically only getcontenttype and getetag properties are requested in GetChildren call by CalDAV/CardDAV clients. // The iCalendar/vCard (calendar-data/address-data) is typically requested not in GetChildren, but in a separate multiget // report, in MultiGetAsync, that follow this request. // Bynari submits PROPFIND without props - Engine will request getcontentlength IList <IHierarchyItemAsync> children = new List <IHierarchyItemAsync>(); return(new PageResults((await CalendarFile.LoadByCalendarFolderIdAsync(Context, calendarFolderId, PropsToLoad.Minimum)), null)); }
public void Serialize(CalendarFile calendarFile, Stream outStream) { // get the content as string (unicode) string unfoldedContent = calendarFile.Serialize(); // fold the unfolded content var foldedContent = FoldHelper.FoldContent(unfoldedContent); // convert unicode string to UTF-8 bytes var unicodeBytes = Encoding.Default.GetBytes(foldedContent); var utf8Bytes = Encoding.Convert(Encoding.Default, Encoding.UTF8, unicodeBytes); // write the bytes to the output file using (var writer = new BinaryWriter(outStream)) { writer.Write(utf8Bytes); } }
public void Save(CALDAVContext mDb, CalendarFile calendarFile) { this.ValidateModel(); // assuming all events come with a UID // Create Event for the file var calendarEvent = calendarFile.CalendarEvent.Where(a => a.EventId == this.FileUid()).SingleOrDefault(); if (calendarEvent == null) { calendarEvent = new CalendarEvent { FolderId = calendarFile.FolderId, CalendarFileId = calendarFile.CalendarFileId, EventId = this.FileUid() }; mDb.CalendarEvent.Add(calendarEvent); } //calendarEvent.Class = this.Class; calendarEvent.Created = this.Created; if ((this.Description ?? "").Length <= (int.MaxValue / 2)) { calendarEvent.Description = this.Description; } calendarEvent.End = this.End; calendarEvent.IsAllDay = this.IsAllDay; calendarEvent.Location = this.Location; calendarEvent.Modified = this.LastModified; //calendarFile.CalendarEvent.Organizer = this.Organizer; calendarEvent.Priority = this.Priority; calendarEvent.Sequence = this.Sequence; calendarEvent.Start = this.Start; //calendarFile.CalendarEvent.Status = this.Status; calendarEvent.Summary = this.Summary; calendarEvent.Transparency = this.Transparency; if (this.Url != null) { calendarEvent.Url = this.Url.LocalPath; } }
public CalendarFile Deserialize(string calendarFilePath) { CalendarFile data = null; // check if the calendar file exists if (!File.Exists(calendarFilePath)) { throw new FileNotFoundException("input file not found", calendarFilePath); } // open a stream that is reading in the calendar file using (var stream = File.OpenRead(calendarFilePath)) { // make sure the stream starts at the beginning of the file stream.Seek(0, SeekOrigin.Begin); // deserialize the content from the file stream data = Deserialize(stream); } return(data); }
/// <summary> /// Creates a file that contains event or to-do item in this calendar. /// </summary> /// <param name="name">Name of the file. Same as event/to-do UID but ending with '.ics'.</param> /// <returns>The newly created file.</returns> /// <remarks></remarks> public async Task <IFileAsync> CreateFileAsync(string name) { // The actual event or to-do object is created in datatbase in CardFile.Write call. return(CalendarFile.CreateCalendarFile(Context, calendarFolderId)); }
public void Delete(CALDAVContext mDb, Guid folderId, Guid fileId) { // eager load the calendar file details CalendarFile calendarFile = mDb.CalendarFile .Include(a => a.FolderNavigation.CalendarFolderInfo) .Include(a => a.CalendarEvent) .Include(a => a.CalendarFreeBusy) .Include(a => a.CalendarJournal) .Include(a => a.CalendarTimeZone) .Include(a => a.CalendarToDo) .Where(a => a.FolderId == folderId && a.CalendarFileId == fileId).SingleOrDefault(); if (calendarFile == null) { return; } // Update Folder CTag else { calendarFile.FolderNavigation.Modified = DateTime.UtcNow; // used to trigger CTag RowVersion Update calendarFile.FolderNavigation.CalendarFolderInfo.Modified = DateTime.UtcNow; } foreach (var e in Events) { e.Calendar = this; e.Delete(mDb, calendarFile); } foreach (var td in ToDos) { td.Calendar = this; td.Delete(mDb, calendarFile); } /* * foreach (var tz in TimeZones) * { * tz.Calendar = this; * tz.Delete(mDb, calendarFile); * } * foreach (var fb in FreeBusy) * { * fb.Calendar = this; * fb.Delete(mDb, calendarFile); * } * foreach (var jn in JournalEntries) * { * jn.Calendar = this; * jn.Delete(mDb, calendarFile); * } */ if (calendarFile != null) { mDb.Remove(calendarFile); } mDb.SaveChanges(); }
public void Save(CALDAVContext mDb, Guid folderId, Guid fileId) { this.ValidateModel(); // eager load the calendar file details CalendarFile calendarFile = mDb.CalendarFile .Include(a => a.FolderNavigation.CalendarFolderInfo) .Include(a => a.CalendarEvent) .Include(a => a.CalendarFreeBusy) .Include(a => a.CalendarJournal) .Include(a => a.CalendarTimeZone) .Include(a => a.CalendarToDo) .Where(a => a.FolderId == folderId && a.CalendarFileId == fileId).SingleOrDefault(); // Create Calendar File if (calendarFile == null) { calendarFile = new CalendarFile { FolderId = folderId, CalendarFileId = fileId, Created = DateTime.UtcNow }; var calendarFolder = mDb.FolderInfo.Include(a => a.CalendarFolderInfo) .Where(a => a.FolderId == folderId).SingleOrDefault(); if (calendarFolder == null) { throw new Exception($"Calendar folder for folder ID: ({folderId.ToString()}) does not exist in DB context."); } calendarFolder.Modified = DateTime.UtcNow; calendarFolder.CalendarFolderInfo.Modified = DateTime.UtcNow; mDb.CalendarFile.Add(calendarFile); } else { calendarFile.FolderNavigation.Modified = DateTime.UtcNow; // used to trigger CTag RowVersion Update calendarFile.FolderNavigation.CalendarFolderInfo.Modified = DateTime.UtcNow; } // update Calendar File calendarFile.Scale = this.Scale; calendarFile.ProdId = this.ProdID; calendarFile.Modified = DateTime.UtcNow; foreach (var e in Events) { e.Calendar = this; e.Save(mDb, calendarFile); } foreach (var td in ToDos) { td.Calendar = this; td.Save(mDb, calendarFile); } /* * foreach (var tz in TimeZones) * { * tz.Calendar = this; * tz.Save(mDb, calendarFile); * } * foreach (var fb in FreeBusy) * { * fb.Calendar = this; * fb.Save(mDb, calendarFile); * } * foreach (var jn in JournalEntries) * { * jn.Calendar = this; * jn.Save(mDb, calendarFile); * } */ mDb.SaveChanges(); }
public void Delete(CALDAVContext mDb, CalendarFile calendarFile) { throw new NotImplementedException(); }
public IQueryable <ICalendarObject> Filter(CALDAVContext mDb, CalendarFile calendarFile, Filter filer) { throw new NotImplementedException(); }
static void Main(string[] args) { /* TODO DO NOT FORGET TO PUT THIS BACK * string path = ""; * * if (args.Length > 0) path = args[0]; * else { * Console.WriteLine("Current directory is " + Directory.GetCurrentDirectory()); * Console.Write("Enter a directory or leave blank for the above: "); * path = Console.ReadLine(); * } */ string path = @"C:\Users\Nixill\Documents\Git\NXS-GTFS"; if (path != "") { Directory.SetCurrentDirectory(path); } // Get the configuration Console.WriteLine("Reading config..."); Config.Load(); // Make sure we have directories Console.WriteLine("Creating folders..."); Directory.CreateDirectory("gtfs"); Directory.CreateDirectory("shapes"); Directory.CreateDirectory("trip-times"); Directory.CreateDirectory("trips"); // Initialize lists of things List <CompleteRelation> agencies = new List <CompleteRelation>(); List <ICompleteOsmGeo> stops = new List <ICompleteOsmGeo>(); Dictionary <long, RouteRelation> routes = new Dictionary <long, RouteRelation>(); Console.WriteLine("Reading map file..."); using (FileStream fileStream = File.OpenRead("map.osm")) { // Open the map file XmlOsmStreamSource xmlSrc = new XmlOsmStreamSource(fileStream); // We'll keep the whole thing so we can iterate over it multiple times var src = (from osmGeo in xmlSrc select osmGeo).ToComplete(); // Iterate through the file to get all the agencies // Other things will be added later foreach (var obj in src) { if (obj.Tags != null) { // Get agencies // Routes are added within each agency if (obj.Type == OsmGeoType.Relation && obj.Tags.Contains("type", "network")) { agencies.Add((CompleteRelation)obj); } // Get stops else if (obj.Type != OsmGeoType.Relation && obj.Tags.Contains("public_transport", "platform")) { stops.Add(obj); } } } Console.WriteLine(""); // Now make the agency file Console.WriteLine("Found " + agencies.Count + " agency(ies)."); Console.WriteLine("Writing agency.txt..."); AgencyFile.Create(agencies, routes); Console.WriteLine("Done."); Console.WriteLine(""); // Now make the stops file Console.WriteLine("Found " + stops.Count + " stop(s)."); Console.WriteLine("Writing stops.txt..."); StopFile.Create(stops); Console.WriteLine("Done."); Console.WriteLine(""); // Now make the routes file Console.WriteLine("Found " + routes.Count + " route(s)."); Console.WriteLine("Writing routes.txt..."); RoutesFile.Create(routes.Values); Console.WriteLine("Done."); Console.WriteLine(""); // Now make the trips file Console.WriteLine("Writing trips.txt by merging existing files..."); TripsFile.Create(); Console.WriteLine("Done."); Console.WriteLine(""); // Now make the times file Console.WriteLine("Writing stop_times.txt by merging existing files..."); TimesFile.Create(); Console.WriteLine("Done."); Console.WriteLine(""); // Now make the trips file Console.WriteLine("Writing shapes.txt by merging existing files..."); ShapesFile.Create(); Console.WriteLine("Done."); Console.WriteLine(""); // Now the calendar files Console.WriteLine("Writing calendar.txt and calendar_dates.txt..."); CalendarFile.Create(); Console.WriteLine("Done."); } }