User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 4 Nov 2002, 15:10   #1
BuddhistPunk
Registered User
 
Join Date: Apr 2002
Location: Leeds, but looking for a way to escape
Posts: 128
BuddhistPunk is an unknown quantity at this point
C#, Byte Arrays & New Files

To cut a long story short, I have a byte array that I need to write as a file, how can this be done?

To lengthen a short story, I have a remoting client/server setup. The client gets a list of files from the server, if the files on the server and the client dont match the client requests the different files through a remoting tcpchannel (has to be this way, I cant open http channels etc), these files are returned from the server in a bytearray and this needs to be written to a file on the client (these file are not flat file text files, they are executables and dll's)

Thanks in advance
__________________
SELECT everything FROM everywhere WHERE something = something_else;
> 42
BuddhistPunk is offline   Reply With Quote
Unread 4 Nov 2002, 15:24   #2
hinch
Banned
 
Join Date: May 2000
Location: Abducted By Aliens
Posts: 282
hinch is an unknown quantity at this point
one bite array is complete stick it all into a variable to make it the one big file then do filesystemobject.save variable


i believe
havent yet got round to trying this in .net yet
hinch is offline   Reply With Quote
Unread 4 Nov 2002, 15:34   #3
BuddhistPunk
Registered User
 
Join Date: Apr 2002
Location: Leeds, but looking for a way to escape
Posts: 128
BuddhistPunk is an unknown quantity at this point
Unfortunaltly it seems that c# doesnt have that class.

I am using the following line of code to get the byte array back

byte[] incomingfile = call_RemoteObject.GetFile(key, inf.lngSize);

so "incomingfile" is my byte array that I need to write to an exe/dll
__________________
SELECT everything FROM everywhere WHERE something = something_else;
> 42
BuddhistPunk is offline   Reply With Quote
Unread 4 Nov 2002, 16:56   #4
BuddhistPunk
Registered User
 
Join Date: Apr 2002
Location: Leeds, but looking for a way to escape
Posts: 128
BuddhistPunk is an unknown quantity at this point
I seemed to have solved the problem described above, by using the following code (just incase anybody is interested) :

Code:
string strFullPath = "C:\\temp\\loader\\clientfiles\\" + strFileName;
BinaryWriter bwriter = new BinaryWriter(new FileStream(strFullPath, FileMode.Create, FileAccess.ReadWrite));
bwriter.Write(incomingfile); //incomingfile is the byte[]
bwriter.Close();
But this has now led into another problem, I use the FileInfo/GetFileSystemInfos/DirectoryInfo classes to pull back information on the server/client files (things like, file size, extension, version etc), the problem I have is that when I come to create the byte stream my program fails as it sees the server file in use - now this "use" seems to be/is caused by the server application and I can only assume is becuase fileinfo is holding the file open.

Does anybody have any suggestions, there doesnt seem to be any functionality to close/finalize the fileinfo requests
__________________
SELECT everything FROM everywhere WHERE something = something_else;
> 42
BuddhistPunk is offline   Reply With Quote
Unread 4 Nov 2002, 17:10   #5
hinch
Banned
 
Join Date: May 2000
Location: Abducted By Aliens
Posts: 282
hinch is an unknown quantity at this point
once you do a binary read you cannot request any further info from teh client.

perhaps have the client pull back info first store it in vars then do the binary read
hinch is offline   Reply With Quote
Unread 4 Nov 2002, 18:00   #6
BuddhistPunk
Registered User
 
Join Date: Apr 2002
Location: Leeds, but looking for a way to escape
Posts: 128
BuddhistPunk is an unknown quantity at this point
This is the logic I am following, which seems to be more or less what you describe.

When the patcher application starts this is what happens :

- A remote connection opened to server.
- A Sortedlist of serverfiles returned to the client(contains filename, version, bytes).
- The client creates a sortedlist of its own files.
- The client compares the client and server lists, compiling a third list with differences.
- if there are differences the client makes a request to server for that file.
- File is returned in a byte array **
- Byte array written back to client

** this is where the process fails with the following error :

Code:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: The process cannot access the file "C:\temp\ecalloader\server\TestApplication2.exe" because it is being used by another process.
TestApplication2.exe is the file I want to return, this error is generated when the server application attempts to create the byte array - the only other time the server accessed this file is when it pulled back its attributes etc etc etc - so i "assuming" that is has something to do with that.
__________________
SELECT everything FROM everywhere WHERE something = something_else;
> 42
BuddhistPunk is offline   Reply With Quote
Unread 4 Nov 2002, 18:46   #7
W
Gubbish
 
Join Date: Sep 2000
Location: #FoW
Posts: 2,323
W is a jewel in the roughW is a jewel in the roughW is a jewel in the rough
*sings* Blame Canada!


err, I mean, blame MicroSoft!
__________________
Gubble gubble gubble gubble
W is offline   Reply With Quote
Unread 5 Nov 2002, 02:03   #8
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
Re: C#, Byte Arrays & New Files

Quote:
Originally posted by BuddhistPunk
...has to be this way, I cant open http channels etc.
Why can you open arbitary TCP connections, but not an HTTP connection (which is after all, typically done over TCP), or has information been left out.
__________________
Chimney Pots.
Raging.Retard is offline   Reply With Quote
Unread 5 Nov 2002, 02:09   #9
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
Quote:
Originally posted by BuddhistPunk
I can only assume is becuase fileinfo is holding the file open.

Does anybody have any suggestions, there doesnt seem to be any functionality to close/finalize the fileinfo requests
I can tell you that System.IO.FileInfo does not lock the file to read the information you want, and thus that is most likely not your problem. Ive not tested this though. You could manually generate your file list (so its not being read by FileInfo) then pass that back to test your code.

From what I can see, this looks like some kind of file syncronisation tool? In which case there are actually helper classes iirc for file copying.
__________________
Chimney Pots.

Last edited by Raging.Retard; 5 Nov 2002 at 02:14.
Raging.Retard is offline   Reply With Quote
Unread 5 Nov 2002, 10:59   #10
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
rsync!
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 5 Nov 2002, 11:40   #11
BuddhistPunk
Registered User
 
Join Date: Apr 2002
Location: Leeds, but looking for a way to escape
Posts: 128
BuddhistPunk is an unknown quantity at this point
I know, but it sort of takes the fun out of writing your own, this is my mini "learn C#" project. And to be honest I quite like it.

Now this is getting weird, as somebody suggested (in a round about sort of way) I got my client to request a file that the fileinfo routines hadnt touch - surprisingly enough it worked fine, and transferred through the remoting channel.

I am 101% certain that the only time the server application touches these files is to create the fileinfo, hmmm

re http channels, yes I did leave information out, this application will be run on my companies internal network, we as most other companies have nazi network admin, and they dont like http traffic - I stopped asking why a long time ago
__________________
SELECT everything FROM everywhere WHERE something = something_else;
> 42
BuddhistPunk is offline   Reply With Quote
Unread 5 Nov 2002, 12:23   #12
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
You arent running the server and the client on the same box for testing are you?
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 5 Nov 2002, 13:06   #13
hinch
Banned
 
Join Date: May 2000
Location: Abducted By Aliens
Posts: 282
hinch is an unknown quantity at this point
Quote:
Originally posted by BuddhistPunk
re http channels, yes I did leave information out, this application will be run on my companies internal network, we as most other companies have nazi network admin, and they dont like http traffic - I stopped asking why a long time ago

you dont happen to be making a msn/icq style application do you? or perhaps a mini p2p network.

you could try using the dcc protocol though
hinch is offline   Reply With Quote
Unread 5 Nov 2002, 14:13   #14
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
Quote:
Originally posted by hinchles



you dont happen to be making a msn/icq style application do you? or perhaps a mini p2p network.

you could try using the dcc protocol though
You get my email?
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 5 Nov 2002, 14:24   #15
hinch
Banned
 
Join Date: May 2000
Location: Abducted By Aliens
Posts: 282
hinch is an unknown quantity at this point
Quote:
Originally posted by MT


You get my email?
yus tried to get you on irc last night but you were dead0r

wanted to know if you had anyclues as to what caused it.

what happened was my connection dropped for 2 days and after about 12 hours of it being down the server stopped working

i tried a manual daemon restart and failed so i tried a boot see if the init scripts would get it incase i forgot something

nope still not working

then i tried to get hold of you.

sounded like a big mess.

now my only problems is i cant find my hammer to beat the **** out of the machien with due to apache and proftpd still being ****e
hinch is offline   Reply With Quote
Unread 5 Nov 2002, 14:34   #16
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
Oh.

Well cyrus-imapd, postfix and mysql are running smoothly.

I didnt notice a problem with apache, but I'll have a look tomorrow (sorry, out tonight + labs this avvo).
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 5 Nov 2002, 14:45   #17
hinch
Banned
 
Join Date: May 2000
Location: Abducted By Aliens
Posts: 282
hinch is an unknown quantity at this point
no probs apache is actually running its just ignoreing its config file 8o)
hinch is offline   Reply With Quote
Unread 5 Nov 2002, 23:47   #18
BuddhistPunk
Registered User
 
