Esempio n. 1
0
        public ICalendarInfo CreateCalendar(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(null);
            }

            id = MakePathSafe(id);

            var filename = System.IO.Path.Combine(_directory, id + "\\_.ical");
            var calendar = new CalendarInfo();

            calendar.ID = id;

            var serializer = new Serializer();

            System.IO.Directory.CreateDirectory(System.IO.Path.Combine(_directory, id));

            using (var file = System.IO.File.OpenWrite(filename))
            {
                serializer.Serialize(file, calendar);
            }

            calendar.Filename = filename;

            return(calendar);
        }
Esempio n. 2
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. 3
0
		public ICalendarInfo CreateCalendar(string id) {
			if (string.IsNullOrEmpty(id)) return null;
			id = MakePathSafe(id);
			var filename = System.IO.Path.Combine(_Directory, id + "\\_.ical");
			var ical = new CalendarInfo();
			var serializer = new Serializer();
			System.IO.Directory.CreateDirectory(System.IO.Path.Combine(_Directory, id));
			using (var file = System.IO.File.OpenWrite(filename))
				serializer.Serialize(file, ical);
			ical.Filename = filename;
			return ical;
		}
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)) {
				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. 5
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. 6
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. 7
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;
     }
 }