Example #1
0
        private async Task <string> AnalyzeServerImg()
        {
            var bitmap = await DownloadBitmap($"http://{Program.ServerIp}:5000/api/screenshot", Method.Post, ("url", Url), ("html", "0"));

            {
                var guid = Guid.NewGuid().ToString();
                FilePathFromServer = $@"{CurrentDirectory}\screenshot\{guid}";
            }

            bitmap.Save(FilePathFromServer);
            var fileNameFromServer = FilePathFromServer.Substring(FilePathFromServer.LastIndexOf('\\'));
            var filebytes          = File.ReadAllBytes(FilePathFromServer);

            using (var ms = new MemoryStream(filebytes))
            {
                ScreenShotFromServer = new Bitmap(ms);
                ScreenShotFromServer.SaveJpeg(
                    $@"{CurrentDirectory}\img\{fileNameFromServer}", 50);
                DoneCapturingServer?.Invoke(ScreenShotFromServer, EventArgs.Empty);
            }

            var visionHelper = new VisionHelper("visualFeatures=Categories,Tags,Description,Faces,ImageType,Color&language=en");

            return(await visionHelper.MakeAnalysisRequest <string>(FilePathFromServer));
        }
Example #2
0
        private async Task <string> AnalyzePcImg()
        {
            var ps = new Process
            {
                StartInfo = new ProcessStartInfo(
                    $@"{CurrentDirectory}\WebGuard.Supplier.exe")
                {
                    Arguments = $"0 {Url}",
                    RedirectStandardOutput = true,
                    UseShellExecute        = false
                }
            };

            ps.Start();
            var filePath = ps.StandardOutput.ReadLine();

            while (GetProcessesByName("WebGuard.Supplier").Length != 0)
            {
                await Delay(2000);
            }

            if (filePath == null)
            {
                return(null);
            }
            FilePathFromPc = filePath;
            var fileNameFromPc = filePath.Substring(filePath.LastIndexOf('\\'));
            var filebytes      = File.ReadAllBytes(filePath);

            using (var ms = new MemoryStream(filebytes))
            {
                ScreenShotFromPc = new Bitmap(ms);
                ScreenShotFromPc.SaveJpeg(
                    $@"{CurrentDirectory}\img\{fileNameFromPc}", 50);
                DoneCapturingPc?.Invoke(ScreenShotFromPc, EventArgs.Empty);
            }

            var visionHelper = new VisionHelper("visualFeatures=Categories,Tags,Description,Faces,ImageType,Color&language=en");

            return(await visionHelper.MakeAnalysisRequest <string>(FilePathFromPc));
        }