Beispiel #1
0
        public Tuple <bool, string> Run()
        {
            Tuple <bool, string> result = new Tuple <bool, string>(false, "");
            string identifier           = "";
            bool   res = false;

            if (DescribeSensorResponse == null || DescribeSensorResponse.description == null ||
                DescribeSensorResponse.description.Length == 0 ||
                DescribeSensorResponse.description[0] == null ||
                DescribeSensorResponse.description[0].SensorDescription.data == null)
            {
                return(result);
            }

            var descirption = DescribeSensorResponse.description[0].SensorDescription.data;

            try
            {
                InsertSensorType insertSensorRequest = new InsertSensorType();
                insertSensorRequest.observableProperty         = ObservedProperties;
                insertSensorRequest.service                    = "SOS";
                insertSensorRequest.version                    = OGCSOSCopierConfig.DEST_SOS_VERSION;
                insertSensorRequest.procedureDescriptionFormat = DescribeSensorResponse.procedureDescriptionFormat;

                InsertSensorTypeMetadata meta = new InsertSensorTypeMetadata();
                meta.InsertionMetadata = new SosInsertionMetadataType()
                {
                    observationType       = ObservationTypes,
                    featureOfInterestType = FeatureOfInterestType,
                };

                insertSensorRequest.metadata = new[] { meta };
                //insertSensorRequest.relatedFeature =
                //insertSensorRequest.extension =

                if (descirption.Name == "sml:PhysicalSystem" || descirption.Name == "PhysicalSystem")
                {
                    PhysicalSystemType PhysicalSystem = ObjectSerializer.DeserializeFromXmlElement <PhysicalSystemType>(descirption);
                    identifier = PhysicalSystem.identifier.Value;

                    insertSensorRequest.procedureDescription = ObjectSerializer.SerializeToXmlElement(PhysicalSystem, getNameSpacesForSensorML());
                }
                else if (descirption.Name == "sml:PhysicalComponent" || descirption.Name == "PhysicalComponent")
                {
                    PhysicalComponentType PhysicalComponent = ObjectSerializer.DeserializeFromXmlElement <PhysicalComponentType>(descirption);
                    identifier = PhysicalComponent.identifier.Value;

                    insertSensorRequest.procedureDescription = ObjectSerializer.SerializeToXmlElement(PhysicalComponent, getNameSpacesForSensorML());
                }

                var reqcontent = insertSensorRequest.SerializeObjectToXmlString(getNameSpacesForSos());


                var client  = new RestClient(OGCSOSCopierConfig.DEST_SOS_URL);
                var request = new RestRequest(Method.POST);
                request.AddHeader("Authorization", "asdasdasdl");
                request.AddParameter("application/xml", reqcontent, ParameterType.RequestBody);

                IRestResponse response = client.Execute(request);
                var           content  = response.Content;

                if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
                {
                    var err = Util.Common.GetOGCExceptionText(content);
                    throw new Exception("BadRequest " + err);
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    var err = Util.Common.GetOGCExceptionText(content);
                    throw new Exception("Unauthorized " + err);
                }

                Util.Loggers.InsertSensorRequestsLogger.Debug(reqcontent + "\n RESPONSE : \n" + Util.ObjectSerializer.PrintXML(content));

                InsertSensorResponseType insertSensorResponse = new InsertSensorResponseType();

                XmlSerializer serializer = new XmlSerializer(typeof(InsertSensorResponseType));
                object        resultXml  = null;
                using (TextReader reader = new StringReader(content))
                {
                    resultXml = serializer.Deserialize(reader);
                }

                if (resultXml != null)
                {
                    if (resultXml is InsertSensorResponseType)
                    {
                        insertSensorResponse = (InsertSensorResponseType)resultXml;
                        res = true;
                    }
                    //else if (resultXml is ExceptionReport)
                    //{
                    //    ExceptionReport expReport = (ExceptionReport)resultXml;
                    //}
                }

                result = new Tuple <bool, string>(res, identifier);
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp);
                result = new Tuple <bool, string>(false, identifier);
            }

            return(result);
        }