Esempio n. 1
0
        /// <summary>
        /// Sauvegarde le modèle dans le fichier spécifié avec le sérialiseur donné
        /// </summary>
        /// <param name="model">modèle à sauvegarder</param>
        /// <param name="filename">nom du fichier de destination</param>
        /// <param name="serializer">sérialiseur utilisé</param>
        public static void Save(IDocumentData model, string filename, ISerializer serializer)
        {            
            /*IControlData[] controls = new IControlData[model.ControlsDictionary.Count()];

            for(int i=0; i<model.ControlsDictionary.Count(); i++)
            {
                string key = model.ControlsDictionary.Keys[i];
                IControlData control = model.ControlsDictionary[key];
                controls[i] = control;
            }
            string serialization = serializer.Serialize(controls);*/
            string[][] test = new string[model.ControlsDictionary.Count][];
            ControlDataWrapper[] controls = new ControlDataWrapper[model.ControlsDictionary.Count];
            for(int indexControl=0; indexControl<model.ControlsDictionary.Count; indexControl++)
            {
                string key = model.ControlsDictionary.Keys[indexControl];
                SortedList<string, string> properties = model.ControlsDictionary[key].Properties;
                PropertyDataWrapper[] listproperties = new PropertyDataWrapper[properties.Count];
                test[indexControl] = new string[properties.Count];
                for(int indexProperty=0; indexProperty<properties.Count(); indexProperty++)
                {
                    string property = properties.Keys[indexProperty];
                    string value = properties[property];
                    listproperties[indexProperty] = new PropertyDataWrapper(property, value);
                }
                string controlName = model.ControlsDictionary[key].Name;
                string controlType = model.ControlsDictionary[key].Type;
                controls[indexControl] = new ControlDataWrapper(controlName, controlType, listproperties);
            }

            string serialization = serializer.Serialize(controls);
            ControlDataWrapper[] final = serializer.UnSerialize(serialization);

            SaveFile(filename, serialization);
        }
Esempio n. 2
0
 /// <summary>
 /// Sérialise les données
 /// </summary>
 /// <param name="value">le dictionnaire de controles</param>
 /// <returns>la chaîne sérialisée</returns>
 public string Serialize(ControlDataWrapper[] controls)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         IFormatter formatter = new SoapFormatter();
         formatter.Serialize(stream, controls);
         return Encoding.ASCII.GetString(stream.GetBuffer());
     }
 }