Exemplo n.º 1
0
 /// <summary>
 /// Save COSEM objects to the file.
 /// </summary>
 /// <param name="filename">File name.</param>
 /// <param name="settings">XML write settings.</param>
 public void Save(string filename, GXXmlWriterSettings settings)
 {
     using (GXXmlWriter writer = new GXXmlWriter(filename))
     {
         writer.WriteStartDocument();
         writer.WriteStartElement("Objects");
         foreach (GXDLMSObject it in this)
         {
             writer.WriteStartElement("Object");
             writer.WriteAttributeString("Type", ((int)it.ObjectType).ToString());
             // Add SN
             if (it.ShortName != 0)
             {
                 writer.WriteElementString("SN", it.ShortName);
             }
             // Add LN
             writer.WriteElementString("LN", it.LogicalName);
             // Add description if given.
             if (!string.IsNullOrEmpty(it.Description))
             {
                 writer.WriteElementString("Description", it.Description);
             }
             if (settings.Values)
             {
                 (it as IGXDLMSBase).Save(writer);
             }
             // Close object.
             writer.WriteEndElement();
         }
         writer.WriteEndElement();
         writer.WriteEndDocument();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="s">Stream.</param>
        /// <param name="settings">Serialization settings.</param>
        public GXXmlWriter(Stream s, GXXmlWriterSettings settings)
        {
            Settings = settings;
            XmlWriterSettings s2 = new XmlWriterSettings()
            {
                Indent              = true,
                IndentChars         = "  ",
                NewLineOnAttributes = false
            };

            writer = XmlWriter.Create(s, s2);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Save COSEM objects to the file.
        /// </summary>
        /// <param name="filename">File name.</param>
        /// <param name="settings">XML write settings.</param>
        public void Save(string filename, GXXmlWriterSettings settings)
        {
            bool ignoreDescription = false;

            if (settings != null)
            {
                ignoreDescription = settings.IgnoreDescription;
            }
            using (Stream stream = File.OpenWrite(filename))
            {
                Save(stream, settings);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="filename">File name.</param>
        /// <param name="settings">Serialization settings.</param>
        public GXXmlWriter(string filename, GXXmlWriterSettings settings)
        {
            Settings = settings;
            XmlWriterSettings s = new XmlWriterSettings()
            {
                Indent              = true,
                IndentChars         = "  ",
                NewLineOnAttributes = false
            };

            if (File.Exists(filename))
            {
                stream = File.Open(filename, FileMode.Truncate);
            }
            else
            {
                stream = File.Open(filename, FileMode.CreateNew);
            }
            writer = XmlWriter.Create(stream, s);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Save COSEM objects to the file.
        /// </summary>
        /// <param name="stream">Stream.</param>
        /// <param name="settings">XML write settings.</param>
        public void Save(Stream stream, GXXmlWriterSettings settings)
        {
            bool omitXmlDeclaration = false;
            bool ignoreDescription  = false;

            if (settings != null)
            {
                ignoreDescription  = settings.IgnoreDescription;
                omitXmlDeclaration = settings.OmitXmlDeclaration;
            }
            int index = 0;

            if (settings != null)
            {
                index = settings.Index;
            }
            using (GXXmlWriter writer = new GXXmlWriter(stream, settings))
            {
                if (!ignoreDescription)
                {
                    writer.WriteStartDocument();
                }
                writer.WriteStartElement("Objects", 0);
                foreach (GXDLMSObject it in this)
                {
                    if (index < 2)
                    {
                        if (settings == null || !settings.Old)
                        {
                            writer.WriteStartElement("GXDLMS" + it.ObjectType.ToString(), 0);
                        }
                        else
                        {
                            writer.WriteStartElement("Object", 0);
                            writer.WriteAttributeString("Type", ((int)it.ObjectType).ToString(), 0);
                        }
                    }
                    if (index == 0)
                    {
                        // Add SN
                        if (it.ShortName != 0)
                        {
                            writer.WriteElementString("SN", it.ShortName, 0);
                        }
                        // Add LN
                        writer.WriteElementString("LN", it.LogicalName, 0);
                        // Add Version
                        if (it.Version != 0)
                        {
                            writer.WriteElementString("Version", it.Version, 0);
                        }
                        // Add description if given.
                        if (!ignoreDescription && !string.IsNullOrEmpty(it.Description))
                        {
                            writer.WriteElementString("Description", it.Description, 0);
                        }
                        //Add access rights.
                        StringBuilder sb = new StringBuilder();
                        for (int pos = 1; pos != (it as IGXDLMSBase).GetAttributeCount() + 1; ++pos)
                        {
                            sb.Append(((int)it.GetAccess(pos)).ToString());
                        }
                        writer.WriteElementString("Access", sb.ToString(), 0);
                        sb.Length = 0;
                        for (int pos = 1; pos != (it as IGXDLMSBase).GetMethodCount() + 1; ++pos)
                        {
                            sb.Append(((int)it.GetMethodAccess(pos)).ToString());
                        }
                        writer.WriteElementString("MethodAccess", sb.ToString(), 0);
                    }
                    if (settings == null || settings.Values)
                    {
                        (it as IGXDLMSBase).Save(writer);
                    }
                    if (index < 2)
                    {
                        // Close object.
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();
                if (!ignoreDescription)
                {
                    writer.WriteEndDocument();
                }
            }
        }