Author Topic: Best way to serializedeserialize DbDictionaries into a settings class.  (Read 1854 times)

0 Members and 1 Guest are viewing this topic.

Keith Brown

  • Swamp Rat
  • Posts: 601
I am working on a project where I am storing information into the Named Object Dictionary.  The hierarchy is not fairly large but it is 4 levels deep where the last level will have DBDictionaries that contain resultbuffers.  The previous levels of dictionaries are just containers to logically separate the data.  For instance, here would be a typical structure.


Code - Text: [Select]
  1. BROW_AUTOMATIC_INSULATION
  2.         DUCT
  3.                 SUPPLY - MEDIUM PRESSURE
  4.                         SIZE RANGE 01   (RESULTBUFFER CONTAINS - DOUBLE, DOUBLE)                               
  5.                 SUPPLY - HIGH PRESSURE
  6.                         SIZE RANGE 01   (RESULTBUFFER CONTAINS - DOUBLE, DOUBLE)       
  7.         PIPE
  8.                 HEATING HOT WATER - SUPPLY
  9.                         SIZE RANGE 01   (RESULTBUFFER CONTAINS - DOUBLE, DOUBLE)       
  10.                         SIZE RANGE 02   (RESULTBUFFER CONTAINS - DOUBLE, DOUBLE)       
  11.                 HEATING HOT WATER - RETURN
  12.                         SIZE RANGE 01   (RESULTBUFFER CONTAINS - DOUBLE, DOUBLE)       
  13.                         SIZE RANGE 02   (RESULTBUFFER CONTAINS - DOUBLE, DOUBLE)


I am wondering how I should construct the settings class to hold this information.  This class will need to update whenever a new drawing has become active and whenever the user saves new settings from the settings dialog.  The last two levels of the structure can have unlimited entries while the 1st and 2nd will have 1 and 2 respectively.  Should i create a custom data structure or just keep the items in a dictionary for fast lookup?  I will need to access these settings quite a bit.  Every time a duct or pipe is added or modified in the model these settings will need to be accessed which leads me to believe that a dictionary is probably the best bet or is it just as fast/easy/correct to access the DBDictionaries directly?


Any thoughts, ideas or suggestions?
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Best way to serializedeserialize DbDictionaries into a settings class.
« Reply #1 on: September 17, 2014, 06:32:33 PM »
I have a similar situation where I store xml in the NOD of entities for xml class objects (i.e. classes that serialise to/from xml) and I read and write to them when things change without any performance issues at all.

If you are reading/writing the NOD data to and from your dialog now maybe that's enough as you will only be inserting an 'adapter' in between to serialise between them, nothing gained except some decoupling.
 
Having said that, xml classes can be written in/out to file as templates etc and you have the added bonus of validation.

If you want to go the xml route MS has a tool called XSD http://msdn.microsoft.com/en-us/library/x6c1kb0s(v=vs.110).aspx

I use LiquidXML which leverages this and will build the classes and source code for you from your schema and you can't write invalid data without explicitly setting it to allow it.
Its also an xml and schema editor but it is a bit pricey at ~$700+ but it saves a lot of work. For what you want the XSD tools may be enough.
I have around 70 xml classes to deal with and the schema will be updated by the consortium at some stage so the purchase for me was an easy decision.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Best way to serializedeserialize DbDictionaries into a settings class.
« Reply #2 on: September 17, 2014, 10:00:29 PM »
Thanks for the info Mick.  Do you pass the whole xml document to the dictionary at once?
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Best way to serializedeserialize DbDictionaries into a settings class.
« Reply #3 on: September 17, 2014, 10:17:47 PM »
For my particular project I add it to entities per entity and file all entity info out into a single file when the drawing is done. I build the empty doc with collections and write each ent's xml data out with iteration.
I store 'project' information for this file straight to a NOD on the db which is similar to your settings I'm guessing so yes.

There's a class on here by Dan (nullptr) that makes large files a lot easier to store in resbuf's to get around size issues, I'll dig it up if you need it.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Best way to serializedeserialize DbDictionaries into a settings class.
« Reply #4 on: September 17, 2014, 10:20:15 PM »
I would definately wouldnt mind looking at that class.  I am investigating your method and seeing if it makes sense for me.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Best way to serializedeserialize DbDictionaries into a settings class.
« Reply #5 on: September 17, 2014, 10:41:54 PM »
Here's the thread: http://www.theswamp.org/index.php?topic=26687.msg321539#msg321539

In your case Keith, maybe building a simple class with dictionaries as properties may be easier as you only have one 'structure' or settings file. The thing with xml is serialising is built in whereas you would need to write the IO code yourself for your class but at least it will have a small footprint and work exactly how you want.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Best way to serializedeserialize DbDictionaries into a settings class.
« Reply #6 on: September 17, 2014, 10:47:05 PM »
Well I was thinking about it and I will probably need to ability to import and export settings from a file.  XML is the way to go as far as a storage architecture so this might be easier.  Also thinking big picture the settings that I am creating now will be a small part of a larger settings file.  There are alot of smaller projects that I want to complete that will need to have similar settings that could all be wrapped up in a single xml document.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Best way to serializedeserialize DbDictionaries into a settings class.
« Reply #7 on: September 17, 2014, 11:08:29 PM »
Sounds like a plan.

A happy side effect of using xml this way for me is I can also store 'snippets' in seperate files as simple text templates for my entities, the user can hit a 'save as template' button and load it with common settings for each project.

PM me if you want and need a hand with anything or have any questions about the tools I use.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien