Solved

C# to Vb.Net Translate

Posted on 2011-03-04
20
463 Views
Last Modified: 2012-05-11
I am trying to translate the below code to vb.net but I am not sure how to handle the yield statement. I would appreciate help in translating this. Thank you in advance.
IEnumerator<GroupItemsTuple> GetEnumerator()
      {
        foreach (var group in
          this.config.ConfigurationGroups.OrderBy(g => g.Priority))
        {
          yield return new GroupItemsTuple(group,
            group.Catalogs.AsEnumerable().GetEnumerator());
        }
      }

Open in new window

0
Comment
Question by:jimseiwert
  • 10
  • 8
  • 2
20 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 35040984
From http://www.developerfusion.com/tools/convert/csharp-to-vb/....

Private Function GetEnumerator() As IEnumerator(Of GroupItemsTuple)
	For Each group As var In Me.config.ConfigurationGroups.OrderBy(Function(g) g.Priority)
		Yield Return New GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
	Next
End Function

Open in new window

0
 
LVL 2

Author Comment

by:jimseiwert
ID: 35041004
I tried that and it did not convert the yield since it does not exist in vb.net
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 35041047
Ahh. As you are returning an Enumerator, you can safely ignore the "yeild" keyword. Eg....

Private Function GetEnumerator() As IEnumerator(Of GroupItemsTuple)
	For Each group As var In Me.config.ConfigurationGroups.OrderBy(Function(g) g.Priority)
		Return New GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
	Next
End Function

Open in new window

0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35041137
I answered a similar question before.  Please check the following question/solution:

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_26842428.html
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35041259
In your particular case it would be something like this (not tested):

    Public Class ConfigurationGroupsEnumerator
        Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple))
        Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple))

        Private _configGroups As IEnumerator(Of << the type of Me.config.ConfigurationGroups >>)
        Private _current As IEnumerator(Of GroupItemsTuple)

        Sub New(ByVal parent As << type of Me >>)
            _configGroups = parent.config.ConfigurationGroups.OrderBy(g => g.Priority)
            _current = Nothing
        End Sub


        Public Function GetEnumerator() As IEnumerator(Of IEnumerator(Of GroupItemsTuple)) Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple)).GetEnumerator
            Static iFirstTime As Int32
            If iFirstTime = 0 AndAlso Threading.Interlocked.Increment(iFirstTime) = 1 Then
                Return Me
            Else
                Throw New InvalidOperationException("GetEnumerator can only be called once on a stream")
            End If
        End Function


        Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext
            if _configGroups.MoveNext() Then
                dim group = _configGroups.Current()
                _current = new GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
                return True
            End If
            Return False 
        End Function


        Private Function IEnumerator_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
            Return GetEnumerator()
        End Function


        Public ReadOnly Property Current() As GroupItemsTuple Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple)).Current
            Get
                Return _current
            End Get
        End Property

        Private ReadOnly Property IEnumerator_Current() As Object Implements IEnumerator.Current
            Get
                Return Current
            End Get
        End Property


        Private Sub Reset() Implements IEnumerator.Reset
            Throw New NotImplementedException()
        End Sub

        Public Sub Dispose() Implements IDisposable.Dispose
            'not implemented
        End Sub

    End Class

Open in new window


It should be something like this to use it:

Dim tuple As IEnumerator(Of GroupItemsTuple)

For Each tuple in New ConfigurationGroupsEnumerator(Me)
     ' Process your group tuple
Next 

Open in new window


I hope this helps.
0
 
LVL 2

Author Comment

by:jimseiwert
ID: 35041328
Here is the whole class if it helps. Sorry i am struggiling with this one. The GetEnumerator is the function in question. Thanks again
' 
'Microsoft Public License (Ms-PL)
'
'This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
'
'1. Definitions
'
'The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
'
'A "contribution" is the original software, or any additions or changes to the software.
'
'A "contributor" is any person that distributes its contribution under this license.
'
'"Licensed patents" are a contributor's patent claims that read directly on its contribution.
'
'2. Grant of Rights
'
'(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
'
'(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
'
'3. Conditions and Limitations
'
'(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
'
'(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
'
'(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
'
'(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
'
'(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
'
' 
'INSTANT VB NOTE: This code snippet uses implicit typing. You will need to set 'Option Infer On' in the VB file or set 'Option Infer' at the project level.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel.Composition.Hosting
Imports System.Linq
Imports CatalogBits.CatalogBits.Config

