Example #1
0
        private async Task EnsureActivity()
        {
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            bool existActivity = false;

            foreach (string activity in activities.Data)
            {
                if (activity.Contains(ActivityFullName))
                {
                    existActivity = true;
                    continue;
                }
            }

            if (!existActivity)
            {
                // create activity
                string   commandLine  = string.Format(@"$(engine.path)\\accoreconsole.exe /i $(args[inputFile].path) /al $(appbundles[{0}].path) /s $(settings[script].path)", APPNAME);
                Activity activitySpec = new Activity()
                {
                    Id         = ACTIVITY_NAME,
                    Appbundles = new List <string>()
                    {
                        AppBundleFullName
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = ENGINE_NAME,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "inputFile", new Parameter()
                          {
                              Description = "Input DWG File", LocalName = "$(inputFile)", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "results", new Parameter()
                          {
                              Description = "Output JSON Results", LocalName = "results.json", Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                          } },
                    },
                    Settings = new Dictionary <string, ISetting>()
                    {
                        { "script", new StringSetting()
                          {
                              Value = "RUNVALIDATION\n"
                          } }
                    }
                };
                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(ACTIVITY_NAME, aliasSpec);
            }
        }
Example #2
0
        public async Task EnsureAppBundle(string contentRootPath)
        {
            // get the list and check for the name
            Page <string> appBundles = await _designAutomation.GetAppBundlesAsync();

            bool existAppBundle = false;

            foreach (string appName in appBundles.Data)
            {
                if (appName.Contains(AppBundleFullName))
                {
                    existAppBundle = true;
                    continue;
                }
            }

            if (!existAppBundle)
            {
                // check if ZIP with bundle is here
                string packageZipPath = Path.Combine(contentRootPath + "/bundles/", APPBUNBLENAME);
                if (!File.Exists(packageZipPath))
                {
                    throw new Exception("FindColumns appbundle not found at " + packageZipPath);
                }

                AppBundle appBundleSpec = new AppBundle()
                {
                    Package     = APPNAME,
                    Engine      = ENGINE_NAME,
                    Id          = APPNAME,
                    Description = string.Format("Description for {0}", APPBUNBLENAME),
                };
                AppBundle newAppVersion = await _designAutomation.CreateAppBundleAsync(appBundleSpec);

                if (newAppVersion == null)
                {
                    throw new Exception("Cannot create new app");
                }

                // create alias pointing to v1
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateAppBundleAliasAsync(APPNAME, aliasSpec);

                // upload the zip with .bundle
                RestClient  uploadClient = new RestClient(newAppVersion.UploadParameters.EndpointURL);
                RestRequest request      = new RestRequest(string.Empty, Method.POST);
                request.AlwaysMultipartFormData = true;
                foreach (KeyValuePair <string, string> x in newAppVersion.UploadParameters.FormData)
                {
                    request.AddParameter(x.Key, x.Value);
                }
                request.AddFile("file", packageZipPath);
                request.AddHeader("Cache-Control", "no-cache");
                await uploadClient.ExecuteTaskAsync(request);
            }
        }
Example #3
0
        public async Task EnsureActivity()
        {
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            bool existActivity = false;

            foreach (string activity in activities.Data)
            {
                if (activity.Contains(ActivityFullName))
                {
                    existActivity = true;
                    continue;
                }
            }

            if (!existActivity)
            {
                string   commandLine  = string.Format(@"$(engine.path)\\revitcoreconsole.exe /i {0}$(args[inputFile].path){0} /al {0}$(appbundles[{1}].path){0}", "\"", AppName);
                Activity activitySpec = new Activity()
                {
                    Id         = ActivityName,
                    Appbundles = new List <string>()
                    {
                        AppBundleFullName
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = ENGINE_NAME,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "inputFile", new Parameter()
                          {
                              Description = "Input Revit File", LocalName = "$(inputFile)", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "result", new Parameter()
                          {
                              Description = "Resulting File", LocalName = ResultName, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                          } }
                    },
                    Settings = new Dictionary <string, ISetting>()
                    {
                        { "script", new StringSetting()
                          {
                              Value = Script
                          } }
                    }
                };
                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(ActivityName, aliasSpec);
            }
        }
