Example #1
0
        public void Export()
        {
            //Now, write out our file
            using (StreamWriter sW = new StreamWriter(Config.TargetModelFile, false, new UTF8Encoding(false)))
            {
                sW.WriteLine("<?xml version=\"1.0\"?>");
                sW.WriteLine("<NetworkModel SaveTime=\"" + XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Utc) + "\" Model=\"Simulation\">");
                foreach (Sim_Boundary Bound in Boundaries)
                {
                    sW.WriteLine("\t" + Bound.GetXml());
                }
                foreach (Sim_Company Company in Companies)
                {
                    sW.WriteLine("\t" + Company.GetXml());
                }
                foreach (Sim_Substation Sub in Subs)
                {
                    sW.WriteLine("\t" + Sub.GetXml(this));
                }
                foreach (Sim_Unit Unit in Units)
                {
                    sW.WriteLine("\t" + Unit.GetXml(this));
                }
                foreach (Sim_Bus Bus in Buses)
                {
                    sW.WriteLine("\t" + Bus.GetXml(this));
                }
                foreach (Sim_Line Line in Lines)
                {
                    sW.WriteLine("\t" + Line.GetXml(this));
                }
                foreach (Sim_Breaker Breaker in Breakers)
                {
                    sW.WriteLine("\t" + Breaker.GetXml(this));
                }
                foreach (Sim_Load Load in Loads)
                {
                    sW.WriteLine("\t" + Load.GetXml(this));
                }
                foreach (Sim_ShuntCompensator ShuntCompensator in ShuntCompensators)
                {
                    sW.WriteLine("\t" + ShuntCompensator.GetXml(this));
                }
                foreach (Sim_Transformer Transformer in Transformers)
                {
                    sW.WriteLine("\t" + Transformer.GetXml(this));
                }

                sW.WriteLine("</NetworkModel>");
            }

            //Now, write out our one-lines
            foreach (Sim_Substation Sub in Subs)
            {
                GenerateOneLine(Sub, Config.OneLineFolder);
            }

            //Write our our savecase
            using (FileStream fsOut = new FileStream(Path.Combine(Path.GetDirectoryName(Config.TargetModelFile), Path.GetFileNameWithoutExtension(Config.TargetModelFile) + ".MM_Savecase"), FileMode.Create))
            {
                DataContractSerializer dcs = new DataContractSerializer(typeof(MM_Savecase));
                XmlDictionaryWriter    xdw = XmlDictionaryWriter.CreateBinaryWriter(fsOut);
                dcs.WriteObject(xdw, Savecase);
                xdw.Flush();
            }
        }