tags:

views:

182

answers:

2

I am looking for help to achieve the following

The Diagram represents a car, users can add engine and colour

when I view the XML it looks like this:

<Car>
  <Engine>BigEngine</Engine>
  <Colour>Pink</Colour>
</Car>

What I would like to do is to wrap the car inside 'vehicle', i.e

<Vehicle>
  <Car>
    <Engine>BigEngine</Engine>
    <Colour>Pink</Colour>
  </Car>
</Vehicle>

I am not sure of the best way to achieve this. I want the model explorer and the generated XML to be wrapped in 'vehicle' but for all other intents and purposes the user is working with a car only

Info: Visual Studio 2010, C# and DSL SDK for 2010

A: 

I would try two different approaches:


1st: override DSL Package class DocData In DocData.cs file and override method

protected override void OnDocumentSaved(System.EventArgs e)

and then I would create the wrapper

afterwards I'd override in DocData.cs

protected override void OnDocumentLoading(System.EventArgs e)

and before calling the base method base.OnDocumentLoading(e); i would delete from the file.


2nd: Under DSL Explorer go to XML Serialization Behaviour and set Car Domain Class "Is Custom = true".

This solution is not straightforward but it's not as complicated as it seems at the first place. You'll must define every single method but for each custom method you can call a DSL generated method called "DefaulMethod" which has the default DSL serializer behaviour.


I am currently using VS 2005, so some things might have changed...

Luis Filipe
I had a look at your first message but all I could see was SerializedModel (string) but it was a getter only. I could not override any methods either. I am still stumped
Phill Duffy
Hej! I was on vacancies so i didn't have a chance to answer.What do you mean by "1st message"? What approach did you try?
Luis Filipe
A: 

I have fixed this by the following. I am double deriving the Car class and in the Car serializer I am doing this:

Writing the extra elements:

  public partial class CarSerializer : CarSerializerBase
{
    public override void Write(SerializationContext serializationContext, ModelElement element, XmlWriter writer, RootElementSettings rootElementSettings)
    {
        // Adds the Model and LobSystem root elements to match that required by the SharePoint BCS
        writer.WriteStartElement("Garage");
        writer.WriteStartElement("Cars");
        base.Write(serializationContext, element, writer, rootElementSettings);
        writer.WriteEndElement();
        writer.WriteEndElement();
    }
}

To be able to read this back in I am overriding the Car LoadModel method in the SerializationHelper and where it is getting the reader I am reading the elements until I get to Car.

....

XmlReader reader = XmlReader.Create(fileStream, settings);
reader.MoveToContent();
while (!reader.EOF && !reader.Name.Equals("Car"))
{
   reader.Read();
}

reader = reader.ReadSubtree();

//    using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings))
using (reader)
{

....

Phill Duffy