Exemple #1
0
        public static bool ReadDatabase(string fileName = "")
        {
            bool readStatus = true;

#if true
            string data;;
            if (!string.IsNullOrEmpty(fileName))
            {
                data = File.ReadAllText(USER_STATE_FILE);
            }
            else
            {
                data = File.ReadAllText(USER_STATE_FILE);
            }

            AllUserState = XMLSerialUtil <List <UserState> > .Deserialize(data);
#else
            if (!File.Exists(USER_STATE_FILE))
            {
                StreamWriter writer = new StreamWriter(USER_STATE_FILE);
                writer.Close();
            }
            else
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List <UserState>));
                FileStream    fs         = null;
                try
                {
                    fs           = new FileStream(USER_STATE_FILE, FileMode.Open);
                    AllUserState = (List <UserState>)serializer.Deserialize(fs);
                }
                catch (System.Exception ex)
                {
                    readStatus = false;
                    throw ex;
                }
                finally
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
            }

            if (!File.Exists(DEFAULT_IMPLEMENT))
            {
                StreamWriter writer = new StreamWriter(DEFAULT_IMPLEMENT);
                writer.Close();
            }
            else
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List <UserEvent>));
                FileStream    fs         = null;
                try
                {
                    fs             = new FileStream(DEFAULT_IMPLEMENT, FileMode.Open);
                    DefaultImplemt = (List <UserEvent>)serializer.Deserialize(fs);
                }
                catch (System.Exception ex)
                {
                    readStatus = false;
                    throw ex;
                }
                finally
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
            }
#endif
            return(readStatus);
        }
Exemple #2
0
        public static void ReadTest()
        {
            string data = File.ReadAllText(USER_STATE_FILE);

            AllUserState = XMLSerialUtil <List <UserState> > .Deserialize(data);
        }