Пример #1
0
        public virtual ServiceMethodList GetServiceMethods(DbSource dbSource)
        {
            VerifyArgument.IsNotNull("dbSource", dbSource);
            ServiceMethodList cacheResult;

            if (!dbSource.ReloadActions && GetCachedResult(dbSource, out cacheResult))
            {
                return(cacheResult);
            }


            var serviceMethods = new ServiceMethodList();

            Func <IDbCommand, IList <IDbDataParameter>, string, string, bool> procedureFunc = (command, parameters, helpText, executeAction) =>
            {
                var serviceMethod = CreateServiceMethod(command, parameters, helpText, executeAction);
                serviceMethods.Add(serviceMethod);
                return(true);
            };

            Func <IDbCommand, IList <IDbDataParameter>, string, string, bool> functionFunc = (command, parameters, helpText, executeAction) =>
            {
                var serviceMethod = CreateServiceMethod(command, parameters, helpText, executeAction);
                serviceMethods.Add(serviceMethod);
                return(true);
            };

            using (var server = CreateDbServer(dbSource))
            {
                server.Connect(dbSource.ConnectionString);
                server.FetchStoredProcedures(procedureFunc, functionFunc);
            }
            TheCache.AddOrUpdate(dbSource.ConnectionString, serviceMethods, (s, list) => serviceMethods);
            return(GetCachedResult(dbSource, out cacheResult) ? cacheResult : serviceMethods);
        }
        /// <summary>
        /// Lists the methods.
        /// </summary>
        /// <param name="assemblyLocation">The assembly location.</param>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="fullName">The full name.</param>
        /// <returns></returns>
        public ServiceMethodList ListMethods(string assemblyLocation, string assemblyName, string fullName)
        {
            Assembly assembly;
            var      serviceMethodList = new ServiceMethodList();

            if (_assemblyLoader.TryLoadAssembly(assemblyLocation, assemblyName, out assembly))
            {
                var type         = assembly.GetType(fullName);
                var methodInfos  = type.GetMethods();
                var constructors = type.GetConstructors();

                constructors.ToList().ForEach(info =>
                {
                    var serviceMethod = new ServiceMethod {
                        Name = info.Name
                    };
                    var parameterInfos = info.GetParameters().ToList();
                    parameterInfos.ForEach(parameterInfo =>
                                           serviceMethod.Parameters.Add(
                                               new MethodParameter
                    {
                        DefaultValue = parameterInfo.DefaultValue?.ToString() ?? string.Empty,
                        EmptyToNull  = false,
                        IsRequired   = true,
                        Name         = parameterInfo.Name,
                        TypeName     = parameterInfo.ParameterType.AssemblyQualifiedName
                    }));
                    serviceMethodList.Add(serviceMethod);
                });


                methodInfos.ToList().ForEach(info =>
                {
                    var serviceMethod = new ServiceMethod {
                        Name = info.Name
                    };
                    var parameterInfos = info.GetParameters().ToList();
                    parameterInfos.ForEach(parameterInfo =>
                                           serviceMethod.Parameters.Add(
                                               new MethodParameter
                    {
                        DefaultValue = parameterInfo.DefaultValue?.ToString() ?? string.Empty,
                        EmptyToNull  = false,
                        IsRequired   = true,
                        Name         = parameterInfo.Name,
                        TypeName     = parameterInfo.ParameterType.AssemblyQualifiedName
                    }));
                    serviceMethodList.Add(serviceMethod);
                });
            }

            return(serviceMethodList);
        }
Пример #3
0
        public virtual ServiceMethodList GetServiceMethods(DbSource dbSource)
        {
            VerifyArgument.IsNotNull("dbSource", dbSource);

            // Check the cache for a value ;)
            ServiceMethodList cacheResult;

            if (!dbSource.ReloadActions)
            {
                if (GetCachedResult(dbSource, out cacheResult))
                {
                    return(cacheResult);
                }
            }
            // else reload actions ;)

            var serviceMethods = new ServiceMethodList();

            //
            // Function to handle procedures returned by the data broker
            //
            Func <IDbCommand, IList <IDbDataParameter>, string, string, bool> procedureFunc = (command, parameters, helpText, executeAction) =>
            {
                var serviceMethod = CreateServiceMethod(command, parameters, helpText, executeAction);
                serviceMethods.Add(serviceMethod);
                return(true);
            };

            //
            // Function to handle functions returned by the data broker
            //
            Func <IDbCommand, IList <IDbDataParameter>, string, string, bool> functionFunc = (command, parameters, helpText, executeAction) =>
            {
                var serviceMethod = CreateServiceMethod(command, parameters, helpText, executeAction);
                serviceMethods.Add(serviceMethod);
                return(true);
            };

            //
            // Get stored procedures and functions for this database source
            //
            using (var server = CreateDbServer(dbSource))
            {
                server.Connect(dbSource.ConnectionString);
                server.FetchStoredProcedures(procedureFunc, functionFunc);
            }

            // Add to cache ;)
            TheCache.AddOrUpdate(dbSource.ConnectionString, serviceMethods, (s, list) => serviceMethods);

            return(GetCachedResult(dbSource, out cacheResult) ? cacheResult : serviceMethods);
        }
