예제 #1
0
        public void PluginServicesMethodsWithInvalidArgsExpectedReturnsEmptyList()
        {
            var services = new PluginServices();
            var result   = services.Methods(new PluginService(), 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 <PluginSourceDefinition>(values["source"]);
                var ns           = serializer.Deserialize <INamespaceItem>(values["namespace"]);
                // ReSharper disable MaximumChainedReferences
                PluginServices services = new PluginServices();
                var            src      = ResourceCatalog.Instance.GetResource <PluginSource>(GlobalConstants.ServerWorkspaceID, pluginSource.Id);
                //src.AssemblyName = ns.FullName;
                if (ns != null)
                {
                    PluginService svc = new PluginService {
                        Namespace = ns.FullName, 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 = x.Name, 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)
                    }));
                }
                // ReSharper disable once RedundantIfElseBlock
                else
                {
                    return(serializer.SerializeToBuilder(new ExecuteMessage()
                    {
                        HasError = false,
                        Message = serializer.SerializeToBuilder(new List <IPluginAction>())
                    }));
                }

                // ReSharper restore MaximumChainedReferences
            }
            catch (Exception e)
            {
                return(serializer.SerializeToBuilder(new ExecuteMessage
                {
                    HasError = true,
                    Message = new StringBuilder(e.Message)
                }));
            }
        }
예제 #3
0
        public void PluginServicesMethodsWithValidArgsExpectedReturnsList()
        {
            var service     = CreatePluginService();
            var workspaceID = Guid.NewGuid();

            EnvironmentVariables.GetWorkspacePath(workspaceID);

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

            Assert.AreEqual(9, result.Count);
        }