static void SubmitWorkItem(AIO.Activity activity, string inResource, string inResourceKind) { Console.WriteLine("Submitting workitem..."); //create a workitem var wi = new AIO.WorkItem() { UserId = "", //must be set to empty Id = "", //must be set to empty Arguments = new AIO.Arguments(), Version = 1, //should always be 1 ActivityId = new AIO.EntityId { Id = activity.Id, UserId = activity.UserId } }; wi.Arguments.InputArguments.Add(new AIO.Argument() { Name = "HostDwg",// Must match the input parameter in activity Resource = inResource, ResourceKind = inResourceKind, StorageProvider = "Generic" //Generic HTTP download (as opposed to A360) }); wi.Arguments.OutputArguments.Add(new AIO.Argument() { Name = "PdfResult", // Must match activity's output param StorageProvider = "Generic", // Generic HTTP upload HttpVerb = "POST", // Use HTTP POST when delivering result Resource = null // Use storage provided by AutoCAD.io } ); container.AddToWorkItems(wi); container.SaveChanges(); //polling loop do { Console.WriteLine("Sleeping for 5 sec..."); System.Threading.Thread.Sleep(5000); container.LoadProperty(wi, "Status"); //http request is made here Console.WriteLine("WorkItem status: {0}", wi.Status); }while (wi.Status == "Pending" || wi.Status == "InProgress"); //re-query the service so that we can look at the details provided by the service container.MergeOption = System.Data.Services.Client.MergeOption.OverwriteChanges; wi = container.WorkItems.Where(p => p.UserId == wi.UserId && p.Id == wi.Id).First(); //Resource property of the output argument "Results" will have the output url var url = wi.Arguments.OutputArguments.First(a => a.Name == "PdfResult").Resource; DownloadToDocs(url, "AIO.pdf"); //download the status report url = wi.StatusDetails.Report; DownloadToDocs(url, "AIO-report.txt"); }
//creates an activity with inputs and variable number of outputs. static AIO.Activity CreateActivity(AIO.AppPackage package) { Console.WriteLine("Creating/Updating Activity..."); var activity = new AIO.Activity() { UserId = "", Id = ActivityName, Version = 1, Instruction = new AIO.Instruction() { Script = "_tilemode 1 " + "GRID OFF " + "insert formpro 0,0 \n" + "zoom e\n" + "insert bokl 108.38,34.885 0.666 0\n" + "insert korak700 108.38,34.885 0.666 0\n" + "insert BD24pnt 108.38,34.885 0.666 0\n" + "insert korak700 155,34.885 0.666 0\n" + "insert BD24pnvz 155,34.885 0.666 0\n" + "insert bokdl 201.62,34.885 0.666 0\n" + "LTSCALE 13\n" + "_tilemode 0 " + "_save result.dwg\n" + "_-export _pdf _all result.pdf\n" }, Parameters = new AIO.Parameters() { InputParameters = { new AIO.Parameter() { Name = "HostDwg", LocalFileName = "$(HostDwg)" }, }, OutputParameters = { new AIO.Parameter() { Name = "PdfResult", LocalFileName = "result.pdf" }, } }, RequiredEngineVersion = "20.0" }; container.AddToActivities(activity); container.SaveChanges(System.Data.Services.Client.SaveChangesOptions.PatchOnUpdate); //establish link to package container.AddLink(activity, "AppPackages", package); container.SaveChanges(); return(activity); }