Example #4
0
        public async Task EnsureActivity()
        {
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            bool existActivity = activities.Data.Any(item => item == ActivityFullName);

            if (!existActivity)
            {
                string   commandLine  = $"$(engine.path)\\accoreconsole.exe /i \"$(args[inputFile].path)\" /al \"$(appbundles[{AppName}].path)\" /s \"$(settings[script].path)\"";
                Activity activitySpec = new Activity()
                {
                    Id         = ActivityName,
                    Appbundles = new List <string>()
                    {
                        AppBundleFullName
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = ENGINE_NAME,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "inputFile", new Parameter()
                          {
                              Description = "Input Civil 3D File", LocalName = "$(inputFile)", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "params", new Parameter()
                          {
                              Description = "Input Parameters", LocalName = ParamsName, Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "result", new Parameter()
                          {
                              Description = "Resulting File", LocalName = ResultName, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                          } }
                    },
                    Settings = new Dictionary <string, ISetting>()
                    {
                        { "script", new StringSetting()
                          {
                              Value = Script
                          } }
                    }
                };
                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(ActivityName, aliasSpec);
            }
        }
        private async Task EnsureActivity()
        {
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            bool existActivity = false;

            foreach (string activity in activities.Data)
            {
                if (activity.Contains(ActivityFullName))
                {
                    existActivity = true;
                    continue;
                }
            }

            if (!existActivity)
            {
                // create activity
                string   commandLine  = string.Format(@"$(engine.path)\\InventorCoreConsole.exe /i {0}$(args[InventorDoc].path){0} /al {0}$(appbundles[{1}].path){0}", "\"", APPNAME);
                Activity activitySpec = new Activity()
                {
                    Id         = ACTIVITY_NAME,
                    Appbundles = new List <string>()
                    {
                        AppBundleFullName
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = ENGINE_NAME,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "InventorDoc", new Parameter()
                          {
                              Description = "Input IPT File", LocalName = "$(InventorDoc)", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "export", new Parameter()
                          {
                              Description = "Resulting SAT File", LocalName = "export.sat", Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                          } }
                    }
                };
                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(ACTIVITY_NAME, aliasSpec);
            }
        }
        public async Task <IActionResult> CreateAppBundle([FromBody] JObject appBundleSpecs)
        {
            // basic input validation
            string zipFileName = appBundleSpecs["zipFileName"].Value <string>();
            string engineName  = appBundleSpecs["engine"].Value <string>();

            // standard name for this sample
            string appBundleName = zipFileName + "AppBundle";

            // check if ZIP with bundle is here
            string packageZipPath = Path.Combine(LocalBundlesFolder, zipFileName + ".zip");

            if (!System.IO.File.Exists(packageZipPath))
            {
                throw new Exception("Appbundle not found at " + packageZipPath);
            }

            // get defined app bundles
            Page <string> appBundles = await _designAutomation.GetAppBundlesAsync();

            // check if app bundle is already define
            dynamic newAppVersion;
            string  qualifiedAppBundleId = string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias);

            if (!appBundles.Data.Contains(qualifiedAppBundleId))
            {
                // create an appbundle (version 1)
                AppBundle appBundleSpec = new AppBundle()
                {
                    Package     = appBundleName,
                    Engine      = engineName,
                    Id          = appBundleName,
                    Description = string.Format("Description for {0}", appBundleName),
                };
                newAppVersion = await _designAutomation.CreateAppBundleAsync(appBundleSpec);

                if (newAppVersion == null)
                {
                    throw new Exception("Cannot create new app");
                }

                // create alias pointing to v1
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateAppBundleAliasAsync(appBundleName, aliasSpec);
            }
            else
            {
                // create new version
                AppBundle appBundleSpec = new AppBundle()
                {
                    Engine      = engineName,
                    Description = appBundleName
                };
                newAppVersion = await _designAutomation.CreateAppBundleVersionAsync(appBundleName, appBundleSpec);

                if (newAppVersion == null)
                {
                    throw new Exception("Cannot create new version");
                }

                // update alias pointing to v+1
                AliasPatch aliasSpec = new AliasPatch()
                {
                    Version = newAppVersion.Version
                };
                Alias newAlias = await _designAutomation.ModifyAppBundleAliasAsync(appBundleName, Alias, aliasSpec);
            }

            // upload the zip with .bundle
            RestClient  uploadClient = new RestClient(newAppVersion.UploadParameters.EndpointURL);
            RestRequest request      = new RestRequest(string.Empty, Method.POST);

            request.AlwaysMultipartFormData = true;
            foreach (KeyValuePair <string, string> x in newAppVersion.UploadParameters.FormData)
            {
                request.AddParameter(x.Key, x.Value);
            }
            request.AddFile("file", packageZipPath);
            request.AddHeader("Cache-Control", "no-cache");
            await uploadClient.ExecuteTaskAsync(request);

            return(Ok(new { AppBundle = qualifiedAppBundleId, Version = newAppVersion.Version }));
        }
        public async Task <IActionResult> CreateActivity([FromBody] JObject activitySpecs)
        {
            // basic input validation
            string zipFileName = activitySpecs["zipFileName"].Value <string>();
            string engineName  = activitySpecs["engine"].Value <string>();

            // standard name for this sample
            string appBundleName = zipFileName + "AppBundle";
            string activityName  = zipFileName + "Activity";

            //
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            string qualifiedActivityId = string.Format("{0}.{1}+{2}", NickName, activityName, Alias);

            if (!activities.Data.Contains(qualifiedActivityId))
            {
                // define the activity
                // ToDo: parametrize for different engines...
                dynamic engineAttributes = EngineAttributes(engineName);

                string   commandLine  = string.Format(engineAttributes.commandLine, appBundleName);
                Activity activitySpec = new Activity()
                {
                    Id         = activityName,
                    Appbundles = new List <string>()
                    {
                        string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias)
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = engineName,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "inputFile", new Parameter()
                          {
                              Description = "input file", LocalName = "$(inputFile)", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "inputJson", new Parameter()
                          {
                              Description = "input json", LocalName = "params.json", Ondemand = false, Required = false, Verb = Verb.Get, Zip = false
                          } },
                        { "outputFile", new Parameter()
                          {
                              Description = "output file", LocalName = "outputFile." + engineAttributes.extension, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                          } }
                    },
                    Settings = new Dictionary <string, ISetting>()
                    {
                        { "script", new StringSetting()
                          {
                              Value = engineAttributes.script
                          } }
                    }
                };
                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(activityName, aliasSpec);

                return(Ok(new { Activity = qualifiedActivityId }));
            }

            // as this activity points to a AppBundle "dev" alias (which points to the last version of the bundle),
            // there is no need to update it (for this sample), but this may be extended for different contexts
            return(Ok(new { Activity = "Activity already defined" }));
        }
