// 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);
        }
Пример #2
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);
        }
Пример #3
0
 protected bool GetCachedResult(DbSource dbSource, out ServiceMethodList cacheResult)
 {
     TheCache.TryGetValue(dbSource.ConnectionString, out cacheResult);
     if (cacheResult != null)
     {
         return(true);
     }
     return(false);
 }
        /// <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);
        }
Пример #5
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);
        }
Пример #6
0
        // POST: Service/PluginServices/Methods
        public ServiceMethodList Methods(ComPluginService args, Guid workspaceId, Guid dataListId)
        {
            var result = new ServiceMethodList();

            try
            {
                var broker          = new ComPluginBroker();
                var comPluginSource = (ComPluginSource)args.Source;
                result = broker.GetMethods(comPluginSource.ClsId, comPluginSource.Is32Bit);
                return(result);
            }
            catch (Exception ex)
            {
                RaiseError(ex);
            }
            return(result);
        }
Пример #7
0
        // POST: Service/PluginServices/MethodsWithReturns
        public ServiceMethodList MethodsWithReturns(PluginService service, Guid workspaceId, Guid dataListId)
        {
            var result = new ServiceMethodList();

            try
            {
                // BUG 9500 - 2013.05.31 - TWR : changed to use PluginService as args

                var broker = new PluginBroker();
                result = broker.GetMethodsWithReturns(((PluginSource)service.Source).AssemblyLocation, ((PluginSource)service.Source).AssemblyName, service.Namespace);
                return(result);
            }
            catch (Exception ex)
            {
                RaiseError(ex);
            }
            return(result);
        }
Пример #8
0
        // POST: Service/PluginServices/Methods
        public ServiceMethodList Methods(string args, Guid workspaceId, Guid dataListId)
        {
            var result = new ServiceMethodList();

            try
            {
                // BUG 9500 - 2013.05.31 - TWR : changed to use PluginService as args
                var service = JsonConvert.DeserializeObject <PluginService>(args);
                var broker  = new PluginBroker();
                result = broker.GetMethods(((PluginSource)service.Source).AssemblyLocation, ((PluginSource)service.Source).AssemblyName, service.Namespace);
                return(result);
            }
            catch (Exception ex)
            {
                RaiseError(ex);
            }
            return(result);
        }
Пример #9
0
        // POST: Service/PluginServices/Methods
        public ServiceMethodList Methods(string args, Guid workspaceId, Guid dataListId)
        {
            var result = new ServiceMethodList();

            try
            {
                // BUG 9500 - 2013.05.31 - TWR : changed to use PluginService as args
                var service = JsonConvert.DeserializeObject <PluginService>(args);
                var pluginSourceFromCatalog = _resourceCatalog.GetResource <PluginSource>(workspaceId, service.Source.ResourceID);
                if (pluginSourceFromCatalog == null)
                {
                    try
                    {
                        var xmlStr = Resources.ReadXml(workspaceId, ResourceType.PluginSource, service.Source.ResourceID.ToString());
                        if (!string.IsNullOrEmpty(xmlStr))
                        {
                            var xml = XElement.Parse(xmlStr);
                            pluginSourceFromCatalog = new PluginSource(xml);
                        }
                    }
                    catch (Exception)
                    {
                        //ignore this
                    }
                }
                if (pluginSourceFromCatalog != null)
                {
                    service.Source = pluginSourceFromCatalog;
                }
                var broker       = new PluginBroker();
                var pluginSource = (PluginSource)service.Source;
                if (pluginSource != null)
                {
                    result = broker.GetMethods(pluginSource.AssemblyLocation, pluginSource.AssemblyName, service.Namespace);
                }
                return(result);
            }
            catch (Exception ex)
            {
                RaiseError(ex);
            }
            return(result);
        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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;
 }
Пример #13
0
        public override 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>, IList <IDbDataParameter>, string, string, bool> procedureFunc = (command, parameters, outparameters, helpText, executeAction) =>
            {
                var serviceMethod = CreateServiceMethod(command, parameters, outparameters, helpText, executeAction);
                serviceMethods.Add(serviceMethod);
                return(true);
            };

            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);
            };

            using (var server = CreateDbServer(dbSource))
            {
                server.Connect(dbSource.ConnectionString);
                server.FetchStoredProcedures(procedureFunc, functionFunc, false, dbSource.DatabaseName);
            }

            TheCache.AddOrUpdate(dbSource.ConnectionString, serviceMethods, (s, list) => serviceMethods);

            return(GetCachedResult(dbSource, out cacheResult) ? cacheResult : serviceMethods);
        }
