Пример #1
0
        public CommandInvoker(IBasicActivateItems basicActivator)
        {
            _basicActivator    = basicActivator;
            _repositoryLocator = basicActivator.RepositoryLocator;

            _argumentDelegates = _basicActivator.GetDelegates();


            AddDelegate(typeof(ICatalogueRepository), true, (p) => _repositoryLocator.CatalogueRepository);
            AddDelegate(typeof(IDataExportRepository), true, (p) => _repositoryLocator.DataExportRepository);
            AddDelegate(typeof(IBasicActivateItems), true, (p) => _basicActivator);
            AddDelegate(typeof(IRDMPPlatformRepositoryServiceLocator), true, (p) => _repositoryLocator);
            AddDelegate(typeof(DirectoryInfo), false, (p) => _basicActivator.SelectDirectory($"Enter Directory for '{p.Name}'"));
            AddDelegate(typeof(FileInfo), false, (p) => _basicActivator.SelectFile($"Enter File for '{p.Name}'"));

            // Is the Global Check Notifier the best here?
            AddDelegate(typeof(ICheckNotifier), true, (p) => _basicActivator.GlobalErrorCheckNotifier);

            AddDelegate(typeof(string), false, (p) =>

                        _basicActivator.TypeText("Value needed for parameter", GetPromptFor(p), 1000, null, out string result, false)
                ? result
                : throw new OperationCanceledException());

            AddDelegate(typeof(Type), false, (p) =>
                        _basicActivator.SelectType($"Type needed for {p.Name} ", p.DemandIfAny?.TypeOf, out Type chosen)
                    ? chosen
                    : throw new OperationCanceledException());

            AddDelegate(typeof(DiscoveredDatabase), false, (p) => _basicActivator.SelectDatabase(true, GetPromptFor(p)));
            AddDelegate(typeof(DiscoveredTable), false, (p) => _basicActivator.SelectTable(true, GetPromptFor(p)));

            AddDelegate(typeof(DatabaseEntity), false, (p) => _basicActivator.SelectOne(GetPromptFor(p), GetAllObjectsOfType(p.Type)));
            AddDelegate(typeof(IPipeline), false, SelectPipeline);
            AddDelegate(typeof(IMightBeDeprecated), false, SelectOne <IMightBeDeprecated>);
            AddDelegate(typeof(IDisableable), false, SelectOne <IDisableable>);
            AddDelegate(typeof(INamed), false, SelectOne <INamed>);
            AddDelegate(typeof(IDeleteable[]), false, SelectMany <IDeleteable>);
            AddDelegate(typeof(IDeleteable), false, SelectOne <IDeleteable>);
            AddDelegate(typeof(ILoggedActivityRootObject), false, SelectOne <ILoggedActivityRootObject>);
            AddDelegate(typeof(ICollectSqlParameters), false, SelectOne <ICollectSqlParameters>);
            AddDelegate(typeof(IRootFilterContainerHost), false, SelectOne <IRootFilterContainerHost>);

            AddDelegate(typeof(Enum), false, (p) => _basicActivator.SelectEnum(GetPromptFor(p), p.Type, out Enum chosen)?chosen:null);


            _argumentDelegates.Add(new CommandInvokerArrayDelegate(typeof(IMapsDirectlyToDatabaseTable), false, (p) =>
            {
                IMapsDirectlyToDatabaseTable[] available = GetAllObjectsOfType(p.Type.GetElementType());
                var result = _basicActivator.SelectMany(GetPromptFor(p), p.Type.GetElementType(), available);

                if (result == null)
                {
                    return(null);
                }

                var typedArray = Array.CreateInstance(p.Type.GetElementType(), result.Length);
                for (int i = 0; i < typedArray.Length; i++)
                {
                    typedArray.SetValue(result[i], i);
                }

                return(typedArray);
            }));


            AddDelegate(typeof(ICheckable), false,
                        (p) => _basicActivator.SelectOne(GetPromptFor(p),
                                                         _basicActivator.GetAll <ICheckable>()
                                                         .Where(p.Type.IsInstanceOfType)
                                                         .Cast <IMapsDirectlyToDatabaseTable>()
                                                         .ToArray())
                        );

            AddDelegate(typeof(IPatcher), false, (p) =>
            {
                if (!_basicActivator.SelectType("Select Patcher (if any)", typeof(IPatcher), out Type patcherType))
                {
                    throw new OperationCanceledException();
                }

                if (patcherType == null)
                {
                    return(null);
                }

                try
                {
                    return(Activator.CreateInstance(patcherType));
                }
                catch (Exception e)
                {
                    throw new Exception($"Failed to call/find blank constructor of IPatcher Type '{patcherType}'", e);
                }
            }
                        );

            _argumentDelegates.Add(new CommandInvokerValueTypeDelegate((p) =>
                                                                       _basicActivator.SelectValueType(GetPromptFor(p), p.Type, null, out object chosen)
                    ? chosen
                    : throw new OperationCanceledException()));
        }
