Esempio n. 1
0
        /// <summary>
        /// Charge le fichier donné grâce au sérialiseur passé en paramètre
        /// </summary>
        /// <param name="filename">le fichier à ouvrir</param>
        /// <param name="serializer">le sérialiseur utilisé</param>
        /// <returns>les données du document</returns>
        public static IDocumentData Load(string filename, ISerializer serializer)
        {
            if (filename == null)
                throw new ArgumentNullException();

            string loaded = LoadFile(filename);
            //char[] separators = { '\n' };
            //string[] serializedControls = loaded.Split(separators);

            //IControlData[] controls = new IControlData[serializedControls.Count()];
            string extension = Path.GetExtension(filename);

            ControlDataWrapper[] controlwrappers = (ControlDataWrapper[]) serializer.UnSerialize(loaded);
            IDocumentData model = new DocumentModel();

            foreach (ControlDataWrapper wrapper in controlwrappers)
            {
                ControlData control = new ControlData(wrapper.name, wrapper.type);
                PropertyDataWrapper[] datawrappers = wrapper.Properties;
                foreach (PropertyDataWrapper datawrapper in datawrappers)
                    control.Properties.Add(datawrapper.Property, datawrapper.Value);
                model.ControlsDictionary.Add(control.Name, control);
            }
            
            return model;
        }
Esempio n. 2
0
        /// <summary>
        /// Ajout d'un contrôle au dictionnaire
        /// </summary>
        /// <param name="args">
        /// Tableau de chaine représentant les arguments. Le tableau doit contenir deux éléments dont le premier représente le
        /// nom du contrôle à ajouter et le second le type du contrôle à ajouter.
        /// </param>
        private void AddControl(string[] args, ActionType action)
        {
            if (args.Length != 4)
                throw new ArgumentException();
          
            string controlName = args[0];
            string controlType = args[1];
            int controlPosX = Convert.ToInt32(args[2]);
            int controlPosY = Convert.ToInt32(args[3]);

            if(action == ActionType.Undo)
            {
                string[] infos = { controlName };
                RemoveControl(infos, ActionType.Do);
                return;
            }
            
            IControlData data = new ControlData(controlName, controlType);
            Type type = Type.GetType(controlType);
            PropertyDescriptor descriptorLocation = Serializer.DoGetPropertyDescriptorType(type, "Location");
            
            System.Drawing.Point controlLocation = new System.Drawing.Point(controlPosX, controlPosY);
            string controlLocationValue = Serializer.SerializeProperty(descriptorLocation, controlLocation);
            data.Properties.Add("Location", controlLocationValue);

            controlsDictionary.Add(controlName, data);
        }