Esempio n. 1
0
        static Activity CreateActivity(string activityname, string script, Container container)
        {
            Activity activity = null;

            try { activity = container.Activities.ByKey(activityname).GetValue(); }
            catch { }
            if (activity != null)
            {
                if (Prompts.PromptForKeyword(string.Format("Activity '{0}' already exists. Do you want to recreate it? [Yes/No]<No>", activityname)) == "Yes")
                {
                    container.DeleteObject(activity);
                    container.SaveChanges();
                    activity = null;
                }
                else
                {
                    return(activity);
                }
            }

            Console.WriteLine("Creating/Updating Activity...");
            activity = new Activity()
            {
                Id          = activityname,
                Instruction = new Instruction()
                {
                    Script = script
                },
                Parameters = new Parameters()
                {
                    InputParameters =
                    {
                        new Parameter()
                        {
                            Name = "HostDwg", LocalFileName = "$(HostDwg)"
                        },
                        new Parameter()
                        {
                            Name = "Params", LocalFileName = "params.json"
                        }
                    },
                    OutputParameters = { new Parameter()
                                         {
                                             Name = "Results", LocalFileName = "results.json"
                                         } }

                    //OutputParameters = { new Parameter() { Name = "Results", LocalFileName = "outputs" } }
                },
                RequiredEngineVersion = RequiredEngineVersion
            };
            activity.AppPackages.Add(PackageName);
            container.AddToActivities(activity);
            container.SaveChanges();
            return(activity);
        }
Esempio n. 2
0
        static AppPackage CreatePackage(Container container)
        {
            AppPackage package = null;

            try
            {
                package = container.AppPackages.ByKey(PackageName).GetValue();
            }
            catch
            {
            }
            if (package != null)
            {
                string res = null;
                res = Prompts.PromptForKeyword(string.Format("AppPackage '{0}' already exists. What do you want to do? [Recreate/Update/Leave]<Update>", PackageName));
                if (res == "Recreate")
                {
                    container.DeleteObject(package);
                    container.SaveChanges();
                    package = null;
                }
                if (res == "Leave")
                {
                    return(package);
                }
            }

            var dir = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);

            if (!File.Exists(Path.Combine(dir, "ArxApp.dll")))
            {
                Console.WriteLine("Error building ArxApp.dll");
                return(null);
            }

            string zipfile = CreateZip();

            if (string.IsNullOrEmpty(zipfile))
            {
                Console.WriteLine("Error creating package.zip");
                return(null);
            }
            Console.WriteLine("The package.zip file was successfully created");

            Console.WriteLine("Creating/Updating AppPackage...");
            // Query for the url to upload the AppPackage file
            var url    = container.AppPackages.GetUploadUrl().GetValue();
            var client = new HttpClient();

            // Upload AppPackage file
            client.PutAsync(url, new StreamContent(File.OpenRead(zip))).Result.EnsureSuccessStatusCode();

            // third step -- after upload, create the AppPackage entity
            if (package == null)
            {
                package = new AppPackage()
                {
                    Id = PackageName,
                    RequiredEngineVersion = RequiredEngineVersion,
                    Resource = url
                };
                container.AddToAppPackages(package);
            }
            else
            {
                package.Resource = url;
                container.UpdateObject(package);
            }

            container.SaveChanges();
            return(package);
        }