Exemple #1
0
 protected MetadataTestBase()
 {
     Metadata = new ServiceMetadata();
     var dummyServiceType = GetType();
     Metadata.Add(dummyServiceType, typeof(GetCustomer), typeof(GetCustomerResponse));
     Metadata.Add(dummyServiceType, typeof(GetCustomers), typeof(GetCustomersResponse));
     Metadata.Add(dummyServiceType, typeof(StoreCustomer), null);
 }
        public ServiceController(Func <IEnumerable <Type> > resolveServicesFn, ServiceMetadata metadata = null)
        {
            this.Metadata = metadata ?? new ServiceMetadata();

            this.RequestTypeFactoryMap    = new Dictionary <Type, Func <IHttpRequest, object> >();
            this.EnableAccessRestrictions = true;
            this.ResolveServicesFn        = resolveServicesFn;
        }
        public MetadataPagesConfig(
            ServiceMetadata metadata,
            ServiceEndpointsMetadataConfig metadataConfig,
            HashSet <string> ignoredFormats,
            List <string> contentTypeFormats)
        {
            this.ignoredFormats = ignoredFormats;
            this.metadata       = metadata;

            metadataConfigMap = new Dictionary <string, MetadataConfig> {
                { "xml", metadataConfig.Xml },
                { "json", metadataConfig.Json },
                { "jsv", metadataConfig.Jsv },
                { "soap11", metadataConfig.Soap11 },
                { "soap12", metadataConfig.Soap12 },
            };

            AvailableFormatConfigs = new List <MetadataConfig>();

            var config = GetMetadataConfig("xml");

            if (config != null)
            {
                AvailableFormatConfigs.Add(config);
            }
            config = GetMetadataConfig("json");
            if (config != null)
            {
                AvailableFormatConfigs.Add(config);
            }
            config = GetMetadataConfig("jsv");
            if (config != null)
            {
                AvailableFormatConfigs.Add(config);
            }

            foreach (var format in contentTypeFormats)
            {
                metadataConfigMap[format] = metadataConfig.Custom.Create(format);

                config = GetMetadataConfig(format);
                if (config != null)
                {
                    AvailableFormatConfigs.Add(config);
                }
            }

            config = GetMetadataConfig("soap11");
            if (config != null)
            {
                AvailableFormatConfigs.Add(config);
            }
            config = GetMetadataConfig("soap12");
            if (config != null)
            {
                AvailableFormatConfigs.Add(config);
            }
        }
        protected override void RenderOperations(HtmlTextWriter writer, IHttpRequest httpReq, ServiceMetadata metadata)
        {
            var defaultPage = new OperationsControl {
                Title = EndpointHost.Config.ServiceName,
                OperationNames = metadata.GetOperationNamesForMetadata(httpReq, Format),
                MetadataOperationPageBodyHtml = EndpointHost.Config.MetadataOperationPageBodyHtml,
            };

            defaultPage.RenderControl(writer);
        }
Exemple #5
0
        /// <summary>
        /// Inject alternative container and strategy for resolving Service Types
        /// </summary>
        public ServiceManager(Container container, ServiceController serviceController)
        {
            if (serviceController == null)
            {
                throw new ArgumentNullException("serviceController");
            }

            this.Container         = container ?? new Container();
            this.Metadata          = serviceController.Metadata; //always share the same metadata
            this.ServiceController = serviceController;
        }
    	protected override void RenderOperations(HtmlTextWriter writer, IHttpRequest httpReq, ServiceMetadata metadata)
    	{
			var defaultPage = new IndexOperationsControl {
				HttpRequest = httpReq,
                MetadataConfig = EndpointHost.Config.MetadataPagesConfig,                
				Title = EndpointHost.Config.ServiceName,
				Xsds = XsdTypes.Xsds,
				XsdServiceTypesIndex = 1,
                OperationNames = metadata.GetOperationNamesForMetadata(httpReq),
				MetadataPageBodyHtml = EndpointHost.Config.MetadataPageBodyHtml,
			};

			defaultPage.RenderControl(writer);
		}
