public McpConnection() { __LogonResponse2 = new ParseCallback(HandleLogonResponse2); __QueryRealms2 = new ParseCallback(HandleQueryRealms2); __AuthInfo = new ParseCallback(HandleAuthInfo); __LogonRealmEx = new ParseCallback(HandleLogonRealmEx); }
public virtual IBattleNetEvents RegisterCustomPacketHandler(BncsPacketId packetID, ParseCallback parser, out ParseCallback previousParser) { if (object.ReferenceEquals(null, parser)) { throw new ArgumentNullException("parser"); } if (packetID == BncsPacketId.Warden) { throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for the Warden packet. Use the WardenHandler property instead."); } if (packetID > (BncsPacketId)255 || packetID < BncsPacketId.Null) { throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for a packet ID greater than 255 or less than 0."); } if (m_packetToParserMap.ContainsKey(packetID)) { previousParser = m_packetToParserMap[packetID]; } else { previousParser = null; } m_packetToParserMap[packetID] = parser; return(m_customEventSink); }
internal ParseCallback RegisterParseCallback(BncsPacketId packetId, ParseCallback callback) { ParseCallback current; _packetToParserMap.TryGetValue(packetId, out current); _packetToParserMap[packetId] = callback; return(current); }
public void Parse(string text, ParseCallback callback) { int baseoff = 0; foreach (var line in text.Split('\n')) { ParseLine(baseoff, line, callback); baseoff += line.Length + 1; } }
void ParseAddress(int baseoff, int offset, string line, ParseCallback callback) { int s = 0; int e = 0; while (true) { e = line.IndexOf('[', s); if (e < 0) // no address { ParseInstruction(baseoff, offset + s, line.Substring(s).Trim(), callback); break; } else if (e == 0) // a address, try match ] { s = e; e = line.IndexOf(']', s); if (e < s) // no match { break; // treat as text } else { e++; callback(null, Constants.classifier_asm_address, baseoff + offset + s, e - s); s = SkipSpace(line, e); } } else // find address, try match ] { ParseInstruction(baseoff, offset + s, line.Substring(s, e - s).Trim(), callback); s = e; e = line.IndexOf(']', s); if (e < s) // no match { break; //treat as text } else { e++; callback(null, Constants.classifier_asm_address, baseoff + offset + s, e - s); s = SkipSpace(line, e); } } if (e >= line.Length) { break; } } }
private GraphQLValue ParseList(bool isConstant) { int start = _currentToken.Start; // the compiler caches these delegates in the generated code ParseCallback <GraphQLValue> constant = (ref ParserContext context) => context.ParseConstantValue(); ParseCallback <GraphQLValue> value = (ref ParserContext context) => context.ParseValueValue(); return(new GraphQLListValue(ASTNodeKind.ListValue) { Values = Any(TokenKind.BRACKET_L, isConstant ? constant : value, TokenKind.BRACKET_R), Location = GetLocation(start), AstValue = _source.Body.Substring(start, _currentToken.End - start - 1) }); }
/// <summary> /// Retrieves all contacts with a record from a vCard file. /// </summary> /// <param name="path">The file path of vCard stream file</param> /// <param name="callback">The callback function to invoke</param> /// <feature>http://tizen.org/feature/contact</feature> /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception> /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception> /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception> /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception> /// <since_tizen> 4 </since_tizen> public static void ParseForEach(string path, ParseCallback callback) { Interop.Vcard.ContactsVcardParseCallback cb = (IntPtr handle, IntPtr data) => { return(callback(new ContactsRecord(handle, true))); }; int error = Interop.Vcard.ContactsVcardParseToContactForeach(path, cb, IntPtr.Zero); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "ParseForEach Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } }
private List <T>?Any <T>(TokenKind open, ParseCallback <T> next, TokenKind close) where T : ASTNode { Expect(open); ParseComment(); List <T>?nodes = null; while (!Skip(close)) { (nodes ?? (nodes = new List <T>())).Add(next(ref this)); } return(nodes); }
/// <summary> /// Parse vcalendar file with ForEach /// </summary> /// <param name="path">The file path of the vCalendar stream file</param> /// <param name="callback">he callback function to invoke</param> /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception> /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception> /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception> /// <since_tizen> 4 </since_tizen> public static void ParseForEach(string path, ParseCallback callback) { int error = 0; Interop.Vcalendar.ParseCallback cb = (IntPtr handle, IntPtr data) => { return(callback(new CalendarRecord(handle, true))); }; error = Interop.Vcalendar.ParseForEach(path, cb, IntPtr.Zero); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Parse ForEach Vcalendar Failed [" + error + "]"); throw CalendarErrorFactory.GetException(error); } }
void ParseLabel(int baseoff, int offset, string line, ParseCallback callback) { if (string.IsNullOrEmpty(line)) { return; } int s = 0; int e = -1; while (true) { e = line.IndexOf(':', s); if (e < 0) // no more label { ParseAddress(baseoff, offset + s, line.Substring(s).Trim(), callback); break; } else if (e == 0) // empty label, check next { s = SkipSpace(line, e + 1); continue; } else // found a label, check next { var xl = line.Substring(s, e - s); // if has any special char, it's not an effective label if (xl.Any(c => IsSpecialChar(c))) { ParseAddress(baseoff, offset + s, xl.Trim(), callback); } else { // the label may a segment register callback(null, IsSegmentRegister(line.Substring(s, e - s)) ? Constants.classifier_asm_register : Constants.classifier_asm_label, baseoff + offset + s, e - s); } s = SkipSpace(line, e + 1); } if (s >= line.Length) // no more word { return; } } }
public virtual void UnregisterCustomPacketHandler(BncsPacketId packetID, ParseCallback previousParser) { if (packetID == BncsPacketId.Warden) throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for the Warden packet. Use the WardenHandler property instead."); if (packetID > (BncsPacketId)255 || packetID < BncsPacketId.Null) throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for a packet ID greater than 255 or less than 0."); if (object.ReferenceEquals(previousParser, null)) { m_packetToParserMap.Remove(packetID); } else { m_packetToParserMap[packetID] = previousParser; } }
private List <T> Many <T>(TokenKind open, ParseCallback <T> next, TokenKind close) { Expect(open); ParseComment(); var nodes = new List <T> { next(ref this) }; while (!Skip(close)) { nodes.Add(next(ref this)); } return(nodes); }
void ParseInstruction(int baseoff, int offset, string line, ParseCallback callback) { int i = 0; var parts = line.Split(new[] { ' ', '\t', ',', '+', '-', '*', ':' }, StringSplitOptions.None); ClassifierDefinition definition = null; foreach (var part in parts) { if (part.StartsWith("?")) { callback(null, Constants.classifier_asm_cxxdecname, baseoff + offset + i, part.Trim().Length); } else if (m_ClassifierDictionary.TryGetValue(part, out definition)) { callback(definition, definition.classifier, baseoff + offset + i, part.Length); } i += part.Length; i++; } }
public virtual void UnregisterCustomPacketHandler(BncsPacketId packetID, ParseCallback previousParser) { if (packetID == BncsPacketId.Warden) { throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for the Warden packet. Use the WardenHandler property instead."); } if (packetID > (BncsPacketId)255 || packetID < BncsPacketId.Null) { throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for a packet ID greater than 255 or less than 0."); } if (object.ReferenceEquals(previousParser, null)) { m_packetToParserMap.Remove(packetID); } else { m_packetToParserMap[packetID] = previousParser; } }
public virtual IBattleNetEvents RegisterCustomPacketHandler(BncsPacketId packetID, ParseCallback parser, out ParseCallback previousParser) { if (object.ReferenceEquals(null, parser)) throw new ArgumentNullException("parser"); if (packetID == BncsPacketId.Warden) throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for the Warden packet. Use the WardenHandler property instead."); if (packetID > (BncsPacketId)255 || packetID < BncsPacketId.Null) throw new ArgumentOutOfRangeException("packetID", packetID, "Cannot register a custom packet handler for a packet ID greater than 255 or less than 0."); if (m_packetToParserMap.ContainsKey(packetID)) { previousParser = m_packetToParserMap[packetID]; } else { previousParser = null; } m_packetToParserMap[packetID] = parser; return m_customEventSink; }
void ParseLine(int baseoff, string line, ParseCallback callback) { if (callback == null || string.IsNullOrEmpty(line)) { return; } int s = SkipSpace(line, 0); int e = line.IndexOf(";", s); if (e < 0) // no comment { ParseLabel(baseoff, s, line.Trim(), callback); } else if (e == 0) // only comment { callback(null, Constants.classifier_asm_comment, baseoff + s, line.Length); } else // comment and other { ParseLabel(baseoff, s, line.Substring(s, e - s).Trim(), callback); callback(null, Constants.classifier_asm_comment, baseoff + e, line.Length - e); } }
static public void Parse(ParseCallback c, Action <JSONException> ex, string s = "") { JSONParser.ParseStart(c, ex, s); }
internal static extern int ParseForEach(string filePath, ParseCallback parseCb, IntPtr userData);
// // Parses header values calls a callback one value after other. // Note a single string can contain multiple values and any value may have a quoted string in. // The parser will not cut trailing spaces when invoking a callback // internal static void ParseHeaderValues(string[] values, ParseCallback calback, IList list) { if (values == null) { return; } for (int i = 0; i < values.Length; ++i) { string val = values[i]; int end = 0; int start = 0; while (end < val.Length) { //skip spaces while (start < val.Length && val[start] == ' ') { ++start; } if (start == val.Length ) { //empty header value break; } // find comma or quote end = start; find_comma: while (end < val.Length && val[end] != ',' && val[end] != '\"') { ++end; } if (end == val.Length ) { calback(val, start, end-1, list); break; } if (val[end] == '\"') { while (++end < val.Length && val[end] != '"') { ; } if (end == val.Length ) { //warning: no closing quote, accepting calback(val, start, end-1, list); break; } goto find_comma; } else { //Comma calback(val, start, end-1, list); // skip leading spaces while (++end < val.Length && val[end] == ' ') { ; } if (end >= val.Length) { break; } start = end; } } } }
internal static void ParseHeaderValues(string[] values, ParseCallback calback, IList list) { if (values != null) { for (int i = 0; i < values.Length; i++) { string s = values[i]; int num2 = 0; int start = 0; goto Label_00E3; Label_0018: start++; Label_001C: if ((start < s.Length) && (s[start] == ' ')) { goto Label_0018; } if (start != s.Length) { num2 = start; do { while (((num2 < s.Length) && (s[num2] != ',')) && (s[num2] != '"')) { num2++; } if (num2 == s.Length) { calback(s, start, num2 - 1, list); continue; } if (s[num2] != '"') { goto Label_00B4; } while ((++num2 < s.Length) && (s[num2] != '"')) { } } while (num2 != s.Length); calback(s, start, num2 - 1, list); } continue; Label_00B4: calback(s, start, num2 - 1, list); while ((++num2 < s.Length) && (s[num2] == ' ')) { } if (num2 >= s.Length) { continue; } start = num2; Label_00E3: if (num2 < s.Length) { goto Label_001C; } } } }
/// <summary> /// Parses a list of abstract syntax trees asyncronously. /// </summary> /// <param name="callback">Called when a single branch of parsing has completed.</param> /// <param name="newParseBeginning">Called when a new branche of parsing has started.</param> /// <param name="input">The input to parse</param> /// <param name="inputProgression">The index of the current item to parse from.</param> /// <param name="stateStack">The current stack used to parse.</param> /// <param name="currentBranches">The current progression of the created tree.</param> protected void ParseTrees(int id, ParseCallback callback, ParseBegin newParseBeginning, bool syntax, IEnumerable <Terminal <T> > input, int inputProgression = 0, Stack <KeyValuePair <int, GrammarElement <T> > > stateStack = null, List <SyntaxNode <T> > currentBranches = null) { var results = new List <ParseResult <T> >(); newParseBeginning(id); ThreadPool.QueueUserWorkItem(a => { //parse ParseResult <T> result = LRParse(syntax, input.ToArray(), inputProgression, stateStack, currentBranches); //if not successfull if (!result.Success) { if (result.Errors.Count > 0) { //if there are multiple parse actions for the current state. if (result.Errors[0] is MultipleActionsParseError <T> ) { var e = (MultipleActionsParseError <T>)result.Errors[0]; //parse each action foreach (ParserAction <T> action in e.PossibleActions) { //create a new stack for the new thread var stack = new Stack <KeyValuePair <int, GrammarElement <T> > >(result.Stack.Reverse()); //get the ammount of progression through the input int progression = e.Progression; //get the item Terminal <T> item = input.ElementAt(progression >= input.Count() ? input.Count() - 1 : progression); //get a new list of current branches var branches = new List <SyntaxNode <T> >(result.GetParseTree().Root.Children); //perform the action if (PerformAction(true, item, stack, branches, action, ref progression)) { //if the action was to accept, obtain a lock on the results lock (results) { //add the successful result results.Add(new ParseResult <T>(true, new SyntaxTree <T>(branches.First()), stack.ToList())); } continue; } //parse from the action in a new thread ParseTrees(id + 1, callback, newParseBeginning, syntax, input, progression, stack, branches); } } else { results.Add(result); } } //otherwise, we have a unsucessful parse that we can do nothing about. else { results.Add(result); } } //otherwise, we have a successful parse else { results.Add(result); } //send a callback with the results callback.Invoke(id, results); }); }
public BattleNetClientChannel(BattleNetClient source) { _namesToUsers = new Dictionary <string, ChatUser>(); _client = source; _oldParseCallback = _client.RegisterParseCallback(BncsPacketId.ChatEvent, HandleChatEvent); }