Exemplo n.º 1
0
        public void AddPropertyShouldNotIncludePropertyNameInValue()
        {
            const string propName  = "X-WR-CALNAME";
            const string propValue = "Testname";

            var iCal = new Calendar();

            iCal.AddProperty(propName, propValue);

            var result = new CalendarSerializer().SerializeToString(iCal);

            var lines    = result.Split(new [] { SerializationConstants.LineBreak }, StringSplitOptions.None);
            var propLine = lines.FirstOrDefault(x => x.StartsWith("X-WR-CALNAME:"));

            Assert.AreEqual($"{propName}:{propValue}", propLine);
        }
        public static string WriteICalFileString(this IEnumerable <TwinRinksEvent> me, string title)
        {
            var calendar = new Calendar();

            calendar.AddProperty("X-WR-CALNAME", title);


            foreach (var e in me)
            {
                calendar.Events.Add(BuildCalendarEvent(e, title));
            }

            var serializer = new CalendarSerializer();

            return(serializer.SerializeToString(calendar));
        }
Exemplo n.º 3
0
        public void AddPropertyShouldNotIncludePropertyNameInValue()
        {
            var propName  = "X-WR-CALNAME";
            var propValue = "Testname";

            var iCal = new Calendar();

            iCal.AddProperty(propName, propValue);

            var ctx     = new SerializationContext();
            var factory = new SerializerFactory();

            // Get a serializer for our object
            var serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer;

            var result = serializer.SerializeToString(iCal);

            Console.WriteLine(result);
            var lines    = result.Split(new [] { "\r\n" }, StringSplitOptions.None);
            var propLine = lines.FirstOrDefault(x => x.StartsWith("X-WR-CALNAME:"));

            Assert.AreEqual($"{propName}:{propValue}", propLine);
        }
