Пример #1
0
 protected virtual void OnInfoThreadsReceived(AMCPEventArgs e)
 {
     InfoThreadsReceive?.Invoke(this, new InfoThreadsEventArgs(
                                    e.Data.Select(DataParser.ParseInfoThreads)
                                    .ToList()
                                    ));
 }
Пример #2
0
 /// <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);
 }
Пример #3
0
        private void OnInfo(AMCPEventArgs e)
        {
            var infos = e.Data
                        .Select(DataParser.ParseChannelInfo)
                        .Where(x => x != null).ToList();

            InfoReceived?.Invoke(this, new InfoEventArgs(infos));
        }
Пример #4
0
        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));
        }
Пример #5
0
        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));
            }
        }
Пример #6
0
        /// <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);
            }
        }
Пример #7
0
        /// <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);
            }
        }
Пример #8
0
        /// <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()}");
            }
        }
Пример #9
0
        /// <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);
        }
Пример #10
0
 protected virtual void OnInfoConfigReceived(AMCPEventArgs e)
 {
     InfoConfigReceived?.Invoke(this, e);
 }
Пример #11
0
        private void OnCLS(AMCPEventArgs e)
        {
            List <MediaInfo> medias = e.Data.Select(DataParser.ParseClipData).Where(x => x != null).ToList();

            CLSReceived?.Invoke(this, new CLSEventArgs(medias));
        }
Пример #12
0
        private void OnTLS(AMCPEventArgs e)
        {
            var templates = e.Data.Select(DataParser.ParseTemplate).Where(x => x != null).ToList();

            TLSReceived?.Invoke(this, new TLSEventArgs(templates));
        }
Пример #13
0
 protected virtual void OnRemoveReceived(AMCPEventArgs e)
 {
     RemoveReceived?.Invoke(this, e);
 }
Пример #14
0
 /// <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"));
 }
Пример #15
0
        protected virtual void OnInfoPathsReceived(AMCPEventArgs e)
        {
            var infoPaths = DataParser.ParseInfoPaths(e.Data.FirstOrDefault());

            InfoPathsReceived?.Invoke(this, new InfoPathsEventArgs(infoPaths));
        }
Пример #16
0
 protected virtual void OnThumbnailRetrieve(AMCPEventArgs e)
 {
     ThumbnailsRetrievedReceived?.Invoke(this, new ThumbnailsRetrieveEventArgs(e.Data.FirstOrDefault()));
 }
Пример #17
0
 protected virtual void OnDataList(AMCPEventArgs e)
 {
     DataListUpdated?.Invoke(this, new DataListEventArgs(e.Data));
 }
Пример #18
0
 protected virtual void OnPlayReceived(AMCPEventArgs e)
 {
     PlayReceived?.Invoke(this, e);
 }
Пример #19
0
 protected virtual void OnStopReceived(AMCPEventArgs e)
 {
     StopReceived?.Invoke(this, e);
 }
Пример #20
0
 protected virtual void OnClearReceived(AMCPEventArgs e)
 {
     ClearReceived?.Invoke(this, e);
 }
Пример #21
0
 protected virtual void OnMixerReceived(AMCPEventArgs e)
 {
     MixerReceived?.Invoke(this, e);
 }
Пример #22
0
        private void OnInfoSystemReceived(AMCPEventArgs e)
        {
            var systemInfo = DataParser.ParseInfoSystem(e.Data.FirstOrDefault());

            InfoSystemReceived?.Invoke(this, new InfoSystemEventArgs(systemInfo));
        }
Пример #23
0
 /// <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);
 }
Пример #24
0
 /// <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);
 }
Пример #25
0
 protected virtual void OnThumbnailGenerateReceived(AMCPEventArgs e)
 {
     ThumbnailGenerateReceived?.Invoke(this, e);
 }
Пример #26
0
 private void OnStatusReceived(AMCPEventArgs e)
 {
     StatusReceived?.Invoke(this, e);
 }
Пример #27
0
 protected virtual void OnLoad(AMCPEventArgs e)
 {
     Loaded?.Invoke(this, new LoadEventArgs(e.Data.FirstOrDefault() ?? string.Empty));
 }
Пример #28
0
 private void OnSwapReceived(AMCPEventArgs e)
 {
     SwapReceived?.Invoke(this, e);
 }
Пример #29
0
 /// <summary>
 /// Call when a response is parsed completely
 /// </summary>
 /// <param name="args"></param>
 protected void OnResponseParsed(AMCPEventArgs args)
 {
     ResponseParsed?.Invoke(this, args);
 }
Пример #30
0
        protected virtual void OnInfoTemplateReceived(AMCPEventArgs e)
        {
            var templateInfo = DataParser.ParseTemplateInfo(e.Data.FirstOrDefault());

            InfoTemplateReceived?.Invoke(this, new TemplateInfoEventArgs(templateInfo));
        }