public void DispatchReadResult(string[] bundle)
        {
            int    resultCode = Int32.Parse(bundle [1]);
            string message    = bundle[2];

            ReadHistoryResult result = resultCode == 0 ? new ReadHistoryResult(id, isAggregated) : new ReadHistoryResult(id, resultCode, message);

            if (result.IsSucceeded)
            {
                for (int i = 3; i < bundle.Length; i++)
                {
                    string[] setData = bundle [i].Split(new string[] { Connection.SEPARATOR2 }, StringSplitOptions.None);
                    DataSet  set     = new DataSet(new DataType(setData[0]));
                    if (setData.Length > 1)
                    {
                        for (int k = 1; k < setData.Length; k++)
                        {
                            string[]      point = setData[k].Split(new string[] { Connection.SEPARATOR3 }, StringSplitOptions.None);
                            List <string> dp    = new List <string> ();
                            dp.Add(point[0]);
                            dp.Add(point[1]);
                            dp.Add(point[2]);
                            dp.Add(point[3]);

                            DataPoint p = new DataPoint(new DataType(point [0]), dp.ToArray(), Connection.SEPARATOR4);
                            set.AddDataPoint(p);
                        }
                    }
                    result.AddDataSet(set);
                }
            }

            OnReadFinished(result);
        }
Example #2
0
    //--------------------------------------
    // EVENT HANDLERS
    //--------------------------------------

    void Request_OnReadHistoryFinished(SA.Fitness.ReadHistoryResult result)
    {
        Debug.Log("[OnReadHistoryFinished] status: " + result.IsSucceeded);
        if (result.IsSucceeded)
        {
            if (result.IsAggregated)
            {
                int i = 1;
                foreach (SA.Fitness.Bucket bucket in result.Buckets)
                {
                    Debug.Log("Bucket #" + i.ToString() +
                              "\n\t Type: " + bucket.Bucketing.ToString() +
                              "\n\t Start Time: " + bucket.StartTime.ToString() +
                              "\n\t End Time: " + bucket.EndTime.ToString()
                              );

                    int j = 1;
                    foreach (SA.Fitness.DataSet dataSet in bucket.DataSets)
                    {
                        Debug.Log("Data Set #" + j.ToString() +
                                  "\n\t\t Data Type: " + dataSet.DataType.Value
                                  );

                        Debug.Log("Data Points Count: " + dataSet.DataPoints.Count);
                        int k = 1;
                        foreach (SA.Fitness.DataPoint dp in dataSet.DataPoints)
                        {
                            Debug.Log("Data Point #" + k.ToString() +
                                      "\n\t\t\t Data Type: " + dp.DataType.Value +
                                      "\n\t\t\t Start Time: " + dp.StartTime.ToString() +
                                      "\n\t\t\t End Time: " + dp.EndTime.ToString()
                                      );

                            Debug.Log("Fields Count: " + dp.Fields.Count);
                            foreach (KeyValuePair <string, object> pair in dp.Fields)
                            {
                                Debug.Log("\t\t\t\t " + pair.Key + " : " + pair.Value.ToString());
                            }

                            k++;
                        }

                        j++;
                    }
                    i++;
                }
            }
            else
            {
                int j = 1;
                foreach (SA.Fitness.DataSet dataSet in result.DataSets)
                {
                    Debug.Log("Data Set #" + j.ToString() +
                              "\n\t\t Data Type: " + dataSet.DataType.Value
                              );

                    Debug.Log("Data Points Count: " + dataSet.DataPoints.Count);
                    int k = 1;
                    foreach (SA.Fitness.DataPoint dp in dataSet.DataPoints)
                    {
                        Debug.Log("Data Point #" + k.ToString() +
                                  "\n\t\t\t Data Type: " + dp.DataType.Value +
                                  "\n\t\t\t Start Time: " + dp.StartTime.ToString() +
                                  "\n\t\t\t End Time: " + dp.EndTime.ToString()
                                  );

                        Debug.Log("Fields Count: " + dp.Fields.Count);
                        foreach (KeyValuePair <string, object> pair in dp.Fields)
                        {
                            Debug.Log("\t\t\t\t " + pair.Key + " : " + pair.Value.ToString());
                        }

                        k++;
                    }

                    j++;
                }
            }
        }
    }