コード例 #1
0
ファイル: Loader.cs プロジェクト: Johnny-Bee/vlingo-net-http
        public static Resources LoadResources(HttpProperties properties)
        {
            var namedResources = new Dictionary <string, IResource>();

            foreach (var resource in FindResources(properties, ResourceNamePrefix))
            {
                var loaded = LoadResource(properties, resource);

                namedResources[loaded.Name] = loaded;
            }

            foreach (var item in LoadSseResources(properties))
            {
                namedResources[item.Key] = item.Value;
            }

            foreach (var item in LoadFeedResources(properties))
            {
                namedResources[item.Key] = item.Value;
            }

            foreach (var item in LoadStaticFilesResource(properties))
            {
                namedResources[item.Key] = item.Value;
            }

            return(new Resources(namedResources));
        }
コード例 #2
0
ファイル: Loader.cs プロジェクト: muharihar/vlingo-net-http
        private static List <Action> ResourceActionsOf(
            HttpProperties properties,
            string resourceName,
            string[] resourceActionNames)
        {
            var resourceActions = new List <Action>(resourceActionNames.Length);

            foreach (var actionName in resourceActionNames)
            {
                try
                {
                    var keyPrefix = $"action.{resourceName}.{actionName}.";

                    var actionId = resourceActions.Count;
                    var method   = properties.GetProperty($"{keyPrefix}method", null);
                    var uri      = properties.GetProperty($"{keyPrefix}uri", null);
                    var to       = properties.GetProperty($"{keyPrefix}to", null);
                    var mapper   = properties.GetProperty($"{keyPrefix}mapper", null);

                    resourceActions.Add(new Action(actionId, method, uri, to, mapper));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"vlingo-net/http: Failed to load resource: {resourceName} action:{actionName} because: {e.Message}");
                    throw;
                }
            }

            return(resourceActions);
        }
コード例 #3
0
ファイル: Loader.cs プロジェクト: muharihar/vlingo-net-http
        private static HashSet <string> FindResources(HttpProperties properties, string namePrefix)
        {
            var resource = new HashSet <string>();

            properties.Keys
            .Where(k => k.StartsWith(namePrefix))
            .ToList()
            .ForEach(k => resource.Add(k));

            return(resource);
        }
コード例 #4
0
        public static IServer StartWith(Stage stage, HttpProperties properties)
        {
            var configuration = Configuration.DefineWith(properties);

            var resources = Loader.LoadResources(properties);

            return(StartWith(
                       stage,
                       resources,
                       configuration.Port,
                       configuration.Sizing,
                       configuration.Timing));
        }
コード例 #5
0
ファイル: Loader.cs プロジェクト: muharihar/vlingo-net-http
        private static IDictionary <string, IConfigurationResource> LoadSseResources(HttpProperties properties)
        {
            var sseResourceActions = new Dictionary <string, IConfigurationResource>();

            foreach (var streamResourceName in FindResources(properties, SsePublisherNamePrefix))
            {
                var streamUri         = properties.GetProperty(streamResourceName);
                var resourceName      = streamResourceName.Substring(SsePublisherNamePrefix.Length);
                var feedClassnameKey  = $"sse.stream.{resourceName}.feed.class";
                var feedClassname     = properties.GetProperty(feedClassnameKey);
                var feedPayloadKey    = "sse.stream." + resourceName + ".feed.payload";
                var maybeFeedPayload  = int.Parse(properties.GetProperty(feedPayloadKey, "20"));
                var feedPayload       = maybeFeedPayload <= 0 ? 20 : maybeFeedPayload;
                var feedIntervalKey   = $"sse.stream.{resourceName}.feed.interval";
                var maybeFeedInterval = int.Parse(properties.GetProperty(feedIntervalKey, "1000"));
                var feedInterval      = maybeFeedInterval <= 0 ? 1000 : maybeFeedInterval;
                var feedDefaultIdKey  = $"sse.stream.{resourceName}.feed.default.id";
                var feedDefaultId     = properties.GetProperty(feedDefaultIdKey, "");
                var poolKey           = $"sse.stream.{resourceName}.pool";
                var maybePoolSize     = int.Parse(properties.GetProperty(poolKey, "1"));
                var handlerPoolSize   = maybePoolSize <= 0 ? 1 : maybePoolSize;
                var subscribeUri      = streamUri?.Replace(resourceName, SsePublisherNamePathParameter);
                var unsubscribeUri    = subscribeUri + "/" + SsePublisherIdPathParameter;

                try
                {
                    var feedClass                = ActorClassWithProtocol(feedClassname, typeof(ISseFeed));
                    var mappedParameterClass     = new Action.MappedParameter("Type", feedClass);
                    var mappedParameterPayload   = new Action.MappedParameter("int", feedPayload);
                    var mappedParameterInterval  = new Action.MappedParameter("int", feedInterval);
                    var mappedParameterDefaultId = new Action.MappedParameter("string", feedDefaultId);

                    var actions = new List <Action>(2);
                    var additionalParameters = new List <Action.MappedParameter> {
                        mappedParameterClass, mappedParameterPayload, mappedParameterInterval, mappedParameterDefaultId
                    };
                    actions.Add(new Action(0, Method.Get.Name, subscribeUri, SsePublisherSubscribeTo, null, additionalParameters));
                    actions.Add(new Action(1, Method.Delete.Name, unsubscribeUri, SsePublisherUnsubscribeTo, null));
                    var resource = ResourceFor(resourceName, typeof(SseStreamResource), handlerPoolSize, actions);
                    sseResourceActions[resourceName] = resource;
                }
                catch (Exception e)
                {
                    Console.WriteLine("vlingo-net/http: Failed to load SSE resource: " + streamResourceName + " because: " + e.Message);
                    Console.WriteLine(e.StackTrace);
                    throw e;
                }
            }

            return(sseResourceActions);
        }
