Beispiel #1
0
        private List <InnerData> ReadMetaDataUsingSelect(TCommand script, int countElements, bool isfirstAsk,
                                                         ref object lastId,
                                                         Func <MetaData, bool> isMine, ref bool isAllDataRead)
        {
            var list          = new List <InnerData>();
            var idDescription = PrepareKeyDescription(countElements, isfirstAsk, lastId);
            SelectSearchResult result;

            int count = 0;

            var select = new SelectDescriptionForGeneric <TCommand>(idDescription, script, countElements,
                                                                    new List <FieldDescription>());
            var ret = SelectRead(select, out result);

            while (!ret.IsError)
            {
                bool exit = false;
                foreach (var searchData in result.Data)
                {
                    var meta = _metaDataCommandCreator.ReadMetaFromSearchData(searchData);
                    var data = _userCommandCreator.ReadObjectFromSearchData(searchData.Fields);
                    meta.Hash = _hashCalculater.CalculateHashFromValue(data);

                    if (isMine(meta))
                    {
                        var innerData = new InnerData(new Transaction(meta.Hash, ""))
                        {
                            Data     = _hashCalculater.SerializeValue(data),
                            MetaData = meta
                        };

                        list.Add(innerData);
                        count++;
                    }

                    lastId = meta.Id;

                    if (count == countElements)
                    {
                        exit = true;
                        break;
                    }
                }

                if (result.IsAllDataRead || exit)
                {
                    break;
                }

                idDescription = PrepareKeyDescription(countElements, false, lastId);
                select        = new SelectDescriptionForGeneric <TCommand>(idDescription, script, count,
                                                                           new List <FieldDescription>());
                ret = SelectRead(select, out result);
            }

            isAllDataRead = result.IsAllDataRead;

            return(list);
        }
Beispiel #2
0
        private RemoteResult SelectRead(SelectDescriptionForGeneric <TCommand> description, out SelectSearchResult searchResult)
        {
            var result = new List <SearchData>();

            description.IdDescription.PageSize = description.CountElements + 2;
            var command = _metaDataCommandCreator.CreateSelectCommand(description.Script, description.IdDescription,
                                                                      description.UserParametrs);

            if (command == null)
            {
                searchResult = new SelectSearchResult(new List <SearchData>(), true);
                return(new InnerServerError(Errors.QueryError));
            }

            var reader = _implModule.CreateReader(command);

            reader.Start();

            if (reader.IsFail)
            {
                searchResult = new SelectSearchResult(result, true);
                return(new InnerFailResult("script error"));
            }

            while (reader.IsCanRead && result.Count < description.CountElements)
            {
                reader.ReadNext();

                var fields = _metaDataCommandCreator.SelectProcess(reader);

                var key = fields.Find(x => x.Item2.ToLower() == description.IdDescription.AsFieldName.ToLower());
                result.Add(new SearchData(fields, key.Item1));
            }
            bool isAllDataRead = !reader.IsCanRead;

            reader.Dispose();
            searchResult = new SelectSearchResult(result, isAllDataRead);

            return(new SuccessResult());
        }