Ejemplo n.º 1
0
 //TODO: Support true bulk
 public async Task Write(DbConnection ctx, string tableName, PopulationResultCollection populationResult)
 {
     foreach (PopulationResult rs in populationResult)
     {
         await Write(ctx, tableName, populationResult);
     }
 }
Ejemplo n.º 2
0
        private PopulationResult MergeIntoAggregate(PopulationResultCollection resultCollection)
        {
            IDictionary <string, object> merged = new Dictionary <string, object>();

            PopulationResult root = resultCollection.Dequeue();

            foreach (var kv in root)
            {
                string key = Namer.EnsureMinimumUniqueKey(kv.Key, merged);
                merged[key] = kv.Value;
            }

            for (int _ = 0; _ < resultCollection.Count; ++_)
            {
                PopulationResult current = resultCollection.Dequeue();
                foreach (var kv in current)
                {
                    string key = Namer.EnsureMinimumUniqueKey(kv.Key, merged);
                    merged[key] = kv.Value;
                }
            }


            return(new PopulationResult(merged, TypeMap));
        }
Ejemplo n.º 3
0
        public async Task BasicCollection()
        {
            FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions
            {
                ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}")
            };

            PostAnalyzer analyzer = new PostAnalyzer();

            analyzer.ServiceName = "PostsService";

            PopulationResultCollection rs = await DataCollector.CollectData(analyzer, new HttpServiceOptions
            {
                PrefixKey  = "post",
                Parameters = new
                {
                    PostId = 1
                }
            });

            PopulationResult data = rs.Dequeue();

            foreach (string key in data.Keys)
            {
                Assert.IsTrue(analyzer.TypeMap.Keys.Contains(key));
            }
        }
Ejemplo n.º 4
0
        public async Task <PopulationResult> PopulateAsync <TInput>(TInput input)
            where TInput : IServiceInput
        {
            if (MessageMap == null)
            {
                MessageMap = new MessageProperties("NONE", "Id");
            }

            PopulationResultCollection rs = await DataCollector.CollectData(this, input);

            PopulationResult merged = MergeIntoAggregate(rs);

            return(merged);
        }
Ejemplo n.º 5
0
        private PopulationResult MergeIntoAggregate(PopulationResultCollection resultCollection)
        {
            IDictionary <string, object> merged = new Dictionary <string, object>();

            PopulationResult root = resultCollection.Dequeue();

            foreach (KeyValuePair <string, object> kv in root)
            {
                merged.Add(kv);
            }

            for (int _ = 0; _ < resultCollection.Count; ++_)
            {
                PopulationResult current = resultCollection.Dequeue();
                foreach (KeyValuePair <string, object> kv in current)
                {
                    merged.Add(kv);
                }
            }


            return(new PopulationResult(merged));
        }
Ejemplo n.º 6
0
        public static async Task <PopulationResultCollection> CollectData <T>(AnalyticalObject <T> focusedObject,
                                                                              IServiceInput serviceInput)
        {
            if (focusedObject.ServiceName == null)
            {
                throw new Exception("Root analyzer object must have a service defined.");
            }

            if (!FluentOlapConfiguration.ServiceDefinitions.ContainsKey(focusedObject.ServiceName))
            {
                throw new Exception($"Service {focusedObject.ServiceName} not defined.");
            }

            IService <IServiceInput, IServiceOutput> focusedService = FluentOlapConfiguration.ServiceDefinitions[focusedObject.ServiceName];
            PopulationResultCollection results = new PopulationResultCollection();

            PopulationResult rootResult = await CallService(focusedService, serviceInput);

            results.Add(rootResult);

            foreach (var expandable in focusedObject.ExpandableChildren)
            {
                if (expandable.Value.ServiceName == null)
                {
                    throw new Exception("Child analyzer object must have a service defined.");
                }

                if (!FluentOlapConfiguration.ServiceDefinitions.ContainsKey(expandable.Value.ServiceName))
                {
                    throw new Exception($"Service {expandable.Value.ServiceName} not defined.");
                }

                IService <IServiceInput, IServiceOutput> expandableService = FluentOlapConfiguration.ServiceDefinitions[expandable.Value.ServiceName];

                IServiceInput input = null;

                switch (expandableService.Type)
                {
                case ServiceType.HttpCall:
                    HttpService expandableHttpService       = expandableService as HttpService;
                    IDictionary <string, string> parameters = new Dictionary <string, string>();
                    foreach (string innerParam in expandableHttpService.GetRequiredParameters())
                    {
                        JToken parsedRoot = JToken.Parse(rootResult.Raw);
                        parameters.Add(innerParam, parsedRoot[innerParam].Value <string>());
                    }

                    input = new HttpServiceOptions
                    {
                        PrefixKey  = expandable.Value.NodeName,
                        Parameters = parameters
                    };

                    await expandableHttpService.InvokeAsync((HttpServiceOptions)input);

                    break;
                }

                results.Add(await CallService(expandableService, input));
            }

            return(results);
        }
Ejemplo n.º 7
0
 public async Task InsertIntoDb(PopulationResultCollection rs, DbConnection con)
 {
     await base.Insert(rs, con);
 }
Ejemplo n.º 8
0
 protected async Task EnsureConsistency(PopulationResultCollection rs, DbConnection con)
 {
     await base.EnsureScheme(rs.Sample, con);
 }