コード例 #1
0
        public MainWindow()
        {
            _serializator = new BinarySerializator <HistoryAndMemoryContainer>();
            Manager.HistoryAndMemoryContainer = _serializator.Deserialize(Path);

            InitializeComponent();
        }
コード例 #2
0
        protected override void OnClosing(CancelEventArgs e)
        {
            _serializator = _serializator ?? new BinarySerializator <HistoryAndMemoryContainer>();

            if (Manager.HistoryAndMemoryContainer != null)
            {
                _serializator.Serialize(Path, Manager.HistoryAndMemoryContainer);
            }
        }
コード例 #3
0
ファイル: Saver.cs プロジェクト: SalischevAV/EmployeDB_WebAPI
        public Saver(List <Employe> plant) //Hidden initialization
        {
            SerializationFlag = new SetGetSerialezationMethod();
            switch (SerializationFlag.SerialezationMethod)
            {
            case Enums.SerializationMethods.xml:
                Serializator = new XMLSerializator(plant);
                break;

            case Enums.SerializationMethods.bin:
            default:
                Serializator = new BinarySerializator(plant);
                break;
            }

            //string[] filesListWithPath = Directory.GetFiles(Directory.GetCurrentDirectory());
            string[]      filesListWithPath = Directory.GetFiles(@"C:\Users\salischev.a\Documents\Visual Studio 2015\Projects\EmployesDB\EmployesDB\bin\Debug\");
            List <string> fileList          = new List <string>();

            foreach (string item in filesListWithPath)
            {
                fileList.Add(Path.GetFileName(item));
            }

            string dbFile = null;

            foreach (string fileName in fileList)
            {
                if (fileName.ToLower().Contains("plant"))
                {
                    dbFile = fileName;
                    DBName = dbFile;
                }
            }
            if (dbFile != null)
            {
                IsDBExist = true;
                string[] splittingDBFile = dbFile.Split('.');
                if (splittingDBFile.Length == 2)
                {
                    switch (splittingDBFile[1].ToLower())
                    {
                    case "dat":
                        Deserializator = new BinaryDeserializator();
                        break;

                    case "xml":
                    default:
                        Deserializator = new XMLDeserializator();
                        break;
                    }
                }
            }
        }
コード例 #4
0
        private static void Main(string[] args)
        {
            Menu.GameMenu();
            UserChoice();
            void UserChoice()
            {
                var userChoice = Methods.PlayerChoice();

                switch (userChoice)
                {
                // Nowa Gra
                case 1:
                    var player = CharacterCreator.CreatCharacter();
                    player.AddModifire();
                    player.CurrentHpToMax();
                    BinarySerializator.WriteToBinaryFile <PlayerCharacter>("C:/Users/ubalc/Programming/Projects/TextRPGame/Game/Resources/Saves/PlayerCharacter.bin", player);
                    Console.Clear();
                    Gladiator.Begin();
                    break;

                // Kontynuj Gre
                case 2:
                    PlayerCharacter playerOne = BinarySerializator.ReadFromBinaryFile <PlayerCharacter>(
                        "C:/Users/ubalc/Programming/Projects/TextRPGame/Game/Resources/Saves/PlayerCharacter.bin");
                    Gladiator.Begin();
                    break;

                // Zakończ
                case 3:
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine($"Wybierz jedną z możliwych opcji 1, 2, 3\n");
                    UserChoice();
                    break;
                }
            }
        }