public void insertLoadObservation(String sensorId,
                                            String sampleNumber,
                                           long loadTime,
                                           double downstreamActivePowerEEA,
                                            double reactiveInductivePowerEEI,
                                            double reactiveCapacitivePowerEEC,
                                            double upstreamActivePowerEUA,
                                            double reactiveInductivePowerEUI,
                                            double reactiveCapaciticePowerEUC,
                                            String tariffType,
                                            String integrationPeriodRef,
                                            long currentTime
                                            )
        {
            XmlSerializer ser = new XmlSerializer(typeof(InsertObservation));
            Utf8StringWriter textWriter = new Utf8StringWriter();

            InsertObservation io = new InsertObservation();
            io.assignedSensorId = "load:" + sensorId;
            io.observation = new Observation();
            io.observation.samplingTime = new SamplingTime();
            io.observation.samplingTime.timeInstant = new TimeInstant();
            io.observation.samplingTime.timeInstant.timePosition = new TimePosition();
            io.observation.samplingTime.timeInstant.timePosition.frame = "urn:x-ogc:def:trs:IDAS:1.0:ISO8601";
            var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            io.observation.samplingTime.timeInstant.timePosition.dateTime = epoch.AddSeconds(currentTime);//ho messo il currentTime. è giusto?
            io.observation.procedure = new Procedure();
            io.observation.procedure.href = "load:" + sensorId;

            //sampleNumber
            io.observation.observedProperty = new ObservedProperty();
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:sampleNumber";
            io.observation.featureOfInterest = new FeatureOfInterest();
            io.observation.parameter = new Parameter();
            io.observation.result = new Result();
            io.observation.result.text = new Text(sampleNumber);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //loadTime
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:loadTime";
            io.observation.result = new Result();
            io.observation.result.text = new Text(loadTime.ToString());

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //downstreamActivePowerEEA
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:downstreamActivePowerEEA";
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:power");
            io.observation.result.quantity.uom = new Uom("kW");
            io.observation.result.quantity.value = downstreamActivePowerEEA.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //reactiveInductivePowerEEI
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:reactiveInductivePowerEEI";
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:reactivePower");
            io.observation.result.quantity.uom = new Uom("kVAr");
            io.observation.result.quantity.value = reactiveInductivePowerEEI.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //reactiveCapacitivePowerEEC
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:reactiveCapacitivePowerEEC";
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:reactivePower");
            io.observation.result.quantity.uom = new Uom("kVAr");
            io.observation.result.quantity.value = reactiveCapacitivePowerEEC.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //upstreamActivePowerEUA
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:upstreamActivePowerEUA";
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:power");
            io.observation.result.quantity.uom = new Uom("kW");
            io.observation.result.quantity.value = upstreamActivePowerEUA.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //reactiveInductivePowerEUI
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:reactiveInductivePowerEUI";
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:reactivePower");
            io.observation.result.quantity.uom = new Uom("kVAr");
            io.observation.result.quantity.value = reactiveInductivePowerEUI.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //reactiveCapaciticePowerEUC
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:reactiveCapaciticePowerEUC";
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:reactivePower");
            io.observation.result.quantity.uom = new Uom("kVAr");
            io.observation.result.quantity.value = reactiveCapaciticePowerEUC.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //tariffType
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:tariffType";
            io.observation.result = new Result();
            io.observation.result.text = new Text(tariffType);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //integrationPeriodRef
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:integrationPeriodRef";
            io.observation.result = new Result();
            io.observation.result.text = new Text(integrationPeriodRef);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //currentTime
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:currentTime";
            io.observation.result = new Result();
            io.observation.result.text = new Text(currentTime.ToString());

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //meterID
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:meterID";
            io.observation.result = new Result();
            io.observation.result.text = new Text(sensorId);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //meterType
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:meterType";
            io.observation.result = new Result();
            io.observation.result.text = new Text("LOAD");

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //isConcentrator
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:isConcentrator";
            io.observation.result = new Result();
            io.observation.result.text = new Text("false");

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());
        }
        public void insertMeterObservation(string sensorId, 
                                            long samplingTime,
                                            double upstreamActivePower,
                                            double downstreamActivePower,
                                            double reactivePowerQ1,
                                            double reactivePowerQ2,
                                            double reactivePowerQ3,
                                            double reactivePowerQ4)
        {
            XmlSerializer ser = new XmlSerializer(typeof(InsertObservation));
            Utf8StringWriter textWriter = new Utf8StringWriter();

            InsertObservation io = new InsertObservation();
            io.assignedSensorId = "meter:" + sensorId;
            io.observation = new Observation();
            io.observation.samplingTime = new SamplingTime();
            io.observation.samplingTime.timeInstant = new TimeInstant();
            io.observation.samplingTime.timeInstant.timePosition = new TimePosition();
            io.observation.samplingTime.timeInstant.timePosition.frame = "urn:x-ogc:def:trs:IDAS:1.0:ISO8601";
            var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            io.observation.samplingTime.timeInstant.timePosition.dateTime = epoch.AddSeconds(samplingTime);
            io.observation.procedure = new Procedure();
            io.observation.procedure.href = "meter:" + sensorId;
            io.observation.observedProperty = new ObservedProperty();
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:upstreamActivePower";
            io.observation.featureOfInterest = new FeatureOfInterest();
            io.observation.parameter = new Parameter();
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:power");
            io.observation.result.quantity.uom = new Uom("kW");
            io.observation.result.quantity.value = upstreamActivePower.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //downstreamActivePower
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:downstreamActivePower";
            io.observation.result.quantity.value = downstreamActivePower.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //reactivePowerQ1
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:RP_Q1";
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:reactivePower");
            io.observation.result.quantity.uom = new Uom("kVAr");
            io.observation.result.quantity.value = reactivePowerQ1.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //reactivePowerQ2
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:RP_Q2";
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:reactivePower");
            io.observation.result.quantity.uom = new Uom("kVAr");
            io.observation.result.quantity.value = reactivePowerQ2.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //reactivePowerQ3
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:RP_Q3";
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:reactivePower");
            io.observation.result.quantity.uom = new Uom("kVAr");
            io.observation.result.quantity.value = reactivePowerQ3.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //reactivePowerQ4
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:RP_Q4";
            io.observation.result = new Result();
            io.observation.result.quantity = new Quantity("urn:x-ogc:def:phenomenon:IDAS:1.0:reactivePower");
            io.observation.result.quantity.uom = new Uom("kVAr");
            io.observation.result.quantity.value = reactivePowerQ4.ToString("G", CultureInfo.InvariantCulture);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //isConcentrator
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:isConcentrator";
            io.observation.result = new Result();
            io.observation.result.text = new Text("false");

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //meterID
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:meterID";
            io.observation.result = new Result();
            io.observation.result.text = new Text(sensorId);

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());

            //meterType
            io.observation.observedProperty.href = "urn:x-ogc:def:phenomenon:FINESCE:1.0:meterType";
            io.observation.result = new Result();
            io.observation.result.text = new Text("METER");

            textWriter = new Utf8StringWriter();
            ser.Serialize(textWriter, io);
            sendMessage(textWriter.ToString());
        }