Beispiel #1
0
        internal BaseService(IServiceFactory factory, JsonDictionary values, FactoryParameters param)
            : this(factory)
        {
            values.ThrowIfNull("values");
            param = param ?? new FactoryParameters();

            // Set required properties
            Version     = values.GetMandatoryValue <string>("version");
            Name        = values.GetMandatoryValue <string>("name");
            information = values;

            // Set optional properties
            Id                = values.GetValueAsNull("id") as string;
            Labels            = values.GetValueAsStringListOrEmpty("labels").ToList().AsReadOnly();
            Features          = values.GetValueAsStringListOrEmpty("features").ToList().AsReadOnly();
            DocumentationLink = values.GetValueAsNull("documentationLink") as string;
            Protocol          = values.GetValueAsNull("protocol") as string;
            Description       = values.GetValueAsNull("description") as string;
            Title             = values.GetValueAsNull("title") as string;
            Scopes            = LoadScopes();
            Parameters        = LoadParameters();

            // Load resources
            rootResource = CreateResource(new KeyValuePair <string, object>("", information));

            // Determine the Server URL and (optional) Base Path
            param.ServerUrl.ThrowIfNull("param.ServerUrl");
            ServerUrl = param.ServerUrl;
            BasePath  = param.BasePath;
        }
Beispiel #2
0
        internal IDictionary <string, Scope> LoadScopes()
        {
            Dictionary <string, Scope> scopes = new Dictionary <string, Scope>();

            // Access the "auth" node.
            var authObj = information.GetValueAsNull("auth") as JsonDictionary;

            if (authObj == null)
            {
                return(scopes);
            }

            // Access the "oauth2" subnode.
            var oauth2Obj = authObj.GetValueAsNull("oauth2") as JsonDictionary;

            if (oauth2Obj == null)
            {
                return(scopes);
            }

            // Access the "scopes" subnode.
            var scopesObj = oauth2Obj.GetValueAsNull("scopes") as JsonDictionary;

            if (scopesObj == null)
            {
                return(scopes);
            }

            // Iterate through all scopes.
            foreach (KeyValuePair <string, object> pair in scopesObj)
            {
                // Create a new scope object.
                var scope = new Scope();
                scope.ID = pair.Key;

                var data = pair.Value as JsonDictionary;
                if (data != null)
                {
                    scope.Description = data.GetValueAsNull("description") as string;
                }

                // Add it to the scopes dictionary.
                scopes.Add(scope.ID, scope);
            }

            return(scopes);
        }
        internal BaseService(IServiceFactory factory, JsonDictionary discoveryDoc, FactoryParameters param)
            : this(factory)
        {
            discoveryDoc.ThrowIfNull("discoveryDoc");
            this.discoveryDoc = discoveryDoc;

            // Set required properties
            Version       = discoveryDoc.GetMandatoryValue <string>("version");
            Name          = discoveryDoc.GetMandatoryValue <string>("name").Replace(" ", "");
            CanonicalName = discoveryDoc.GetValueAsNull("canonicalName") as string;
            if (!string.IsNullOrEmpty(CanonicalName))
            {
                CanonicalName = CanonicalName.Replace(" ", "");
            }

            // Set optional properties
            Id                = discoveryDoc.GetValueAsNull("id") as string;
            Labels            = discoveryDoc.GetValueAsStringListOrEmpty("labels").ToList().AsReadOnly();
            Features          = discoveryDoc.GetValueAsStringListOrEmpty("features").ToList().AsReadOnly();
            DocumentationLink = discoveryDoc.GetValueAsNull("documentationLink") as string;
            Protocol          = discoveryDoc.GetValueAsNull("protocol") as string;
            Description       = discoveryDoc.GetValueAsNull("description") as string;
            Title             = discoveryDoc.GetValueAsNull("title") as string;
            Scopes            = LoadScopes();
            Parameters        = LoadParameters();

            // Load resources
            rootResource = CreateResource(new KeyValuePair <string, object>("", discoveryDoc));

            // Sets the Server URL (Base Path will be set on the concete class)
            if (param != null && param.ServerUrl != null)
            {
                ServerUrl = param.ServerUrl;
            }
            else
            {
                ServerUrl = discoveryDoc.GetMandatoryValue("rootUrl") as string;
            }
        }