Exemplo n.º 1
0
 private void WriteToFile(bml bmlObj, string filename)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(bml));
     XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
     // Add two namespaces with prefixes.
     ns.Add("","http://www.bml-initiative.org/bml/bml-1.0");
     // Create an XmlTextWriter using a FileStream.
     Stream fs = new FileStream(filename, FileMode.Create);
     XmlWriter writer = new XmlTextWriter(fs, new UTF8Encoding());
     // Serialize using the XmlTextWriter.
     serializer.Serialize(writer, bmlObj, ns);
     writer.Close();
 }
Exemplo n.º 2
0
        public Behavior BmlToBehavior(bml b)
        {
            if (b == null) return Behavior.NullBehavior;

            //List<BehaviorNode> required = new List<BehaviorNode>();
            List<Constraint.Constraint> constraints = new List<Constraint.Constraint>();
            List<BehaviorNode> nodes = new List<BehaviorNode>();
			if (b.required!=null) {
				foreach(BehaviorBlock reqBlock in b.required) {
					List<BehaviorNodes.Action> reqActions = BmlNodeToActionNode(reqBlock);
					BehaviorNodes.Required required = new BehaviorNodes.Required();
		            foreach (BehaviorNodes.Action a in reqActions)
		            {
		                a.RequiredAction = true;
		                required.Actions.Add(a);
		            }
					nodes.Add(required);
				}
			}
			
			List<BehaviorNodes.Action> actions = BmlNodeToActionNode(b);
	            foreach (BehaviorNodes.Action a in actions)
	            {
	                a.RequiredAction = false;
	                nodes.Add(a);
	            }
			
			if (b.constraint!=null) {
	            foreach (GBML.Constraint c in b.constraint)
	            {
	                Constraint.Constraint gmbconstraint = BmlConstraintToGMBConstraint(c);
	                if (gmbconstraint != null) constraints.Add(gmbconstraint);
	            }
			}

            if (nodes.Count > 0)
            {
                if (b.id != null && b.id != "")
                {
                    if (b.composition != null && b.composition != "")
                    {
                        if (Environment.Instance.Characters.ContainsKey(b.character)) return new Behavior(b.id, Environment.Instance.Characters[b.character], nodes, Behavior.CompositionTypeFromString(b.composition), constraints);
                        else return new Behavior(b.id, nodes, Behavior.CompositionTypeFromString(b.composition), constraints);
                    }
                    else
                    {
                        if (Environment.Instance.Characters.ContainsKey(b.character)) return new Behavior(b.id, Environment.Instance.Characters[b.character], nodes, constraints);
                        else return new Behavior(b.id, nodes, constraints);
                    }
                }
                else
                {
                    if (b.composition != null && b.composition != "")
                    {
                        if (Environment.Instance.Characters.ContainsKey(b.character)) return new Behavior(Environment.Instance.Characters[b.character], nodes, Behavior.CompositionTypeFromString(b.composition), constraints);
                        else return new Behavior(nodes, Behavior.CompositionTypeFromString(b.composition), constraints);
                    }
                    else
                    {
                        if (Environment.Instance.Characters.ContainsKey(b.character)) return new Behavior(Environment.Instance.Characters[b.character], nodes, constraints);
                        else return new Behavior(nodes, constraints);
                    }
                }
            }
            else return Behavior.NullBehavior;
        }
Exemplo n.º 3
0
 public static string WriteToText(bml bmlObj)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(bml));
     /* Create a StreamWriter to write with. First create a FileStream
        object, and create the StreamWriter specifying an Encoding to use. */
     StringWriter writer = new StringWriter();
     // Serialize using the XmlTextWriter.
     serializer.Serialize(writer, bmlObj);
     writer.Close();
     return writer.ToString();
 }