Namespace CatalogBits.Loading
    Partial Public Class DeploymentCatalogLoader
        Private Class ConfigLoadHelper
            Public Class GroupItemsTuple
                Public Item1 As DeploymentCatalogConfigGroup
                Public Item2 As IEnumerator(Of DeploymentCatalogConfigItem)

                Public Sub New(ByVal item1 As DeploymentCatalogConfigGroup, ByVal item2 As IEnumerator(Of DeploymentCatalogConfigItem))
                    Me.Item1 = item1
                    Me.Item2 = item2
                End Sub
            End Class
            Public Sub New(ByVal config As DeploymentCatalogConfig)
                Me.config = config
            End Sub
            Public Sub LoadAsync(ByVal loadedAction As Action(Of DeploymentCatalogConfig), ByVal groupLoadedAction As Action(Of DeploymentCatalogConfigGroup), ByVal itemLoadedAction As Action(Of DeploymentCatalogConfigItem, DeploymentCatalog, Exception))
                Me.groupEnumerator = GetEnumerator()
                Me.loadedAction = loadedAction
                Me.groupLoadedAction = groupLoadedAction
                Me.itemLoadedAction = itemLoadedAction
                LoadNextGroupAsync()
            End Sub
            Private Function GetEnumerator() As IEnumerator(Of GroupItemsTuple)

                For Each group In Me.config.ConfigurationGroups.OrderBy(Function(g) g.Priority)
                    Return New GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
                Next group
            End Function
            Private Sub LoadNextGroupAsync()
                If Me.groupEnumerator.MoveNext() Then
                    LoadNextGroupItemAsync()
                Else
                    Me.loadedAction(Me.config)
                End If
            End Sub
            Private Sub LoadNextGroupItemAsync()
                If Me.groupEnumerator.Current.Item2.MoveNext() Then
                    Dim catalog As New DeploymentCatalog(Me.groupEnumerator.Current.Item2.Current.Uri)

                    AddHandler catalog.DownloadCompleted, Sub(s, e)
                                                              Me.itemLoadedAction(Me.groupEnumerator.Current.Item2.Current, catalog, e.Error)

                                                              ' we stop on the first error and load no more...
                                                              If e.Error Is Nothing Then
                                                                  LoadNextGroupItemAsync()
                                                              End If
                                                          End Sub
                    catalog.DownloadAsync()
                Else
                    Me.groupLoadedAction(Me.groupEnumerator.Current.Item1)
                    LoadNextGroupAsync()
                End If
            End Sub


            Private config As DeploymentCatalogConfig
            Private groupEnumerator As IEnumerator(Of GroupItemsTuple)
            Private loadedAction As Action(Of DeploymentCatalogConfig)
            Private groupLoadedAction As Action(Of DeploymentCatalogConfigGroup)
            Private itemLoadedAction As Action(Of DeploymentCatalogConfigItem, DeploymentCatalog, Exception)
        End Class
    End Class
End Namespace

Open in new window

0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35041430
Ít should be something like this.  I cannot compile/test it here, so you may have to tweak something:

' 
'Microsoft Public License (Ms-PL)
'
'This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
'
'1. Definitions
'
'The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
'
'A "contribution" is the original software, or any additions or changes to the software.
'
'A "contributor" is any person that distributes its contribution under this license.
'
'"Licensed patents" are a contributor's patent claims that read directly on its contribution.
'
'2. Grant of Rights
'
'(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
'
'(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
'
'3. Conditions and Limitations
'
'(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
'
'(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
'
'(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
'
'(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
'
'(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
'
' 
'INSTANT VB NOTE: This code snippet uses implicit typing. You will need to set 'Option Infer On' in the VB file or set 'Option Infer' at the project level.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel.Composition.Hosting
Imports System.Linq
Imports CatalogBits.CatalogBits.Config

