private bool validAfterFilters(string file) { if (Excludes.Any() == false && Includes.Any() == false) { // Default match when nothing has been added return(true); } // If Exclude has been define, guard everything against it // If Include has been defined, do the same // If both then check exclude then include first if (Excludes.Any()) { if (_matchesFilter(Excludes, file)) { return(false); } } if (Includes.Any()) { if (_matchesFilter(Includes, file)) { return(true); } // Otherwise let filter fail return(false); } return(true); }
/// <summary> /// Поиск всех вхождений по указанным инклукдам /// </summary> /// <returns> /// Перечисление путей файлов, подходящих по маске /// к списку инклудов /// </returns> public IEnumerable <string> Collect() { var directincludes = Includes.Where(File.Exists).Select(_ => _.NormalizePath()).ToArray(); foreach (var directinclude in directincludes) { yield return(directinclude); } foreach (var root in Roots) { foreach (var mask in SearchMasks) { foreach (var f in Directory.GetFiles(root, mask, SearchOption.AllDirectories) ) { var normalized = f.Replace(root, "").Replace("\\", "/"); if (Includes.Any()) { if (directincludes.Contains(normalized)) { continue; } if (!Includes.Any(normalized.Contains)) { continue; } } if (Excludes.Any()) { if (Excludes.Any(normalized.Contains)) { continue; } } yield return(f); } } } }
/************************************************************************************************************/ /************************************************************************************************************/ private bool AbhereSynchronizationRules(FileFolder file, bool recursive, bool children) { if (!children && !recursive && !(file.Folder.FullName.Equals(VaultPath, StringComparison.InvariantCultureIgnoreCase) || (file.Folder.FullName + "/" + file.File.Name).Equals(VaultPath, StringComparison.InvariantCultureIgnoreCase))) { return(false); } if (!children && !(file.Folder.FullName + "/" + file.File.Name).ToLower().Contains(VaultPath.ToLower())) { return(false); } if (((PatternsToSynchronize.Count() > 0) && (!PatternsToSynchronize.Any(s => file.File.Name.ToLower().EndsWith(s.ToLower())))) && !((PatternsToSynchronize.Count() == 1) && (PatternsToSynchronize[0].Equals("/", StringComparison.InvariantCultureIgnoreCase)))) { return(false); } if ((Excludes.Count() > 0) && (Excludes.Any(s => (file.Folder.FullName + "/" + file.File.Name).ToLower().Contains(s.ToLower())))) { return(false); } return(true); }
/// <summary>处理Span集合。默认输出日志,可重定义输出控制台</summary> protected override void ProcessSpans(ISpanBuilder[] builders) { if (builders == null) { return; } // 剔除项 if (Excludes != null) { builders = builders.Where(e => !Excludes.Any(y => y.IsMatch(e.Name))).ToArray(); } builders = builders.Where(e => !e.Name.EndsWithIgnoreCase("/Trace/Report")).ToArray(); if (builders.Length == 0) { return; } // 初始化 Init(); // 构建应用信息 var info = new AppInfo(_process); try { // 调用WindowApi获取进程的连接数 var tcps = NetHelper.GetAllTcpConnections(); if (tcps != null && tcps.Length > 0) { var pid = Process.GetCurrentProcess().Id; info.Connections = tcps.Count(e => e.ProcessId == pid); } } catch { } // 发送,失败后进入队列 var model = new TraceModel { AppId = AppId, AppName = AppName, ClientId = ClientId, Version = _version, Info = info, Builders = builders }; try { // 检查令牌 if (!AppSecret.IsNullOrEmpty()) { CheckAuthorize(); } var rs = Client.Invoke <TraceResponse>("Trace/Report", model); // 处理响应参数 if (rs != null) { if (rs.Period > 0) { Period = rs.Period; } if (rs.MaxSamples > 0) { MaxSamples = rs.MaxSamples; } if (rs.MaxErrors > 0) { MaxErrors = rs.MaxErrors; } if (rs.Timeout > 0) { Timeout = rs.Timeout; } if (rs.Excludes != null) { Excludes = rs.Excludes; } } } catch (ApiException ex) { Log?.Error(ex + ""); } catch (Exception ex) { //XTrace.WriteException(ex); Log?.Error(ex + ""); //throw; if (_fails.Count < MaxFails) { _fails.Enqueue(model); } return; } // 如果发送成功,则继续发送以前失败的数据 while (_fails.Count > 0) { model = _fails.Dequeue(); try { Client.Invoke <Object>("Trace/Report", model); } catch (ApiException ex) { Log?.Error(ex + ""); } catch (Exception ex) { XTrace.WriteLine("二次上报失败,放弃该批次采样数据,{0}", model.Builders.FirstOrDefault()?.StartTime.ToDateTime()); XTrace.WriteException(ex); //Log?.Error(ex + ""); // 星尘收集器上报,二次失败后放弃该批次数据,因其很可能是错误数据 //_fails.Enqueue(model); break; } } }
internal bool Matches(string str) { return(Includes.Any(i => i.Matches(str)) && !Excludes.Any(e => e.Matches(str))); }
/// <summary> /// Determine whether the given path should be excluded. /// </summary> /// <param name="path">The path to query.</param> /// <returns>True iff the path matches an exclusion.</returns> public bool ExcludesFile(string path) { return(Excludes.Any(ex => path.Contains(ex))); }
public bool IsExcluded(string fileName) { fileName = PathHelper.NormalizeFilePath(fileName); return(Excludes.Any(exclude => exclude.IsMatch(fileName))); }
/// <summary>处理Span集合。默认输出日志,可重定义输出控制台</summary> protected override void ProcessSpans(ISpanBuilder[] builders) { if (builders == null) { return; } // 剔除项 if (Excludes != null) { builders = builders.Where(e => !Excludes.Any(y => y.IsMatch(e.Name))).ToArray(); } builders = builders.Where(e => !e.Name.EndsWithIgnoreCase("/Trace/Report")).ToArray(); if (builders.Length == 0) { return; } // 初始化 Init(); // 构建应用信息 if (_appInfo == null) { _appInfo = new AppInfo(_process) { Version = _version } } ; else { _appInfo.Refresh(); } // 发送,失败后进入队列 var model = new TraceModel { AppId = AppId, AppName = AppName, ClientId = ClientId, Version = _version, Info = _appInfo, Builders = builders }; try { //// 检查令牌 //if (!Secret.IsNullOrEmpty()) CheckAuthorize(); var rs = Client.Invoke <TraceResponse>("Trace/Report", model); // 处理响应参数 if (rs != null) { if (rs.Period > 0) { Period = rs.Period; } if (rs.MaxSamples > 0) { MaxSamples = rs.MaxSamples; } if (rs.MaxErrors > 0) { MaxErrors = rs.MaxErrors; } if (rs.Timeout > 0) { Timeout = rs.Timeout; } Excludes = rs.Excludes; } } catch (ApiException ex) { //if (ex.Code == 401 || ex.Code == 403) _token = null; Log?.Error(ex + ""); } catch (Exception ex) { //if (ex is ApiException ae && (ae.Code == 401 || ae.Code == 403)) _token = null; Log?.Error(ex + ""); if (_fails.Count < MaxFails) { _fails.Enqueue(model); } return; } // 如果发送成功,则继续发送以前失败的数据 while (_fails.Count > 0) { model = _fails.Dequeue(); try { Client.Invoke <Object>("Trace/Report", model); } catch (ApiException ex) { Log?.Error(ex + ""); } catch (Exception ex) { XTrace.WriteLine("二次上报失败,放弃该批次采样数据,{0}", model.Builders.FirstOrDefault()?.StartTime.ToDateTime()); XTrace.WriteException(ex); //Log?.Error(ex + ""); // 星尘收集器上报,二次失败后放弃该批次数据,因其很可能是错误数据 //_fails.Enqueue(model); break; } } }