开发者

Google calendar in vb.net

开发者 https://www.devze.com 2023-03-05 06:52 出处:网络
I am trying to convert the calendar code of C#.NET provided on google site to VB.NET and facing some conversion issues. Please help me.

I am trying to convert the calendar code of C#.NET provided on google site to VB.NET and facing some conversion issues. Please help me.

Code in C#.net:

static void RetrieveAcls(CalendarService service)
            {
                FeedQuery query = new FeedQuery();
                query.Uri = new Uri("http://www.google.com/calendar/feeds/testingforfinals@gmail.com");
                AtomFeed calFeed = service.Query(query);

                Console.WriteLine();
                Console.WriteLine("Sharing permissions for your calendars:");

                // Retrieve the meta-feed of all calendars.
                foreach (AtomEntry calendarEntry in calFeed.Entries)
                {
                    Co开发者_如何学Cnsole.WriteLine("Calendar: {0}", calendarEntry.Title.Text);
                    AtomLink link = calendarEntry.Links.FindService(
                        AclNameTable.LINK_REL_ACCESS_CONTROL_LIST, null);

                    // For each calendar, retrieve its ACL feed.
                    if (link != null)
                    {
                        AclFeed feed = service.Query(new AclQuery(link.HRef.ToString()));
                        foreach (AclEntry aclEntry in feed.Entries)
                        {
                            Console.WriteLine("\tScope: Type={0} ({1})", aclEntry.Scope.Type,
                                aclEntry.Scope.Value);
                            Console.WriteLine("\tRole: {0}", aclEntry.Role.Value);
                        }
                    }
                }
            }

My code in VB.NET:

Public Sub RetrieveAcls(ByVal service As CalendarService)

        Dim query As New FeedQuery
        query.Uri = New Uri("http://www.google.com/calendar/feeds/testingforfinals@gmail.com")

        Dim calFeed As New AtomFeed(service.Query(query))

        Console.WriteLine()
        Console.WriteLine("Sharing permissions for your calendars:")

        Dim calendarEntry As New AtomEntry
        Dim link As New AtomLink
        Dim aclEntry As New AclEntry
        For Each calendarEntry In calFeed.Entries
            Console.WriteLine("Calendar: {0}", calendarEntry.Title.Text)

            link = calendarEntry.Links.FindService(AclNameTable.LINK_REL_ACCESS_CONTROL_LIST, "")

            If (link Is Nothing) Then
                Dim feed As AclFeed()

                feed = New AclFeed(query, service)

                feed = service.Query(New AclQuery(link.HRef.ToString()))



                For Each aclEntry In feed.Entries
                    Console.WriteLine("\tScope: Type={0} ({1})", aclEntry.Scope.Type, aclEntry.Scope.Value)
                    Console.WriteLine("\tRole: {0}", aclEntry.Role.Value)
                Next
            End If

        Next


    End Sub

Am facing error at "query" in "feed = New AclFeed(query, service)" which says Value of type Google.GData.Client.FeedQuery cannot be converted to 'System.Uri'... This issue is resolved... One more last issue is as per below...

Dim myQuery As New EventQuery(feedURI)

Dim myResultsFeed As New EventFeed(service.Query(myQuery))

I am getting error on "myResultsFeed" as "Argument not specified for parameter 'iService' of 'Public Sub New(uriBase As System.Uri, iService As Google.GData.Client.IService)'." and another error on "service.Query(myQuery)) as "Value of type 'Google.GData.Calendar.EventFeed' cannot be converted to 'System.Uri'."

static void DateRangeQuery(CalendarService service, DateTime startTime, DateTime endTime)
            {
                EventQuery myQuery = new EventQuery(feedUri);
                myQuery.StartTime = startTime;
                myQuery.EndTime = endTime;

                EventFeed myResultsFeed = service.Query(myQuery) as EventFeed;

                Console.WriteLine("Matching events from {0} to {1}:",
                                  startTime.ToShortDateString(),
                                  endTime.ToShortDateString());
                Console.WriteLine();
                for (int i = 0; i < myResultsFeed.Entries.Count; i++)
                {
                    Console.WriteLine(myResultsFeed.Entries[i].Title.Text);
                }
                Console.WriteLine();
            }


Well you've converted this:

AclFeed feed = service.Query(new AclQuery(link.HRef.ToString()));

to this:

Dim feed As AclFeed()
feed = New AclFeed(query, service)
feed = service.Query(New AclQuery(link.HRef.ToString()))

They're not the same at all! Your second line is calling a constructor for no obvious reason.

Just this would be fine:

Dim feed As AclFeed = service.Query(New AclQuery(link.HRef.ToString()))

It's also not clear why you've got lines like this:

Dim calendarEntry As New AtomEntry

Why are you calling the parameterless constructor for AtomEntry? Why are you declaring the variable outside the ForEach loop at all? Just use:

For Each calendarEntry As AtomEntry In calFeed.Entries

EDIT: For the other issue, I think you just need:

Dim myEventFeed As CType(service.Query(myQuery), EventFeed)

If you could provide the full method, that would help.


I'm not sure if it works, but this is the direct c#->VB.Net-Translation from developerfusion, the syntax seems to be correct. Only as a hint for your next problems ;)

Shared Sub RetrieveAcls(ByVal service As CalendarService)
    Dim query As New FeedQuery()
    query.Uri = New Uri("http://www.google.com/calendar/feeds/testingforfinals@gmail.com")
    Dim calFeed As AtomFeed = service.Query(query)

    Console.WriteLine()
    Console.WriteLine("Sharing permissions for your calendars:")

    ' Retrieve the meta-feed of all calendars.
    For Each calendarEntry As AtomEntry In calFeed.Entries
        Console.WriteLine("Calendar: {0}", calendarEntry.Title.Text)
        Dim link As AtomLink = calendarEntry.Links.FindService(AclNameTable.LINK_REL_ACCESS_CONTROL_LIST, Nothing)

        ' For each calendar, retrieve its ACL feed.
        If Not link Is Nothing Then
            Dim feed As AclFeed = service.Query(New AclQuery(link.HRef.ToString()))
            For Each aclEntry As AclEntry In feed.Entries
                Console.WriteLine(vbTab & "Scope: Type={0} ({1})", aclEntry.Scope.Type, aclEntry.Scope.Value)
                Console.WriteLine(vbTab & "Role: {0}", aclEntry.Role.Value)
            Next
        End If
    Next
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号