Пример #14
0
        static void ServiceMethodList(ref List <ServiceMethod> serviceMethodList, ServiceMethodList orderMethodsList, List <MethodInfoTO> ipcMethods)
        {
            foreach (MethodInfoTO ipcMethod in ipcMethods)
            {
                var parameterInfos = ipcMethod.Parameters;
                var serviceMethod  = new ServiceMethod {
                    Name = ipcMethod.Name
                };
                foreach (var parameterInfo in parameterInfos)
                {
                    serviceMethod.Parameters.Add(new MethodParameter
                    {
                        DefaultValue = parameterInfo.DefaultValue?.ToString() ?? string.Empty,
                        EmptyToNull  = false,
                        IsRequired   = true,
                        Name         = parameterInfo.Name,
                        TypeName     = parameterInfo.TypeName
                    });
                }
                serviceMethodList.Add(serviceMethod);
            }

            orderMethodsList.AddRange(serviceMethodList.OrderBy(method => method.Name));
        }
Пример #15
0
        public override StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            var serializer = new Dev2JsonSerializer();

            try
            {
                var pluginSource = serializer.Deserialize <ComPluginSourceDefinition>(values["source"]);
                var ns           = serializer.Deserialize <INamespaceItem>(values["namespace"]);

                var services = new ComPluginServices();
                var src      = ResourceCatalog.Instance.GetResource <ComPluginSource>(GlobalConstants.ServerWorkspaceID, pluginSource.Id);
                var svc      = new ComPluginService();
                if (ns != null)
                {
                    svc.Namespace = ns.FullName;
                    svc.Source    = src;
                }
                else
                {
                    svc.Source = src;
                }


                var serviceMethodList = new ServiceMethodList();
                var task = Task.Run(() =>
                {
                    return(serviceMethodList = services.Methods(svc, Guid.Empty, Guid.Empty));
                });
                try
                {
                    var timeoutAfter = task.TimeoutAfter(TimeSpan.FromSeconds(3));
                    serviceMethodList = timeoutAfter.Result;
                }
                catch (Exception e)
                {
                    Dev2Logger.Error(e, GlobalConstants.WarewolfError);
                }


                var methods = serviceMethodList.Select(a => new PluginAction
                {
                    FullName = ns?.FullName,
                    Inputs   = a.Parameters.Select(x =>
                                                   new ServiceInput(x.Name, x.DefaultValue ?? "")
                    {
                        Name = BuildServiceInputName(x.Name, x.TypeName)
                        ,
                        EmptyIsNull = x.EmptyToNull
                        ,
                        RequiredField = x.IsRequired
                        ,
                        TypeName = x.TypeName
                    } as IServiceInput).ToList(),
                    Method    = a.Name,
                    Variables = a.Parameters.Select(x => new NameValue {
                        Name = x.Name + " (" + x.TypeName + ")", Value = ""
                    } as INameValue).ToList(),
                } as IPluginAction).ToList();
                return(serializer.SerializeToBuilder(new ExecuteMessage
                {
                    HasError = false,
                    Message = serializer.SerializeToBuilder(methods)
                }));
            }
            catch (Exception e)
            {
                return(serializer.SerializeToBuilder(new ExecuteMessage()
                {
                    HasError = true,
                    Message = new StringBuilder(e.Message)
                }));
            }
        }
Пример #16
0
 // POST: Service/PluginServices/Methods
 public ServiceMethodList Methods(string args, Guid workspaceId, Guid dataListId)
 {
     var result = new ServiceMethodList();
     try
     {
         // BUG 9500 - 2013.05.31 - TWR : changed to use PluginService as args 
         var service = JsonConvert.DeserializeObject<PluginService>(args);
         var pluginSourceFromCatalog = _resourceCatalog.GetResource<PluginSource>(workspaceId, service.Source.ResourceID);
         if (pluginSourceFromCatalog == null)
         {
             try
             {
                 var xmlStr = Resources.ReadXml(workspaceId, ResourceType.PluginSource, service.Source.ResourceID.ToString());
                 if (!string.IsNullOrEmpty(xmlStr))
                 {
                     var xml = XElement.Parse(xmlStr);
                     pluginSourceFromCatalog = new PluginSource(xml);
                 }
             }
             catch(Exception)
             {
                 //ignore this
             }
         }
         if (pluginSourceFromCatalog != null)
         {
             service.Source = pluginSourceFromCatalog;
         }
         var broker = new PluginBroker();
         var pluginSource = (PluginSource)service.Source;
         if(pluginSource != null)
         {
             result = broker.GetMethods(pluginSource.AssemblyLocation, pluginSource.AssemblyName, service.Namespace);
         }
         return result;
     }
     catch(Exception ex)
     {
         RaiseError(ex);
     }
     return result;
 }
// ReSharper disable InconsistentNaming
        public void AbstractDataBaseBroker_GetServiceMethods_WhenCachedNoRefreshRequested_FreshResults()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            TestDatabaseBroker broker = new TestDatabaseBroker();

            DbSource source = new DbSource { ReloadActions = true };

            TestDatabaseBroker.TheCache = new ConcurrentDictionary<string, ServiceMethodList>();
            var methodList = new ServiceMethodList { new ServiceMethod("bob", "bob src", null, 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(0, result.Count);
        }
        /// <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;
        }