コード例 #1
0
        static void Main(string[] args)
        {
            coupe coupe1 = new coupe(1, 4);
            coupe coupe2 = new coupe(2, 3);
            coupe coupe3 = new coupe(3, 3);
            coupe coupe4 = new coupe(4, 4);
            coupe coupe5 = new coupe(5, 2);

            carriage carriage = new carriage(1, 5);

            carriage.add(coupe1);
            carriage.add(coupe2);
            carriage.add(coupe3);
            carriage.add(coupe4);
            carriage.add(coupe5);

            carriage carriage1 = new carriage(1, 1);

            carriage1.add(coupe1);

            carriage carriage2 = new carriage(2, 2);

            carriage2.add(coupe1);
            carriage2.add(coupe5);

            carriage carriage3 = new carriage(3, 3);

            carriage3.add(coupe1);
            carriage3.add(coupe3);
            carriage3.add(coupe4);

            train train = new train(1, 4);

            train.add(carriage);
            train.add(carriage1);
            train.add(carriage2);
            train.add(carriage3);

            Workwithfiles f = new Workwithfiles();
            train         b = f.readfrombinaryfile(train);

            foreach (coupe c in carriage)
            {
                Console.WriteLine(c.Number.ToString() + "вагон, кол. пассажиров=" + c.Number_passenger.ToString());
            }
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: EvgeniyProtas/studies
        static void Main(string[] args)
        {
            coupe coupe1 = new coupe(1, 4);
            coupe coupe2 = new coupe(2, 3);
            coupe coupe3 = new coupe(3, 3);
            coupe coupe4 = new coupe(4, 4);
            coupe coupe5 = new coupe(5, 2);

            carriage carriage = new carriage(1, 5);

            carriage.add(coupe1);
            carriage.add(coupe2);
            carriage.add(coupe3);
            carriage.add(coupe4);
            carriage.add(coupe5);

            carriage carriage1 = new carriage(1, 1);

            carriage1.add(coupe1);

            carriage carriage2 = new carriage(2, 2);

            carriage2.add(coupe1);
            carriage2.add(coupe5);

            carriage carriage3 = new carriage(3, 3);

            carriage3.add(coupe1);
            carriage3.add(coupe3);
            carriage3.add(coupe4);

            train train = new train();

            train.add(carriage);
            train.add(carriage1);
            train.add(carriage2);
            train.add(carriage3);

            Serialize s = new Serialize();

            s.SerializeWithDataContract(train);

            train _train = new train();

            _train = s.DeserializeWithDataContract();
        }
コード例 #3
0
        public train readfromfile(train stream)
        {
            RijndaelManaged rijmanaged = new RijndaelManaged();

            byte[] key = { 0x17, 0x54, 0x03, 0x34, 0x05, 0x63, 0x51, 0x48, 0x29, 0x15, 0x11 };
            byte[] iv  = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };


            using (Stream f = File.OpenRead("D:\\file.txt"))
            {
                using (var ds = new DeflateStream(f, CompressionMode.Decompress))
                {
                    using (var crypto = new CryptoStream(ds, rijmanaged.CreateDecryptor(key, iv),
                                                         CryptoStreamMode.Read))
                    {
                        using (TextReader bw = new StreamReader(crypto))
                        {
                            stream.number           = int.Parse(bw.ReadLine());
                            stream.number_carriages = int.Parse(bw.ReadLine());
                            for (int i = 0; i < stream.number_carriages; i++)
                            {
                                int number, number_coupes;
                                number        = int.Parse(bw.ReadLine());
                                number_coupes = int.Parse(bw.ReadLine());
                                carriage newcar = new carriage(number, number_coupes);
                                for (int j = 0; j < newcar.number_coupes; j++)
                                {
                                    int numberof, number_passenger;
                                    numberof         = int.Parse(bw.ReadLine());
                                    number_passenger = int.Parse(bw.ReadLine());
                                    coupe newcoupe = new coupe(numberof, number_passenger);
                                    newcar.add(newcoupe);
                                }
                                stream.add(newcar);
                            }
                        }
                    }
                }
            }
            return(stream);
        }
コード例 #4
0
        public train readfrombinaryfile(train stream)
        {
            RijndaelManaged rijmanaged = new RijndaelManaged();

            byte[] key = { 0x17, 0x54, 0x03, 0x34, 0x05, 0x63, 0x51, 0x48, 0x29, 0x15, 0x11 };
            byte[] iv  = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };

            using (Stream str = File.OpenRead("myfile.bin"))
            {
                using (var ds = new DeflateStream(str, CompressionMode.Decompress))
                {
                    using (var crypto = new CryptoStream(ds, rijmanaged.CreateDecryptor(key, iv),
                                                         CryptoStreamMode.Read))
                    {
                        using (var f = new BinaryReader(crypto))
                        {
                            stream.number           = f.ReadInt32();
                            stream.number_carriages = f.ReadInt32();
                            for (int i = 0; i < stream.number_carriages; i++)
                            {
                                int number, number_coupes;
                                number        = f.ReadInt32();
                                number_coupes = f.ReadInt32();
                                carriage newcar = new carriage(number, number_coupes);
                                for (int j = 0; j < newcar.number_coupes; j++)
                                {
                                    int numberof, number_passenger;
                                    numberof         = f.ReadInt32();
                                    number_passenger = f.ReadInt32();
                                    coupe newcoupe = new coupe(numberof, number_passenger);
                                    newcar.add(newcoupe);
                                }
                                stream.add(newcar);
                            }
                        }
                    }
                }
            }
            return(stream);
        }