internal CustomFileFormatImpl(CustomFileFormat customFileFormat)
     : base(customFileFormat)
 {
     attributes = customFileFormat.getAttributes();
     //foreach (var attr in customFileFormat.getAttributes())
     //{
     //    attributes.Add(attr.Key, attr.Value);
     //}
 }
Esempio n. 2
0
        internal XmlElement createElement(XmlDocument document)
        {
            document.AppendChild(document.CreateXmlDeclaration("1.0", "UTF-8", ""));
            var unisensElement = document.CreateElement(Constants.UNISENS, "http://www.unisens.org/unisens2.0");

            unisensElement.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            unisensElement.SetAttribute("xsi:schemaLocation", "http://www.unisens.org/unisens2.0 http://www.unisens.org/unisens2.0/unisens.xsd");
            //.Attributes.Append(document.CreateAttribute("http://www.w3.org/2001/XMLSchema-instance",);
            //"xsi:schemaLocation",
            //"http://www.unisens.org/unisens2.0 http://www.unisens.org/unisens2.0/unisens.xsd")));

            if (getComment() != null)
            {
                unisensElement.SetAttribute(Constants.UNISENS_COMMENT, getComment());
            }
            if (getDuration() != 0)
            {
                unisensElement.SetAttribute(Constants.UNISENS_DURATION, "" + getDuration());
            }
            if (getTimestampStart() != null)
            {
                unisensElement.SetAttribute(Constants.UNISENS_TIMESTAMP_START,
                                            Utilities.convertDateToString(timestampStart));
            }

            ;
            if (getMeasurementId() != null)
            {
                unisensElement.SetAttribute(Constants.UNISENS_MEASUREMENT_ID, getMeasurementId());
            }
            if (getVersion() != null)
            {
                unisensElement.SetAttribute(Constants.UNISENS_VERSION, getVersion());
            }

            if (customAttributes.Count > 0)
            {
                XmlElement customAttributesElement = document.CreateElement(Constants.CUSTOM_ATTRIBUTES, unisensElement.NamespaceURI);
                foreach (string key in customAttributes.Keys)
                {
                    XmlElement customAttributeElement = document.CreateElement(Constants.CUSTOM_ATTRIBUTE);
                    customAttributeElement.SetAttribute(Constants.CUSTOM_ATTRIBUTE_KEY, key);
                    customAttributeElement.SetAttribute(Constants.CUSTOM_ATTRIBUTE_VALUE, customAttributes[key]);
                    customAttributesElement.AppendChild(customAttributeElement);
                }
                unisensElement.AppendChild(customAttributesElement);
            }

            if (context != null)
            {
                XmlElement contextElement = document.CreateElement(Constants.CONTEXT, unisensElement.NamespaceURI);
                if (context.getSchemaUrl() != null)
                {
                    contextElement.SetAttribute(Constants.CONTEXT_SCHEMAURL, context.getSchemaUrl());
                }
                unisensElement.AppendChild(contextElement);
            }

            Entry entry;

            foreach (Entry t in entries)
            {
                entry = (Entry)t;
                XmlElement entryElement = null;

                if (entry is SignalEntry)
                {
                    entryElement = document.CreateElement(Constants.SIGNALENTRY, unisensElement.NamespaceURI);
                }
                if (entry is ValuesEntry)
                {
                    entryElement = document.CreateElement(Constants.VALUESENTRY, unisensElement.NamespaceURI);
                }
                if (entry is EventEntry)
                {
                    entryElement = document.CreateElement(Constants.EVENTENTRY, unisensElement.NamespaceURI);
                }
                if (entry is CustomEntry)
                {
                    entryElement = document.CreateElement(Constants.CUSTOMENTRY, unisensElement.NamespaceURI);
                }

                if (entry.getComment() != null)
                {
                    entryElement.SetAttribute(Constants.ENTRY_COMMENT, entry.getComment());
                }
                if (entry.getContentClass() != null)
                {
                    entryElement.SetAttribute(Constants.ENTRY_CONTENTCLASS, entry.getContentClass());
                }
                if (entry.getSource() != null)
                {
                    entryElement.SetAttribute(Constants.ENTRY_SOURCE, entry.getSource());
                }
                if (entry.getSourceId() != null)
                {
                    entryElement.SetAttribute(Constants.ENTRY_SOURCE_ID, entry.getSourceId());
                }
                if (entry.getId() != null)
                {
                    entryElement.SetAttribute(Constants.ENTRY_ID, entry.getId());
                }

                if (entry.getCustomAttributes().Count > 0)
                {
                    XmlElement customAttributesElement = document.CreateElement(Constants.CUSTOM_ATTRIBUTES, unisensElement.NamespaceURI);
                    foreach (string key in customAttributes.Keys)
                    {
                        var customAttributeElement = document.CreateElement(Constants.CUSTOM_ATTRIBUTE);
                        customAttributeElement.SetAttribute(Constants.CUSTOM_ATTRIBUTE_KEY, key);
                        customAttributeElement.SetAttribute(Constants.CUSTOM_ATTRIBUTE_VALUE, customAttributes[key]);
                        customAttributesElement.AppendChild(customAttributeElement);
                    }
                    unisensElement.AppendChild(customAttributesElement);
                }

                FileFormat fileFormat        = entry.getFileFormat();
                XmlElement fileFormatElement = null;

                if (fileFormat is BinFileFormat)
                {
                    BinFileFormat binFileFormat = (BinFileFormat)fileFormat;
                    fileFormatElement = document.CreateElement(Constants.BINFILEFORMAT, unisensElement.NamespaceURI);
                    fileFormatElement.SetAttribute(Constants.BINFILEFORMAT_ENDIANESS, binFileFormat.getEndianess().ToString().ToUpper());
                }
                if (fileFormat is CsvFileFormat)
                {
                    CsvFileFormat csvFileFormat = (CsvFileFormat)fileFormat;
                    fileFormatElement = document.CreateElement(Constants.CSVFILEFORMAT, unisensElement.NamespaceURI);
                    fileFormatElement.SetAttribute(Constants.CSVFILEFORMAT_SEPARATOR, csvFileFormat.getSeparator());
                    fileFormatElement.SetAttribute(Constants.CSVFILEFORMAT_DECIMAL_SEPARATOR, csvFileFormat.getDecimalSeparator());
                }
                if (fileFormat is XmlFileFormat)
                {
                    fileFormatElement = document.CreateElement(Constants.XMLFILEFORMAT, unisensElement.NamespaceURI);
                }
                if (fileFormat is CustomFileFormat)
                {
                    CustomFileFormat customFileFormat = (CustomFileFormat)fileFormat;
                    fileFormatElement = document.CreateElement(Constants.CUSTOMFILEFORMAT, unisensElement.NamespaceURI);
                    fileFormatElement.SetAttribute(Constants.CUSTOMFILEFORMAT_FILEFORMATNAME, customFileFormat.getFileFormatName());
                    Dictionary <string, string> attributes = customFileFormat.getAttributes();
                    var attrNames = attributes.Keys;
                    foreach (string attrName in attrNames)
                    {
                        fileFormatElement.SetAttribute(attrName, attributes[attrName]);
                    }
                }
                if (fileFormat.getComment() != null)
                {
                    fileFormatElement.SetAttribute(Constants.FILEFORMAT_COMMENT, fileFormat.getComment());
                }

                entryElement.AppendChild(fileFormatElement);

                if (entry is MeasurementEntry)
                {
                    var measurementEntry = (MeasurementEntry)entry;
                    if (measurementEntry.getAdcResolution() != 0)
                    {
                        entryElement.SetAttribute(Constants.MEASUREMENTENTRY_ADCRESOLUTION, "" + measurementEntry.getAdcResolution());
                    }
                    if (measurementEntry.getAdcZero() != 0)
                    {
                        entryElement.SetAttribute(Constants.MEASUREMENTENTRY_ADCZERO, "" + measurementEntry.getAdcZero());
                    }
                    if (measurementEntry.getBaseline() != 0)
                    {
                        entryElement.SetAttribute(Constants.MEASUREMENTENTRY_BASELINE, "" + measurementEntry.getBaseline());
                    }
                    entryElement.SetAttribute(Constants.MEASUREMENTENTRY_DATATYPE, measurementEntry.getDataType().ToString().ToLower());
                    if (measurementEntry.getLsbValue() != 0)
                    {
                        entryElement.SetAttribute(Constants.MEASUREMENTENTRY_LSBVALUE, measurementEntry.getLsbValue().ToString(decimalFormat));
                    }
                    if (measurementEntry.getSampleRate() != 0)
                    {
                        entryElement.SetAttribute(Constants.TIMEDENTRY_SAMPLERATE, measurementEntry.getSampleRate().ToString(decimalFormat));
                    }
                    if (measurementEntry.getUnit() != null)
                    {
                        entryElement.SetAttribute(Constants.MEASUREMENTENTRY_UNIT, measurementEntry.getUnit());
                    }

                    string[] channelNames = measurementEntry.getChannelNames();

                    foreach (string t1 in channelNames)
                    {
                        XmlElement channelElement = document.CreateElement(Constants.CHANNEL, unisensElement.NamespaceURI);
                        channelElement.SetAttribute(Constants.CHANNEL_NAME, t1);
                        entryElement.AppendChild(channelElement);
                    }
                }
                if (entry is EventEntry)
                {
                    EventEntry eventEntry = (EventEntry)entry;
                    if (eventEntry.getSampleRate() != 0)
                    {
                        entryElement.SetAttribute(Constants.TIMEDENTRY_SAMPLERATE, eventEntry.getSampleRate().ToString(decimalFormat));
                    }
                    if (eventEntry.getTypeLength() != 0)
                    {
                        entryElement.SetAttribute(Constants.EVENTENTRY_TYPE_LENGTH, "" + eventEntry.getTypeLength());
                    }
                    if (eventEntry.getCommentLength() != 0)
                    {
                        entryElement.SetAttribute(Constants.EVENTENTRY_COMMENT_LENGTH, "" + eventEntry.getCommentLength());
                    }
                }

                if (entry is CustomEntry)
                {
                    CustomEntry customEntry = (CustomEntry)entry;
                    Dictionary <string, string> attributes = customEntry.getAttributes();
                    ICollection <string>        keySet     = attributes.Keys;
                    foreach (String key in keySet)
                    {
                        entryElement.SetAttribute(key, attributes[key]);
                    }
                }

                unisensElement.AppendChild(entryElement);
            }
            Group      group;
            XmlElement groupElement;
            XmlElement groupEntryElement;

            foreach (Group t in groups)
            {
                group        = (Group)t;
                groupElement = document.CreateElement(Constants.GROUP, unisensElement.NamespaceURI);

                if (group.getComment() != null)
                {
                    groupElement.SetAttribute(Constants.GROUP_COMMENT, group.getComment());
                }
                if (group.getId() != null)
                {
                    groupElement.SetAttribute(Constants.GROUP_ID, group.getId());
                }

                var entriList = group.getEntries();
                foreach (Entry e in entriList)
                {
                    groupEntryElement = document.CreateElement(Constants.GROUPENTRY, unisensElement.NamespaceURI);
                    groupEntryElement.SetAttribute(Constants.GROUPENTRY_REF, ((Entry)e).getId());
                    groupElement.AppendChild(groupEntryElement);
                }
                unisensElement.AppendChild(groupElement);
            }
            return(unisensElement);
        }