public StandardXmlMediaHandler(XElement handlerElement)
        {
            try
            {
                Name              = handlerElement.Element("Name").Value;
                ContentDirectory  = handlerElement.Element("ContentDirectory").Value;
                SearchDirectories = new List <string>();

                //TODO: this one is volatile, make it safer
                var searchDirectoriesElement = handlerElement.Element("SearchDirectories");

                if (searchDirectoriesElement != null)
                {
                    SearchDirectories =
                        searchDirectoriesElement
                        .Elements("SearchDirectory")
                        .Select(element => element.Value).ToList();
                }
                else
                {
                    SearchDirectories = new List <string>();
                    Logging.Log.WarnFormat("No directores found for {0}", Name);
                }

                //TODO: volatile code, can easily crash. fix it
                FileActions    = new WindowsFileActions();
                ContentMatcher = HandlerXmlParser.ParseContentMatches(handlerElement.Element("MatchPatterns")).FirstOrDefault();
            }
            catch (Exception ex)
            {
                Logging.Log.Error("Failure loading showhandler", ex);
                throw;
            }
        }
Exemplo n.º 2
0
        public ShowHandler(XElement handlerElement)
        {
            try
            {
                if (handlerElement?.Element("Name") == null)
                {
                    throw new NullReferenceException(nameof(handlerElement));
                }

                Name              = handlerElement.Element("Name").Value;
                ContentDirectory  = handlerElement.Element("ContentDirectory").Value;
                SearchDirectories = new List <string>();

                //TODO: this one is volatile, make it safer
                var searchDirectoriesElement = handlerElement.Element("SearchDirectories");

                if (searchDirectoriesElement != null)
                {
                    SearchDirectories =
                        searchDirectoriesElement
                        .Elements("SearchDirectory")
                        .Select(element => element.Value).ToList();
                }
                else
                {
                    SearchDirectories = new List <string>();
                    Logging.Log.WarnFormat("No directores found for {0}", Name);
                }

                //TODO: volatile code, can easily crash. fix it
                _showMatches = new List <ShowMatcher>();
                //HandlerXmlParser.ParseContentMatches(handlerElement.Element("MatchPatterns")).Cast<ShowMatcher>().ToList();

                _showMatches = HandlerXmlParser.ParseContentMatches(handlerElement.Element("MatchPatterns")).Cast <ShowMatcher>().ToList();

                Shows = _showMatches.Select(matcher => matcher.Show).ToList();

                FileActions = new WindowsFileActions();
            }
            catch (Exception ex)
            {
                Logging.Log.Error("Failure loading showhandler", ex);
                throw;
            }
        }