[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.1

VB to C# conversion

Asked by shri0809 in C# Programming Language, Microsoft Visual C#.Net, VB Objects

hello everyone,
I m trying to convert this code to C#
any help wud be appriciated

thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
Public Function Parse(ByVal arrStreamData() As Byte) As Boolean
        '
        Dim arrBuffer() As Byte
        Dim udtHeader As udtDNSHeader
		Dim objDnsMessage As DnsMessage = Nothing
        Dim shtLabelLength As Short
		Dim strLabel As String = String.Empty
        Dim shtCurPosition As Short
		Dim strTemp As String = String.Empty
        Dim shtTemp As Short
        Dim strStreamData As String
        Dim i As Integer
 
        '
        '## Parse the header of the DNS message
        '
        'Destroy the old object
        m_objHeader = Nothing
        '
        'Create a new one
        m_objHeader = New DnsHeader()
        '
        'Convert the String data type to a byte array
        arrBuffer = arrStreamData
        strStreamData = System.Text.Encoding.Unicode.GetString(arrBuffer)
        'Copy the string to memory
        Dim dataPointer As IntPtr = Marshal.StringToHGlobalAuto(strStreamData)
 
        '
        'Read the header of the DNS message into the
        'udtHeader structure
        udtHeader = CType(Marshal.PtrToStructure(dataPointer, GetType(udtDNSHeader)), udtDNSHeader)
 
        Marshal.FreeHGlobal(dataPointer)
        '
        'Initialize values of the properties of the m_objHeader
        'object which holds data for the Header property of this
        'class (CDnsMessage). The data are read from the members
        'of the udtHeader structure.
        With m_objHeader
            '
            .MessageId = IntegerToUnsigned(Win32.Network.ntohs(udtHeader.Identification))
            '
            .IsResponse = CBool(udtHeader.Field2 And &H80)
            .IsQuery = Not .IsResponse
            '
            If Not CBool(udtHeader.Field2 And &H8) Then .OPCode = DnsOPCode.QUERY
            If CBool(udtHeader.Field2 And &H10) Then .OPCode = DnsOPCode.IQUERY
            If CBool(udtHeader.Field2 And &H20) Then .OPCode = DnsOPCode.STATUS
            '
            .AuthoritativeAnswer = CBool(udtHeader.Field2 And &H4)
            .IsTruncated = CBool(udtHeader.Field2 And &H2)
            .RecursionDesired = CBool(udtHeader.Field2 And &H1)
            '
            .RecursionAvailable = CBool(udtHeader.Field3 And &H80)
            .ResponseCode = CShort(udtHeader.Field3 Xor &H80)
            '
            .ANCount = IntegerToUnsigned(Win32.Network.ntohs(udtHeader.ANCount))
            .ARCount = IntegerToUnsigned(Win32.Network.ntohs(udtHeader.ARCount))
            .NSCount = IntegerToUnsigned(Win32.Network.ntohs(udtHeader.NSCount))
            .QDCount = IntegerToUnsigned(Win32.Network.ntohs(udtHeader.QDCount))
            '
        End With
        '
        '## Parse the QUESTION section of the DNS message
        '
        Dim strQName As String
        Dim intQClass As Integer
        Dim intQType As Integer
        '
        mvarQuestions = Nothing
        mvarQuestions = New DnsQuestions()
        '
        'The HEADER takes 12 octets(bytes) so the QUESTION
        'section begins at 13rd octet in the stream,
        'that is 12th item in a zero-based byte array - arrBuffer
        '
        shtCurPosition = 12
        '
        strStreamData = ConversionFunctions.BytesToString(arrBuffer)
        For i = 1 To m_objHeader.QDCount
            '
            'Get lehgth of the first label of QNAME
            shtLabelLength = arrBuffer(shtCurPosition)
            '
            'The QNAME parameter of the QUESTION section
            'ends with Chr$(0) character
            Do Until shtLabelLength = 0
                '
                'Retrieve the next label of the QNAME parameter
                'The "dot" character is added at the end of each label
                strTemp = strTemp & Mid$(strStreamData, shtCurPosition + 2, shtLabelLength) & "."
                '
                'Move the stream pointer at the octet where length
                'of the next label is defined
                shtCurPosition = CShort(shtCurPosition + shtLabelLength + 1)
                '
                'Get length of the next label
                shtLabelLength = arrBuffer(shtCurPosition)
                '
            Loop
            '
            'Remove the last "dot" symbol from the strTemp string
            strQName = Left$(strTemp, Len(strTemp) - 1)
            '
            'Move the stream pointer to read the QTYPE parameter
            shtCurPosition = CShort(shtCurPosition + 1)
            '
            'Read the QTYPE parameter
 
            shtTemp = MarshalBytesToShort(arrBuffer, shtCurPosition)
            ' free memory
 
            intQType = IntegerToUnsigned(Win32.Network.ntohs(shtTemp))
            '
            'Move the stream pointer to read the QCLASS parameter
            shtCurPosition = CShort(shtCurPosition + 2)
            '
            'Read the QCLASS parameter
            shtTemp = MarshalBytesToShort(arrBuffer, shtCurPosition)
 
            intQClass = IntegerToUnsigned(Win32.Network.ntohs(shtTemp))
            '
            mvarQuestions.Add(strQName, CType(intQType, DnsTypeField), CType(intQClass, DnsClassField))
            '
        Next i  '--> For i = 1 To m_objHeader.QDCount
        '
        '## Parse the Answer,Authority, and Additional sections of the DNS message
        '
        Dim strRName As String
        Dim intRType As DnsTypeField
        Dim intRClass As Integer
        Dim dblRTTL As Double
        Dim intRDataLength As Integer
        Dim strRData As String
		Dim j As Short
        Dim intCount As Integer
        Dim arrData() As Byte
        Dim intAddress As Integer
        Dim intTemp As Integer
		Dim varData As Object = Nothing
        '
        mvarAnswers = Nothing
        mvarAnswers = New DnsResourceRecords()
        mvarAuthorities = Nothing
        mvarAuthorities = New DnsResourceRecords()
        mvarAdditionalInfos = Nothing
        mvarAdditionalInfos = New DnsResourceRecords()
        '
        'Move the stream pointer at the begining of the Answer section
        shtCurPosition = CShort(shtCurPosition + 2)
        '
        For j = 1 To 3
            '
            Select Case j
                Case 1 : intCount = m_objHeader.ANCount
                Case 2 : intCount = m_objHeader.NSCount
                Case 3 : intCount = m_objHeader.ARCount
            End Select
            '
            For i = 1 To intCount
                '
                'Get the NAME parameter
                strRName = GetLabelsByPosition(strStreamData, arrBuffer, shtCurPosition)
                '
                'Read the TYPE parameter
                shtTemp = MarshalBytesToShort(arrBuffer, shtCurPosition)
                intRType = CType(IntegerToUnsigned(Win32.Network.ntohs(shtTemp)), DnsTypeField)
                '
                'Move the pointer to read the CLASS parameter
                shtCurPosition = CShort(shtCurPosition + 2)
                '
                'Read the CLASS parameter
                shtTemp = MarshalBytesToShort(arrBuffer, shtCurPosition)
                intRClass = IntegerToUnsigned(Win32.Network.ntohs(shtTemp))
                '
                'Move the pointer to read the TTL parameter
                shtCurPosition = CShort(shtCurPosition + 2)
                '
                'Read the TTL parameter
                intTemp = MarshalBytesToInteger(arrBuffer, shtCurPosition)
                dblRTTL = LongToUnsigned(Win32.Network.ntohl(intTemp))
                '
                'Move the pointer to read the RDLENGTH parameter
                shtCurPosition = CShort(shtCurPosition + 4)
                '
                'Read the RDLENGTH parameter
                shtTemp = MarshalBytesToShort(arrBuffer, shtCurPosition)
                intRDataLength = IntegerToUnsigned(Win32.Network.ntohs(shtTemp))
                '
                'Move the pointer to read the RDATA parameter
                shtCurPosition = CShort(shtCurPosition + 2)
                '
                Select Case intRType
                    Case DnsTypeField.DNS_TYPE_A
                        'IP address
                        intAddress = MarshalBytesToInteger(arrBuffer, shtCurPosition)
                        Dim pointer As IntPtr = New IntPtr(Win32.Network.inet_ntoa(intAddress))
                        strRData = Marshal.PtrToStringAnsi(pointer)    'StringFromPointer(inet_ntoa(lngAddress))
                        varData = strRData
                        shtCurPosition = CShort(shtCurPosition + 4)
                    Case DnsTypeField.DNS_TYPE_CNAME, DnsTypeField.DNS_TYPE_NS, DnsTypeField.DNS_TYPE_MB, DnsTypeField.DNS_TYPE_MG, DnsTypeField.DNS_TYPE_MR, DnsTypeField.DNS_TYPE_PTR
                        'Domain name
                        strRData = GetLabelsByPosition(strStreamData, arrBuffer, shtCurPosition)
                        varData = strRData
                        '
                    Case DnsTypeField.DNS_TYPE_MX
                        '
                        Dim objMxData As DnsMxData
                        objMxData = New DnsMxData()
                        '
                        arrData = arrStreamData
                        '
                        If objMxData.CreateFromStream(arrData, shtCurPosition) Then
                            varData = objMxData
                        End If
                        '
                    Case DnsTypeField.DNS_TYPE_SOA
                        '
                        Dim objSoaData As DnsSoaData
                        objSoaData = New DnsSoaData()
                        '
                        If objSoaData.CreateFromStream(arrBuffer, shtCurPosition) Then
                            varData = objSoaData
                        End If
                        '
                End Select
 
                Select Case j
                    Case 1
                        mvarAnswers.Add(strRName, intRType, intRClass, dblRTTL, intRDataLength, varData)
                    Case 2
                        mvarAuthorities.Add(strRName, intRType, intRClass, dblRTTL, intRDataLength, varData)
                    Case 3
                        mvarAdditionalInfos.Add(strRName, intRType, intRClass, dblRTTL, intRDataLength, varData)
                End Select
                '
            Next i
            '
        Next j
        '
        Return True
    End Function
[+][-]09/24/09 02:55 PM, ID: 25418408Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C# Programming Language, Microsoft Visual C#.Net, VB Objects
Sign Up Now!
Solution Provided By: mas_oz2003
Participating Experts: 3
Solution Grade: C
 
[+][-]09/24/09 06:41 PM, ID: 25419562Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/24/09 06:51 PM, ID: 25419593Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]09/24/09 08:52 PM, ID: 25419919Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]09/25/09 04:46 AM, ID: 25422013Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]09/25/09 06:40 AM, ID: 25422815Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/26/09 12:36 AM, ID: 25429103Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625