{
[Serializable()]
{
public bool Status
; // Trang thai kenh tat hay bat [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2500)]
{
IdChannel = "ch1";
Infor = " ";
Pos = 0.0;
for (int i
= 0; i
< 2500; i
++) data
[i
] = 0; }
//construction with copy data
public OscChannel
(OscChannel channel
) {
Status = channel.Status;
IdChannel = channel.IdChannel;
Infor = channel.Infor;
Pos = channel.Pos;
for (int i
= 0; i
< 2500; i
++) data
[i
] = channel
.data[i
]; }
{
IdChannel = id;
Infor = info;
Pos = 0.0;
for (int i
= 0; i
< 2500; i
++) data
[i
] = 0; }
// Deserialize
public OscChannel
(SerializationInfo info, StreamingContext ctxt
) {
}
// Get object data
public void GetObjectData
(SerializationInfo info, StreamingContext ctxt
) {
//You can use any custom name for your name-value pair. But make sure you
// read the values with the same name.
info.AddValue("status", Status);
info.AddValue("idchannel", IdChannel);
info.AddValue("channelInfor", Infor);
info.AddValue("position", Pos);
info.AddValue("data", data);
}
}
[Serializable()]
{
//Construction
{
SysInfo = "";
chanel1
= new OscChannel
("ch1",
""); chanel2
= new OscChannel
("ch2",
""); chanel3
= new OscChannel
("ch3",
""); chanel4
= new OscChannel
("ch4",
""); }
//construction with copy data
{
SysInfo = input.SysInfo;
chanel1
= new OscChannel
(input
.chanel1); chanel2
= new OscChannel
(input
.chanel2); chanel3
= new OscChannel
(input
.chanel3); chanel4
= new OscChannel
(input
.chanel4); }
// Deserialize
public Oscillo
(SerializationInfo info, StreamingContext ctxt
) {
chanel1
= (OscChannel
)info
.GetValue("channel1",
typeof(OscChannel
)); chanel2
= (OscChannel
)info
.GetValue("channel2",
typeof(OscChannel
)); chanel3
= (OscChannel
)info
.GetValue("channel3",
typeof(OscChannel
)); chanel4
= (OscChannel
)info
.GetValue("channel4",
typeof(OscChannel
)); }
public void GetObjectData
(SerializationInfo info, StreamingContext ctxt
) {
info.AddValue("sysInfo", SysInfo);
info.AddValue("channel1", chanel1);
info.AddValue("channel2", chanel2);
info.AddValue("channel3", chanel3);
info.AddValue("channel4", chanel4);
}
}
{
//Oscillo oscillo;
{
//oscillo = new Oscillo();
}
// Serialization oscillo object
{
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bformatter
= new BinaryFormatter
(); bformatter.Serialize(stream, os);
stream.Close();
}
// Deserialization oscillo object
{
Oscillo os
= new Oscillo
(); Stream stream = File.Open(filename, FileMode.Open);
BinaryFormatter bformatter
= new BinaryFormatter
(); bformatter
.Binder = new Verbinder
(); // Dong nay quan trong // Neu dung voi WinForm thi khong can
// Khi project dang Control library thi can ^_^
os = (Oscillo)bformatter.Deserialize(stream);
stream.Close();
}
}
// Tao Binder cho Binaryformatter
// Search in MSDN online (^_^)
{
{
Type typeToDeserialize
= null;
// For each assemblyName/typeName that you want to deserialize to
// a different type, set typeToDeserialize to the desired type.
String assemVer1
= "";// Assembly.GetExecutingAssembly().FullName; String typeVer1
= "Version1Type";
if (assemblyName
== assemVer1
&& typeName
== typeVer1
) {
// To use a type from a different assembly version,
// change the version number.
// To do this, uncomment the following line of code.
// assemblyName = assemblyName.Replace("1.0.0.0", "2.0.0.0");
// To use a different type from the same assembly,
// change the type name.
typeName = "Version2Type";
}
// The following line of code returns the type.
typeToDeserialize
= Type
.GetType(String.Format("{0}, {1}",
typeName, assemblyName));
}
}
}