Hi David :

Thank you for your quick reply, I have read your VB code but I have not try
it..
Actually, my job is to develop an application for user interacting with the
ajax viewer.
When user logined for authorization, he did something making the layer and
feature source changes, then the code save theses changes.

So, answer your question, I think my job isn't making changes without using
the viewer neither making the changes before the viewer loads.

But I am going to do my best to try your code today.
Appreciate for your support.


On 7/11/07, David Hequet <[EMAIL PROTECTED] > wrote:


Are you trying to the change without using the viewer? or before the
viewer
loads?
Here is what the viewer do when loading :

1. Initialize web tier with an ini file.
2. Connect to the site.
3. Instantiate an MgMap object.
4. Call MgMap.Create to actually create it.
5. Save the MgMap object to your session with MgMap.Save.

then you can use MgMap.open("mymap")

Here is the code to simulate this:

MapGuideApi.MgInitializeWebTier
(@"C:\yourpath\WebServerExtensions\www\webconfig.ini");
    MgUserInformation userInfo = new MgUserInformation("Anonymous", "");
    MgSite site = new MgSite();
    site.Open(userInfo);
    String sessionId = site.CreateSession();

    //Associate a session ID with the MgSiteConnection Object
    MgUserInformation userInfo_new = new MgUserInformation(sessionId);
    MgSiteConnection siteConnection = new MgSiteConnection();
    siteConnection.Open(userInfo_new);

    MgResourceService resourceSrvc =
(MgResourceService)siteConnection.CreateService(
MgServiceType.ResourceService );
    MgMap map = new MgMap();
    MgResourceIdentifier resId = new

MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
    String mapName = resId.GetName();
    map.Create (resourceSrvc, resId, mapName);

    MgResourceIdentifier mapStateId = new MgResourceIdentifier("Session:"
+
sessionId + "//" + mapName + "." + MgResourceType.Map);
    map.Save(resourceSrvc, mapStateId);
    Response.Write("Done. The map name is " + map.GetName());

about using Administrator insteed of Anonymous, i think you'r right.


Tsai Chih-Cheng wrote:
>
> Hi David:
>
> Thank you for your reply.
> I try it referenced the Developer's Guide Version 1.2RC2.
> And I modified my code in your way.
> Then I got this exception :
> OSGeo.MapGuide.MgUnclassifiedException : An unclassified exception
> occurred.
>
> Error points to the first line :
>     MgUserInformation userInfo = new MgUserInformation(mgSessionId);
>     MgSiteConnection siteConnection = new MgSiteConnection();
>     siteConnection.Open(userInfo);
>
> I gather that in order to make changes permanent should be logined in
> Administrator.
> The codes look like this :
>
> MgUserInformation userInfo = new MgUserInformation("Administrator",
> "admin");
> MgSiteConnection siteConnection = new MgSiteConnection();
> siteConnection.Open(userInfo);
> //Create a MgResourceService
> MgResourceService resourceService = siteConnection.CreateService (
> MgServiceType.ResourceService ) as MgResourceService;
>
> And I got another exception :
> OSGeo.MapGuide.MgInvalidArgumentException: Invalid argument(s):
> [0] = " "
> The string cannot be empty.
>
> Error points to the first line:
> // Open the map
> MgMap map = new MgMap();
> map.Open(resourceService, "Sheboygan");
>
> So I refer to the developer's Guide, and created a session in this way :

>
> MgSite site = siteConnection.GetSite();
> string sessionID = site.CreateSession();
> userInfo.SetMgSessionId(sessionID);
>
> I use this session to create a MgResourceService to do some
modifications.
> But I get confusion in how to save the map.
> I try 3 save methods, but I still got some error exceptions.
>
> Could you provide me some specific method in how to create & save map
> status
> permanently ?
> Or, could you give me a complete code to demonstrate how to manipulate
and
> modify the data in the Library:// ?
>
> Thank you for your help.
>
> patrick
>
>
> On 7/9/07, David Hequet <[EMAIL PROTECTED]> wrote:
>>
>>
>> To make changes permanent you have to work in Library repository
insteed
>> of
>> Session repository,
>> here is a php sample, after a modification, we save the layer :
>>
>> IN SESSION:
>> // modification here..
>> $byteSource = new
>> MgByteSource($layerDefinition,strlen($layerDefinition));
>>
>> $byteSource->SetMimeType(MgMimeType::Xml);
>> $resourceID = new
>>
MgResourceIdentifier("Session:$mgSessionId//$layerName.LayerDefinition");
>> $resourceService->SetResource($resourceID,$byteSource->GetReader(),
>> null);
>>
>>
>> PERMANENT:
>> // modification here...
>> $byteSource = new MgByteSource($layerDefinition,
>> strlen($layerDefinition));
>> $byteSource->SetMimeType(MgMimeType::Xml);
>> $resourceId =new
>> MgResourceIdentifier("Library://LayerName.LayerDefinition");
>> $resourceService->SetResource($resourceId, $byteSource->GetReader(),
>> null);
>>
>> Just do it :)
>>
>
> _______________________________________________
> mapguide-users mailing list
> [email protected]
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>

--
View this message in context: 
http://www.nabble.com/How-can-we-make-the-changes-stored-in-the-map-in-programming-methods---tf4044102s16610.html#a11537116

Sent from the MapGuide Users mailing list archive at Nabble.com.

_______________________________________________
mapguide-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapguide-users

_______________________________________________
mapguide-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapguide-users

Reply via email to