Example #8
0
        private async Task EnsureActivity()
        {
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            bool existActivity = false;

            foreach (string activity in activities.Data)
            {
                if (activity.Contains(ActivityFullName))
                {
                    existActivity = true;
                    continue;
                }
            }

            if (!existActivity)
            {
                // create activity
                string   commandLine  = string.Format(@"$(engine.path)\\revitcoreconsole.exe /i $(args[rvtFile].path) /al $(appbundles[{0}].path)", APPNAME);
                Activity activitySpec = new Activity()
                {
                    Id         = ACTIVITY_NAME,
                    Appbundles = new List <string>()
                    {
                        AppBundleFullName
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = ENGINE_NAME,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "rvtFile", new Parameter()
                          {
                              Description = "Input Revit Model", LocalName = "$(rvtFile)", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "inputGeometry", new Parameter()
                          {
                              Description = "Input SAT File", LocalName = "InputGeometry.sat", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "familyTemplate", new Parameter()
                          {
                              Description = "Input RFT File", LocalName = "FamilyTemplate.rft", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "result", new Parameter()
                          {
                              Description = "Modifed Revit Model", LocalName = "ResultModel.rvt", Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                          } }
                    }
                };
                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(ACTIVITY_NAME, aliasSpec);
            }
        }
        public async Task <IActionResult> CreateActivity([FromBody] JObject activitySpecs)
        {
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            string qualifiedActivityId = string.Format("{0}.{1}+{2}", NickName, ActivityName, Alias);

            if (!activities.Data.Contains(qualifiedActivityId))
            {
                // define the activity
                // ToDo: parametrize for different engines...
                dynamic engineAttributes = EngineAttributes(EngineName);

                string   commandLine  = string.Format(engineAttributes.commandLine, AppBundleName);
                Activity activitySpec = new Activity()
                {
                    Id         = ActivityName,
                    Appbundles = new List <string>()
                    {
                        string.Format("{0}.{1}+{2}", NickName, AppBundleName, Alias)
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = EngineName,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "inputFile", new Parameter()
                          {
                              Description = "IAM file to process",
                              LocalName   = "CleanSlate.iam",
                              Verb        = Verb.Get,
                              Zip         = true
                          } },
                        { "inputJson", new Parameter()
                          {
                              Description = "JSON file with User Params",
                              LocalName   = "params.json",
                              Verb        = Verb.Get,
                              Zip         = false
                          } },
                        { "outputFile", new Parameter()
                          {
                              Description = "Resulting assembly",
                              LocalName   = @"Kitchen\Result",
                              Verb        = Verb.Put,
                              Zip         = true
                          } }
                    }
                };
                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(ActivityName, aliasSpec);

                return(Ok(new { Activity = qualifiedActivityId }));
            }

            // as this activity points to a AppBundle "dev" alias (which points to the last version of the bundle),
            // there is no need to update it (for this sample), but this may be extended for different contexts
            return(Ok(new { Activity = "Activity already defined" }));
        }
Example #10
0
        public async Task <IActionResult> CreateAppBundle([FromBody] JObject appBundleSpecs) //
        {
            //each call make new instance so every time i is nessessary to read Engine name
            string EngineName = appBundleSpecs["engine"].Value <string>();

            // check if ZIP with bundle is here
            string packageZipPath = Path.Combine(LocalBundlesFolder, ZipFileName);

            if (!System.IO.File.Exists(packageZipPath))
            {
                throw new Exception("Appbundle not found at " + packageZipPath);
            }

            // get defined app bundles
            Page <string> appBundles = await _designAutomation.GetAppBundlesAsync();

            // check if app bundle is already define
            dynamic newAppVersion;
            string  qualifiedAppBundleId = string.Format("{0}.{1}+{2}", NickName, AppBundleName, Alias);

            if (!appBundles.Data.Contains(qualifiedAppBundleId))
            {
                // create an appbundle (version 1)
                AppBundle appBundleSpec = new AppBundle()
                {
                    Package     = packageZipPath,
                    Engine      = EngineName,
                    Id          = AppBundleName,
                    Description = "Creates wall shelf based on JSON file",
                };
                newAppVersion = await _designAutomation.CreateAppBundleAsync(appBundleSpec);

                if (newAppVersion == null)
                {
                    throw new Exception("Cannot create new app");
                }

                // create alias pointing to v1
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateAppBundleAliasAsync(AppBundleName, aliasSpec);

                //upload the zip with .bundle
                RestClient  uploadClient = new RestClient(newAppVersion.UploadParameters.EndpointURL);
                RestRequest request      = new RestRequest(string.Empty, Method.POST);
                request.AlwaysMultipartFormData = true;
                foreach (KeyValuePair <string, string> x in newAppVersion.UploadParameters.FormData)
                {
                    request.AddParameter(x.Key, x.Value);
                }
                request.AddFile("file", packageZipPath);
                request.AddHeader("Cache-Control", "no-cache");
                await uploadClient.ExecuteAsync(request);
            }

            /*
             * else // TODO - Remove this code for creating versions.
             * {
             *  // create new version
             *  AppBundle appBundleSpec = new AppBundle()
             *  {
             *      Engine = engineName,
             *      Description = appBundleName
             *  };
             *  newAppVersion = await _designAutomation.CreateAppBundleVersionAsync(appBundleName, appBundleSpec);
             *  if (newAppVersion == null) throw new Exception("Cannot create new version");
             *
             *  // update alias pointing to v+1
             *  AliasPatch aliasSpec = new AliasPatch()
             *  {
             *      Version = newAppVersion.Version
             *  };
             *  Alias newAlias = await _designAutomation.ModifyAppBundleAliasAsync(appBundleName, Alias, aliasSpec);
             * }
             *
             * // upload the zip with .bundle
             * RestClient uploadClient = new RestClient(newAppVersion.UploadParameters.EndpointURL);
             * RestRequest request = new RestRequest(string.Empty, Method.POST);
             * request.AlwaysMultipartFormData = true;
             * foreach (KeyValuePair<string, string> x in newAppVersion.UploadParameters.FormData) request.AddParameter(x.Key, x.Value);
             * request.AddFile("file", packageZipPath);
             * request.AddHeader("Cache-Control", "no-cache");
             * await uploadClient.ExecuteAsync(request);
             *
             * return Ok(new { AppBundle = qualifiedAppBundleId, Version = newAppVersion.Version });*/
            return(Ok(new { AppBundle = qualifiedAppBundleId, Version = "1" }));
        }
Example #11
0
        public async Task <IActionResult> CreateActivity([FromBody] JObject activitySpecs)
        {
            if (OAuthController.GetAppSetting("DISABLE_SETUP") == "true")
            {
                return(Unauthorized());
            }

            System.Diagnostics.Debug.WriteLine("CreateActivity");
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            if (!activities.Data.Contains(QualifiedBundleActivityName))
            {
                string   commandLine  = CommandLine();
                Activity activitySpec = new Activity()
                {
                    Id         = kBundleActivityName,
                    Appbundles = new List <string>()
                    {
                        QualifiedBundleActivityName
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = kEngineName,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "inputJson", new Parameter()
                          {
                              Description = "input json", LocalName = "params.json", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "outputZip", new Parameter()
                          {
                              Description = "output zip file", LocalName = "output.zip", Ondemand = false, Required = false, Verb = Verb.Put, Zip = false
                          } },
                        { "outputPng", new Parameter()
                          {
                              Description = "output png file", LocalName = "output.png", Ondemand = false, Required = false, Verb = Verb.Put, Zip = false
                          } },
                        { "outputJson", new Parameter()
                          {
                              Description = "output json file", LocalName = "output.json", Ondemand = false, Required = false, Verb = Verb.Put, Zip = false
                          } }
                    }
                };
                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(kBundleActivityName, aliasSpec);

                return(Ok(new { Activity = QualifiedBundleActivityName }));
            }

            // as this activity points to a AppBundle "dev" alias (which points to the last version of the bundle),
            // there is no need to update it (for this sample), but this may be extended for different contexts
            return(Ok(new { Activity = "Activity already defined" }));
        }
        public async Task <IActionResult> CreateAppBundle([FromBody] JObject appBundleSpecs)
        {
            // 基本入力検証
            string zipFileName = appBundleSpecs["zipFileName"].Value <string>();
            string engineName  = appBundleSpecs["engine"].Value <string>();

            // このサンプルの標準名
            string appBundleName = zipFileName + "AppBundle";

            // ZIP with bundle がここに存在するかどうかを確認する
            string packageZipPath = Path.Combine(LocalBundlesFolder, zipFileName + ".zip");

            if (!System.IO.File.Exists(packageZipPath))
            {
                throw new Exception("Appbundle not found at " + packageZipPath);
            }

            // アプリケーションバンドルを定義する
            Page <string> appBundles = await _designAutomation.GetAppBundlesAsync();

            // アプリケーションバンドルがすでに定義されているかどうかを確認する
            dynamic newAppVersion;
            string  qualifiedAppBundleId = string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias);

            if (!appBundles.Data.Contains(qualifiedAppBundleId))
            {
                // appbundle(version 1)を作成す
                AppBundle appBundleSpec = new AppBundle()
                {
                    Package     = appBundleName,
                    Engine      = engineName,
                    Id          = appBundleName,
                    Description = string.Format("Description for {0}", appBundleName),
                };
                newAppVersion = await _designAutomation.CreateAppBundleAsync(appBundleSpec);

                if (newAppVersion == null)
                {
                    throw new Exception("Cannot create new app");
                }

                // v1を指すエイリアスを作成する
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateAppBundleAliasAsync(appBundleName, aliasSpec);
            }
            else
            {
                // 新しいバージョンを作成する
                AppBundle appBundleSpec = new AppBundle()
                {
                    Engine      = engineName,
                    Description = appBundleName
                };
                newAppVersion = await _designAutomation.CreateAppBundleVersionAsync(appBundleName, appBundleSpec);

                if (newAppVersion == null)
                {
                    throw new Exception("Cannot create new version");
                }

                // v+1を指す更新エイリアス
                AliasPatch aliasSpec = new AliasPatch()
                {
                    Version = newAppVersion.Version
                };
                Alias newAlias = await _designAutomation.ModifyAppBundleAliasAsync(appBundleName, Alias, aliasSpec);
            }

            // .bundleでzipをアップロードする
            RestClient  uploadClient = new RestClient(newAppVersion.UploadParameters.EndpointURL);
            RestRequest request      = new RestRequest(string.Empty, Method.POST);

            request.AlwaysMultipartFormData = true;
            foreach (KeyValuePair <string, string> x in newAppVersion.UploadParameters.FormData)
            {
                request.AddParameter(x.Key, x.Value);
            }
            request.AddFile("file", packageZipPath);
            request.AddHeader("Cache-Control", "no-cache");
            await uploadClient.ExecuteTaskAsync(request);

            return(Ok(new { AppBundle = qualifiedAppBundleId, Version = newAppVersion.Version }));
        }
        public async Task <IActionResult> CreateActivity([FromBody] JObject activitySpecs)
        {
            // 基本入力検証
            string zipFileName = activitySpecs["zipFileName"].Value <string>();
            string engineName  = activitySpecs["engine"].Value <string>();

            // このサンプルの標準名
            string appBundleName = zipFileName + "AppBundle";
            string activityName  = zipFileName + "Activity";

            //
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            string qualifiedActivityId = string.Format("{0}.{1}+{2}", NickName, activityName, Alias);

            if (!activities.Data.Contains(qualifiedActivityId))
            {
                // アクティビティを定義する
                // ToDo: 異なるエンジン用のパラメタライズ...
                dynamic  engineAttributes = EngineAttributes(engineName);
                string   commandLine      = string.Format(engineAttributes.commandLine, appBundleName);
                Activity activitySpec     = new Activity()
                {
                    Id         = activityName,
                    Appbundles = new List <string>()
                    {
                        string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias)
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = engineName,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "inputFile", new Parameter()
                          {
                              Description = "input file", LocalName = "$(inputFile)", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "inputJson", new Parameter()
                          {
                              Description = "input json", LocalName = "params.json", Ondemand = false, Required = false, Verb = Verb.Get, Zip = false
                          } },
                        { "outputFile", new Parameter()
                          {
                              Description = "output file", LocalName = "outputFile." + engineAttributes.extension, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                          } }
                    },
                    Settings = new Dictionary <string, ISetting>()
                    {
                        { "script", new StringSetting()
                          {
                              Value = engineAttributes.script
                          } }
                    }
                };
                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // このアクティビティのエイリアスを指定する
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(activityName, aliasSpec);

                return(Ok(new { Activity = qualifiedActivityId }));
            }

            // このアクティビティは,AppBundleの"dev"エイリアス(バンドルの最後のバージョンを指す)を指します。
            // アップデートの必要はありませんが(このサンプルでは),これは異なるコンテキスト用に拡張できます。
            return(Ok(new { Activity = "Activity already defined" }));
        }
