public IResponseManager New(IOutputDescription outputDescription)
 {
     return(new ResponseManager
     {
         OutputDescription = outputDescription
     });
 }
示例#2
0
        /// <summary>
        ///     Deserialize the given data to an output description
        /// </summary>
        public IOutputDescription Deserialize(string data)
        {
            IOutputDescription outputDescription = null;

            if (!string.IsNullOrWhiteSpace(data))
            {
                data = data.Replace("<![CDATA[", "");
                data = data.Replace("]]>", "");

                var dataContractSerializer = new DataContractSerializer(typeof(IOutputDescription), _knownTypes);

                using (var stringReader = new StringReader(StripKnownLegacyTags(data)))
                {
                    using (var xmlTextReader = new XmlTextReader(stringReader))
                    {
                        try
                        {
                            outputDescription = dataContractSerializer.ReadObject(xmlTextReader) as IOutputDescription;
                        }
                        catch (Exception ex)
                        {
                            Dev2Logger.Log.Error(ex);
                            // we want to return null
                        }
                    }
                }
            }

            return(outputDescription);
        }
示例#3
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);
        }
示例#4
0
        // ReSharper disable InconsistentNaming
        public void SqlDatabaseBroker_TestService_ValidDbServiceThatReturnsNull_RecordsetWithNullColumn()
        // ReSharper restore InconsistentNaming
        {
            var service = new DbService
            {
                ResourceID   = Guid.NewGuid(),
                ResourceName = "NullService",
                ResourceType = ResourceType.DbService,
                ResourcePath = "Test",
                Method       = new ServiceMethod
                {
                    Name          = "Pr_GeneralTestColumnData",
                    Parameters    = new List <MethodParameter>(),
                    ExecuteAction = "Pr_GeneralTestColumnData"
                },
                Recordset = new Recordset
                {
                    Name = "Collections",
                },
                Source = SqlServerTests.CreateDev2TestingDbSource()
            };

            var broker = new SqlDatabaseBroker();
            IOutputDescription outputDescription = broker.TestService(service);

            Assert.AreEqual(1, outputDescription.DataSourceShapes.Count);
            IDataSourceShape dataSourceShape = outputDescription.DataSourceShapes[0];

            Assert.IsNotNull(dataSourceShape);
            Assert.AreEqual(3, dataSourceShape.Paths.Count);
            StringAssert.Contains(dataSourceShape.Paths[2].DisplayPath, "TestTextNull"); //This is the field that contains a null value. Previously this column would not have been returned.
        }
        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);
        }
        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 WhenTheMappingIsGenerated()
        {
            var webService = scenarioContext.Get <Runtime.ServiceModel.Data.WebService>("WebService");
            IOutputDescription outputDescription = webService.GetOutputDescription();

            webService.OutputDescription = outputDescription;
            outputDescription.ToRecordsetList(webService.Recordsets);
        }
        public void ThenTheMappingShouldBe(string resultingMapping)
        {
            var webService = ScenarioContext.Current.Get <ServiceModel.Data.WebService>("WebService");
            IOutputDescription outputDescription = webService.GetOutputDescription();
            var foundValidPath = outputDescription.DataSourceShapes.Find(shape => shape.Paths.Find(path => path.ActualPath == resultingMapping) != null);

            Assert.IsNotNull(foundValidPath);
        }
示例#9
0
        public static IOutputFormatter CreateOutputFormatter(IOutputDescription outputDescription, string rootNodeName)
        {
            IOutputFormatter outputFormatter;

            outputFormatter = outputDescription.Format == OutputFormats.ShapedXML ? new ShapedXmlOutputFormatter(outputDescription, rootNodeName) : null;

            return(outputFormatter);
        }