Namespace CatalogBits.Loading
	Partial Public Class DeploymentCatalogLoader
		Private Class ConfigLoadHelper
			Public Class GroupItemsTuple
				Public Item1 As DeploymentCatalogConfigGroup
				Public Item2 As IEnumerator(Of DeploymentCatalogConfigItem)

				Public Sub New(ByVal item1 As DeploymentCatalogConfigGroup, ByVal item2 As IEnumerator(Of DeploymentCatalogConfigItem))
					Me.Item1 = item1
					Me.Item2 = item2
				End Sub
			End Class
			Public Sub New(ByVal config As DeploymentCatalogConfig)
				Me.config = config
			End Sub
			Public Sub LoadAsync(ByVal loadedAction As Action(Of DeploymentCatalogConfig), ByVal groupLoadedAction As Action(Of DeploymentCatalogConfigGroup), ByVal itemLoadedAction As Action(Of DeploymentCatalogConfigItem, DeploymentCatalog, Exception))
				Me.groupEnumerator = New ConfigurationGroupsEnumerator(Me)
				Me.loadedAction = loadedAction
				Me.groupLoadedAction = groupLoadedAction
				Me.itemLoadedAction = itemLoadedAction
				LoadNextGroupAsync()
			End Sub
			'Private Function GetEnumerator() As IEnumerator(Of GroupItemsTuple)
            '
			'	For Each group In Me.config.ConfigurationGroups.OrderBy(Function(g) g.Priority)
			'		Return New GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
			'	Next group
			'End Function
			Private Sub LoadNextGroupAsync()
				If Me.groupEnumerator.MoveNext() Then
					LoadNextGroupItemAsync()
				Else
					Me.loadedAction(Me.config)
				End If
			End Sub
			Private Sub LoadNextGroupItemAsync()
				If Me.groupEnumerator.Current.Item2.MoveNext() Then
					Dim catalog As New DeploymentCatalog(Me.groupEnumerator.Current.Item2.Current.Uri)

					AddHandler catalog.DownloadCompleted, Sub(s, e)
															  Me.itemLoadedAction(Me.groupEnumerator.Current.Item2.Current, catalog, e.Error)

															  ' we stop on the first error and load no more...
															  If e.Error Is Nothing Then
																  LoadNextGroupItemAsync()
															  End If
														  End Sub
					catalog.DownloadAsync()
				Else
					Me.groupLoadedAction(Me.groupEnumerator.Current.Item1)
					LoadNextGroupAsync()
				End If
			End Sub


			Private config As DeploymentCatalogConfig
			Private groupEnumerator As IEnumerator(Of GroupItemsTuple)
			Private loadedAction As Action(Of DeploymentCatalogConfig)
			Private groupLoadedAction As Action(Of DeploymentCatalogConfigGroup)
			Private itemLoadedAction As Action(Of DeploymentCatalogConfigItem, DeploymentCatalog, Exception)

			Public Class ConfigurationGroupsEnumerator
				Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple))
				Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple))
		
				Private _configGroups As IEnumerator(Of DeploymentCatalogConfigGroup)
				Private _current As IEnumerator(Of GroupItemsTuple)
		
				Sub New(ByVal parent As ConfigLoadHelper)
					_configGroups = parent.config.ConfigurationGroups.OrderBy(Function(g) g.Priority)
					_current = Nothing
				End Sub
		
		
				Public Function GetEnumerator() As IEnumerator(Of IEnumerator(Of GroupItemsTuple)) Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple)).GetEnumerator
					Static iFirstTime As Int32
					If iFirstTime = 0 AndAlso Threading.Interlocked.Increment(iFirstTime) = 1 Then
						Return Me
					Else
						Throw New InvalidOperationException("GetEnumerator can only be called once on a stream")
					End If
				End Function
		
		
				Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext
					if _configGroups.MoveNext() Then
						dim group = _configGroups.Current()
						_current = new GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
						return True
					End If
					Return False 
				End Function
		
		
				Private Function IEnumerator_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
					Return GetEnumerator()
				End Function
		
		
				Public ReadOnly Property Current() As GroupItemsTuple Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple)).Current
					Get
						Return _current
					End Get
				End Property
		
				Private ReadOnly Property IEnumerator_Current() As Object Implements IEnumerator.Current
					Get
						Return Current
					End Get
				End Property
		
		
				Private Sub Reset() Implements IEnumerator.Reset
					Throw New NotImplementedException()
				End Sub
		
				Public Sub Dispose() Implements IDisposable.Dispose
					'not implemented
				End Sub
		
			End Class
		End Class
	End Class
End Namespace

Open in new window

0
 
LVL 2

Author Comment

