Exemplo n.º 1
0
 public SqlCommandProcessor(
     IDataReaderFactory dataReaderFactory,
     IParameterConverter parameterConverter)
 {
     _dataReaderFactory  = dataReaderFactory;
     _parameterConverter = parameterConverter;
 }
Exemplo n.º 2
0
 // Use the ASP.NET Core DI system to inject these dependencies
 public PluginLoadOptions(
     IPluginLogger <T> logger,
     IAssemblyScanner <T> assemblyScanner,
     ISharedServicesProvider <T> sharedServicesProvider,
     IPluginTypesProvider <T> pluginTypesProvider,
     IPluginActivationContextProvider <T> pluginActivationContextProvider,
     IRemotePluginActivator <T> activator,
     IParameterConverter parameterConverter,
     IResultConverter resultConverter,
     IPluginAssemblyLoader <T> assemblyLoader,
     IPluginProxyCreator <T> proxyCreator,
     IHostTypesProvider <T> hostTypesProvider,
     IRemoteTypesProvider <T> remoteTypesProvider,
     IRuntimePlatformContext runtimePlatformContext,
     IAssemblySelector <T> assemblySelector,
     IPluginSelector <T> pluginSelector
     )
 {
     this.logger                          = logger;
     this.assemblyScanner                 = assemblyScanner;
     this.sharedServicesProvider          = sharedServicesProvider;
     this.pluginTypesProvider             = pluginTypesProvider;
     this.pluginActivationContextProvider = pluginActivationContextProvider;
     this.activator                       = activator;
     this.parameterConverter              = parameterConverter;
     this.resultConverter                 = resultConverter;
     this.assemblyLoader                  = assemblyLoader;
     this.proxyCreator                    = proxyCreator;
     this.hostTypesProvider               = hostTypesProvider;
     this.remoteTypesProvider             = remoteTypesProvider;
     this.runtimePlatformContext          = runtimePlatformContext;
     this.assemblySelector                = assemblySelector;
     this.pluginSelector                  = pluginSelector;
 }
Exemplo n.º 3
0
 public DimensionConverter(IDimensionMapper dimensionMapper, IParameterConverter parameterConverter, IUsingFormulaConverter usingFormulaConverter, IDataRepositoryConverter dataRepositoryConverter)
 {
     _dimensionMapper         = dimensionMapper;
     _parameterConverter      = parameterConverter;
     _usingFormulaConverter   = usingFormulaConverter;
     _dataRepositoryConverter = dataRepositoryConverter;
 }
Exemplo n.º 4
0
 public RAMLDocGeneratorV08(IApiDescriptionGroupCollectionProvider apiDescription, IParameterConverter parameterConverter, IMethodConverter methodConverter, IComments comments)
 {
     this.apiDescription     = apiDescription;
     this.parameterConverter = parameterConverter;
     this.methodConverter    = methodConverter;
     this.comments           = comments;
 }
