public override async Task <ReturnValue> Open(Int64 auditKey, SelectQuery query, CancellationToken cancelToken)
        {
            AuditKey = auditKey;
            try
            {
                if (_isOpen)
                {
                    return(new ReturnValue(false, "The web service connection is already open.", null));
                }

                var wsResult = await((ConnectionSoap)ReferenceConnection).GetWebService();
                if (wsResult.Success == false)
                {
                    return(wsResult);
                }

                _webServiceObject = wsResult.Value;
                _webServiceType   = _webServiceObject.GetType();

                //if no driving table is set, then use the row creator to simulate a single row.
                if (ReferenceTransform == null)
                {
                    ReaderRowCreator rowCreator = new ReaderRowCreator();
                    rowCreator.InitializeRowCreator(1, 1, 1);
                    ReferenceTransform = rowCreator;
                }
                else
                {
                    var result = await ReferenceTransform.Open(auditKey, null, cancelToken);

                    if (!result.Success)
                    {
                        return(result);
                    }
                }

                //create a dummy inreader to allow fieldcount and other queries to work.
                return(new ReturnValue(true));
            }
            catch (Exception ex)
            {
                return(new ReturnValue(false, "The following error occurred when starting the web service: " + ex.Message, ex));
            }
        }
Beispiel #2
0
        // public override List<Sort> SortFields => new List<Sort>();

        public override async Task <bool> Open(long auditKey, SelectQuery query, CancellationToken cancellationToken)
        {
            AuditKey = auditKey;

            var primarySorts   = new List <Sort>();
            var referenceSorts = new List <Sort>();

            //we need to translate filters and sorts to source column names before passing them through.
            if (query?.Sorts != null)
            {
                foreach (var sort in query.Sorts)
                {
                    if (sort.Column != null)
                    {
                        var column = PrimaryTransform.CacheTable[sort.Column.Name];
                        if (column != null)
                        {
                            primarySorts.Add(new Sort(column, sort.Direction));
                        }

                        column = ReferenceTransform.CacheTable[sort.Column.Name];
                        if (column != null)
                        {
                            referenceSorts.Add(new Sort(column, sort.Direction));
                        }
                    }
                }
            }

            var primaryQuery = new SelectQuery()
            {
                Sorts = primarySorts
            };
            var referenceQuery = new SelectQuery()
            {
                Sorts = referenceSorts
            };

            var returnValue = await PrimaryTransform.Open(auditKey, primaryQuery, cancellationToken);

            if (!returnValue)
            {
                return(false);
            }

            returnValue = await ReferenceTransform.Open(auditKey, referenceQuery, cancellationToken);

            //if the primary & reference transforms are sorted, we will merge sort the items.
            if (PrimaryTransform.SortFields != null && ReferenceTransform.SortFields != null)
            {
                var newSortFields = new List <Sort>();
                _primarySortOrdinals   = new List <int>();
                _referenceSortOrdinals = new List <int>();

                var index = 0;
                var referenceSortFields = ReferenceTransform.SortFields;

                foreach (var sortField in PrimaryTransform.SortFields)
                {
                    if (referenceSortFields.Count <= index)
                    {
                        break;
                    }

                    var referenceSortField = referenceSortFields[index];
                    if (sortField.Column.Name == referenceSortField.Column.Name &&
                        sortField.Direction == referenceSortField.Direction)
                    {
                        newSortFields.Add(sortField);

                        _primarySortOrdinals.Add(PrimaryTransform.CacheTable.GetOrdinal(sortField.Column.Name));
                        _referenceSortOrdinals.Add(ReferenceTransform.CacheTable.GetOrdinal(sortField.Column.Name));
                    }
                    else
                    {
                        break;
                    }

                    index++;
                }

                if (newSortFields.Count > 0)
                {
                    _sortedMerge = true;
                    CacheTable.OutputSortFields = newSortFields;
                }
            }

            return(returnValue);
        }
Beispiel #3
0
        public override async Task <bool> Open(Int64 auditKey, SelectQuery query, CancellationToken cancellationToken)
        {
            AuditKey = auditKey;
            if (query == null)
            {
                query = new SelectQuery();
            }

            //only apply a sort if there is not already a sort applied.
            // if(query.Sorts == null || query.Sorts.Count == 0)
            query.Sorts = RequiredSortFields();

            var returnValue = await PrimaryTransform.Open(auditKey, query, cancellationToken);

            if (!returnValue)
            {
                return(false);
            }

            var referenceQuery = new SelectQuery()
            {
                Sorts = RequiredReferenceSortFields()
            };

            returnValue = await ReferenceTransform.Open(auditKey, referenceQuery, cancellationToken);

            if (!returnValue)
            {
                return(false);
            }

            //check if the primary and reference transform are sorted in the join
            if (SortFieldsMatch(RequiredSortFields(), PrimaryTransform.SortFields) && SortFieldsMatch(RequiredReferenceSortFields(), ReferenceTransform.SortFields))
            {
                JoinAlgorithm = EJoinAlgorithm.Sorted;
            }
            else
            {
                JoinAlgorithm = EJoinAlgorithm.Hash;
            }

            //store the ordinals for the joins to improve performance.
            if (_joinColumns == null)
            {
                _joinKeyOrdinals   = new int[0];
                _sourceKeyOrdinals = new int[0];
            }
            else
            {
                _joinKeyOrdinals   = new int[_joinColumns.Length];
                _sourceKeyOrdinals = new int[_joinColumns.Length];

                for (var i = 0; i < _joinColumns.Length; i++)
                {
                    _joinKeyOrdinals[i]   = ReferenceTransform.GetOrdinal(_joinColumns[i].JoinColumn.Name);
                    _sourceKeyOrdinals[i] = _joinColumns[i].SourceColumn == null ? -1 : PrimaryTransform.GetOrdinal(_joinColumns[i].SourceColumn.Name);
                }
            }


            return(true);
        }