by:jimseiwert
ID: 35041446
When I copied your code the attatched errors show up. It says that the functions are not implemented but it looks like they are. it all revolves around the below code. Error Messages
Public Class ConfigurationGroupsEnumerator
                Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple))
                Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple))

                Private _configGroups As IEnumerator(Of DeploymentCatalogConfigGroup)
                Private _current As IEnumerator(Of GroupItemsTuple)

                Sub New(ByVal parent As ConfigLoadHelper)
                    _configGroups = parent.config.ConfigurationGroups.OrderBy(Function(g) g.Priority)
                    _current = Nothing
                End Sub


                Public Function GetEnumerator() As IEnumerator(Of IEnumerator(Of GroupItemsTuple)) Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple)).GetEnumerator
                    Static iFirstTime As Int32
                    If iFirstTime = 0 AndAlso Threading.Interlocked.Increment(iFirstTime) = 1 Then
                        Return Me
                    Else
                        Throw New InvalidOperationException("GetEnumerator can only be called once on a stream")
                    End If
                End Function


                Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext
                    If _configGroups.MoveNext() Then
                        Dim group = _configGroups.Current()
                        _current = New GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
                        Return True
                    End If
                    Return False
                End Function


                Private Function IEnumerator_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
                    Return GetEnumerator()
                End Function


                Public ReadOnly Property Current() As GroupItemsTuple Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple)).Current
                    Get
                        Return _current
                    End Get
                End Property

                Private ReadOnly Property IEnumerator_Current() As Object Implements IEnumerator.Current
                    Get
                        Return Current
                    End Get
                End Property


                Private Sub Reset() Implements IEnumerator.Reset
                    Throw New NotImplementedException()
                End Sub

                Public Sub Dispose() Implements IDisposable.Dispose
                    'not implemented
                End Sub

            End Class

Open in new window

0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35041538
Please try the following:

Public Class ConfigurationGroupsEnumerator
	Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple))
	Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple))

	Private _configGroups As IEnumerator(Of DeploymentCatalogConfigGroup)
	Private _current As IEnumerator(Of GroupItemsTuple)

	Sub New(ByVal parent As ConfigLoadHelper)
		_configGroups = parent.config.ConfigurationGroups.OrderBy(Function(g) g.Priority)
		_current = Nothing
	End Sub


	Public Function GetEnumerator() As IEnumerator(Of IEnumerator(Of GroupItemsTuple)) Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple)).GetEnumerator
		Static iFirstTime As Int32
		If iFirstTime = 0 AndAlso Threading.Interlocked.Increment(iFirstTime) = 1 Then
			Return Me
		Else
			Throw New InvalidOperationException("GetEnumerator can only be called once on a stream")
		End If
	End Function


	Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext
		if _configGroups.MoveNext() Then
			dim group = _configGroups.Current()
			_current = new GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
			return True
		End If
		Return False 
	End Function


	Private Function IEnumerator_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
		Return GetEnumerator()
	End Function


	Public ReadOnly Property Current() As IEnumerator(Of GroupItemsTuple) Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple)).Current
		Get
			Return _current
		End Get
	End Property

	Private ReadOnly Property IEnumerator_Current() As Object Implements IEnumerator.Current
		Get
			Return Current
		End Get
	End Property


	Private Sub Reset() Implements IEnumerator.Reset
		Throw New NotImplementedException()
	End Sub

	Public Sub Dispose() Implements IDisposable.Dispose
		'not implemented
	End Sub

End Class

Open in new window

0
 
LVL 2

Author Comment

by:jimseiwert
ID: 35041575
Down to 9 errors

Error      5      Class 'ConfigurationGroupsEnumerator' must implement 'Function GetEnumerator() As IEnumerator' for interface 'System.Collections.IEnumerable'.
Error      6      Class 'ConfigurationGroupsEnumerator' must implement 'Function MoveNext() As Boolean' for interface 'System.Collections.IEnumerator'.
Error      7      Class 'ConfigurationGroupsEnumerator' must implement 'ReadOnly Property Current As Object' for interface 'System.Collections.IEnumerator'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers.
Error      8      Class 'ConfigurationGroupsEnumerator' must implement 'Sub Reset()' for interface 'System.Collections.IEnumerator'.
Error      9      Too few type arguments to 'System.Collections.Generic.IEnumerator(Of T)'.
Error      10      Too few type arguments to 'System.Collections.Generic.IEnumerator(Of T)'.
Error      11      Too few type arguments to 'System.Collections.Generic.IEnumerable(Of T)'.
Error      12      Too few type arguments to 'System.Collections.Generic.IEnumerator(Of T)'.
Error      13      Too few type arguments to 'System.Collections.Generic.IEnumerator(Of T)'.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 23