Exemplo n.º 5
0
        public PluginLoadOptionsBuilder <T> WithDefaultOptions(string pluginPath = null)
        {
            if (String.IsNullOrEmpty(pluginPath))
            {
                pluginPath = Path.Join(GetLocalExecutionPath(), "Plugins");
            }

            this.pluginPathProvider     = new DefaultPluginPathProvider <T>(pluginPath);
            this.dependencyPathProvider = new DependencyPathProvider <T>(pluginPath);

            this.runtimePlatformContext = new RuntimePlatformContext();
            this.ScanForAssemblies(composer =>
                                   composer.WithDefaultOptions <DefaultAssemblyScanner <T>, DefaultAssemblyScannerOptions <T> >());

            this.pluginAssemblyNameProvider = new PluginAssemblyNameProvider <T>($"{typeof(T).Name}.dll");
            this.sharedServicesProvider     = new DefaultSharedServicesProvider <T>(new ServiceCollection());
            this.activator    = new DefaultRemotePluginActivator <T>(this.sharedServicesProvider);
            this.proxyCreator = new PluginProxyCreator <T>();

            // Use System.Text.Json in 3.0
#if NETCORE3_0
            this.parameterConverter = new JsonSerializerParameterConverter();
            this.resultConverter    = new JsonSerializerResultConverter();
            this.assemblyLoaderType = typeof(DefaultAssemblyLoaderWithNativeResolver <T>);
#endif
            // Use Newtonsoft.Json in 2.1
#if NETCORE2_1
            this.parameterConverter = new NewtonsoftParameterConverter();
            this.resultConverter    = new NewtonsoftResultConverter();
            this.assemblyLoaderType = typeof(DefaultAssemblyLoader <T>);
#endif
            this.assemblySelector    = new DefaultAssemblySelector <T>();
            this.assemblyLoadOptions = new DefaultAssemblyLoadOptions <T>(
                PluginPlatformVersion.Empty(),
                false,
                NativeDependencyLoadPreference.PreferInstalledRuntime);

            this.probingPathsProvider = new ProbingPathsProvider <T>();

            var hostTypesProvider = new HostTypesProvider();
            hostTypesProvider.AddHostType(typeof(Prise.Plugin.PluginAttribute)); // Add the Prise.Infrastructure assembly to the host types
            hostTypesProvider.AddHostType(typeof(ServiceCollection));            // Adds the BuildServiceProvider assembly to the host types
            this.hostTypesProvider = hostTypesProvider;

            var remoteTypesProvider = new RemoteTypesProvider <T>();
            remoteTypesProvider.AddRemoteType(typeof(T)); // Add the contract to the remote types, so that we can have backwards compatibility
            this.remoteTypesProvider = remoteTypesProvider;

            this.pluginSelector               = new DefaultPluginSelector <T>();
            this.depsFileProviderType         = typeof(DefaultDepsFileProvider <T>);
            this.pluginDependencyResolverType = typeof(DefaultPluginDependencyResolver <T>);
            // Typically used for downloading and storing plugins from the network, but it could be useful for caching local plugins as well
            this.tempPathProviderType = typeof(UserProfileTempPathProvider <T>);

            this.nativeAssemblyUnloaderType = typeof(DefaultNativeAssemblyUnloader);
            this.hostFrameworkProviderType  = typeof(HostFrameworkProvider);

            return(this);
        }
Exemplo n.º 6
0
        internal PluginProxy <T> SetParameterConverter(IParameterConverter parameterConverter)
        {
            if (parameterConverter == null)
            {
                throw new PrisePluginException($"IParameterConverter for Proxy<{typeof(T).Name}> was null");
            }

            this.parameterConverter = parameterConverter;
            return(this);
        }
Exemplo n.º 7
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed && disposing)
     {
         this.parameterConverter = null;
         this.resultConverter    = null;
         this.remoteObject       = null;
     }
     this.disposed = true;
 }
Exemplo n.º 8
0
        public static TProxyType CreateProxy <TProxyType>(object remoteObject, IParameterConverter parameterConverter, IResultConverter resultConverter)
        {
            var proxy = PluginProxy <TProxyType> .Create();

            ((PluginProxy <TProxyType>)proxy)
            .SetRemoteObject(remoteObject)
            .SetParameterConverter(parameterConverter)
            .SetResultConverter(resultConverter);
            return((TProxyType)proxy);
        }
Exemplo n.º 9
0
 public CommandProcessorFactory(
     IProcedureLibrary storedProcedureLibrary,
     IProcedureRunner storedProcedureRunner,
     IDataReaderFactory dataReaderFactory,
     IParameterConverter parameterConverter)
 {
     _storedProcedureLibrary = storedProcedureLibrary;
     _storedProcedureRunner  = storedProcedureRunner;
     _dataReaderFactory      = dataReaderFactory;
     _parameterConverter     = parameterConverter;
 }
Exemplo n.º 10
0
        internal static object[] SerializeParameters(IParameterConverter parameterConverter, MethodInfo targetMethod, object[] args)
        {
            var parameters = targetMethod.GetParameters();
            var results    = new List <object>();

            for (var index = 0; index < parameters.Count(); index++)
            {
                var parameter      = parameters[index];
                var parameterValue = args[index];
                results.Add(parameterConverter.ConvertToRemoteType(parameter.ParameterType, parameterValue));
            }

            return(results.ToArray());
        }
