/// <summary> /// Interprets the specified parameters. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="resource">The resource.</param> /// <returns></returns> public static string Interpret(string executionName, string parameters, Resource resource) { string result = parameters; do { System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(result, @"\$([a-zA-Z0-9 ]+(?:\.[a-zA-Z0-9 ]+)*)\$" ); if (match == null || !match.Success) { break; } /// break the variable name into its inner structure /// For instance: Sequence File.File string varValue = null; string completeVarName = match.Groups[1].Captures[0].Value; if (completeVarName.Equals("ExecutionFolder")) { varValue = GetExecutionFolder(executionName, resource); } else { string[] varNameParts = completeVarName.Split('.'); /// follow the inner structure to the last internal reference IScriptableValue currentResource = resource; for (int i = 0; i < varNameParts.Length; ++i) { currentResource = currentResource[varNameParts[i]]; } varValue = currentResource.ToString(); } /// replace the $variable$ with the value result = System.Text.RegularExpressions.Regex.Replace( result, @"\$" + completeVarName + @"\$", varValue); }while (true); return(result); }
private Resource LoadResource(System.Xml.XmlNode node, Resource parent) { System.Diagnostics.Debug.Assert(node.Name == "resource"); /// get resource type string resourceTypeName = node.Attributes["type"].Value; SNAP.Resources.ResourceType resourceType = _resourceTypes[resourceTypeName]; /// get resource name string resourceName = node.Attributes["name"].Value; /// get resource id /// if the id is not available (for instance when importing an externallay generated resource) /// generate a new one instead Guid guid = (node.Attributes["id"] != null) ? (new Guid(node.Attributes["id"].Value)) : (Guid.NewGuid()); /// create the new resource Resource resource = new Resource(guid, resourceType, resourceName); /// add field values foreach (System.Xml.XmlNode fieldNode in node.SelectNodes("field")) { string fieldName = fieldNode.Attributes["name"].Value; FieldType fieldType = resource.ResourceType.Fields[fieldName]; FieldValueList fieldValue = null; if (!resource.Fields.ContainsKey(fieldName)) { fieldValue = new FieldValueList(fieldType); resource.Fields.Add(fieldName, fieldValue); } else { fieldValue = resource.Fields[fieldName]; } IScriptableValue value = null; switch (fieldType.Type) { case "internal_ref": value = new InternalRefValue(fieldNode.InnerText); break; case "external_ref": value = new ExternalRefValue(fieldNode.InnerText); break; case "text": value = new TextValue(fieldNode.InnerText); break; default: System.Diagnostics.Debug.Fail(fieldType.Type + " is not a recognized field type"); break; } fieldValue.Values.Add(value); } /// add this node to it's parent if (parent == null) { string family = node["family"].InnerText; parent = _resourceList[family]; } parent.Children.Add(resource); return(resource); }