Esempio n. 1
0
        public void DataHubTest()
        {
            var dataHub = new DataHub();

            dataHub.Add(new DataPath("a.b.c".Split('.')), 123);
            dataHub.Add(new DataPath("a.b.d".Split('.')), 456);
            dataHub.Add(new DataPath("e.b.d".Split('.')), 789);
            var data = dataHub.CreateDynamicObject();

            Assert.AreEqual(123, data.a.b.c);
            Assert.AreEqual(456, data.a.b.d);
            Assert.AreEqual(789, data.e.b.d);
        }
Esempio n. 2
0
        public async Task DataOverPreProcessorTest()
        {
            var dataHub = new DataHub();

            dataHub.Add(new DataPath("a.b.c".Split('.')), 123);
            dataHub.Add(new DataPath("a.b.d".Split('.')), 456);
            dataHub.Add(new DataPath("e.b.d".Split('.')), 789);

            var globals       = new DataOverPreProcessorTestGlobals(dataHub);
            var scriptOptions = ScriptOptions.Default.AddReferences("Microsoft.CSharp");
            var preProcessor  = new RoslynPreProcessor(globals, scriptOptions);

            Assert.AreEqual(123, await preProcessor.ExecuteAsync <int>("@Data.a.b.c"));
            Assert.AreEqual(456, await preProcessor.ExecuteAsync <int>("@Data.a.b.d"));
            Assert.AreEqual(789, await preProcessor.ExecuteAsync <int>("@Data.e.b.d"));
        }
        public void LoadTextResources(DataHub dataHub, Assembly assembly, Regex regex, DataPath?basePath = null)
        {
            var resourceNames = embeddedResourceUtils.GetLocalEmbeddedResourceNames(assembly, regex);

            foreach (var resourceName in resourceNames)
            {
                var content     = embeddedResourceUtils.GetLocalEmbeddedResourceText(assembly, resourceName);
                var contentPath = new DataPath(regex.Match(resourceName).Groups[1].Value.Split('.'));
                var path        = DataPath.Combine(basePath, contentPath);
                dataHub.Add(path, content);
            }
        }
Esempio n. 4
0
 private void AddJsonElementValuesToDataHub(DataHub dataHub, DataPath basePath, JsonElement jsonElement)
 {
     if (jsonElement.ValueKind == JsonValueKind.Object)
     {
         foreach (var jsonProperty in jsonElement.EnumerateObject())
         {
             var path = DataPath.Combine(basePath, new DataPath(jsonProperty.Name));
             AddJsonElementValuesToDataHub(dataHub, path, jsonProperty.Value);
         }
     }
     else
     {
         dataHub.Add(basePath, GetJsonElementValue(jsonElement));
     }
 }
        public void LoadTextResource(DataHub dataHub, Assembly assembly, string resourceName, DataPath path)
        {
            var content = embeddedResourceUtils.GetLocalEmbeddedResourceText(assembly, resourceName);

            dataHub.Add(path, content);
        }