//序列化
    public static void SerializedPingBiMenDeviceInfoCollection(UInt16 stationIndex, DeviceType deviceType, int count, float[,] moves, string filePath)
    {
        PingBiMenDeviceInfoCollection collection = new PingBiMenDeviceInfoCollection();

        for (int i = 1; i <= moves.GetLength(0); ++i)
        {
            //闸机
            PingBiMenDeviceInfo deviceInfo = new PingBiMenDeviceInfo();
            deviceInfo.Name           = "屏蔽门";
            deviceInfo.StationIndex   = stationIndex;
            deviceInfo.DeviceId       = (int)deviceType + i;
            deviceInfo.DeviceType     = (int)deviceType;
            deviceInfo.LeftOpenMoveX  = moves[i - 1, 0];
            deviceInfo.LeftOpenMoveY  = moves[i - 1, 1];
            deviceInfo.LeftOpenMoveZ  = moves[i - 1, 2];
            deviceInfo.RightOpenMoveX = moves[i - 1, 3];
            deviceInfo.RightOpenMoveY = moves[i - 1, 4];
            deviceInfo.RightOpenMoveZ = moves[i - 1, 5];
            collection.AddPingBiMenDeviceInfo(deviceInfo);
        }
        FileStream fileStream = new FileStream(filePath,
                                               FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
        StreamWriter  sw  = new StreamWriter(fileStream, System.Text.Encoding.UTF8);
        XmlSerializer xml = new XmlSerializer(collection.GetType());

        xml.Serialize(sw, collection);
        sw.Close();
        fileStream.Close();
    }
    //反序列化
    public static PingBiMenDeviceInfoCollection DeserializedPingBiMenDeviceInfoCollection(string filePath)
    {
        FileStream    fs  = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
        XmlSerializer xml = new XmlSerializer(typeof(PingBiMenDeviceInfoCollection));
        PingBiMenDeviceInfoCollection collection = (PingBiMenDeviceInfoCollection)xml.Deserialize(fs);

        fs.Close();
        return(collection);
    }
예제 #3
0
 private static void CreatePingBiMenDeviceInfoXmlAboutStation0()
 {
     PingBiMenDeviceInfoCollection.SerializedPingBiMenDeviceInfoCollectionAtStation0();
 }