public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            var serializer = new Dev2JsonSerializer();

            try
            {
                var dbSource = serializer.Deserialize <ComPluginSourceDefinition>(values["source"]);
                // ReSharper disable MaximumChainedReferences
                ComPluginServices services = new ComPluginServices();
                var src     = ResourceCatalog.Instance.GetResource <ComPluginSource>(GlobalConstants.ServerWorkspaceID, dbSource.Id);
                var methods = services.Namespaces(src, Guid.Empty, Guid.Empty).Select(a => a as INamespaceItem).ToList();
                return(serializer.SerializeToBuilder(new ExecuteMessage()
                {
                    HasError = false,
                    Message = serializer.SerializeToBuilder(methods)
                }));
                // ReSharper restore MaximumChainedReferences
            }
            catch (Exception e)
            {
                return(serializer.SerializeToBuilder(new ExecuteMessage()
                {
                    HasError = true,
                    Message = new StringBuilder(e.Message)
                }));
            }
        }
        public void ComPluginServicesMethodsWithInvalidArgsExpectedReturnsEmptyList()
        {
            var services = new ComPluginServices();
            var result   = services.Methods(new ComPluginService(), Guid.Empty, Guid.Empty);

            Assert.AreEqual(0, result.Count);
        }
        public void ComPluginServicesNamespacesWithNullArgsExpectedReturnsEmptyList()
        {
            var services = new ComPluginServices();
            var result   = services.Namespaces(null, Guid.Empty, Guid.Empty);

            Assert.AreEqual(0, result.Count);
        }
        public 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"]);
                // ReSharper disable MaximumChainedReferences
                ComPluginServices services = new ComPluginServices();
                var src = ResourceCatalog.Instance.GetResource <ComPluginSource>(GlobalConstants.ServerWorkspaceID, pluginSource.Id);
                //src.AssemblyName = ns.FullName;
                ComPluginService svc = new ComPluginService();
                if (ns != null)
                {
                    svc.Namespace = ns.FullName; svc.Source = src;
                }
                else
                {
                    svc.Source = src;
                }
                var serviceMethodList = services.Methods(svc, Guid.Empty, Guid.Empty);
                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)
                }));
            }
        }
        public void ComPluginServicesMethodsWithValidArgsExpectedReturnsList()
        {
            var service     = CreatePluginService();
            var workspaceID = Guid.NewGuid();

            EnvironmentVariables.GetWorkspacePath(workspaceID);

            var services = new ComPluginServices();
            var result   = services.Methods(service, workspaceID, Guid.Empty);

            Assert.IsTrue(result.Count > 5, "Not enough items in COM server method list.");
        }
        public void ComPluginServicesMethodsWithValidArgsExpectedReturnsList()
        {
            var service     = CreatePluginService();
            var workspaceID = Guid.NewGuid();

            EnvironmentVariables.GetWorkspacePath(workspaceID);

            var services = new ComPluginServices();
            var result   = services.Methods(service, workspaceID, Guid.Empty);

            Assert.AreEqual(55, result.Count);
        }
        public void ComPluginServicesNamespacesWithValidArgsExpectedReturnsList()
        {
            var source      = CreatePluginSource();
            var args        = source.ToString();
            var workspaceID = Guid.NewGuid();

            EnvironmentVariables.GetWorkspacePath(workspaceID);

            var services = new ComPluginServices();
            var result   = services.Namespaces(source, workspaceID, Guid.Empty);

            Assert.IsTrue(result.Count > 0);
        }
        public void ComPluginServices_Test_WhenTestingPluginReturningJsonString_ExpectValidPaths()
        {
            var pluginServices = new ComPluginServices();
            var serviceDef     = JsonResource.Fetch("ComPrimitivePluginReturningJsonString");

            //------------Execute Test---------------------------
            try
            {
                pluginServices.Test(serviceDef, out string serializedResult);
            }
            catch (Exception e)
            {
                Assert.AreEqual("[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified", e.InnerException.Message);
            }
        }
        public void ComPluginServices_Test_WhenTestingPluginReturningJsonString_ExpectValidPaths()
        {
            var pluginServices = new ComPluginServices();
            var serviceDef     = JsonResource.Fetch("ComPrimitivePluginReturningJsonString");

            //------------Execute Test---------------------------
            try
            {
                string serializedResult;
                pluginServices.Test(serviceDef, out serializedResult);
            }
            catch (Exception e)
            {
                //Calls the execution correctly;
                // ReSharper disable once PossibleNullReferenceException
                Assert.AreEqual("[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified", e.InnerException.Message);
            }
        }
Exemple #10
0
        public override StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            var serializer = new Dev2JsonSerializer();

            try
            {
                var dbSource = serializer.Deserialize <ComPluginSourceDefinition>(values["source"]);

                var services = new ComPluginServices();
                var src      = ResourceCatalog.Instance.GetResource <ComPluginSource>(GlobalConstants.ServerWorkspaceID, dbSource.Id);
                var methods  = new List <INamespaceItem>();
                var task     = Task.Run(() =>
                {
                    return(methods = services.Namespaces(src, Guid.Empty, Guid.Empty).Select(a => a as INamespaceItem).ToList());
                });
                try
                {
                    var timeoutAfter = task.TimeoutAfter(TimeSpan.FromSeconds(3));
                    methods = timeoutAfter.Result;
                }
                catch (Exception e)
                {
                    Dev2Logger.Error(e, GlobalConstants.WarewolfError);
                }

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