Exemple #1
0
        /// <summary>
        /// Extracts attributes common to all idf elements
        /// </summary>
        /// <param name="node"></param>
        /// <param name="parentGroup"></param>
        public IdfElement(XElement node, IdfGroup parentGroup)
        {
            Node        = node ?? throw new ArgumentNullException(nameof(node));
            ParentGroup = parentGroup;
            Id          = node.Attribute(IdfElementId).Value;
            Name        = node.Attribute(IdfElementName).Value;
            T1Id        = Node.Attribute(GisT1Asset)?.Value;
            Node1Id     = Node.Attribute(IdfDeviceS1Node)?.Value ?? "";
            Node2Id     = Node.Attribute(IdfDeviceS1Node)?.Value ?? "";

            if (!string.IsNullOrWhiteSpace(Node.Attribute(IdfDeviceS1PhaseId1)?.Value))
            {
                S1Phases++;
            }
            if (!string.IsNullOrWhiteSpace(Node.Attribute(IdfDeviceS1PhaseId2)?.Value))
            {
                S1Phases++;
            }
            if (!string.IsNullOrWhiteSpace(Node.Attribute(IdfDeviceS1PhaseId3)?.Value))
            {
                S1Phases++;
            }
            if (!string.IsNullOrWhiteSpace(Node.Attribute(IdfDeviceS2PhaseId1)?.Value))
            {
                S2Phases++;
            }
            if (!string.IsNullOrWhiteSpace(Node.Attribute(IdfDeviceS2PhaseId2)?.Value))
            {
                S2Phases++;
            }
            if (!string.IsNullOrWhiteSpace(Node.Attribute(IdfDeviceS2PhaseId3)?.Value))
            {
                S2Phases++;
            }

            //TODO: to be removed
            if (parentGroup != null && !(this is IdfSource))
            {
                node.SetAttributeValue(IdfElementAorGroup, AorDefault);
                node.SetAttributeValue(IdfViolations, IdfTrue);
                //TODO: change this depending on voltage, either HV or LV
                node.SetAttributeValue(IdfLimits, "Limits,System");
            }
        }
Exemple #2
0
 public IdfRegion(XElement node, IdfGroup processor) : base(node, processor)
 {
 }
 public IdfTransformer(XElement node, IdfGroup processor) : base(node, processor)
 {
 }
Exemple #4
0
        public bool Initialize(string path)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            Info("Sorting idfs...");
            //Read all the xml files in the directory
            var files = Directory.GetFiles(path, "*.xml", SearchOption.TopDirectoryOnly);

            foreach (var file in files)
            {
                try
                {
                    var idf = new IdfFile();
                    idf.Content      = XDocument.Load(file);
                    idf.FullFileName = file;
                    var type = idf.Content.Root.Attribute("type").Value;
                    switch (type)
                    {
                    case "OSI Oneline":
                        //TODO: remove cruft
                        //idf.Type = IdfFileType.Graphics;
                        GraphicsFiles.Add(idf);
                        break;

                    case "Import Configuration":
                        //idf.Type = IdfFileType.ImportConfig;
                        if (ImportConfig == null)
                        {
                            ImportConfig = new ImportConfig(idf);
                        }
                        else
                        {
                            Fatal($"Import Configuration is already set ({ImportConfig.FullFileName}), ignoring second import configuration ({idf.FullFileName})");
                        }
                        break;

                    case "Electric Distribution":
                        //idf.Type = IdfFileType.Data;
                        DataFiles.Add(idf);
                        break;

                    default:
                        Fatal($"File {file} had an unrecognised type ({type})");
                        break;
                    }
                    idf.Content.Root.SetAttributeValue("timestamp", DateTime.UtcNow.ToString("s"));
                }
                catch (Exception ex)
                {
                    Fatal($"Error processing xml file {file}: {ex.Message}");
                    return(false);
                }
            }

            Info("Reading Import Config...");
            ImportConfig.MainPowerGroups = ImportConfig.Content.Descendants("container").Where(x => x.Attribute("name")?.Value == "Mainpower").FirstOrDefault();
            ImportConfig.GlobalGroups    = ImportConfig.Content.Descendants("container").Where(x => x.Attribute("name")?.Value == "Globals").FirstOrDefault();

            //Read all the groups we are going to import add them to the collection
            foreach (var group in ImportConfig.Content.Descendants("group"))
            {
                var g = new IdfGroup(group, null);
                Groups.Add(g.Id, g);
            }

            Info("Loading groups from data files...");
            //loop through the data files and assign the elements to the groups
            foreach (var idf in DataFiles)
            {
                var groups = idf.Content.Descendants("group");
                foreach (var group in groups)
                {
                    var id = group.Attribute("id").Value;
                    if (Groups.ContainsKey(id))
                    {
                        Groups[id].SetDataGroup(group);
                    }
                    else
                    {
                        Err("Data group is not in the import configuration.", id, idf.FileName);
                    }
                }
            }

            Info("Loading groups from display files...");
            //loop through the graphics files and assign the elements to the groups
            foreach (var idf in GraphicsFiles)
            {
                string display = idf.Content.Root.Attribute("displayName").Value;
                var    groups  = idf.Content.Descendants("group");
                //TODO: tolist  required so we can add new ones...
                foreach (var group in groups.ToList())
                {
                    var id = group.Attribute("id")?.Value;
                    if (id == null)
                    {
                        Err($"A display group with no id was in file {idf.FileName} and will be deleted");
                        group.Remove();
                        continue;
                    }
                    if (!Groups.ContainsKey(id))
                    {
                        Err("Display group is not in the import configuration", id, idf.FileName);
                    }
                    Groups[id].AddDisplayGroup(display, group);
                }
            }

            return(true);
        }
Exemple #5
0
 /// <summary>
 /// Creates a new Area
 /// </summary>
 /// <param name="node">The XElement node from the IDF</param>
 /// <param name="processor">The IDF Group that the Area belongs to</param>
 public IdfArea(XElement node, IdfGroup processor) : base(node, processor)
 {
 }
Exemple #6
0
 public IdfSource(XElement node, IdfGroup processor) : base(node, processor)
 {
 }
Exemple #7
0
 public IdfFeeder(XElement node, IdfGroup processor) : base(node, processor)
 {
 }
Exemple #8
0
 public IdfSubstation(XElement node, IdfGroup processor) : base(node, processor)
 {
 }
 /// <summary>
 /// Represents a IDF Capacitor object
 /// </summary>
 /// <param name="node">The XElement node from the IDF</param>
 /// <param name="parent">The Group that this element belongs to</param>
 public IdfCapacitor(XElement node, IdfGroup parent) : base(node, parent)
 {
 }
Exemple #10
0
 public IdfRegulator(XElement node, IdfGroup processor) : base(node, processor)
 {
 }
Exemple #11
0
 /// <summary>
 /// Creates a new Circuit
 /// </summary>
 /// <param name="node">The XElement node from the IDF</param>
 /// <param name="processor">The IDF Group that the Circuit belongs to</param>
 public IdfCircuit(XElement node, IdfGroup processor) : base(node, processor)
 {
 }
 /// <summary>
 /// Represents a IDF Generator object
 /// </summary>
 /// <param name="node">The XElement node from the IDF</param>
 /// <param name="parent">The Group that this element belongs to</param>
 public IdfGenerator(XElement node, IdfGroup parent) : base(node, parent)
 {
 }