Return Distinct Objects with Linq - vb.net

(I'm new in VB.Net) I have these three classes:
Public Class Classe_PIVA_Cond
Public Property my_codFiscale As String
Public Property my_presenzaDuplicati As Boolean
Public Property my_listaCondominii As New List(Of Classe_Condominio)
Public Sub New()
End Sub
Public Sub New(codFiscale As String, presenzaDuplicati As Boolean, listaCondominii As List(Of Classe_Condominio))
Me.my_codFiscale = codFiscale
Me.my_presenzaDuplicati = presenzaDuplicati
Me.my_listaCondominii = listaCondominii
End Sub
End Class
'==================================
Public Class Classe_Condominio
Public Property my_Studio As New Classe_Studio
Public Property my_Amministratore As New Classe_Amministratore
Public Property my_codCondominio As String
Public Property my_indirizzo As String
Public Property my_comune As String
Public Property my_cap As String
Public Property my_provincia As String
Public Property my_codFiscale As String
Public Sub New()
End Sub
Public Sub New(studio As Classe_Studio, amministratore As Classe_Amministratore, codCondominio As String, indirizzo As String, comune As String, cap As String, provincia As String, codFiscale As String)
Me.my_Studio = studio
Me.my_Amministratore = amministratore
Me.my_codCondominio = codCondominio
Me.my_indirizzo = indirizzo
Me.my_comune = comune
Me.my_cap = cap
Me.my_provincia = provincia
Me.my_codFiscale = codFiscale
End Sub
End Class
'==================================
Public Class Classe_Studio
Public Property my_codice As String
Public Property my_ragioneSociale As String
Public Property my_pIvaCodFisc As String
Public Sub New()
End Sub
Public Sub New(codice As String, ragioneSociale As String, pIvaCodFisc As String)
Me.my_codice = codice
Me.my_ragioneSociale = ragioneSociale
Me.my_pIvaCodFisc = pIvaCodFisc
End Sub
End Clas
I would try to return a List of distinct Classe_Studio.my_codice in a List(Of Classe_PIVA_Cond).
Any suggestion?

Try
Dim my_codiceDistinctList = Classe_PIVA_CondList
.SelectMany(Function(x) x.my_listaCondominii)
.Select(Function(y) y.my_Studio.my_codice)
.Distinct()
.ToList()

Related

How to create zip:// protocol in GeckoFx to read password protected zip files?

I'm create a program in VB.NET with embedded GeckoFx browser. How to creating zip:// protocol to read from password protected zip file?
Example: zip:///d:/dir/file.zip!/idnex.html
Note: jar:file:///d:/dir/file.zip!/idnex.html is not read the index.html from password protected ZIP file.
Initialize Gecko in MainWindow class:
Sub New()
InitializeComponent()
Xpcom.Initialize("Firefox64")
Xpcom.RegisterFactory(
New Guid("66170430-e4ec-11e9-aaef-0800200c9a66"),
"Zip protocol handler",
"#mozilla.org/network/protocol;1?name=zip",
New ZipFacrory)
End Sub
The ZipFactory class:
Class ZipFacrory
Implements nsIFactory
Public Function CreateInstance(aOuter As nsISupports, ByRef iid As Guid) As IntPtr Implements nsIFactory.CreateInstance
Return Marshal.GetComInterfaceForObject(New ZipProtocolHandler(), GetType(nsIProtocolHandler))
End Function
Public Sub LockFactory(lock As Boolean) Implements nsIFactory.LockFactory
End Sub
End Class
The ZipProtocolHandler class:
Class ZipProtocolHandler
Implements nsIProtocolHandler
Public Sub GetSchemeAttribute(aScheme As nsACStringBase) Implements nsIProtocolHandler.GetSchemeAttribute
aScheme.SetData("zip")
End Sub
Public Function GetDefaultPortAttribute() As Integer Implements nsIProtocolHandler.GetDefaultPortAttribute
Return -1
End Function
Public Function GetProtocolFlagsAttribute() As UInteger Implements nsIProtocolHandler.GetProtocolFlagsAttribute
Return nsIProtocolHandlerConsts.URI_NOAUTH Or nsIProtocolHandlerConsts.URI_IS_LOCAL_FILE Or
nsIProtocolHandlerConsts.URI_IS_LOCAL_RESOURCE
End Function
Public Function NewURI(aSpec As nsAUTF8StringBase, aOriginCharset As String, aBaseURI As nsIURI) As nsIURI Implements nsIProtocolHandler.NewURI
Dim mutator As nsIStandardURLMutator = Xpcom.CreateInstance(Of nsIStandardURLMutator)("#mozilla.org/network/standard-url-mutator;1")
Return mutator.Init(nsIStandardURLConsts.URLTYPE_STANDARD, -1, aSpec, aOriginCharset, aBaseURI).Finalize()
End Function
Public Function NewChannel2(aURI As nsIURI, aLoadinfo As nsILoadInfo) As nsIChannel Implements nsIProtocolHandler.NewChannel2
Return New ZipChannel(aURI, aLoadinfo)
End Function
Public Function NewChannel(aURI As nsIURI) As nsIChannel Implements nsIProtocolHandler.NewChannel
Return NewChannel2(aURI, Nothing)
End Function
Public Function AllowPort(port As Integer, scheme As String) As Boolean Implements nsIProtocolHandler.AllowPort
Return False
End Function
End Class
The ZipChannel class:
Class ZipChannel
Implements nsIChannel
Private status As Integer
Private loadGroup As nsILoadGroup
Private loadFlags As UInteger
Private originalURI As nsIURI
Private owner As nsISupports
Private notificationCallbacks As nsIInterfaceRequestor
Private contentType As String
Private contentCharset As String
Private loadInfo As nsILoadInfo
Private contentLengt As Long
Private contentDisposition As UInteger
Private contentDispositionFilename As Integer
Sub New(aURI As nsIURI, aloadInfo As nsILoadInfo)
originalURI = aURI
loadInfo = aloadInfo
End Sub
Public Sub GetNameAttribute(aName As nsAUTF8StringBase) Implements nsIChannel.GetNameAttribute, nsIRequest.GetNameAttribute
aName.SetData("Zip channel")
End Sub
Public Function IsPending() As Boolean Implements nsIChannel.IsPending, nsIRequest.IsPending
Return False
End Function
Public Function GetStatusAttribute() As Integer Implements nsIChannel.GetStatusAttribute, nsIRequest.GetStatusAttribute
Return status
End Function
Public Sub Cancel(aStatus As Integer) Implements nsIChannel.Cancel, nsIRequest.Cancel
status = aStatus
End Sub
Public Sub Suspend() Implements nsIChannel.Suspend, nsIRequest.Suspend
status = GeckoError.NS_OK
End Sub
Public Sub [Resume]() Implements nsIChannel.Resume, nsIRequest.Resume
status = GeckoError.NS_OK
End Sub
Public Function GetLoadGroupAttribute() As nsILoadGroup Implements nsIChannel.GetLoadGroupAttribute, nsIRequest.GetLoadGroupAttribute
Return loadGroup
End Function
Public Sub SetLoadGroupAttribute(aLoadGroup As nsILoadGroup) Implements nsIChannel.SetLoadGroupAttribute, nsIRequest.SetLoadGroupAttribute
loadGroup = aLoadGroup
End Sub
Public Function GetLoadFlagsAttribute() As UInteger Implements nsIChannel.GetLoadFlagsAttribute, nsIRequest.GetLoadFlagsAttribute
Return loadFlags
End Function
Public Sub SetLoadFlagsAttribute(aLoadFlags As UInteger) Implements nsIChannel.SetLoadFlagsAttribute, nsIRequest.SetLoadFlagsAttribute
loadFlags = aLoadFlags
End Sub
Public Function GetOriginalURIAttribute() As nsIURI Implements nsIChannel.GetOriginalURIAttribute
Return originalURI
End Function
Public Sub SetOriginalURIAttribute(aOriginalURI As nsIURI) Implements nsIChannel.SetOriginalURIAttribute
originalURI = aOriginalURI
End Sub
Public Function GetURIAttribute() As nsIURI Implements nsIChannel.GetURIAttribute
Return originalURI
End Function
Public Function GetOwnerAttribute() As nsISupports Implements nsIChannel.GetOwnerAttribute
Return owner
End Function
Public Sub SetOwnerAttribute(aOwner As nsISupports) Implements nsIChannel.SetOwnerAttribute
owner = aOwner
End Sub
Public Function GetNotificationCallbacksAttribute() As nsIInterfaceRequestor Implements nsIChannel.GetNotificationCallbacksAttribute
Return notificationCallbacks
End Function
Public Sub SetNotificationCallbacksAttribute(aNotificationCallbacks As nsIInterfaceRequestor) Implements nsIChannel.SetNotificationCallbacksAttribute
notificationCallbacks = aNotificationCallbacks
End Sub
Public Function GetSecurityInfoAttribute() As nsISupports Implements nsIChannel.GetSecurityInfoAttribute
'???
Return Nothing
End Function
Public Sub GetContentTypeAttribute(aContentType As nsACStringBase) Implements nsIChannel.GetContentTypeAttribute
aContentType.SetData(contentType)
End Sub
Public Sub SetContentTypeAttribute(aContentType As nsACStringBase) Implements nsIChannel.SetContentTypeAttribute
contentType = aContentType.ToString
End Sub
Public Sub GetContentCharsetAttribute(aContentCharset As nsACStringBase) Implements nsIChannel.GetContentCharsetAttribute
aContentCharset.SetData(contentCharset)
End Sub
Public Sub SetContentCharsetAttribute(aContentCharset As nsACStringBase) Implements nsIChannel.SetContentCharsetAttribute
contentCharset = aContentCharset.ToString
End Sub
Public Function GetContentLengthAttribute() As Long Implements nsIChannel.GetContentLengthAttribute
Return contentLengt
End Function
Public Sub SetContentLengthAttribute(aContentLength As Long) Implements nsIChannel.SetContentLengthAttribute
contentLengt = aContentLength
End Sub
Public Function Open() As nsIInputStream Implements nsIChannel.Open
'NS_ERROR_IN_PROGRESS (if the channel is reopened)
Throw New NotImplementedException()
End Function
Public Function Open2() As nsIInputStream Implements nsIChannel.Open2
Throw New NotImplementedException()
End Function
Public Sub AsyncOpen(aListener As nsIStreamListener, aContext As nsISupports) Implements nsIChannel.AsyncOpen
'example zip://impera.zip!/folder/file.png
Dim uri As Uri = originalURI.ToUri
Dim filespec As String = uri.Authority & uri.AbsolutePath
Dim t As String() = filespec.Split({"!/", "!\", "!"}, StringSplitOptions.None)
' MIME type
Dim ms = Xpcom.CreateInstance(Of nsIMIMEService)("#mozilla.org/mime;1")
Dim mime As nsACString = New nsACString
ms.GetTypeFromURI(originalURI, mime)
SetContentTypeAttribute(mime)
contentCharset = Text.Encoding.Default.WebName
aListener.OnStartRequest(Me, aContext)
Try
Using zip As ZipFile = New ZipFile(t(0))
Using zipstream As System.IO.Stream = zip(t(1)).OpenReader(kulcs), sr As System.IO.StreamReader = New System.IO.StreamReader(zipstream, Text.Encoding.Default)
Dim data As String = sr.ReadToEnd
Dim s = New nsAString
s.SetData(data)
Dim converter = Xpcom.CreateInstance(Of nsIConverterOutputStream)("#mozilla.org/intl/converter-output-stream;1")
Dim size As UInteger = zipstream.Length
Dim storagestream = Xpcom.CreateInstance(Of nsIStorageStream)("#mozilla.org/storagestream;1")
storagestream.Init(8192, size)
converter.Init(storagestream.GetOutputStream(0), Text.Encoding.Default.WebName) 'UTF-8 Text.Encoding.Default.BodyName
converter.WriteString(s)
converter.Close()
Dim stream = storagestream.NewInputStream(0)
aListener.OnDataAvailable(Me, aContext, stream, 0, stream.Available)
End Using
End Using
Catch ex As Exception
End Try
aListener.OnStopRequest(Me, aContext, GeckoError.NS_OK)
End Sub
Public Sub AsyncOpen2(aListener As nsIStreamListener) Implements nsIChannel.AsyncOpen2
AsyncOpen(aListener, Nothing)
End Sub
Public Function GetContentDispositionAttribute() As UInteger Implements nsIChannel.GetContentDispositionAttribute
Return contentDisposition
End Function
Public Sub SetContentDispositionAttribute(aContentDisposition As UInteger) Implements nsIChannel.SetContentDispositionAttribute
contentDisposition = aContentDisposition
End Sub
Public Sub GetContentDispositionFilenameAttribute(aContentDispositionFilename As nsAStringBase) Implements nsIChannel.GetContentDispositionFilenameAttribute
aContentDispositionFilename.SetData(contentDispositionFilename)
End Sub
Public Sub SetContentDispositionFilenameAttribute(aContentDispositionFilename As nsAStringBase) Implements nsIChannel.SetContentDispositionFilenameAttribute
contentDispositionFilename = aContentDispositionFilename.ToString
End Sub
Public Sub GetContentDispositionHeaderAttribute(aContentDispositionHeader As nsACStringBase) Implements nsIChannel.GetContentDispositionHeaderAttribute
'???
'aContentDispositionHeader.SetData("inline")
'aContentDispositionHeader.SetData("Content-Disposition: inline")
End Sub
Public Function GetLoadInfoAttribute() As nsILoadInfo Implements nsIChannel.GetLoadInfoAttribute
Return loadInfo
End Function
Public Sub SetLoadInfoAttribute(aLoadInfo As nsILoadInfo) Implements nsIChannel.SetLoadInfoAttribute
loadInfo = aLoadInfo
End Sub
Public Function GetIsDocumentAttribute() As Boolean Implements nsIChannel.GetIsDocumentAttribute
Return False
End Function
End Class
Test HTML page (D:/index.html):
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<p><img src="zip:///d:/web.zip!/truck.png"/><img src="truck.png"/></p>
</body>
</html>
The image does not load from the web.zip file.
But the channel works:
Dim uri = IOService.CreateNsIUri("zip:///d:/web.zip!/truck.png")
Dim ch As nsIChannel = IOService.NewChannelFromUri(uri)
Dim list = New Listener
ch.AsyncOpen(list, Nothing)
The Listener class:
Class Listener
Implements nsIStreamListener
Public Sub OnStartRequest(aRequest As nsIRequest, aContext As nsISupports) Implements nsIStreamListener.OnStartRequest
End Sub
Public Sub OnStopRequest(aRequest As nsIRequest, aContext As nsISupports, aStatusCode As Integer) Implements nsIStreamListener.OnStopRequest
End Sub
Public Sub OnDataAvailable(aRequest As nsIRequest, aContext As nsISupports, aInputStream As nsIInputStream, aOffset As ULong, aCount As UInteger) Implements nsIStreamListener.OnDataAvailable
Try
Dim ss = Gecko.IO.InputStream.Create(aInputStream)
Dim fs = System.IO.File.Create("d:\truck2.png")
ss.CopyTo(fs)
fs.Close()
Catch ex As Exception
End Try
End Sub
Private Sub nsIRequestObserver_OnStartRequest(aRequest As nsIRequest, aContext As nsISupports) Implements nsIRequestObserver.OnStartRequest
End Sub
Private Sub nsIRequestObserver_OnStopRequest(aRequest As nsIRequest, aContext As nsISupports, aStatusCode As Integer) Implements nsIRequestObserver.OnStopRequest
End Sub
End Class
The D:/truck.png and D:/truck2.png are same.
Why doesn't the picture appear in browser?

Class with property that is a List Of items in a subclass

I want a class for a Customer, with a text property name.
Another property CustAddress will be a list of multiple addresses.
Each address will have two string properties.
Here is what I have.
I am not sure if I need something in the constructor of the class address.
And I'm even not sure what the code would look like to exploit this class.
Also, I can't get the F11 Step Into debug feature to step into the class code. If i put a break in the class code it does break and works fine. I have modified the option "Just My Code" to remove checkbox, but it does not help. I have a solution containing one class module and one Windows App together.
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)>
Public Class ComClass1
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "c8e723b4-f229-4368-9737-97c4c71d490a"
Public Const InterfaceId As String = "16275ddb-5cfe-47c0-995f-84a5f868ad1b"
Public Const EventsId As String = "dad73a5c-8ac4-4384-a5f9-8e2c388b5514"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
'Fields
Private _name As String
Public _CustAddress As List(Of address)
'Constructor for class ComClass
Public Sub New()
_CustAddress = New List(Of address)
End Sub
Public Property CustName() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Public Property CustAddress() As List(Of address)
Get
Return _CustAddress
End Get
Set(value As List(Of address))
_CustAddress = value
End Set
End Property
Public Class address
Private _address1 As String
Private _address2 As String
Public Sub New()
'??????
End Sub
Public Property Address1 As String
Get
Return _address1
End Get
Set(value As String)
_address1 = value
End Set
End Property
Public Property Address2 As String
Get
Return _address2
End Get
Set(value As String)
_address2 = value
End Set
End Property
End Class
End Class
I took out the com stuff just to shorten the answer. Since you had no extra code in the Property Procedures I shortened that to automatic Properties. I also moved the address Class out on its own. This class could be useful else where in the program so a nested class is not really necessary.
Public Class ComClass1
Public Property CustName As String
Public Property CustAddress As List(Of address)
Public Sub New(cName As String, cAddresses As List(Of address))
CustName = cName
CustAddress = cAddresses
End Sub
End Class
Public Class address
Public Property Address1 As String 'Street Address
Public Property Address2 As String 'City and State
Public Sub New(a1 As String, a2 As String)
Address1 = a1
Address2 = a2
End Sub
End Class
Private Sub DeclareAComClass1()
Dim addrList As New List(Of address) From {
New address("12 Main Street", "Los Angeles, CA"),
New address("13 Park Avenue", "New York, NY")
}
Dim cc As New ComClass1("Big Company, Inc.", addrList)
End Sub
Here is what I have ended up with. #Mary got me further ahead. But because I am using a COM class, I can't have any public constructors with parameters.
I added a method called AddAddress which gives me the functionality I need.
In my original post I somehow left out MyBase.New which is required for a COM class.
I encourage comments with insights on this approach.
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)>
Public Class ComClass1
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "c8e723b4-f229-4368-9737-97c4c71d490a"
Public Const InterfaceId As String = "16275ddb-5cfe-47c0-995f-84a5f868ad1b"
Public Const EventsId As String = "dad73a5c-8ac4-4384-a5f9-8e2c388b5514"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
'Fields
Private _name As String
Private _CustAddress As List(Of address)
'Constructor for class ComClass
Public Sub New()
MyBase.New
_CustAddress = New List(Of address)
End Sub
Public Sub AddAddress(a1 As String, a2 As String)
Dim addr As New address(a1, a2)
_CustAddress.Add(addr)
End Sub
Public Property CustName() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Public Property CustAddress() As List(Of address)
Get
Return _CustAddress
End Get
Set(value As List(Of address))
_CustAddress = value
End Set
End Property
Public Class address
Private _address1 As String
Private _address2 As String
Public Sub New(a1 As String, a2 As String)
_address1 = a1
_address2 = a2
End Sub
Public Property Address1 As String
Get
Return _address1
End Get
Set(value As String)
_address1 = value
End Set
End Property
Public Property Address2 As String
Get
Return _address2
End Get
Set(value As String)
_address2 = value
End Set
End Property
End Class
End Class
And the code to implement/test is as follows:
Dim TestClass As New ComClass1
Dim myint As Int32
TestClass.CustName = "John Smith"
TestClass.AddAddress("123 Main Street", "Los Angeles")
TestClass.AddAddress("13 Park Avenue", "New York")
Debug.Print(TestClass.CustAddress(0).Address1) '123 Main Stree'
Debug.Print(TestClass.CustAddress(1).Address1) '13 Park Avenue
TestClass.CustAddress.Remove(TestClass.CustAddress(0))
Debug.Print(TestClass.CustAddress(0).Address1) ' 13 Park Avenue

Getting a property from the instantiator class

Not an experienced programmer, so probably not a hard question.
Developing a small application in VB.net in WPF.
I made 3 classes, EngineeringObject<==Inherits==PartOfInstallation<==Inherits==SensorActor
In the class SensorActor I'm trying to get a property of PartOfInstallation with the function MyBase.Name. But this goes directly to EngineeringObject. How do I solve this?
Public Class EngineeringObject
''Private declarations, alleen objecten die erven kunnen hieraan, of dmv van getters en setters
'Name of part
Private sName As String = "Naam"
'81346 Id's
Private sSystemId As String = "Functie" 'VentilationSystem, Pumpsystem
Private sLocationId As String = "Locatie" 'Room 0.0
Private sObjectId As String = "Object" 'Fan, Pump
'General
Private sPartNumber As String
Private sLinkToDatasheet As String
'Property's
Public Property Name() As String
Get
Return sName
End Get
Set(ByVal value As String)
sName = value
End Set
End Property
Public Property SystemId() As String
Get
Return sSystemId
End Get
Set(ByVal value As String)
sSystemId = value
End Set
End Property
Public Property PartNumber() As String
Get
Return sPartNumber
End Get
Set(ByVal value As String)
sPartNumber = value
End Set
End Property
Public Property LinkToDatasheet() As String
Get
Return sLinkToDatasheet
End Get
Set(ByVal value As String)
sLinkToDatasheet = value
End Set
End Property
Public Sub New()
End Sub
End Class
Public Class PartOfInstallation
Inherits EngineeringObject
'src: https://stackoverflow.com/questions/21308881/parent-creating-child-object
'src: https://stackoverflow.com/questions/16244548/how-to-create-a-list-of-parent-objects-where-each-parent-can-have-a-list-of-chil
Private lSensorActor As New List(Of SensorActor)
Public Function GetSensorActor()
Return Me.lSensorActor
End Function
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor)
End Sub
End Class
Public Class SensorActor
Inherits PartOfInstallation
Dim sMyPartOfInstallation As String
Public Property MyPartOfInstallation As String
Get
Return sMyPartOfInstallation
End Get
Set(value As String)
sMyPartOfInstallation = MyBase.Name
End Set
End Property
End Class
If I understand it correctly, based on your comments, you want every SensorActor instantiated within a PartOfInstallation instance to get the same name as that instance.
If so, then just add a second constructor to your SensorActor class allowing you to pass a name for it as well:
Public Class SensorActor
Inherits PartOfInstallation
...your code...
Public Sub New() 'Empty constructor, for if/when you don't want to set the name immediately.
End Sub
Public Sub New(ByVal Name As String)
Me.Name = Name
End Sub
End Class
Now in your PartOfInstallation class you can do:
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me.Name)) 'Here, "Me" refers to the current PartOfInstallation instance.
End Sub
Alternatively you can make the SensorActor constructor take a PartOfInstallation instance instead, allowing you to copy any properties you like:
Public Class SensorActor
Inherits PartOfInstallation
...your code...
Public Sub New()
End Sub
Public Sub New(ByVal BasedOnPOI As PartOfInstallation)
Me.Name = BasedOnPOI.Name
End Sub
End Class
Thus making the code in the PartOfInstallation class:
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me))
End Sub
Read more about constructors: Object Lifetime: How Objects Are Created and Destroyed (Visual Basic) | Microsoft Docs
The result below, if there's room for improvement... always welcome.
SensorActor
Public Class SensorActor
Inherits PartOfInstallation
Dim sTemp As String
Public Overloads Property SystemId() As String
Get
Return Me.sSystemId
End Get
Set(ByVal value As String)
Me.sSystemId = sTemp + "." + value
End Set
End Property
Public Sub New(ByVal BasedOnPOI As PartOfInstallation)
sTemp = BasedOnPOI.SystemId
End Sub
End Class
PartOfInstallation
Public Class PartOfInstallation
Inherits EngineeringObject
'src: https://stackoverflow.com/questions/21308881/parent-creating-child-object
'src: https://stackoverflow.com/questions/16244548/how-to-create-a-list-of-parent-objects-where-each-parent-can-have-a-list-of-chil
Private lSensorActor As New List(Of SensorActor)
Public Function GetSensorActor()
Return Me.lSensorActor
End Function
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me))
End Sub
End Class
EngineeringObject
Public Class EngineeringObject
''Private declarations, alleen objecten die erven kunnen hieraan, of dmv van getters en setters
'Name of part
Private sName As String = "Naam"
'81346 Id's
Friend sSystemId As String = "Functie" 'VentilationSystem, Pumpsystem
Private sLocationId As String = "Locatie" 'Room 0.0
Private sObjectId As String = "Object" 'Fan, Pump
'General
Private sPartNumber As String
Private sLinkToDatasheet As String
'Property's
Public Property Name() As String
Get
Return sName
End Get
Set(ByVal value As String)
sName = value
End Set
End Property
Public Property SystemId() As String
Get
Return sSystemId
End Get
Set(ByVal value As String)
sSystemId = "=" + value
End Set
End Property
Public Property PartNumber() As String
Get
Return sPartNumber
End Get
Set(ByVal value As String)
sPartNumber = value
End Set
End Property
Public Property LinkToDatasheet() As String
Get
Return sLinkToDatasheet
End Get
Set(ByVal value As String)
sLinkToDatasheet = value
End Set
End Property
Public Sub New()
End Sub
End Class

