Ejemplo n.º 1
0
        public async Task <bool> SendTaskCompletedEventAsync(ResultTypes resultType)
        {
            var taskCompletedEventUrl = $"{PlanUrl}/{ProjectId}/_apis/distributedtask/hubs/{HubName}/plans/{PlanId}/events?api-version=2.0-preview.1";

            var body = new
            {
                name   = "TaskCompleted",
                taskId = TaskInstanceId,
                jobId  = JobId,
                result = resultType.ToString().ToLowerInvariant()
            };

            var requestBody = JsonSerializer.Serialize(body);

            try
            {
                var result = await PostDataAsync(taskCompletedEventUrl, requestBody);

                if (!result.IsSuccessStatusCode)
                {
                    Console.WriteLine($"SendTaskCompletedEventAsync failed: {result.StatusCode} - {result.Content}");
                    return(false);
                }

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine($"SendTaskCompletedEventAsync failed: {taskCompletedEventUrl}");
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void ShowResult(ComplexResult complexResult)
        {
            List <Image>  images            = new List <Image>();
            List <string> image_graphics    = new List <string>();
            string        read_result       = null;
            int           result_id         = -1;
            ResultTypes   collected_results = ResultTypes.None;

            // Take a reference or copy values from the locked result info object. This is done
            // so that the lock is used only for a short period of time.
            lock (_currentResultInfoSyncLock)
            {
                foreach (var simple_result in complexResult.SimpleResults)
                {
                    collected_results |= simple_result.Id.Type;

                    switch (simple_result.Id.Type)
                    {
                    case ResultTypes.Image:
                        Image image = ImageArrivedEventArgs.GetImageFromImageBytes(simple_result.Data);
                        if (image != null)
                        {
                            images.Add(image);
                        }
                        break;

                    case ResultTypes.ImageGraphics:
                        image_graphics.Add(simple_result.GetDataAsString());
                        break;

                    case ResultTypes.ReadXml:
                        read_result = GetReadStringFromResultXml(simple_result.GetDataAsString());
                        result_id   = simple_result.Id.Id;
                        break;

                    case ResultTypes.ReadString:
                        read_result = simple_result.GetDataAsString();
                        result_id   = simple_result.Id.Id;
                        break;
                    }
                }
            }

            AddListItem(string.Format("Complex result arrived: resultId = {0}, read result = {1}", result_id, read_result));
            Log("Complex result contains", string.Format("{0}", collected_results.ToString()));

            if (images.Count > 0)
            {
                Image first_image = images[0];

                Size  image_size   = Gui.FitImageInControl(first_image.Size, picResultImage.Size);
                Image fitted_image = Gui.ResizeImageToBitmap(first_image, image_size);

                if (image_graphics.Count > 0)
                {
                    using (Graphics g = Graphics.FromImage(fitted_image))
                    {
                        foreach (var graphics in image_graphics)
                        {
                            ResultGraphics rg = GraphicsResultParser.Parse(graphics, new Rectangle(0, 0, image_size.Width, image_size.Height));
                            ResultGraphicsRenderer.PaintResults(g, rg);
                        }
                    }
                }

                if (picResultImage.Image != null)
                {
                    var image = picResultImage.Image;
                    picResultImage.Image = null;
                    image.Dispose();
                }

                picResultImage.Image = fitted_image;
                picResultImage.Invalidate();
            }

            if (read_result != null && !_cbEmulateEnabled)
            {
                lbReadString.Text = read_result;
            }
            if (_cbEmulateEnabled)
            {
                SendKeys.Send(read_result);
            }
        }
Ejemplo n.º 3
0
 public override string ToSmallString()
 {
     return(type.ToString() + "|" + Common.ArrayToString(result));
 }