/// <summary>
        /// Creates a new WorkItem
        /// </summary>
        /// <param name="activityId">ActivityId that is associated with the new workItem</param>
        /// <param name="hostDwgS3Url">Url of the drawing after it has been uploaded to Amazon S3</param>
        /// <returns>true if WorkItem was created, false otherwise</returns>
        public static String SubmitWorkItem(String activityId, String hostDwgS3Url)
        {
            try
            {
                AIO.ACES.Models.WorkItem wi = new AIO.ACES.Models.WorkItem()
                {
                    Id = "",
                    Arguments = new AIO.ACES.Models.Arguments(),
                    ActivityId = activityId 
                };

                // Drawing
                wi.Arguments.InputArguments.Add(new AIO.ACES.Models.Argument()
                {
                    Name = "HostDwg",
                    Resource = hostDwgS3Url,
                    StorageProvider = AIO.ACES.Models.StorageProvider.Generic,
                    HttpVerb = AIO.ACES.Models.HttpVerbType.GET
                });

                wi.Arguments.OutputArguments.Add(new AIO.ACES.Models.Argument()
                {
                    Name = "Result",
                    Resource = null,
                    StorageProvider = AIO.ACES.Models.StorageProvider.Generic,
                    HttpVerb = AIO.ACES.Models.HttpVerbType.POST
                });

                container.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;
                container.AddToWorkItems(wi);
                container.SaveChanges();

                Console.WriteLine("Submitted WorkItem. WorkItem Id= {0}", wi.Id);
                Console.WriteLine("Checking WorkItem status...");

                do
                {
                    System.Threading.Thread.Sleep(5000);
                    wi = container.WorkItems.Where(p => p.Id == wi.Id).SingleOrDefault();
                    Console.WriteLine("WorkItem Status : {0}", wi.Status);
                } while (wi.Status == AIO.ACES.Models.ExecutionStatus.Pending || wi.Status == AIO.ACES.Models.ExecutionStatus.InProgress);

                Console.WriteLine("WorkItem Status : {0}", wi.Status);
                Console.WriteLine("The result is downloadable at {0}", wi.Arguments.OutputArguments.First().Resource);

                return wi.Arguments.OutputArguments.First().Resource;
            }
            catch (System.Net.WebException ex)
            {
                Console.WriteLine(String.Format("WorkItem using {0} activity was not processed. {1}", activityId, ex.Message));
            }
            catch (System.Data.Services.Client.DataServiceRequestException ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(String.Format("WorkItem using {0} activity was not processed. {1}", activityId, ex.Message));
            }

            return String.Empty;
        }
Exemple #2
0
        /// <summary>
        /// Creates a new WorkItem
        /// </summary>
        /// <param name="activityId">ActivityId that is associated with the new workItem</param>
        /// <param name="hostDwgS3Url">Url of the drawing after it has been uploaded to Amazon S3</param>
        /// <returns>true if WorkItem was created, false otherwise</returns>
        public static String SubmitWorkItem(String activityId, String hostDwgS3Url)
        {
            try
            {
                AIO.ACES.Models.WorkItem wi = new AIO.ACES.Models.WorkItem()
                {
                    Id         = "",
                    Arguments  = new AIO.ACES.Models.Arguments(),
                    ActivityId = activityId
                };

                // Drawing
                wi.Arguments.InputArguments.Add(new AIO.ACES.Models.Argument()
                {
                    Name            = "HostDwg",
                    Resource        = hostDwgS3Url,
                    StorageProvider = AIO.ACES.Models.StorageProvider.Generic,
                    HttpVerb        = AIO.ACES.Models.HttpVerbType.GET
                });

                wi.Arguments.OutputArguments.Add(new AIO.ACES.Models.Argument()
                {
                    Name            = "Result",
                    Resource        = null,
                    StorageProvider = AIO.ACES.Models.StorageProvider.Generic,
                    HttpVerb        = AIO.ACES.Models.HttpVerbType.POST
                });

                container.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;
                container.AddToWorkItems(wi);
                container.SaveChanges();

                Console.WriteLine("Submitted WorkItem. WorkItem Id= {0}", wi.Id);
                Console.WriteLine("Checking WorkItem status...");

                do
                {
                    System.Threading.Thread.Sleep(5000);
                    wi = container.WorkItems.Where(p => p.Id == wi.Id).SingleOrDefault();
                    Console.WriteLine("WorkItem Status : {0}", wi.Status);
                } while (wi.Status == AIO.ACES.Models.ExecutionStatus.Pending || wi.Status == AIO.ACES.Models.ExecutionStatus.InProgress);

                Console.WriteLine("WorkItem Status : {0}", wi.Status);
                Console.WriteLine("The result is downloadable at {0}", wi.Arguments.OutputArguments.First().Resource);

                return(wi.Arguments.OutputArguments.First().Resource);
            }
            catch (System.Net.WebException ex)
            {
                Console.WriteLine(String.Format("WorkItem using {0} activity was not processed. {1}", activityId, ex.Message));
            }
            catch (System.Data.Services.Client.DataServiceRequestException ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(String.Format("WorkItem using {0} activity was not processed. {1}", activityId, ex.Message));
            }

            return(String.Empty);
        }