[mapguide-users] ByteReader Problem
Kenneth, GEOGRAF A/S
ks at geograf.dk
Mon Sep 3 07:47:48 EDT 2007
Very odd.
I have been using this code to read data from the server:
XmlDocument doc = new XmlDocument();
{
MgByteReader rd = rs.GetResourceContent(new
MgResourceIdentifier(webLayout));
using(System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
byte[] buf = new byte[1024];
int c = 0;
do
{
c = rd.Read(buf, buf.Length);
ms.Write(buf, 0, c);
} while (c != 0);
ms.Position = 0;
doc.Load(ms);
}
}
It worked the last time I used it, but that was a while ago (around 1.2
beta 1, I think).
Regards, Kenneth, GEOGRAF A/S
Campbell, Keith A skrev:
> Kenneth,
>
> If I run this code, it results in an endless loop because the
> read = mapByteRdr.Read(buf, buf.length);
> call reads the same data each time - the start point for each read is
> not advanced.
>
> Keith
>
> ------------------------------------------------------------------------
> *From:* mapguide-users-bounces at lists.osgeo.org
> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of
> *Kenneth, GEOGRAF A/S
> *Sent:* 31 August 2007 17:14
> *To:* MapGuide Users Mail List
> *Subject:* Re: [mapguide-users] ByteReader Problem
>
> The only way around it, that I have found, is to copy/paste code like
> this:
>
> System.IO.MemoryStream ms = new System.IO.MemoryStream();
> byte[] buf = new byte[8*1024];
> int read = 1;
> while(read != 0)
> {
> read = mapByteRdr.Read(buf, buf.length);
> ms.Write(buf, 0, read);
> }
>
> //ms now contains the stream
>
> Regards, Kenneth, GEOGRAF A/S
>
>
>
> Campbell, Keith A skrev:
>> Thanks Dennis.
>>
>> I've tried this, but I'm only getting 8192 bytes read into the byte
>> buffer. This seems to be the problem mentioned by Kenneth. The Read
>> method doesn't seem to allow the start location for the read to be
>> set, so looping until the entire content of the Resource is read into
>> the buffer doesn't seem to be an option.
>>
>> Presumably somebody must have found a way around this.
>>
>> Keith
>>
>> ------------------------------------------------------------------------
>> *From:* mapguide-users-bounces at lists.osgeo.org
>> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Jonio,
>> Dennis (Aviation)
>> *Sent:* 31 August 2007 14:05
>> *To:* MapGuide Users Mail List
>> *Subject:* RE: [mapguide-users] ByteReader Problem
>>
>> ... this sequence tends to work
>>
>>
>>
>> // For some reason the MgByteReader "disappears"
>>
>> // This seems to work ....
>>
>> long long_length = rs.GetResourceContent(resId).GetLength();
>>
>> byte[] byteBuffer = new byte[long_length];
>>
>> int numBytes =
>> rs.GetResourceContent(resId).Read(byteBuffer, (int)long_length);
>>
>>
>>
>> -----Original Message-----
>> *From:* mapguide-users-bounces at lists.osgeo.org
>> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of
>> *Campbell, Keith A
>> *Sent:* Friday, August 31, 2007 7:10 AM
>> *To:* MapGuide Users Mail List
>> *Subject:* [mapguide-users] ByteReader Problem
>>
>>
>>
>> I am trying to alter a map definition through the API and cannot get
>> the contents of the MgByteReader in string format. Here's the code:-
>>
>> String mapDefinition = "Library://My Folder/Maps/My
>> Map.MapDefinition";
>> MgResourceIdentifier MapResID = new
>> MgResourceIdentifier(mapDefinition);
>>
>> MgByteReader mapByteRdr =
>> res.GetResourceContent(MapResID);//res is instantiated Resource Service.
>>
>> XmlDocument doc = new XmlDocument();
>>
>> doc.LoadXml(mapByteRdr.ToString());
>>
>> LoadXML fails with an error ' Root element is missing'. I can copy
>> the contents of mapByteRdr from Visual Studio at runtime and it
>> contains properly formatted XML for the map definition. If I use the
>> ToFile() method, the resultant file is empty. I cannot see why these
>> two methods do not return the xml string in the reader. Any help is
>> welcome.
>>
>> Cheers,
>>
>> Keith
>>
>>
>>
>> *This email and any attached files are confidential and copyright
>> protected. If you are not the addressee, any dissemination of this
>> communication is strictly prohibited. Unless otherwise expressly
>> agreed in writing, nothing stated in this communication shall be
>> legally binding.*
>>
>> The ultimate parent company of the Atkins Group is WS Atkins plc.
>> Registered in England No. 1885586. Registered Office Woodcote Grove,
>> Ashley Road, Epsom, Surrey KT18 5BW.
>>
>> P *Consider the environment. Please don't print this e-mail unless
>> you really need to.*
>>
>> ------------------------------------------------------------------------
>>
>> E-mails are automatically scanned for viruses using McAfee.
>>
>>
>>
>> This message has been scanned for viruses by MailControl
>> <http://bluepages.wsatkins.co.uk/?6875772>
>>
>>
>>
>> *This email and any attached files are confidential and copyright
>> protected. If you are not the addressee, any dissemination of this
>> communication is strictly prohibited. Unless otherwise expressly
>> agreed in writing, nothing stated in this communication shall be
>> legally binding.*
>>
>> The ultimate parent company of the Atkins Group is WS Atkins plc.
>> Registered in England No. 1885586. Registered Office Woodcote Grove,
>> Ashley Road, Epsom, Surrey KT18 5BW.
>>
>> P *Consider the environment. Please don't print this e-mail unless
>> you really need to.*
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> mapguide-users mailing list
>> mapguide-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>
> ------------------------------------------------------------------------
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20070903/5730103a/attachment.html
More information about the mapguide-users
mailing list