private void ExportParameters(BsonSerializer file, Attachments.Attachment attachment) { Attachments.Event evt = attachment as Attachments.Event; if (evt == null || evt.Pars.Count == 0) { return; } file.WriteStartElement("pars"); for (int i = 0; i < evt.Pars.Count; ++i) { file.WriteStartElement("par"); file.WriteString(evt.Pars[i].Name); file.WriteString(Plugin.GetNativeTypeName(evt.Pars[i].Type)); file.WriteString(evt.Pars[i].DefaultValue); if (!string.IsNullOrEmpty(evt.Pars[i].EventParam)) { file.WriteString(evt.Pars[i].EventParam); } file.WriteEndElement(); } file.WriteEndElement(); }
/// <summary> /// Exports a node to the given file. /// </summary> /// <param name="file">The file we want to export to.</param> /// <param name="namspace">The namespace of the behaviour we are currently exporting.</param> /// <param name="behavior">The behaviour we are currently exporting.</param> /// <param name="parentName">The name of the variable of the node which is the parent of this node.</param> /// <param name="node">The node we want to export.</param> /// <param name="indentDepth">The indent of the ocde we are exporting.</param> /// <param name="nodeID">The current id used for generating the variables for the nodes.</param> protected void ExportNode(BsonSerializer file, BehaviorNode behavior, Node parent, Node node) { if (!node.Enable) { return; } file.WriteStartElement("node"); file.WriteString(node.ExportClass); file.WriteString(node.Version.ToString()); file.WriteString(node.Id.ToString()); //// we have to handle a referenced behaviour differently //if (node is ReferencedBehaviorNode) //{ // // generate the namespace and name of the behaviour we are referencing // string refRelativeFilename = behavior.MakeRelative(((ReferencedBehaviorNode)node).ReferenceFilename); // string refBehaviorName = Path.GetFileNameWithoutExtension(((ReferencedBehaviorNode)node).ReferenceFilename.Replace(" ", string.Empty)); // file.WriteStartElement("property"); // file.WriteAttributeString("referencefilename", refBehaviorName); // file.WriteEndElement(); //} //else { // export the properties this.ExportProperties(file, node); this.ExportParameters(file, node); this.ExportAttachments(file, node); // add the node to its parent //file.Write(string.Format("{0}\t{1}.AddChild({1}.GetConnector(\"{2}\"), {3});\r\n", indent, parentName, node.ParentConnector.Identifier, nodeName)); if (!(node is ReferencedBehavior)) { // export the child nodes foreach (Node child in node.Children) { this.ExportNode(file, behavior, node, child); } } } file.WriteEndElement(); }
static private void WriteParString(BsonSerializer file, string valueName, ParInfo par) { string parStr = par.DefaultValue; //file.WriteAttribute(valueName, parStr); file.WriteString(parStr); }
protected void ExportAttachments(BsonSerializer file, Node node) { //int localVars = ReferencedBehaviorLocalVars(node); int localVars = 0; if (node.Attachments.Count > 0 || localVars > 0) { file.WriteStartElement("attachments"); //this.ExportReferencedBehaviorLocalVars(node, file); foreach (Attachments.Attachment a in node.Attachments) { if (!a.Enable) { continue; } file.WriteStartElement("attachment"); Type type = a.GetType(); file.WriteString(a.ExportClass); file.WriteString(a.Id.ToString()); file.WriteBool(a.IsPrecondition); bool bIsEffector = a.IsEffector; if (a.IsTransition) { bIsEffector = false; } file.WriteBool(bIsEffector); file.WriteBool(a.IsTransition); this.ExportProperties(file, a); //this.ExportEventLocalVars(a, file); file.WriteEndElement(); } file.WriteEndElement(); } }
private void ExportPar(BsonSerializer file, ParInfo par, bool bExportValue) { file.WriteStartElement("par"); file.WriteString(par.BasicName); file.WriteString(par.NativeType); if (bExportValue) { file.WriteString(par.DefaultValue); } else { file.WriteString(""); } file.WriteEndElement(); }
/// <summary> /// Exports a behaviour to the given file. /// </summary> /// <param name="file">The file we want to export to.</param> /// <param name="behavior">The behaviour we want to export.</param> protected void ExportBehavior(BsonSerializer file, BehaviorNode behavior) { file.WriteComment("EXPORTED BY TOOL, DON'T MODIFY IT!"); file.WriteComment("Source File: " + behavior.MakeRelative(behavior.FileManager.Filename)); file.WriteStartElement("behavior"); Behavior b = behavior as Behavior; Debug.Check(b != null); Debug.Check(b.Id == -1); //'\\' ->'/' string behaviorName = b.MakeRelative(b.Filename); behaviorName = behaviorName.Replace('\\', '/'); int pos = behaviorName.IndexOf(".xml"); if (pos != -1) { behaviorName = behaviorName.Remove(pos); } file.WriteString(behaviorName); file.WriteString(b.AgentType.AgentTypeName); file.WriteString(b.Version.ToString()); this.ExportProperties(file, b); this.ExportParameters(file, (Node)behavior); this.ExportAttachments(file, b); // export the children foreach (Node child in ((Node)behavior).Children) { this.ExportNode(file, behavior, (Node)behavior, child); } file.WriteEndElement(); }
/// <summary> /// Exports a node to the given file. /// </summary> /// <param name="file">The file we want to export to.</param> /// <param name="behavior">The behaviour we are currently exporting.</param> /// <param name="node">The node we want to export.</param> protected void ExportNode(BsonSerializer file, BehaviorNode behavior, Node node) { if (!node.Enable) { return; } file.WriteStartElement("node"); file.WriteString(node.ExportClass); file.WriteString(node.Id.ToString()); { // export the properties this.ExportProperties(file, node); this.ExportAttachments(file, node); if (!node.IsFSM && !(node is ReferencedBehavior)) { // export the child nodes foreach (Node child in node.Children) { if (!node.GetConnector(child).IsAsChild) { file.WriteStartElement("custom"); this.ExportNode(file, behavior, child); file.WriteEndElement(); } else { this.ExportNode(file, behavior, child); } } } } file.WriteEndElement(); }
private void ExportParameters(BsonSerializer file, Node node) { if (node.Pars.Count == 0) { return; } file.WriteStartElement("pars"); for (int i = 0; i < node.Pars.Count; ++i) { string parType = Plugin.GetNativeTypeName(node.Pars[i].Type); file.WriteStartElement("par"); file.WriteString(node.Pars[i].Name); file.WriteString(parType); file.WriteString(node.Pars[i].DefaultValue); file.WriteEndElement(); } file.WriteEndElement(); }
protected void ExportAttachments(BsonSerializer file, Node node) { if (node.Attachments.Count > 0) { file.WriteStartElement("attachments"); foreach (Attachments.Attachment a in node.Attachments) { file.WriteStartElement("attachment"); Type type = a.GetType(); file.WriteString(a.ExportClass); file.WriteString(a.Id.ToString()); this.ExportProperties(file, a); this.ExportParameters(file, a); file.WriteEndElement(); } file.WriteEndElement(); } }
/// <summary> /// Exports a behaviour to the given file. /// </summary> /// <param name="file">The file we want to export to.</param> /// <param name="behavior">The behaviour we want to export.</param> protected void ExportBehavior(BsonSerializer file, BehaviorNode behavior) { if (behavior.FileManager == null) { return; } file.WriteComment("EXPORTED BY TOOL, DON'T MODIFY IT!"); file.WriteComment("Source File: " + behavior.MakeRelative(behavior.FileManager.Filename)); file.WriteStartElement("behavior"); Behavior b = behavior as Behavior; Debug.Check(b != null); Debug.Check(b.Id == -1); //'\\' ->'/' string behaviorName = b.MakeRelative(b.Filename); behaviorName = behaviorName.Replace('\\', '/'); int pos = behaviorName.IndexOf(".xml"); if (pos != -1) { behaviorName = behaviorName.Remove(pos); } file.WriteString(behaviorName); file.WriteString(b.AgentType.AgentTypeName); file.WriteBool(b.IsFSM); file.WriteString(b.Version.ToString()); this.ExportProperties(file, b); this.ExportPars(file, b); if (!b.IsFSM) { this.ExportAttachments(file, b); } if (b.IsFSM) { file.WriteStartElement("node"); file.WriteString("FSM"); file.WriteString("-1"); file.WriteStartElement("properties"); file.WriteAttributeString("initialid", behavior.InitialStateId.ToString()); file.WriteEndElement(); foreach (Node child in ((Node)behavior).FSMNodes) { this.ExportNode(file, behavior, child); } file.WriteEndElement(); } else { // export the children foreach (Node child in ((Node)behavior).Children) { this.ExportNode(file, behavior, child); } } file.WriteEndElement(); }