LINQ Query returning Ienumerable

I have the following 2 classes
Public Class LookupsModel
Implements IEnumerable(Of LookupModel)
Public _LookupModel() As LookupModel
Public Sub New(pArray As ArrayList)
_LookupModel = New LookupModel(pArray.Count - 1) {}
Dim i As Integer
For Each l As LookupModel In pArray
_LookupModel(i) = l
i += 1
Next
End Sub
Public Function GetEnumerator() As IEnumerator(Of LookupModel) Implements IEnumerable(Of LookupModel).GetEnumerator
Return New LookupEmum(_LookupModel)
End Function
Public Function GetEnumerator1() As IEnumerator Implements IEnumerable.GetEnumerator
Return New LookupEmum(_LookupModel)
End Function
Public Property Heading1 As String
Public Property Heading2 As String
Public Property Heading3 As String
Public Property Heading4 As String
Public Property Heading5 As String
Public Property Heading6 As String
Public Property CalledBy As String
Public Property ParmName1 As String
Public Property ParmName2 As String
Public Property ParmName3 As String
Public Property ParmName4 As String
Public Property ParmName5 As String
Public Property ParmName6 As String
Public Property ValueFieldGetter() As Func(Of LookupModel, String)
Public Property DescriptionFieldGetter() As Func(Of LookupModel, String)
End Class
Public Class LookupModel
Public Sub New(ByVal Key As String, Optional ByVal Desc As String = Nothing, Optional Extra_1 As String = Nothing, Optional Extra_2 As String = Nothing, Optional Extra_3 As String = Nothing, Optional Extra_4 As String = Nothing)
Me.Field1 = Key
Me.Field2 = Desc
Me.Field3 = Extra_1
Me.Field4 = Extra_2
Me.Field5 = Extra_3
Me.Field6 = Extra_4
End Sub
Public Sub New()
Me.Field1 = Nothing
Me.Field2 = Nothing
Me.Field3 = Nothing
Me.Field4 = Nothing
Me.Field5 = Nothing
Me.Field6 = Nothing
End Sub
Public Property Field1 As String
Public Property Field2 As String
Public Property Field3 As String
Public Property Field4 As String
Public Property Field5 As String
Public Property Field6 As String
End Class
This is the linq query:
Dim lm As LookupsModel = GetLookupsModel(FieldID, lookup, LookupPage:=1, SearchField:=SearchField, SearchFields:=searchFields, SearchString:=String.Empty)
Dim lm2 As IEnumerable(Of LookupModel) = lm.Where(Function(p) p.Field1.Contains("A"))
I'm trying to query LookupsModel and only get the LookupModel collection where LookupModel.Field1 starts with "A". But the following query returns an Ienumerable of LookupModel, not the LookupsModel object with those items excluded. How do we accomplish this and get a LookupsModel object as a result?
You can't directly cast from an IEnumerable(Of LookpupModel) to a LookupsModel. You have a few options:
Add a constructor that takes an existing IEnumerable(Of LookupModel)
Convert the output of Where to an ArrayList and use your existing constructor.
But what's the point of LookupsModel in the first place? All you're doing is wrapping an array of LookupModel and not adding any additional functionality. Why not just stick with IEnumerable(Of LookupModel)?