Exemplo n.º 4
0
        public Task <byte[]> GeneratorAsync(CalendarEventCollection events)
        {
            var calendar = new Calendar();

            foreach (var levent in events)
            {
                CalDateTime calStart = levent.IsWholeDay
                    ? new CalDateTime(levent.Begin.Year, levent.Begin.Month, levent.Begin.Day)
                    : new CalDateTime(levent.Begin.ToUniversalTime());

                CalDateTime calEnd = !levent.End.HasValue
                    ? calStart
                    : levent.IsWholeDay
                    ? new CalDateTime(levent.End.Value.Year, levent.End.Value.Month, levent.End.Value.Day)
                    : new CalDateTime(levent.End.Value.ToUniversalTime());

                if (levent.IsWholeDay)
                {
                    calStart.HasDate = true;
                    calStart.HasTime = false;

                    calEnd.HasDate = true;
                    calEnd.HasTime = false;

                    //https://github.com/toosean/ChinaPublicCalendar/issues/9
                    //非常感谢 JarmoHu 指正
                    calEnd = (CalDateTime)calEnd.AddDays(1);
                }

                using (var sha1 = SHA1.Create())
                {
                    byte[] titleBytes  = UTF8Encoding.UTF8.GetBytes(levent.Title);
                    byte[] hashMessage = sha1.ComputeHash(titleBytes);
                    string uid         = BitConverter.ToString(hashMessage).Replace("-", "").ToLower();

                    var revent = new Ical.Net.CalendarComponents.CalendarEvent()
                    {
                        Uid         = uid,
                        DtStamp     = calStart,
                        Start       = calStart,
                        End         = calEnd,
                        Summary     = levent.Title,
                        Description = levent.Description,
                        IsAllDay    = levent.IsWholeDay
                    };

                    calendar.Events.Add(revent);
                }
            }

            //for Google Calendar
            if (events.Name != null)
            {
                calendar.AddProperty("X-WR-CALNAME", events.Name);
            }
            calendar.Method = "PUBLISH";

            using (var memoryStream = new MemoryStream())
            {
                var serializer = new CalendarSerializer();
                serializer.Serialize(calendar, memoryStream, new UTF8Encoding(false));

                return(Task.FromResult(memoryStream.ToArray()));
            }
        }
        public string TransferToiCalFeed(Spieler spieler, List <Trainingstermin> trainingsTermine, List <Auftrittstermin> auftrittsTermine, List <Ort> orte)
        {
            Calendar iCalender = new Calendar();

            iCalender.Method = "PUBLISH";

            foreach (Auftrittstermin auftritt in auftrittsTermine.Where(a => a.Helfer.Contains(spieler.Id) ||
                                                                        a.Moderator.Contains(spieler.Id) ||
                                                                        a.Spieler.Contains(spieler.Id) ||
                                                                        a.Vorgemerkt.Contains(spieler.Id)))
            {
                CalendarEvent moehreEvent = new CalendarEvent();
                moehreEvent.Start    = new CalDateTime(auftritt.Datum);
                moehreEvent.Duration = TimeSpan.FromHours(2);
                if (auftritt.Vorgemerkt.Contains(spieler.Id))
                {
                    moehreEvent.Description = "Vorgemerkt für Volle Möhre: " + auftritt.Showtyp;
                }
                else
                {
                    moehreEvent.Description = "Volle Möhre: " + auftritt.Showtyp;
                }
                if (!string.IsNullOrEmpty(auftritt.OrtId) && orte.Where(o => o.Id == auftritt.OrtId).Count() == 1)
                {
                    var beschreibung = orte.Where(o => o.Id == auftritt.OrtId).First().Bezeichnung;
                    moehreEvent.Location = beschreibung + " - Freitext: " + auftritt.FreitextInfoIntern;
                    if (!string.IsNullOrEmpty(beschreibung) && !beschreibung.Contains("Freitext"))
                    {
                        moehreEvent.Description = moehreEvent.Description + ", " + beschreibung;
                    }
                    else if (!string.IsNullOrEmpty(auftritt.SpezialOrtText))
                    {
                        moehreEvent.Description = moehreEvent.Description + ", " + auftritt.SpezialOrtText;
                    }
                    else
                    {
                        moehreEvent.Description = moehreEvent.Description + ", " + auftritt.FreitextInfoIntern;
                    }
                }
                if (!string.IsNullOrEmpty(auftritt.Ansprechpartner))
                {
                    moehreEvent.Description = moehreEvent.Description + ", " + auftritt.Ansprechpartner;
                }
                moehreEvent.Summary = moehreEvent.Description;
                iCalender.Events.Add(moehreEvent);
            }
            foreach (Trainingstermin training in trainingsTermine.Where(a => a.Teilnehmer.Contains(spieler.Id) ||
                                                                        a.Vorgemerkt.Contains(spieler.Id) ||
                                                                        a.Leiter.Contains(spieler.Id) ||
                                                                        a.Online.Contains(spieler.Id)))
            {
                CalendarEvent moehreEvent = new CalendarEvent();
                moehreEvent.Start = new CalDateTime(training.Datum);
                if (training.Dauer == 0)
                {
                    moehreEvent.Duration = TimeSpan.FromHours(2);
                }
                else
                {
                    moehreEvent.Duration = TimeSpan.FromMinutes(training.Dauer);
                }
                if (training.Vorgemerkt.Contains(spieler.Id))
                {
                    moehreEvent.Description = "Vorgemerkt für Volle Möhre: " + training.FreitextInfo;
                }
                else
                {
                    moehreEvent.Description = "Volle Möhre: " + training.FreitextInfo;
                }
                if (!string.IsNullOrEmpty(training.OrtId) && orte.Where(o => o.Id == training.OrtId).Count() == 1)
                {
                    var beschreibung = orte.Where(o => o.Id == training.OrtId).First().Bezeichnung;
                    moehreEvent.Location = beschreibung + " - Freitext: " + training.FreitextInfo;
                    if (!string.IsNullOrEmpty(beschreibung) && !beschreibung.Contains("Freitext"))
                    {
                        moehreEvent.Description = moehreEvent.Description + ", " + beschreibung;
                    }
                }
                moehreEvent.Summary = moehreEvent.Description;
                iCalender.Events.Add(moehreEvent);
            }
            iCalender.AddProperty("CALSCALE", "GREGORIAN");

            CalendarSerializer serializer = new CalendarSerializer();

            return(serializer.SerializeToString(iCalender));
        }