Exemplo n.º 11
0
 public DefaultPluginLoader(
     IAssemblyScanner assemblyScanner,
     IPluginTypeSelector pluginTypeSelector,
     IAssemblyLoader assemblyLoader,
     IParameterConverter parameterConverter,
     IResultConverter resultConverter,
     IPluginActivator pluginActivator)
 {
     this.assemblyScanner    = assemblyScanner;
     this.pluginTypeSelector = pluginTypeSelector;
     this.assemblyLoader     = assemblyLoader;
     this.parameterConverter = parameterConverter;
     this.resultConverter    = resultConverter;
     this.pluginActivator    = pluginActivator;
     this.pluginContexts     = new ConcurrentBag <IPluginLoadContext>();
 }
        protected override void Context()
        {
            _element = new XElement("Root",
                                    new XElement("Container1",
                                                 new XElement("Parameter1", new XAttribute(Constants.Serialization.Attribute.Dimension, "OldDim1")),
                                                 new XElement("Parameter2", new XAttribute(Constants.Serialization.Attribute.Dimension, "Dim1"))),
                                    new XElement("Container2",
                                                 new XElement("Parameter3", new XAttribute(Constants.Serialization.Attribute.Dimension, "OldDim2")),
                                                 new XElement("Parameter4", new XAttribute(Constants.Serialization.Attribute.Dimension, "Dim2"))));

            _dimensionMapper         = A.Fake <IDimensionMapper>();
            _parameterConverter      = A.Fake <IParameterConverter>();
            _usingFormulaConverter   = A.Fake <IUsingFormulaConverter>();
            _dataRepositoryConverter = A.Fake <IDataRepositoryConverter>();
            A.CallTo(() => _dimensionMapper.DimensionNameFor("OldDim1", false)).Returns("NewDim1");
            A.CallTo(() => _dimensionMapper.DimensionNameFor("Dim1", false)).Returns("Dim1");
            A.CallTo(() => _dimensionMapper.DimensionNameFor("OldDim2", false)).Returns("NewDim2");
            A.CallTo(() => _dimensionMapper.DimensionNameFor("Dim2", false)).Returns("Dim2");
            sut = new DimensionConverter(_dimensionMapper, _parameterConverter, _usingFormulaConverter, _dataRepositoryConverter);
        }
        internal static string[] EvaluateAsConverter(string converterClassName, params string[] parameters)
        {
            Type converterType = GetConverterType(converterClassName);

            if (converterType == null)
            {
                return(Array.Empty <string>());
            }

            try
            {
                IParameterConverter converter = Activator.CreateInstance(converterType) as IParameterConverter;
                MethodInfo          method    = converterType.GetMethod("TransformParameter");
                return(method.Invoke(converter, new object[] { parameters }) as string[]);
            }
            catch (Exception exception)
            {
                s_log.Warn(LocalizationService.FormatResourceString("ExpressionEvaluatorMessage01", converterClassName, parameters), exception);
            }
            return(Array.Empty <string>());
        }
        private ParameterExpression CustomConverter(MethodContext methodContext, IParameterConverter parameterConverter)
        {
            var param = methodContext.AddVariable(typeof(object), "dispArgs");

            var dict = Expression.Variable(typeof(IDictionary <string, object>), "params");

            var dictInit = new List <Expression>
            {
                dict.Assign(Expression.Constant(new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase)))
            };

            foreach (var parameter in Parameters.Skip(1))
            {
                dictInit.Add(Expression.Call(dict, _dictAdd, Expression.Constant(parameter.Name), parameter));
            }

            dictInit.Add(Expression.Call(Expression.Constant(parameterConverter), StoredProcedureAttribute.Convert, dict));

            methodContext.Do(param.Assign(Expression.Block(param.Type, new[] { dict }, dictInit)));
            return(param);
        }
Exemplo n.º 15
0
        internal static object[] SerializeParameters(IParameterConverter parameterConverter, MethodInfo targetMethod, object[] args)
        {
            var parameters = targetMethod.GetParameters();
            var results    = new List <object>();

            for (var index = 0; index < parameters.Count(); index++)
            {
                var parameter      = parameters[index];
                var parameterValue = args[index];

                if (parameter.ParameterType.BaseType == typeof(System.MulticastDelegate))
                {
                    if (parameter.ParameterType.GenericTypeArguments.Any(g => g != typeof(EventArgs)))
                    {
                        throw new PriseProxyException($"Custom EventArgs are not supported in Prise");
                    }

                    results.Add(parameterValue);
                    continue;
                }

                object result = null;
                if (parameter.ParameterType.IsGenericParameter)
                {
                    var runtimeType = parameterValue.GetType();
                    result = parameterConverter.ConvertToRemoteType(runtimeType, parameterValue);
                }
                else
                {
                    result = parameterConverter.ConvertToRemoteType(parameter.ParameterType, parameterValue);
                }

                results.Add(result);
            }

            return(results.ToArray());
        }
