Example #1
0
		public object Eval(IBranch b, string childScript)
		{
			try
			{
				if (!Cache.ContainsKey(b.VPath))
				{
					if (b.GetOrCreateValue("declarationType", "source").ContentString == "source")
					{
						String val;
						IValue v;

						val = (v = b.GetValue("valueForTesting")) == null ? "" : v.ContentString;
						if (string.IsNullOrEmpty(val))
						{
							var repositoryVal = (v = b.GetValue("repositoryValue")) == null ? null : v.ContentString;
							if (!string.IsNullOrEmpty(repositoryVal))
							{
								val = Repository.GetValue(repositoryVal).ContentString;
							}
						}


						var type = (v = b.GetValue("type")) == null ? "string" : v.ContentString;
						var script = String.Format("'[[{0}]]{1}'", type, val);
						Cache.Add(b.VPath, EvalScript(script));
					}
					else
					{
						if (NodesInProgress.Contains(b.VPath))
						{
							throw new EvalStackOverflowException(b, NodesInProgress.Select(vp => Vault.GetBranch(vp)));
						}
						else
						{
							object result;

							var old = NodeInProgress;
							NodeInProgress = b;
							NodesInProgress.Add(b.VPath);

							try
							{
								var source = b.GetValue("elfCode").ContentString;
								if (!string.IsNullOrEmpty(source))
								{
									IBranch conditions = null;
									// in case of a conditional node, we replace its formula body with the corresponding body of checked child node
									if (_checkedNodes != null && (conditions = b.Parent.Parent.GetBranch("_conditions")) != null && conditions.GetBranches().Length > 0)
									{
										var index = 0;
										if ((index = source.IndexOf('=')) > 0) // is subject to replace?
										{
											// look for the very first checked child
											foreach (var child in b.Parent.Parent.GetBranches())
											{
												if (!_checkedNodes.Contains(child.Id)) continue;
												var varName = source.Substring(0, index);
												var formulasBranch = child.GetBranch("_formulaDeclarations");
												if (formulasBranch == null) continue;
												foreach (var formula in formulasBranch.GetBranches())
												{
													var formulaBody = "";
													// look for the very first formula body having $varName within
													if (string.IsNullOrEmpty(formulaBody = formula.GetValue("elfCode").ContentString) || formulaBody.IndexOf(varName) < 0) continue;

													var lines = formulaBody.Split('\n');
													lines[lines.Length - 1] = "ret " + lines[lines.Length - 1];
													source = string.Join(Environment.NewLine, lines);
													break;
												}
												break;
											}
										}
									}
									if (!string.IsNullOrEmpty(childScript))
										source = string.Concat(source, Environment.NewLine, childScript);
								}
								result = EvalScript(source);
							}
							finally
							{
								NodeInProgress = old;
								NodesInProgress.Remove(b.VPath);
							}

							Cache.Add(b.VPath, result);
						}
					}
				}

				return Cache[b.VPath];
			}
			catch (BaseEvalException)
			{
				throw;
			}
			catch (ErroneousScriptRuntimeException esex)
			{
				if (esex.Type == ElfExceptionType.OperandsDontSuitMethod)
				{
					throw new ArgsDontSuitTheFunctionException(b, esex.Thread.RuntimeContext.PendingClrCall, esex);
				}
				else
				{
					throw new UnexpectedErrorException(b, esex);
				}
			}
			catch (Exception ex)
			{
				if (ex.InnerException is FormatException)
				{
					throw new BadFormatOfSerializedStringException(b, ex);
				}
				else
				{
					throw new UnexpectedErrorException(b, ex);
				}
			}
		}
Example #2
0
 public static IValue GetOrCreateValue(this IBranch branch, VPath vpath, Stream content)
 {
     return(branch.GetOrCreateValue(vpath, () => content));
 }
Example #3
0
 public static IValue GetOrCreateValue(this IBranch branch, VPath vpath)
 {
     return(branch.GetOrCreateValue(vpath, ((String)null).AsLazyStream()));
 }
Example #4
0
 public static IValue GetOrCreateValue(this IBranch branch, VPath vpath, String content)
 {
     return(branch.GetOrCreateValue(vpath, content.AsLazyStream()));
 }
Example #5
0
		private void LoadBranchOld(IBranch branch, TreeNode parent)
		{
			if (parent == null) // root
			{
				parent = new TreeNode
				         	{
				         		Text = branch.GetOrCreateValue(new VPath("name"), branch.Name).ContentString,
				         		Tag = branch,
				         		//Name = branch.GetOrCreateValue(new VPath("id"), Guid.NewGuid().ToString()).ContentString,
				         		NodeFont = new Font("Tahoma", 8, FontStyle.Bold),
				         	};
				treeScenario.Nodes.Add(parent);
			}
			foreach (var b in branch.GetBranches())
			{
				if (b.Name.StartsWith("_")) continue; // service node
				var n = new TreeNode
				        	{
				        		Text = b.GetOrCreateValue("name", Guid.NewGuid().ToString().Replace('-', '_')).ContentString,
				        		Tag = b,
				        		//Name = b.GetOrCreateValue(new VPath("id"), Guid.NewGuid().ToString().Replace('-', '_')).ContentString
				        	};
				parent.Nodes.Add(n);
				LoadBranchOld(b, n);
			}
		}