Пример #1
0
        public override void Aggregate(XElement e)
        {
            RefId = GetAttributeValue(e, "RefId");
            Role  = GetAttributeValue(e, "Role");

            if (_context.Datapoints.ContainsKey(RefId))
            {
                Datapoint = _context.Datapoints[RefId];
            }

            base.Aggregate(e);
        }
Пример #2
0
        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);
                }
            }
        }