Expert Comment

by:wdosanjos
ID: 35041670
I mocked the referenced classes and I'm able to compile the ConfigurationGroupsEnumerator class as is without any errors.  Can you paste the complete updated DeploymentCatalogLoader class?
0
 
LVL 2

Author Comment

by:jimseiwert
ID: 35041741
Here you go!
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel.Composition.Hosting
Imports System.Linq
Imports CatalogBits.CatalogBits.Config

Namespace CatalogBits.Loading
    Partial Public Class DeploymentCatalogLoader
        Private Class ConfigLoadHelper
            Public Class GroupItemsTuple
                Public Item1 As DeploymentCatalogConfigGroup
                Public Item2 As IEnumerator(Of DeploymentCatalogConfigItem)

                Public Sub New(ByVal item1 As DeploymentCatalogConfigGroup, ByVal item2 As IEnumerator(Of DeploymentCatalogConfigItem))
                    Me.Item1 = item1
                    Me.Item2 = item2
                End Sub
            End Class
            Public Sub New(ByVal config As DeploymentCatalogConfig)
                Me.config = config
            End Sub
            Public Sub LoadAsync(ByVal loadedAction As Action(Of DeploymentCatalogConfig), ByVal groupLoadedAction As Action(Of DeploymentCatalogConfigGroup), ByVal itemLoadedAction As Action(Of DeploymentCatalogConfigItem, DeploymentCatalog, Exception))
                Me.groupEnumerator = New ConfigurationGroupsEnumerator(Me)
                Me.loadedAction = loadedAction
                Me.groupLoadedAction = groupLoadedAction
                Me.itemLoadedAction = itemLoadedAction
                LoadNextGroupAsync()
            End Sub
            'Private Function GetEnumerator() As IEnumerator(Of GroupItemsTuple)
            '
            '	For Each group In Me.config.ConfigurationGroups.OrderBy(Function(g) g.Priority)
            '		Return New GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
            '	Next group
            'End Function
            Private Sub LoadNextGroupAsync()
                If Me.groupEnumerator.MoveNext() Then
                    LoadNextGroupItemAsync()
                Else
                    Me.loadedAction(Me.config)
                End If
            End Sub
            Private Sub LoadNextGroupItemAsync()
                If Me.groupEnumerator.Current.Item2.MoveNext() Then
                    Dim catalog As New DeploymentCatalog(Me.groupEnumerator.Current.Item2.Current.Uri)

                    AddHandler catalog.DownloadCompleted, Sub(s, e)
                                                              Me.itemLoadedAction(Me.groupEnumerator.Current.Item2.Current, catalog, e.Error)

                                                              ' we stop on the first error and load no more...
                                                              If e.Error Is Nothing Then
                                                                  LoadNextGroupItemAsync()
                                                              End If
                                                          End Sub
                    catalog.DownloadAsync()
                Else
                    Me.groupLoadedAction(Me.groupEnumerator.Current.Item1)
                    LoadNextGroupAsync()
                End If
            End Sub


            Private config As DeploymentCatalogConfig
            Private groupEnumerator As IEnumerator(Of GroupItemsTuple)
            Private loadedAction As Action(Of DeploymentCatalogConfig)
            Private groupLoadedAction As Action(Of DeploymentCatalogConfigGroup)
            Private itemLoadedAction As Action(Of DeploymentCatalogConfigItem, DeploymentCatalog, Exception)

            Public Class ConfigurationGroupsEnumerator
                Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple))
                Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple))

                Private _configGroups As IEnumerator(Of DeploymentCatalogConfigGroup)
                Private _current As IEnumerator(Of GroupItemsTuple)

                Sub New(ByVal parent As ConfigLoadHelper)
                    _configGroups = parent.config.ConfigurationGroups.OrderBy(Function(g) g.Priority)
                    _current = Nothing
                End Sub


                Public Function GetEnumerator() As IEnumerator(Of IEnumerator(Of GroupItemsTuple)) Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple)).GetEnumerator
                    Static iFirstTime As Int32
                    If iFirstTime = 0 AndAlso Threading.Interlocked.Increment(iFirstTime) = 1 Then
                        Return Me
                    Else
                        Throw New InvalidOperationException("GetEnumerator can only be called once on a stream")
                    End If
                End Function


                Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext
                    If _configGroups.MoveNext() Then
                        Dim group = _configGroups.Current()
                        _current = New GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
                        Return True
                    End If
                    Return False
                End Function


                Private Function IEnumerator_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
                    Return GetEnumerator()
                End Function


                Public ReadOnly Property Current() As IEnumerator(Of GroupItemsTuple) Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple)).Current
                    Get
                        Return _current
                    End Get
                End Property

                Private ReadOnly Property IEnumerator_Current() As Object Implements IEnumerator.Current
                    Get
                        Return Current
                    End Get
                End Property


                Private Sub Reset() Implements IEnumerator.Reset
                    Throw New NotImplementedException()
                End Sub

                Public Sub Dispose() Implements IDisposable.Dispose
                    'not implemented
                End Sub

            End Class
        End Class
    End Class
