public static IEnumerable <byte[]> MACs(IEnumerable <string> stringMACs, OnParseError onParseError) { foreach (string stringMAC in stringMACs) { byte[] parsedMAC = null; string tmpMAC = stringMAC.ToUpper().Replace(":", "-"); try { parsedMAC = PhysicalAddress.Parse(tmpMAC).GetAddressBytes(); if (parsedMAC.Length != 6) { onParseError?.Invoke(stringMAC, $"E: MAC [{stringMAC}] has a length of {parsedMAC.Length}. Should be 6."); parsedMAC = null; } } catch (FormatException fex) { onParseError?.Invoke(tmpMAC, $"E: MAC [{stringMAC}] could not be parsed. Was transformed to [{tmpMAC}]. Exception: {fex.Message}"); parsedMAC = null; } if (parsedMAC != null) { yield return(parsedMAC); } } }
public static IEnumerable <IPAddress> CIDRs(IEnumerable <string> CIDRs, OnParseError onParseError) { char[] CIDRsplit = new char[] { '/' }; foreach (string cidr in CIDRs) { IPAddress broadcast = null; try { string[] cidrParts = cidr.Split(CIDRsplit); if (cidrParts.Length != 2) { throw new Exception($"CIDR split by / gave {cidrParts.Length}. should be 2."); } IPAddress net = IPAddress.Parse(cidrParts[0]); int netBits = Int32.Parse(cidrParts[1]); broadcast = NetMisc.Broadcast(net, netBits); } catch (Exception ex) { onParseError?.Invoke(cidr, ex.Message); } if (broadcast != null) { yield return(broadcast); } } }
public virtual void OnMessage(Message message, UserData userData) { try { TVariable parsed = Parse(message.Text); OnVariableParsed(parsed, message, userData); } catch (Exception ex) { OnParseError?.Invoke(ex, message, userData); } }
/// <summary> /// 对qq音乐服务器返回内容进行解析 /// </summary> /// <param name="searchInfo"></param> /// <returns></returns> public async Task <Tuple <int, List <BasicMusicInfoModel> > > ParseAsync(string searchInfo) { return(await Task.Run(async() => { try { OnBeforeParse?.Invoke(); var results = await _qqMusicParse.ParseAsync(searchInfo); OnAfterParse?.Invoke(); return results; } catch (Exception exception) { OnParseError?.Invoke(exception); return null; } })); }
public static IEnumerable <IPAddress> IPs(IEnumerable <string> IPs, OnParseError onParseError) { foreach (string stringIP in IPs) { IPAddress ip = null; try { ip = IPAddress.Parse(stringIP); } catch (FormatException fex) { onParseError?.Invoke(stringIP, fex.Message); } if (ip != null) { yield return(ip); } } }
/// <summary> /// Parse the runbook content /// </summary> /// <param name="content"></param> public void Parse(string content) { if (_tokens == null || _scriptBlock == null) { IsDirty = true; } if (!IsDirty) { return; } _scriptBlock = System.Management.Automation.Language.Parser.ParseInput(content, out _tokens, out _parseErrors); if (_parseErrors != null && _parseErrors.Length > 0) { _currentlyHasParseErrors = true; OnParseError?.Invoke(this, new ParseErrorEventArgs(_parseErrors)); } else if (_currentlyHasParseErrors) { _currentlyHasParseErrors = false; OnClearParseErrors?.Invoke(this, new EventArgs()); } // Analyze the code too if (SettingsService.CurrentSettings.EnableCodeAnalysis && !string.IsNullOrEmpty(content) && IsDirty) { Task.Run(() => { var records = AnalyzerService.Analyze(_scriptBlock, _tokens);//ScriptAnalyzer.Instance.AnalyzeSyntaxTree(_scriptBlock, _tokens, string.Empty); if (SettingsService.CurrentSettings.EnableCodeAnalysis) {// && (_cachedRecords == null || _cachedRecords.Count() != records.Count())) Execute.OnUIThread(() => { OnAnalysisCompleted?.Invoke(this, new AnalysisEventArgs(records)); }); } }); } }