Пример #4
0
// ReSharper disable InconsistentNaming
        public void AbstractDataBaseBroker_GetServiceMethods_WhenCached_CachedResults()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            TestDatabaseBroker broker = new TestDatabaseBroker();

            DbSource source = new DbSource();

            TestDatabaseBroker.TheCache = new ConcurrentDictionary <string, ServiceMethodList>();
// ReSharper disable UseObjectOrCollectionInitializer
            var methodList = new ServiceMethodList();

// ReSharper restore UseObjectOrCollectionInitializer
            methodList.Add(new ServiceMethod("bob", "bob src", null, null, null, ""));

            TestDatabaseBroker.TheCache.TryAdd(source.ConnectionString, methodList);
            //------------Execute Test---------------------------

            var result = broker.GetServiceMethods(source);

            // set back to empty ;)
            TestDatabaseBroker.TheCache = new ConcurrentDictionary <string, ServiceMethodList>();
            //------------Assert Results-------------------------

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("bob", result[0].Name);
        }
// ReSharper disable InconsistentNaming
        public void AbstractDataBaseBroker_GetServiceMethods_WhenCached_CachedResults()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            TestDatabaseBroker broker = new TestDatabaseBroker();

            DbSource source = new DbSource();

            TestDatabaseBroker.TheCache = new ConcurrentDictionary<string, ServiceMethodList>();
// ReSharper disable UseObjectOrCollectionInitializer
            var methodList = new ServiceMethodList();
// ReSharper restore UseObjectOrCollectionInitializer
            methodList.Add(new ServiceMethod("bob", "bob src", null, null, null,""));

            TestDatabaseBroker.TheCache.TryAdd(source.ConnectionString, methodList);
            //------------Execute Test---------------------------

            var result = broker.GetServiceMethods(source);

            // set back to empty ;)
            TestDatabaseBroker.TheCache = new ConcurrentDictionary<string, ServiceMethodList>();
            //------------Assert Results-------------------------

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("bob", result[0].Name);
        }
Пример #6
0
        public void AbstractDataBaseBroker_GetServiceMethods_WhenCached_CachedResults()

        {
            //------------Setup for test--------------------------
            var broker = new TestDatabaseBroker();

            var source = new DbSource();

            TestDatabaseBroker.TheCache = new ConcurrentDictionary <string, ServiceMethodList>();

            var methodList = new ServiceMethodList();

            methodList.Add(new ServiceMethod("bob", "bob src", null, null, null, ""));

            TestDatabaseBroker.TheCache.TryAdd(source.ConnectionString, methodList);
            //------------Execute Test---------------------------

            var result = broker.GetServiceMethods(source);

            // set back to empty ;)
            TestDatabaseBroker.TheCache = new ConcurrentDictionary <string, ServiceMethodList>();
            //------------Assert Results-------------------------

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("bob", result[0].Name);
        }
Пример #7
0
        public ServiceMethodList ListMethodsWithReturns(string assemblyLocation, string assemblyName, string fullName)
        {
            var serviceMethodList = new ServiceMethodList();

            if (_assemblyLoader.TryLoadAssembly(assemblyLocation, assemblyName, out Assembly assembly))
            {
                var type        = assembly.GetType(fullName);
                var methodInfos = type.GetMethods();

                methodInfos.ToList().ForEach(info =>
                {
                    var serviceMethod = new ServiceMethod
                    {
                        Name = info.Name
                    };
                    //https://msdn.microsoft.com/en-us/library/system.reflection.methodbase.isspecialname(v=vs.110).aspx
                    if (info.IsSpecialName)
                    {
                        serviceMethod.IsProperty = true;
                    }
                    var returnType = info.ReturnType;
                    if (returnType.IsPrimitive || returnType == typeof(decimal) || returnType == typeof(string))
                    {
                        serviceMethod.Dev2ReturnType = $"return: {returnType.Name}";
                        serviceMethod.IsObject       = false;
                    }
                    else if (info.ReturnType == typeof(void))
                    {
                        serviceMethod.IsVoid = true;
                    }
                    else
                    {
                        ListReturnTypes(serviceMethod, returnType);
                    }
                    var parameterInfos = info.GetParameters().ToList();
                    foreach (var parameterInfo in parameterInfos)
                    {
                        var methodParameter = new MethodParameter
                        {
                            DefaultValue  = parameterInfo.DefaultValue?.ToString() ?? string.Empty,
                            EmptyToNull   = false,
                            IsRequired    = true,
                            Name          = parameterInfo.Name,
                            TypeName      = parameterInfo.ParameterType.AssemblyQualifiedName,
                            ShortTypeName = parameterInfo.ParameterType.FullName
                        };
                        var parameterType = parameterInfo.ParameterType;
                        BuildParameter(parameterType, methodParameter);

                        serviceMethod.Parameters.Add(methodParameter);
                    }
                    serviceMethodList.Add(serviceMethod);
                });
            }

            return(serviceMethodList);
        }
