Ejemplo n.º 1
0
        public void UpdateCalendars()
        {
            CalendarQuery query;
            CalendarFeed  calendarFeed;
            GCalendarItem allEventsCal;
            Dictionary <GCalendarItem, List <GCalendarEventItem> > cals;

            query        = new CalendarQuery(FeedUri);
            cals         = new Dictionary <GCalendarItem, List <GCalendarEventItem> > ();
            allEventsCal = new GCalendarItem(AllEventsCalName, CalendarUiUrl);

            // we add this default meta-calendar which contains all events
            cals [allEventsCal] = new List <GCalendarEventItem> ();

            try {
                calendarFeed = service.Query(query);

                foreach (CalendarEntry calendar in calendarFeed.Entries)
                {
                    GCalendarItem gcal;

                    gcal        = new GCalendarItem(calendar.Title.Text, calendar.Content.AbsoluteUri);
                    cals [gcal] = UpdateEvents(gcal);
                    // append the previous calendar's events to the All Calendars calendar
                    cals [allEventsCal].AddRange(cals [gcal]);
                }
            } catch (Exception e) {
                Log.Error(ErrorInMethod, "UpdateCalendars", e.Message);
                Log.Debug(e.StackTrace);
            }

            events = new Dictionary <GCalendarItem, List <GCalendarEventItem> > (cals);
        }
