473,624 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom file DeSerialization and file access

Hi,

I have to read files generated by 3rd party application, these files are in
a propriotary format ( not generated using the .NET framework ), I want to
implement a custom DeSerializer to read the data in the file, I wonder is it
possible to read files in this manner ( e.g. custom implementation of the
ISerializable interface )? is this right way to extract data from the file?
OR should I rather 'manually' use the FileStream to read the desiered chunks
of data?

Another Issue, is there a C# equivalent to the unmanaged CreateFileMappi ng,
MapViewOfFile ??? accessing files in this manner dramatically impove
performance as the kernel is resposible for loading the data from the disk (
and not the application ) so less context switch are done between the
application layer and the kernel...

--
Nadav
http://www.ddevel.com
Nov 16 '05 #1
3 2456
Nadav,

While this certainly could be acheived using ISerializable, there is no
point in doing so. ISerializable's purpose is to implement custom
serialization - so that IFormatter (BinaryFormatte r for example), can call
the proper constructor and the proper GetObjectData - in your case you are
probably better off implementing the "deserializatio n" to .NET via a non
ISerializable or Serializable mechanism.

Secondly,

Kernel32.Dll->CreateFileMapp ing and
Kernel32.Dll->MapViewOfFil e ..

AFAIK donot have managed implementations .

But they can be easily used in C# like this --

[DllImport("kern el32.dll", SetLastError=tr ue)]
static extern IntPtr CreateFileMappi ng(IntPtr hFile,
IntPtr lpFileMappingAt tributes, PageProtection flProtect, uint
dwMaximumSizeHi gh,
uint dwMaximumSizeLo w, string lpName);

and

[DllImport("kern el32.dll")]
static extern IntPtr MapViewOfFile(I ntPtr hFileMappingObj ect, uint
dwDesiredAccess , uint dwFileOffsetHig h, uint dwFileOffsetLow ,
UIntPtr dwNumberOfBytes ToMap);

TTFN :-)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:F6******** *************** ***********@mic rosoft.com...
Hi,

I have to read files generated by 3rd party application, these files are
in
a propriotary format ( not generated using the .NET framework ), I want to
implement a custom DeSerializer to read the data in the file, I wonder is
it
possible to read files in this manner ( e.g. custom implementation of the
ISerializable interface )? is this right way to extract data from the
file?
OR should I rather 'manually' use the FileStream to read the desiered
chunks
of data?

Another Issue, is there a C# equivalent to the unmanaged
CreateFileMappi ng,
??? accessing files in this manner dramatically impove
performance as the kernel is resposible for loading the data from the disk
(
and not the application ) so less context switch are done between the
application layer and the kernel...

--
Nadav
http://www.ddevel.com

Nov 16 '05 #2
Sahil,

Thanks for you immediate responce, concerning the FileMapping issue, indeed
it is possible to use these APIs through DllImport BUT all access to the
mapped data would have to be done in an unsafe manner, therefor it is not
posibble to reffer to the mapped data directly as can be done in C++ ( by
pointers ), my guess is that usage of the file mapping API should be done
only in the unmanaged world....

Nadav.

"Sahil Malik" wrote:
Nadav,

While this certainly could be acheived using ISerializable, there is no
point in doing so. ISerializable's purpose is to implement custom
serialization - so that IFormatter (BinaryFormatte r for example), can call
the proper constructor and the proper GetObjectData - in your case you are
probably better off implementing the "deserializatio n" to .NET via a non
ISerializable or Serializable mechanism.

Secondly,

Kernel32.Dll->CreateFileMapp ing and
Kernel32.Dll->MapViewOfFil e ..

AFAIK donot have managed implementations .

But they can be easily used in C# like this --

[DllImport("kern el32.dll", SetLastError=tr ue)]
static extern IntPtr CreateFileMappi ng(IntPtr hFile,
IntPtr lpFileMappingAt tributes, PageProtection flProtect, uint
dwMaximumSizeHi gh,
uint dwMaximumSizeLo w, string lpName);

and

[DllImport("kern el32.dll")]
static extern IntPtr MapViewOfFile(I ntPtr hFileMappingObj ect, uint
dwDesiredAccess , uint dwFileOffsetHig h, uint dwFileOffsetLow ,
UIntPtr dwNumberOfBytes ToMap);

TTFN :-)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:F6******** *************** ***********@mic rosoft.com...
Hi,

I have to read files generated by 3rd party application, these files are
in
a propriotary format ( not generated using the .NET framework ), I want to
implement a custom DeSerializer to read the data in the file, I wonder is
it
possible to read files in this manner ( e.g. custom implementation of the
ISerializable interface )? is this right way to extract data from the
file?
OR should I rather 'manually' use the FileStream to read the desiered
chunks
of data?

Another Issue, is there a C# equivalent to the unmanaged
CreateFileMappi ng,
??? accessing files in this manner dramatically impove
performance as the kernel is resposible for loading the data from the disk
(
and not the application ) so less context switch are done between the
application layer and the kernel...

--
Nadav
http://www.ddevel.com


Nov 16 '05 #3
Nadav,

Good news. You can do pointer operations in C# using the unsafe keyword. I
am using Kernel32.dll->MoveMemory happily in a heavily used caching block I
wrote for a windows service that gets hit a few thousand times a second in
an enterprise block.

You have to compile this with the /unsafe option, but it works.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:ED******** *************** ***********@mic rosoft.com...
Sahil,