Пример #8
0
        public override ServiceMethodList GetServiceMethods(DbSource dbSource)
        {
            VerifyArgument.IsNotNull("dbSource", dbSource);


            var serviceMethods = new ServiceMethodList();

            //
            // Function to handle procedures returned by the data broker
            //
            Func <IDbCommand, IList <IDbDataParameter>, IList <IDbDataParameter>, string, string, bool> procedureFunc = (command, parameters, outparameters, helpText, executeAction) =>
            {
                var serviceMethod = CreateServiceMethod(command, parameters, outparameters, helpText, executeAction);
                serviceMethods.Add(serviceMethod);
                return(true);
            };

            //
            // Function to handle functions returned by the data broker
            //
            Func <IDbCommand, IList <IDbDataParameter>, IList <IDbDataParameter>, string, string, bool> functionFunc = (command, parameters, outparameters, helpText, executeAction) =>
            {
                var serviceMethod = CreateServiceMethod(command, parameters, outparameters, helpText, executeAction);
                serviceMethods.Add(serviceMethod);
                return(true);
            };

            //
            // Get stored procedures and functions for this database source
            //
            using (var server = CreateDbServer(dbSource))
            {
                server.Connect(dbSource.ConnectionString);
                server.FetchStoredProcedures(procedureFunc, functionFunc, false, dbSource.DatabaseName);
            }

            // Add to cache ;)

            return(serviceMethods);
        }
Пример #9
0
        public ServiceMethodList ListMethods(string classId, bool is32Bit)
        {
            var serviceMethodList = new List <ServiceMethod>();
            var orderMethodsList  = new ServiceMethodList();

            classId = classId.Replace("{", "").Replace("}", "");
            if (is32Bit)
            {
                var execute = IpcClient.GetIPCExecutor(_clientStreamWrapper).Invoke(classId.ToGuid(), "", Execute.GetMethods, new ParameterInfoTO[] { });
                if (execute is List <MethodInfoTO> ipcMethods)
                {
                    ServiceMethodList(ref serviceMethodList, orderMethodsList, ipcMethods);
                    return(orderMethodsList);
                }
            }
            if (string.IsNullOrEmpty(classId))
            {
                return(new ServiceMethodList());
            }
            var type        = Type.GetTypeFromCLSID(classId.ToGuid(), true);
            var methodInfos = type.GetMethods();

            methodInfos.ToList().ForEach(info =>
            {
                var serviceMethod = new ServiceMethod {
                    Name = info.Name
                };
                var parameterInfos = info.GetParameters().ToList();
                parameterInfos.ForEach(parameterInfo =>
                                       serviceMethod.Parameters.Add(
                                           new MethodParameter
                {
                    DefaultValue = parameterInfo.DefaultValue?.ToString() ?? string.Empty,
                    EmptyToNull  = false,
                    IsRequired   = true,
                    Name         = parameterInfo.Name,
                    TypeName     = parameterInfo.ParameterType.AssemblyQualifiedName
                }));
                orderMethodsList.Add(serviceMethod);
            });
            return(orderMethodsList);
        }
Пример #10
0
 // POST: Service/Services/DbMethods
 public ServiceMethodList DbMethods(string args, Guid workspaceId, Guid dataListId)
 {
     var result = new ServiceMethodList();
     if(!string.IsNullOrEmpty(args))
     {
         try
         {
             Dev2JsonSerializer serialiser = new Dev2JsonSerializer();
             var source = serialiser.Deserialize<DbSource>(args);
             var actualSource = _resourceCatalog.GetResource<DbSource>(workspaceId, source.ResourceID);
             actualSource.ReloadActions = source.ReloadActions;
             var serviceMethods = FetchMethods(actualSource);
             result.AddRange(serviceMethods);
         }
         catch(Exception ex)
         {
             RaiseError(ex);
             result.Add(new ServiceMethod(ex.Message, ex.StackTrace));
         }
     }
     return result;
 }
        /// <summary>
        /// Lists the methods.
        /// </summary>
        /// <param name="assemblyLocation">The assembly location.</param>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="fullName">The full name.</param>
        /// <returns></returns>
        public ServiceMethodList ListMethods(string assemblyLocation, string assemblyName, string fullName)
        {
            Assembly assembly;
            var serviceMethodList = new ServiceMethodList();
            if(TryLoadAssembly(assemblyLocation, assemblyName, out assembly))
            {
                var type = assembly.GetType(fullName);
                var methodInfos = type.GetMethods();

                methodInfos.ToList().ForEach(info =>
                {
                    var serviceMethod = new ServiceMethod { Name = info.Name };
                    var parameterInfos = info.GetParameters().ToList();
                    parameterInfos.ForEach(parameterInfo =>
                        serviceMethod.Parameters.Add(
                            new MethodParameter
                            {
                                DefaultValue = parameterInfo.DefaultValue==null ? string.Empty : parameterInfo.DefaultValue.ToString(),
                                EmptyToNull = false,
                                IsRequired = true,
                                Name = parameterInfo.Name,
                                Type = parameterInfo.ParameterType
                            }));
                    serviceMethodList.Add(serviceMethod);
                });
            }

            return serviceMethodList;
        }