示例#10
0
        public static IOutputFormatter CreateOutputFormatter(IOutputDescription outputDescription)
        {
            IOutputFormatter outputFormatter;

            outputFormatter = outputDescription.Format == OutputFormats.ShapedXML ? new ShapedXmlOutputFormatter(outputDescription) : null;

            return(outputFormatter);
        }
        public void WhenTheMappingIsGenerated()
        {
            var webService = ScenarioContext.Current.Get <ServiceModel.Data.WebService>("WebService");
            IOutputDescription outputDescription = webService.GetOutputDescription();

            webService.OutputDescription = outputDescription;
            outputDescription.ToRecordsetList(webService.Recordsets);
            webService.OutputSpecification = webService.GetOutputString(webService.Recordsets);
        }
        public void MySqlMapDbOutputs(IOutputDescription outputDescription, ref DbService theService, bool addFields)
        {
            // only fetch paths with valid data to map ;)
            var outputsToMap = outputDescription.DataSourceShapes[0].Paths.Where(p => !string.IsNullOrEmpty(p.DisplayPath) && p.DisplayPath != "DocumentElement");

            var rsFields = new List <RecordsetField>(theService.Recordset.Fields);

#pragma warning disable 219
            int recordsetIndex = 0;
#pragma warning restore 219

            foreach (var path in outputsToMap)
            {
                // Remove bogus names and dots
                var name  = path.DisplayPath.Replace("NewDataSet", "").Replace(".Table.", "").Replace("DocumentElement", "");
                var alias = path.DisplayPath.Replace("NewDataSet", "").Replace(".Table.", "").Replace(".", "").Replace("DocumentElement", "");

                var idx = name.IndexOf("()", StringComparison.InvariantCultureIgnoreCase);
                if (idx >= 0)
                {
                    name = name.Remove(0, idx + 3);
                }
                idx = alias.IndexOf("()", StringComparison.InvariantCultureIgnoreCase);
                if (idx >= 0)
                {
                    alias = alias.Remove(0, idx + 2);
                }
                var field = new RecordsetField {
                    Name = name, Alias = string.IsNullOrEmpty(path.OutputExpression) ? alias : path.OutputExpression, Path = path
                };

                RecordsetField rsField;
                if (!addFields && (rsField = rsFields.FirstOrDefault(f => f.Path != null ? f.Path.ActualPath == path.ActualPath : f.Name == field.Name)) != null)
                {
                    field.Alias = rsField.Alias;
                }

                theService.Recordset.Fields.Add(field);

                // 2013.12.11 - COMMUNITY BUG - 341463 - data with empty cells displays incorrectly
                var data        = path.SampleData.Split(new[] { GlobalConstants.AnytingToXmlCommaToken }, StringSplitOptions.None);
                var recordIndex = 0;

                foreach (var item in data)
                {
                    theService.Recordset.SetValue(recordIndex, recordsetIndex, item);
                    recordIndex++;
                }

                recordsetIndex++;
            }
        }
示例#13
0
 public ServiceMethod(string name, string sourceCode, string queryString, IOutputDescription outputDescription, IEnumerable <MethodOutput> outputs)
 {
     Name              = name;
     SourceCode        = sourceCode;
     QueryString       = queryString;
     OutputDescription = outputDescription;
     OutParameters     = new List <MethodParameter>();
     Outputs           = new List <MethodOutput>();
     if (outputs != null)
     {
         Outputs.AddRange(outputs);
     }
 }
示例#14
0
        public void MySqlMapDbOutputs(IOutputDescription outputDescription, ref DbService theService, bool addFields)
        {

            // only fetch paths with valid data to map ;)
            var outputsToMap = outputDescription.DataSourceShapes[0].Paths.Where(p => !string.IsNullOrEmpty(p.DisplayPath) && p.DisplayPath != "DocumentElement");

            var rsFields = new List<RecordsetField>(theService.Recordset.Fields);
#pragma warning disable 219
            int recordsetIndex = 0;
#pragma warning restore 219

            foreach (var path in outputsToMap)
            {
                // Remove bogus names and dots
                var name = path.DisplayPath.Replace("NewDataSet", "").Replace(".Table.", "").Replace("DocumentElement", "");
                var alias = path.DisplayPath.Replace("NewDataSet", "").Replace(".Table.", "").Replace(".", "").Replace("DocumentElement", "");

                var idx = name.IndexOf("()", StringComparison.InvariantCultureIgnoreCase);
                if (idx >= 0)
                {
                    name = name.Remove(0, idx + 3);
                }
                idx = alias.IndexOf("()", StringComparison.InvariantCultureIgnoreCase);
                if (idx >= 0)
                {
                    alias = alias.Remove(0, idx + 2);
                }
                var field = new RecordsetField { Name = name, Alias = string.IsNullOrEmpty(path.OutputExpression) ? alias : path.OutputExpression, Path = path };

                RecordsetField rsField;
                if (!addFields && (rsField = rsFields.FirstOrDefault(f => f.Path != null ? f.Path.ActualPath == path.ActualPath : f.Name == field.Name)) != null)
                {
                    field.Alias = rsField.Alias;
                }

                theService.Recordset.Fields.Add(field);

                // 2013.12.11 - COMMUNITY BUG - 341463 - data with empty cells displays incorrectly
                var data = path.SampleData.Split(new[] { GlobalConstants.AnytingToXmlCommaToken }, StringSplitOptions.None);
                var recordIndex = 0;

                foreach (var item in data)
                {
                    theService.Recordset.SetValue(recordIndex, recordsetIndex, item);
                    recordIndex++;
                }

                recordsetIndex++;
            }

        }