Example #14
0
        public async Task <IActionResult> CreateActivity([FromBody] JObject activitySpecs)
        {
            // basic input validation
            string zipFileName = activitySpecs["zipFileName"].Value <string>();
            string engineName  = activitySpecs["engine"].Value <string>();

            // standard name for this sample
            string appBundleName = zipFileName + "AppBundle";
            string activityName  = zipFileName + "Activity";

            //
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            string qualifiedActivityId = string.Format("{0}.{1}+{2}", NickName, activityName, Alias);

            if (!activities.Data.Contains(qualifiedActivityId))
            {
                // define the activity
                // ToDo: parametrize for different engines...
                dynamic  engineAttributes = EngineAttributes(engineName);
                string   commandLine;
                Activity activitySpec;
                if (engineName.Contains("3dsMax"))
                {
                    // Note, 3ds Max DA engine does not need to specify app bundle in commandline.
                    commandLine  = string.Format(@"$(engine.path)\\{0} -sceneFile $(args[inputFile].path) $(settings[script].path)", engineAttributes.executable);
                    activitySpec = new Activity()
                    {
                        Id         = activityName,
                        Appbundles = new List <string>()
                        {
                            string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias)
                        },
                        CommandLine = new List <string>()
                        {
                            commandLine
                        },
                        Engine     = engineName,
                        Parameters = new Dictionary <string, Parameter>()
                        {
                            { "inputFile", new Parameter()
                              {
                                  Description = "input file", LocalName = "$(inputFile)", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                              } },
                            { "inputJson", new Parameter()
                              {
                                  Description = "input json", LocalName = "params.json", Ondemand = false, Required = false, Verb = Verb.Get, Zip = false
                              } },
                            { "outputFile", new Parameter()
                              {
                                  Description = "output file", LocalName = "outputFile." + engineAttributes.extension, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                              } }
                        },
                        Settings = new Dictionary <string, ISetting>()
                        {
                            { "script", new StringSetting()
                              {
                                  Value = "da = dotNetClass(\"Autodesk.Forge.Sample.DesignAutomation.Max.RuntimeExecute\")\n" +
                                          "da.ModifyWindowWidthHeight()\n"
                              } }
                        }
                    };
                }
                else
                {
                    commandLine  = string.Format(@"$(engine.path)\\{0} /i $(args[inputFile].path) /al $(appbundles[{1}].path) /s $(settings[script].path)", engineAttributes.executable, appBundleName);
                    activitySpec = new Activity()
                    {
                        Id         = activityName,
                        Appbundles = new List <string>()
                        {
                            string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias)
                        },
                        CommandLine = new List <string>()
                        {
                            commandLine
                        },
                        Engine     = engineName,
                        Parameters = new Dictionary <string, Parameter>()
                        {
                            { "inputFile", new Parameter()
                              {
                                  Description = "input file", LocalName = "$(inputFile)", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                              } },
                            { "inputJson", new Parameter()
                              {
                                  Description = "input json", LocalName = "params.json", Ondemand = false, Required = false, Verb = Verb.Get, Zip = false
                              } },
                            { "outputFile", new Parameter()
                              {
                                  Description = "output file", LocalName = "outputFile." + engineAttributes.extension, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                              } }
                        },
                        Settings = new Dictionary <string, ISetting>()
                        {
                            { "script", new StringSetting()
                              {
                                  Value = "UpdateParam"
                              } }
                        }
                    };
                }


                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(activityName, aliasSpec);

                return(Ok(new { Activity = qualifiedActivityId }));
            }

            // as this activity points to a AppBundle "dev" alias (which points to the last version of the bundle),
            // there is no need to update it (for this sample), but this may be extended for different contexts
            return(Ok(new { Activity = "Activity already defined" }));
        }
        /// <summary>
        /// Creates Activity
        /// </summary>
        private async Task <dynamic> CreateActivity()
        {
            Page <string> appBundles = await _designAutomation.GetAppBundlesAsync();

            string appBundleID = string.Format("{0}.{1}+{2}", nickName, APPNAME, ALIAS);

            if (!appBundles.Data.Contains(appBundleID))
            {
                if (!System.IO.File.Exists(LocalAppPackageZip))
                {
                    throw new Exception("Appbundle not found at " + LocalAppPackageZip);
                }
                AppBundle appBundleSpec = new AppBundle()
                {
                    Package     = APPNAME,
                    Engine      = EngineName,
                    Id          = APPNAME,
                    Description = string.Format("Description for {0}", APPNAME),
                };
                AppBundle newApp = await _designAutomation.CreateAppBundleAsync(appBundleSpec);

                if (newApp == null)
                {
                    throw new Exception("Cannot create new app");
                }

                // create alias pointing to v1
                Alias aliasSpec = new Alias()
                {
                    Id = ALIAS, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateAppBundleAliasAsync(APPNAME, aliasSpec);

                // upload the zip with .bundle
                RestClient  uploadClient = new RestClient(newApp.UploadParameters.EndpointURL);
                RestRequest request      = new RestRequest(string.Empty, Method.POST);
                request.AlwaysMultipartFormData = true;
                foreach (KeyValuePair <string, string> x in newApp.UploadParameters.FormData)
                {
                    request.AddParameter(x.Key, x.Value);
                }
                request.AddFile("file", LocalAppPackageZip);
                request.AddHeader("Cache-Control", "no-cache");
                await uploadClient.ExecuteTaskAsync(request);
            }
            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            string qualifiedActivityId = string.Format("{0}.{1}+{2}", nickName, ACTIVITY_NAME, ALIAS);

            if (!activities.Data.Contains(qualifiedActivityId))
            {
                // define the activity
                string   commandLine  = string.Format(@"$(engine.path)\\inventorcoreconsole.exe /al $(appbundles[{0}].path) $(args[inputJson].path)", APPNAME);
                Activity activitySpec = new Activity()
                {
                    Id         = ACTIVITY_NAME,
                    Appbundles = new List <string>()
                    {
                        string.Format("{0}.{1}+{2}", nickName, APPNAME, ALIAS)
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = EngineName,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "inputJson", new Parameter()
                          {
                              Description = "input json", LocalName = "params.json", Ondemand = false, Required = false, Verb = Verb.Get, Zip = false
                          } },
                        { "ResultIPT", new Parameter()
                          {
                              Description = "output IPT file", LocalName = outputIPTFile, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                          } },
                        { "ResultIDW", new Parameter()
                          {
                              Description = "output IDW file", LocalName = outputIDWFile, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                          } },
                        { "ResultPDF", new Parameter()
                          {
                              Description = "output PDF file", LocalName = outputPDFile, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false
                          } }
                    }
                };

                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = ALIAS, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(ACTIVITY_NAME, aliasSpec);

                return(Ok(new { Activity = qualifiedActivityId }));
            }
            return(Ok(new { Activity = "Activity already defined" }));
        }
