示例#1
0
        private SearchResponse ParseQueryResult(IReportsDataSource dataSource, IEnumerable <dynamic> queryResult, SearchRequest request, out long countResult)
        {
            var result = new SearchResponse();

            result.Data = new List <SearchResultRow>();
            countResult = 0;

            int rowIndex          = 1;
            var allColumnMappings = dataSource.GetColumnMappings(request.SelectedColumns);
            // need to preserve order
            var selectedColumnMappings = request.SelectedColumns.Select(x => allColumnMappings.First(y => y.Id == x.ColumnId)).ToList();

            foreach (dynamic doc in queryResult)
            {
                var data = new SearchResultRow();
                data.Values = new List <ResultColumnValue>();

                IDictionary <string, object> propertyValues = (IDictionary <string, object>)doc;

                foreach (var col in selectedColumnMappings)
                {
                    var columnAlias = dataSource.GetFieldAlias(col);
                    var displayName = dataSource.GetColumnDisplayName(col);

                    object value = null;

                    if (!propertyValues.ContainsKey(columnAlias))
                    {
                        result.DebugInfo.WarningMessages.Add(
                            String.Format(
                                "Cannot find the '{0}' column (column alias: '{1}') in the database query result set. It could be a column that's not allowed for this type of stats query. For example, the DateTime column can only be requested for stats queries that return timestamped data (e.g. queries with a daily temporal aggregation). Will set this value to null in the response data.",
                                displayName, columnAlias));
                    }
                    else
                    {
                        value = propertyValues[columnAlias];
                    }

                    data.Values.Add(new ResultColumnValue
                    {
                        ColumnId = col.Id,
                        Value    = value == null ? null : value.ToString(),
                        Name     = (request.DebugMode || rowIndex == 1) ? displayName : null
                    });
                }

                result.Data.Add(data);

                if (rowIndex == 1 && propertyValues.ContainsKey("_COUNT"))
                {
                    countResult = long.Parse(propertyValues["_COUNT"].ToString());
                }

                rowIndex++;
            }

            return(result);
        }
        public void AdaptPresidentToSearchResultRow()
        {
            var actual = new SearchResultRow();

            var fromValue = UnitTestUtility.GetThomasJeffersonAsPresident(true);

            SystemUnderTest.Adapt(fromValue, actual);

            AssertAreEqual(fromValue, actual);
        }
示例#3
0
        private static object[] GetRowValues(SearchResultRow row, List <ReportColumnMapping> columnInfo)
        {
            var list = new List <object>();

            foreach (var column in row.Values)
            {
                var col = columnInfo.First(x => x.Id == column.ColumnId);
                var obj = Convert.ChangeType(column.Value, col.DbType.ToClrType());
                list.Add(obj);
            }
            return(list.ToArray());
        }
        private void Adapt(IList <President> fromValues, List <SearchResultRow> toValues)
        {
            if (fromValues == null)
            {
                throw new ArgumentNullException("fromValues", "fromValues is null.");
            }
            if (toValues == null)
            {
                throw new ArgumentNullException("toValues", "toValues is null.");
            }

            var adapter = new PresidentToSearchResultRowAdapter();

            SearchResultRow toValue;

            foreach (var fromValue in fromValues)
            {
                toValue = new SearchResultRow();

                adapter.Adapt(fromValue, toValue);

                toValues.Add(toValue);
            }
        }
示例#5
0
 public AXAClaimSearchRow(SearchResultRow row)
     : base(row)
 {
 }
示例#6
0
        protected override string TryFormatValue(string value, ReportColumnMapping columnMapping, SearchResultRow row)
        {
            long parsed;

            if (long.TryParse(value, out parsed))
            {
                if (parsed > 0)
                {
                    var date = parsed.DateTimeFromUnixTime();
                    return(date.ToString("dd/MM/yyyy HH:mm:ss"));
                }
            }
            return(value);
        }
示例#7
0
        protected override string TryFormatValue(string value, ReportColumnMapping columnMapping, SearchResultRow row)
        {
            bool result;

            if (Boolean.TryParse(value, out result))
            {
                return(result.ToString());
            }
            if (value == "1")
            {
                return(true.ToString());
            }
            if (value == "0" || value == null)
            {
                return(false.ToString());
            }

            return(value);
        }
示例#8
0
 public override bool CanApply(string value, ReportColumnMapping columnMapping, SearchResultRow row)
 {
     return(base.CanApply(value, columnMapping, row) || columnMapping.DbType == DbType.Boolean);
 }
示例#9
0
 public virtual bool CanApply(string value, ReportColumnMapping columnMapping, SearchResultRow row)
 {
     return(value != null &&
            columnMapping.MetaData != null &&
            columnMapping.MetaData.ContainsKey(MetaDataKey));
 }
