2011-05-12 134 views
0

我想将谷歌网站上提供的C#.NET的日历代码转换为VB.NET,并面临一些转换问题。请帮帮我。谷歌日历vb.net

代码在C#.net:

static void RetrieveAcls(CalendarService service) 
      { 
       FeedQuery query = new FeedQuery(); 
       query.Uri = new Uri("http://www.google.com/calendar/feeds/[email protected]"); 
       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) 
       { 
        Console.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); 
         } 
        } 
       } 
      } 

我在VB.NET代码:

Public Sub RetrieveAcls(ByVal service As CalendarService) 

     Dim query As New FeedQuery 
     query.Uri = New Uri("http://www.google.com/calendar/feeds/[email protected]") 

     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 

上午在 “查询” 面对错误 “饲料=新AclFeed(查询服务)”其中说Google.GData.Client.FeedQuery类型的值不能转换为'System.Uri'...此问题已解决...最后一个问题是根据以下...

Dim myQuery As New EventQuery(feedURI) 

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

我收到“myResultsFeed”的错误为“未为'Public Sub New(uriBase As System.Uri,iService As Google.GData.Client.IService)'的参数'iService'指定的参数'”。并在另一个错误“service.Query(更改为MyQuery))作为‘类型的值‘Google.GData.Calendar.EventFeed’不能转换为‘的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(); 
      } 
+0

那么你没有向我们展示原始的C#,但基本上你没有通过正确的参数,通过它的外观。看看你正在转换的C#更仔细。 – 2011-05-12 20:14:00

+0

这是好吗? “Dim myResultsFeed As EventFeed = service.Query(New EventQuery(feedURI))” – user688175 2011-05-12 20:15:57

+0

我将发布原始C#代码1分钟 – user688175 2011-05-12 20:16:10

回答

1

,那么您已经转换这个:

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

这样:!

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

他们是不一样的,在所有你的第二行是调用没有明显的理由构造

只是这将是罚款:

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

它也不清楚为什么你有这样的台词:

Dim calendarEntry As New AtomEntry 

你为什么要呼吁AtomEntry参数的构造函数?为什么你在ForEach循环之外声明变量?只需使用:

For Each calendarEntry As AtomEntry In calFeed.Entries 

编辑:对于其他的问题,我认为你只需要:

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

如果你能提供完整的方法,这将有助于。

+0

很酷的工作...非常感谢... – user688175 2011-05-12 20:08:20

+0

我有一个更多的最后一个错误...我在上面发布代码...请帮助... – user688175 2011-05-12 20:09:06

+0

嘿,我试过这个第二个错误。它是否正确? “Dim myResultsFeed As EventFeed = service.Query(New EventQuery(feedURI))”我没有得到这个错误。 – user688175 2011-05-12 20:15:30

0

我不确定它是否有效,但这是直接c#->VB.Net-从developerfusion翻译,语法似乎是正确的。只是作为你的下一个问题的提示;)

Shared Sub RetrieveAcls(ByVal service As CalendarService) 
    Dim query As New FeedQuery() 
    query.Uri = New Uri("http://www.google.com/calendar/feeds/[email protected]") 
    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