Example #1
0
        public IOutputDescription GetOutputDescription()
        {
            IOutputDescription result = null;
            var dataSourceShape       = DataSourceShapeFactory.CreateDataSourceShape();

            var requestResponse = Scrubber.Scrub(RequestResponse);

            try
            {
                result          = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
                dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();
                result.DataSourceShapes.Add(dataSourceShape);
                var dataBrowser = DataBrowserFactory.CreateDataBrowser();
                dataSourceShape.Paths.AddRange(dataBrowser.Map(requestResponse));
            }

            catch (Exception ex)
            {
                var dataBrowser = DataBrowserFactory.CreateDataBrowser();
                var errorResult = new XElement("Error");
                errorResult.Add(ex);
                var data = errorResult.ToString();
                dataSourceShape.Paths.AddRange(dataBrowser.Map(data));
            }
            return(result);
        }
        public void SerializeOutputDescriptionWithXMLPaths_Expected_DeserializationToWork()
        {
            IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();

            dataSourceShape.Paths.Add(new XmlPath("Company:Name", "Company:Name", "[[Names().CompanyName]]"));
            dataSourceShape.Paths.Add(new XmlPath("Company.Departments().Department:Name", "Company.Departments.Department:Name", "[[Names().DepartmentName]]"));
            dataSourceShape.Paths.Add(new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name", "[[Names().EmployeeName]]"));

            IOutputDescription testOutputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);

            testOutputDescription.DataSourceShapes.Add(dataSourceShape);

            IOutputDescriptionSerializationService outputDescriptionSerializationService = OutputDescriptionSerializationServiceFactory.CreateOutputDescriptionSerializationService();

            string             serializedData = outputDescriptionSerializationService.Serialize(testOutputDescription);
            IOutputDescription deserializedOutputDescription = outputDescriptionSerializationService.Deserialize(serializedData);

            string expected = testOutputDescription.Format.ToString() + "^" +
                              string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.ActualPath)) + "^" +
                              string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.DisplayPath)) + "^" +
                              string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.OutputExpression));

            string actual = deserializedOutputDescription.Format.ToString() + "^" +
                            string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.ActualPath)) + "^" +
                            string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.DisplayPath)) + "^" +
                            string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.OutputExpression));

            Assert.AreEqual(expected, actual);
        }
        public void SerializeOutputDescriptionWithJSONPaths_Expected_DeserializationToWork()
        {
            IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();

            dataSourceShape.Paths.Add(new JsonPath("Name", "Name", "[[ScalarName]]"));
            dataSourceShape.Paths.Add(new JsonPath("Departments().Name", "Departments.Name", "[[Names().DepartmentName]]"));
            dataSourceShape.Paths.Add(new JsonPath("Departments().Employees().Name", "Departments.Employees.Name", "[[Names().EmployeeName]]"));
            dataSourceShape.Paths.Add(new JsonPath("PrimitiveRecordset()", "PrimitiveRecordset", "[[OtherNames().Name]]"));

            IOutputDescription testOutputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);

            testOutputDescription.DataSourceShapes.Add(dataSourceShape);

            IOutputDescriptionSerializationService outputDescriptionSerializationService = OutputDescriptionSerializationServiceFactory.CreateOutputDescriptionSerializationService();

            string             serializedData = outputDescriptionSerializationService.Serialize(testOutputDescription);
            IOutputDescription deserializedOutputDescription = outputDescriptionSerializationService.Deserialize(serializedData);

            string expected = testOutputDescription.Format.ToString() + "^" +
                              string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.ActualPath)) + "^" +
                              string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.DisplayPath)) + "^" +
                              string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.OutputExpression));

            string actual = deserializedOutputDescription.Format.ToString() + "^" +
                            string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.ActualPath)) + "^" +
                            string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.DisplayPath)) + "^" +
                            string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.OutputExpression));

            Assert.AreEqual(expected, actual);
        }
