void GetTimestreamsCallback(string xml, string extra, TimeStreamCallbackType3 callback) { // string txtData = www.text; //.Replace("<?xml version=\"1.0\"?>",""); //ArrayList timestreams = new ArrayList(); XMLParser parser = new XMLParser(); XMLNode node = parser.Parse(xml); //www.text); // XMLNodeList arr = node.GetNodeList("map>0>nodes>0>n"); XMLNodeList arr = node.GetNodeList("methodResponse>0>params>0>param>0>value>0>array>0>data>0>value"); for (int i=0; i<arr.length; i++) { XMLNode myNode = node.GetNode( "methodResponse>0>params>0>param>0>value>0>array>0>data>0>value>"+i.ToString() ); //Debug.Log(myNode.GetType()); //Debug.Log(myNode.GetValue("struct>0>member>0>name")); //XMLNodeList arr2 = myNode.GetNodeList("struct"); XMLNode myNode2 = myNode.GetNode("struct>0"); // Debug.Log("struct "+myNode2.ToString()); XMLNodeList arr2 = myNode2.GetNodeList("member"); string id = ""; string myName = ""; string headId = ""; string metadataId = ""; string startTime = ""; string endTime = ""; for(int i2=0; i2<arr2.length; i2++) { XMLNode myNode3 = myNode2.GetNode("member>"+i2.ToString()); // Debug.Log("member "+myNode3.ToString()); XMLNode myNode4 = myNode3.GetNode("name>0"); // myNode2 = myNode2.GetNode("member>0"); // Debug.Log("name "+myNode4.ToString()); // Debug.Log("_text="+myNode4.GetValue("_text")); string key = myNode4.GetValue("_text"); myNode4 = myNode3.GetNode("value>0"); // Debug.Log("value "+myNode4.ToString()); myNode4 = myNode4.GetNode("string>0"); // Debug.Log("string "+myNode4.ToString()); // Debug.Log("_text="+myNode4.GetValue("_text")); string val = myNode4.GetValue("_text"); /* switch (key) { case "timestream_id": timestream.id = val; break; case "name": timestream.name = val; break; case "head_id": timestream.headId = val; break; case "metadata_id": timestream.metadataId = val; break; case "starttime": timestream.startTime = val; break; case "endtime": timestream.endTime = val; break; } */ switch (key) { case "timestream_id": id = val; break; case "name": myName = val; break; case "head_id": headId = val; break; case "metadata_id": metadataId = val; break; case "starttime": startTime = val; break; case "endtime": endTime = val; break; } //streams.Add( // Debug.Log("_text "+myNode3.ToString()); } Timestream.Create(id, myName, headId, metadataId, startTime, endTime); //new Timestream(); //timestreams.Add(timestream); // StartCoroutine(tss.GetTimestreamMetadata(timestream.id, timestream.id, GetTimestreamMetadataCallback, GetTimestreamsErrorCallback)); /* for (int i2=0; i2<arr2.length; i2++) { XMLNode myNode2 = myNode.GetNode("struct>"+i2.ToString()); Debug.Log(myNode2.ToString()); //Debug.Log(myNode2.GetValue("@name").ToString()); } */ } if (callback != null) callback(Timestream.GetList(), extra); }
void GetTimestreamMetadataCallback(string xml, string extra, TimeStreamCallbackType3 callback) { // string txtData = www.text; //.Replace("<?xml version=\"1.0\"?>",""); XMLParser parser = new XMLParser(); XMLNode node = parser.Parse(xml); TimestreamMetadata metadata = new TimestreamMetadata(); Timestream timestream = Timestream.FindFromId(extra); //timestreams); timestream.metadata = metadata; XMLNodeList arr = node.GetNodeList("methodResponse>0>params>0>param>0>value>0>struct>0>member"); for (int i=0; i<arr.length; i++) { XMLNode myNode = node.GetNode( "methodResponse>0>params>0>param>0>value>0>struct>0>member>"+i.ToString() ); XMLNode myNode2 = myNode.GetNode("name>0"); string name = myNode2.GetValue("_text"); // Debug.Log("name "+myNode2.ToString()); myNode2 = myNode.GetNode("value>0"); // Debug.Log("value "+myNode.ToString()); XMLNode myNode3 = myNode2.GetNode("string>0"); // Debug.Log("string "+myNode3.ToString()); // Debug.Log("_text="+myNode3.GetValue("_text")); string val = myNode3.GetValue("_text"); switch (name) { case "metadata_id": metadata.id = val; SaveXML(xml, "metadata", timestream.id); break; case "tablename": metadata.tableName = val; break; case "measurement_type": metadata.measurementType = val; break; case "first_record": metadata.firstRecord = val; break; case "unit": metadata.unit = val; break; } } if (callback != null) callback(metadata, extra); }
void GetTimestreamDataCallback(string xml, string extra, TimeStreamCallbackType3 callback) { Debug.Log("getTimestreamDataCallback"); // string txtData = www.text; //.Replace("<?xml version=\"1.0\"?>",""); XMLParser parser = new XMLParser(); XMLNode node = parser.Parse(xml); //timestreamDataList.Clear(); Timestream ts = Timestream.FindFromId(extra); //timestreams); XMLNodeList arr = node.GetNodeList("methodResponse>0>params>0>param>0>value>0>array>0>data>0>value"); for (int i=0; i<arr.length; i++) { XMLNode myNode = node.GetNode( "methodResponse>0>params>0>param>0>value>0>array>0>data>0>value>"+i.ToString() ); XMLNode myNode2 = myNode.GetNode("struct>0"); // Debug.Log("struct "+myNode2.ToString()); TimestreamData timestreamData = new TimestreamData(ts); //ts.timestreamDataList.Add(timestreamData); // timestreamDataList.Add(timestreamData); XMLNodeList arr2 = myNode2.GetNodeList("member"); for(int i2=0; i2<arr2.length; i2++) { // Debug.Log("i2="+i2); XMLNode myNode3 = myNode2.GetNode("member>"+i2.ToString()); // Debug.Log("member "+myNode3.ToString()); XMLNode myNode4 = myNode3.GetNode("name>0"); // myNode2 = myNode2.GetNode("member>0"); // Debug.Log("name "+myNode4.ToString()); // Debug.Log("_text="+myNode4.GetValue("_text")); string name = myNode4.GetValue("_text"); myNode4 = myNode3.GetNode("value>0"); // Debug.Log("value "+myNode4.ToString()); myNode4 = myNode4.GetNode("string>0"); // Debug.Log("string "+myNode4.ToString()); // Debug.Log("_text="+myNode4.GetValue("_text")); string val = myNode4.GetValue("_text"); switch (name) { case "id": timestreamData.id = val; break; case "value": timestreamData.value = val; string[] parts = val.Split('/'); timestreamData.filename = parts[parts.Length-1]; break; case "valid_time": timestreamData.validTime = val; break; case "transaction_time": timestreamData.transactionTime = val; break; } //streams.Add( // Debug.Log("_text "+myNode3.ToString()); } } //ts.timestreamDataList.Sort(); /* foreach(TimestreamData tsd in timestreamDataList) { Debug.Log("Sorted: id:"+tsd.id+" Value:"+tsd.value+" Valid:"+tsd.validTime+" Transaction:"+tsd.transactionTime); } */ // Timestream ts = Timestream.FindFromId(extra, timestreams); // if (ts.metadata.unit == "image/png") StartCoroutine(GetThumbnails(ts)); // if (extra == "true") StartCoroutine(GetThumbnails()); if (callback != null) callback(ts, extra); }
public IEnumerator GetTimestreams(string extra, TimeStreamCallbackType3 callback, TimeStreamCallbackType errorCallback) { string xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"+ "<methodCall>"+ "<methodName>timestreams.ext_get_timestreams</methodName>"+ "<params>"+ "<param><value><string>"+username+"</string></value></param>"+ "<param><value><string>"+password+"</string></value></param>"+ "</params>"+ "</methodCall>"; WWW www = new WWW("http://"+project+server+"/"+file, System.Text.Encoding.UTF8.GetBytes(xml)); yield return www; if (www.error != null) { Debug.Log("Error: "+www.error); GetTimestreamsErrorCallback(www.error, errorCallback); //if (errorCallback != null) errorCallback(www.error); } else { Debug.Log(www.text); GetTimestreamsCallback(www.text, extra, callback); // if (callback != null) callback(www.text, extra); } yield return null; }
public IEnumerator GetTimestreamMetadata(string id, string extra, TimeStreamCallbackType3 callback, TimeStreamCallbackType errorCallback) { string path = Application.persistentDataPath+"/metadata/"+id+".xml"; Debug.Log(path); if (File.Exists(path)) { Debug.Log("file exist "+path); WWW www2 = new WWW("file://"+path); yield return www2; GetTimestreamMetadataCallback(www2.text, extra, callback); } else { string xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"+ "<methodCall>"+ "<methodName>timestreams.ext_get_timestream_metadata</methodName>"+ "<params>"+ "<param><value><string>"+username+"</string></value></param>"+ "<param><value><string>"+password+"</string></value></param>"+ "<param><value><string>"+id+"</string></value></param>"+ "</params>"+ "</methodCall>"; Debug.Log("getting metadata: "+xml); WWW www = new WWW("http://"+project+server+"/"+file, System.Text.Encoding.UTF8.GetBytes(xml)); yield return www; if (www.error != null) { Debug.Log("Error: "+www.error); if (errorCallback != null) errorCallback(www.error); } else { Debug.Log(www.text); GetTimestreamMetadataCallback(www.text, extra, callback); // if (callback != null) callback(www.text, extra); } } yield return null; }
public IEnumerator GetTimestreamData(string id, string timeLastAsked, string maxReadings, string extra, TimeStreamCallbackType3 callback, TimeStreamCallbackType errorCallback) { Debug.Log("GetTimestreamData()"); if (timeLastAsked == "") { timeLastAsked = "0"; TimestreamData timestreamData; Timestream timestream = Timestream.FindFromId(id); if (timestream.timestreamDataList.Count > 0) { System.DateTime dt; timestreamData = (TimestreamData)timestream.timestreamDataList[timestream.timestreamDataList.Count-1]; if (System.DateTime.TryParse(timestreamData.validTime.ToString(), out dt)) { System.TimeSpan timespan = (dt - new System.DateTime(1970,1,1,0,0,0)); timeLastAsked = timespan.TotalSeconds.ToString(); } } } string xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"+ "<methodCall>"+ "<methodName>timestreams.ext_get_timestream_data</methodName>"+ "<params>"+ "<param><value><string>"+username+"</string></value></param>"+ "<param><value><string>"+password+"</string></value></param>"+ "<param><value><string>"+id+"</string></value></param>"+ "<param><value><string>"+timeLastAsked+"</string></value></param>"+ "<param><value><string>"+maxReadings+"</string></value></param>"+ "<param><value><string>ASC</string></value></param>"+ "</params>"+ "</methodCall>"; WWW www = new WWW("http://"+project+server+"/"+file, System.Text.Encoding.UTF8.GetBytes(xml)); yield return www; if (www.error != null) { Debug.Log("Error: "+www.error); GetTimestreamDataErrorCallback(www.error, errorCallback); //if (errorCallback != null) errorCallback(www.error); } else { Debug.Log(www.text); if (www.text.Contains("<int>0</int>") || www.text.Contains("faultCode")) { GetTimestreamDataErrorCallback("platform faultCode or other", errorCallback); } else { GetTimestreamDataCallback(www.text, extra, callback); } //if (callback != null) callback(www.text, extra); } yield return null; }