Esempio n. 1
0
 public static YamlStream Load(string file)
 {
     string text = File.ReadAllText(file);
     TextInput input = new TextInput(text);
     YamlParser parser = new YamlParser();
     bool success;
     YamlStream stream = parser.ParseYamlStream(input, out success);
     if (success)
     {
         return stream;
     }
     else
     {
         string message = parser.GetEorrorMessages();
         throw new Exception(message);
     }
 }
		/// <summary>
		/// Parses an asset's YAML header and updates its Requires / Provides properties
		/// </summary>
		/// <param name="asset">A reference to an Asset object</param>
		public static void ParseAsset(ref Asset asset)
		{
			var yaml = Utilities.FetchYAMLFromFile(asset.MappedPath);

			if (yaml == "")
			{
				asset.Provides.Add("Nothing");
			}

			var parser = new YamlParser();
			bool success;
			YamlStream yamlStream = parser.ParseYamlStream(new TextInput(yaml), out success);

			foreach (YamlDocument doc in yamlStream.Documents)
			{
				Mapping map = (doc.Root as Mapping);
				if (map == null && Config.ShowErrors == true)
				{
					throw new Exception("Packager: Failed to resolve dependencies for " + asset.MappedPath);
				}
				else
				{
					foreach (MappingEntry entry in map.Enties)
					{
						if (entry.Value is Sequence)
						{
							foreach (DataItem item in (entry.Value as Sequence).Enties)
							{
								if (entry.Key.ToString() == "requires")
								{
									string value = item.ToString();
									var cleanItem = value.LastIndexOf('/') == -1 ? value : value.Substring(value.LastIndexOf('/') + 1);
									asset.Requires.Add(cleanItem);
								}
								else if (entry.Key.ToString() == "provides")
								{
									string value = item.ToString();
									var cleanItem = value.LastIndexOf('/') == -1 ? value : value.Substring(value.LastIndexOf('/') + 1);
									asset.Provides.Add(cleanItem);
								}
							}
						}
					}
				}
			}
		}