private string GetAssemblyPath() { string assemblyName = null; string assemblyPath = null; if (TreeReference.StartsWith("x12", StringComparison.OrdinalIgnoreCase)) { assemblyName = TreeReference; assemblyName = assemblyName.Replace(".transactions", ""); } else if (TreeReference.StartsWith("GCommerce.EDI", StringComparison.OrdinalIgnoreCase)) { assemblyName = TreeReference; assemblyName = assemblyName.Replace("._", "."); assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(".Schemas")); } if (string.IsNullOrWhiteSpace(assemblyName) == false) { assemblyName += ".dll"; assemblyPath = Directory.GetFiles(BtmFileDirName, assemblyName, SearchOption.AllDirectories).FirstOrDefault(); if (assemblyPath != null) { ConsoleExtensions.WriteInfo("Found {0}", Path.GetFileName(assemblyPath)); } else { ConsoleExtensions.WriteError("No assembly {0} found for {1} ", assemblyName, TreeReference); } } return(assemblyPath); }
public IDataPayload createSerializedPayload(FormInstance model, IDataReference ref_) { init(); rootRef = model.unpackReference2(ref_); if (this.serializer == null) { this.setAnswerDataSerializer(new XFormAnswerDataSerializer()); } model.accept(this); if (theXmlDoc != null) { byte[] form = Encoding.UTF8.GetBytes(XFormSerializer.getString(theXmlDoc)); if (dataPointers.Count == 0) { return(new ByteArrayPayload(form, null, IDataPayload_Fields.PAYLOAD_TYPE_XML)); } MultiMessagePayload payload = new MultiMessagePayload(); payload.addPayload(new ByteArrayPayload(form, null, IDataPayload_Fields.PAYLOAD_TYPE_XML)); IEnumerator en = dataPointers.GetEnumerator(); while (en.MoveNext()) { IDataPointer pointer = (IDataPointer)en.Current; payload.addPayload(new DataPointerPayload(pointer)); } return(payload); } else { return(null); } }
public TreeCheckFieldAccessNode(TreeContext context, SourceLocation location, TreeReference subject, string name) : base(context, location) { Subject = subject; Name = name; }
public TreeMatchNode(TreeContext context, SourceLocation location, TreeReference operand, ImmutableArray <TreePatternArm> arms) : base(context, location) { Operand = operand; Arms = arms; }
private Boolean setRepeatNextMultiplicity(ArrayList elements, ArrayList multiplicities) { // find out if node is repeatable TreeReference nodeRef = form.getChildInstanceRef(elements, multiplicities); TreeElement node = form.Instance.resolveReference(nodeRef); if (node == null || node.repeatable) { // node == null if there are no // instances of the repeat int mult; if (node == null) { mult = 0; // no repeats; next is 0 } else { String name = node.getName(); TreeElement parentNode = form.Instance.resolveReference(nodeRef.getParentRef()); mult = parentNode.getChildMultiplicity(name); } multiplicities[multiplicities.Count - 1] = (System.Int32)(repeatStructure == REPEAT_STRUCTURE_NON_LINEAR ? TreeReference.INDEX_REPEAT_JUNCTURE : mult); return(true); } else { return(false); } }
public Condition(IConditionExpr expr, int trueAction, int falseAction, TreeReference contextRef, ArrayList targets) : base(expr, contextRef) { this.trueAction = trueAction; this.falseAction = falseAction; this.targets = targets; }
private static void getTriggers(XPathExpression x, List <TreeReference> v) { if (x is XPathPathExpr) { TreeReference ref_ = ((XPathPathExpr)x).getReference(); if (!v.Contains(ref_)) { v.Add(ref_); } } else if (x is XPathBinaryOpExpr) { getTriggers(((XPathBinaryOpExpr)x).a, v); getTriggers(((XPathBinaryOpExpr)x).b, v); } else if (x is XPathUnaryOpExpr) { getTriggers(((XPathUnaryOpExpr)x).a, v); } else if (x is XPathFuncExpr) { XPathFuncExpr fx = (XPathFuncExpr)x; for (int i = 0; i < fx.args.Length; i++) { getTriggers(fx.args[i], v); } } }
public void addTarget(TreeReference target) { if (targets.IndexOf(target) == -1) { targets.Add(target); } }
public TreeIfNode(TreeContext context, SourceLocation location, TreeReference condition, TreeReference then, TreeReference @else) : base(context, location) { Condition = condition; Then = then; Else = @else; }
public void setDestRef(QuestionDef q) { destRef = FormInstance.unpackReference(q.Bind).clone(); if (copyMode) { destRef.add(copyRef.getNameLast(), TreeReference.INDEX_UNBOUND); } }
public TreeForNode(TreeContext context, SourceLocation location, TreePattern pattern, TreeReference collection, TreeReference body) : base(context, location) { Pattern = pattern; Collection = collection; Body = body; }
public TreeBinaryNode(TreeContext context, SourceLocation location, TreeReference left, string @operator, TreeReference right) : base(context, location) { Left = left; Operator = @operator; Right = right; }
public TreeRelationalNode(TreeContext context, SourceLocation location, TreeReference left, TreeRelationalOperator @operator, TreeReference right) : base(context, location) { Left = left; Operator = @operator; Right = right; }
public TreeIndexNode(TreeContext context, SourceLocation location, TreeReference subject, ImmutableArray <TreeReference> arguments, TreeReference?variadicArgument) : base(context, location) { Subject = subject; Arguments = arguments; VariadicArgument = variadicArgument; }
public TreeTryReceiveNode(TreeContext context, SourceLocation location, TreeLocal result, TreeReference then, TreeReference @else) : base(context, location) { Result = result; Then = then; Else = @else; }
public TreeCallNode(TreeContext context, SourceLocation location, TreeReference subject, ImmutableArray <TreeReference> arguments, TreeReference?variadicArgument, ImmutableArray <TreePatternArm> catchArms) : base(context, location) { Subject = subject; Arguments = arguments; VariadicArgument = variadicArgument; CatchArms = catchArms; }
public TreeTryCallNode(TreeContext context, SourceLocation location, TreeReference subject, ImmutableArray <TreeReference> arguments, TreeReference?variadicArgument, TreeLocal exception, TreeReference @catch) : base(context, location) { Subject = subject; Arguments = arguments; VariadicArgument = variadicArgument; Exception = exception; Catch = @catch; }
public void readExternal(BinaryReader in_renamed, PrototypeFactory pf) { nodesetRef = (TreeReference)ExtUtil.read(in_renamed, typeof(TreeReference), pf); nodesetExpr = (IConditionExpr)ExtUtil.read(in_renamed, new ExtWrapTagged(), pf); contextRef = (TreeReference)ExtUtil.read(in_renamed, typeof(TreeReference), pf); labelRef = (TreeReference)ExtUtil.read(in_renamed, typeof(TreeReference), pf); labelExpr = (IConditionExpr)ExtUtil.read(in_renamed, new ExtWrapTagged(), pf); valueRef = (TreeReference)ExtUtil.read(in_renamed, new ExtWrapNullable(typeof(TreeReference)), pf); valueExpr = (IConditionExpr)ExtUtil.read(in_renamed, new ExtWrapNullable(new ExtWrapTagged()), pf); copyRef = (TreeReference)ExtUtil.read(in_renamed, new ExtWrapNullable(typeof(TreeReference)), pf); labelIsItext = ExtUtil.readBool(in_renamed); copyMode = ExtUtil.readBool(in_renamed); }
public Object pivot(FormInstance model, EvaluationContext evalContext, List <Object> pivots, Object sentinal) { TreeReference out_ = this.getReference(); //Either concretely the sentinal, or "." if (out_.Equals(sentinal) || (out_.getRefLevel() == 0)) { return(sentinal); } else { return(this.eval(model, evalContext)); } }
public void apply(FormInstance instance, EvaluationContext evalContext, FormDef f) { Object result = eval(instance, evalContext); for (int i = 0; i < targets.Count; i++) { TreeReference targetRef = ((TreeReference)targets[i]).contextualize(evalContext.ContextRef); List <TreeReference> v = instance.expandReference(targetRef); for (int j = 0; j < v.Count; j++) { TreeReference affectedRef = (TreeReference)v[j]; apply(affectedRef, result, instance, f); } } }
public IConditionExpr getRelativeValue() { TreeReference relRef = null; if (copyRef == null) { relRef = valueRef; //must be absolute in this case } else if (valueRef != null) { relRef = valueRef.relativize(copyRef); } return(relRef != null?RestoreUtils.xfFact.refToPathExpr(relRef) : null); }
/** * Determine if the current FormIndex is relevant. Only relevant indexes * should be returned when filling out a form. * * @param index * @return true if current element at FormIndex is relevant */ public Boolean isIndexRelevant(FormIndex index) { TreeReference ref_ = form.getChildInstanceRef(index); Boolean isAskNewRepeat = (getEvent(index) == FormEntryController.EVENT_PROMPT_NEW_REPEAT); Boolean isRepeatJuncture = (getEvent(index) == FormEntryController.EVENT_REPEAT_JUNCTURE); Boolean relevant; if (isAskNewRepeat) { relevant = form.isRepeatRelevant(ref_) && form.canCreateRepeat(ref_, index); //repeat junctures are still relevant if no new repeat can be created; that option //is simply missing from the menu } else if (isRepeatJuncture) { relevant = form.isRepeatRelevant(ref_); } else { TreeElement node = form.Instance.resolveReference(ref_); relevant = node.isRelevant(); // check instance flag first } if (relevant) { // if instance flag/condition says relevant, we still // have to check the <group>/<repeat> hierarchy FormIndex ancestorIndex = index; while (!ancestorIndex.isTerminal()) { // This should be safe now that the TreeReference is contained // in the ancestor index itself TreeElement ancestorNode = form.Instance.resolveReference(ancestorIndex.getLocalReference()); if (!ancestorNode.isRelevant()) { relevant = false; break; } ancestorIndex = ancestorIndex.getNextLevel(); } } return(relevant); }
/** * Constructs an index which references an element past the level of * specificity of the current context, founded by the currentLevel * index. * (currentLevel, (nextLevel...)) */ public FormIndex(FormIndex nextLevel, FormIndex currentLevel) { if (currentLevel == null) { this.nextLevel = nextLevel.nextLevel; this.localIndex = nextLevel.localIndex; this.instanceIndex = nextLevel.instanceIndex; this.reference = nextLevel.reference; } else { this.nextLevel = nextLevel; this.localIndex = currentLevel.getLocalIndex(); this.instanceIndex = currentLevel.getInstanceIndex(); this.reference = currentLevel.reference; } }
public IDataPayload createSerializedPayload(FormInstance model, IDataReference ref_) { init(); rootRef = model.unpackReference2(ref_); if (this.serializer == null) { this.setAnswerDataSerializer(new XFormAnswerDataSerializer()); } model.accept(this); if (theSmsStr != null) { byte[] form = Encoding.UTF8.GetBytes(theSmsStr); return(new ByteArrayPayload(form, null, IDataPayload_Fields.PAYLOAD_TYPE_SMS)); } else { return(null); } }
// // boolean nodeset = forceNodeset; // if (!nodeset) { // //is this a nodeset? it is if the ref contains any unbound multiplicities AND the unbound nodes are repeatable // //the way i'm calculating this sucks; there has got to be an easier way to find out if a node is repeatable // TreeReference repeatTestRef = TreeReference.rootRef(); // for (int i = 0; i < ref.size(); i++) { // repeatTestRef.add(ref.getName(i), ref.getMultiplicity(i)); // if (ref.getMultiplicity(i) == TreeReference.INDEX_UNBOUND) { // if (m.getTemplate(repeatTestRef) != null) { // nodeset = true; // break; // } // } // } // } public static Object getRefValue(FormInstance model, EvaluationContext ec, TreeReference ref_) { if (ec.isConstraint && ref_.Equals(ec.ContextRef)) { //ITEMSET TODO: need to update this; for itemset/copy constraints, need to simulate a whole xml sub-tree here return(unpackValue(ec.candidateValue)); } else { TreeElement node = model.resolveReference(ref_); if (node == null) { //shouldn't happen -- only existent nodes should be in nodeset throw new XPathTypeMismatchException("Node " + ref_.toString() + " does not exist!"); } return(unpackValue(node.isRelevant() ? node.getValue() : null)); } }
/* * (non-Javadoc) * @see org.javarosa.core.model.utils.IInstanceSerializingVisitor#serializeInstance(org.javarosa.core.model.instance.FormInstance, org.javarosa.core.model.IDataReference) */ public byte[] serializeInstance(FormInstance model, IDataReference ref_) { init(); rootRef = model.unpackReference2(ref_); if (this.serializer == null) { this.setAnswerDataSerializer(new XFormAnswerDataSerializer()); } model.accept(this); if (theSmsStr != null) { //Encode in UTF-16 by default, since it's the default for complex messages return(Encoding.UTF8.GetBytes(theSmsStr)); } else { return(null); } }
public static XPathPathExpr fromRef(TreeReference out_) { XPathPathExpr path = new XPathPathExpr(); path.init_context = (out_.isAbsolute() ? INIT_CONTEXT_ROOT : INIT_CONTEXT_RELATIVE); path.steps = new XPathStep[out_.size()]; for (int i = 0; i < path.steps.Length; i++) { if (out_.getName(i).Equals(TreeReference.NAME_WILDCARD)) { path.steps[i] = new XPathStep(XPathStep.AXIS_CHILD, XPathStep.TEST_NAME_WILDCARD); } else { path.steps[i] = new XPathStep(XPathStep.AXIS_CHILD, new XPathQName(out_.getName(i))); } } return(path); }
public virtual byte[] serializeInstance(FormInstance model, IDataReference ref_) { init(); rootRef = model.unpackReference2(ref_); if (this.serializer == null) { this.setAnswerDataSerializer(new XFormAnswerDataSerializer()); } model.accept(this); if (theXmlDoc != null) { return(Encoding.UTF8.GetBytes(XFormSerializer.getString(theXmlDoc))); } else { return(null); } }
/** * @param index * @return true if the element at the specified index is read only */ public Boolean isIndexReadonly(FormIndex index) { if (index.isBeginningOfFormIndex() || index.isEndOfFormIndex()) { return(true); } TreeReference ref_ = form.getChildInstanceRef(index); Boolean isAskNewRepeat = (getEvent(index) == FormEntryController.EVENT_PROMPT_NEW_REPEAT || getEvent(index) == FormEntryController.EVENT_REPEAT_JUNCTURE); if (isAskNewRepeat) { return(false); } else { TreeElement node = form.Instance.resolveReference(ref_); return(!node.isEnabled()); } }
private string ReadSchema(string treeAssemblyPath) { string schema = null; Assembly tree = Assembly.LoadFrom(treeAssemblyPath); Type schemaType = tree.GetType(TreeReference); PropertyInfo xmlContents = schemaType.GetProperty("XmlContent"); object obj = Activator.CreateInstance(schemaType); MethodInfo xmlContentsGet = xmlContents.GetMethod; schema = xmlContentsGet.Invoke(obj, null) as string; if (TreeReference.Contains("Interchange_")) { string importSchemaReference = TreeReference.Replace("Interchange_", ""); schemaType = tree.GetType(TreeReference); xmlContents = schemaType.GetProperty("XmlContent"); obj = Activator.CreateInstance(schemaType); xmlContentsGet = xmlContents.GetMethod; string importSchema = xmlContentsGet.Invoke(obj, null) as string; //http://msdn.microsoft.com/en-us/library/ms256237%28v=vs.110%29.aspx XmlSchemaSet schemaSet = new XmlSchemaSet(); } // To avoid XmlException: There is no Unicode byte order mark. Cannot switch to Unicode. // http://social.msdn.microsoft.com/Forums/en-US/750b76df-6728-47f3-8199-d9c2b9c9db44/there-is-no-unicode-byte-order-markcannot-switch-to-unicode-error-while-loading-with-xmldocument?forum=xmlandnetfx schema = schema.Replace(" encoding=\"utf-16\"", ""); string tempSchemaFileName = Path.ChangeExtension(TreeReference, ".xsd"); if (File.Exists(tempSchemaFileName)) { File.Delete(tempSchemaFileName); } File.AppendAllText(tempSchemaFileName, schema); return(schema); }
private static bool EnsureTileLoaded(MapId map, TileCoord tile, TreeReference<Model> tree) { if (IsTileLoaded(map, tile) || noTileExists.ContainsKey(GenerateKey(map, tile))) return true; if (!LoadTile(tree, map, tile)) { noTileExists.Add(GenerateKey(map, tile), true); return false; } return true; }
internal static QuadTree<Building> GetBuildingTree(MapId mapId, TileCoord tileCoord) { if (!MapDataExists(mapId)) return null; TreeReference<Building> treeRef; lock (worldBuildings) { // map has tree? if (worldBuildings.TryGetValue(mapId, out treeRef)) { if (treeRef.Tree != null) return treeRef.Tree; } else { // Create map tree var box = RegionBoundaries.GetRegionBoundaries()[(int)mapId]; worldBuildings[mapId] = treeRef = new TreeReference<Building>(new QuadTree<Building>(box)); } } lock (treeRef.LoadLock) { EnsureGroupLoaded(treeRef, mapId, tileCoord); return treeRef.Tree; } }
internal static QuadTree<Model> GetBuildingTree(MapId map, TileCoord tileCoord) { if (!HasMap(map)) return null; TreeReference<Model> tree; lock (worldModels) { // map has tree? if (worldModels.TryGetValue(map, out tree)) { if (tree.Tree != null) return tree.Tree; } else { // Create map tree var box = RegionBoundaries.GetRegionBoundaries()[(int)map]; worldModels[map] = tree = new TreeReference<Model>(new QuadTree<Model>(box)); } } lock (tree.LoadLock) { EnsureGroupLoaded(tree, map, tileCoord); return tree.Tree; } }
private static void ReadModels(BinaryReader br, TreeReference<Model> tree) { var numModels = br.ReadInt32(); for (var i = 0; i < numModels; i++) { var bounds = br.ReadBoundingBox(); Vector3[] vertices; var numVertices = br.ReadInt32(); if (numVertices > 0) { vertices = new Vector3[numVertices]; for (var j = 0; j < numVertices; j++) { vertices[j] = br.ReadVector3(); } } else { vertices = null; } Index3[] indices; var numIndices = br.ReadInt32(); if (numIndices > 0) { indices = new Index3[numIndices]; for (var j = 0; j < numIndices; j++) { indices[j] = br.ReadIndex3(); } } else { indices = null; } var model = new Model { Bounds = bounds, Vertices = vertices, Triangles = indices }; tree.Tree.Insert(model); } }
private static bool LoadTileModels(TreeReference<Model> tree, string filePath) { using (var file = File.OpenRead(filePath)) using (var br = new BinaryReader(file)) { var key = br.ReadString(); if (key != fileType) { Console.WriteLine("Invalid file format, suckah!"); } ReadModels(br, tree); br.Close(); } return true; }
private static bool LoadTile(TreeReference<Model> tree, MapId mapId, TileCoord tileCoord) { var dir = Path.Combine(WorldMap.HeightMapFolder, ((int)mapId).ToString()); if (!Directory.Exists(dir)) return false; var fileName = String.Format("{0}{1}.fub", tileCoord.TileX, tileCoord.TileY); var fullPath = Path.Combine(dir, fileName); if (!File.Exists(fullPath)) return false; return LoadTileModels(tree, fullPath); }
private static bool EnsureGroupLoaded(TreeReference<Model> tree, MapId map, TileCoord tileCoord) { var result = true; var tile = new TileCoord { TileX = tileCoord.TileX, TileY = tileCoord.TileY }; result = EnsureTileLoaded(map, tile, tree); tile.TileX = tileCoord.TileX - 1; result = result && EnsureTileLoaded(map, tile, tree); tile.TileX = tileCoord.TileX + 1; result = result && EnsureTileLoaded(map, tile, tree); tile.TileX = tileCoord.TileX; tile.TileY = tileCoord.TileY - 1; result = result && EnsureTileLoaded(map, tile, tree); tile.TileY = tileCoord.TileY + 1; result = result && EnsureTileLoaded(map, tile, tree); return result; }
private static void ReadBuildings(BinaryReader br, TreeReference<Building> tree) { var numBuildings = br.ReadInt32(); for (var i = 0; i < numBuildings; i++) { var bounds = br.ReadBoundingBox(); var invRot = br.ReadSingle(); var matrix = Matrix.CreateRotationY(((-1.0f*(invRot - 90)))*RadiansPerDegree); var center = br.ReadVector3(); BuildingGroup[] groups; var numGroups = br.ReadInt32(); if (numGroups > 0) { groups = new BuildingGroup[numGroups]; for (var j = 0; j < numGroups; j++) { groups[j] = ReadBuildingGroup(br); } } else { groups = null; } var building = new Building { Bounds = bounds, Center = center, InverseRotation = matrix, BuildingGroups = groups }; tree.Tree.Insert(building); } }
private static bool LoadTileBuildings(TreeReference<Building> tree, string filePath) { using(var file = File.OpenRead(filePath)) using(var br = new BinaryReader(file)) { var key = br.ReadString(); if (key != fileType) { Console.WriteLine(String.Format("{0} has an invalid file format, suckah!", filePath)); } ReadBuildings(br, tree); br.Close(); } return true; }
private static bool LoadTile(TreeReference<Building> tree, MapId mapId, TileCoord tileCoord) { var dir = Path.Combine(WorldMap.HeightMapFolder, ((int)mapId).ToString()); if (!Directory.Exists(dir)) return false; var fileName = TerrainConstants.GetWMOFile(tileCoord.TileX, tileCoord.TileY); var fullPath = Path.Combine(dir, fileName); if (!File.Exists(fullPath)) return false; return LoadTileBuildings(tree, fullPath); }