C#, Win CE 4.2, Write file, power loss - c#

I'm using C# & the compact framework on an embedded device to log data to a compact flash card. Because data integrity is of upper most importance, I'm wondering how to write the data to the flash disk. Will files get lost/damaged if power is lost during a write/flush or while the file is opened? What's the best way to do this?
By the way, the card uses FAT32 as file system if that's important.
greetings,
Korexio

If performance is not an issue, I personally would prefer to use the first method which is OPEN-WRITE-CLOSE. FAT32 is really vulnerable to data damage during write operation.

Related

Uploading video content whilst still recording

This is a bit of a weird question but, with the functionalities of C++, c# and objective C as we speak is there any possible way for video content to be uploaded whilst its recording. So as you record the video it would be being compressed and uploaded to a website.
Would this involve cutting the video into small parts as you record, hardly noticeable stops and starts during the recording?
If anyone knows if this is at all possible, please let me know.
Sorry for the odd question.
You've just asked for streaming media -- something that's been done for over a decade (and, if you overlook "television", something that's probably been underway in research settings for several decades).
Typically, the video recorder will feed the raw data through filters of some sort -- correct white balance, sharpen or soften the video, image stabilize, and then compress the raw data using a codec. Most codec designs will happily take a block of input, work on it, and then produce a block of encoded data ready for writing. Instead of writing to disk, you could "write" to a socket opened to a remote machine.
Or, if you're working with an API that only writes to disk, you could easily re-read the data off disk as it is being written and send the data to a remote site. You'd have to "follow" the writing using something like tail -f's magic ability to follow the file as it is written. (Heck, if you're just bodging something together for a one-off, I'd even recommend using tail -f as part of your system.)
It depends on if the application recording to disk is locking the file. My guess is that, unless you wrote the recording software, the application locks the file(or doesn't even create the real file) until it stops recording. If you are writing the recording software as well, then yes, you can do this. you would just use sychronized threads.

Most efficient data storage

I need to transform/convert/process TransXchange data dump to reduce the size of data as some of the xml files can be up to 400 MB. I have the following options:
Sqlite database
CSV files
Binary Serialization
?
What is the best method of reducing the file sizes so that they would be feasible for use in a Windows Phone 7 application?
EDIT: I am going to create journey planning application that will allow users to specify source and destination. The application will then present the available services. In down under we have spotty mobile broadband coverage therefore I am aiming to have offline application.
This analysis is superb for showing you the timing of serialisation: http://www.eugenedotnet.com/2010/12/windows-phone-7-serialization-comparison/
For size... It's quite easy to guess that binary is smaller than sqlite (or Sterling) which in turn is smaller than CSV
However, if you are looking at processing 400MB of data on the phone... then I'd say you are doing the wrong thing - farm the processing out to a server (to the cloud?) and just view the summary results on the phone - think "thin client".
(Off to wash my mouth out now after all those jargon words!)
The main question is what are you going to do with that data.
If you just need to store the data and files are fine then binary serialization + compression (zlib, lzo...) will work best.
CSV won't do you any good.. will probably occupy more than the XML.
Database (for example, Sqlite) is the most expensive it terms of storage but you can manage and search the data more easily.

Record and save audio in c# .net web application

Is there anyway that I can record sound from a microphone using c# .net
What is the best option if i have to save the audio online in terms of the file occupying storage space.
Any particular format that the file should be saved in for optimum output.
I think you have to use either a small flash application or a silverlight application to do the actual recording. Then you upload the file to your application using a web service or similar.
And mp3 is sort of a standard file format for sound on the web. So I'd go with that.
Have a look at these projects:
http://www.codeproject.com/KB/winsdk/SoundRecord.aspx
http://www.codeproject.com/Articles/67568/Creating-a-Sound-Recorder-in-C-and-Csharp.aspx
http://www.codeproject.com/KB/audio-video/cswavrec.aspx
What is the best option if i have to save the audio online in terms of the file occupying storage space.
May be real media (.rm).
Any particular format that the file should be saved in for optimum output.
Not sure but I think that depends on
your player.
You might also be interested in ffmpeg for converting the media and its c# wrapper library.

Secure Wiping of files in Compact Framework

Given the path of a string i want to wipe out the contents of a file. The natural way I thought (which maybe incorrect) was to open a FileStream to the file and write gibberish (random data perhaps taken from a RNGCryptoServiceProvider) to it. And then perhaps do this several times and then delete the file.
My problem is that while this may look logically correct, i read up on another blog that Windows might actually choose to write the file to a different place in the hard disk.
Is that the case in Windows Mobile? Will this actually be a problem? Does this writing to a different location in the hard disk apply to even flash based (SD etc) cards ?
I've not personally done this, but you will probably need to use the low-level FLASH driver IOCTLs to do this correctly.
http://msdn.microsoft.com/en-us/library/aa927166.aspx
I think IOCTL_FMD_RAW_WRITE_BLOCKS looks particularly useful.
-PaulH
Another possibility that may work would be to erase the file normally, then use the defragment APIs to wipe ALL of the freespace on your flash. Since you're wiping everything, it won't be necessary to know exactly where on the disk your file was. But, this will wear out your flash drive more quickly. The C# method is detailed in this blog post: http://blogs.msdn.com/b/jeffrey_wall/archive/2004/09/13/229137.aspx

Editing raw data of a FAT drive

I am trying to edit the raw data of a FAT drive (I think I found a solution for NTFS, but didn't work for FAT. I don't have anything with FAT, just all my devices are using it) with C# (the result should be a drive in a different format - my own format). I was able to read the raw data (was nice seeing the FAT from inside) from it using CreateFile and opening a stream using the IntPtr I got, but couldn't write to it.
I tried several computers, USB flash drives, SD cards, floppy disks - nothing.
If it isn't possible with C#, I can do it with another language and later call the function using DLLImport.
Thanks.
If you edit/modify the drive on the sector level it could be no longer be fully compatible.
The standard way is to make a big file to fill al the space and then operate on those sectors.
Since your goal is space FAT is actually not efficient. If you control both ends ( read/write) you can just cange sector 0 so that is is not recogninzed as an existing file system and then you can wirte your own sectors.
Windows would nag you at insertion that the drive is not formatted.

Categories

Resources