Exemplo n.º 1
0
        public void Save(String forcedDirectory = null)
        {
            String directory = (forcedDirectory == null ? StorageDirectory : forcedDirectory);

            //  Save each body as individual file with name indicating type, current name, and some random number
            //throw new NotImplementedException();

            var duplicates = Bodies.Where(b => Bodies.Count(o => o.Id == b.Id) > 1);

            if (duplicates.Count() > 0)
            {
                throw new Exception("Cannot save! Invalid db state!");
            }

            foreach (var body in Bodies)
            {
                var map = _WorkingSerializations.Where(p => p.Key.Id == body.Id).Select(p => p.Value);
                if (map.Count() > 0)
                {
                    var m   = map.Single();
                    var xml = SaveBody(m.Filename, body);
                    m.Xml = xml;
                }
                else
                {
                    var fname = Path.Combine(directory, String.Format("{0}_{1}.fb", body.Type, body.Id));
                    var xml   = SaveBody(fname, body);
                    _WorkingSerializations.Add(body, new FileXmlMap {
                        Filename = fname, Xml = xml
                    });
                }
            }
        }