public static ScriptScraper TryCreate(string path, bool fromAssembly) { if (string.IsNullOrEmpty(path)) return null; string scriptTxt = null; try { Stream scriptStream; if(fromAssembly) scriptStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path); else scriptStream = File.OpenRead(path); using (StreamReader sr = new StreamReader(scriptStream)) scriptTxt = sr.ReadToEnd(); } catch (Exception ex) { Logger.LogError("ScriptScraper: Error loading script from '{0}' - {1}", path, ex.Message); return null; } if (string.IsNullOrEmpty(scriptTxt)) return null; ScriptableScraper scraper = new ScriptableScraper(scriptTxt, false); if (!scraper.LoadSuccessful) { Logger.LogError("ScriptScraper: Error loading script from '{0}'", path); return null; } return new ScriptScraper(scraper); }
public ScriptScraper(ScriptableScraper scriptableScraper) { scraper = scriptableScraper; name = scraper.Name; idString = scraper.ID.ToString(); retrievesDetails = scraper.ScriptType.Contains("GameDetailsFetcher"); retrievesCovers = scraper.ScriptType.Contains("GameCoverFetcher"); retrievesScreens = scraper.ScriptType.Contains("GameScreenFetcher"); retrievesFanart = scraper.ScriptType.Contains("GameFanartFetcher"); }
public ScraperNode(XmlNode xmlNode, ScriptableScraper context) { this.xmlNode = xmlNode; children = new List <ScraperNode>(); this.Context = context; loadSuccess = loadChildren(); // try to load our node attrbute foreach (Attribute currAttr in this.GetType().GetCustomAttributes(true)) { if (currAttr is ScraperNodeAttribute) { nodeSettings = (ScraperNodeAttribute)currAttr; continue; } } if (nodeSettings.LoadNameAttribute) { // Load attributes foreach (XmlAttribute attr in xmlNode.Attributes) { switch (attr.Name) { case "name": name = attr.Value; break; } } // Validate NAME attribute if (name == null) { logger.Error("Missing NAME attribute on: " + xmlNode.OuterXml); loadSuccess = false; return; } // if it's a bad variable name we fail as well if (Name.Contains(" ")) { logger.Error("Invalid NAME attribute (no spaces allowed) \"" + Name + "\" for " + xmlNode.OuterXml); loadSuccess = false; return; } } }
public ScraperNode(XmlNode xmlNode, ScriptableScraper context) { this.xmlNode = xmlNode; children = new List<ScraperNode>(); this.Context = context; loadSuccess = loadChildren(); // try to load our node attrbute foreach(Attribute currAttr in this.GetType().GetCustomAttributes(true)) if (currAttr is ScraperNodeAttribute) { nodeSettings = (ScraperNodeAttribute) currAttr; continue; } if (nodeSettings.LoadNameAttribute) { // Load attributes foreach (XmlAttribute attr in xmlNode.Attributes) { switch (attr.Name) { case "name": name = attr.Value; break; } } // Validate NAME attribute if (name == null) { logger.Error("Missing NAME attribute on: " + xmlNode.OuterXml); loadSuccess = false; return; } // if it's a bad variable name we fail as well if (Name.Contains(" ")) { logger.Error("Invalid NAME attribute (no spaces allowed) \"" + Name + "\" for " + xmlNode.OuterXml); loadSuccess = false; return; } } }
public static ScraperNode Load(XmlNode xmlNode, ScriptableScraper context) { if (xmlNode == null || xmlNode.NodeType == XmlNodeType.Comment || xmlNode.NodeType == XmlNodeType.CDATA) { return(null); } Type nodeType = null; string nodeTypeName = xmlNode.Name; string nodeTypeKey = "node:" + nodeTypeName; // try to grab the type from our dictionary if (typeCache.ContainsKey(nodeTypeKey)) { nodeType = typeCache[nodeTypeKey]; } // if it's not there, search the assembly for the type else { Type[] typeList = Assembly.GetExecutingAssembly().GetTypes(); foreach (Type currType in typeList) { foreach (Attribute currAttr in currType.GetCustomAttributes(true)) { if (currAttr.GetType() == typeof(ScraperNodeAttribute) && nodeTypeName.Equals(((ScraperNodeAttribute)currAttr).NodeName)) { // store our type and put it in our dictionary so we dont have to // look it up again typeCache[nodeTypeKey] = currType; nodeType = currType; break; } } } } // if we couldn't find anything log the unhandled node and exit if (nodeType == null) { logger.Error("Unsupported node type: " + xmlNode.OuterXml); return(null); } // try to create a new scraper node object try { ConstructorInfo constructor = nodeType.GetConstructor(new Type[] { typeof(XmlNode), typeof(ScriptableScraper) }); ScraperNode newNode = (ScraperNode)constructor.Invoke(new object[] { xmlNode, context }); return(newNode); } catch (Exception e) { if (e.GetType() == typeof(ThreadAbortException)) { throw e; } logger.Error("Error instantiating ScraperNode based on: " + xmlNode.OuterXml, e); return(null); } }
public bool Load(string script) { bool debugMode = MovingPicturesCore.Settings.DataSourceDebugActive; scraper = new ScriptableScraper(script, debugMode); if (!scraper.LoadSuccessful) { scraper = null; return false; } providesMovieDetails = scraper.ScriptType.Contains("MovieDetailsFetcher"); providesCoverArt = scraper.ScriptType.Contains("MovieCoverFetcher"); providesBackdrops = scraper.ScriptType.Contains("MovieBackdropFetcher"); return true; }
public static ScraperNode Load(XmlNode xmlNode, ScriptableScraper context) { if (xmlNode == null || xmlNode.NodeType == XmlNodeType.Comment || xmlNode.NodeType == XmlNodeType.CDATA) return null; Type nodeType = null; string nodeTypeName = xmlNode.Name; string nodeTypeKey = "node:" + nodeTypeName; // try to grab the type from our dictionary if (typeCache.ContainsKey(nodeTypeKey)) nodeType = typeCache[nodeTypeKey]; // if it's not there, search the assembly for the type else { Type[] typeList = Assembly.GetExecutingAssembly().GetTypes(); foreach (Type currType in typeList) foreach (Attribute currAttr in currType.GetCustomAttributes(true)) if (currAttr.GetType() == typeof(ScraperNodeAttribute) && nodeTypeName.Equals(((ScraperNodeAttribute)currAttr).NodeName)) { // store our type and put it in our dictionary so we dont have to // look it up again typeCache[nodeTypeKey] = currType; nodeType = currType; break; } } // if we couldn't find anything log the unhandled node and exit if (nodeType == null) { logger.Error("Unsupported node type: " + xmlNode.OuterXml); return null; } // try to create a new scraper node object try { ConstructorInfo constructor = nodeType.GetConstructor(new Type[] { typeof(XmlNode), typeof(ScriptableScraper) }); ScraperNode newNode = (ScraperNode)constructor.Invoke(new object[] { xmlNode, context }); return newNode; } catch (Exception e) { if (e.GetType() == typeof(ThreadAbortException)) throw e; logger.Error("Error instantiating ScraperNode based on: " + xmlNode.OuterXml, e); return null; } }