Exemple #7
0
        //public ServiceOperations ServiceOperations { get; set; }
        //public ServiceOperations AllServiceOperations { get; set; }

        public ServiceManager(params Assembly[] assembliesWithServices)
        {
            if (assembliesWithServices == null || assembliesWithServices.Length == 0)
            {
                throw new ArgumentException(
                          "No Assemblies provided in your AppHost's base constructor.\n"
                          + "To register your services, please provide the assemblies where your web services are defined.");
            }

            this.Container = new Container {
                DefaultOwner = Owner.External
            };
            this.Metadata          = new ServiceMetadata();
            this.ServiceController = new ServiceController(() => GetAssemblyTypes(assembliesWithServices), this.Metadata);
        }
        public MetadataPagesConfig(
            ServiceMetadata metadata,
            ServiceEndpointsMetadataConfig metadataConfig,
            HashSet<string> ignoredFormats,
            List<string> contentTypeFormats)
        {
            this.ignoredFormats = ignoredFormats;
            this.metadata = metadata;

            metadataConfigMap = new Dictionary<string, MetadataConfig> {
                {"xml", metadataConfig.Xml},
                {"json", metadataConfig.Json},
                {"jsv", metadataConfig.Jsv},
                {"soap11", metadataConfig.Soap11},
                {"soap12", metadataConfig.Soap12},
            };

            AvailableFormatConfigs = new List<MetadataConfig>();

            var config = GetMetadataConfig("xml");
            if (config != null) AvailableFormatConfigs.Add(config);
            config = GetMetadataConfig("json");
            if (config != null) AvailableFormatConfigs.Add(config);
            config = GetMetadataConfig("jsv");
            if (config != null) AvailableFormatConfigs.Add(config);

            foreach (var format in contentTypeFormats)
            {
                metadataConfigMap[format] = metadataConfig.Custom.Create(format);

                config = GetMetadataConfig(format);
                if (config != null) AvailableFormatConfigs.Add(config);
            }

            config = GetMetadataConfig("soap11");
            if (config != null) AvailableFormatConfigs.Add(config);
            config = GetMetadataConfig("soap12");
            if (config != null) AvailableFormatConfigs.Add(config);
        }
 public XsdMetadata(ServiceMetadata metadata, bool flash = false)
 {
     Metadata = metadata;
     Flash = flash;
 }
 public XsdMetadata(ServiceMetadata metadata, bool flash = false)
 {
     Metadata = metadata;
     Flash    = flash;
 }
 public XsdMetadata(ServiceMetadata metadata, bool flash = false, bool includeAllTypes = true)
 {
     Metadata = metadata;
     Flash = flash;
     IncludeAllTypes = includeAllTypes;
 }
        private IEnumerable<PostmanRequest> GetRequests(IHttpRequest request, ServiceMetadata metadata, string parentId, IEnumerable<Operation> operations)
        {
            var feature = EndpointHost.GetPlugin<PostmanFeature>();
            var label = request.GetParam("label") ?? feature.DefaultLabel;

            var customHeaders = request.GetParam("headers");
            var headers = customHeaders == null ? feature.DefaultHeaders : customHeaders.Split(',');

            foreach (var op in metadata.OperationsMap.Values.Where(o => metadata.IsVisible(request, o)))
            {
                var exampleObject = ReflectionUtils.PopulateObject(op.RequestType.CreateInstance()).ToStringDictionary();
                
                var data = op.RequestType.GetSerializableFields().Select(f => f.Name)
                    .Concat(op.RequestType.GetSerializableProperties().Select(p => p.Name))
                    .ToDictionary(f => f, f => exampleObject.GetValueOrDefault(f));

                foreach (var route in op.Routes)
                {
                    var routeVerbs = route.AllowsAllVerbs ? new[] { "POST" } : route.AllowedVerbs.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    var restRoute = new RestRoute(route.RequestType, route.Path, route.AllowedVerbs);

                    foreach (var verb in routeVerbs)
                    {
                        yield return new PostmanRequest
                        {                            
                            Id = Guid.NewGuid().ToString(),
                            Headers = string.Join("\n", headers),
                            Method = verb,
                            Url = CalculateAppUrl(request, _aspnetSubPath) + restRoute.Path.ReplaceVariables(),
                            Name = label.FormatLabel(op.RequestType, restRoute.Path),
                            Description = op.RequestType.GetDescription(),
                            PathVariables = restRoute.Variables.ToDictionary(v => v, v => data.GetValueOrDefault(v)),
                            Data = data.Keys.Except(restRoute.Variables).Select(v => new PostmanData
                            {
                                Key = v,
                                Value = data[v],
                                Type = "text",
                            }).ToArray(),
                            DataMode = "params",                            
                            Version = 2,
                            Time = DateTime.UtcNow.ToUnixTimeMs(),
                            CollectionId = parentId,
                            Folder = restRoute.Path.GetFolderName()
                        };
                    }
                }
            }
        }