public EtsDatapoint(XElement e, EtsGroup parent) : base(e) { Parent = parent; AddDatapointTypeOrSize(GetAttributeValue(e, "DatapointType")); Address = int.Parse(GetAttributeValue(e, "Address")); GroupIndex = parent.Level == 0 ? Address % 2048 : Address % 256; }
public EtsGroup(XElement e, EtsGroup parent) : base(e) { Parent = parent; Level = parent != null ? parent.Level + 1 : 0; int rangeStart; if (int.TryParse(GetAttributeValue(e, "RangeStart"), out rangeStart)) { if (Level == 0) { GroupIndex = rangeStart / 2048; } else { GroupIndex = (rangeStart >> 8) % 8; } } else { GroupIndex = -1; } }
private void ParseProjectDirectory(FileInfo file) { XElement doc = XElement.Load(file.FullName); XNamespace ns = doc.GetDefaultNamespace(); foreach(var p in from el in doc.Descendants(ns + "Project") where el.Attribute("Id") != null select el) { String id = GetAttributeValue(p, "Id"); if (!Context.Projects.ContainsKey(id)) Context.Projects[id] = new EtsProject(p); var project = Context.Projects[id]; project.Aggregate(p); foreach (var groupRange in from el in p.Descendants(ns + "GroupRange") select el) { EtsGroup parent = null; String parentId = GetAttributeValue(groupRange.Parent, "Id"); if (!String.IsNullOrEmpty(parentId) && Context.Groups.ContainsKey(parentId)) parent = Context.Groups[parentId]; EtsGroup newGroup = new EtsGroup(groupRange, parent); Context.Groups[newGroup.Id] = newGroup; if (parent == null) // has to be a top level group project.AddChild(newGroup); else parent.AddChild(newGroup); foreach (var groupAddresse in from el in groupRange.Elements(ns + "GroupAddress") select el) { EtsDatapoint newDatapoint = new EtsDatapoint(groupAddresse, newGroup); newGroup.AddChild(newDatapoint); Context.Datapoints[newDatapoint.Id] = newDatapoint; } } foreach (var groupAddressConnector in from el in p.Descendants(ns + "Send") where el.Parent?.Parent != null && (el.Parent != null && el.Parent.Parent.Name.LocalName == "ComObjectInstanceRef") select el) { String groupAddressRefId = GetAttributeValue(groupAddressConnector, "GroupAddressRefId"); if (String.IsNullOrEmpty(groupAddressRefId)) continue; if (groupAddressConnector.Parent != null) { XElement comObjectInstanceRef = groupAddressConnector.Parent.Parent; if (!Context.GroupAddressRefId2ComObjectInstanceRefId.ContainsKey(groupAddressRefId)) Context.GroupAddressRefId2ComObjectInstanceRefId[groupAddressRefId] = new List<String>(); Context.GroupAddressRefId2ComObjectInstanceRefId[groupAddressRefId].Add(GetAttributeValue(comObjectInstanceRef, "RefId")); if (Context.GroupAddressRefId2DatapointType.ContainsKey(groupAddressRefId)) continue; String datapointType = GetAttributeValue(comObjectInstanceRef, "DatapointType"); if (!String.IsNullOrEmpty(datapointType)) { Context.GroupAddressRefId2DatapointType[groupAddressRefId] = datapointType; } } } foreach (var groupAddressConnector in from el in p.Descendants(ns + "Receive") where el.Parent?.Parent != null && (el.Parent != null && el.Parent.Parent.Name.LocalName == "ComObjectInstanceRef") select el) { String groupAddressRefId = GetAttributeValue(groupAddressConnector, "GroupAddressRefId"); if (String.IsNullOrEmpty(groupAddressRefId)) continue; if (groupAddressConnector.Parent != null) { XElement comObjectInstanceRef = groupAddressConnector.Parent.Parent; if (!Context.GroupAddressRefId2ComObjectInstanceRefId.ContainsKey(groupAddressRefId)) Context.GroupAddressRefId2ComObjectInstanceRefId[groupAddressRefId] = new List<String>(); Context.GroupAddressRefId2ComObjectInstanceRefId[groupAddressRefId].Add(GetAttributeValue(comObjectInstanceRef, "RefId")); if (Context.GroupAddressRefId2DatapointType.ContainsKey(groupAddressRefId)) continue; String datapointType = GetAttributeValue(comObjectInstanceRef, "DatapointType"); if (!String.IsNullOrEmpty(datapointType)) { Context.GroupAddressRefId2DatapointType[groupAddressRefId] = datapointType; } } } var firstBuildingParts = (from el in p.Descendants(ns + "Locations") select el).Elements(); foreach (var building in firstBuildingParts) { var etsBuilding = new EtsBuilding(building, ns, Context); etsBuilding.Aggregate(building); project.Buildings.Add(etsBuilding); } } }