/// <summary>
        /// Wrap those operations to handle cases like nullable, or types that do not persist
        /// directly like the TimeSpan.
        /// In the case of getting no direct conversions needed.
        /// </summary>
        object HandleGetValue(IDBPersistent item, PropertyInfo info)
        {
            DBPersistenceAttribute[] dbPersistence = (DBPersistenceAttribute[])info.GetCustomAttributes(typeof(DBPersistenceAttribute), true);
            if (dbPersistence.Length > 0)
            {
                SystemMonitor.CheckThrow(dbPersistence.Length == 1 && dbPersistence[0].PersistenceType != DBPersistenceAttribute.PersistenceTypeEnum.None, "Misteken usage of persistence attributes or internal error.");
                if (dbPersistence[0].PersistenceType == DBPersistenceAttribute.PersistenceTypeEnum.Binary)
                {
                    object val = info.GetValue(item, null);
                    if (val == null)
                    {
                        return(null);
                    }
                    using (MemoryStream ms = new MemoryStream())
                    {// SaveState object persistance as BYTE[].
                        SerializationHelper.Serialize(ms, val);
                        ms.Flush();
                        return(ms.GetBuffer());
                    }
                }
            }

            // Default case - no specific persistance instructions given.
            return(info.GetValue(item, null));
        }
Example #2
0
        void HandleComponentPersistenceDataUpdatedEvent(IDBPersistent dbComponent)
        {
            PlatformComponent component = (PlatformComponent)dbComponent;

            if (component.IsPersistableToDB)
            {
                PersistenceHelper.UpdateToDB <PlatformComponent>((PlatformComponent)component);
            }
        }
        /// <summary>
        /// Wrap those operations to handle cases like nullable, or types that do not persist
        /// directly like the TimeSpan.
        /// </summary>
        bool HandleSetValue(IDBPersistent item, PropertyInfo info, object value)
        {
            Type propertyType   = info.PropertyType;
            Type underlyingType = Nullable.GetUnderlyingType(info.PropertyType);

            if (underlyingType != null)
            {// Unwrap nullable properties.
                propertyType = underlyingType;

                if (value == null)
                {// Nullable enums with null values not displayed.
                    info.SetValue(item, null, null);
                    return(true);
                }
            }

            object actualValue = value;

            DBPersistenceAttribute[] dbPersistence = (DBPersistenceAttribute[])info.GetCustomAttributes(typeof(DBPersistenceAttribute), true);
            if (dbPersistence.Length > 0)
            {
                SystemMonitor.CheckThrow(dbPersistence.Length == 1 && dbPersistence[0].PersistenceType != DBPersistenceAttribute.PersistenceTypeEnum.None, "Misteken usage of persistence attributes or internal error.");
                if (dbPersistence[0].PersistenceType == DBPersistenceAttribute.PersistenceTypeEnum.Binary)
                {// DeSerialize object persistence from BYTE[].
                    byte[] byteValue = (byte[])value;
                    SystemMonitor.CheckThrow(byteValue != null || byteValue.Length != 0, "Byte value size not expected at deserialization.");
                    using (MemoryStream ms = new MemoryStream(byteValue))
                    {
                        if (SerializationHelper.DeSerialize(ms, out actualValue) == false)
                        {// Failed to deserialize.
                            return(false);
                        }
                    }
                }
            }
            else
            if (propertyType == typeof(TimeSpan))
            {
                actualValue = TimeSpan.Parse(value as string);
            }
            else if (propertyType.IsEnum)
            {
                actualValue = Enum.ToObject(propertyType, (int)value);
            }
            else if (propertyType == typeof(Uri))
            {
                actualValue = new Uri(value as string);
            }

            info.SetValue(item, actualValue, null);
            return(true);
        }
Example #4
0
        void source_PersistenceDataUpdatedEvent(IDBPersistent source)
        {
            if (_persistenceHelper == null)
            {
                SystemMonitor.OperationWarning("Can not operate, since persistence helper not available.");
                return;
            }

            if (_persistenceHelper.UpdateToDB((EventSource)source, null) == false)
            {
                SystemMonitor.OperationError("Failed to update source.");
            }
        }
 void HandleComponentPersistenceDataUpdatedEvent(IDBPersistent dbComponent)
 {
     PlatformComponent component = (PlatformComponent)dbComponent;
     if (component.IsPersistableToDB)
     {
         PersistenceHelper.UpdateToDB<PlatformComponent>((PlatformComponent)component);
     }
 }
 void source_PersistenceDataUpdatedEvent(IDBPersistent source)
 {
     SystemMonitor.CheckError(_persistenceHelper.UpdateToDB((NewsSource)source, null), "Failed to update source.");
 }
        void source_PersistenceDataUpdatedEvent(IDBPersistent source)
        {
            if (_persistenceHelper == null)
            {
                SystemMonitor.OperationWarning("Can not operate, since persistence helper not available.");
                return;
            }

            if (_persistenceHelper.UpdateToDB((EventSource)source, null) == false)
            {
                SystemMonitor.OperationError("Failed to update source.");
            }
        }
 void source_PersistenceDataUpdatedEvent(IDBPersistent source)
 {
     SystemMonitor.CheckError(_persistenceHelper.UpdateToDB((NewsSource)source, null), "Failed to update source.");
 }