static public string buildFile(AlarmDefinitionList alarms) { XmlWriterSettings settings = new XmlWriterSettings { ConformanceLevel = ConformanceLevel.Document, Encoding = Encoding.UTF8, Indent = true }; string filename; using (Stream stream = TempFile.Open("sDB_Larm", "xml", out filename)) { // Round up to multiples of 16, since HMI uses words to transfer alarm state int maxAlarmCount = ((alarms.Count() + 15) / 16) * 16; XmlWriter w = XmlWriter.Create(stream, settings); w.WriteStartDocument(); w.WriteStartElement("Document"); w.WriteStartElement("DocumentInfo"); w.WriteEndElement(); // DocumentInfo w.WriteStartElement("SW.DataBlock"); w.WriteAttributeString("ID", "0"); w.WriteStartElement("AttributeList"); XMLUtil.SimpleValue(w, "AutoNumber", "true"); XMLUtil.SimpleValue(w, "DatablockType", "SharedDB"); XMLUtil.SimpleValue(w, "HeaderVersion", "0.1"); w.WriteStartElement("Interface"); w.WriteStartElement("Sections", "http://www.siemens.com/automation/Openness/SW/Interface/v1"); w.WriteStartElement("Section"); w.WriteAttributeString("Name", "Static"); w.WriteStartElement("Member"); w.WriteAttributeString("Name", "Props"); w.WriteAttributeString("Remanence", "Classic"); w.WriteAttributeString("Datatype", "Array[1.." + maxAlarmCount + "] of \"AlarmProperties\""); w.WriteStartElement("AttributeList"); XMLUtil.BooleanAttribute(w, "HmiAccessible", true, XMLUtil.SystemDefined); XMLUtil.BooleanAttribute(w, "HmiVisible", true, XMLUtil.SystemDefined); w.WriteEndElement(); // AttributeList w.WriteStartElement("Sections"); w.WriteStartElement("Section"); w.WriteAttributeString("Name", "None"); // Silent member w.WriteStartElement("Member"); w.WriteAttributeString("Name", "Silent"); w.WriteAttributeString("Datatype", "Bool"); w.WriteStartElement("AttributeList"); w.WriteEndElement(); // AttributeList int index = 1; foreach (AlarmDefinition a in alarms) { StartValue(w, index.ToString(), (a.Options & AlarmDefinition.Option.Silent) != 0 ? "true" : "false"); index++; } w.WriteEndElement(); // Member // AutoAck member w.WriteStartElement("Member"); w.WriteAttributeString("Name", "AutoAck"); w.WriteAttributeString("Datatype", "Bool"); w.WriteStartElement("AttributeList"); w.WriteEndElement(); // AttributeList index = 1; foreach (AlarmDefinition a in alarms) { StartValue(w, index.ToString(), (a.Options & AlarmDefinition.Option.AutoAck) != 0 ? "true" : "false"); index++; } w.WriteEndElement(); // Member // Text member w.WriteStartElement("Member"); w.WriteAttributeString("Name", "Text"); w.WriteAttributeString("Datatype", "String[64]"); w.WriteStartElement("AttributeList"); w.WriteEndElement(); // AttributeList index = 1; foreach (AlarmDefinition a in alarms) { StartValue(w, index.ToString(), "'" + a.Text + "'"); index++; } w.WriteEndElement(); // Member w.WriteEndElement(); // Section w.WriteEndElement(); // Sections w.WriteEndElement(); // Member w.WriteEndElement(); // Section w.WriteEndElement(); // Sections w.WriteEndElement(); // Interface string now = DateTime.UtcNow.ToString("o"); XMLUtil.SimpleValue(w, "InterfaceModifiedDate", now, true); XMLUtil.SimpleValue(w, "IsKnowHowProtected", now, true); XMLUtil.SimpleValue(w, "IsOnlyStoredInLoadMemory", "false"); XMLUtil.SimpleValue(w, "IsPLCDB", "false", true); XMLUtil.SimpleValue(w, "IsWriteProtectedInAS", "false"); XMLUtil.SimpleValue(w, "MemoryLayout", "Standard"); XMLUtil.SimpleValue(w, "ModifiedDate", now, true); XMLUtil.SimpleValue(w, "Name", "sDB_LarmDefs"); XMLUtil.SimpleValue(w, "Number", "532"); XMLUtil.SimpleValue(w, "ParameterModified", now, true); XMLUtil.SimpleValue(w, "ProgrammingLanguage", "DB"); XMLUtil.SimpleValue(w, "StructureModified", now, true); XMLUtil.SimpleValue(w, "Type", "DB"); w.WriteEndElement(); // AttributeList w.WriteEndElement(); // SW.Datablock w.WriteEndElement(); // Document w.Close(); } return(filename); }