示例#15
0
        public static IOutputFormatter CreateOutputFormatter(IOutputDescription outputDescription, string rootNodeName)
        {
            IOutputFormatter outputFormatter;

            if (outputDescription.Format == OutputFormats.ShapedXML)
            {
                outputFormatter = new ShapedXmlOutputFormatter(outputDescription, rootNodeName);
            }
            else
            {
                outputFormatter = null;
            }

            return(outputFormatter);
        }
        public static IOutputFormatter CreateOutputFormatter(IOutputDescription outputDescription, string rootNodeName)
        {
            IOutputFormatter outputFormatter;

            if (outputDescription.Format == OutputFormats.ShapedXML)
            {
                outputFormatter = new ShapedXmlOutputFormatter(outputDescription, rootNodeName);
            }
            else
            {
                outputFormatter = null;
            }

            return outputFormatter;
        }
示例#17
0
        public ServiceMethod(string name, string sourceCode, IEnumerable <MethodParameter> parameters, IOutputDescription outputDescription, IEnumerable <MethodOutput> outputs, string executeAction)
        {
            Name              = name;
            SourceCode        = sourceCode;
            OutputDescription = outputDescription;
            Parameters        = new List <MethodParameter>();
            Outputs           = new List <MethodOutput>();
            ExecuteAction     = executeAction;
            if (parameters != null)
            {
                Parameters.AddRange(parameters);
            }

            if (outputs != null)
            {
                Outputs.AddRange(outputs);
            }
        }
示例#18
0
        public void GivenIHaveTheGetCitiesWebservice()
        {
            var webSourceXml = XmlResource.Fetch("Google_Address_Lookup");
            var webSource    = new WebSource(webSourceXml);
            var webService   = new Runtime.ServiceModel.Data.WebService {
                Source = webSource, RequestUrl = webSource.DefaultQuery
            };
            ErrorResultTO errors;

            WebServices.ExecuteRequest(webService, false, out errors);
            IOutputDescription outputDescription = webService.GetOutputDescription();

            webService.OutputDescription = outputDescription;
            outputDescription.ToRecordsetList(webService.Recordsets);
            webService.OutputSpecification = webService.GetOutputString(webService.Recordsets);

            ScenarioContext.Current.Add("WebService", webService);
        }
示例#19
0
        public ServiceMethod(string name, string sourceCode, IEnumerable<MethodParameter> parameters, IOutputDescription outputDescription, IEnumerable<MethodOutput> outputs,string executeAction)
        {
            Name = name;
            SourceCode = sourceCode;
            OutputDescription = outputDescription;
            Parameters = new List<MethodParameter>();
            OutParameters = new List<MethodParameter>();
            Outputs = new List<MethodOutput>();
            ExecuteAction = executeAction;
            if(parameters != null)
            {
                Parameters.AddRange(parameters);
            }

            if(outputs != null)
            {
                Outputs.AddRange(outputs);
            }
        }
