コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
        private static void LoadStaticFileResource(Dictionary <string, IConfigurationResource> staticFilesResources,
                                                   string root,
                                                   string poolSize,
                                                   string?validSubPaths,
                                                   IEnumerable <string> actionSubPaths, ILogger logger)
        {
            try
            {
                var resourceSequence = 0;

                foreach (var actionSubPath in ListOfSorted(actionSubPaths.ToArray()))
                {
                    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, PatternFrom(actionSubPath, slash), StaticFilesResourceServeFile, null, additionalParameters));
                    var resource = ResourceFor(resourceName, typeof(StaticFilesResource), int.Parse(poolSize), actions, logger);
                    staticFilesResources[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;
            }
        }