0

My code is -

public partial class App : Application
{

    HarvestApp.GoogleAPIManager GAPImanager = new HarvestApp.GoogleAPIManager();

    List<Event>todayCalendar = GAPImanager.GetCalendarEventsForDate(DateTime.Today);

    HarvestApp.HarvestManager HAPIManager = new HarvestApp.HarvestManager();

    Console.WriteLine("Entries found for Today :" + todayCalendar.Count);

    foreach(Event todayEvent in todayCalendar)
    {
        var addEvent = new HarvestApp.Harvest_TimeSheetEntry(todayEvent);
        EntryList.Add(addEvent);
        HAPIManager.postHarvestEntry(addEvent);
    }

 }

It gives me token error. Please help.

Michal Borek
  • 4,584
  • 2
  • 30
  • 40
user2380428
  • 21
  • 1
  • 1
  • 1

2 Answers2

11

The problem is that you did put your code directly in the class and not inside a member like a constructor:

public partial class App : Application
{
    public App()
    {
        HarvestApp.GoogleAPIManager GAPImanager = new HarvestApp.GoogleAPIManager();

        List<Event>todayCalendar = GAPImanager.GetCalendarEventsForDate(DateTime.Today);

        HarvestApp.HarvestManager HAPIManager = new HarvestApp.HarvestManager();

        Console.WriteLine("Entries found for Today :" + todayCalendar.Count);

        foreach(Event todayEvent in todayCalendar)
        {
            var addEvent = new HarvestApp.Harvest_TimeSheetEntry(todayEvent);
            EntryList.Add(addEvent);
            HAPIManager.postHarvestEntry(addEvent);
        }
    }
 }
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
1

You can't declare code instructions like:

Console.WriteLine("Entries found for Today :" + todayCalendar.Count);

foreach(Event todayEvent in todayCalendar)
{
    var addEvent = new HarvestApp.Harvest_TimeSheetEntry(todayEvent);
    EntryList.Add(addEvent);
    HAPIManager.postHarvestEntry(addEvent);
}

in your class body.

You should make these calls in a constructor, or a specific method.

LittleSweetSeas
  • 6,786
  • 2
  • 21
  • 26