End Namespace

Open in new window

0
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 500 total points
ID: 35041811
OK. One more time (hopefully the last).

    Public Class ConfigurationGroupsEnumerator
	Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple))
	Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple))

	Private _configGroups As IEnumerator(Of DeploymentCatalogConfigGroup)
	Private _current As IEnumerator(Of GroupItemsTuple)

	Sub New(ByVal parent As ConfigLoadHelper)
	    _configGroups = parent.config.ConfigurationGroups.OrderBy(Function(g) g.Priority)
	    _current = Nothing
	End Sub


	Public Function GetEnumerator() As IEnumerator(Of IEnumerator(Of GroupItemsTuple)) Implements IEnumerable(Of IEnumerator(Of GroupItemsTuple)).GetEnumerator
	    Static iFirstTime As Int32
	    If iFirstTime = 0 AndAlso Threading.Interlocked.Increment(iFirstTime) = 1 Then
		Return Me
	    Else
		Throw New InvalidOperationException("GetEnumerator can only be called once on a stream")
	    End If
	End Function


	Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext
	    If _configGroups.MoveNext() Then
		Dim group = _configGroups.Current()
		_current = New GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
		Return True
	    End If
	    Return False
	End Function


	Private Function IEnumerator_GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
	    Return GetEnumerator()
	End Function


	Public ReadOnly Property Current() As IEnumerator(Of GroupItemsTuple) Implements IEnumerator(Of IEnumerator(Of GroupItemsTuple)).Current
	    Get
		Return _current
	    End Get
	End Property

	Private ReadOnly Property IEnumerator_Current() As Object Implements System.Collections.IEnumerator.Current
	    Get
		Return Current
	    End Get
	End Property


	Private Sub Reset() Implements System.Collections.IEnumerator.Reset
	    Throw New NotImplementedException()
	End Sub

	Public Sub Dispose() Implements IDisposable.Dispose
	    'not implemented
	End Sub

    End Class

Open in new window

0
 
LVL 2

Author Comment

by:jimseiwert
ID: 35041828
The app compiles now. I do get a runtime error when I run the code and it hits  the first line in the below sub I get the below error message

  Sub New(ByVal parent As ConfigLoadHelper)
                    _configGroups = parent.config.ConfigurationGroups '.OrderBy(Function(g) g.Priority)
                    _current = Nothing
                End Sub

Unable to cast object of type 'System.Collections.Generic.List`1[CatalogBits.CatalogBits.Config.DeploymentCatalogConfigGroup]' to type 'System.Collections.Generic.IEnumerator`1[CatalogBits.CatalogBits.Config.DeploymentCatalogConfigGroup]'.
0
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 500 total points
ID: 35041841
Please try:

Sub New(ByVal parent As ConfigLoadHelper)
    _configGroups = parent.config.ConfigurationGroups.GetEnumerator() '.OrderBy(Function(g) g.Priority)
    _current = Nothing
End Sub

Open in new window


or

Sub New(ByVal parent As ConfigLoadHelper)
    _configGroups = parent.config.ConfigurationGroups.OrderBy(Function(g) g.Priority).GetEnumerator()
    _current = Nothing
End Sub

Open in new window

0
 
LVL 2

