private string GetUserId(APLSkillRequest request) { Session session = request.Session; APLContext skillContext = request.Context; return(session != null ? session.User.UserId : skillContext.System.User.UserId); }
private string GetAttributeWithNamespace(APLContext Context, XElement Node, XNamespace Namespace, string AttributeName, bool bExpand = true, bool bRequired = true, string Fallback = null) { XAttribute Attribute = Node.Attribute(Namespace + AttributeName); if (Attribute == null) { if (bRequired) { Log.TraceWarning("\nMissing attribute '{0}' in '{1}' (skipping instruction)", AttributeName, TraceNodeString(Node)); } return Fallback; } string Result = Attribute.Value; return bExpand ? ExpandVariables(Context, Result) : Result; }
private string ExpandVariables(APLContext Context, string InputString) { string Result = InputString; for (int Idx = Result.IndexOf("$B("); Idx != -1; Idx = Result.IndexOf("$B(", Idx)) { // Find the end of the variable name int EndIdx = Result.IndexOf(')', Idx + 3); if (EndIdx == -1) { break; } // Extract the variable name from the string string Name = Result.Substring(Idx + 3, EndIdx - (Idx + 3)); // Find the value for it, either from the dictionary or the environment block bool Value; if (!Context.BoolVariables.TryGetValue(Name, out Value)) { if (!GlobalContext.BoolVariables.TryGetValue(Name, out Value)) { Idx = EndIdx + 1; continue; } } // Replace the variable, or skip past it Result = Result.Substring(0, Idx) + Value.ToString().ToLower() + Result.Substring(EndIdx + 1); } for (int Idx = Result.IndexOf("$I("); Idx != -1; Idx = Result.IndexOf("$I(", Idx)) { // Find the end of the variable name int EndIdx = Result.IndexOf(')', Idx + 3); if (EndIdx == -1) { break; } // Extract the variable name from the string string Name = Result.Substring(Idx + 3, EndIdx - (Idx + 3)); // Find the value for it, either from the dictionary or the environment block int Value; if (!Context.IntVariables.TryGetValue(Name, out Value)) { if (!GlobalContext.IntVariables.TryGetValue(Name, out Value)) { Idx = EndIdx + 1; continue; } } // Replace the variable, or skip past it Result = Result.Substring(0, Idx) + Value.ToString() + Result.Substring(EndIdx + 1); } for (int Idx = Result.IndexOf("$S("); Idx != -1; Idx = Result.IndexOf("$S(", Idx)) { // Find the end of the variable name int EndIdx = Result.IndexOf(')', Idx + 3); if (EndIdx == -1) { break; } // Extract the variable name from the string string Name = Result.Substring(Idx + 3, EndIdx - (Idx + 3)); // Find the value for it, either from the dictionary or the environment block string Value; if (!Context.StringVariables.TryGetValue(Name, out Value)) { if (!GlobalContext.StringVariables.TryGetValue(Name, out Value)) { Idx = EndIdx + 1; continue; } } // Replace the variable, or skip past it Result = Result.Substring(0, Idx) + Value + Result.Substring(EndIdx + 1); } for (int Idx = Result.IndexOf("$E("); Idx != -1; Idx = Result.IndexOf("$E(", Idx)) { // Find the end of the variable name int EndIdx = Result.IndexOf(')', Idx + 3); if (EndIdx == -1) { break; } // Extract the variable name from the string string Name = Result.Substring(Idx + 3, EndIdx - (Idx + 3)); // Find the value for it, either from the dictionary or the environment block XElement Value; if (!Context.ElementVariables.TryGetValue(Name, out Value)) { if (!GlobalContext.ElementVariables.TryGetValue(Name, out Value)) { Idx = EndIdx + 1; continue; } } // Replace the variable, or skip past it Result = Result.Substring(0, Idx) + Value + Result.Substring(EndIdx + 1); } return Result; }
private bool GetCondition(APLContext Context, XElement Node, string Condition, out bool Result) { Result = false; if (!Context.BoolVariables.TryGetValue(Condition, out Result)) { if (!GlobalContext.BoolVariables.TryGetValue(Condition, out Result)) { Log.TraceWarning("\nMissing condition '{0}' in '{1}' (skipping instruction)", Condition, TraceNodeString(Node)); return false; } } return true; }
private string DumpContext(APLContext Context) { StringBuilder Text = new StringBuilder(); foreach (var Variable in Context.BoolVariables) { Text.AppendLine(string.Format("\tbool {0} = {1}", Variable.Key, Variable.Value.ToString().ToLower())); } foreach (var Variable in Context.IntVariables) { Text.AppendLine(string.Format("\tint {0} = {1}", Variable.Key, Variable.Value)); } foreach (var Variable in Context.StringVariables) { Text.AppendLine(string.Format("\tstring {0} = {1}", Variable.Key, Variable.Value)); } foreach (var Variable in Context.ElementVariables) { Text.AppendLine(string.Format("\telement {0} = {1}", Variable.Key, Variable.Value)); } return Text.ToString(); }
public bool MergeXML(XDocument MergeDoc, string PluginDir, List<string> Architectures) { if (MergeDoc == null) { return false; } // create a context for each architecture ContextIndex++; foreach (string Architecture in Architectures) { APLContext Context = new APLContext(Architecture, PluginDir); Contexts[Architecture + "_" + ContextIndex] = Context; } // merge in the nodes foreach (var Element in MergeDoc.Root.Elements()) { var Parent = XDoc.Root.Element(Element.Name); if (Parent != null) { var Entry = new XElement("Context", new XAttribute("index", ContextIndex.ToString())); Entry.Add(Element.Elements()); Parent.Add(Entry); } else { var Entry = new XElement("Context", new XAttribute("index", ContextIndex.ToString())); Entry.Add(Element.Elements()); var Base = new XElement(Element.Name); Base.Add(Entry); XDoc.Root.Add(Base); } } return true; }
public AndroidPluginLanguage(List<string> XMLFiles, List<string> Architectures) { Contexts = new Dictionary<string, APLContext>(); GlobalContext = new APLContext("", ""); ContextIndex = 0; AndroidNameSpace = "http://schemas.android.com/apk/res/android"; string PathPrefix = Path.GetFileName(Directory.GetCurrentDirectory()).Equals("Source") ? ".." : "Engine"; XDoc = XDocument.Parse("<root xmlns:android=\"http://schemas.android.com/apk/res/android\"></root>"); foreach (string Basename in XMLFiles) { string Filename = Path.Combine(PathPrefix, Basename.Replace("\\", "/")); Log.TraceInformation("\nAPL: {0}", Filename); if (File.Exists(Filename)) { string PluginDir = Path.GetDirectoryName(Filename); try { XDocument MergeDoc = XDocument.Load(Filename); MergeXML(MergeDoc, PluginDir, Architectures); } catch (Exception e) { Log.TraceError("\nAndroid Plugin file {0} parsing failed! {1}", Filename, e); } } else { Log.TraceError("\nAndroid Plugin file {0} missing!", Filename); Log.TraceInformation("\nCWD: {0}", Directory.GetCurrentDirectory()); } } }