473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Serialize class with hashtable

Hello,

I'm trying to serialize a class with a Hashtable within:

' Class code:
Imports System.Collections
Class clsOptions
Public countID As Integer
Public persons As New Hashtable
End Class

'Main app code:
Dim serializer As XmlSerializer = New XmlSerializer(GetType(clsOptions))
This doesn't work.
I've read something in the helpfiles that I have to add a count property and
add method, because Hashtable implements IList.
But I have no clue what is needed.
Nov 21 '05 #1
5 2671
"Dick" <Di**@nospam.com> wrote in message news:<eG**************@TK2MSFTNGP10.phx.gbl>...
Hello,

I'm trying to serialize a class with a Hashtable within:

' Class code:
Imports System.Collections
Class clsOptions
Public countID As Integer
Public persons As New Hashtable
End Class

'Main app code:
Dim serializer As XmlSerializer = New XmlSerializer(GetType(clsOptions))
This doesn't work.
I've read something in the helpfiles that I have to add a count property and
add method, because Hashtable implements IList.
But I have no clue what is needed.
You must put atribuite before class declaration
<Serializable()> Class clsOptions private countID As Integer
private persons As Hashtable public sub new
persons =new Hashtable

end sub End Class

Nov 21 '05 #2
Thanks a lot!
I will try it.

"Oldkrot" <ol*******@hotmail.com> wrote in message
news:3c**************************@posting.google.c om...
"Dick" <Di**@nospam.com> wrote in message

news:<eG**************@TK2MSFTNGP10.phx.gbl>...
Hello,

I'm trying to serialize a class with a Hashtable within:

' Class code:
Imports System.Collections
Class clsOptions
Public countID As Integer
Public persons As New Hashtable
End Class

'Main app code:
Dim serializer As XmlSerializer = New XmlSerializer(GetType(clsOptions))
This doesn't work.
I've read something in the helpfiles that I have to add a count property and add method, because Hashtable implements IList.
But I have no clue what is needed.


You must put atribuite before class declaration
<Serializable()> Class clsOptions
private countID As Integer
private persons As Hashtable

public sub new
persons =new Hashtable

end sub
End Class

Nov 21 '05 #3
It din't work like that.

Find a solution though:
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

"Oldkrot" <ol*******@hotmail.com> wrote in message
news:3c**************************@posting.google.c om...
"Dick" <Di**@nospam.com> wrote in message

news:<eG**************@TK2MSFTNGP10.phx.gbl>...
Hello,

I'm trying to serialize a class with a Hashtable within:

' Class code:
Imports System.Collections
Class clsOptions
Public countID As Integer
Public persons As New Hashtable
End Class

'Main app code:
Dim serializer As XmlSerializer = New XmlSerializer(GetType(clsOptions))
This doesn't work.
I've read something in the helpfiles that I have to add a count property and add method, because Hashtable implements IList.
But I have no clue what is needed.


You must put atribuite before class declaration
<Serializable()> Class clsOptions
private countID As Integer
private persons As Hashtable

public sub new
persons =new Hashtable

end sub
End Class

Nov 21 '05 #4


serialization functions
Imports System.IO
Imports System