Example #4
0
        public virtual IOutputDescription TestService(DbService dbService)
        {
            VerifyArgument.IsNotNull("dbService", dbService);
            VerifyArgument.IsNotNull("dbService.Source", dbService.Source);

            IOutputDescription result;

            using (var server = CreateDbServer(dbService.Source as DbSource))
            {
                server.Connect(((DbSource)dbService.Source).ConnectionString);
                server.BeginTransaction();
                try
                {
                    var command   = CommandFromServiceMethod(server, dbService.Method);
                    var dataTable = server.FetchDataTable(command);

                    result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
                    var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();
                    result.DataSourceShapes.Add(dataSourceShape);

                    var dataBrowser = DataBrowserFactory.CreateDataBrowser();
                    dataSourceShape.Paths.AddRange(dataBrowser.Map(dataTable));
                }
                catch (Exception ex)
                {
                    throw new WarewolfDbException(ex.Message);
                }
                finally
                {
                    server.RollbackTransaction();
                }
            }

            return(result);
        }
Example #5
0
        public IOutputDescription Test(PluginInvokeArgs setupInfo)
        {
            Assembly loadedAssembly;

            if (!TryLoadAssembly(setupInfo.AssemblyLocation, setupInfo.AssemblyName, out loadedAssembly))
            {
                return(null);
            }

            var parameters = BuildParameterList(setupInfo.Parameters);
            var typeList   = BuildTypeList(setupInfo.Parameters);

            var type         = loadedAssembly.GetType(setupInfo.Fullname);
            var methodToRun  = type.GetMethod(setupInfo.Method, typeList);
            var instance     = Activator.CreateInstance(type);
            var pluginResult = methodToRun.Invoke(instance, parameters);

            // do formating here to avoid object serialization issues ;)
            var dataBrowser     = DataBrowserFactory.CreateDataBrowser();
            var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();

            if (pluginResult != null)
            {
                pluginResult = AdjustPluginResult(pluginResult, methodToRun);

                var tmpData = dataBrowser.Map(pluginResult);
                dataSourceShape.Paths.AddRange(tmpData);
            }

            var result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);

            result.DataSourceShapes.Add(dataSourceShape);

            return(result);
        }
        public void SerializeOutputDescriptionWithPocoPaths_Expected_DeserializationToWork()
        {
            var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();

            dataSourceShape.Paths.Add(new PocoPath("Name", "Name", "[[Names().CompanyName]]"));
            dataSourceShape.Paths.Add(new PocoPath("Departments().Name", "Departments.Name", "[[Names().DepartmentName]]"));
            dataSourceShape.Paths.Add(new PocoPath("Departments().Employees().Name", "Departments.Employees.Name", "[[Names().EmployeeName]]"));

            var testOutputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);

            testOutputDescription.DataSourceShapes.Add(dataSourceShape);

            var outputDescriptionSerializationService = OutputDescriptionSerializationServiceFactory.CreateOutputDescriptionSerializationService();

            var serializedData = outputDescriptionSerializationService.Serialize(testOutputDescription);
            var deserializedOutputDescription = outputDescriptionSerializationService.Deserialize(serializedData);

            var expected = testOutputDescription.Format + "^" +
                           string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.ActualPath)) + "^" +
                           string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.DisplayPath)) + "^" +
                           string.Join("|", testOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.OutputExpression));

            var actual = deserializedOutputDescription.Format + "^" +
                         string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.ActualPath)) + "^" +
                         string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.DisplayPath)) + "^" +
                         string.Join("|", deserializedOutputDescription.DataSourceShapes.SelectMany(d => d.Paths).Select(p => p.OutputExpression));

            Assert.AreEqual(expected, actual);
        }
