コード例 #1
0
        public void AddOperation(IPipelineOperation <TClass> operation)
        {
            if (_operations.Any(o => o.Type == operation.Type))
            {
                var message = String.Format("Already exists an operation of type: {0}", operation.Type);
                throw new InvalidOperationException(message);
            }

            _operations.Add(operation);
        }
コード例 #2
0
 protected virtual void CheckDependencies(IPipelineOperation <TContext> operation)
 {
     operation
     .Dependencies
     .ToList()
     .ForEach(d =>
     {
         if (!OperationsExecuted.Contains(d))
         {
             var operationName  = operation.GetType().Name;
             var dependencyName = d.Name;
             var message        = $"The {operationName} operation could not execute because it requires that the {dependencyName} operation be executed before it";
             throw new OperationDependencyNotExecutedException(message);
         }
     });
 }
コード例 #3
0
        /// <summary>
        /// Adds new system to processing.
        /// </summary>
        /// <param name="system">System instance.</param>
        public Pipeline Add(IPipelineOperation system)
        {
#if DEBUG
            if (system == null)
            {
                throw new Exception("system is null");
            }
#endif
#if !ECP_DISABLE_INJECT
            if (_injectSystemsCount == _injectSystems.Length)
            {
                Array.Resize(ref _injectSystems, _injectSystemsCount << 1);
            }
            _injectSystems[_injectSystemsCount++] = system;
#endif
            var preInitSystem = system as IPreInitOperation;
            if (preInitSystem != null)
            {
                if (_preInitSystemsCount == _preInitSystems.Length)
                {
                    Array.Resize(ref _preInitSystems, _preInitSystemsCount << 1);
                }
                _preInitSystems[_preInitSystemsCount++] = preInitSystem;
            }

            var initSystem = system as IInitOperation;
            if (initSystem != null)
            {
                if (_initSystemsCount == _initSystems.Length)
                {
                    Array.Resize(ref _initSystems, _initSystemsCount << 1);
                }
                _initSystems[_initSystemsCount++] = initSystem;
            }

            var runSystem = system as IUpdateOperation;
            if (runSystem != null)
            {
                if (_runSystemsCount == _runSystems.Length)
                {
                    Array.Resize(ref _runSystems, _runSystemsCount << 1);
                }
                _runSystems[_runSystemsCount++] = runSystem;
            }
            return(this);
        }
コード例 #4
0
        /// <summary>
        /// Domyślny konstruktor
        /// </summary>
        public MainWindowViewModel() : base()
        {
            _extractOperation   = new ExtractOperation();
            _transformOperation = new TransformOperation();
            _loadOperation      = new LoadOperation();

            _etlOperations = new List <IPipelineOperation>
            {
                _extractOperation,
                _transformOperation,
                _loadOperation
            };

            OutputList.Add("Starting..");
            Logger.NewLogAppeared += (sender, msg) => Application.Current.Dispatcher.Invoke(() =>
            {
                OutputList.Add(msg);
                OnPropertyChanged("TabIndex");
            });
        }
コード例 #5
0
ファイル: EcpInjections.cs プロジェクト: jtferson/Jtfer.Ecp
        /// <summary>
        /// Injects EcsWorld / EcsFilter fields to IEcsSystem.
        /// </summary>
        /// <param name="system">System to scan for injection.</param>
        /// <param name="world">EcsWorld instance to inject.</param>
        public static void Inject(IPipelineOperation system, Domain domain, EntityManager entityManager, System.Collections.Generic.Dictionary <Type, object> injections)
        {
            var systemType = system.GetType();

            if (!Attribute.IsDefined(systemType, typeof(EcpInjectAttribute)))
            {
                return;
            }
            var worldType         = domain.GetType();
            var entityManagerType = entityManager.GetType();
            var supervisor        = domain.GetSupervisor();
            var containerPool     = domain.GetContainerPool();
            var containerType     = typeof(IContainer);
            var contextType       = typeof(PipelineContext);
            var supervisorType    = typeof(EntitySupervisor);
            var filterType        = typeof(EntityFilter);
            var ignoreType        = typeof(EcpIgnoreInjectAttribute);
            var injectChildType   = typeof(EcpInjectChildAttribute);

            foreach (var f in systemType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                // skip fields with [EcsIgnoreInject] attribute.
                if (Attribute.IsDefined(f, ignoreType))
                {
                    continue;
                }
                var injectChild = false;
                if (Attribute.IsDefined(f, injectChildType))
                {
                    injectChild = true;
                }

                // EntityManager
                if (f.FieldType.IsAssignableFrom(entityManagerType) && !f.IsStatic)
                {
                    f.SetValue(system, entityManager);
                    continue;
                }

                // IContainer
                if (containerType.IsAssignableFrom(f.FieldType) && !f.IsStatic)
                {
                    f.SetValue(system, containerPool.GetContainer(f.FieldType, injectChild));
                    continue;
                }

                // PipelineContext
                if (f.FieldType.IsSubclassOf(contextType) && !f.IsStatic)
                {
                    f.SetValue(system, domain.GetPipelineContext(f.FieldType));
                    continue;
                }

                // EcsFilter
#if DEBUG
                if (f.FieldType == filterType)
                {
                    throw new Exception(string.Format("Cant use EcsFilter type at \"{0}\" system for dependency injection, use generic version instead", system));
                }
#endif
                if (f.FieldType.IsSubclassOf(filterType) && !f.IsStatic)
                {
                    f.SetValue(system, supervisor.GetFilter(f.FieldType));
                    continue;
                }
                // Other injections.
                foreach (var pair in injections)
                {
                    if (f.FieldType.IsAssignableFrom(pair.Key) && !f.IsStatic)
                    {
                        f.SetValue(system, pair.Value);
                        break;
                    }
                }
            }
        }