コード例 #1
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  = 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
                          } },
                        { "outputFile", new Parameter()
                          {
                              Description = "output file", LocalName = "outputFile." + engineAttributes.extension, Ondemand = false, Required = true, Verb = Verb.Put, Zip = true
                          } }
                    },
                    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" }));
        }
コード例 #2
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>()
                    {
                        { "inputZip", new Parameter()
                          {
                              Description = "input zip", LocalName = "files", Ondemand = false, Required = true, Verb = Verb.Get, Zip = true
                          } },
                        { "inputJson", new Parameter()
                          {
                              Description = "input json", LocalName = "input.json", Ondemand = false, Required = true, Verb = Verb.Get, Zip = false
                          } },
                        { "outputZip", new Parameter()
                          {
                              Description = "output zip file", LocalName = "files", Ondemand = false, Required = false, Verb = Verb.Put, Zip = true
                          } },
                        { "outputRfa", new Parameter()
                          {
                              Description = "output zip file", LocalName = "output.rfa", 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" }));
        }
コード例 #3
0
        /// <summary>
        /// The SetupActivityAsync.
        /// </summary>
        /// <param name="myApp">The myApp<see cref="string"/>.</param>
        /// <returns>The <see cref="Task{string}"/>.</returns>
        private async Task <string> SetupActivityAsync(string myApp)
        {
            Console.WriteLine("Setting up activity...");
            var myActivity  = $"{Owner}.{ActivityName}+{Label}";
            var actResponse = await this.api.ActivitiesApi.GetActivityAsync(myActivity, throwOnError : false);

            var activity = new Activity()
            {
                Appbundles = new List <string>()
                {
                    myApp
                },
                CommandLine = new List <string>()
                {
                    $"$(engine.path)\\accoreconsole.exe /i " +
                    $"\"$(args[inputFile].path)\" " +
                    $"/al \"$(appbundles[{PackageName}].path)\" " +
                    $"/s \"$(settings[script].path)\" "
                },
                Engine   = TargetEngine,
                Settings = new Dictionary <string, ISetting>()
                {
                    { "script", new StringSetting()
                      {
                          Value = "BatchPublishCmd\n"
                      } }
                },
                Parameters = new Dictionary <string, Parameter>()
                {
                    { "inputFile", new Parameter()
                      {
                          Verb      = Verb.Get,
                          LocalName = "$(HostDwg)", Required = true
                      } },
                    { "inputZip", new Parameter()
                      {
                          Verb = Verb.Get,
                          Zip  = true, LocalName = "export", Required = true
                      } },
                    { "Result", new Parameter()
                      {
                          Verb      = Verb.Put,
                          LocalName = "result.pdf", Required = true
                      } }
                },
                Id = ActivityName
            };


            if (actResponse.HttpResponse.StatusCode == HttpStatusCode.NotFound)
            {
                Console.WriteLine($"Creating activity {myActivity}...");
                await api.CreateActivityAsync(activity, Label);

                return(myActivity);
            }
            await actResponse.HttpResponse.EnsureSuccessStatusCodeAsync();

            Console.WriteLine("\tFound existing activity...");
            if (!Equals(activity, actResponse.Content))
            {
                Console.WriteLine($"\tUpdating activity {myActivity}...");
                await api.UpdateActivityAsync(activity, Label);
            }
            return(myActivity);

            bool Equals(Autodesk.Forge.DesignAutomation.Model.Activity a, Autodesk.Forge.DesignAutomation.Model.Activity b)
            {
                Console.Write("\tComparing activities...");
                //ignore id and version
                b.Id      = a.Id;
                b.Version = a.Version;
                var res = a.ToString() == b.ToString();

                Console.WriteLine(res ? "Same." : "Different");
                return(res);
            }
        }
コード例 #4
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 {0}$(args[rvtFile].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>()
                    {
                        { "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);
            }
        }
        /// <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" }));
        }
コード例 #6
0
        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" }));
        }