protected override void Execute(NativeActivityContext context)
 {
     try
     {
         //ThreadInvoker.Instance.RunByUiThread(() =>
         //{
         string ScreenPath = ImagePath.Get(context);
         if ((ScreenPath != null) && (ScreenPath != string.Empty))
         {
             if (File.Exists(ScreenPath))
             {
                 string           sValue         = SetText.Get(context);
                 GetSetClick      getSetClick    = new GetSetClick();
                 ImageRecognition imgRecognition = new ImageRecognition();
                 getSetClick = GetSetClick.Set;
                 bool result = imgRecognition.GetSetClickImage(ScreenPath, getSetClick, sValue, 10000, accuracy);
                 Result.Set(context, result);
             }
         }
         //});
     }
     catch (Exception ex)
     {
         Logger.Log.Logger.LogData(ex.Message + " in activity Image_FindAndSetText", Logger.LogLevel.Error);
         if (!ContinueOnError)
         {
             context.Abort();
         }
     }
 }
        protected override void Execute(NativeActivityContext context)
        {
            try
            {
                string sImagePath = ImagePath.Get(context);
                bool   result     = false;

                if (File.Exists(sImagePath))
                {
                    GetSetClick      getSetClick    = new GetSetClick();
                    ImageRecognition imgRecognition = new ImageRecognition();
                    getSetClick = GetSetClick.Click;
                    result      = imgRecognition.GetSetClickImage(sImagePath, getSetClick, "", 10000, Accuracy);
                    Result.Set(context, result);
                }
                //});
            }
            catch (Exception ex)
            {
                Logger.Log.Logger.LogData(ex.Message + " in activity Image_FindAndClick", Logger.LogLevel.Error);
                if (!ContinueOnError)
                {
                    context.Abort();
                }
            }
        }
Exemplo n.º 3
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                string outFolder   = OutputFolder.Get(context);
                string _imagePath  = ImagePath.Get(context);
                string _targetType = Convert_To_Type.Get(context).ToLower();
                string _destPath   = _imagePath; // default value

                if (System.IO.File.Exists(ImagePath.Get(context)))
                {
                    var sourceImg = System.Drawing.Image.FromFile(_imagePath);
                    if (Directory.Exists(outFolder) == false)
                    {
                        outFolder = Path.GetDirectoryName(_imagePath);
                    }

                    _destPath = outFolder + "\\" + Path.GetFileNameWithoutExtension(_imagePath) + "." + _targetType;



                    switch (_targetType)
                    {
                    case "jpg":
                        sourceImg.Save(_destPath, ImageFormat.Jpeg);
                        break;

                    case "png":
                        sourceImg.Save(_destPath, ImageFormat.Png);
                        break;

                    case "bmp":
                        sourceImg.Save(_destPath, ImageFormat.Bmp);
                        break;

                    case "gif":
                        sourceImg.Save(_destPath, ImageFormat.Gif);
                        break;

                    default:
                        Console.WriteLine("Conversion Type Not Supported. Supported types are  jpg, png, gif, bmp");
                        break;
                    }
                    ConvertedFilePath.Set(context, _destPath);
                    Console.WriteLine("File saved as " + _destPath);
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "Source" + ex.Source);
            }
        }
        /// <summary>
        /// Runs the main logic of the activity. Has access to the context,
        /// which holds the values of properties for this activity and those from the parent scope.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            var property = context.DataContext.GetProperties()[BaiduOcrScope.ApplicationTag];
            var app      = property.GetValue(context.DataContext) as Application;

            var imagePath = ImagePath.Get(context);
            var image     = File.ReadAllBytes(imagePath);

            var result = await InvokeBaiduOcrAsync(app, image);

            return(ctx => Result.Set(ctx, result));
        }
