protected virtual void OnInfoThreadsReceived(AMCPEventArgs e) { InfoThreadsReceive?.Invoke(this, new InfoThreadsEventArgs( e.Data.Select(DataParser.ParseInfoThreads) .ToList() )); }
/// <summary> /// Parsing when we receiving multiline /// </summary> /// <param name="line"></param> protected void ParseMultilineData(string line, AMCPEventArgs eventArgs) { if (line.Length == 0) { return; } eventArgs.Data.Add(line); }
private void OnInfo(AMCPEventArgs e) { var infos = e.Data .Select(DataParser.ParseChannelInfo) .Where(x => x != null).ToList(); InfoReceived?.Invoke(this, new InfoEventArgs(infos)); }
protected virtual void OnThumbnalList(AMCPEventArgs e) { var thumbnails = new List <Thumbnail>(); foreach (string data in e.Data) { thumbnails.Add(DataParser.ParseThumbnailData(data)); } ThumbnailsListReceived?.Invoke(this, new ThumbnailsListEventArgs(thumbnails)); }
protected virtual void OnDataRetrieve(AMCPEventArgs e) { if (e.Error == AMCPError.FileNotFound) { DataRetrieved?.Invoke(this, new DataRetrieveEventArgs(string.Empty)); } if (e.Error == AMCPError.None && e.Data.Any()) { DataRetrieved?.Invoke(this, new DataRetrieveEventArgs(e.Data.FirstOrDefault())); } else { DataRetrieved?.Invoke(this, new DataRetrieveEventArgs(string.Empty)); } }
/// <summary> /// Parse the header line to get return code and command type result /// </summary> /// <param name="line"></param> /// <param name="eventArgs"></param> protected AMCPParserState?ParseHeader(string line, AMCPEventArgs eventArgs) { if (string.IsNullOrEmpty(line)) { return(null); } var command = line; var code = _regexCode.Match(line).Value; if (string.IsNullOrEmpty(code)) { return(null); } //If we found a code we can remove him to line to get only the command if (!string.IsNullOrEmpty(code)) { command = line.Replace(code, ""); } //Removing extra chars that are returned when success command = command.Replace("OK", "").Trim(); //Testing the code return 100+more Information, 200+more Success operation, 400+more error switch (code[0]) { case '1': return(ParseInformationalHeader(code)); case '2': return(ParseSuccessHeader(command, code, eventArgs)); case '4': case '5': ParseErrorHeader(command, code, eventArgs); return(null); default: ParseRetrieveData(line, eventArgs); return(AMCPParserState.ExpectingMultilineData); } }
/// <summary> /// Parse code in the 200 range /// </summary> /// <param name="command"></param> /// <param name="code"></param> protected AMCPParserState?ParseSuccessHeader(string command, string code, AMCPEventArgs eventArgs) { eventArgs.Command = command.TryParseFromCommandValue(AMCPCommand.Undefined); if (!int.TryParse(code, out var returnCode)) { return(null); } switch (returnCode) { case 200: return(AMCPParserState.ExpectingMultilineData); case 201: return(AMCPParserState.ExpectingOneLineData); default: return(null); } }
/// <summary> /// Parse a line to know what type of line was received. Header, OneLine or Multiline /// </summary> /// <param name="line"></param> /// <param name="state"></param> /// <param name="nextParserEventArgs"></param> protected AMCPParserState?ParseLine(string line, AMCPParserState?state, AMCPEventArgs nextParserEventArgs) { if (state == null) { return(null); } switch (state) { case AMCPParserState.ExpectingHeader: return(ParseHeader(line, nextParserEventArgs)); case AMCPParserState.ExpectingOneLineData: ParseOneLineData(line, nextParserEventArgs); return(null); case AMCPParserState.ExpectingMultilineData: ParseMultilineData(line, nextParserEventArgs); return(AMCPParserState.ExpectingMultilineData); default: throw new NotImplementedException($"{state.ToString()}"); } }
/// <summary> /// Get TCP Message, parse it to retrieve block for command send /// </summary> /// <param name="data"></param> /// <returns></returns> protected IEnumerable <AMCPEventArgs> Parse(string data) { var amcpParserEventArgsList = new List <AMCPEventArgs>(); if (string.IsNullOrEmpty(data)) { return(amcpParserEventArgsList); } //If we received multiple response we delimiter the response by block var responseBlocks = _regexBlockDelimiter.Split(data); foreach (var block in responseBlocks) { var parsingState = new AMCPParserState?(AMCPParserState.ExpectingHeader); var eventArgs = new AMCPEventArgs(); var lines = _regexCommandDelimiter.Split(block); lines.Aggregate(parsingState, (current, line) => ParseLine(line, current, eventArgs)); amcpParserEventArgsList.Add(eventArgs); OnResponseParsed(eventArgs); } return(amcpParserEventArgsList); }
protected virtual void OnInfoConfigReceived(AMCPEventArgs e) { InfoConfigReceived?.Invoke(this, e); }
private void OnCLS(AMCPEventArgs e) { List <MediaInfo> medias = e.Data.Select(DataParser.ParseClipData).Where(x => x != null).ToList(); CLSReceived?.Invoke(this, new CLSEventArgs(medias)); }
private void OnTLS(AMCPEventArgs e) { var templates = e.Data.Select(DataParser.ParseTemplate).Where(x => x != null).ToList(); TLSReceived?.Invoke(this, new TLSEventArgs(templates)); }
protected virtual void OnRemoveReceived(AMCPEventArgs e) { RemoveReceived?.Invoke(this, e); }
/// <summary> /// Parsing for block containing data, like CLS or TLS command /// </summary> /// <param name="line"></param> protected void ParseRetrieveData(string line, AMCPEventArgs eventArgs) { eventArgs.Command = AMCPCommand.DATA_RETRIEVE; eventArgs.Data.Add(line.Replace("\\n", "\n")); }
protected virtual void OnInfoPathsReceived(AMCPEventArgs e) { var infoPaths = DataParser.ParseInfoPaths(e.Data.FirstOrDefault()); InfoPathsReceived?.Invoke(this, new InfoPathsEventArgs(infoPaths)); }
protected virtual void OnThumbnailRetrieve(AMCPEventArgs e) { ThumbnailsRetrievedReceived?.Invoke(this, new ThumbnailsRetrieveEventArgs(e.Data.FirstOrDefault())); }
protected virtual void OnDataList(AMCPEventArgs e) { DataListUpdated?.Invoke(this, new DataListEventArgs(e.Data)); }
protected virtual void OnPlayReceived(AMCPEventArgs e) { PlayReceived?.Invoke(this, e); }
protected virtual void OnStopReceived(AMCPEventArgs e) { StopReceived?.Invoke(this, e); }
protected virtual void OnClearReceived(AMCPEventArgs e) { ClearReceived?.Invoke(this, e); }
protected virtual void OnMixerReceived(AMCPEventArgs e) { MixerReceived?.Invoke(this, e); }
private void OnInfoSystemReceived(AMCPEventArgs e) { var systemInfo = DataParser.ParseInfoSystem(e.Data.FirstOrDefault()); InfoSystemReceived?.Invoke(this, new InfoSystemEventArgs(systemInfo)); }
/// <summary> /// Parsing for the case we received only one line /// </summary> /// <param name="line"></param> /// <param name="eventArgs"></param> protected void ParseOneLineData(string line, AMCPEventArgs eventArgs) { eventArgs.Data.Add(line); }
/// <summary> /// Parse error code /// </summary> /// <param name="command"></param> /// <param name="code"></param> protected void ParseErrorHeader(string command, string code, AMCPEventArgs eventArgs) { eventArgs.Error = code.ToAMCPError(); eventArgs.Command = command.TryParseFromCommandValue(AMCPCommand.Undefined); }
protected virtual void OnThumbnailGenerateReceived(AMCPEventArgs e) { ThumbnailGenerateReceived?.Invoke(this, e); }
private void OnStatusReceived(AMCPEventArgs e) { StatusReceived?.Invoke(this, e); }
protected virtual void OnLoad(AMCPEventArgs e) { Loaded?.Invoke(this, new LoadEventArgs(e.Data.FirstOrDefault() ?? string.Empty)); }
private void OnSwapReceived(AMCPEventArgs e) { SwapReceived?.Invoke(this, e); }
/// <summary> /// Call when a response is parsed completely /// </summary> /// <param name="args"></param> protected void OnResponseParsed(AMCPEventArgs args) { ResponseParsed?.Invoke(this, args); }
protected virtual void OnInfoTemplateReceived(AMCPEventArgs e) { var templateInfo = DataParser.ParseTemplateInfo(e.Data.FirstOrDefault()); InfoTemplateReceived?.Invoke(this, new TemplateInfoEventArgs(templateInfo)); }