コード例 #6
0
        public IServer StartWith(Stage stage,
                                 HttpProperties properties)
        {
            if (!_actor.IsStopped)
            {
                Action <IServer> cons128873 = __ => __.StartWith(stage, properties);
                if (_mailbox.IsPreallocated)
                {
                    _mailbox.Send(_actor, cons128873, null, StartWithRepresentation2);
                }
                else
                {
                    _mailbox.Send(new LocalMessage <IServer>(_actor, cons128873,
                                                             StartWithRepresentation2));
                }
            }
            else
            {
                _actor.DeadLetters?.FailedDelivery(new DeadLetter(_actor, StartWithRepresentation2));
            }

            return(null !);
        }
コード例 #7
0
ファイル: Loader.cs プロジェクト: muharihar/vlingo-net-http
        private static IConfigurationResource LoadResource(HttpProperties properties, string resourceNameKey)
        {
            var resourceName             = resourceNameKey.Substring(ResourceNamePrefix.Length);
            var resourceActionNames      = ActionNamesFrom(properties.GetProperty(resourceNameKey), resourceNameKey);
            var resourceHandlerKey       = $"resource.{resourceName}.handler";
            var resourceHandlerClassname = properties.GetProperty(resourceHandlerKey);
            var handlerPoolKey           = $"resource.{resourceName}.pool";
            var maybeHandlerPoolSize     = int.Parse(properties.GetProperty(handlerPoolKey, "1"));
            var handlerPoolSize          = maybeHandlerPoolSize <= 0 ? 1 : maybeHandlerPoolSize;

            try
            {
                var resourceActions = ResourceActionsOf(properties, resourceName, resourceActionNames);

                var resourceHandlerClass = ConfigurationResource <ResourceHandler> .NewResourceHandlerTypeFor(resourceHandlerClassname);

                return(ResourceFor(resourceName, resourceHandlerClass !, handlerPoolSize, resourceActions));
            }
            catch (Exception e)
            {
                Console.WriteLine("vlingo-net/http: Failed to load resource: " + resourceName + " because: " + e.Message);
                throw;
            }
        }
