コード例 #1
0
        public override void FixtureSetup()
        {
            base.FixtureSetup();
            context.BaseUrl = "http://*****:*****@www.brockmann-consult.de/bc-wps/wps/calvalus";
            providerSecret.Proxy      = true;

            processIdentifier = "com.terradue.wps_oozie.process.OozieAbstractAlgorithm";
            processVersion    = "1.0.0";

            processSecretIdentifier = "urbantep-local~1.0~Subset";
            processSecretVersion    = "1.0";

            provider.Store();
            provider.StoreProcessOfferings();

            providerSecret.Store();
            providerSecret.StoreProcessOfferings();
        }
コード例 #2
0
        /// <summary>
        /// Tos the entity.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="context">Context.</param>
        public WpsProvider ToEntity(IfyContext context, WpsProvider input)
        {
            WpsProvider entity = (input == null ? new WpsProvider(context) : input);

            entity.Identifier = this.Identifier;
            entity.Name       = this.Name;
            if (!string.IsNullOrEmpty(this.DomainId))
            {
                entity.DomainId = Int32.Parse(this.DomainId);
            }
            entity.BaseUrl      = this.Url;
            entity.Proxy        = this.Proxy;
            entity.Contact      = this.Contact;
            entity.AutoSync     = this.AutoSync;
            entity.StageResults = this.StageResults;
            if (this.Tags != null && this.Tags.Count > 0)
            {
                entity.Tags = "";
                foreach (var tag in this.Tags)
                {
                    entity.AddTag(tag);
                }
            }
            else
            {
                entity.Tags = null;
            }

            return(entity);
        }
コード例 #3
0
        public void UpdateProcessOfferings()
        {
            WpsProvider provider = CreateProvider("test-wps-1-sync", "test provider 1", "http://dem.terradue.int:8080/wps/WebProcessingService", false);

            provider.AddTag("mytag1");
            List <WpsProcessOffering> services = provider.GetWpsProcessOfferingsFromRemote();

            Assert.AreEqual(1, services.Count());
            var service = services[0];

            foreach (var s in services)
            {
                s.Store();
            }
            Assert.True(!string.IsNullOrEmpty(service.Tags) && service.Tags.Contains("mytag1"));
            provider.AddTag("mytag2");//mytag2 is added only for new services
            provider.UpdateProcessOfferings();
            Assert.True(!string.IsNullOrEmpty(service.Tags) && service.Tags.Contains("mytag1") && !service.Tags.Contains("mytag2"));
            service.Delete();
            provider.UpdateProcessOfferings();
            EntityList <WpsProcessOffering> dbProcesses = provider.GetWpsProcessOfferings(false);

            Assert.AreEqual(1, dbProcesses.Count());
            service = dbProcesses.Items.First();
            Assert.True(!string.IsNullOrEmpty(service.Tags) && service.Tags.Contains("mytag1") && service.Tags.Contains("mytag2"));
            provider.Delete();
        }
コード例 #4
0
        private WpsProcessOffering CreateProcess(bool proxy)
        {
            WpsProvider        provider = CreateProvider("test-wps-" + proxy.ToString(), "test provider " + (proxy ? "p" : "np"), "http://dem.terradue.int:8080/wps/WebProcessingService", proxy);
            WpsProcessOffering process  = CreateProcess(provider, "com.test.provider", "test provider " + (proxy ? "p" : "np"), true);

            return(process);
        }