LongListSelector not working (not navigating to other pages)

I have implemented a LongListSelector for my Windows Phone 7 app. However when I tap an item it doesn't navigate to the desired page. Does anyone know why and how this can be fixed? Below is my code. Each page has it's own uri and I want to navigate to different pages.
All help would be very much appreciated.
Many thanks
Code:
Imports System.Linq
Imports Microsoft.Phone.Controls
Partial Public Class Victoria_line
Inherits PhoneApplicationPage
Public Sub New()
InitializeComponent()
Dim source As New List(Of JumpDemo)()
source.Add(New JumpDemo() With { _
.Name = "Blackhorse Road", _
.FareZone = "Fare zone 3", _
.GroupBy = "b", _
.Link = "/Lines and Stations/Victoria/Blackhorse_Road_(Victoria).xaml" _
})
source.Add(New JumpDemo() With { _
.Name = "Warren Street", _
.FareZone = "Fare zone 1", _
.GroupBy = "w", _
.Link = "/Lines and Stations/Victoria/Warren_Street_(Victoria).xaml" _
})
Dim MygroupBy = From jumpdemo In source _
Group jumpdemo By jumpdemo.GroupBy Into c = Group _
Order By GroupBy _
Select New _
Group(Of JumpDemo)(GroupBy, c)
Me.Victoria_line.ItemsSource = MygroupBy
End Sub
Private Sub Victoria_line_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
If Victoria_line.SelectedItem = Nothing Then
Return
End If
Dim addressString As String = "/StationPage.xaml"
Dim pageUri As Uri = New Uri(addressString, UriKind.Relative)
NavigationService.Navigate(pageUri)
' Reset selected item to -1 (no selection)
Victoria_line.SelectedItem = Nothing
End Sub
End Class
Public Class Group(Of T)
Implements IEnumerable(Of T)
Public Sub New(name As String, items As IEnumerable(Of T))
Me.Title = name
Me.Items = New List(Of T)(items)
End Sub
Public Overrides Function Equals(obj As Object) As Boolean
Dim that As Group(Of T) = TryCast(obj, Group(Of T))
Return (that IsNot Nothing) AndAlso (Me.Title.Equals(that.Title))
End Function
Public Property Title() As String
Get
Return m_Title
End Get
Set(value As String)
m_Title = value
End Set
End Property
Private m_Title As String
Public Property Items() As IList(Of T)
Get
Return m_Items
End Get
Set(value As IList(Of T))
m_Items = value
End Set
End Property
Private m_Items As IList(Of T)
Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator
Return Me.Items.GetEnumerator()
End Function
Private Function System_Collections_IEnumerable_GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
Return Me.Items.GetEnumerator()
End Function
End Class
Public Class Victoria
Public Property Name() As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
Private m_Name As String
Public Property FareZone() As String
Get
Return m_FareZone
End Get
Set(value As String)
m_FareZone = value
End Set
End Property
Private m_FareZone As String
Public Property GroupBy() As String
Get
Return m_GroupBy
End Get
Set(value As String)
m_GroupBy = value
End Set
End Property
Private m_GroupBy As String
Public Property Link() As Uri
Get
Return m_Link
End Get
Set(value As Uri)
m_Link = value
End Set
End Property
Private m_Link As Uri
End Class
If what you are trying to achieve is navigate to another page when you tap on an item you should just register for the Tap event inside your Item DataTemplate and in the event handler do something like this:
Private Sub Item_Tap(sender As Object, e As GestureEventArgs)
Dim element As FrameworkElement = TryCast(sender, FrameworkElement)
Dim item As JumpDemo = TryCast(element.DataContext, JumpDemo)
Dim addressString As String = item.Link
Dim pageUri As Uri = New Uri(addressString, UriKind.Relative)
NavigationService.Navigate(pageUri)
End Sub