Example #16
0
        public async Task <IActionResult> CreateActivity([FromBody] JObject activitySpecs)
        {
            string EngineName = activitySpecs["engine"].Value <string>();

            Page <string> activities = await _designAutomation.GetActivitiesAsync();

            string qualifiedActivityId = string.Format("{0}.{1}+{2}", NickName, ActivityName, Alias);

            if (!activities.Data.Contains(qualifiedActivityId))
            {
                // define the activity
                dynamic  engineAttributes = EngineAttributes();
                string   commandLine      = string.Format(engineAttributes.commandLine, AppBundleName);
                Activity activitySpec     = new Activity()
                {
                    Id         = ActivityName,
                    Appbundles = new List <string>()
                    {
                        string.Format("{0}.{1}+{2}", NickName, AppBundleName, Alias)
                    },
                    CommandLine = new List <string>()
                    {
                        commandLine
                    },
                    Engine     = EngineName,
                    Parameters = new Dictionary <string, Parameter>()
                    {
                        { "inputFile", new Parameter()
                          {
                              Description = "input Data Set for wall shelf creation",
                              LocalName   = "MyWallShelf.iam",
                              Verb        = Verb.Get,
                              Zip         = true
                          } },/*
                               * { "inputJson", new Parameter()
                               * {
                               *    Description = "input json",
                               *    LocalName = "params.json",
                               *    Verb = Verb.Get,
                               *    Zip = false
                               * }
                               *    },*/
                        { "outputFile", new Parameter()
                          {
                              Description = "Resulting model and drawing",
                              LocalName   = "Wall_shelf",
                              Verb        = Verb.Put,
                              Zip         = true
                          } },
                        { "outputPDFFile", new Parameter()
                          {
                              Description = "Drawing in PDF format",
                              LocalName   = @"Wall_shelf\test.pdf",
                              Verb        = Verb.Put,
                              Zip         = false
                          } }
                    }
                };
                Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateActivityAliasAsync(ActivityName, aliasSpec);

                return(Ok(new { Activity = qualifiedActivityId }));
            }

            // as this activity points to a AppBundle "dev" alias (which points to the last version of the bundle),
            // there is no need to update it (for this sample), but this may be extended for different contexts
            return(Ok(new { Activity = "Activity already defined" }));
        }
        public async Task <IActionResult> CreateAppBundle() //([FromBody] JObject appBundleSpecs)
        {
            // check if ZIP with bundle is here
            string packageZipPath = Path.Combine(LocalBundlesFolder, ZipFileName);

            if (!System.IO.File.Exists(packageZipPath))
            {
                throw new Exception("Appbundle not found at " + packageZipPath);
            }

            // get defined app bundles - but this line is wrong when running on heroku server instead of localhost.
            Page <string> appBundles = await _designAutomation.GetAppBundlesAsync();

            // check if app bundle is already define
            dynamic newAppVersion;
            string  qualifiedAppBundleId = string.Format("{0}.{1}+{2}", NickName, AppBundleName, Alias);

            if (!appBundles.Data.Contains(qualifiedAppBundleId))
            {
                // create an appbundle (version 1)
                AppBundle appBundleSpec = new AppBundle()
                {
                    Package     = packageZipPath, //appBundleName,
                    Engine      = EngineName,
                    Id          = AppBundleName,
                    Description = "Creates an kitchen elements based on template files"
                };
                newAppVersion = await _designAutomation.CreateAppBundleAsync(appBundleSpec);

                if (newAppVersion == null)
                {
                    throw new Exception("Cannot create new app");
                }

                // create alias pointing to v1
                Alias aliasSpec = new Alias()
                {
                    Id = Alias, Version = 1
                };
                Alias newAlias = await _designAutomation.CreateAppBundleAliasAsync(AppBundleName, aliasSpec);

                // upload the zip with .bundle
                RestClient  uploadClient = new RestClient(newAppVersion.UploadParameters.EndpointURL);
                RestRequest request      = new RestRequest(string.Empty, Method.POST);
                request.AlwaysMultipartFormData = true;
                foreach (KeyValuePair <string, string> x in newAppVersion.UploadParameters.FormData)
                {
                    request.AddParameter(x.Key, x.Value);
                }
                request.AddFile("file", packageZipPath);
                request.AddHeader("Cache-Control", "no-cache");
                await uploadClient.ExecuteTaskAsync(request);
            }

            /* else
             * {
             *
             *  // create new version
             *  AppBundle appBundleSpec = new AppBundle()
             *  {
             *      Engine = EngineName,
             *      Description = AppBundleName
             *  };
             *  newAppVersion = await _designAutomation.CreateAppBundleVersionAsync(AppBundleName, appBundleSpec);
             *  if (newAppVersion == null)
             *  {
             *      throw new Exception("Cannot create new version");
             *  }
             *
             *  // update alias pointing to v+1
             *  AliasPatch aliasSpec = new AliasPatch()
             *  {
             *      Version = newAppVersion.Version
             *  };
             *  Alias newAlias = await _designAutomation.ModifyAppBundleAliasAsync(AppBundleName, Alias, aliasSpec);
             * }
             *
             * // upload the zip with .bundle
             * RestClient uploadClient = new RestClient(newAppVersion.UploadParameters.EndpointURL);
             * RestRequest request = new RestRequest(string.Empty, Method.POST);
             * request.AlwaysMultipartFormData = true;
             * foreach (KeyValuePair<string, string> x in newAppVersion.UploadParameters.FormData) request.AddParameter(x.Key, x.Value);
             * request.AddFile("file", packageZipPath);
             * request.AddHeader("Cache-Control", "no-cache");
             * await uploadClient.ExecuteTaskAsync(request);
             *
             * return Ok(new { AppBundle = qualifiedAppBundleId, Version = newAppVersion.Version });*/
            return(Ok(new { AppBundle = qualifiedAppBundleId, Version = "1" }));
        }