コード例 #1
0
ファイル: CloudWpsFactory.cs プロジェクト: Terradue/DotNetTep
        /// <summary>
        /// Gets the wps process offering from DB or from cloud
        /// </summary>
        /// <returns>The wps process offering.</returns>
        /// <param name="identifier">Identifier.</param>
        public static WpsProcessOfferingTep GetWpsProcessOffering(IfyContext context, string identifier)
        {
            WpsProcessOfferingTep wps = null;

            try {
                //wps is stored in DB
                wps = WpsProcessOfferingTep.FromIdentifier(context, identifier);
            } catch (UnauthorizedAccessException e) {
                throw e;
            } catch (Exception) {
                //wps is not stored in DB
                string[] identifierParams = identifier.Split("-".ToCharArray());
                if (identifierParams.Length == 3)
                {
                    switch (identifierParams[0])
                    {
                    //wps is stored in OpenNebula Cloud Provider
                    case "one":
                        wps = new CloudWpsFactory(context).CreateWpsProcessOfferingForOne(identifierParams[1], identifierParams[2]);
                        break;

                    default:
                        break;
                    }
                }
            }
            if (wps == null)
            {
                throw new Exception("Unknown identifier");
            }
            return(wps);
        }
コード例 #2
0
        public static new WpsProcessOfferingTep FromIdentifier(IfyContext context, string identifier)
        {
            var p = new WpsProcessOfferingTep(context);

            p.Identifier = identifier;
            p.Load();
            return(p);
        }
コード例 #3
0
        public static WpsProcessOfferingTep Copy(WpsProcessOfferingTep service, IfyContext context)
        {
            WpsProcessOfferingTep newservice = new WpsProcessOfferingTep(context);

            newservice.OwnerId             = context.UserId;
            newservice.UserId              = context.UserId;
            newservice.Identifier          = Guid.NewGuid().ToString();
            newservice.Name                = service.Name;
            newservice.Description         = service.Description;
            newservice.Url                 = service.Url;
            newservice.Version             = service.Version;
            newservice.IconUrl             = service.IconUrl;
            newservice.ValidationUrl       = service.ValidationUrl;
            newservice.TermsConditionsUrl  = service.TermsConditionsUrl;
            newservice.TermsConditionsText = service.TermsConditionsText;
            newservice.Domain              = service.Domain;
            newservice.Tags                = service.Tags;
            newservice.RemoteIdentifier    = service.RemoteIdentifier;
            newservice.Available           = service.Available;
            newservice.Commercial          = service.Commercial;
            newservice.Provider            = service.Provider;
            newservice.Geometry            = service.Geometry;
            return(newservice);
        }
コード例 #4
0
        /// <summary>
        /// Synchronize WPS services
        /// </summary>
        /// <param name="context"></param>
        /// <param name="entry"></param>
        /// <param name="domain"></param>
        public static void SyncWpsServices(IfyContext context, OwsContextAtomEntry entry, Domain domain = null)
        {
            if (entry.Offerings == null)
            {
                return;
            }

            var offering = entry.Offerings.First(p => p.Code == "http://www.opengis.net/spec/owc/1.0/req/atom/wps");

            if (offering == null)
            {
                return;
            }

            string wpsDomainIdentifier = null;
            string wpsTags             = null;

            //get domain and tag for app
            var op = offering.Operations.FirstOrDefault(o => o.Code == "ListProcess");

            if (op != null && op.Href != null)
            {
                var nvc = HttpUtility.ParseQueryString((new Uri(op.Href)).Query);
                foreach (var key in nvc.AllKeys)
                {
                    switch (key)
                    {
                    case "domain":
                        wpsDomainIdentifier = nvc[key];
                        break;

                    case "tag":
                        wpsTags = nvc[key];
                        break;

                    default:
                        break;
                    }
                }
            }

            //check domain
            if (domain == null)
            {
                domain = Domain.FromIdentifier(context, wpsDomainIdentifier);
            }

            op = offering.Operations.FirstOrDefault(o => o.Code == "RemoteSyncProcess");
            if (op != null && op.Href != null)
            {
                //get current services from DB
                string[] tags        = !string.IsNullOrEmpty(wpsTags) ? wpsTags.Split(",".ToArray()) : new string[0];
                var      dbProcesses = WpsProcessOfferingTep.GetWpsProcessingOfferingsForApp(context, domain, tags);

                //get new services from remote
                var remoteProcesses = WpsProcessOfferingTep.GetRemoteWpsProcessingOfferingsFromUrl(context, op.Href, true);
                foreach (var p in remoteProcesses)
                {
                    p.Domain    = domain;
                    p.Tags      = wpsTags;
                    p.Available = true;
                }

                //store only new services (not already in DB)
                foreach (WpsProcessOffering pR in remoteProcesses)
                {
                    bool inDB = false;
                    foreach (WpsProcessOffering pDB in dbProcesses)
                    {
                        if (pR.ProviderId == pDB.ProviderId &&
                            pR.RemoteIdentifier == pDB.RemoteIdentifier &&
                            pR.Version == pDB.Version)
                        {
                            inDB = true;
                            //we update title/description/icon
                            pDB.Name        = pR.Name;
                            pDB.Description = pR.Description;
                            pDB.IconUrl     = pR.IconUrl;
                            pDB.Store();
                        }
                    }
                    if (!inDB)
                    {
                        pR.Store();
                    }
                }

                //remove services from DB not anymore in the list
                foreach (WpsProcessOffering pDB in dbProcesses)
                {
                    bool inRemote = false;
                    foreach (WpsProcessOffering pR in remoteProcesses)
                    {
                        if (pR.ProviderId == pDB.ProviderId &&
                            pR.RemoteIdentifier == pDB.RemoteIdentifier &&
                            pR.Version == pDB.Version)
                        {
                            inRemote = true;
                            break;
                        }
                    }
                    if (!inRemote)
                    {
                        pDB.Delete();
                    }
                }
            }
        }