示例#10
0
        protected override string TryFormatValue(string value, ReportColumnMapping columnMapping, SearchResultRow row)
        {
            double parsed;

            if (double.TryParse(value, out parsed))
            {
                //return "?" + parsed.ToString("0.00");
                return(parsed.ToString("0.00"));
            }
            return(value);
        }
示例#11
0
 protected override string TryFormatValue(string value, ReportColumnMapping columnMapping, SearchResultRow row)
 {
     return(value);
 }
示例#12
0
        private void WriteColumnHeaders(List <ReportColumnMapping> columnDefinitions, SearchResultRow row)
        {
            int columnIndex = 1;

            for (var i = 0; i < row.Values.Count; i++)
            {
                Worksheet.SetCellValue(rowIndex, columnIndex, row.Values[i].Name);
                columnIndex++;
            }
            rowIndex++;
        }
 private void AssertAreEqual(President expected, SearchResultRow actual)
 {
     Assert.AreEqual <string>(expected.FirstName, actual.FirstName, "FirstName");
     Assert.AreEqual <string>(expected.LastName, actual.LastName, "LastName");
     Assert.AreEqual <int>(expected.Id, actual.Id, "Id");
 }
示例#14
0
        public ClaimFinancialAmount(SearchResultRow data)
        {
            this._row = data;

            this.ClaimDetailID = (long?)this.GetColumnValue("ClaimDetailID");
            if (_Logger.IsDebugEnabled && this.ClaimDetailID.HasValue)
            {
                _Logger.Debug(string.Format("Claim detailID output value :{0}", this.ClaimDetailID.Value.ToString()));
            }

            this.TotalClaimLoss = (decimal?)this.GetColumnValue("TotalClaimLoss");
            if (_Logger.IsDebugEnabled && this.TotalClaimLoss.HasValue)
            {
                _Logger.Debug(string.Format("Total Claim Loss output value :{0}", this.TotalClaimLoss.Value.ToString()));
            }

            this.Excess = (decimal?)this.GetColumnValue("Excess");
            if (_Logger.IsDebugEnabled && this.Excess.HasValue)
            {
                _Logger.Debug(string.Format("Excess output value :{0}", this.Excess.Value.ToString()));
            }

            this.OutstandingEstimates = (decimal?)this.GetColumnValue("OutstandingEstimates");
            if (_Logger.IsDebugEnabled && this.OutstandingEstimates.HasValue)
            {
                _Logger.Debug(string.Format("Outstanding Estimates output value :{0}", this.OutstandingEstimates.Value.ToString()));
            }

            this.PaymentsInProgress = (decimal?)this.GetColumnValue("PaymentsInProgress");
            if (_Logger.IsDebugEnabled && this.PaymentsInProgress.HasValue)
            {
                _Logger.Debug(string.Format("Payments In Progress output value :{0}", this.PaymentsInProgress.Value.ToString()));
            }

            this.TotalPaymentsPaid = (decimal?)this.GetColumnValue("TotalPaymentsPaid");
            if (_Logger.IsDebugEnabled && this.TotalPaymentsPaid.HasValue)
            {
                _Logger.Debug(string.Format("Total Payments Paid output value :{0}", this.TotalPaymentsPaid.Value.ToString()));
            }

            this.OutstandingRecoveryEstimates = (decimal?)this.GetColumnValue("OutstandingRecoveryEstimates");
            if (_Logger.IsDebugEnabled && this.OutstandingRecoveryEstimates.HasValue)
            {
                _Logger.Debug(string.Format("Outstanding Recovery Estimates output value :{0}", this.OutstandingRecoveryEstimates.Value.ToString()));
            }

            this.OutstandingULREstimate = (decimal?)this.GetColumnValue("OutstandingULREstimate");
            if (_Logger.IsDebugEnabled && this.OutstandingULREstimate.HasValue)
            {
                _Logger.Debug(string.Format("Outstanding ULR Estimate output value :{0}", this.OutstandingULREstimate.Value.ToString()));
            }

            this.RecoveriesInProgress = (decimal?)this.GetColumnValue("RecoveriesInProgress");
            if (_Logger.IsDebugEnabled && this.RecoveriesInProgress.HasValue)
            {
                _Logger.Debug(string.Format("Recoveries In Progress output value :{0}", this.RecoveriesInProgress.Value.ToString()));
            }

            this.ULRInProgress = (decimal?)this.GetColumnValue("ULRInProgress");
            if (_Logger.IsDebugEnabled && this.ULRInProgress.HasValue)
            {
                _Logger.Debug(string.Format("ULR In Progress output value :{0}", this.ULRInProgress.Value.ToString()));
            }

            this.RecoveriesCompleted = (decimal?)this.GetColumnValue("RecoveriesCompleted");
            if (_Logger.IsDebugEnabled && this.RecoveriesCompleted.HasValue)
            {
                _Logger.Debug(string.Format("Recoveries Completed output value :{0}", this.RecoveriesCompleted.Value.ToString()));
            }

            this.ULRCompleted = (decimal?)this.GetColumnValue("ULRCompleted");
            if (_Logger.IsDebugEnabled && this.ULRCompleted.HasValue)
            {
                _Logger.Debug(string.Format("ULR Completed output value :{0}", this.ULRCompleted.Value.ToString()));
            }

            this.MovementDeductibleType = (short?)this.GetColumnValue("MovementDeductibleType");
            if (_Logger.IsDebugEnabled && this.MovementDeductibleType.HasValue)
            {
                _Logger.Debug(string.Format("Movement Deductible Type output value :{0}", this.MovementDeductibleType.Value.ToString()));
            }

            this.OrderShareCoinsurance = (short?)this.GetColumnValue("OrderShareCoinsurance");
            if (_Logger.IsDebugEnabled && this.OrderShareCoinsurance.HasValue)
            {
                _Logger.Debug(string.Format("OrderShareCoinsurance value :{0}", this.OrderShareCoinsurance.Value.ToString()));
            }           
        }
