Exemple #1
0
        public static iCalendar GetFromUrl(string url, string calendarId)
        {
            var cache = new iCalendarCache();
            iCalendar calendar = null;
            if (calendarId != null)
                calendar = cache.GetCalendarFromCache(calendarId);

            if (calendar == null)
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                WebResponse resp = req.GetResponse();

                var ms = new MemoryStream();
                resp.GetResponseStream().StreamCopyTo(ms);
                ms.Seek(0, SeekOrigin.Begin);

                using (var tempReader = new StreamReader(ms))
                {
                    var reader = new StringReader(tempReader.ReadToEnd());
                    calendar = GetFromStream(reader);
                    
                    if (calendar != null && calendarId != null)
                    {
                        tempReader.BaseStream.Seek(0, SeekOrigin.Begin);
                        cache.UpdateCalendarCache(calendarId, tempReader);
                    }                    
                }
            }

            if (calendar == null)
                throw new Exception(CalendarApiResource.WrongiCalFeedLink);

            return calendar;
        }
Exemple #2
0
        public static iCalendar GetFromUrl(string url, string calendarId)
        {
            var       cache    = new iCalendarCache();
            iCalendar calendar = null;

            if (calendarId != null)
            {
                calendar = cache.GetCalendarFromCache(calendarId);
            }

            if (calendar == null)
            {
                HttpWebRequest req  = (HttpWebRequest)WebRequest.Create(url);
                WebResponse    resp = req.GetResponse();

                var ms = new MemoryStream();
                resp.GetResponseStream().StreamCopyTo(ms);
                ms.Seek(0, SeekOrigin.Begin);

                using (var tempReader = new StreamReader(ms))
                {
                    var reader = new StringReader(tempReader.ReadToEnd());
                    calendar = GetFromStream(reader);

                    if (calendar != null && calendarId != null)
                    {
                        tempReader.BaseStream.Seek(0, SeekOrigin.Begin);
                        cache.UpdateCalendarCache(calendarId, tempReader);
                    }
                }
            }

            return(calendar);
        }
        public static iCalendar GetFromUrl(string url, string calendarId)
        {
            var       cache    = new iCalendarCache();
            iCalendar calendar = null;

            if (calendarId != null)
            {
                calendar = cache.GetCalendarFromCache(calendarId);
            }

            if (calendar == null)
            {
                if (url.StartsWith("webcal"))
                {
                    url = new Regex("webcal").Replace(url, "http", 1);
                }

                var req = (HttpWebRequest)WebRequest.Create(url);
                using (var resp = req.GetResponse())
                    using (var stream = resp.GetResponseStream())
                    {
                        var ms = new MemoryStream();
                        stream.StreamCopyTo(ms);
                        ms.Seek(0, SeekOrigin.Begin);

                        using (var tempReader = new StreamReader(ms))
                        {
                            var reader = new StringReader(tempReader.ReadToEnd());
                            calendar = GetFromStream(reader);

                            if (calendar != null && calendarId != null)
                            {
                                tempReader.BaseStream.Seek(0, SeekOrigin.Begin);
                                cache.UpdateCalendarCache(calendarId, tempReader);
                            }
                        }
                    }
            }

            if (calendar == null)
            {
                throw new Exception(CalendarApiResource.WrongiCalFeedLink);
            }

            return(calendar);
        }