コード例 #1
0
        public void CreateJobTest()
        {
            var recipeOwner = "ladybug-tools";
            var recipeName  = "daylight-factor";
            var recipeApi   = new RecipesApi();
            var rec         = recipeApi.GetRecipeByTag(recipeOwner, recipeName, "latest").Manifest;

            var jobInfo = new JobInfo(rec);

            var model = Path.GetFullPath(@"../../../TestSample/two_rooms.hbjson");

            if (!File.Exists(model))
            {
                throw new ArgumentException("Input doesn't exist");
            }
            jobInfo.AddArgument(new JobPathArgument("model", new ProjectFolder(path: model)));

            jobInfo.SetJobSubFolderPath("round1/test");
            jobInfo.SetJobName("A new daylight simulation");

            // run a job
            var task = jobInfo.RunJobOnCloud(Project, (s) => Console.WriteLine(s));


            //cts.CancelAfter(60000);
            ScheduledJob = task.Result;

            Assert.IsTrue(!string.IsNullOrEmpty(ScheduledJob.CloudJob.Id));
        }
コード例 #2
0
        /// <summary>
        /// Here we use the Adapter Pattern to adapt the XML result we receive from the RecipesApi
        /// to work with our client-side code, which "only works" with JSON.  Here we gain the benefit
        /// of allowing the API dependency to just continue working as it needs to while changing the
        /// interface of our Adapter to match what's needed here in the client.
        ///
        /// If the interface of the RecipesApi changes, or if its return types or structure get updated,
        /// Our client code here will likely remain unchanged, as we can then write a new Adapter or update
        /// our existing Adapter code.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private static async Task Main(string[] args)
        {
            var logger = new ConsoleLogger();

            logger.LogInfo("👩‍🍳  Aggregating Recipes from the API...");

            // The RecipesAPI Produces XML results
            var recipesApi = new RecipesApi(logger);

            // Let's adapt it with our RecipeFinder adapter to produce JSON instead
            var recipeFinder = new RecipeFinder(recipesApi);

            var mashedPotatoesResult = recipeFinder.GetRecipeAsJson("mashed_potatoes");
            var greenBeansResult     = recipeFinder.GetRecipeAsJson("green_beans");
            var redCurryResult       = recipeFinder.GetRecipeAsJson("red_curry");

            var tasks = new List <Task <string> > {
                mashedPotatoesResult,
                greenBeansResult,
                redCurryResult
            };

            await Task.WhenAll(tasks);

            // We only want to work with JSON in this client
            PrintJsonRecipes(tasks);
        }
コード例 #3
0
        private static void GetRecipeParameters()
        {
            var api = new RecipesApi();
            var d   = api.ListRecipes(owner: new[] { "ladybug-tools" }.ToList()).Resources.First(_ => _.Name == "daylight-factor");


            var recTag = api.GetRecipeByTag(d.Owner.Name, d.Name, d.LatestTag);
            //TODO: ask Antoine to fix why Manifest returns Recipe
            var mani = recTag.Manifest;
            //TODO: ask Antoine to fix why Flow returns DAG
            var flow       = mani.Flow.First();
            var inputs     = flow.Inputs;
            var ParamNames = inputs.Parameters.Select(_ => _.Name);

            Console.WriteLine("------------------Getting Recipe Input Params---------------------");
            Console.WriteLine(string.Join("\n", ParamNames));

            var artifactNames = inputs.Artifacts.Select(_ => _.Name);

            Console.WriteLine("------------------Getting Recipe Input artifacts---------------------");
            Console.WriteLine(string.Join("\n", artifactNames));

            //return inputs.ToString();
            //return recipes;
        }
コード例 #4
0
        //private static PrivateUserDto GetUser()
        //{
        //    var api = new UserApi();
        //    //var config = api.Configuration;
        //    var me = api.GetMe();
        //    return me;
        //}

        private static IEnumerable <string> GetRecipes()
        {
            var api     = new RecipesApi();
            var d       = api.ListRecipes(_public: true);
            var recipes = d.Resources.Select(_ => _.Name);

            return(recipes);
        }
コード例 #5
0
        private static void CreateSimulation(ProjectDto project)
        {
            // Get project
            var proj = project;


            //Recipe
            var recipeApi = new RecipesApi();
            // why Recipe returns repository
            RepositoryAbridgedDto recipe = recipeApi.ListRecipes(owner: new[] { "ladybug-tools" }.ToList(), _public: true).Resources.First(_ => _.Name == "daylight-factor");


            // create a recipeSelection
            var rec = new RecipeSelection(recipe.Owner.Name, recipe.Name);

            // Upload artifacts
            var dir = @"C:\Users\mingo\Downloads\Compressed\project_folder\project_folder";
            //UploadDirectory(proj, dir);

            // create a recipe argument
            var arg = new Arguments()
            {
                Parameters = new List <ArgumentParameter>()
                {
                    new ArgumentParameter("radiance-parameters", "-I -ab 1 -h"),
                    new ArgumentParameter("sensor-grid-count", "10")
                },
                Artifacts = new List <ArgumentArtifact>()
                {
                    new ArgumentArtifact("input-grid", new ArtifaceSourcePath("model/grid/room.pts")),
                    new ArgumentArtifact("model", new ArtifaceSourcePath("model/"))
                }
            };

            Console.WriteLine("-------------------Arguments:-------------------------");
            Console.WriteLine(arg.ToJson());


            // create a new Simulation
            var api  = new SimulationsApi();
            var simu = new SubmitSimulationDto(rec, arg);

            var ret = api.CreateSimulation(proj.Owner.Name, proj.Name, simu);

            Console.WriteLine(ret.Id);
            Console.WriteLine(ret.Message);


            // check simulation status
            var done = CheckSimulationStatus(proj, ret.Id.ToString()).Result;

            var outputs = api.GetSimulationLogs(proj.Owner.Name, proj.Name, ret.Id.ToString());

            //return recipes;
        }