Exemplo n.º 16
0
        public static TProxyType CreateProxy <TProxyType>(
            object remoteObject,
            IParameterConverter parameterConverter = null,
            IResultConverter resultConverter       = null)
        {
            if (parameterConverter == null)
            {
                parameterConverter = new PassthroughParameterConverter();
            }

            if (resultConverter == null)
            {
                resultConverter = new PassthroughResultConverter();
            }

            var proxy = PriseProxy <TProxyType> .Create();

            ((PriseProxy <TProxyType>)proxy)
            .SetRemoteObject(remoteObject)
            .SetParameterConverter(parameterConverter)
            .SetResultConverter(resultConverter);

            return((TProxyType)proxy);
        }
Exemplo n.º 17
0
 public MethodConverterV10(IParameterConverter parameterConverter, IComments comments) : base(parameterConverter, comments)
 {
 }
Exemplo n.º 18
0
 public EventParameterInfo(IParameterSymbol parameter, GenerationOptions options, IParameterConverter converter)
 {
     m_converter = converter;
     m_options   = options;
     m_parameter = parameter;
 }
Exemplo n.º 19
0
 public Parameter(string name, IParameterConverter rawValue)
 {
     Key   = name;
     Value = rawValue.QueryValue;
 }
Exemplo n.º 20
0
 public MethodConverterV08(IParameterConverter parameterConverter, IComments comments)
 {
     this.parameterConverter = parameterConverter;
     this.comments           = comments;
 }
Exemplo n.º 21
0
 public T CreatePluginProxy(object remoteObject, IParameterConverter parameterConverter, IResultConverter resultConverter) =>
 ProxyCreator.CreateProxy <T>(remoteObject, parameterConverter, resultConverter);
Exemplo n.º 22
0
 public MethodConverterV10(IParameterConverter parameterConverter) : base(parameterConverter)
 {
 }
Exemplo n.º 23
0
        public static object Invoke(object remoteObject, MethodInfo targetMethod, object[] args, IParameterConverter parameterConverter, IResultConverter resultConverter)
        {
            try
            {
                var localType    = targetMethod.ReturnType;
                var remoteMethod = FindMethodOnRemoteObject(targetMethod, remoteObject);
                if (remoteMethod == null)
                {
                    throw new PriseProxyException($"Target method {targetMethod.Name} is not found on Proxy Type {remoteObject.GetType().Name}.");
                }

                object result = null;
                if (remoteMethod.IsGenericMethod)
                {
                    var generic = remoteMethod.MakeGenericMethod(targetMethod.GetGenericArguments());
                    result = generic.Invoke(remoteObject, SerializeParameters(parameterConverter, remoteMethod, args));
                }
                else
                {
                    result = remoteMethod.Invoke(remoteObject, SerializeParameters(parameterConverter, remoteMethod, args));
                }

                var remoteType = remoteMethod.ReturnType;
                if (remoteType.BaseType == typeof(System.Threading.Tasks.Task))
                {
                    return(resultConverter.ConvertToLocalTypeAsync(localType, remoteType, result as System.Threading.Tasks.Task));
                }
                return(resultConverter.ConvertToLocalType(localType, remoteType, result));
            }
            catch (Exception ex) when(ex is TargetInvocationException)
            {
                throw ex.InnerException ?? ex;
            }
        }
Exemplo n.º 24
0
 public AdoQueryRunner(IParameterConverter parameterConverter)
 {
     _parameterConverter = parameterConverter;
 }
 public EventParameterInfo(IParameterSymbol parameter, GenerationOptions options, IParameterConverter converter)
 {
     m_converter = converter;
     m_options = options;
     m_parameter = parameter;
 }
Exemplo n.º 26
0
 public RAMLDocGeneratorV10(IApiDescriptionGroupCollectionProvider apiDescription, IParameterConverter parameterConverter, IMethodConverter methodConverter, IComments comments)
     : base(apiDescription, parameterConverter, methodConverter, comments)
 {
 }
Exemplo n.º 27
0
 public PluginLoadOptionsBuilder <T> WithParameterConverter(IParameterConverter parameterConverter)
 {
     this.parameterConverter = parameterConverter;
     return(this);
 }
Exemplo n.º 28
0
 public MethodConverterV08(IParameterConverter parameterConverter)
 {
     this.parameterConverter = parameterConverter;
 }