Exemplo n.º 1
0
        private void DeSerializeTuringMachine(string filename)
        {
            ArrayList       objectToSerialize;
            Stream          stream     = File.Open(filename, FileMode.Open);
            BinaryFormatter bFormatter = new BinaryFormatter();

            objectToSerialize = (ArrayList)bFormatter.Deserialize(stream);
            stream.Close();
            dataGridView1.DataSource = objectToSerialize;

            stream     = File.Open(Path.GetDirectoryName(filename) + @"/" + Path.GetFileNameWithoutExtension(filename) + ".cfg", FileMode.Open);
            bFormatter = new BinaryFormatter();
            TuringMachineConfig config = (TuringMachineConfig)bFormatter.Deserialize(stream);

            stream.Close();

            CreateEmptyMachine();

            TM.CurrentState        = config.curr_state;
            TM.TapeLength          = config.tape_lenght;
            TM.CurrentTapePosition = config.curr_tape_pos;
            TM.NumberOfStates      = config.number_of_states;
            TM.NumberOfSymbols     = config.number_of_symbols;
            TM.Name         = config.name;
            TM.BlankSymbol  = config.blank_symbol;
            TM.FillSymbol   = config.fill_symbol;
            TM.InitialState = config.init_state;

            propertyGrid1.SelectedObject = TM;
        }
Exemplo n.º 2
0
        private void SerializeTuringMachine(string filename)
        {
            TuringMachineConfig config = new TuringMachineConfig();

            config.curr_state        = TM.CurrentState;
            config.curr_tape_pos     = TM.CurrentTapePosition;
            config.number_of_shifts  = TM.Shifts;
            config.number_of_states  = TM.NumberOfStates;
            config.number_of_symbols = TM.NumberOfSymbols;
            config.tape_lenght       = TM.TapeLength;
            config.sigma             = TM.Sigma;
            config.name         = TM.Name;
            config.blank_symbol = TM.BlankSymbol;
            config.fill_symbol  = TM.FillSymbol;
            config.init_state   = TM.InitialState;

            SerializeObject(filename, (ArrayList)dataGridView1.DataSource);
            SerializeObject(Path.GetDirectoryName(filename) + @"/" + Path.GetFileNameWithoutExtension(filename) + ".cfg", config);
        }