コード例 #6
0
        public async Task MakeHttpRequestForRecipe_Logs_Recipe()
        {
            var logger = new Mock <IApplicationLogger>();
            var api    = new RecipesApi(logger.Object);
            var result = await api.MakeHttpRequestForRecipe("mashed_potatoes");

            logger.Verify(mock
                          => mock.LogInfo(
                              It.IsAny <string>(),
                              It.IsAny <ConsoleColor>()),
                          Times.AtLeastOnce());
        }
コード例 #7
0
        public async Task MakeHttpRequestForRecipe_Gets_Value_From_Database_Given_Recipe()
        {
            var logger = new Mock <IApplicationLogger>();
            var api    = new RecipesApi(logger.Object);
            var result = await api.MakeHttpRequestForRecipe("mashed_potatoes");

            using var reader = new StringReader(result);
            var recipe = (Recipe)xml.Deserialize(reader);

            recipe.Should().NotBeNull();
            recipe.Name.Should().Be("Mashed Potatoes");
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: andreialex007/recipes
        static void Main(string[] args)
        {
            var basePath = "http://*****:*****@admin.com",
                Password = "******"
            });

            var recipesApi = new RecipesApi(basePath, token.Trim('"'));
            var itemsList  = recipesApi.RecipesGet();
            var item       = recipesApi.RecipesRecepieIdGet(itemsList.First().Id);
        }
コード例 #9
0
        private static void GetRecipeParameters()
        {
            var api = new RecipesApi();
            //var d = api.ListRecipes(owner: new[] { "ladybug-tools" }.ToList()).Resources.First(_ => _.Name == "annual-energy-use");

            var rec = api.GetRecipeByTag("ladybug-tools", "annual-energy-use", "*").Manifest;
            //var recTag = api.GetRecipeByTag("ladybug-tools", "annual-energy-use", "c2657adb0b13db6cd3ff706d9d6db59b98ef8f994d2809d23c3ed449c19b52ea");

            var inputs     = rec.Inputs.OfType <GenericInput>();
            var ParamNames = inputs.Select(_ => _.Name);

            Console.WriteLine("------------------Getting Recipe Input Params---------------------");
            Console.WriteLine(string.Join("\n", ParamNames));
        }
コード例 #10
0
ファイル: Helper.cs プロジェクト: pollination/csharp-sdk
        public static bool GetRecipeFromRecipeSourceURL(string recipeSource, out RecipeInterface recipe)
        {
            //var recipeSource = this.Run.Job.Source;
            var isRecipe = Helper.GetRecipeFromRecipeSourceURL(recipeSource, out var recOwner, out var recName, out var recVersion);

            if (!isRecipe)
            {
                throw new ArgumentException($"Invalid recipe source URL {recipeSource}.\nThe correct formate should be something like:https://api.staging.pollination.cloud/registries/ladybug-tools/recipe/annual-daylight/0.2.0");
            }
            var recApi = new RecipesApi();

            recipe = recApi.GetRecipeByTag(recOwner, recName, recVersion).Manifest;
            return(recipe != null);
        }
コード例 #11
0
        private static JobInfo CreateJob_DaylightFactor()
        {
            var recipeOwner = "ladybug-tools";
            var recipeName  = "daylight-factor";
            var recipeApi   = new RecipesApi();
            var rec         = recipeApi.GetRecipeByTag(recipeOwner, recipeName, "latest").Manifest;

            var jobInfo = new JobInfo(rec);

            jobInfo.AddArgument(new JobPathArgument("model", new ProjectFolder(path: @"D:\Test\queenbeeTest\model.hbjson")));
            //job.AddArgument(new JobPathArgument("input", new ProjectFolder(path: @"D:\Test\queenbeeTest\inputs.json")));


            return(jobInfo);
        }
コード例 #12
0
        private static JobInfo CreateJob_AnnualDaylight()
        {
            var recipeOwner = "ladybug-tools";
            var recipeName  = "annual-daylight";
            var recipeApi   = new RecipesApi();
            var rec         = recipeApi.GetRecipeByTag(recipeOwner, recipeName, "latest").Manifest;

            var jobInfo = new JobInfo(rec);

            //job.AddArgument(new JobArgument("sensor-grids", "[\"room\"]"));
            jobInfo.AddArgument(new JobPathArgument("model", new ProjectFolder(path: @"D:\Test\queenbeeTest\two_rooms.hbjson")));
            jobInfo.AddArgument(new JobPathArgument("wea", new ProjectFolder(path: @"D:\Test\queenbeeTest\golden_co.wea")));

            return(jobInfo);
        }
コード例 #13
0
 public RecipeFinder(RecipesApi recipesApi)
 {
     _recipesApi = recipesApi;
 }
コード例 #14
0
 public void Init()
 {
     instance = new RecipesApi();
 }
コード例 #15
0
 public void Init()
 {
     api = new RecipesApi();
 }