public void BeginDownloadingDataForType(BusDataType dataType, System.Action <BusDataType> dataReadyCallback)
    {
        int dataIndex = (int)dataType;

        if (dataIndex < this.busTrackerItemDataInfo.Length)
        {
            if (!this.usePredownloadedFiles)
            {
                this.StartCoroutine(this.co_DownloadData(this.busTrackerItemDataInfo[dataIndex].dataUrl, delegate(string dataString) {
                    this.CreateParserForData(dataType, this.busTrackerItemDataInfo[dataIndex].dataUrl, dataString, dataReadyCallback);
                }));
            }
            else
            {
                if (dataIndex < this.predownloadedDataSet.AllDataArrayByType().Count&& this.predownloadedDataSet.AllDataArrayByType()[dataIndex].Count
                    > 0)
                {
                    string dataText       = this.predownloadedDataSet.AllDataArrayByType()[dataIndex][0].text;
                    string dataInfoString = predownloadedDataSet.AllDataArrayByType()[dataIndex][0].name;

                    this.CreateParserForData(dataType, dataInfoString, dataText, dataReadyCallback);
                }
                else
                {
                    Debug.LogError("Couldn't load predownloaded data, data not populated for type: " + dataType);
                }
            }
        }
    }
    private void CreateParserForData(BusDataType dataType, string infoString, string dataString, System.Action <BusDataType> dataReadyCallback)
    {
        XMLQuickParser xmlParsing = new XMLQuickParser(infoString, dataString);

        if (dataType == BusDataType.Stops)
        {
            this.LoadDataIntoObjects <BusDataStop>(dataType, xmlParsing, "stops", this.busStops, dataReadyCallback);

            Debug.Log("Stops, lowest id: " + BusDataStop._lowestIdValue + " highest id: " + BusDataStop._highestIdValue);
        }
        else if (dataType == BusDataType.RouteStops)
        {
            this.LoadDataIntoObjects <BusRouteStopItemData>(dataType, xmlParsing, "routestops", this.busRouteStops, dataReadyCallback);
        }
        else
        {
            Debug.LogError("No loading algorithm specified for dataType: " + dataType);
        }
    }
Beispiel #3
0
    private IEnumerator co_LoadCompletedForDataType(BusDataType dataType)
    {
        if (dataType == BusDataType.Stops)
        {
            foreach (BusDataStop busStop in this.busRouteDataController.busStops)
            {
                // Show all bus stops
//				this.mapIndicatorController.AddIndicatorAtLatLong(busStop.latitudeLongitude);
            }
        }
        else if (dataType == BusDataType.RouteStops)
        {
            Debug.Log("-------- this.busRouteDataController.busRouteStops.Count: " + this.busRouteDataController.busRouteStops.Count);

//			foreach (BusRouteStopItemData routeStop in this.busRouteDataController.busRouteStops) {
//				if (routeStop.routeNumber == 1) {
//					BusDataStop busStop = this.busRouteDataController.BusStopForStopId(routeStop.stopId);
//
//					this.mapIndicatorController.AddIndicatorAtLatLong(busStop.latitudeLongitude);
//
//					yield return null;
//				}
//			}

            int routeId = 3;

            for (int i = 0; i < BusRouteStopItemData.NumberOfRouteStopItemsForRoute(routeId); i++)
            {
                BusRouteStopItemData routeStopItem = BusRouteStopItemData.RouteStopItemForRouteAtIndex(routeId, i);

                BusDataStop busStop = this.busRouteDataController.BusStopForStopId(routeStopItem.stopId);

                this.mapIndicatorController.AddIndicatorAtLatLong(busStop.latitudeLongitude, 1);

                Debug.Log("Adding routeStopItem sort id: " + routeStopItem.sortOrder + " stopIds are equal: " + (routeStopItem.stopId == busStop.id).ToString());

//				yield return new WaitForSeconds(0.25f);
            }
        }

        yield return(null);
    }
    private void LoadDataIntoObjects <T>(BusDataType busDataType, XMLQuickParser xmlData, string rootNodeName, List <T> dataArray, System.Action <BusDataType> dataReadyCallback) where T : BusDataBaseObject
    {
        int dataLength = 0;

        try {
            BusDataBaseObject dataObj = null;

            foreach (XmlNode node in xmlData.xmlDoc)
            {
                if (node.Name == rootNodeName)
                {
                    foreach (XmlNode stopNode in node)
                    {
                        dataLength++;

                        // Hmm... need to look up this error
//						dataObj = new T(); // Cannot create an instance of the variable type `T' because it does not have the new() constraint

                        if (typeof(T) == typeof(BusDataStop))
                        {
                            dataObj = new BusDataStop();
                        }
                        else if (typeof(T) == typeof(BusRouteStopItemData))
                        {
                            dataObj = new BusRouteStopItemData();
                        }
                        else
                        {
                            Debug.LogWarning("No class defined for T: " + typeof(T).ToString());
                            dataObj = null;
                        }

                        foreach (XmlNode stopNodeElement in stopNode)
                        {
                            dataObj.ParseAndLoadDataElement(stopNodeElement.Name, stopNodeElement.InnerText);
                        }

                        dataObj.ParseAndLoadFinishedForObject();

                        dataArray.Add((T)dataObj);
                    }
                }
            }

            if (dataObj != null)
            {
                dataObj.ParseAndLoadFinishedForClass();
            }
            else
            {
                Debug.LogError("dataObj null on ParseAndLoadFinishedForClass");
            }

            if (dataReadyCallback != null)
            {
                dataReadyCallback(busDataType);
            }
        }
        catch (System.Exception e) {
            Debug.LogError("Failed to parse data for type: " + BusDataType.Stops + " error: " + e.ToString());
        }

        Debug.Log("Loaded data count: " + dataLength + " for type: " + typeof(T).ToString());
    }
Beispiel #5
0
    //
    // XML related
    //

    private void LoadCompletedForDataType(BusDataType dataType)
    {
        this.StartCoroutine(this.co_LoadCompletedForDataType(dataType));
    }