Exemplo n.º 5
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                base.LoadValues(context);

                this.intSlideIndex = SlideIndex.Get(context);
                this.strImage      = ImagePath.Get(context);

                this.DoInsertPicture();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 6
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                service = new TwitterService(ConsumerKey.Get(context),
                                             ConsumerSecret.Get(context),
                                             AccessToken.Get(context),
                                             AccessSecret.Get(context));

                TwitterStatus status;
                if (ImagePath.Get(context) == null)
                {
                    // Send Tweet without Image
                    status = service.SendTweet(new SendTweetOptions {
                        Status = Message.Get(context)
                    });
                }
                else
                {
                    // Send Tweet with Image
                    MediaFile mf     = new MediaFile();
                    Stream    stream = new FileStream(ImagePath.Get(context), FileMode.Open);
                    mf.Content = stream;

                    var media = service.UploadMedia(new UploadMediaOptions {
                        Media = mf
                    });
                    var id = media.Media_Id;

                    List <string> ls = new List <string>();
                    ls.Add(id.ToString());

                    status = service.SendTweet(new SendTweetOptions
                    {
                        Status   = Message.Get(context),
                        MediaIds = ls,
                    });
                }

                // Capture Posted Tweet Id
                TweetId.Set(context, status.Id);
            }
            catch (Exception e)
            {
                TweetId.Set(context, e.Message);
            }
        }
Exemplo n.º 7
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var imagepath       = ImagePath.Get(context);
            var objectContainer = context.GetFromContext <IObjectContainer>(OcrScope.ParentContainerPropertyTag);
            var ocrClient       = objectContainer.Get <IOcrClient>();

            ///////////////////////////
            // Add execution logic HERE
            ///////////////////////////
            var recognizerName    = GetRecognizerName();
            var recognizerOptions = GetRecognizerOptions(context);
            var result            = await ocrClient.RecognizeAsync(recognizerName, imagepath, recognizerOptions);

            // Outputs
            return((ctx) =>
            {
                Result.Set(ctx, result);
            });
        }
Exemplo n.º 8
0
        protected override void Execute(NativeActivityContext context)
        {
            try
            {
                string        filepath = ImagePath.Get(context);
                List <string> result   = new List <string>();

                using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default))
                {
                    using (var pixA = PixArray.LoadMultiPageTiffFromFile(filepath))
                    {
                        int i = 1;
                        foreach (var pix in pixA)
                        {
                            using (var page = engine.Process(pix))
                            {
                                var text = page.GetText().Trim();

                                string expectedText = String.Format("Page {0}", i);
                                result.Add(text);
                            }
                            i++;
                        }
                    }
                }
                string[] strvalues = result.ToArray();
                if ((strvalues != null) && (strvalues.Length > 0))
                {
                    TextValues.Set(context, strvalues);
                }
            }
            catch (Exception ex)
            {
                Log.Logger.LogData(ex.Message + " in activity MultipageTifToText", LogLevel.Error);
                if (!ContinueOnError)
                {
                    context.Abort();
                }
            }
        }
Exemplo n.º 9
0
        protected override void Execute(CodeActivityContext context)
        {
            string imagePath = ImagePath.Get(context);
            string actionUrl = ActionUrl.Get(context);
            string outPath   = OutExcelPath.Get(context);
            string result    = TaskAsync(actionUrl, imagePath).Result;

            Workbook workbook  = new Workbook();
            var      worksheet = workbook.Worksheets[0];

            var json = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(result);
            int n    = 1;

            foreach (var item in json)
            {
                worksheet.Cells["A" + n + ""].PutValue(item);
                n++;
            }
            workbook.Save(outPath);
            worksheet.Dispose();
            workbook.Dispose();
        }
        protected override void Execute(NativeActivityContext context)
        {
            try
            {
                string filepath = ImagePath.Get(context);
                Bitmap bitmap   = new Bitmap(filepath);

                var ocrtext = string.Empty;
                using (var engine = new TesseractEngine(@".\tessdata", "eng", EngineMode.Default))
                {
                    using (var img = PixConverter.ToPix(bitmap))
                    {
                        using (var page = engine.Process(img))
                        {
                            ocrtext = page.GetText();
                        }
                    }
                }
                Text.Set(context, ocrtext);
            }
            catch (Exception ex)
            {
                if (ex.Message.Equals("Parameter is not valid."))
                {
                    Log.Logger.LogData("File Path Issue: Could Not Find Image", LogLevel.Error);
                }
                else
                {
                    Log.Logger.LogData(ex.Message + " in activity SingleImageToText", LogLevel.Error);
                }

                if (!ContinueOnError)
                {
                    context.Abort();
                }
            }
        }
