protected override void Init(Workspace workspace) { mFuncMap.Clear(); mVariableNames.Reset(); List <VariableModel> variables = workspace.GetAllVariables(); if (variables.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (VariableModel variable in variables) { string type = variable.Type; if (string.IsNullOrEmpty(type)) { type = "var"; } else { foreach (string[] strs in Define.DataTypeDB.Values) { if (!string.IsNullOrEmpty(strs.FirstOrDefault(s => s.ToLower().Equals(type.ToLower())))) { type = strs[0]; } } } sb.Append(type + " " + mVariableNames.GetName(variable.Name, Define.VARIABLE_CATEGORY_NAME) + ";\n"); } mFuncMap["variables"] = new KeyValuePair <string, string>(null, sb.ToString()); } }
/// <summary> /// Encode a block tree as XML. /// </summary> /// <param name="workspace"> The workspace containing blocks.</param> /// <param name="optNoId"> Ture if the encoder should skip the block ids.</param> /// <returns> XML document.</returns> public static XmlNode WorkspaceToDom(Workspace workspace, bool optNoId = false) { var xml = XmlUtil.CreateDom("xml"); xml.AppendChild(VariablesToDom(workspace.GetAllVariables())); var blocks = workspace.GetTopBlocks(true); foreach (var block in blocks) { xml.AppendChild(BlockToDomWithXY(block, optNoId)); } return(xml); }