Esempio n. 1
0
        /// <summary>
        /// Flushes all changes to the designer.
        /// </summary>
        /// <param name="serializationManager">An <see cref="T:System.ComponentModel.Design.Serialization.IDesignerSerializationManager"/> to use for persisting the state of loaded designers.</param>
        protected override void PerformFlush(IDesignerSerializationManager serializationManager)
        {
            bool          success = true;
            ArrayList     errors  = new ArrayList();
            IDesignerHost idh     = (IDesignerHost)this.Host.GetService(typeof(IDesignerHost));

            Controls.ISerializableControl serializable = (LoaderHost.RootComponent as Controls.ISerializableControl);
            if (serializable == null)
            {
                throw new ApplicationException("Invalid root control type in designer.");
            }

            Serialization.SerializationObject serializationObject = this.GetSerializationObject();

            try
            {
                this.Buffer = this.SerializeFrameXml(serializationObject);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);

                success = false;
                errors.Add(exception);
            }

            IDesignerLoaderHost host = this.LoaderHost;

            host.EndLoad(FrameXmlDesignerLoader.hostedBaseClassName, success, errors);

            Trace.WriteLine("PerformFlush");
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves the serialization object hierarchy of the root control.
        /// </summary>
        /// <returns></returns>
        private Serialization.Ui GetSerializationObject()
        {
            Controls.Ui      rootControl = this.RootControl;
            Serialization.Ui rootObject  = rootControl.TypedSerializationObject;

            // remove objects that are shown in the view - they will be serialized
            rootObject.Controls.RemoveAll(obj => objectsInView.Contains(obj));

            List <SerializationObject> objects = new List <SerializationObject>(rootObject.Controls);

            foreach (Controls.ISerializableControl childControl in rootControl.BaseControls)
            {
                Serialization.SerializationObject childObject = GetSerializationObject(childControl);
                objects.Add(childObject);

                // add eventual new controls to the view
                if (!objectsInView.Contains(childObject))
                {
                    objectsInView.Add(childObject);
                }
            }

            rootObject.Controls.Clear();
            rootObject.Controls.AddRange(objects.SortRootObjects());

            return(rootObject);
        }
Esempio n. 3
0
        private string SerializeFrameXml(Serialization.SerializationObject ui)
        {
            const string xmlIndentChars = "\t";

            StringBuilder sb = new StringBuilder();

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent             = true;
            settings.IndentChars        = xmlIndentChars;
            settings.OmitXmlDeclaration = true;

            this.IsSerializing = true;
            try
            {
                using (XmlWriter writer = XmlWriter.Create(sb, settings))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Serialization.Ui));
                    serializer.Serialize(writer, ui);
                }
            }
            finally
            {
                this.IsSerializing = false;
            }
            return(sb.ToString());
        }
Esempio n. 4
0
        public void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case "virtual":
                OnVirtualChanged(sender);
                break;

            case "name":
                OnNameChanged(sender);
                break;
            }
            Serialization.SerializationObject ui = GetSerializationObject();
            this.Buffer = this.SerializeFrameXml(ui);

            // Refresh the property browser
            this.RefreshPropertyBrowser();
        }
 private void CreateLayers(SerializationObject serializationObject, Control parent, bool inherited)
 {
     FrameType frameType = serializationObject as FrameType;
     if (frameType != null)
     {
         foreach (FrameTypeLayers layers in frameType.LayersList)
         {
             foreach (FrameTypeLayersLayer layer in layers.Layer)
             {
                 foreach (SerializationObject so in layer.Layerables)
                 {
                     ILayerable layerable = CreateControl(so, parent, inherited) as ILayerable;
                     layerable.LayerLevel = layer.level;
                 }
             }
         }
     }
 }
        /// <summary>
        /// Creates the controls from the hierarchy of Serialization object.
        /// </summary>
        /// <param name="serializationObject">The serialization object.</param>
        /// <param name="parent">The parent.</param>
        /// <remarks>Recursive</remarks>
        private Control CreateControls(SerializationObject serializationObject, Control parent, bool inherited)
        {
            Control control = this.CreateControl(serializationObject, parent, inherited) as Control;
            // bypass controls that cannot be created by the control factory (and the virtual ones)
            if (control == null)
            {
                Debug.WriteLine(String.Format("Bypassing object '{0}' during control creation.", serializationObject));
            }
            else
            {
                parent = control;
            }

            CreateLayers(serializationObject, parent, false);
            foreach (SerializationObject childItem in serializationObject.Controls)
            {
                CreateControls(childItem, parent, inherited);
            }

            LayoutFrameType layoutFrame = serializationObject as LayoutFrameType;
            if (layoutFrame != null)
            {
                LayoutFrameType inheritedLayoutFrame = layoutFrame.InheritedObject;
                if (inheritedLayoutFrame != null)
                {
                    CreateLayers(inheritedLayoutFrame, parent, true);
                    foreach (SerializationObject childItem in inheritedLayoutFrame.Controls)
                    {
                        CreateControls(childItem, parent, true);
                    }
                }
            }

            return control;
        }
 private Control CreateControls(SerializationObject serializationObject, Control parent)
 {
     return CreateControls(serializationObject, parent, false);
 }
        /// <summary>
        /// Creates a control corresponding to the serialization object passed.
        /// </summary>
        /// <param name="serializationObject">The serialization object.</param>
        /// <param name="parent">parent control</param>
        /// <param name="inherited">true if the control is inherited (should be locked)</param>
        /// <returns></returns>
        private ISerializableControl CreateControl(SerializationObject serializationObject, Control parent, bool inherited)
        {
            Type controlType = GetControlType(serializationObject);
            if (controlType == null)
                return null;

            IComponent component = LoaderHost.CreateComponent(controlType);
            ISerializableControl iControl = (ISerializableControl) component;
            iControl.DesignerLoader = this;
            iControl.SerializationObject = serializationObject;

            LayoutFrameType layoutFrameType = serializationObject as LayoutFrameType;
            if (layoutFrameType != null)
            {
                if (!inherited)
                    component.Site.Name = layoutFrameType.ExpandedName;

                BaseControl control = iControl as BaseControl;
                if (control != null)
                {
                    control.Inherited = inherited;
                    Size size = layoutFrameType.SizeInPixels;
                    if (!size.IsEmpty)
                        control.Size = size;
                    else
                    {
                        control.SetDefaultSize();
                    }

                    if (parent != null)
                    {
                        control.Parent = parent;
                    }
                }
            }

            return iControl;
        }
        /// <summary>
        /// Returns the type of the control corresponding to the serialization object passed
        /// </summary>
        /// <param name="serializationObject">The serialization object.</param>
        /// <returns></returns>
        private static Type GetControlType(SerializationObject serializationObject)
        {
            //LayoutFrameType layoutFrame = serializationObject as LayoutFrameType;
            //if (layoutFrame != null && layoutFrame.@virtual)
            //    return typeof(VirtualComponent);

            // converts serialization object type name to control type name
            string typeName = serializationObject.GetType().Name;

            if (typeName.EndsWith("Type"))
                typeName = typeName.Substring(0, typeName.Length - 4);

            typeName = typeof(ISerializableControl).Namespace + '.' + typeName;

            return Type.GetType(typeName);
        }