Join Date: Apr 2002
Location: Leeds, but looking for a way to escape
Posts: 128
BuddhistPunk is an unknown quantity at this point
Quote:
Originally posted by hinchles



you dont happen to be making a msn/icq style application do you? or perhaps a mini p2p network.

you could try using the dcc protocol though
The application I am producing is a patching/loading system for an various inhouse applications, essentially the end luser runs the application which checks for updates on a central server, gets any updates if needed, and then runs the application. Becuase my boss got brainwashed at a Microsoft conference (more on this below) we are doing this in C# which is new to me and the rest of the R&D department, anyways i am going of on a tangent.

So I have got it working now, the problem was obviously my mistake, but its a weird one, if you want to know what the problem was then read on :

C# supports assembly versioning, i.e. you can set a version (and other information) for an entire project, and that assembly information will encompass everything within the same namespace - the mistake I made was that the test applications I was using for testing the patching process were small .NET applications thrown together in the same project (i.e. the same namespace), so as far as .NET was concerned the version information was the same even tho "technically" it wasnt. The reason that it was crashing on generating the byte array was that .NET (and me) was getting confused becuase I was requesting an update for a file that as far as it was concerned didnt need one as the versions matched.

Did that make sense?

And back to the Boss, this PROOVES that microsoft is evil, my Boss has always been a *nix evangelist, MS is the root of evil, MS products are bloated blah blah blah blah blah, anyways about 5 months ago he went to an MS .NET conference in Barcelona and since then his has done a full U-turn and everything is now MS - we think he has been brainwashed or had some sort of MS borg implant - he has even formatted his Linux laptop and put Win XP on it!!!!!!!
__________________
SELECT everything FROM everywhere WHERE something = something_else;
> 42
BuddhistPunk is offline   Reply With Quote
Unread 5 Nov 2002, 23:57   #19
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
C# is pretty shaggable tho.
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 6 Nov 2002, 11:11   #20
hinch
Banned
 
Join Date: May 2000
Location: Abducted By Aliens
Posts: 282
hinch is an unknown quantity at this point
Quote:
Originally posted by BuddhistPunk

Did that make sense?

And back to the Boss, this PROOVES that microsoft is evil, my Boss has always been a *nix evangelist, MS is the root of evil, MS products are bloated blah blah blah blah blah, anyways about 5 months ago he went to an MS .NET conference in Barcelona and since then his has done a full U-turn and everything is now MS - we think he has been brainwashed or had some sort of MS borg implant - he has even formatted his Linux laptop and put Win XP on it!!!!!!!

i went to the same conference its held every 6 months one in Barcelona and one in San Francisco.

but then im an MS evangelist (if you cant beat them join them)
hinch is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 04:34.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018