void LoadFromText() { XmlNode _node = DataMakerXmlUtils.StringToXmlNode(source.text); if (_node == null) { Debug.LogError(DataMakerXmlUtils.lastError); Fsm.EventData.StringData = DataMakerXmlUtils.lastError; Fsm.Event(errorEvent); return; } if (!storeReference.IsNone) { DataMakerXmlUtils.XmlStoreNode(_node, storeReference.Value); } GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), go, reference.Value, false) as DataMakerXmlProxy; if (proxy != null) { proxy.InjectXmlNode(_node); } if (!xmlString.IsNone) { xmlString.Value = source.text; } Finish(); }
public override void OnEnter() { GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), go, reference.Value, false) as DataMakerXmlProxy; if (proxy != null) { if (!storeReference.IsNone) { proxy.InjectXmlNode(DataMakerXmlUtils.XmlRetrieveNode(storeReference.Value)); } else if (!xmlSource.IsNone) { proxy.InjectXmlString(xmlSource.Value); } } else { Fsm.Event(errorEvent); } Finish(); }
void ConvertFromJsonString() { string _jsonSource = jsonSource.Value; /* fail to check if json root is a list of a single object... odd * // check if json has unique root or not. * try{ * * System.Object _json = (System.Object)JsonConvert.DeserializeObject(_jsonSource, typeof(System.Object)); * }catch(Exception e) * { * Debug.LogError(e.Message); * Fsm.EventData.StringData = e.Message; * Fsm.Event(errorEvent); * return; * } * * bool jsonHasRoot = _jsonSource.Length==1; * * string ForcedRootName = string.IsNullOrEmpty(rootElementName.Value)?"root":rootElementName.Value; * */ XmlDocument _document = new XmlDocument(); try{ //if(!jsonHasRoot || !string.IsNullOrEmpty(rootElementName.Value) || forceRootElementName.Value) if (!string.IsNullOrEmpty(rootElementName.Value)) { _document = JsonConvert.DeserializeXmlNode(_jsonSource, rootElementName.Value); } else { _document = JsonConvert.DeserializeXmlNode(_jsonSource); } }catch (Exception e) { Debug.LogError(e.Message); Fsm.EventData.StringData = e.Message; Fsm.Event(errorEvent); return; } if (_document == null) { Debug.LogError(DataMakerXmlUtils.lastError); Fsm.EventData.StringData = DataMakerXmlUtils.lastError; Fsm.Event(errorEvent); return; } if (!storeReference.IsNone) { if (_document.DocumentElement.GetType() == typeof(XmlNodeList)) { //DataMakerXmlUtils.XmlStoreNodeList(_document.DocumentElement as XmlNodeList,storeReference.Value); } else { DataMakerXmlUtils.XmlStoreNode(_document.DocumentElement as XmlNode, storeReference.Value); } } GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), go, reference.Value, false) as DataMakerXmlProxy; if (proxy != null) { if (_document.DocumentElement.GetType() == typeof(XmlNodeList)) { // proxy.InjectXmlNodeList(_document.DocumentElement as XmlNode); } else { proxy.InjectXmlNode(_document.DocumentElement as XmlNode); } } proxy.RefreshStringVersion(); if (!xmlString.IsNone) { xmlString.Value = proxy.content; } Finish(); }
void ConvertFromCsvString() { CsvData _data; if (!delimiter.IsNone) { _data = CsvReader.LoadFromString(csvSource.Value, hasHeader.Value, delimiter.Value [0]); } else { _data = CsvReader.LoadFromString(csvSource.Value, hasHeader.Value); } XmlDocument _document = new XmlDocument(); XmlNode _root = _document.AppendChild(_document.CreateElement("Root")); try{ if (_data.HasHeader) { _csvHeader = _data.HeaderKeys.ToArray(); } foreach (List <string> _row in _data.Data) { XmlNode _xmlRowNode = _document.CreateElement("Record"); for (int i = 0; i < _row.Count; i++) { XmlNode _Item = _document.CreateElement(_data.HasHeader?_csvHeader[i]:"Field"); _Item.InnerText = _row[i]; _xmlRowNode.AppendChild(_Item); } _root.AppendChild(_xmlRowNode); } }catch (Exception e) { Debug.LogError(e.Message); Fsm.EventData.StringData = e.Message; Fsm.Event(errorEvent); return; } if (_document == null) { Debug.LogError(DataMakerXmlUtils.lastError); Fsm.EventData.StringData = DataMakerXmlUtils.lastError; Fsm.Event(errorEvent); return; } if (!storeReference.IsNone) { if (_document.DocumentElement.GetType() == typeof(XmlNodeList)) { // DataMakerXmlUtils.XmlStoreNodeList(_document.DocumentElement as XmlNodeList,storeReference.Value); } else { DataMakerXmlUtils.XmlStoreNode(_document.DocumentElement as XmlNode, storeReference.Value); } } GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); if (go != null) { DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), go, reference.Value, false) as DataMakerXmlProxy; if (proxy != null) { if (_document.DocumentElement.GetType() == typeof(XmlNodeList)) { // proxy.InjectXmlNodeList(_document.DocumentElement as XmlNode); } else { proxy.InjectXmlNode(_document.DocumentElement as XmlNode); } } proxy.RefreshStringVersion(); } if (!xmlString.IsNone) { xmlString.Value = DataMakerXmlUtils.XmlNodeToString(_document.DocumentElement as XmlNode); } Finish(); }