''' <summary>
''' this class in charge of all operations with reaction <database>
''' </summary>
Public Class clsDataServices

''' <summary>
''' load relation data from HD
''' </summary>
Private Function LoadRelationData() As PluginsRelation
Dim data As PluginsRelation
Dim fs As FileStream
Try
fs = New FileStream(relationPath, FileMode.Open)
Dim bf As New
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter
data = CType(bf.Deserialize(fs), PluginsRelation)
WriteToMonitor.writeDebugModeLine("Successful", "Load relation
data", System.Drawing.Color.Magenta)
Catch ex As Exception
WriteToMonitor.writeDebugModeLine("Error during load relation
data", ex.Message, System.Drawing.Color.Red)
Finally
Try
fs.Close()
Catch ex1 As Exception
End Try
End Try
Return data
End Function

''' <summary>
''' save operation for relation data
''' </summary>
''' <param name="data"></param>
Private Function SaveRelationData(ByVal data As PluginsRelation) As
Boolean
Dim result As Boolean = False
Dim fs As FileStream
Try
fs = New FileStream(relationPath, FileMode.OpenOrCreate)
Dim bf As New
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter
bf.Serialize(fs, data)
WriteToMonitor.writeDebugModeLine("Successful", "Save relation
data", System.Drawing.Color.Magenta)
result = True
Catch ex As Exception
WriteToMonitor.writeDebugModeLine("Error during save relation
data", ex.Message, System.Drawing.Color.Red)
Finally
Try
fs.Close()
Catch ex1 As Exception
End Try
End Try
Return result
End Function
end class
************************************************** ****
Class for serialization,it's work this is code from my application

' ----------------------------------------------------
' Created on: 05/04/2003
' Created by: Gregory
'
' Name: SidCamera
' Version: 1.00
' Description:Get all inform about relationship between sidname ->
camera number
'per ptz model
' ----------------------------------------------------
' Edited last on:
' Edited last by:
'
' Added/Changed:
' 1. ??????
' 2. ??????
' 3. ??????
' ----------------------------------------------------
<Serializable()> Public Class PluginsRelation
Private objPtzModelRelationHash As Hashtable
Public Sub New()
objPtzModelRelationHash = New Hashtable
End Sub
Public Property PluginRelationsData(ByVal plugin As
Constant.Enum.ePTZModel) As cameraRelation
Get
Return objPtzModelRelationHash.Item(plugin)
End Get
Set(ByVal Value As cameraRelation)
objPtzModelRelationHash.Item(plugin) = Value
End Set
End Property

Public Property PluginsData() As Hashtable
Get
Return objPtzModelRelationHash
End Get
Set(ByVal Value As Hashtable)
objPtzModelRelationHash = Value
End Set
End Property
End Class

<Serializable()> Public Class cameraRelation
Private objSidNameToSidIndexHash As Hashtable
Private objCamerasArray As clsCamera()
Private pluginID As Constant.Enum.ePTZModel

Public Property Plugin() As Constant.Enum.ePTZModel
Get
Return pluginID
End Get
Set(ByVal Value As Constant.Enum.ePTZModel)
pluginID = Value
End Set
End Property
Public Sub New(ByVal count As Integer)
objSidNameToSidIndexHash = Hashtable.Synchronized(New Hashtable)
ReDim objCamerasArray(count - 1)
End Sub
'************************************************* ******************
' created by: Gregory
'input camera number, sidname
' adding camera to hashtable for building relationship between
' sid -> physical camera number
' History:
' 1.
' 2.
'************************************************* *******************

Public Overloads Sub AddCamera(ByVal Sid As String, ByVal
cameraNumber As Int32)
Try
Dim index As Integer
Dim camera As clsCamera
Try
If objSidNameToSidIndexHash.ContainsKey(Sid) Then
index = objSidNameToSidIndexHash.Item(Sid)
camera = New clsCamera
With camera
.Camera = cameraNumber
.Index = index
.Name = Sid
End With
objCamerasArray(index) = camera
End If
Catch ex As Exception

End Try
Catch ex As Exception
ExceptionManagement.ExceptionManager.Publish(ex)
End Try
End Sub

Public Overloads Sub AddCamera(ByVal SidName As String, ByVal
sidIndex As Integer, ByVal cameraNumber As Int32)
Try
Dim index As Integer
Dim camera As clsCamera
Try
If objSidNameToSidIndexHash.ContainsKey(SidName) Then
camera = New clsCamera
With camera
.Camera = cameraNumber
.Index = sidIndex
.Name = SidName
End With
objCamerasArray(sidIndex) = camera
objSidNameToSidIndexHash.Item(SidName) = sidIndex
End If
Catch ex As Exception

End Try
Catch ex As Exception
ExceptionManagement.ExceptionManager.Publish(ex)
End Try
End Sub

Public Sub RemoveCamera(ByVal SidName As String)
Try
Dim index As Integer
Try
If objSidNameToSidIndexHash.ContainsKey(SidName) Then
index = objSidNameToSidIndexHash.Item(SidName)
objCamerasArray(index) = Nothing
End If
Catch ex As Exception
End Try
Catch ex As Exception
ExceptionManagement.ExceptionManager.Publish(ex)
End Try
End Sub

'************************************************* ******************
' created by: Gregory
'sid object
' getting physical camera from hashtable
' sid -> physical camera number
' History:
' 1.
' 2.
'************************************************* *******************
Public Overloads Function getCameraNumber(ByVal sid As Integer) As
Integer
Dim cameraNumber As Integer = -1
Dim camera As clsCamera
Try
camera = objCamerasArray(sid)
If Not camera Is Nothing Then
cameraNumber = camera.Camera
End If
Catch ex As Exception
ExceptionManagement.ExceptionManager.Publish(ex)
End Try
Return cameraNumber
End Function

Public Overloads Function getCameraNumber(ByVal sid As String) As
Integer
Dim cameraNumber = -1, index As Integer
Dim camera As clsCamera
Try
If objSidNameToSidIndexHash.ContainsKey(sid) Then
index = objSidNameToSidIndexHash.Item(sid)
camera = objCamerasArray(index)
If Not camera Is Nothing Then
cameraNumber = camera.Camera
End If
End If
Catch ex As Exception
ExceptionManagement.ExceptionManager.Publish(ex)
End Try
Return cameraNumber
End Function

Public Property SidNameToSidIndex() As Hashtable
Get
Return objSidNameToSidIndexHash
End Get
Set(ByVal Value As Hashtable)
objSidNameToSidIndexHash = Value
End Set
End Property

Public Property getCameras() As clsCamera()
Get
Return objCamerasArray
End Get
Set(ByVal Value As clsCamera())
objCamerasArray = Value
End Set
End Property
End Class

<Serializable()> Public Class clsCamera
Private sidIndex As Integer
Private cameraNumber As Integer
Private cameraName As String

Public Sub New()
End Sub
Public Property Index() As Integer
Get
Return sidIndex
End Get
Set(ByVal Value As Integer)
sidIndex = Value
End Set
End Property

Public Property Camera() As Integer
Get
Return cameraNumber
End Get
Set(ByVal Value As Integer)
cameraNumber = Value
End Set
End Property

Public Property Name() As String
Get
Return cameraName
End Get
Set(ByVal Value As String)
cameraName = Value
End Set
End Property
End Class

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
And this variant use xml serialization
Private Function SaveRelationData(ByVal data As PluginsRelation) As
Boolean
Dim result As Boolean = False
Dim fs As FileStream
Try
fs = New FileStream(relationPath, FileMode.OpenOrCreate)
'Dim bf As New
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter
Dim bf As New
System.Runtime.Serialization.Formatters.Soap.SoapF ormatter
bf.Serialize(fs, data)
WriteToMonitor.writeDebugModeLine("Successful", "Save relation
data", System.Drawing.Color.Magenta)
result = True
Catch ex As Exception
WriteToMonitor.writeDebugModeLine("Error during save relation
data", ex.Message, System.Drawing.Color.Red)
Finally
Try
fs.Close()
Catch ex1 As Exception
End Try
End Try
Return result
End Function

Reagards OldKrot

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
0
by: Arjen | last post by:
Hello, I have made a little test application and needs some help. I have two classes with hash tables which I want to serialize inside one xml file. My question is if someone can make the...
0
by: Arjen | last post by:
Hello, I have made a little test application and needs some help. I have two classes with hash tables which I want to serialize inside one xml file. My question is if someone can make the...
2
by: Diego F. | last post by:
I need to serialize a hash table in a file (xml or other), but I'm new with all this and I don't know how to serialize. Can you put me a piece of code to do this? Regards, Diego F.
2
by: MichiSu11 | last post by:
I want to serialize the properties of controls. I write Property Name and Value to an Hashtable. This hashtable is serialized. So I want to find out which properties of the control are serializable....
1
by: Bill L | last post by:
Hi guys, Because of restarting application after new DLLs installed into \Bin folder , we move the session to StateServer, everything'a alright except when I try to write any simple hash table...
1
by: Raed Sawalha | last post by:
we have already built Web Application,we did changes on in class in application so , we need to pass a Hashtable object to a webserivce, we're using XML Serialization , my problem in how to...
7
by: Ben Amada | last post by:
I've created a class that I need to store in ViewState. However when I try to store it in ViewState, I get the following error: "The type 'solution.pe2' must be marked as Serializable or have a...
6
by: Joe | last post by:
Hello All, I want to serialize a hashtable to a database table to persist its values between postbacks. The client requires that I not use ViewState, hence the database. The samples in MSDN...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.