public void FromXmlBase(ref XElement res, string directoryName)
{
//var xmlSerializer = new XmlSerializer(typeof (PoI));
//var p = xmlSerializer.Deserialize(res.CreateReader());
try
{
Id = res.GetGuid("Id");
if (Id == Guid.Empty) Id = Guid.NewGuid();
var n = res.GetString("Name");
ContentId = res.GetString("PoiId", "");
if (String.IsNullOrEmpty(ContentId)) ContentId = n;
Priority = res.GetInt("Priority", 2);
UserId = res.GetString("UserId");
DateLong = res.GetLong("Date", DateTime.Now.ToEpoch());
UpdatedLong = res.GetLong("Updated", DateTime.Now.ToEpoch());
Layer = res.GetString("Layer");
MaxItems = res.GetNullInt("MaxItems");
var xMid = res.Element("MetaInfoData");
PoiTypeId = res.GetString("PoiTypeId", "");
IsVisibleInMenu = res.GetBool("IsVisibleInMenu", true);
Orientation = res.GetDouble("Orientation", 0.0);
//if (!string.IsNullOrEmpty(PoiTypeId))
//{
//}
if (xMid != null)
{
var metaInfo = new MetaInfoCollection();
foreach (var xMi in xMid.Elements())
{
var mi = new MetaInfo();
mi.FromXml(xMi);
metaInfo.Add(mi);
}
MetaInfo = metaInfo;
}
if (res.Element("WKT") != null)
{
var xElement = res.Element("WKT");
if (xElement != null) WktText = xElement.Value;
}
var xlabels = res.Element("Labels");
if (xlabels != null)
{
Labels = new Dictionary<string, string>();
foreach (var xk in xlabels.Elements())
{
var k = xk.Name.LocalName;
// Restore keys starting with numbers or having % or '.
k = k.Replace(LabelPercentSubst, "%");
k = k.Replace(LabelQuoteSubst, "'");
if (k.StartsWith(LabelNumPrefix))
{
k = k.Substring(LabelNumPrefix.Length);
}
var s = xk.InnerXml();
Labels[k] = s.RestoreInvalidCharacters();
Labels[k] = Labels[k].Replace("<", "<").Replace(">", ">");
}
}
var xkeywords = res.Element("Keywords");
if (xkeywords != null)
{
Keywords = new WordHistogram();
Keywords.FromXml(xkeywords);
}
if (res.Element("Style") != null)
{
try
{
var newStyle = new PoIStyle();
newStyle.FromXml(res.Element("Style"), directoryName, false); //, Service.Settings); // TODO REVIEW: Settings were ignored.
Style = newStyle;
}
catch (Exception)
{
// OK, keep the old style.
}
}
var media = res.Element("AllMedia");
if (media != null)
{
AllMedia = new BindableCollection<Media>();
foreach (var m in media.Elements())
{
var me = new Media { Content = this };
me.FromXml(m);
AllMedia.Add(me);
}
}
var xpos = res.Element("Position");
if (xpos != null)
Position = new Position(xpos.GetDouble(Position.LONG_LABEL), xpos.GetDouble(Position.LAT_LABEL), xpos.GetDouble(Position.ALT_LABEL)); // TODO Remember other Position attributes.
var px = res.Element("Points");
var mo = res.Element("Models");
if (mo != null)
{
Models = new List<Model>();
foreach (var xm in mo.Elements())
{
var m = new Model();
m.FromXml(xm);
Models.Add(m);
}
}
if (px == null) return;
var pp = px.Value;
Points = new ObservableCollection<Point>();
var ppo = pp.Split(' ');
foreach (var poss in ppo)
{
var split = poss.Split(',');
var pt = new Point(
Double.Parse(split[0], CultureInfo.InvariantCulture),
Double.Parse(split[1], CultureInfo.InvariantCulture));
Points.Add(pt);
}
}
catch (SystemException e)
{
Logger.Log("DataServer.BaseContent", "Error reading XML " + res + " from " + directoryName, e.Message, Logger.Level.Error, true);
}
}