Пример #1
0
        private void XmlSerialization(string filename, GUIControlProperties obj)
        {
            //Create a file stream object
            FileStream serializeStream = File.Create(filename);

            //Start Serialization
            XmlSerializer xmlFmt = new XmlSerializer(obj.GetType());

            xmlFmt.Serialize(serializeStream, obj);
            serializeStream.Close();
        }
Пример #2
0
        private void SoapSerialization(string filename, GUIControlProperties obj)
        {
            //Create a file stream object
            FileStream serializeStream = File.Create(filename);

            //Start Serialization
            SoapFormatter soapFmt = new SoapFormatter();

            soapFmt.Serialize(serializeStream, obj);
            serializeStream.Close();
        }
Пример #3
0
        private void BinarySerialization(string filename, GUIControlProperties obj)
        {
            //Create a file stream object
            FileStream serializeStream = File.Create(filename);

            //Start Serialization
            BinaryFormatter binFmt = new BinaryFormatter();

            binFmt.Serialize(serializeStream, obj);
            serializeStream.Close();
        }
Пример #4
0
        private GUIControlProperties XmlDeSerialization(string filename)
        {
            GUIControlProperties GuiCtrlProp = new GUIControlProperties();

            //Create a file stream object
            FileStream serializeStream = File.OpenRead(filename);

            //Start Serialization
            XmlSerializer xmlFmt = new XmlSerializer(GuiCtrlProp.GetType());

            GuiCtrlProp = (GUIControlProperties)xmlFmt.Deserialize(serializeStream);
            serializeStream.Close();
            return(GuiCtrlProp);
        }
Пример #5
0
        private void btnSerialize_Click(object sender, System.EventArgs e)
        {
            //initialize a GUIControlProperties object
            GUIControlProperties GuiCtrlProp;

            GuiCtrlProp         = new GUIControlProperties();
            GuiCtrlProp.GUIName = txtName.Text;
            GuiCtrlProp.GUIText = txtText.Text;
            GuiCtrlProp.GUIType = txtType.Text;

            //make a filename to serialize the object
            string filename = "";

            sfdSerialize.Filter = "Serializing Files (*.bin; *.soap; *.xml)|*.bin;*.soap;*.xml|All Files|*.*";
            if (sfdSerialize.ShowDialog() == DialogResult.OK)
            {
                filename = sfdSerialize.FileName;
            }
            else
            {
                return;
            }

            //Start serialization
            FileInfo fi = new FileInfo(filename);

            switch (fi.Extension)
            {
            case ".bin":
                BinarySerialization(filename, GuiCtrlProp);
                break;

            case ".soap":
                SoapSerialization(filename, GuiCtrlProp);
                break;

            case ".xml":
                XmlSerialization(filename, GuiCtrlProp);
                break;
            }
        }
Пример #6
0
        private void btnDeserialize_Click(object sender, System.EventArgs e)
        {
            //Get the serilized file name
            string filename = "";

            ofdDeserialize.Filter = "Serializing Files (*.bin; *.soap; *.xml)|*.bin;*.soap;*.xml|All Files|*.*";
            if (ofdDeserialize.ShowDialog() == DialogResult.OK)
            {
                filename = ofdDeserialize.FileName;
            }
            else
            {
                return;
            }

            //reconstruct the object from a file
            GUIControlProperties GuiCtrlProp = null;
            FileInfo             fi          = new FileInfo(filename);

            switch (fi.Extension)
            {
            case ".bin":
                GuiCtrlProp = BinaryDeSerialization(filename);
                break;

            case ".soap":
                GuiCtrlProp = SoapDeSerialization(filename);
                break;

            case ".xml":
                GuiCtrlProp = XmlDeSerialization(filename);
                break;
            }

            //populate the text of the GUI controls on the form
            txtName.Text = GuiCtrlProp.GUIName;
            txtText.Text = GuiCtrlProp.GUIText;
            txtType.Text = GuiCtrlProp.GUIType;
        }