Example #7
0
        public IOutputDescription Test(ComPluginInvokeArgs setupInfo, out string serializedResult)
        {
            try
            {
                serializedResult = null;

                var methodToRun = ExecuteComPlugin(setupInfo, out object pluginResult);

                // do formating here to avoid object serialization issues ;)
                var dataBrowser     = DataBrowserFactory.CreateDataBrowser();
                var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();

                if (pluginResult != null)
                {
                    if (pluginResult is KeyValuePair <bool, string> )
                    {
                        var pluginKeyValuePair = (KeyValuePair <bool, string>)pluginResult;
                        serializedResult = "Exception: " + pluginKeyValuePair.Value;
                    }
                    else
                    {
                        serializedResult = pluginResult.ToString();
                    }
                    pluginResult = AdjustPluginResult(pluginResult);
                    var tmpData = dataBrowser.Map(pluginResult);
                    dataSourceShape.Paths.AddRange(tmpData);
                }

                var result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
                result.DataSourceShapes.Add(dataSourceShape);
                return(result);
            }
            catch (COMException e)
            {
                Dev2Logger.Error("IOutputDescription Test(PluginInvokeArgs setupInfo)", e, GlobalConstants.WarewolfError);
                throw;
            }
            catch (Exception e)
            {
                if (e.InnerException is COMException)
                {
                    throw e.InnerException;
                }

                Dev2Logger.Error("IOutputDescription Test(PluginInvokeArgs setupInfo)", e, GlobalConstants.WarewolfError);
                serializedResult = null;
                return(null);
            }
        }
        public override IOutputDescription TestService(DbService dbService)
        {
            VerifyArgument.IsNotNull("dbService", dbService);
            VerifyArgument.IsNotNull("dbService.Source", dbService.Source);

            IOutputDescription result;

            using (var server = CreateDbServer(dbService.Source as DbSource))
            {
                server.Connect(((DbSource)dbService.Source).ConnectionString);
                server.BeginTransaction();
                try
                {
                    var command = CommandFromServiceMethod(server, dbService.Method);

                    var outParams = server.GetProcedureOutParams(command.CommandText);

                    foreach (var dbDataParameter in outParams)
                    {
                        if (command.Parameters.Contains(dbDataParameter))
                        {
                            continue;
                        }

                        command.Parameters.Add(dbDataParameter);
                    }
                    var dataTable = server.FetchDataTable(command);

                    result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
                    var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();
                    result.DataSourceShapes.Add(dataSourceShape);

                    var dataBrowser = DataBrowserFactory.CreateDataBrowser();
                    dataSourceShape.Paths.AddRange(dataBrowser.Map(dataTable));
                }
                catch (Exception ex)
                {
                    Dev2Logger.Error(ex.Message, GlobalConstants.WarewolfError);
                    throw;
                }
                finally
                {
                    server.RollbackTransaction();
                }
            }

            return(result);
        }
        public override IOutputDescription TestService(DbService dbService)
        {
            VerifyArgument.IsNotNull("dbService", dbService);
            VerifyArgument.IsNotNull("dbService.Source", dbService.Source);

            IOutputDescription result;

            using (var server = CreateDbServer(dbService.Source as DbSource))
            {
                server.Connect(((DbSource)dbService.Source).ConnectionString);
                server.BeginTransaction();
                try
                {
                    //
                    // Execute command and normalize XML
                    //
                    var command = CommandFromServiceMethod(server, dbService.Method);
                    // ReSharper disable PossibleNullReferenceException
                    var outParams = server.GetProcedureOutParams(dbService.Method.Name, (dbService.Source as DbSource).DatabaseName);
                    // ReSharper restore PossibleNullReferenceException
                    foreach (var dbDataParameter in outParams)
                    {
                        command.Parameters.Add(dbDataParameter);
                    }
                    var dataTable = server.FetchDataTable(command);

                    //
                    // Map shape of XML
                    //
                    result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
                    var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();
                    result.DataSourceShapes.Add(dataSourceShape);

                    var dataBrowser = DataBrowserFactory.CreateDataBrowser();
                    dataSourceShape.Paths.AddRange(dataBrowser.Map(dataTable));
                }
                finally
                {
                    server.RollbackTransaction();
                }
            }

            return(result);
        }
        public IOutputDescription Test(PluginInvokeArgs setupInfo, out string jsonResult)
        {
            try
            {
                Assembly loadedAssembly;
                jsonResult        = null;
                _assemblyLocation = setupInfo.AssemblyLocation;
                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
                if (!_assemblyLoader.TryLoadAssembly(setupInfo.AssemblyLocation, setupInfo.AssemblyName, out loadedAssembly))
                {
                    return(null);
                }
                object pluginResult;
                var    methodToRun = ExecutePlugin(setupInfo, loadedAssembly, out pluginResult);

                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
                // do formating here to avoid object serialization issues ;)
                var dataBrowser     = DataBrowserFactory.CreateDataBrowser();
                var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();

                if (pluginResult != null)
                {
                    jsonResult   = JsonConvert.SerializeObject(pluginResult);
                    pluginResult = AdjustPluginResult(pluginResult, methodToRun);
                    var tmpData = dataBrowser.Map(pluginResult);
                    dataSourceShape.Paths.AddRange(tmpData);
                }

                var result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
                result.DataSourceShapes.Add(dataSourceShape);
                return(result);
            }
            catch (Exception e)
            {
                Dev2Logger.Error("IOutputDescription Test(PluginInvokeArgs setupInfo)", e);
                jsonResult = null;
                return(null);
            }
        }
