Пример #1
0
        public static bool SaveAsDatabase(string stateFileName, string defaultImplementFile)
        {
            bool writeStatus = true;

#if true
            string data = XMLSerialUtil <List <UserState> > .Serialize(AllUserState);

            File.WriteAllText(stateFileName, data);
#else
            XmlSerializer mySerializer;
            if (!string.IsNullOrEmpty(stateFileName))
            {
                try
                {
                    mySerializer = new XmlSerializer(typeof(List <UserState>));
                    // Writing the file requires a TextWriter.
                    if (!File.Exists(stateFileName))
                    {
                        //File.Create(stateFileName);
                        StreamWriter Fwriter = new StreamWriter(stateFileName);
                        Fwriter.Close();
                    }
                    TextWriter writer = new StreamWriter(stateFileName);
                    mySerializer.Serialize(writer, AllUserState);
                    writer.Close();
                }
                catch (System.Exception ex)
                {
                    writeStatus = false;
                    throw ex;
                }
            }

            if (!string.IsNullOrEmpty(defaultImplementFile))
            {
                try
                {
                    mySerializer = new XmlSerializer(typeof(List <UserEvent>));
                    // Writing the file requires a TextWriter.
                    if (!File.Exists(defaultImplementFile))
                    {
                        //File.Create(defaultImplementFile);
                        StreamWriter Fwriter = new StreamWriter(defaultImplementFile);
                        Fwriter.Close();
                    }
                    TextWriter writer = new StreamWriter(defaultImplementFile);
                    mySerializer.Serialize(writer, DefaultImplemt);
                    writer.Close();
                }
                catch (System.Exception ex)
                {
                    writeStatus = false;
                    throw ex;
                }
            }
#endif
            return(writeStatus);
        }
Пример #2
0
        public static void WriteTest()
        {
            string data = XMLSerialUtil <List <UserState> > .Serialize(AllUserState);

            File.WriteAllText(USER_STATE_FILE, data);
        }