Ejemplo n.º 2
0
        public EventEntry 创建活动(string 标题, string 说明, string 地点, DateTime 开始时间, DateTime 结束时间, Reminder.ReminderMethod 提醒方式, TimeSpan 提前提醒时间)
        {
            if (提醒方式 != Reminder.ReminderMethod.none && 提前提醒时间.TotalMinutes < 1)
            {
                throw new Exception("提前提醒时间不得小于1分钟,因为低于分钟的单位将被忽略");
            }

            var q = new EventEntry(标题, 说明, 地点);

            q.Times.Add(new When(开始时间, 结束时间));
            q.Reminder = new Reminder {
                Minutes = 提前提醒时间.Minutes, Days = 提前提醒时间.Days, Hours = 提前提醒时间.Hours, Method = Reminder.ReminderMethod.all
            };

            if (操作日历名称 == null)
            {
                return(日历服务.Insert(new Uri(访问网址), q) as EventEntry);
            }
            else
            {
                var           query = new CalendarQuery(访问网址);
                CalendarEntry c     = null;
                foreach (CalendarEntry f in 日历服务.Query(query).Entries)
                {
                    if (f.Title.Text == 操作日历名称)
                    {
                        c = f;
                    }
                }
                return(日历服务.Insert(new Uri(c.Content.AbsoluteUri), q) as EventEntry);
            }
        }
    public static bool CheckForNotExpiredAccess(string AccessTokenStatus, string RefreshTokenStatus)
    {
        GoogleTokenModel TokenObject = new GoogleTokenModel();

        TokenObject.Access_Token  = AccessTokenStatus;
        TokenObject.Refresh_Token = RefreshTokenStatus;
        CalendarService CalService      = GoogleCalendarManager.GetCalendarService(TokenObject);
        string          AllCalendarFeed = @"http://www.google.com/calendar/feeds/default/allcalendars/full";
        Uri             postUri         = new Uri(AllCalendarFeed);

        CalendarQuery CalendarQuery = new CalendarQuery();

        CalendarQuery.Uri = postUri;

        bool inform = true;

        try
        {
            CalendarFeed calFeed = CalService.Query(CalendarQuery);
        }
        catch (Exception e) { inform = false; };



        return(inform);
    }
        private bool SaveCalendarIdAndUrl()
        {
            CalendarFeed resultFeed = null;

            CalendarService myService = new CalendarService("MyCalendar-1");

            m_Service.setUserCredentials(m_UserName, m_Password);

            CalendarQuery query = new CalendarQuery();

            // query.Uri = new Uri(CALENDARS_URL);
            query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");

            resultFeed = (CalendarFeed)m_Service.Query(query);


            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                //LogManager.Instance.WriteToFlatFile(entry.Title.Text);
                //LogManager.Instance.WriteToFlatFile(m_CalendarName);
                if (entry.Title.Text == m_CalendarName)
                {
                    int p = entry.Id.AbsoluteUri.IndexOf("full/");
                    m_CalendarId = entry.Id.AbsoluteUri.Substring(p + 5);
                    //m_CalendarId = entry.Id.AbsoluteUri.Substring(63);
                    m_CalendarUrl = string.Format(CALENDAR_TEMPLATE, m_CalendarId);
                    //"https://www.google.com/calendar/feeds/" + m_CalendarId + "/private/full";// string.Format(CALENDAR_TEMPLATE, m_CalendarId);

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        public ICollection <Event> GetEvents(DateTime?from = null, DateTime?to = null)
        {
            var result     = new List <Event>();
            var q          = CalendarQuery.SearchEvents(from, to);
            var callendars = this.Search(q);

            foreach (var cal in callendars)
            {
                result.AddRange(cal.Events);
            }

            return(result);
        }
        static void Main(string[] args)
        {
            try
            {
                // create an OAuth factory to use
                GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "MyApp");
                requestFactory.ConsumerKey    = "CONSUMER_KEY";
                requestFactory.ConsumerSecret = "CONSUMER_SECRET";

                // example of performing a query (use OAuthUri or query.OAuthRequestorId)
                Uri calendarUri = new OAuthUri("http://www.google.com/calendar/feeds/default/owncalendars/full", "USER", "DOMAIN");
                // can use plain Uri if setting OAuthRequestorId in the query
                // Uri calendarUri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full");

                CalendarQuery query = new CalendarQuery();
                query.Uri = calendarUri;
                query.OAuthRequestorId = "USER@DOMAIN"; // can do this instead of using OAuthUri for queries

                CalendarService service = new CalendarService("MyApp");
                service.RequestFactory = requestFactory;
                service.Query(query);
                Console.WriteLine("Query Success!");

                // example with insert (must use OAuthUri)
                Uri contactsUri = new OAuthUri("http://www.google.com/m8/feeds/contacts/default/full", "USER", "DOMAIN");

                ContactEntry entry        = new ContactEntry();
                EMail        primaryEmail = new EMail("*****@*****.**");
                primaryEmail.Primary = true;
                primaryEmail.Rel     = ContactsRelationships.IsHome;
                entry.Emails.Add(primaryEmail);

                ContactsService contactsService = new ContactsService("MyApp");
                contactsService.RequestFactory = requestFactory;
                contactsService.Insert(contactsUri, entry); // this could throw if contact exists

                Console.WriteLine("Insert Success!");

                // to perform a batch use
                // service.Batch(batchFeed, new OAuthUri(atomFeed.Batch, userName, domain));

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fail!");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.ReadKey();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets all the calendars the user has write access to
        /// </summary>
        public List <string> GetAllOwnedCalendars()
        {
            List <string> calendars = new List <string>();
            CalendarQuery query     = new CalendarQuery();

            query.Uri = new Uri(calendarsOwnedUrl);
            CalendarFeed resultFeed = (CalendarFeed)this.calService.Query(query);

            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                calendars.Add(entry.Title.Text);
            }

            return(calendars);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Download a list of all of the user's calendars.
        /// </summary>
        public static IEnumerable <CalendarEntry> GetAllCalendars(CalendarService service, DateTime?modifiedSince, CancellationToken token)
        {
            // Create the query object:
            CalendarQuery query = new CalendarQuery();

            query.Uri = new Uri(CalendarFeedUrl);
            query.NumberToRetrieve = 1000;

            if (modifiedSince.HasValue)
            {
                query.ModifiedSince = modifiedSince.Value;
            }

            return(DownloadAll(query, service, token));
        }
Ejemplo n.º 9
0
        public void ParseICal()
        {
            //http://blogs.nologin.es/rickyepoderi/index.php?/archives/14-Introducing-CalDAV-Part-I.html
            //http://blogs.nologin.es/rickyepoderi/index.php?/archives/15-Introducing-CalDAV-Part-II.html

            var server    = new CalDav.Client.Server("https://www.google.com/calendar/dav/[email protected]/events/", "*****@*****.**", "Gboey6Emo!");
            var calendars = server.GetCalendars();

            calendars.ShouldNotBeEmpty();

            var calendar = calendars[0];
            var events   = calendar.Search(CalendarQuery.SearchEvents(new DateTime(2012, 8, 1), new DateTime(2012, 8, 31))).ToArray();

            events.Length.ShouldBeGreaterThan(0);
        }
Ejemplo n.º 10
0
        private void refreshCalendar()
        {
            CalendarQuery query = new CalendarQuery();

            query.Uri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarFeed resultFeed = (CalendarFeed)myService.Query(query);

            //Console.WriteLine("Your calendars:\n");
            listBox1.Items.Clear();
            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                listBox1.Items.Add(entry.Title.Text);
                richTextBox1.AppendText(entry.Content.AbsoluteUri.ToString() + "\n");
                //richTextBox1.Text += entry.Title.Text + "\n";
            }
        }
Ejemplo n.º 11
0
        private string getUriOfSelectedCalendar(string calendarTitle)
        {
            CalendarQuery query = new CalendarQuery();

            query.Uri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarFeed resultFeed = (CalendarFeed)myService.Query(query);

            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                if (calendarTitle == entry.Title.Text)
                {
                    return(entry.Content.AbsoluteUri);
                }
            }
            return("NO");
        }
Ejemplo n.º 12
0
            private bool SaveCalIdAndUrl()
            {
                CalendarQuery qry = new CalendarQuery();

                qry.Uri = new Uri(CAL_URL);
                CalendarFeed resultFeed = (CalendarFeed)g_calService.Query(qry);

                foreach (CalendarEntry entry in resultFeed.Entries)
                {
                    if (entry.Title.Text == g_CalendarName)
                    {
                        g_CalId  = entry.Id.AbsoluteUri.Substring(63);
                        g_CalUrl = string.Format(CAL_TEMPLATE, g_CalId);
                        return(true);
                    }
                }
                return(false);
            }
Ejemplo n.º 13
0
        private bool SaveCalendarIdAndUrl()
        {
            CalendarQuery query = new CalendarQuery();

            query.Uri = new Uri(CALENDARS_URL);
            CalendarFeed resultFeed = (CalendarFeed)m_Service.Query(query);

            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                if (entry.Title.Text == m_CalendarName)
                {
                    m_CalendarId  = entry.Id.AbsoluteUri.Substring(63);
                    m_CalendarUrl = string.Format(CALENDAR_TEMPLATE, m_CalendarId);
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 14
0
        private void deleteCalendar(CalendarService service, string calendarTitle)
        {
            //assume title is non-empty for now
            CalendarQuery query = new CalendarQuery();

            query.Uri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarFeed resultFeed = (CalendarFeed)service.Query(query);

            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                if (entry.Title.Text == calendarTitle)
                {
                    try
                    {
                        entry.Delete();
                    }
                    catch (GDataRequestException)
                    {
                        MessageBox.Show("Unable to delete primary calendar.\n");
                    }
                }
            }
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            string calendarURI = "http://www.google.com/calendar/feeds/default/allcalendars/full";
            string userName    = "******";
            string passWord    = "******";

            //创建日历服务对象
            CalendarService services = new CalendarService("CalendarTestApp");

            services.setUserCredentials(userName, passWord);

            CalendarQuery query = new CalendarQuery();

            query.Uri = new Uri("http://www.google.com/calendar/feeds/default/allcalendars/full");
            CalendarFeed resultFeed = (CalendarFeed)services.Query(query);

            Console.WriteLine("Your calendars:\n");
            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                Console.WriteLine(entry.Title.Text + "\n");
            }
            Console.ReadKey();
        }
Ejemplo n.º 16
0
        public static IEnumerable <Calendar> DownloadCalendars()
        {
            var query   = new CalendarQuery(CALENDAR_URL);
            var fetcher = new DownloadHelper <CalendarEntry>(_Service);

            try
            {
                fetcher.Download(query);
            }
            catch (Exception e)
            {
                Logging.LogException(true, e,
                                     "Error downloading calendars",
                                     "Did you enter your username and password correctly?",
                                     "Are you connected to the internet?"
                                     );
            }

            foreach (var entry in fetcher.Results)
            {
                yield return(new Calendar(entry));
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets all events for a calendar within the specified time range.
        /// </summary>
        /// <param name="calendar">Calendar containing events</param>
        /// <param name="start">Start of event range</param>
        /// <param name="end">End of event range</param>
        /// <returns>Calendar events</returns>
        /// <exception cref="System.ArgumentException">Calendar does not exist on device</exception>
        /// <exception cref="System.UnauthorizedAccessException">Calendar access denied</exception>
        /// <exception cref="Plugin.Calendars.Abstractions.PlatformException">Unexpected platform-specific error</exception>
        public Task <IList <CalendarEvent> > GetEventsAsync(Calendar calendar, DateTime start, DateTime end)
        {
            var             calEvent   = new List <CalendarEvent>();
            CalendarManager calManager = null;
            CalendarQuery   calQuery   = null;
            CalendarList    calList    = null;
            CalendarRecord  calRecord  = null;
            CalendarFilter  calFilter  = null;

            try
            {
                calManager = new CalendarManager();
                calFilter.AddCondition(CalendarFilter.LogicalOperator.And, Event.Start, CalendarFilter.IntegerMatchType.GreaterThanOrEqual, ConvertIntPtrToCalendarTime(start));
                calFilter.AddCondition(CalendarFilter.LogicalOperator.And, Event.End, CalendarFilter.IntegerMatchType.LessThanOrEqual, ConvertIntPtrToCalendarTime(end));
                calQuery = new CalendarQuery(Event.Uri);
                calQuery.SetFilter(calFilter);
                calList = calManager.Database.GetRecordsWithQuery(calQuery, 0, 0);

                if (calList.Count == 0)
                {
                    return(Task.FromResult <IList <CalendarEvent> >(calEvent));
                }

                calList.MoveFirst();

                do
                {
                    calRecord = calList.GetCurrentRecord();
                    string       summary     = calRecord.Get <string>(Event.Summary);
                    CalendarTime startTime   = calRecord.Get <CalendarTime>(Event.Start);
                    CalendarTime endTime     = calRecord.Get <CalendarTime>(Event.End);
                    string       location    = calRecord.Get <string>(Event.Location);
                    string       description = calRecord.Get <string>(Event.Description);
                    int          IsAllday    = calRecord.Get <int>(Event.IsAllday);
                    int          Id          = calRecord.Get <int>(Event.Id);

                    calEvent.Add(
                        new CalendarEvent
                    {
                        Name        = summary,
                        Start       = startTime.UtcTime,
                        End         = endTime.UtcTime,
                        Location    = location,
                        Description = description,
                        AllDay      = Convert.ToBoolean(IsAllday),
                        ExternalID  = Id.ToString(),
                    }
                        );
                } while (calList.MoveNext());
            }
            finally
            {
                calRecord?.Dispose();
                calRecord = null;

                calFilter?.Dispose();
                calFilter = null;

                calQuery?.Dispose();
                calQuery = null;

                calList?.Dispose();
                calList = null;

                calManager?.Dispose();
                calManager = null;
            }
            return(Task.FromResult <IList <CalendarEvent> >(calEvent));
        }
Ejemplo n.º 18
0
    // povikuvanje na id na defaultniot calendar
    public string GetCalendarIdentifier()
    {
        GoogleTokenModel GoogleTokenModelObject = new GoogleTokenModel();


        SqlConnection konekcija3 = new SqlConnection();

        konekcija3.ConnectionString = ConfigurationManager.ConnectionStrings["mojaKonekcija"].ConnectionString;

        SqlCommand komanda = new SqlCommand();

        komanda.Connection  = konekcija3;
        komanda.CommandText = "SELECT * FROM Users WHERE UserName=@UserName";
        komanda.Parameters.Add("@UserName", (string)Session["UserName"]);

        try
        {
            konekcija3.Open();
            SqlDataReader citac = komanda.ExecuteReader();
            while (citac.Read())
            {
                GoogleTokenModelObject.Access_Token  = (string)citac["AccessToken"];
                GoogleTokenModelObject.Refresh_Token = (string)citac["RefreshToken"];
            }
            citac.Close();
        }
        catch (Exception ex) { lblMessage.Text = ex.ToString(); }
        finally { konekcija3.Close(); }

        // zapocnuva get calendar id
        CalendarService CalService      = GoogleCalendarManager.GetCalendarService(GoogleTokenModelObject);
        string          AllCalendarFeed = @"http://www.google.com/calendar/feeds/default/allcalendars/full";
        Uri             postUri         = new Uri(AllCalendarFeed);

        CalendarQuery CalendarQuery = new CalendarQuery();

        CalendarQuery.Uri = postUri;
        string CalendarID = "";

        try
        {
            CalendarFeed calFeed = CalService.Query(CalendarQuery);



            if (calFeed != null && calFeed.Entries.Count > 0)
            {
                foreach (CalendarEntry CalEntry in calFeed.Entries)
                {
                    //Commented to post the new appointments on the main calendar instead of cleverfox calendar
                    //if (CalEntry.Title.Text.Contains("Cleverfox") == true)
                    //{
                    //CalendarID = CalEntry.Title.Text;
                    CalendarID = CalEntry.EditUri.ToString().Substring(CalEntry.EditUri.ToString().LastIndexOf("/") + 1);
                    break;
                    //}
                }
            }
        }
        catch (Exception e) { lblMessage.Text = e.ToString(); }
        return(CalendarID);
    }
    //zamanje na id od default calendar
    private static string GetCalendarID(CalendarService CalService)
    {
        Uri           postUri       = new Uri(AllCalendarFeed);
        CalendarQuery CalendarQuery = new CalendarQuery();

        CalendarQuery.Uri = postUri;

        CalendarFeed calFeed = CalService.Query(CalendarQuery);

        string CalendarID = "";

        if (calFeed != null && calFeed.Entries.Count > 0)
        {
            foreach (CalendarEntry CalEntry in calFeed.Entries)
            {
                //Commented to post the new appointments on the main calendar instead of cleverfox calendar
                //if (CalEntry.Title.Text.Contains("Cleverfox") == true)
                //{
                //CalendarID = CalEntry.Title.Text;
                CalendarID = CalEntry.EditUri.ToString().Substring(CalEntry.EditUri.ToString().LastIndexOf("/") + 1);
                break;
                //}
            }
        }

        #region Commented to post the new appointments on the main calendar instead of cleverfox calendar

        /*if (string.IsNullOrEmpty(CalendarID) == false)
         *  {
         *
         *  }
         *  else
         *  {
         *      Google.GData.Client.AtomEntry cal = new AtomEntry();
         *      cal.Title.Text = "Cleverfox";
         *
         *      CalService.Insert(new Uri(OwnCalendarFeed), cal);
         *  }
         *  calFeed = CalService.Query(CalendarQuery);
         *
         *  //if search contains result then update
         *  if (calFeed != null && calFeed.Entries.Count > 0)
         *  {
         *      foreach (CalendarEntry CalEntry in calFeed.Entries)
         *      {
         *          if (CalEntry.Title.Text.Contains("Cleverfox") == true)
         *          {
         *              //CalendarName = CalEntry.Title.Text;
         *              CalendarID = CalEntry.EditUri.ToString().Substring(CalEntry.EditUri.ToString().LastIndexOf("/") + 1);
         *              //if (CalEntry.TimeZone != "Canada/Vancouver")
         *              //{
         *              //    CalEntry.TimeZone = "(GMT-07:00) Arizona";
         *              //    CalEntry.Update();
         *              //}
         *              if (CalEntry.TimeZone != MerchantTimeZone)
         *              {
         *                  CalEntry.TimeZone = MerchantTimeZone;
         *                  CalEntry.Update();
         *              }
         *              break;
         *          }
         *      }
         *  }*/
        #endregion
        return(CalendarID);
    }
Ejemplo n.º 20
0
        //private static IEnumerable<CalendarEntry> DownloadAll(CalendarQuery query, CalendarService service)
        //{
        //	IEnumerable<CalendarEntry> allCalendars = new List<CalendarEntry>();
        //	CalendarFeed feed = service.Query(query);
        //	bool hasCals = false;

        //	while (feed != null && feed.Entries.Count > 0)
        //	{
        //		hasCals = true;
        //		allCalendars = allCalendars.Concat<CalendarEntry>(feed.Entries.Cast<CalendarEntry>());

        //		// just query the same query again.
        //		if (feed.NextChunk != null)
        //		{
        //			query.Uri = new Uri(feed.NextChunk);
        //			feed = service.Query(query);
        //		}
        //		else
        //			feed = null;
        //	}

        //	return hasCals ? allCalendars : null;
        //}

        private static IEnumerable <CalendarEntry> DownloadAll(CalendarQuery query, CalendarService service, CancellationToken token)
        {
            CalendarFeed feed = null;

            for (int i = 0; i < MaxTries; i++)
            {
                try
                {
                    feed = service.Query(query);
                    break;
                }
                catch
                {
                    if (i == MaxTries - 1)
                    {
                        throw;
                    }

                    Thread.Sleep(AttemptDelay);
                }

                token.ThrowIfCancellationRequested();
            }

            while (feed != null && feed.Entries.Count > 0)
            {
                foreach (CalendarEntry entry in feed.Entries.Cast <CalendarEntry>())
                {
                    yield return(entry);
                }

                // just query the same query again.
                if (feed.NextChunk != null)
                {
                    query.Uri = new Uri(feed.NextChunk);

                    for (int i = 0; i < MaxTries; i++)
                    {
                        try
                        {
                            feed = service.Query(query);
                            break;
                        }
                        catch
                        {
                            if (i == MaxTries - 1)
                            {
                                throw;
                            }

                            Thread.Sleep(AttemptDelay);
                        }

                        token.ThrowIfCancellationRequested();
                    }
                }
                else
                {
                    feed = null;
                }
            }
        }
Ejemplo n.º 21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string[] uris;
            string   povtoruvanje = "";
            mwGoogleEvent.ActiveViewIndex = 0;



            if ((Request.QueryString["token"] != null) && Session["sessionToken"] == null)
            {
                Session["sessionToken"] = AuthSubUtil.exchangeForSessionToken(Request.QueryString["token"], null);
            }
            GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("cl", "FEITPortal");
            authFactory.Token = (string)Session["sessionToken"];
            myCalendarService.RequestFactory = authFactory;
            CalendarQuery query = new CalendarQuery();
            query.Uri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full");
            try
            {
                CalendarFeed resultFeed = myCalendarService.Query(query);
                foreach (CalendarEntry entry in resultFeed.Entries)
                {
                    uris = entry.Id.Uri.ToString().Split('/');
                    ListItem li = new ListItem();
                    li.Text  = entry.Title.Text;
                    li.Value = uris[8];
                    ddlKalendari.Items.Add(li);
                }
            }
            catch (Exception ex)
            {
                hlGcal1.Visible  = true;
                hlNazad1.Visible = true;
                lblGreska.Text   = "Немате креирано Google Calendar";
                mwGoogleEvent.ActiveViewIndex = 3;
            }


            Calendar.COURSE_EVENTS_INSTANCEDataTable nastan = (Calendar.COURSE_EVENTS_INSTANCEDataTable)Session["gNastan"];



            foreach (Calendar.COURSE_EVENTS_INSTANCERow r in nastan)
            {
                CoursesTier CourseTier = new CoursesTier(Convert.ToInt32(Session["COURSE_ID"]));
                novNastan.Content.Language = r.COURSE_EVENT_ID.ToString();
                novNastan.Title.Text       = r.TITLE;
                novNastan.Content.Content  = "Предмет: " + CourseTier.Name + " Опис: " + r.DESCRIPTION + " Тип: " + r.TYPEDESCRIPTION + " ID:" + r.COURSE_EVENT_ID.ToString();
                Where mesto = new Where();
                mesto.ValueString = r.ROOM;
                novNastan.Locations.Add(mesto);
                int recType = Convert.ToInt32(r.RECURRENCE_TYPE);


                DateTime startDate = Convert.ToDateTime(r.STARTDATE);
                DateTime endDate   = Convert.ToDateTime(r.ENDDATE);
                DateTime startTime = Convert.ToDateTime(r.STARTIME);
                DateTime endTime   = Convert.ToDateTime(r.ENDTIME);
                TimeSpan span      = endTime - startTime;

                if (recType != 0)
                {
                    Recurrence rec = new Recurrence();
                    string     recData;
                    string     dStart = "DTSTART;TZID=" + System.TimeZone.CurrentTimeZone.StandardName + ":" + startDate.ToString("yyyyMMddT") + startTime.AddHours(-1).ToString("HHmm") + "00\r\n";
                    string     dEnd   = "DTEND;TZID=" + System.TimeZone.CurrentTimeZone.StandardName + ":" + startDate.ToString("yyyyMMddT") + startTime.AddHours(-1 + span.Hours).ToString("HHmm") + "00\r\n";
                    string     rRule  = "";
                    povtoruvanje = "<b>Повторување:</b> ";

                    switch (recType)
                    {
                    case 1:
                        rRule         = "RRULE:FREQ=DAILY;INTERVAL=" + r.RECURRENCE_NUMBER + ";UNTIL=" + endDate.ToString("yyyyMMddTHHmm") + "00Z\r\n";
                        povtoruvanje += "Дневно, секој " + r.RECURRENCE_NUMBER.ToString() + " ден <br> </br> <br> </br>";
                        break;

                    case 2:
                        string daysInWeek = "";
                        string denovi     = "";

                        if (r.DAYSINWEEK[0] == '1')
                        {
                            daysInWeek += "MO,";
                            denovi     += " Понеделник,";
                        }
                        if (r.DAYSINWEEK[1] == '1')
                        {
                            daysInWeek += "TU,";
                            denovi     += " Вторник,";
                        }
                        if (r.DAYSINWEEK[2] == '1')
                        {
                            daysInWeek += "WE,";
                            denovi     += " Среда,";
                        }
                        if (r.DAYSINWEEK[3] == '1')
                        {
                            daysInWeek += "TH,";
                            denovi     += " Четврток,";
                        }
                        if (r.DAYSINWEEK[4] == '1')
                        {
                            daysInWeek += "FR,";
                            denovi     += " Петок,";
                        }
                        if (r.DAYSINWEEK[5] == '1')
                        {
                            daysInWeek += "SA,";
                            denovi     += " Сабота,";
                        }
                        if (r.DAYSINWEEK[6] == '1')
                        {
                            daysInWeek += "SU,";
                            denovi     += " Недела,";
                        }
                        daysInWeek    = daysInWeek.Substring(0, daysInWeek.Length - 1);
                        denovi        = denovi.Substring(0, denovi.Length - 1);
                        rRule         = "RRULE:FREQ=WEEKLY;INTERVAL=" + r.RECURRENCE_NUMBER + ";BYDAY=" + daysInWeek + ";UNTIL=" + endDate.ToString("yyyyMMddTHHmm") + "00Z\r\n";
                        povtoruvanje += "Неделно, секоја " + r.RECURRENCE_NUMBER + " недела и тоа во: " + denovi + " <br> </br> <br> </br>";
                        break;

                    case 3:
                        rRule         = "RRULE:FREQ=MONTHLY;INTERVAL=" + r.RECURRENCE_NUMBER + ";UNTIL=" + endDate.ToString("yyyyMMddTHHmm") + "00Z\r\n";
                        povtoruvanje += "Месечно, секој " + r.RECURRENCE_NUMBER + " месец <br> </br> <br> </br>";
                        break;
                    }
                    recData              = dStart + dEnd + rRule;
                    rec.Value            = recData;
                    novNastan.Recurrence = rec;
                }
                else
                {
                    When vreme = new When();
                    vreme.StartTime = r.STARTIME;
                    vreme.EndTime   = r.ENDTIME;
                    novNastan.Times.Add(vreme);
                }


                lblPrikaz.Text += "<b>Наслов: </b>" + r.TITLE + "<br> </br> <br> </br>";
                lblPrikaz.Text += "<b>Опис: </b>" + r.DESCRIPTION + "<br> </br> <br> </br>";
                lblPrikaz.Text += "<b>Просторија: </b>" + r.ROOM + "<br> </br> <br> </br>";
                lblPrikaz.Text += "<b>Тип: </b>" + r.TYPEDESCRIPTION + "<br> </br> <br> </br>";
                lblPrikaz.Text += povtoruvanje;
                lblPrikaz.Text += "<b>Почетен датум: </b>" + startDate.ToShortDateString() + "  <b>Краен датум: </b>" + endDate.ToShortDateString() + "<br> </br> <br> </br>";
                lblPrikaz.Text += "<b>Време: Од </b>" + startTime.ToShortTimeString() + " <b>До</b> " + endTime.ToShortTimeString();
            }
            Session["novNastan"] = novNastan;
        }
    }