Example #11
0
        public IOutputDescription ExecuteWebService(WcfService src)
        {
            var source  = (WcfSource)src.Source;
            var factory = new DynamicProxyFactory(source.EndpointUrl);

            var contract = factory.Contracts.FirstOrDefault();

            if (contract == null)
            {
                throw new DynamicProxyException(ErrorResource.NoContractFound);
            }

            var proxy = factory.CreateProxy(contract.Name);

            var parameters = src.Method.Parameters?.Select(a => new MethodParameter {
                Name = a.Name, Value = a.Value, TypeName = a.TypeName
            })
                             .ToList() ?? new List <MethodParameter>();
            var paramObjects =
                parameters.Select(methodParameter => Convert.ChangeType(methodParameter.Value, Type.GetType(methodParameter.TypeName))).ToArray();

            var result          = proxy.CallMethod(src.Method.Name, paramObjects);
            var dataBrowser     = DataBrowserFactory.CreateDataBrowser();
            var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();
            var method          = GetMethod(src.Method.Name, proxy);

            if (result != null)
            {
                result = AdjustPluginResult(result, method);

                var tmpData = dataBrowser.Map(result);
                dataSourceShape.Paths.AddRange(tmpData);
            }

            var output = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);

            output.DataSourceShapes.Add(dataSourceShape);
            return(output);
        }
Example #12
0
        public override IOutputDescription TestSqliteService(SqliteDBService dbService)
        {
            VerifyArgument.IsNotNull("SqliteDBService", dbService);
            VerifyArgument.IsNotNull("SqliteDBService.Source", dbService.Source);

            IOutputDescription result;

            using (var server = CreateSqliteDbServer(dbService.Source as SqliteDBSource))
            {
                server.Connect(((SqliteDBSource)dbService.Source).ConnectionString);
                server.BeginTransaction();
                try
                {
                    //
                    // Execute command and normalize XML
                    //
                    var command = server.CreateCommand();
                    command.CommandText = dbService.Method.QueryString;
                    var dataTable = server.FetchDataTable(command);

                    //
                    // Map shape of XML
                    //

                    result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
                    var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();
                    result.DataSourceShapes.Add(dataSourceShape);

                    var dataBrowser = DataBrowserFactory.CreateDataBrowser();
                    dataSourceShape.Paths.AddRange(dataBrowser.Map(dataTable));
                }
                finally
                {
                    server.RollbackTransaction();
                }
            }

            return(result);
        }
