예제 #1
0
파일: TaskHub.cs 프로젝트: JoB70/Bifrost
 static dynamic ToDynamic(Task task)
 {
     dynamic dynamicTask = new ExpandoObject();
     dynamicTask.Type = task.GetType().Name;
     dynamicTask.Id = task.Id.Value;
     dynamicTask.CurrentOperation = task.CurrentOperation;
     PopulateStateFromProperties(dynamicTask, task);
     return dynamicTask;
 }
예제 #2
0
파일: TaskHub.cs 프로젝트: JoB70/Bifrost
        static void PopulateStateFromProperties(ExpandoObject target, Task source)
        {
            var sourceType = source.GetType();
            var taskType = typeof(Task);
            var taskProperties = taskType.GetProperties();
            var declaringTypeProperties = sourceType.GetProperties().Where(p => p.DeclaringType == sourceType);
            var sourceProperties = declaringTypeProperties.Where(p => !taskProperties.Any(pp => pp.Name == p.Name));
            var dictionary = sourceProperties.ToDictionary(p => p.Name, p => p.GetValue(source, null).ToString());

            foreach (var key in dictionary.Keys)
                ((IDictionary<string, object>)target)[key] = dictionary[key];
        }
예제 #3
0
        void PopulateStateFromProperties(TaskEntity target, Task source)
        {
            var sourceType = source.GetType();
            var taskType = typeof(Task);
#if(NETFX_CORE)
            var taskProperties = taskType.GetTypeInfo().DeclaredProperties;
            var declaringTypeProperties = sourceType.GetTypeInfo().DeclaredProperties.Where(p => p.DeclaringType == sourceType);
#else
            var taskProperties = taskType.GetProperties();
            var declaringTypeProperties = sourceType.GetProperties().Where(p => p.DeclaringType == sourceType);
#endif

            var sourceProperties = declaringTypeProperties.Where(p=>!taskProperties.Any(pp=>pp.Name == p.Name));
            var sourcePropertiesDictionary = sourceProperties.ToDictionary(p => p.Name, p => p.GetValue(source, null).ToString());
            sourcePropertiesDictionary.ForEach(target.State.Add);
        }
예제 #4
0
        TaskEntity ToTaskEntity(Task task, TaskEntity taskEntity = null)
        {
            if( taskEntity == null ) 
                taskEntity = new TaskEntity();

            taskEntity.Id = task.Id;
            taskEntity.CurrentOperation = task.CurrentOperation;
            taskEntity.Type = task.GetType();
            PopulateStateFromProperties(taskEntity, task);
            return taskEntity;
        }
예제 #5
0
        void PopulatePropertiesFromState(Task target, TaskEntity source)
        {
            var targetType = target.GetType();
            foreach (var key in source.State.Keys)
            {
#if(NETFX_CORE)
                var property = targetType.GetTypeInfo().GetDeclaredProperty(key);
#else
                var property = targetType.GetProperty(key);
#endif
                if (property != null)
                {
                    var value = Convert.ChangeType(source.State[key], property.PropertyType, null);
                    property.SetValue(target, value, null);
                }
            }
        }
예제 #6
0
 void PopulatePropertiesFromState(Task target, TaskEntity source)
 {
     var targetType = target.GetType();
     foreach (var key in source.State.Keys)
     {
         var property = targetType.GetProperty(key);
         if (property != null)
         {
             var value = Convert.ChangeType(source.State[key], property.PropertyType, null);
             property.SetValue(target, value, null);
         }
     }
 }