示例#20
0
        /// <summary>
        ///     Serializes the given ouput description to XML
        /// </summary>
        public string Serialize(IOutputDescription outputDescription)
        {
            var dataContractSerializer = new DataContractSerializer(typeof(IOutputDescription), _knownTypes);

            string data;

            using (var stringWriter = new StringWriter())
            {
                using (var xmlTextWriter = new XmlTextWriter(stringWriter))
                {
                    dataContractSerializer.WriteObject(xmlTextWriter, outputDescription);

                    data = stringWriter.GetStringBuilder().ToString();

                    xmlTextWriter.Close();
                    stringWriter.Close();
                }
            }

            return(data);
        }
        /// <summary>
        ///     Serializes the given ouput description to XML
        /// </summary>
        public string Serialize(IOutputDescription outputDescription)
        {
            var dataContractSerializer = new DataContractSerializer(typeof (IOutputDescription), _knownTypes);

            string data;

            using (var stringWriter = new StringWriter())
            {
                using (var xmlTextWriter = new XmlTextWriter(stringWriter))
                {
                    dataContractSerializer.WriteObject(xmlTextWriter, outputDescription);

                    data = stringWriter.GetStringBuilder().ToString();

                    xmlTextWriter.Close();
                    stringWriter.Close();
                }
            }

            return data;
        }
 public static RecordsetList ToRecordsetList(this IOutputDescription outputDescription) => outputDescription.ToRecordsetList(null, "");
 public ShapedXmlOutputFormatter(IOutputDescription outputDescription, string rootNodeName)
 {
     RootNodeName      = rootNodeName;
     OutputDescription = outputDescription;
     DataBrowser       = DataBrowserFactory.CreateDataBrowser();
 }
 public ShapedXmlOutputFormatter(IOutputDescription outputDescription)
 {
     RootNodeName = "ADL";
     OutputDescription = outputDescription;
     DataBrowser = DataBrowserFactory.CreateDataBrowser();
 }
 public ShapedXmlOutputFormatter(IOutputDescription outputDescription, string rootNodeName)
 {
     RootNodeName = rootNodeName;
     OutputDescription = outputDescription;
     DataBrowser = DataBrowserFactory.CreateDataBrowser();
 }
示例#26
0
 public ServiceConstructor(string name, IEnumerable <ConstructorParameter> parameters, IOutputDescription outputDescription)
 {
     Name       = name;
     Parameters = new List <ConstructorParameter>();
     if (parameters != null)
     {
         Parameters.AddRange(parameters);
     }
 }
 public ShapedXmlOutputFormatter(IOutputDescription outputDescription)
 {
     RootNodeName      = "ADL";
     OutputDescription = outputDescription;
     DataBrowser       = DataBrowserFactory.CreateDataBrowser();
 }
示例#28
0
        public static RecordsetList ToRecordsetList(this IOutputDescription outputDescription, RecordsetList currentList = null, string defaultFieldName = "")
        {
            if (outputDescription == null || outputDescription.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0)
            {
                throw new Exception("Error retrieving shape from service output.");
            }

            var result        = currentList ?? new RecordsetList();
            var currentFields = new List <RecordsetField>();

            #region Create a copy of the current list's fields so that we don't lose the user-defined aliases.

            foreach (var rs in result)
            {
                currentFields.AddRange(rs.Fields);
                rs.Fields.Clear();
            }

            #endregion

            var paths = outputDescription.DataSourceShapes[0].Paths;

            foreach (var path in paths)
            {
                var names     = SplitRecordsetAndFieldNames(path);
                var rsName    = names.Item1;
                var rsAlias   = rsName;
                var fieldName = names.Item2;
                if (string.IsNullOrEmpty(fieldName) && string.IsNullOrEmpty(defaultFieldName))
                {
                    continue;
                }

                if (string.IsNullOrEmpty(fieldName) && !string.IsNullOrEmpty(defaultFieldName))
                {
                    fieldName = defaultFieldName;
                }

                // Bug 10532 - Amend to remove : from the alias ;)
                var fieldAlias = fieldName.Replace(":", "");

                var pathLoop = path;
                var rsField  = currentFields.FirstOrDefault(f => f.Path == pathLoop) ?? new RecordsetField {
                    Path = path, Alias = fieldAlias, RecordsetAlias = rsAlias
                };
                rsField.Name = fieldName;

                var rs = result.FirstOrDefault(r => r.Name == rsName);
                if (rs == null)
                {
                    rs = new Recordset {
                        Name = rsName
                    };
                    result.Add(rs);
                }
                var fieldIndex = rs.Fields.Count;
                rs.Fields.Add(rsField);

                var data = path.SampleData.Split(',');
                for (var recordIndex = 0; recordIndex < data.Length; recordIndex++)
                {
                    rs.SetValue(recordIndex, fieldIndex, data[recordIndex]);
                }
            }
            return(result);
        }
示例#29
0
        public bool Equals(IOutputDescription other)
        {
            var collectionEquals = CommonEqualityOps.CollectionEquals(DataSourceShapes, other.DataSourceShapes, new DataSourceShapeComparer());

            return(Format == other.Format && collectionEquals);
        }
 public static RecordsetList ToRecordsetList(this IOutputDescription outputDescription, RecordsetList currentList) => outputDescription.ToRecordsetList(currentList, "");