Exemplo n.º 1
0
        private DashboardableControlHostPanel Hydrate(IDashboardableControl theControlCreated, DashboardControl dbRecord)
        {
            var emptyCollection = theControlCreated.ConstructEmptyCollection(dbRecord);

            foreach (DashboardObjectUse objectUse in dbRecord.ObjectsUsed)
            {
                var o = _activator.RepositoryLocator.GetArbitraryDatabaseObject(objectUse.ReferencedObjectRepositoryType, objectUse.ReferencedObjectType, objectUse.ReferencedObjectID);
                emptyCollection.DatabaseObjects.Add(o);
            }
            try
            {
                emptyCollection.LoadExtraText(dbRecord.PersistenceString);
            }
            catch (Exception e)
            {
                throw new DashboardControlHydrationException("Could not resolve extra text persistence string for control '" + theControlCreated.GetType() + "'", e);
            }

            theControlCreated.SetCollection(_activator, emptyCollection);

            var host = new DashboardableControlHostPanel(_activator, dbRecord, theControlCreated);

            host.Location = new Point(dbRecord.X, dbRecord.Y);
            host.Width    = dbRecord.Width;
            host.Height   = dbRecord.Height;

            return(host);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of Type t (which must be an IDashboardableControl derrived ultimately from UserControl) which is then hydrated with an empty collection and a database
        /// record is created which can be used to save it's collection state for the lifetime of the control (allowing you to restore the state later)
        /// </summary>
        /// <param name="forLayout"></param>
        /// <param name="t"></param>
        /// <param name="theControlCreated"></param>
        /// <returns></returns>
        public DashboardControl Create(DashboardLayout forLayout, Type t, out DashboardableControlHostPanel theControlCreated)
        {
            var instance = CreateControl(t);

            //get the default size requirements of the control as it exists post construction
            int w = instance.Width;
            int h = instance.Height;

            var dbRecord = new DashboardControl(_activator.RepositoryLocator.CatalogueRepository, forLayout, t, _startLocationForNewControls.X, _startLocationForNewControls.Y, w, h, "");

            theControlCreated = Hydrate((IDashboardableControl)instance, dbRecord);

            return(dbRecord);
        }