Example #13
0
        // BUG 9626 - 2013.06.11 - TWR : refactored
        public IEnumerable <XElement> CreateOutputsXml(IEnumerable <Recordset> recordsets)
        {
            var outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
            var dataSourceShape   = DataSourceShapeFactory.CreateDataSourceShape();

            outputDescription.DataSourceShapes.Add(dataSourceShape);

            var outputs = new XElement("Outputs");

            if (recordsets != null)
            {
                foreach (var recordset in recordsets)
                {
                    var rsName = string.IsNullOrEmpty(recordset.Name) ? "" : recordset.Name.Replace("()", "");

                    foreach (var field in recordset.Fields)
                    {
                        if (String.IsNullOrEmpty(field.Name))
                        {
                            continue;
                        }
                        var path    = field.Path;
                        var rsAlias = string.IsNullOrEmpty(field.RecordsetAlias) ? "" : field.RecordsetAlias.Replace("()", "");

                        var value = string.Empty;
                        if (!string.IsNullOrEmpty(field.Alias))
                        {
                            value = string.IsNullOrEmpty(rsAlias)
                                        ? string.Format("[[{0}]]", field.Alias)
                                        : string.Format("[[{0}().{1}]]", rsAlias, field.Alias);
                        }

                        if (path != null)
                        {
                            path.OutputExpression = value;
                            dataSourceShape.Paths.Add(path);
                        }

                        // MapsTo MUST NOT contain recordset name
                        var mapsTo = field.Alias ?? string.Empty;
                        var idx    = mapsTo.IndexOf("().", StringComparison.InvariantCultureIgnoreCase);
                        if (idx != -1)
                        {
                            mapsTo = mapsTo.Substring(idx + 3);
                        }


                        var output = new XElement("Output",
                                                  new XAttribute("OriginalName", field.Name),
                                                  new XAttribute("Name", mapsTo), // Name MUST be same as MapsTo
                                                  new XAttribute("MapsTo", mapsTo),
                                                  new XAttribute("Value", value),
                                                  new XAttribute("RecordsetName", rsName),
                                                  new XAttribute("RecordsetAlias", rsAlias),
                                                  new XAttribute("Recordset", rsAlias) // legacy - used by LanguageParser._recordSetAttribute and hard-coded in our tests
                                                  );
                        outputs.Add(output);
                    }
                }
            }

            var outputDescriptionSerializationService = OutputDescriptionSerializationServiceFactory.CreateOutputDescriptionSerializationService();
            var serializedOutputDescription           = outputDescriptionSerializationService.Serialize(outputDescription);

            var description = new XElement("OutputDescription", new XCData(serializedOutputDescription));

            return(new[] { outputs, description });
        }
Example #14
0
        public override IOutputDescription TestService(DbService dbService)
        {
            VerifyArgument.IsNotNull("dbService", dbService);
            VerifyArgument.IsNotNull("dbService.Source", dbService.Source);

            IOutputDescription result;

            using (var server = CreateDbServer(dbService.Source as DbSource))
            {
                server.Connect(((DbSource)dbService.Source).ConnectionString);
                server.BeginTransaction();
                try
                {
                    //
                    // Execute command and normalize XML
                    //
                    var command = CommandFromServiceMethod(server, dbService.Method);



                    var databaseName      = (dbService.Source as DbSource).DatabaseName;
                    var fullProcedureName = dbService.Method.ExecuteAction.Substring(dbService.Method.ExecuteAction.IndexOf(".", StringComparison.Ordinal) + 1);


                    var outParams         = server.GetProcedureOutParams(fullProcedureName, databaseName);
                    var countRefCursors   = outParams.Count(parameter => parameter.OracleDbType == OracleDbType.RefCursor);
                    var countSingleParams = outParams.Count(parameter => parameter.OracleDbType != OracleDbType.RefCursor);
                    if (countRefCursors > 1)
                    {
                        throw new Exception("Multiple Ref Cursor are not currently supported.");
                    }
                    if (countRefCursors >= 1 && countSingleParams >= 1)
                    {
                        throw new Exception("Mixing single return values and Ref Cursors are not currently supported.");
                    }
                    var dbDataParameters = server.GetProcedureInputParameters(command, databaseName, fullProcedureName);
                    var cmd = command.Connection.CreateCommand();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = databaseName + "." + fullProcedureName;
                    var parameters = dbService.Method.Parameters;
                    foreach (var dbDataParameter in dbDataParameters)
                    {
                        var foundParameter = parameters.FirstOrDefault(parameter => parameter.Name == dbDataParameter.ParameterName);
                        if (foundParameter != null)
                        {
                            dbDataParameter.Value = foundParameter.Value;
                        }
                        cmd.Parameters.Add(dbDataParameter);
                    }



                    foreach (var dbDataParameter in outParams)
                    {
                        cmd.Parameters.Add(dbDataParameter);
                    }
                    var dataTable = server.FetchDataTable(cmd);

                    //
                    // Map shape of XML
                    //
                    result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
                    var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();
                    result.DataSourceShapes.Add(dataSourceShape);

                    var dataBrowser = DataBrowserFactory.CreateDataBrowser();
                    dataSourceShape.Paths.AddRange(dataBrowser.Map(dataTable));
                    cmd.Dispose();
                }
                finally
                {
                    server.RollbackTransaction();
                }
            }

            return(result);
        }