Exemplo n.º 11
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                int    sizex         = Size_X.Get(context);
                int    sizey         = Size_Y.Get(context);
                string outFolder     = OutputFolder.Get(context);
                string _imagePath    = ImagePath.Get(context);
                string destPath      = _imagePath; // default value
                int    percentage    = Percentage_Value.Get(context);
                bool   usePercentage = Percent_Reduction.Get(context);


                if (System.IO.File.Exists(ImagePath.Get(context)))
                {
                    if (Directory.Exists(outFolder) == false)
                    {
                        outFolder = Path.GetDirectoryName(_imagePath);
                    }

                    var sourceImg = System.Drawing.Image.FromFile(_imagePath);

                    destPath = outFolder + "\\" + System.IO.Path.GetFileNameWithoutExtension(_imagePath)
                               + "_" + sizex.ToString() + "x" + sizey.ToString() + System.IO.Path.GetExtension(_imagePath);

                    // Get the size
                    Console.WriteLine("Resizing file  " + _imagePath);
                    System.Drawing.Rectangle destRect;
                    Bitmap destImage;

                    if (usePercentage != true)
                    {
                        destRect  = new System.Drawing.Rectangle(0, 0, sizex, sizey);
                        destImage = new Bitmap(sizex, sizey);
                        destPath  = outFolder + "\\" + System.IO.Path.GetFileNameWithoutExtension(_imagePath)
                                    + "_" + sizex.ToString() + "x" + sizey.ToString() + System.IO.Path.GetExtension(_imagePath);
                    }
                    else
                    {
                        if (percentage > 0 && percentage <= 100)
                        {
                            int newsizex = Convert.ToInt32(sourceImg.Width * percentage / 100);
                            int newsizey = Convert.ToInt32(sourceImg.Height * percentage / 100);
                            destRect  = new System.Drawing.Rectangle(0, 0, newsizex, newsizey);
                            destImage = new Bitmap(newsizex, newsizey);
                            destPath  = outFolder + "\\" + System.IO.Path.GetFileNameWithoutExtension(_imagePath)
                                        + "_" + newsizex.ToString() + "x" + newsizey.ToString() + System.IO.Path.GetExtension(_imagePath);
                        }
                        else
                        {
                            Console.WriteLine("Wroing percentage is defined taking 100% ");
                            destRect  = new System.Drawing.Rectangle(0, 0, sizex, sizey);
                            destImage = new Bitmap(sizex, sizey);
                            destImage = new Bitmap(Convert.ToInt32(sizex * percentage / 100), Convert.ToInt32(sizey * percentage / 100));
                            destPath  = outFolder + "\\" + System.IO.Path.GetFileName(_imagePath);
                        }
                    }

                    destImage.SetResolution(sourceImg.HorizontalResolution, sourceImg.VerticalResolution);

                    using (var graphics = Graphics.FromImage(destImage))
                    {
                        graphics.CompositingMode    = CompositingMode.SourceCopy;
                        graphics.CompositingQuality = CompositingQuality.HighQuality;
                        graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                        graphics.SmoothingMode      = SmoothingMode.HighQuality;
                        graphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;

                        using (var wrapMode = new ImageAttributes())
                        {
                            wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                            graphics.DrawImage(sourceImg, destRect, 0, 0, sourceImg.Width, sourceImg.Height, GraphicsUnit.Pixel, wrapMode);
                        }
                    }

                    destImage.Save(destPath);
                    destImage.Dispose();
                    sourceImg.Dispose();
                    Console.WriteLine("Saved resized image file " + destPath);
                    ResizedImagePath.Set(context, destPath);
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "Source" + ex.Source);
            }
        }