AnalyzeResult

We found 10 examples in language CSharp for this search. You will see 37 fragments of code.

Other methods


        //调用方法获取POST请求的真实服务器响应
        public ResponseResult GetResponse(Home.AnalyzeResult AnalyzeResult)
        {
            return Send(AnalyzeResult);
        }

        //调用方法获取GET请求的真实服务器响应
        public ResponseResult GetResponseByGet(Home.AnalyzeResult AnalyzeResult)
        {
            return SendByGet(AnalyzeResult);
        }

        public static void BuildParameters(AnalyzeResult analyze, ref Dictionary<string, object> parameters)
        {
            if(analyze == null) return;

            analyze.BuildParameters(ref parameters);

            BuildParameters(analyze.Left, ref parameters);
            BuildParameters(analyze.Right, ref parameters);
        }

        public static AnalyzeResult AnalyzeWhere(IDatabaseProvider provider, Expression expression)
        {
            return Analyze(provider, null, expression);
        }
        private static AnalyzeResult Analyze(IDatabaseProvider provider, AnalyzeResult previousAnalyze, ConstantExpression expression)
        {
            return new AnalyzeResult(null, expression.Value);
        }

		public List<AnalyzeResult> Analize(List<LogEntry> logEntries)
		{
			List<AnalyzeResult> results = new List<AnalyzeResult>();

			string[] serialNumbers = logEntries.Select(log => log.GameProviderSerialNumber).Distinct().ToArray();

			foreach (string serialNumber in serialNumbers)
			{
				List<LogEntry> gameLogs = logEntries.Where(log => log.GameProviderSerialNumber == serialNumber).OrderBy(log => log.CreateDate).ToList();
				results.Add(AnalyzeGame(gameLogs));
			}

			return results;
		}


        [Fact]
        public void InitialCallShouldReturnOperationStatusResult()
        {
            int[] expeectedLineBoundingBox =  new int[] { 202, 618, 2047, 643, 2046, 840, 200, 813 };
            var result = new ReadImageAnalysisResult(new MockCommsResult(_readImageAnalysisResponse));

            Assert.NotNull(result);
            Assert.NotNull(result.ResponseData);
            Assert.NotNull(result.ResponseData.analyzeResult);
            Assert.NotEmpty(result.ResponseData.analyzeResult.readResults);
            Assert.Equal(2,result.ResponseData.analyzeResult.readResults.Length);
            Assert.Equal(49.59, result.ResponseData.analyzeResult.readResults[0].angle);
            Assert.Equal(400, result.ResponseData.analyzeResult.readResults[0].height);
            Assert.Equal("en", result.ResponseData.analyzeResult.readResults[0].language);
            Assert.Equal(1, result.ResponseData.analyzeResult.readResults[0].page);
            Assert.Equal("pixel", result.ResponseData.analyzeResult.readResults[0].unit);
            Assert.Equal(600, result.ResponseData.analyzeResult.readResults[0].width);
            Assert.NotEmpty(result.ResponseData.analyzeResult.readResults[0].lines);
            Assert.Equal(3, result.ResponseData.analyzeResult.readResults[0].lines.Length);
            Assert.Equal("Our greatest glory is not", result.ResponseData.analyzeResult.readResults[0].lines[0].text);
            Assert.NotEmpty(result.ResponseData.analyzeResult.readResults[0].lines[0].boundingBox);
            Assert.NotEmpty(result.ResponseData.analyzeResult.readResults[0].lines[0].words);
            Assert.Equal(5,result.ResponseData.analyzeResult.readResults[0].lines[0].words.Length);
            // Ensure we extract all the result words
            Assert.Equal("Our",result.ResponseData.analyzeResult.readResults[0].lines[0].words[0].text);
            Assert.Equal(0.164,result.ResponseData.analyzeResult.readResults[0].lines[0].words[0].confidence);
            Assert.NotEmpty(result.ResponseData.analyzeResult.readResults[0].lines[0].words[0].boundingBox);
            Assert.Equal("greatest", result.ResponseData.analyzeResult.readResults[0].lines[0].words[1].text);
            Assert.Equal(0.164, result.ResponseData.analyzeResult.readResults[0].lines[0].words[1].confidence);
            Assert.NotEmpty(result.ResponseData.analyzeResult.readResults[0].lines[0].words[1].boundingBox);
            Assert.Equal("glory", result.ResponseData.analyzeResult.readResults[0].lines[0].words[2].text);
            Assert.Equal(0.164, result.ResponseData.analyzeResult.readResults[0].lines[0].words[2].confidence);
            Assert.NotEmpty(result.ResponseData.analyzeResult.readResults[0].lines[0].words[2].boundingBox);
            Assert.Equal("is", result.ResponseData.analyzeResult.readResults[0].lines[0].words[3].text);
            Assert.Equal(0.164, result.ResponseData.analyzeResult.readResults[0].lines[0].words[3].confidence);
            Assert.NotEmpty(result.ResponseData.analyzeResult.readResults[0].lines[0].words[3].boundingBox);
            Assert.Equal("not", result.ResponseData.analyzeResult.readResults[0].lines[0].words[4].text);
            Assert.Equal(0.164, result.ResponseData.analyzeResult.readResults[0].lines[0].words[4].confidence);
            Assert.NotEmpty(result.ResponseData.analyzeResult.readResults[0].lines[0].words[4].boundingBox);

            for (var cnt=0; cnt < expeectedLineBoundingBox.Length; cnt++)
            {
                Assert.Equal(expeectedLineBoundingBox[cnt],result.ResponseData.analyzeResult.readResults[0].lines[0].boundingBox[cnt]);
            }
        }

        void Add(AnalyzeResult analyzeResult);
        public static IAttackPreventService GetInstance()
        {
            if (attackPreventService == null)
            {
                lock (obj_Sync)
                {
                    if (attackPreventService == null)
                    {
                        attackPreventService = new AttackPreventService();
                    }
                }
            }
            return attackPreventService;
        }

        public void Add(AnalyzeResult analyzeResult)
        {
            //logger.Info(JsonConvert.SerializeObject(new
            //{
            //    DataType = "0-analyzeResult",
            //    Value = analyzeResult,
            //}));
            analyzeResults.Enqueue(analyzeResult);
            if ( analyzeResult != null)
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                Analyze(analyzeResult);
                stopwatch.Stop();
                logger.Debug(stopwatch.Elapsed.TotalMilliseconds);
            }
        }

        public void doWork()
        {
            while (true)
            {
                AnalyzeResult analyzeResult = null;
                try
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    if (analyzeResults.TryDequeue(out analyzeResult))
                    {
                        Analyze(analyzeResult);
                        stopwatch.Stop();
                        logger.Debug(stopwatch.Elapsed.TotalMilliseconds);
                    }

                }
                catch(Exception e)
                {
                    logger.Error(e.StackTrace);
                    if (analyzeResult != null)
                    {
                        Add(analyzeResult);
                    }
                }
                finally
                {

                }
            }
        }
        private void Analyze(AnalyzeResult analyzeResult)
        {
            if (analyzeResult != null && analyzeResult.result != null)
            {
                List<AuditLogEntity> auditLogEntities = new List<AuditLogEntity>();
                string key = "AnalyzeRatelimit_GetZoneList_Key";
                List<ZoneEntity> zoneList = Utils.GetMemoryCache(key, () =>
                {
                    return ZoneBusiness.GetZoneList();
                }, 1440);

                string zoneID = analyzeResult.ZoneId;
                var zone = zoneList.FirstOrDefault(a => a.ZoneId == zoneID);

                if (zone != null)
                {
                    string authEmail = zone.AuthEmail;
                    string authKey = zone.AuthKey;

                    var cloudflare = new CloudFlareApiService(zone.ZoneId, zone.AuthEmail, zone.AuthKey);

                    //发送警报
                    Warn(analyzeResult);

                    //开启RateLimit
                    var logs = OpenRageLimit(zone, cloudflare, analyzeResult);
                    auditLogEntities.AddRange(logs);

                    //Ban IP
                    //logs = BanIp(zone, cloudflare, analyzeResult);
                    //auditLogEntities.AddRange(logs);

                    //记录日志
                    InsertLogs(auditLogEntities);
                }

            }
        }
        private void InsertLogs(List<AuditLogEntity> logs)
        {
            if (logs != null)
            {
                IISLogBusiness.AddList(logs);
            }
        }

        //处理GET请求
        [HttpGet]
        public ActionResult Index()
        {
            //实例化CompleteLimitList类,以用于处理用户设置防火墙的历史
            CompleteLimitList completelimitlist = new CompleteLimitList();

            //将设置历史进行格式转换,存入ViewData,供前端显示
            string[] DataResult = new string[50];           //用于存储设置历史的Data记录
            int num = 0;
            DataResult = completelimitlist.GetLimitSettings();
            if (DataResult[0] == "读取成功")
            {
                while (DataResult[num] != null && DataResult[num + 1] != null)
                {
                    DataResult[num] = DataResult[num + 1];
                    num++;
                }
                DataResult[num] = null;
                ViewData["row"] = num;
                ViewData["Data"] = DataResult;
            }
            else
                ViewData["Data"] = "错误";
            return View();
        }

        //处理POST请求
        [HttpPost]
        public string Index(SetWafManager SetLimitRequest)
        {
            //对POST请求进行报文分析、过滤
            Home AnalyzeRequest = new Home();
            firewall.Models.Home.AnalyzeResult AnalyzeResult = AnalyzeRequest.GetPostRequestResult(Request);
            if (AnalyzeResult.ResultReport == "请求过滤成功")
            {
                CompleteLimitList completelimitlist = new CompleteLimitList();  //成功时将该请求执行,并存入设置历史
                return completelimitlist.CompleteLimitResult(SetLimitRequest);
            }
            else if (AnalyzeResult.ResultReport == "该主机已被设置为黑名单,无法访问")
            {
                CompleteLimitList completelimitlist = new CompleteLimitList();  //若已被设置为黑名单,则强制执行更改并存入设置历史
                return completelimitlist.CompleteLimitResult(SetLimitRequest);
            }
            else
            {
                return AnalyzeResult.ResultReport;                              //若设置失败,返回失败报告
            }
        }

        //该Search页面用于显示近期访问防火墙的用户记录
        [HttpGet]
        public ActionResult Search()
        {
            //将日志从数据库中提取出来显示在前端
            DBRecords DBRecord = new DBRecords();
            ViewData["DBJournal"] = DBRecord.GetJournal();      
            return View();
        }


        /// <summary>ベースフォルダが指定されている場合、ベースフォルダを検索し、登録されていないデータを新たに登録します</summary>
        /// <param name="baseFolderPath">ベースフォルダリスト</param>
        /// <exception cref="DirectoryNotFoundException">ベースフォルダが存在しない。または指定されていない</exception>
        public static void SyncBaseFolder(string baseFolderPath)
        {
            shelf = shelf.ReadJson(baseFolderPath);
            Array.ForEach(shelf.Books.ToArray(), b => b.Status = AnalyzeResult.NotRunning);
            foreach (var b in shelf.Books.Where(b => sortedbooks.ContainsKey(b.Hash)))
            {
                sortedbooks.Add(b.Hash, b);
            }

            // ファイルの検索と除外処理
            var syncPaths = new HashSet<string>(shelf.Books.Select(b => b.FilePath.ToLower()).OrderBy(v => v));
            IEnumerable<string> files = GetAllFiles(baseFolderPath, "*").AsParallel();
            files = files.Where(f => extensions.Contains(Path.GetExtension(f).ToLower()));
            var count = files.Count();
            files = files.Where(f => !syncPaths.Contains(f.ToLower()));
            Console.WriteLine($"ファイル>書籍ファイル総数:{count},新規・変更数:{files.Count()}");

            foreach (var filePath in files)
            {
                var book = new BookModel(filePath);
                book = CheckHash(book);
                Console.WriteLine($"{LabelAttributeUtils.GetLabelName(book.Status)}>{book.FilePath}");
            }

            var books = shelf.Books.Where(b => b.Status == AnalyzeResult.NotRunning);
            foreach (var book in books)
            {
                if (!book.FileExists())
                {
                    book.Status = AnalyzeResult.FileNotFound;
                    Console.WriteLine($"{LabelAttributeUtils.GetLabelName(book.Status)}>{book.FilePath}");
                }
            }

            shelf.WriteJson();
        }


        /// <summary>ハッシュの状態を確認する</summary>
        /// <param name="book">書籍</param>
        /// <returns>処理結果</returns>
        /// <remarks>ファイルを解析し、リストに登録する</remarks>
        private static BookModel CheckHash(BookModel book)
        {
            if (book.Status == AnalyzeResult.FileSizeZero ||
                book.Status == AnalyzeResult.FileNotFound)
            {
                // ファイルサイズがゼロの場合、ハッシュチェック処理を行わず終了する
                return book;
            }

            // 同一ハッシュチェック
            BookModel movedModel = sortedbooks.ContainsKey(book.Hash) ? sortedbooks[book.Hash] : null;
            //BookModel movedModel =  shelf.Books.Where(b => b.Hash == book.Hash).FirstOrDefault();

            if (movedModel != null && (movedModel.Status != AnalyzeResult.NotRunning || !movedModel.FileExists()))
            {
                // ハッシュが同一で、見つかったデータが処理済みか、ファイルが存在しない場合、移動とみなす
                movedModel.FilePath = book.FilePath;
                return movedModel;
            }
            else if (movedModel?.Status == AnalyzeResult.NotRunning)
            {
                // ハッシュが同一で同期されたデータが存在する場合、重複とみなす
                movedModel.Status = AnalyzeResult.Duplicate;
                book.Status = AnalyzeResult.Duplicate;
                return book;
            }

            // 同じハッシュを持つファイルが無い(新規ファイル)
            book.Status = AnalyzeResult.Success;
            shelf.Books.Add(book);
            sortedbooks.Add(book.Hash, book);
            return book;
        }

        /// <summary>指定されたフォルダ以下にあるすべてのファイルを取得する
        /// </summary>
        /// <param name="folder">ファイルを検索するフォルダ名。</param>
        /// <param name="searchPattern">ファイル名検索文字列
        /// ワイルドカード指定子(*, ?)を使用する。</param>
        /// <returns>ファイル名リスト</returns>
        private static List<string> GetAllFiles(string folder, string searchPattern)
        {
            // folderにあるファイルを取得する
            var files = new List<string>();
            IEnumerable<string> fs = Directory.GetFiles(folder, searchPattern);
            files.AddRange(fs);

            // folderのサブフォルダを取得する
            IEnumerable<string> subFolders = Directory.GetDirectories(folder);

            // サブフォルダにあるファイルも調べる
            foreach (string d in subFolders)
            {
                files.AddRange(GetAllFiles(d, searchPattern));
            }

            return files;
        }

        
        public override List<AnalyzeResult> RefreshAnalysis(AddressableAssetSettings aaSettings)
        {
            var analyzeResults = new List<AnalyzeResult>();
            foreach (var group in aaSettings.groups)
            {
                foreach (var entry in group.entries)
                {
                    if (entry.MainAsset == null)
                        continue;
                    var assetType = entry.MainAsset.GetType();
                    if (assetType == typeof(VideoClip))
                    {
                        var bundledAssetGroupSchema = entry.parentGroup.GetSchema<BundledAssetGroupSchema>();
                        if (bundledAssetGroupSchema.Compression != BundledAssetGroupSchema.BundleCompressionMode.Uncompressed)
                        {
                            analyzeResults.Add(new AnalyzeResult {resultName = $"Video' '{entry.address}' should not be in compressed asset bundle"});
                        }
                    }
                }
            }

            return analyzeResults;
        }
        
        public override List<AnalyzeResult> RefreshAnalysis(AddressableAssetSettings aaSettings)
        {
            var analyzeResults = new List<AnalyzeResult>();
            foreach (var group in aaSettings.groups)
            {
                foreach (var entry in group.entries)
                {
                    if (entry.MainAsset == null)
                        continue;
                    var assetType = entry.MainAsset.GetType();
                    if (assetType == typeof(VideoClip))
                    {
                        if (entry.AssetPath.Contains("/Videos/") == false)
                        {
                            analyzeResults.Add(new AnalyzeResult {resultName = $"Video '{entry.address}' should be within a Videos directory"});
                        }
                    }
                }
            }

            return analyzeResults;
        }
        
        public override List<AnalyzeResult> RefreshAnalysis(AddressableAssetSettings aaSettings)
        {
            _videosToLabel = new List<AddressableAssetEntry>();
            var analyzeResults = new List<AnalyzeResult>();
            foreach (var group in aaSettings.groups)
            {
                foreach (var entry in group.entries)
                {
                    if (entry.MainAsset == null)
                        continue;
                    var assetType = entry.MainAsset.GetType();
                    if (assetType == typeof(VideoClip))
                    {
                        if (entry.labels.Contains("Video") == false)
                        {
                            analyzeResults.Add(new AnalyzeResult {resultName = $"Video '{entry.address}' should have a Video label"});
                            _videosToLabel.Add(entry);
                        }
                    }
                }
            }

            return analyzeResults;
        }

        public override void FixIssues(AddressableAssetSettings aaSettings)
        {
            foreach (var entry in _videosToLabel)
            {
                entry.SetLabel("Video", true, true);
            }

            _videosToLabel = null;
        }

        public override void ClearAnalysis()
        {
            base.ClearAnalysis();
            _videosToLabel = null;
        }

        public override List<AnalyzeResult> RefreshAnalysis(AddressableAssetSettings aaSettings)
        {
            _prefabAddressesToRename = new List<AddressableAssetEntry>();
            var analyzeResults = new List<AnalyzeResult>();
            foreach (var group in aaSettings.groups)
            {
                foreach (var entry in group.entries)
                {
                    if (entry.MainAsset == null)
                        continue;
                    var assetType = entry.MainAsset.GetType();
                    if (assetType == typeof(GameObject))
                    {
                        var requiredAddress = GetSuggestedAddressForAsset(entry);
                        if (entry.address != requiredAddress)
                        {
                            analyzeResults.Add(new AnalyzeResult {resultName = $"Video '{entry.address}' should have address '{requiredAddress}'"});
                            _prefabAddressesToRename.Add(entry);
                        }
                    }
                }
            }

            return analyzeResults;
        }


        protected abstract Task<AnalyzerResult> AnalyzeAsync(SelectionResult selectionResult, CancellationToken cancellationToken);
        protected abstract Task<InsertionPoint> GetInsertionPointAsync(SemanticDocument document, int position, CancellationToken cancellationToken);
        protected abstract Task<TriviaResult> PreserveTriviaAsync(SelectionResult selectionResult, CancellationToken cancellationToken);
        protected abstract Task<SemanticDocument> ExpandAsync(SelectionResult selection, CancellationToken cancellationToken);

        protected abstract Task<GeneratedCode> GenerateCodeAsync(InsertionPoint insertionPoint, SelectionResult selectionResult, AnalyzerResult analyzeResult, CancellationToken cancellationToken);

        protected abstract SyntaxToken GetMethodNameAtInvocation(IEnumerable<SyntaxNodeOrToken> methodNames);


        /// <summary>
        /// 图片场景分析
        /// </summary>
        /// <param name="imgUrl">图片链接</param>
        /// <returns>分析结果Dto</returns>
        [HttpPost]
        [DisableAuditing]
        public async Task<ImgSceneRecognitionDto> ImgSceneRecognition([FromBody]ImgSceneRecognitionInput input)
        {
            var analyzeResult = await _azureCognitiveManager.ImgAnalyze(input.ImgUrl);


            // 主色彩
            //analyzeResult.Color.DominantColors

            // 是否黑白照
            // analyzeResult.Color.IsBWImg


            var result = new ImgSceneRecognitionDto()
            {
                Captions = GetCaptions(analyzeResult),
                ImgTags = GetImgTag(analyzeResult),
                Faces = analyzeResult.Faces?.ToList(),// 图片中的人脸和相关信息
                Height = analyzeResult.Metadata.Height,
                Width = analyzeResult.Metadata.Width
            };

            return result;
        }


        /// <summary>
        /// 图片Ocr
        /// </summary>
        /// <param name="input">输入</param>
        /// <returns>ocr识别结果</returns>
        [HttpPost]
        [DisableAuditing]
        public async Task<string> ImgOcr([FromBody]ImgOcrInput input)
        {
            var result = await _azureCognitiveManager.ImgOcrSimpleFormattedText(input.ImgUrl, input.Lang);

            return result;

        }

        /// <summary>
        /// 文字转语音
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [DisableAuditing]
        public async Task<FileContentResult> TextToSpeech([FromBody]TextToSpeechInput input)
        {
            try
            {
                input.Text = input.Text.Replace("\n", string.Empty);
                var result = await _azureCognitiveManager.TextToSpeech(input.Text, input.Lang, input.Voice);

                return File(result, MimeTypeNames.ApplicationZip);
            }
            finally
            {
                Response.Body.Dispose();
            }
        }


        /// <summary>
        /// 语音转文字
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [DisableAuditing]
        public async Task<string> SpeechToText(string lang)
        {
            var profilePictureFile = Request.Form.Files.First();

            using (var stream = profilePictureFile.OpenReadStream())
            {
                var result = await _azureCognitiveManager.SpeechToText(stream, lang);

                return result;
            }

        }





        #region 图片场景分析内部函数

        /// <summary>
        /// 获取分析结果中的图片说明
        /// </summary>
        /// <param name="analysis">图片分析结果</param>
        /// <returns></returns>
        private static List<string> GetCaptions(ImageAnalysis analysis)
        {
            var result = new List<string>();
            foreach (var caption in analysis.Description.Captions)
            {
                result.Add(caption.Text);
            }

            return result;
        }


        /// <summary>
        /// 获取分析结果中的图片标签和百分比
        /// </summary>
        /// <param name="analysis">图片分析结果</param>
        /// <returns></returns>
        private static List<ImgSceneRecognitionTagDto> GetImgTag(ImageAnalysis analysis)
        {
            var result = new List<ImgSceneRecognitionTagDto>();

            var tmpPercentage = 0.0;
            foreach (var tag in analysis.Tags)
            {
                tmpPercentage = Math.Round(tag.Confidence * 100, 2);
                result.Add(new ImgSceneRecognitionTagDto()
                {
                    TagName = tag.Name,
                    Percentage = tmpPercentage,
                    PercentageStr = $"{tmpPercentage}%"
                });
            }

            return result;
        }

NuGet.DependencyResolver.AnalyzeResult<TItem> : Object

Constructors :

public AnalyzeResult()

Methods :

public List<DowngradeResult<TItem>> get_Downgrades()
public List<VersionConflictResult<TItem>> get_VersionConflicts()
public List<GraphNode<TItem>> get_Cycles()
public Void Combine(AnalyzeResult result = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()