コード例 #8
0
ファイル: Loader.cs プロジェクト: muharihar/vlingo-net-http
        private static IDictionary <string, IConfigurationResource> LoadStaticFilesResource(HttpProperties properties)
        {
            var staticFilesResourceActions = new Dictionary <string, IConfigurationResource>();

            var root = properties.GetProperty(StaticFilesResourceRoot);

            if (root == null)
            {
                return(staticFilesResourceActions);
            }

            var poolSize       = properties.GetProperty(StaticFilesResourcePool, "5");
            var validSubPaths  = properties.GetProperty(StaticFilesResourceSubPaths);
            var actionSubPaths = ActionNamesFrom(validSubPaths, StaticFilesResourceSubPaths).OrderByDescending(x => x.Length);

            try
            {
                int resourceSequence = 0;

                foreach (var actionSubPath in actionSubPaths)
                {
                    var mappedParameterRoot          = new Action.MappedParameter("string", root);
                    var mappedParameterValidSubPaths = new Action.MappedParameter("string", validSubPaths);

                    var slash        = actionSubPath.EndsWith("/") ? "" : "/";
                    var resourceName = StaticFilesResource + resourceSequence++;

                    var actions = new List <Action>(1);
                    var additionalParameters = new List <Action.MappedParameter> {
                        mappedParameterRoot, mappedParameterValidSubPaths
                    };
                    actions.Add(new Action(0, Method.Get.Name, actionSubPath + slash + StaticFilesResourcePathParameter, StaticFilesResourceServeFile, null, additionalParameters));
                    var resource = ResourceFor(resourceName, typeof(StaticFilesResource), int.Parse(poolSize), actions);
                    staticFilesResourceActions[resourceName] = resource;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("vlingo-net/http: Failed to load static files resource: " + StaticFilesResource + " because: " + e.Message);
                Console.WriteLine(e.StackTrace);
                throw e;
            }

            return(staticFilesResourceActions);
        }
コード例 #9
0
 public IServer StartWith(Stage stage, HttpProperties properties) => ServerFactory.StartWith(stage, properties);
コード例 #10
0
ファイル: Loader.cs プロジェクト: Johnny-Bee/vlingo-net-http
        private static IDictionary <string, IConfigurationResource> LoadFeedResources(HttpProperties properties)
        {
            var feedResourceActions = new Dictionary <string, IConfigurationResource>();

            foreach (var feedResourceName in FindResources(properties, FeedProducerNamePrefix))
            {
                var feedUri                  = properties.GetProperty(feedResourceName);
                var resourceName             = feedResourceName.Substring(FeedProducerNamePrefix.Length);
                var feedProducerClassnameKey = $"feed.resource.{resourceName}.producer.class";
                var feedProducerClassname    = properties.GetProperty(feedProducerClassnameKey);
                var feedElementsKey          = $"feed.resource.{resourceName}.elements";
                var maybeFeedElements        = int.Parse(properties.GetProperty(feedElementsKey, "20"));
                var feedElements             = maybeFeedElements <= 0 ? 20 : maybeFeedElements;
                var poolKey                  = $"feed.resource.{resourceName}.pool";
                var maybePoolSize            = int.Parse(properties.GetProperty(poolKey, "1"));
                int handlerPoolSize          = maybePoolSize <= 0 ? 1 : maybePoolSize;
                var feedRequestUri           =
                    $"{feedUri?.Replace(resourceName, FeedNamePathParameter)}/{FeedProductIdPathParameter}";

                try
                {
                    var feedClass = ActorClassWithProtocol(feedProducerClassname, typeof(IFeedProducer));
                    var mappedParameterProducerClass   = new Action.MappedParameter("Type", feedClass);
                    var mappedParameterProductElements = new Action.MappedParameter("int", feedElements);

                    var actions = new List <Action>(1);
                    var additionalParameters = new List <Action.MappedParameter> {
                        mappedParameterProducerClass, mappedParameterProductElements
                    };
                    actions.Add(new Action(0, Method.Get.Name, feedRequestUri, FeedProducerFeed, null, additionalParameters));
                    var resource = ResourceFor(resourceName, typeof(FeedResource), handlerPoolSize, actions);
                    feedResourceActions.Add(resourceName, resource);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"vlingo/http: Failed to load feed resource: {resourceName} because: {e.Message}");
                    Console.WriteLine(e.StackTrace);
                    throw e;
                }
            }

            return(feedResourceActions);
        }
コード例 #11
0
        private static IDictionary <string, IConfigurationResource> LoadStaticFilesResource(HttpProperties properties, ILogger logger)
        {
            var staticFilesResourceActions = new Dictionary <string, IConfigurationResource>();

            var root = properties.GetProperty(StaticFilesResourceRoot);

            if (root == null)
            {
                return(staticFilesResourceActions);
            }

            var poolSize       = properties.GetProperty(StaticFilesResourcePool, "5") !;
            var validSubPaths  = properties.GetProperty(StaticFilesResourceSubPaths);
            var actionSubPaths = ActionNamesFrom(validSubPaths, StaticFilesResourceSubPaths);

            LoadStaticFileResource(staticFilesResourceActions, root, poolSize, validSubPaths, actionSubPaths, logger);

            return(staticFilesResourceActions);
        }