Пример #2
0
        public CommandInvoker(IBasicActivateItems basicActivator)
        {
            _basicActivator    = basicActivator;
            _repositoryLocator = basicActivator.RepositoryLocator;

            _argumentDelegates = _basicActivator.GetDelegates();


            AddDelegate(typeof(ICatalogueRepository), true, (p) => _repositoryLocator.CatalogueRepository);
            AddDelegate(typeof(IDataExportRepository), true, (p) => _repositoryLocator.DataExportRepository);
            AddDelegate(typeof(IBasicActivateItems), true, (p) => _basicActivator);
            AddDelegate(typeof(IRDMPPlatformRepositoryServiceLocator), true, (p) => _repositoryLocator);
            AddDelegate(typeof(DirectoryInfo), false, (p) => _basicActivator.SelectDirectory($"Enter Directory for '{p.Name}'"));
            AddDelegate(typeof(FileInfo), false, (p) => _basicActivator.SelectFile($"Enter File for '{p.Name}'"));

            AddDelegate(typeof(string), false, (p) =>

                        _basicActivator.TypeText("Value needed for parameter", p.Name, 1000, null, out string result, false)
                ? result
                : throw new OperationCanceledException());

            AddDelegate(typeof(Type), false, (p) =>
                        _basicActivator.SelectType($"Type needed for {p.Name} ", p.DemandIfAny?.TypeOf, out Type chosen)
                    ? chosen
                    : throw new OperationCanceledException());

            AddDelegate(typeof(DiscoveredDatabase), false, (p) => _basicActivator.SelectDatabase(true, "Value needed for parameter " + p.Name));
            AddDelegate(typeof(DiscoveredTable), false, (p) => _basicActivator.SelectTable(true, "Value needed for parameter " + p.Name));

            AddDelegate(typeof(DatabaseEntity), false, (p) => _basicActivator.SelectOne(p.Name, GetAllObjectsOfType(p.Type)));
            AddDelegate(typeof(IMightBeDeprecated), false, SelectOne <IMightBeDeprecated>);
            AddDelegate(typeof(IDisableable), false, SelectOne <IDisableable>);
            AddDelegate(typeof(INamed), false, SelectOne <INamed>);
            AddDelegate(typeof(IDeleteable), false, SelectOne <IDeleteable>);

            AddDelegate(typeof(Enum), false, (p) => _basicActivator.SelectEnum("Value needed for parameter " + p.Name, p.Type, out Enum chosen)?chosen:null);


            _argumentDelegates.Add(new CommandInvokerArrayDelegate(typeof(IMapsDirectlyToDatabaseTable), false, (p) =>
            {
                IMapsDirectlyToDatabaseTable[] available = GetAllObjectsOfType(p.Type.GetElementType());
                return(_basicActivator.SelectMany(p.Name, p.Type.GetElementType(), available));
            }));


            AddDelegate(typeof(ICheckable), false,
                        (p) => _basicActivator.SelectOne(p.Name,
                                                         _basicActivator.GetAll <ICheckable>()
                                                         .Where(p.Type.IsInstanceOfType)
                                                         .Cast <IMapsDirectlyToDatabaseTable>()
                                                         .ToArray())
                        );

            AddDelegate(typeof(IPatcher), false, (p) =>
            {
                if (!_basicActivator.SelectType("Select Patcher (if any)", typeof(IPatcher), out Type patcherType))
                {
                    throw new OperationCanceledException();
                }

                if (patcherType == null)
                {
                    return(null);
                }

                try
                {
                    return(Activator.CreateInstance(patcherType));
                }
                catch (Exception e)
                {
                    throw new Exception($"Failed to call/find blank constructor of IPatcher Type '{patcherType}'", e);
                }
            }
                        );

            _argumentDelegates.Add(new CommandInvokerValueTypeDelegate((p) =>
                                                                       _basicActivator.SelectValueType(p.Name, p.Type, null, out object chosen)
                    ? chosen
                    : throw new OperationCanceledException()));
        }
Пример #3
0
 private T[] SelectMany <T>(RequiredArgument parameterInfo)
 {
     return
         (_basicActivator.SelectMany(parameterInfo.Name, typeof(T), _basicActivator.GetAll <T>().Cast <IMapsDirectlyToDatabaseTable>().ToArray())
          .Cast <T>().ToArray());
 }