Author Comment

by:jimseiwert
ID: 35041875
One error down and another to go. Now with that change the loadasync is throwing an error at          Me.groupEnumerator = New ConfigurationGroupsEnumerator(Me), I am trying to understand but i am not following this class. I aploigize
Public Sub LoadAsync(ByVal loadedAction As Action(Of DeploymentCatalogConfig), ByVal groupLoadedAction As Action(Of DeploymentCatalogConfigGroup), ByVal itemLoadedAction As Action(Of DeploymentCatalogConfigItem, DeploymentCatalog, Exception))
                Me.groupEnumerator = New ConfigurationGroupsEnumerator(Me)
                Me.loadedAction = loadedAction
                Me.groupLoadedAction = groupLoadedAction
                Me.itemLoadedAction = itemLoadedAction
                LoadNextGroupAsync()
            End Sub

Unable to cast object of type 'ConfigurationGroupsEnumerator' to type 'System.Collections.Generic.IEnumerator`1[CatalogBits.CatalogBits.Loading.DeploymentCatalogLoader

Open in new window

0
 
LVL 2

Author Comment

by:jimseiwert
ID: 35041880
Here is the original c# project link if you want to see how it works. It is at the very bottom of the blog http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2010/03/09/mef-and-the-deploymentcatalog.aspx
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 35041917
There you go:

            Public Sub LoadAsync(ByVal loadedAction As Action(Of DeploymentCatalogConfig), ByVal groupLoadedAction As Action(Of DeploymentCatalogConfigGroup), ByVal itemLoadedAction As Action(Of DeploymentCatalogConfigItem, DeploymentCatalog, Exception))
                Me.groupEnumerator = New ConfigurationGroupsEnumerator(Me).GetEnumerator()
                Me.loadedAction = loadedAction
                Me.groupLoadedAction = groupLoadedAction
                Me.itemLoadedAction = itemLoadedAction
                LoadNextGroupAsync()
            End Sub

Open in new window


            Public Class ConfigurationGroupsEnumerator
                Implements IEnumerable(Of GroupItemsTuple)
                Implements IEnumerator(Of GroupItemsTuple)

                Private _configGroups As IEnumerator(Of DeploymentCatalogConfigGroup)
                Private _current As GroupItemsTuple

                Sub New(ByVal parent As ConfigLoadHelper)
                    _configGroups = parent.config.ConfigurationGroups.OrderBy(Function(g) g.Priority).GetEnumerator()
                    _current = Nothing
                End Sub


                Public Function GetEnumerator() As IEnumerator(Of GroupItemsTuple) Implements IEnumerable(Of GroupItemsTuple).GetEnumerator
                    Static iFirstTime As Int32
                    If iFirstTime = 0 AndAlso Threading.Interlocked.Increment(iFirstTime) = 1 Then
                        Return Me
                    Else
                        Throw New InvalidOperationException("GetEnumerator can only be called once on a stream")
                    End If
                End Function


                Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext
                    If _configGroups.MoveNext() Then
                        Dim group = _configGroups.Current()
                        _current = New GroupItemsTuple(group, group.Catalogs.AsEnumerable().GetEnumerator())
                        Return True
                    End If
                    Return False
                End Function


                Private Function IEnumerator_GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
                    Return GetEnumerator()
                End Function


                Public ReadOnly Property Current() As GroupItemsTuple Implements IEnumerator(Of GroupItemsTuple).Current
                    Get
                        Return _current
                    End Get
                End Property

                Private ReadOnly Property IEnumerator_Current() As Object Implements System.Collections.IEnumerator.Current
                    Get
                        Return Current
                    End Get
                End Property


                Private Sub Reset() Implements System.Collections.IEnumerator.Reset
                    Throw New NotImplementedException()
                End Sub

                Public Sub Dispose() Implements IDisposable.Dispose
                    'not implemented
                End Sub

            End Class

Open in new window

0
 
LVL 2

Author Closing Comment

by:jimseiwert
ID: 35041940
Excllent Thank you, Now if i can only get the xap plugins to load hahaha

Thank you again!
0
 
LVL 2

Author Comment

by:jimseiwert
ID: 35041990
I am still having problems getting the xap files to download. NOt sure if you are still up for helping but if you are I have asked the question here http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26865747.html so if you are up for it you can get more points.

I appreciate your help.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now