示例#15
0
        public async Task <SearchResult> Search(SearchRequest request)
        {
            if (request == null)
            {
                throw new Exception($"{request} cannot be null");
            }

            RetsResource resource = await GetResourceMetadata(request.SearchType);

            if (resource == null)
            {
                string message = string.Format("The provided '{0}' is not valid. You can get a list of all valid value by calling '{1}' method on the Session object.", nameof(SearchRequest.SearchType), nameof(GetResourcesMetadata));

                throw new Exception(message);
            }

            var uriBuilder = new UriBuilder(SearchUri);

            var query = HttpUtility.ParseQueryString(uriBuilder.Query);

            query.Add("SearchType", request.SearchType);
            query.Add("Class", request.Class);
            query.Add("QueryType", request.QueryType);
            query.Add("Count", request.Count.ToString());
            query.Add("Format", request.Format);
            query.Add("Limit", request.Limit.ToString());
            query.Add("StandardNames", request.StandardNames.ToString());
            query.Add("RestrictedIndicator", request.RestrictedIndicator);
            query.Add("Query", request.ParameterGroup.ToString());

            if (request.HasColumns())
            {
                var columns = request.GetColumns().ToList();

                if (!request.HasColumn(resource.KeyField))
                {
                    columns.Add(resource.KeyField);
                }

                query.Add("Select", string.Join(",", columns));
            }

            uriBuilder.Query = query.ToString();

            return(await Requester.Get(uriBuilder.Uri, async (response) =>
            {
                using (Stream stream = await GetStream(response))
                {
                    XDocument doc = XDocument.Load(stream);

                    int code = GetReplayCode(doc.Root);

                    AssertValidReplay(doc.Root, code);

                    var result = new SearchResult(resource, request.Class, request.RestrictedIndicator);

                    if (code == 0)
                    {
                        char delimiterValue = GetCompactDelimiter(doc);

                        XNamespace ns = doc.Root.GetDefaultNamespace();
                        XElement columns = doc.Descendants(ns + "COLUMNS").FirstOrDefault();

                        IEnumerable <XElement> records = doc.Descendants(ns + "DATA");

                        string[] tableColumns = columns.Value.Split(delimiterValue);
                        result.SetColumns(tableColumns);

                        foreach (var record in records)
                        {
                            string[] fields = record.Value.Split(delimiterValue);

                            SearchResultRow row = new SearchResultRow(tableColumns, fields, resource.KeyField, request.RestrictedIndicator);

                            result.AddRow(row);
                        }
                    }

                    return result;
                }
            }, Session.Resource));
        }
示例#16
0
 protected abstract string TryFormatValue(string value, ReportColumnMapping columnMapping, SearchResultRow row);
示例#17
0
        protected override string TryFormatValue(string value, ReportColumnMapping columnMapping, SearchResultRow row)
        {
            double parsed;

            if (value.Contains(".") && double.TryParse(value, out parsed))
            {
                var toPrecision = Math.Round(parsed, columnMapping.MetaData.GetInt(MetaDataKey));
                return(toPrecision.ToString());
            }

            return(value);
        }
示例#18
0
        public virtual string ApplyFilter(string value, ReportColumnMapping columnMapping, SearchResultRow row)
        {
            if (CanApply(value, columnMapping, row))
            {
                return(TryFormatValue(value, columnMapping, row));
            }

            return(value);
        }
示例#19
0
 public override bool CanApply(string value, ReportColumnMapping columnMapping, SearchResultRow row)
 {
     return(base.CanApply(value, columnMapping, row) && columnMapping.MetaData.GetString(MetaDataKey) == DataFormatValue);
 }