Thanks for you immediate responce, concerning the FileMapping issue,
indeed
it is possible to use these APIs through DllImport BUT all access to the
mapped data would have to be done in an unsafe manner, therefor it is not
posibble to reffer to the mapped data directly as can be done in C++ ( by
pointers ), my guess is that usage of the file mapping API should be done
only in the unmanaged world....

Nadav.

"Sahil Malik" wrote:
Nadav,

While this certainly could be acheived using ISerializable, there is no
point in doing so. ISerializable's purpose is to implement custom
serialization - so that IFormatter (BinaryFormatte r for example), can
call
the proper constructor and the proper GetObjectData - in your case you
are
probably better off implementing the "deserializatio n" to .NET via a non
ISerializable or Serializable mechanism.

Secondly,

Kernel32.Dll->CreateFileMapp ing and
Kernel32.Dll->MapViewOfFil e ..

AFAIK donot have managed implementations .

But they can be easily used in C# like this --

[DllImport("kern el32.dll", SetLastError=tr ue)]
static extern IntPtr CreateFileMappi ng(IntPtr hFile,
IntPtr lpFileMappingAt tributes, PageProtection flProtect, uint
dwMaximumSizeHi gh,
uint dwMaximumSizeLo w, string lpName);

and

[DllImport("kern el32.dll")]
static extern IntPtr MapViewOfFile(I ntPtr hFileMappingObj ect, uint
dwDesiredAccess , uint dwFileOffsetHig h, uint dwFileOffsetLow ,
UIntPtr dwNumberOfBytes ToMap);

TTFN :-)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:F6******** *************** ***********@mic rosoft.com...
> Hi,
>
> I have to read files generated by 3rd party application, these files
> are
> in
> a propriotary format ( not generated using the .NET framework ), I want
> to
> implement a custom DeSerializer to read the data in the file, I wonder
> is
> it
> possible to read files in this manner ( e.g. custom implementation of
> the
> ISerializable interface )? is this right way to extract data from the
> file?
> OR should I rather 'manually' use the FileStream to read the desiered
> chunks
> of data?
>
> Another Issue, is there a C# equivalent to the unmanaged
> CreateFileMappi ng,
> ??? accessing files in this manner dramatically impove
> performance as the kernel is resposible for loading the data from the
> disk
> (
> and not the application ) so less context switch are done between the
> application layer and the kernel...
>
> --
> Nadav
> http://www.ddevel.com


Nov 16 '05 #4

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

Similar topics

0
2333
by: psy000 | last post by:
Hi, I have a C# web service client that talks to a JAVA application sever. I use AXIS to generate the WSDL file, use wsdl.exe to generate proxy stub c# code. When I try to use c# client connect to application server, I did not get the result in the C# client side, I used a soap monitor to look at the SOAP messages that were exchanged, I can see server returned a correct SOAP message, but the C# client failed to deserialize the XML...
1
3422
by: Mark Overstreet | last post by:
Hi, I have several custom collections that inherit from System.Collections.Specialized.NameObjectCollectionBase and I want to serialize and deserialize with the XMLSerializer object. This works great but my problem is that when the deserialization occurs, it uses the default add method to add objects to the collection without adding the keys. My question is this. Is there any way to use the XMLSerializer object to deserialize and...
2
5083
by: Nadav | last post by:
Hi, Introduction: **************** I am trying to DeSerialize a file that was created by an unmanaged application by the binary formatter, to achieve that I am implementing the following ISerializable methods: 1. GetObjectData(SerializationInfo info, StreamingContext context) 2. constructor(SerializationInfo info, StreamingContext context)
6
1855
by: Whoever | last post by:
Here's what I have A custom collection: public class aUser { public string UserName { get {...} set {...} } public class UserList : System.Collection.CollectionBase { public void Add(aUser user) {...} public aUser this {...}
5
2529
by: Graham | last post by:
I have created a custom MembershipProvider called "LassieMembershipProvider" that derives from "MembershipProvider". This providor is located in a Businesslogic layer dll called "Enlighten.LinkMad.Businesslogic". In one of my frontend websites I use this type to authenticate a user who is trying to login. The following excerpt is from the web.config of the particular site showing the reference to the custom provider, allowing .Net to do...
2
2578
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a good while and I'm getting really frustrated now! My problem is this - my custom controls periodically disappear from my
4
2758
by: Marc Scheuner | last post by:
Folks, I have a text file which contains some XML. In its XML header, it claims to be of UTF-8 encoding - however, it's really not, it's a ANSI / Windows-1252 / ISO-8859-1 encoding. Trouble is: when I deserialize objects from that file, all the German umlauts and other special characters get dropped, some even cause deserialization errors.
3
2633
by: Zachary Turner | last post by:
Hello, I have a situation where I would like to perform custom serialization and deserialization of an existing .NET framework object (specifically, System.DateTime). Is there a common paradigm here, for how I can override the default behavior of DateTime serialization and provide my own? I want to use this custom serialized DateTime in many places, and don't want to provide custom serialization routines for every single object that...
4
6444
by: Val | last post by:
I have a complex object that I need to serialize. Rather than rely on a standard routine, which is called during the serialization/deserialization, I would like to be able to use my own functions that would convert this object into a string and would then write that string to a file. Upon deserialization, I need to be able to call another custom function to recreate the object. I have looked and both implementing the ISerializable...
0
8177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8488
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.