Esempio n. 1
0
        /// <summary>
        /// Factory method for instanting widget objects based on the data passed in through xml
        /// </summary>
        /// <param name="reader">XML reader which is used to read serialized data object hierarchy</param>
        /// <returns>Newly created widget data instance</returns>
        public static WidgetData Create(XmlReader reader)
        {
            WidgetData widget = null;

            // LATER: This method breaks OCP since addition/removal of widget types will require modification of the
            // base class which is not desirable. For now we'll keep it this way, but if this method is revisited, we
            // should consider creating a stand-alone factory which could potentially use reflection to dynamically
            // build a list of creatable widgets.

            switch (reader.Name)
            {
            case "WidgetContainerData":
                widget = new WidgetContainerData();
                break;

            case "FolderWidgetData":
                widget = new FolderWidgetData();
                break;

            default:
                // Unknown element, skip to next one
                reader.Skip();
                break;
            }

            if (widget != null)
            {
                (( IXmlSerializable)widget).ReadXml(reader);
            }

            return(widget);
        }
Esempio n. 2
0
        /// <summary>
        /// Loads widget data from a stream whose format must match the specified format that is expected.
        /// </summary>
        /// <param name="stream">Stream object which contains serialized data</param>
        /// <param name="format">Identifies the expected format of the stream being read</param>
        public void Load(Stream stream, WidgetDocSaveFormat format)
        {
            WidgetContainerData container = null;

            if (format == WidgetDocSaveFormat.Xml)
            {
                using (XmlTextReader reader = new XmlTextReader(stream))
                {
                    reader.MoveToContent();

                    container = (WidgetContainerData)WidgetData.Create(reader);
                }
            }
            else if (format == WidgetDocSaveFormat.Binary)
            {
                IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                container = (WidgetContainerData)formatter.Deserialize(stream);
            }
            else
            {
                throw new InvalidOperationException(string.Format("Invalid save mode specified ({0})", (int)format));
            }

            container.PostDeserialize();

            this.Root = container;
        }
Esempio n. 3
0
        private void UpdateSource(Data.WidgetContainerData source)
        {
            if (_controlData.Source != null)
            {
                _controlData.Source.ContainerChanged -= OnWidgetContainerChanged;
                _controlData.Source.ContainerResized -= OnWidgetContainerResized;
            }

            _controlData.Source = source;

            if (_controlData.Source != null)
            {
                _controlData.Source.ContainerChanged += OnWidgetContainerChanged;
                _controlData.Source.ContainerResized += OnWidgetContainerResized;
            }

            UpdateGrid(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Loads widget data from a stream whose format must match the specified format that is expected.
        /// </summary>
        /// <param name="stream">Stream object which contains serialized data</param>
        /// <param name="format">Identifies the expected format of the stream being read</param>
        public void Load( Stream stream, WidgetDocSaveFormat format )
        {
            WidgetContainerData     container = null;

            if( format == WidgetDocSaveFormat.Xml )
            {
                using( XmlTextReader reader = new XmlTextReader( stream ) )
                {
                    reader.MoveToContent();

                    container = (WidgetContainerData)WidgetData.Create( reader );
                }
            }
            else if( format == WidgetDocSaveFormat.Binary )
            {
                IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                container = (WidgetContainerData)formatter.Deserialize( stream );
            }
            else
            {
                throw new InvalidOperationException( string.Format( "Invalid save mode specified ({0})", (int)format ) );
            }

            container.PostDeserialize();

            this.Root = container;
        }
Esempio n. 5
0
        /// <summary>
        /// Loads widget data. This function loads data from default, application-specific isolated storage location
        /// </summary>
        /// <remarks>
        /// When this function is used, the application need not be concerned with or where the application data is 
        /// stored. Once this method is called, internall the WidgetDocument will take care of locating and opening 
        /// the persistent file.
        /// </remarks>
        public void Load()
        {
            try
            {
                using( IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly() )
                using( Stream stream = new IsolatedStorageFileStream( "DroppyData", FileMode.Open, FileAccess.Read, FileShare.Read, isf ) )
                {
                    Load( stream, _defaultSaveFormat );
                }
            }
            catch( Exception )
            {
            }

            if( _rootNode == null )
            {
                this.Root = new WidgetContainerData( 6, 1 );
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Sets parent container information on the current widget
 /// </summary>
 /// <param name="parent">Reference to the parent widget container</param>
 /// <param name="location">Location of the widget within the parent container</param>
 public void SetOwner( WidgetContainerData parent, MatrixLoc location )
 {
     _location = location;
     _parent = parent;
 }
Esempio n. 7
0
 /// <summary>
 /// Removes any association between the widget and its parent
 /// </summary>
 public void ClearOwner()
 {
     _parent = null;
     _location = new MatrixLoc();
 }
Esempio n. 8
0
        /// <summary>
        /// Factory method for instanting widget objects based on the data passed in through xml
        /// </summary>
        /// <param name="reader">XML reader which is used to read serialized data object hierarchy</param>
        /// <returns>Newly created widget data instance</returns>
        public static WidgetData Create( XmlReader reader )
        {
            WidgetData      widget = null;

            // LATER: This method breaks OCP since addition/removal of widget types will require modification of the
            // base class which is not desirable. For now we'll keep it this way, but if this method is revisited, we
            // should consider creating a stand-alone factory which could potentially use reflection to dynamically
            // build a list of creatable widgets.

            switch( reader.Name )
            {
                case "WidgetContainerData":
                    widget = new WidgetContainerData();
                    break;
                case "FolderWidgetData":
                    widget = new FolderWidgetData();
                    break;
                default:
                    // Unknown element, skip to next one
                    reader.Skip();
                    break;
            }

            if( widget != null )
            {
                ( ( IXmlSerializable)widget ).ReadXml( reader );
            }

            return widget;
        }
Esempio n. 9
0
 /// <summary>
 /// Sets parent container information on the current widget
 /// </summary>
 /// <param name="parent">Reference to the parent widget container</param>
 /// <param name="location">Location of the widget within the parent container</param>
 public void SetOwner(WidgetContainerData parent, MatrixLoc location)
 {
     _location = location;
     _parent   = parent;
 }