Esempio n. 1
0
        public IEnumerable <ICalendarInfo> GetCalendars()
        {
            var files = System.IO.Directory.GetDirectories(_directory, "*.ical", System.IO.SearchOption.AllDirectories);

            if (files.Length == 0)
            {
                return(new[] { CreateCalendar("me") }.AsQueryable());
            }

            var serializer = new Serializer();

            return(files.Select(x =>
            {
                using (var file = System.IO.File.OpenText(x))
                {
                    var cal = new CalendarInfo();
                    cal.Deserialize(file, serializer);
                    cal.Filename = x;
                    cal.ID = System.IO.Path.GetDirectoryName(x)
                             .Trim(System.IO.Path.DirectorySeparatorChar)
                             .Split(System.IO.Path.DirectorySeparatorChar)
                             .LastOrDefault();
                    return cal;
                }
            }).Where(x => x != null).AsQueryable());
        }
Esempio n. 2
0
		public ICalendarInfo GetCalendarByID(string id) {
			if (string.IsNullOrEmpty(id)) id = "me";
			id = MakePathSafe(id);
			var filename = System.IO.Path.Combine(_Directory, id + "\\_.ical");
			if (!System.IO.File.Exists(filename)) {
				if (id == "me") return CreateCalendar("me");
				return null;
			}

			var calendar = new CalendarInfo();
			using (var file = System.IO.File.OpenText(filename)) {
				calendar.Deserialize(file);
				calendar.Filename = filename;
				calendar.ID = id;
				return calendar;
			}
		}
Esempio n. 3
0
		public IQueryable<ICalendarInfo> GetCalendars() {
			var files = System.IO.Directory.GetDirectories(_Directory, "*.ical", System.IO.SearchOption.AllDirectories);
			if (files.Length == 0)
				return new[] { CreateCalendar("me") }.AsQueryable();

			var serializer = new Serializer();
			return files.Select(x => {
				using (var file = System.IO.File.OpenText(x)) {
					var cal = new CalendarInfo();
					cal.Deserialize(file, serializer);
					cal.Filename = x;
					cal.ID = System.IO.Path.GetDirectoryName(x)
						.Trim(System.IO.Path.DirectorySeparatorChar)
						.Split(System.IO.Path.DirectorySeparatorChar)
						.LastOrDefault();
					return cal;
				}
			}).Where(x => x != null).AsQueryable();
		}
Esempio n. 4
0
        public ICalendarInfo GetCalendarByID(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                id = "me";
            }
            id = MakePathSafe(id);
            var filename = System.IO.Path.Combine(_directory, id + "\\_.ical");

            if (!System.IO.File.Exists(filename))
            {
                return(id == "me" ? CreateCalendar("me") : null);
            }

            var calendar = new CalendarInfo();

            using (var file = System.IO.File.OpenText(filename))
            {
                calendar.Deserialize(file);

                //var e = new Event
                //{
                //    Created = DateTime.Now,
                //    Start = DateTime.Now,
                //    End = DateTime.Now.AddDays(1),
                //    Description = "Test",
                //    Location = "sdfsdf"
                //};


                //calendar.AddItem(e);

                //calendar.Save(@"C:\X\CalDAV\Demo.MVC\App_Data\Calendars\", "me", "_");

                calendar.Filename = filename;
                calendar.ID       = id;
                return(calendar);
            }
        }
Esempio n. 5
0
 private CalendarInfo LoadSerializedCalendarFromFileName(string id, string filename)
 {
     var calendar = new CalendarInfo();
     using (var file = System.IO.File.OpenText(filename))
     {
         calendar.Deserialize(file);
         calendar.Filename = filename;
         calendar.ID = id;
         return calendar;
     }
 }