コード例 #5
0
ファイル: Rates.Service.cs プロジェクト: Terradue/DotNetTep
        public object Get(RatesForProviderRequestTep request)
        {
            var             context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);
            List <WebRates> result  = new List <WebRates>();

            try {
                context.Open();
                context.LogInfo(this, string.Format("/cr/wps/{{identifier}}/rates GET, identifier='{0}'", request.ProviderIdentifier));

                // Load the complete request
                var httpRequest = HttpContext.Current.Request;

                var service = WpsProvider.FromIdentifier(context, request.ProviderIdentifier);

                EntityList <Rates> rates = new EntityList <Rates>(context);
                rates.SetFilter("EntityId", service.Id.ToString());
                rates.SetFilter("EntityTypeId", EntityType.GetEntityType(typeof(WpsProvider)).Id.ToString());
                rates.Load();

                foreach (var rate in rates.GetItemsAsList())
                {
                    result.Add(new WebRates(rate));
                }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
コード例 #6
0
        public void CreateWpsServiceFromRemote()
        {
            WpsProvider provider = CreateProvider("test-wps-1-remote", "test provider 1", "http://dem.terradue.int:8080/wps/WebProcessingService", false);
            List <WpsProcessOffering> services = provider.GetWpsProcessOfferingsFromRemote();

            Assert.AreEqual(1, services.Count());
            provider.Delete();
        }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Terradue.WebService.Model.WebWpsProvider"/> class.
 /// </summary>
 /// <param name="entity">Entity.</param>
 public WebWpsProvider(WpsProvider entity) : base(entity)
 {
     this.Url          = entity.BaseUrl;
     this.Proxy        = entity.Proxy;
     this.Contact      = entity.Contact;
     this.AutoSync     = entity.AutoSync;
     this.StageResults = entity.StageResults;
     this.Tags         = entity.GetTagsAsList();
 }
コード例 #8
0
        public void SearchWpsServicesByQ()
        {
            var         uid      = Guid.NewGuid().ToString();
            WpsProvider provider = CreateProvider(uid, "test provider", "http://gpod.eo.esa.int/wps?service=WPS&version=1.0.0&request=GetCapabilities", true);

            provider.UpdateProcessOfferings(true);

            EntityList <WpsProcessOffering> wpsProcessList = new EntityList <WpsProcessOffering>(context);

            wpsProcessList.Template.Provider = provider;
            wpsProcessList.Load();

            var nbprocesses = wpsProcessList.Items.Count();

            WpsProcessOffering service1 = wpsProcessList.Items.First();

            service1.Identifier  = "searchbyQidentifier";
            service1.Name        = "searchbyQname";
            service1.Description = "searchbyQdescription";
            service1.Store();

            EntityList <WpsProcessOffering> services = new EntityList <WpsProcessOffering>(context);

            var parameters = new NameValueCollection();

            parameters.Set("count", (nbprocesses + 1) + "");

            IOpenSearchResultCollection osr = ose.Query(services, parameters);

            parameters.Set("q", "searchbyNoQidentifier");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(0, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("q", "searchbyQ");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(1, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("q", "searchbyQidentifier");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(1, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("q", "searchbyQname");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(1, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("q", "searchbyQdescription");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(1, osr.Items.Count());

            provider.Delete();
        }
コード例 #9
0
        public void CreateWpsServiceFromRemoteWithTags()
        {
            WpsProvider provider = CreateProvider("test-wps-1-tag", "test provider 1", "http://dem.terradue.int:8080/wps/WebProcessingService", false);

            provider.AddTag("mytag");
            List <WpsProcessOffering> services = provider.GetWpsProcessOfferingsFromRemote();

            Assert.AreEqual(1, services.Count());
            Assert.True(!string.IsNullOrEmpty(services[0].Tags) && services[0].Tags.Contains("mytag"));
            provider.Delete();
        }
コード例 #10
0
        private WpsProcessOffering CreateProcess(WpsProvider provider, string identifier, string name)
        {
            WpsProcessOffering process = new WpsProcessOffering(context);

            process.Name             = name;
            process.Description      = name;
            process.RemoteIdentifier = identifier;
            process.Identifier       = Guid.NewGuid().ToString();
            process.Url      = provider.BaseUrl;
            process.Version  = "1.0.0";
            process.Provider = provider;
            return(process);
        }
コード例 #11
0
        public void CreateWpsServiceFromRemoteWithDomain()
        {
            Domain domainpub = new Domain(context);

            domainpub.Identifier = "domainPublic";
            domainpub.Kind       = DomainKind.Public;
            domainpub.Store();

            WpsProvider provider = CreateProvider("test-wps-1-domain", "test provider 1", "http://dem.terradue.int:8080/wps/WebProcessingService", false);

            provider.Domain = domainpub;
            List <WpsProcessOffering> services = provider.GetWpsProcessOfferingsFromRemote();

            Assert.AreEqual(1, services.Count());
            Assert.True(services[0].DomainId == domainpub.Id);
            provider.Delete();
        }
コード例 #12
0
        private WpsProvider CreateProvider(string identifier, string name, string url, bool proxy)
        {
            WpsProvider provider;

            provider             = new WpsProvider(context);
            provider.Identifier  = identifier;
            provider.Name        = name;
            provider.Description = name;
            provider.BaseUrl     = url;
            provider.Proxy       = proxy;
            try{
                provider.Store();
            }catch (Exception e) {
                throw e;
            }
            return(provider);
        }
コード例 #13
0
        public void GetProcessOfferingEntityList()
        {
            WpsProvider        provider = CreateProvider("test-wps-1", "test provider 1", "http://dem.terradue.int:8080/wps/WebProcessingService", false);
            WpsProcessOffering process  = CreateProcess(provider, "com.test.provider.1", "test provider 1", false);

            process.Store();
            Assert.IsFalse(process.Available);
            WpsProvider        provider2 = CreateProvider("test-wps-2", "test provider 2", "http://dem.terradue.int:8080/wps/WebProcessingService", false);
            WpsProcessOffering process2  = CreateProcess(provider2, "com.test.provider.2", "test provider 2", false);

            process2.Store();
            Assert.IsFalse(process2.Available);
            EntityList <WpsProcessOffering> processes = provider.GetWpsProcessOfferings(false);

            Assert.That(processes.Count == 1);
            provider.Delete();
            provider2.Delete();
        }
コード例 #14
0
ファイル: CloudWpsFactory.cs プロジェクト: Terradue/DotNetTep
        /// \xrefitem rmodp "RM-ODP" "RM-ODP Documentation"
        public WpsProcessOfferingTep CreateWpsProcessOfferingForOne(string vmId, string processId)
        {
            WpsProvider wps = this.CreateWpsProviderForOne(vmId);

            foreach (WpsProcessOffering process in wps.GetWpsProcessOfferingsFromRemote())
            {
                context.LogDebug(this, "Get process -- " + process.RemoteIdentifier);
                if (process.RemoteIdentifier.Equals(processId))
                {
                    if (process.Domain == null && wps.Domain != null)
                    {
                        process.Domain = wps.Domain;
                    }
                    process.Available = true;
                    return(process as WpsProcessOfferingTep);
                }
            }

            return(null);
        }
コード例 #15
0
ファイル: Rates.Service.cs プロジェクト: Terradue/DotNetTep
        public object Delete(DeleteRatesFromProviderRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/cr/wps/{{providerIdentifier}}/rates/{{id}} DELETE providerIdentifier='{0}', Id='{1}'", request.ProviderIdentifier, request.Id));

                var   service = WpsProvider.FromIdentifier(context, request.ProviderIdentifier);
                Rates rate    = Rates.FromId(context, request.Id);
                context.LogInfo(this, string.Format("Deleting rates {0} of service {1}", rate.Identifier, service.Identifier));
                rate.Delete();

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(true));
        }
コード例 #16
0
        public void SearchWpsServicesByTags()
        {
            WpsProvider        provider = CreateProvider("test-wps-search-1", "test provider 1", "http://dem.terradue.int:8080/wps/WebProcessingService", false);
            WpsProcessOffering process  = CreateProcess(provider, "com.test.provider.1", "test provider 1", true);

            process.AddTag("mytag");
            process.AddTag("mytag1");
            process.AddTag("mytag2");
            process.Store();

            EntityList <WpsProcessOffering> services = new EntityList <WpsProcessOffering>(context);

            var parameters = new NameValueCollection();

            parameters.Set("tag", "mytag");

            IOpenSearchResultCollection osr = ose.Query(services, parameters);

            Assert.AreEqual(1, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("tag", "tag");

            osr = ose.Query(services, parameters);
            Assert.AreEqual(0, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("tag", "tag,mytag");

            osr = ose.Query(services, parameters);
            Assert.AreEqual(0, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("tag", "mytag,mytag1");

            osr = ose.Query(services, parameters);
            Assert.AreEqual(1, osr.Items.Count());

            provider.Delete();
        }
コード例 #17
0
        public void LoadWpsJobStatus()
        {
            WpsProvider provider = CreateProvider("planetek", "planetek", "http://urban-tep.planetek.it/wps/WebProcessingService", true);

            provider.Store();
            WpsProcessOffering process = CreateProcess(provider, "it.planetek.wps.extension.Processor", "Title of the processor");

            process.Store();
            WpsJob job = new WpsJob(context);

            job.WpsId          = process.Identifier;
            job.StatusLocation = "http://urban-tep.planetek.it/wps/RetrieveResultServlet?id=72ed982a-8522-4c02-bb71-77f4c22a7808";

            var jobresponse  = job.GetStatusLocationContent();
            var execResponse = jobresponse as ExecuteResponse;

            job.UpdateStatusFromExecuteResponse(execResponse);

            //get job recast response
            execResponse = ProductionResultHelper.GetWpsjobRecastResponse(context, job, execResponse);
            Assert.True(true);
        }
コード例 #18
0
ファイル: Rates.Service.cs プロジェクト: Terradue/DotNetTep
        public object Post(AddRatesForProviderRequestTep request)
        {
            var      context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);
            WebRates result  = null;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/cr/wps/{{providerIdentifier}}/rates POST providerIdentifier='{0}', Identifier='{1}', Unit='{2}', Cost='{3}'", request.ProviderIdentifier, request.Identifier, request.Unit, request.Cost));

                var   service = WpsProvider.FromIdentifier(context, request.ProviderIdentifier);
                Rates rate    = request.ToEntity(context, service);
                rate.Store();

                result = new WebRates(rate);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
コード例 #19
0
ファイル: Proxy.Service.cs プロジェクト: Terradue/DotNetTep
        public object Get(ProxyWpsJobSearchRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

            context.Open();
            context.LogInfo(this, string.Format("/proxy/wps/{{jobid}}/search GET jobid='{0}'", request.jobid));

            WpsJob wpsjob = WpsJob.FromIdentifier(context, request.jobid);

            if (string.IsNullOrEmpty(wpsjob.StatusLocation))
            {
                throw new Exception("Invalid Status Location");
            }

            context.LogDebug(this, string.Format("Wps Proxy search for wpsjob {0}", wpsjob.Identifier));

            HttpWebRequest executeHttpRequest;

            if (wpsjob.Provider != null)
            {
                executeHttpRequest = wpsjob.Provider.CreateWebRequest(wpsjob.StatusLocation);
            }
            else
            {
                NetworkCredential credentials = null;
                var uri = new UriBuilder(wpsjob.StatusLocation);
                if (!string.IsNullOrEmpty(uri.UserName) && !string.IsNullOrEmpty(uri.Password))
                {
                    credentials = new NetworkCredential(uri.UserName, uri.Password);
                }
                executeHttpRequest = WpsProvider.CreateWebRequest(wpsjob.StatusLocation, credentials, context.Username);
            }

            if (wpsjob.StatusLocation.Contains("gpod.eo.esa.int"))
            {
                executeHttpRequest.Headers.Add("X-UserID", context.GetConfigValue("GpodWpsUser"));
            }
            OpenGis.Wps.ExecuteResponse execResponse = null;
            try {
                context.LogDebug(this, string.Format("Wps proxy - exec response requested - {0}", executeHttpRequest.Address.AbsoluteUri));
                using (var response = executeHttpRequest.GetResponse())
                    using (var stream = response.GetResponseStream())
                        execResponse = (OpenGis.Wps.ExecuteResponse) new System.Xml.Serialization.XmlSerializer(typeof(OpenGis.Wps.ExecuteResponse)).Deserialize(stream);
                context.LogDebug(this, string.Format("Wps proxy - exec response OK"));
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
            }
            if (execResponse == null)
            {
                throw new Exception("Unable to get execute response from proxied job");
            }

            execResponse.statusLocation = context.BaseUrl + "/wps/RetrieveResultServlet?id=" + wpsjob.Identifier;
            context.LogDebug(this, string.Format("Proxy WPS - uri: " + execResponse.statusLocation));

            AtomFeed feed = new AtomFeed();

            if (execResponse.ProcessOutputs != null)
            {
                foreach (OutputDataType output in execResponse.ProcessOutputs)
                {
                    if (output.Identifier != null && output.Identifier.Value != null && output.Identifier.Value.Equals("result_metadata"))
                    {
                        context.LogDebug(this, string.Format("Wps proxy - metadata"));
                        if (output.Item is OutputReferenceType)
                        {
                            var            reference = output.Item as OutputReferenceType;
                            HttpWebRequest atomRequest;
                            if (wpsjob.Provider != null)
                            {
                                atomRequest = wpsjob.Provider.CreateWebRequest(reference.href);
                            }
                            else
                            {
                                NetworkCredential credentials = null;
                                var uri = new UriBuilder(reference.href);
                                if (!string.IsNullOrEmpty(uri.UserName) && !string.IsNullOrEmpty(uri.Password))
                                {
                                    credentials = new NetworkCredential(uri.UserName, uri.Password);
                                }
                                atomRequest = WpsProvider.CreateWebRequest(reference.href, credentials, context.Username);
                            }
                            feed = CreateFeedForMetadata(atomRequest);
                        }
                        else if (output.Item is DataType)
                        {
                            var            item      = ((DataType)(output.Item)).Item as ComplexDataType;
                            var            reference = item.Reference as OutputReferenceType;
                            HttpWebRequest atomRequest;
                            if (wpsjob.Provider != null)
                            {
                                atomRequest = wpsjob.Provider.CreateWebRequest(reference.href);
                            }
                            else
                            {
                                NetworkCredential credentials = null;
                                var uri = new UriBuilder(reference.href);
                                if (!string.IsNullOrEmpty(uri.UserName) && !string.IsNullOrEmpty(uri.Password))
                                {
                                    credentials = new NetworkCredential(uri.UserName, uri.Password);
                                }
                                atomRequest = WpsProvider.CreateWebRequest(reference.href, credentials, context.Username);
                            }
                            feed = CreateFeedForMetadata(atomRequest);
                        }
                    }
                    else
                    {
                        if (output.Item is DataType && ((DataType)(output.Item)).Item != null)
                        {
                            var item = ((DataType)(output.Item)).Item as ComplexDataType;
                            if (item.Any != null && item.Any [0].LocalName != null)
                            {
                                if (item.Any [0].LocalName.Equals("RDF"))
                                {
                                    context.LogDebug(this, string.Format("Wps proxy - RDF"));
                                    feed = CreateFeedForRDF(item.Any [0], request.jobid, context.BaseUrl);
                                }
                                else if (item.Any [0].LocalName.Equals("metalink"))
                                {
                                    context.LogDebug(this, string.Format("Wps proxy - metalink"));
                                    feed = CreateFeedForMetalink(item.Any [0], request.jobid, context.BaseUrl, context);
                                }
                            }
                        }
                    }
                }
            }

            /* Proxy id + add self */
            foreach (var item in feed.Items)
            {
                var self   = context.BaseUrl + "/proxy/wps/" + wpsjob.Identifier + "/search?uid=" + HttpUtility.UrlEncode(item.Id);
                var search = context.BaseUrl + "/proxy/wps/" + wpsjob.Identifier + "/description";
                item.Id = self;
                item.Links.Add(Terradue.ServiceModel.Syndication.SyndicationLink.CreateSelfLink(new Uri(self), "application/atom+xml"));
                item.Links.Add(new Terradue.ServiceModel.Syndication.SyndicationLink(new Uri(search), "search", "OpenSearch Description link", "application/opensearchdescription+xml", 0));
            }

            feed.Id = wpsjob.StatusLocation;

            var  ose          = MasterCatalogue.OpenSearchEngine;
            Type responseType = OpenSearchFactory.ResolveTypeFromRequest(HttpContext.Current.Request.QueryString, HttpContext.Current.Request.Headers, ose);
            var  ext          = ose.GetFirstExtensionByTypeAbility(responseType);

            var osfeed = new AtomFeedOpenSearchable(feed);
            IOpenSearchResultCollection osr = ose.Query(osfeed, HttpContext.Current.Request.QueryString, responseType);

            var osrDesc = new Uri(context.BaseUrl + "/proxy/wps/" + wpsjob.Identifier + "/description");

            osr.Links.Add(new Terradue.ServiceModel.Syndication.SyndicationLink(osrDesc, "search", "OpenSearch Description link", "application/opensearchdescription+xml", 0));

            context.Close();
            return(new HttpResult(osr.SerializeToString(), osr.ContentType));
        }
コード例 #20
0
ファイル: Proxy.Service.cs プロジェクト: Terradue/DotNetTep
        private AtomFeed CreateFeedForMetalink(XmlNode any, string identifier, string baseurl, IfyContext context)
        {
            OwsContextAtomFeed         feed    = new OwsContextAtomFeed();
            List <OwsContextAtomEntry> entries = new List <OwsContextAtomEntry> ();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(any.OuterXml);
            XmlNamespaceManager xmlns = new XmlNamespaceManager(doc.NameTable);

            xmlns.AddNamespace("ml", "http://www.metalinker.org");

            var onlineResource = doc.SelectNodes("ml:metalink/ml:files/ml:file/ml:resources/ml:url", xmlns);
            var createddate    = doc.SelectSingleNode("ml:metalink/ml:files/ml:file/ml:releasedate", xmlns).InnerText;

            var self   = baseurl + "/proxy/wps/" + identifier + "/search";
            var search = baseurl + "/proxy/wps/" + identifier + "/description";

            feed.Id    = self;
            feed.Title = new Terradue.ServiceModel.Syndication.TextSyndicationContent("Wps job results");
            feed.Date  = new DateTimeInterval {
                StartDate = Convert.ToDateTime(createddate),
                EndDate   = Convert.ToDateTime(createddate)
            };

            foreach (XmlNode node in onlineResource)
            {
                string url = node.InnerText;
                context.LogDebug(this, "Url = " + url);
                Uri remoteUri             = new Uri(url);
                OwsContextAtomEntry entry = new OwsContextAtomEntry();

                //link is an OWS context, we add it as is
                Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter();
                if (url.Contains(".atom"))
                {
                    NetworkCredential credentials = null;
                    var uri = new UriBuilder(url);
                    if (!string.IsNullOrEmpty(uri.UserName) && !string.IsNullOrEmpty(uri.Password))
                    {
                        credentials = new NetworkCredential(uri.UserName, uri.Password);
                    }
                    HttpWebRequest atomRequest = WpsProvider.CreateWebRequest(url, credentials, context.Username);
                    atomRequest.Accept    = "*/*";
                    atomRequest.UserAgent = "Terradue TEP";

                    try {
                        using (var atomResponse = (HttpWebResponse)atomRequest.GetResponse()) {
                            using (var atomResponseStream = new MemoryStream()) {
                                using (var stream = atomResponse.GetResponseStream())
                                    stream.CopyTo(atomResponseStream);
                                atomResponseStream.Seek(0, SeekOrigin.Begin);
                                var sr = XmlReader.Create(atomResponseStream);
                                atomFormatter.ReadFrom(sr);
                                sr.Close();
                            }
                        }
                    } catch (Exception e) {
                        context.LogError(this, e.Message, e);
                        throw e;
                    }
                    return(new AtomFeed(atomFormatter.Feed));
                }
                //we build the OWS context
                entry.Id    = node.InnerText.Contains("/") ? node.InnerText.Substring(node.InnerText.LastIndexOf("/") + 1) : node.InnerText;
                entry.Title = new Terradue.ServiceModel.Syndication.TextSyndicationContent(remoteUri.AbsoluteUri);

                entry.PublishDate     = new DateTimeOffset(Convert.ToDateTime(createddate));
                entry.LastUpdatedTime = new DateTimeOffset(Convert.ToDateTime(createddate));

                entry.Date = new DateTimeInterval {
                    StartDate = Convert.ToDateTime(createddate),
                    EndDate   = Convert.ToDateTime(createddate)
                };

                entry.ElementExtensions.Add("identifier", OwcNamespaces.Dc, entry.Id);
                entry.Links.Add(Terradue.ServiceModel.Syndication.SyndicationLink.CreateMediaEnclosureLink(remoteUri, "application/octet-stream", 0));

                List <OwcOffering> offerings = new List <OwcOffering> ();
                OwcOffering        offering  = new OwcOffering();
                OwcContent         content   = new OwcContent();
                content.Url = remoteUri;
                string extension = remoteUri.AbsoluteUri.Substring(remoteUri.AbsoluteUri.LastIndexOf(".") + 1);

                switch (extension.ToLower())
                {
                case "gif":
                    content.Type  = "image/gif";
                    offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/gif";
                    break;

                case "gtiff":
                    content.Type  = "image/tiff";
                    offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/geotiff";
                    break;

                case "jpeg":
                    content.Type  = "image/jpg";
                    offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/jpg";
                    break;

                case "png":
                    content.Type  = "image/png";
                    offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/png";
                    break;

                case "tgz":
                    content.Type  = "application/tar+gzip";
                    offering.Code = "http://www.opengis.net/spec/owc-atom/1.0/req/tgz";
                    break;

                default:
                    content.Type  = "application/octet-stream";
                    offering.Code = "";
                    break;
                }

                List <OwcContent> contents = new List <OwcContent> ();
                contents.Add(content);
                offering.Contents = contents.ToArray();
                offerings.Add(offering);
                entry.Offerings = offerings;

                entries.Add(entry);
            }
            feed.Items = entries;

            AtomFeed atomfeed = new AtomFeed(feed);

            atomfeed.Title       = feed.Title;
            atomfeed.Description = feed.Description;

            var urib = new UriBuilder(baseurl);

            urib.Path += "/proxy/wps/" + identifier + "/description";
            atomfeed.Links.Add(new Terradue.ServiceModel.Syndication.SyndicationLink(urib.Uri, "search", "OpenSearch Description link", "application/opensearchdescription+xml", 0));

            return(atomfeed);
        }
コード例 #21
0
        /// <summary>
        /// Get list of Processing Services from Atom Feed
        /// Each Item of the feed contains a Describe Process url
        /// </summary>
        /// <param name="context"></param>
        /// <param name="feed"></param>
        /// <param name="createProviderIfNotFound"></param>
        /// <returns></returns>
        public static List <WpsProcessOffering> GetRemoteWpsProcessingOfferingsFromUrl(IfyContext context, string url, bool createProviderIfNotFound)
        {
            var remoteProcesses = new List <WpsProcessOffering>();

            var items = GetRemoteWpsServiceEntriesFromUrl(context, url);

            foreach (OwsContextAtomEntry item in items)
            {
                var wps = GetWpsProcessOfferingFromProcessDescriptionAtomFeed(context, item);
                if (wps == null)
                {
                    continue;
                }

                var         describeProcessUrl = wps.Url;
                var         providerBaseUrl    = describeProcessUrl.Substring(0, describeProcessUrl.LastIndexOf("/"));
                var         processIdentifier  = describeProcessUrl.Substring(describeProcessUrl.LastIndexOf("/") + 1);
                WpsProvider wpsprovider        = null;
                try {
                    wpsprovider = WpsProvider.FromBaseUrl(context, providerBaseUrl);
                } catch (System.Exception) {
                    if (createProviderIfNotFound)
                    {
                        var urip = new Uri(providerBaseUrl);
                        wpsprovider            = new WpsProvider(context);
                        wpsprovider.Identifier = urip.AbsolutePath.Contains("/wps3/processes") ?
                                                 urip.Host + urip.AbsolutePath.Substring(0, urip.AbsolutePath.IndexOf("/wps3/processes")).Replace("/", ".") :
                                                 Guid.NewGuid().ToString();
                        wpsprovider.Name = urip.AbsolutePath.Contains("/wps3/processes") ?
                                           urip.Host + urip.AbsolutePath.Substring(0, urip.AbsolutePath.IndexOf("/wps3/processes")).Replace("/", ".") :
                                           urip.Host + urip.AbsolutePath.Replace("/", ".");
                        wpsprovider.BaseUrl      = providerBaseUrl;
                        wpsprovider.StageResults = true;
                        wpsprovider.Proxy        = true;
                        wpsprovider.Store();

                        wpsprovider.GrantPermissionsToAll();
                    }
                }
                if (wpsprovider != null)
                {
                    wps.Provider = wpsprovider;
                }

                //case WPS 3.0
                if (IsWPS3(describeProcessUrl))
                {
                    try
                    {
                        WpsProcessOffering process = GetProcessingFromDescribeProcessWps3(context, describeProcessUrl);
                        wps.RemoteIdentifier = process.RemoteIdentifier;
                        if (string.IsNullOrEmpty(wps.Name))
                        {
                            wps.Name = process.Name;
                        }
                        if (string.IsNullOrEmpty(wps.Description))
                        {
                            wps.Description = process.Description;
                        }
                        if (string.IsNullOrEmpty(wps.Version))
                        {
                            wps.Version = process.Version;
                        }
                    }catch (System.Exception e) {
                        context.LogError(context, "Error with url '" + describeProcessUrl + "' : " + e.Message);
                        wps = null;
                    }
                }
                if (wps == null)
                {
                    continue;
                }
                remoteProcesses.Add(wps);
            }
            return(remoteProcesses);
        }
コード例 #22
0
ファイル: CloudWpsFactory.cs プロジェクト: Terradue/DotNetTep
        /// <summary>
        /// Creates the wps provider from VM (OpenNebula).
        /// </summary>
        /// <returns>The wps provider</returns>
        /// <param name="vm">Virtual machine object.</param>
        public static WpsProvider CreateWpsProviderForOne(IfyContext context, VM vm, NameValueCollection parameters = null)
        {
            context.LogDebug(context, "VM id = " + vm.ID);
            context.LogDebug(context, "VM name = " + vm.GNAME);
            WpsProvider wps = new WpsProvider(context);

            wps.Name        = vm.NAME;
            wps.Identifier  = "one-" + vm.ID;
            wps.Description = vm.NAME + " by " + vm.UNAME + " from laboratory " + vm.GNAME;
            wps.Proxy       = true;
            wps.IsSandbox   = true;
            wps.Tags        = "";

            try {
                var user = UserTep.FromId(context, context.UserId);
                wps.Domain = user.GetPrivateDomain();
            } catch (Exception e) {
                context.LogError(wps, e.Message);
            }

            XmlNode[] user_template = (XmlNode[])vm.USER_TEMPLATE;
            bool      isWPS = false;
            string    wpsPort = "8080", wpsPath = "wps/WebProcessingService", nic = "";

            context.LogDebug(wps, "Loading user template");
            foreach (XmlNode nodeUT in user_template)
            {
                switch (nodeUT.Name)
                {
                case "WPS":
                    context.LogDebug(wps, string.Format("WPS found : {0} - {1}", vm.ID, vm.GNAME));
                    isWPS = true;
                    break;

                case "OPERATIONAL":
                    context.LogDebug(wps, string.Format("Operational VM found : {0} - {1}", vm.ID, vm.GNAME));
                    wps.IsSandbox = false;
                    break;

                case "TAGS":
                    context.LogDebug(wps, string.Format("Tags found : {0} - {1} : {2}", vm.ID, vm.GNAME, nodeUT.InnerText));
                    var tags = nodeUT.InnerText.Split(',').ToList();
                    if (tags != null)
                    {
                        foreach (var tag in tags)
                        {
                            wps.AddTag(tag);
                        }
                    }
                    break;

                case "LOGO":
                    context.LogDebug(wps, string.Format("Logo found : {0} - {1} : {2}", vm.ID, vm.GNAME, nodeUT.InnerText));
                    wps.IconUrl = nodeUT.InnerText;
                    break;

                case "WPS_PORT":
                    context.LogDebug(wps, string.Format("Wps Port found : {0} - {1} : {2}", vm.ID, vm.GNAME, nodeUT.InnerText));
                    wpsPort = nodeUT.InnerText;
                    break;

                case "WPS_PATH":
                    context.LogDebug(wps, string.Format("Wps Path found : {0} - {1} : {2}", vm.ID, vm.GNAME, nodeUT.InnerText));
                    wpsPath = nodeUT.InnerText;
                    break;

                default:
                    break;
                }
            }

            context.LogDebug(wps, "Loading template");
            foreach (XmlNode nodeT in (XmlNode[])vm.TEMPLATE)
            {
                context.LogDebug(context, "node name = " + nodeT.Name);
                switch (nodeT.Name)
                {
                case "NIC":
                    nic = nodeT["IP"].InnerText;
                    break;

                default:
                    break;
                }
            }

            wps.BaseUrl = String.Format("http://{0}:{1}/{2}", nic, wpsPort, wpsPath);
            context.LogDebug(context, "wpsbaseurl = " + wps.BaseUrl);

            if (isWPS)
            {
                //check query parameters
                if (parameters != null)
                {
                    //case sandbox
                    if (parameters["sandbox"] != null)
                    {
                        switch (parameters["sandbox"])
                        {
                        case "true":
                            if (!wps.IsSandbox)
                            {
                                return(null);
                            }
                            break;

                        case "false":
                            if (wps.IsSandbox)
                            {
                                return(null);
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    //case hostname
                    if (parameters["hostname"] != null)
                    {
                        var uriHost = new UriBuilder(nic);
                        var r       = new System.Text.RegularExpressions.Regex(parameters["hostname"]);
                        var m       = r.Match(uriHost.Host);
                        if (!m.Success)
                        {
                            return(null);
                        }
                    }
                    //case tags
                    if (parameters["tag"] != null)
                    {
                        if (wps.Tags == null || !wps.Tags.Contains(parameters["tag"]))
                        {
                            return(null);
                        }
                    }
                }
            }
            return(wps);
        }
コード例 #23
0
        public void SearchWpsServicesByAvailability()
        {
            var         uid      = Guid.NewGuid().ToString();
            WpsProvider provider = CreateProvider(uid, "test provider", "http://gpod.eo.esa.int/wps?service=WPS&version=1.0.0&request=GetCapabilities", false);

            provider.UpdateProcessOfferings();

            EntityList <WpsProcessOffering> wpsProcessList = new EntityList <WpsProcessOffering>(context);

            wpsProcessList.Template.Provider = provider;
            wpsProcessList.Load();

            var nbprocesses = wpsProcessList.Items.Count();

            EntityList <WpsProcessOffering> services = new EntityList <WpsProcessOffering>(context);

            var parameters = new NameValueCollection();

            parameters.Set("count", (nbprocesses + 1) + "");

            IOpenSearchResultCollection osr = ose.Query(services, parameters);

            Assert.AreEqual(nbprocesses, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("available", "all");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(nbprocesses, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("available", "false");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(nbprocesses, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("available", "true");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(0, osr.Items.Count());

            WpsProcessOffering service1 = wpsProcessList.Items.First();

            service1.Available = true;
            service1.Store();

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("available", "all");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(nbprocesses, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("available", "false");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(nbprocesses - 1, osr.Items.Count());

            services = new EntityList <WpsProcessOffering>(context);
            parameters.Set("available", "true");
            osr = ose.Query(services, parameters);
            Assert.AreEqual(1, osr.Items.Count());

            provider.Delete();
        }