Ejemplo n.º 1
0
    public static bool WriteToFile(ref MedicalAppData mediData, string filename)
    {
        bool         succeeded = false;
        StreamWriter writer    = null;

        try
        {
            XmlSerializer serializer = new XmlSerializer(typeof(MedicalAppData));
            writer = new StreamWriter(filename);
            serializer.Serialize(writer, mediData);
            succeeded = true;
        }
        catch (Exception e)
        {
            Debug.Log("Exception writing XML: " + e.Message);
            succeeded = false;
        }
        finally
        {
            if (writer != null)
            {
                writer.Close();
            }
        }
        return(succeeded);
    }
Ejemplo n.º 2
0
    public static bool ReadFromFile(string filename, out MedicalAppData result)
    {
        bool succeeded = false;

        result = null;
        StreamReader reader = null;

        try
        {
            XmlSerializer serializer = new XmlSerializer(typeof(MedicalAppData));
            reader    = new StreamReader(filename);
            result    = (MedicalAppData)serializer.Deserialize(reader);
            succeeded = true;
        }
        catch (Exception e)
        {
            Debug.Log("Exception reading XML: " + e.Message);
            succeeded = false;
        }
        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
        }
        return(succeeded);
    }
Ejemplo n.º 3
0
    //protected string scenarioToLoad;
    //protected Scenario scenarioToLoad;

    void Awake()                                                             //use awake so by Start in other classes XMLData class will be already filled in
    {
        bool success = MedicalAppData.ReadFromFile("read.xml", out appData); //try reading in the xml

        Debug.Log("Reading file succeeded? " + success);
        XMLData.appData = this.appData; //copy the xml data to the static XMLData class so it's accesible from every script. You're welcome.
        if (XMLData.appData.mScenarios[0] != null)
        {
            XMLData.scenario = XMLData.appData.mScenarios[0]; //get first scenario and set it as default
        }
        else
        {
            Debug.Log("Problem loading scenario. Are you sure there is a given scenario in your XML?");
        }

        //StartScenario(scenarioToLoad);
    }