Пример #1
0
    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);
        }
    }
Пример #2
0
    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());
    }