コード例 #1
0
        public void SetGetProperties()
        {
            SelectParameter parameter = new SelectParameter();

            Assert.AreEqual(typeof(string), parameter.DataType, "DataType does not match");

            parameter.IsRequired = false;
            Assert.AreEqual(false, parameter.IsRequired, "IsRequired does not match");
            parameter.IsRequired = true;
            Assert.AreEqual(true, parameter.IsRequired, "IsRequired does not match");
            parameter.DataValues = new NameValuePair[] {
                new NameValuePair(string.Empty, "Dev"),
                new NameValuePair("Test", "Test"),
                new NameValuePair(null, "Prod")
            };
            Assert.AreEqual(3, parameter.AllowedValues.Length, "AllowedValues does not match");
            parameter.Description = "Some description goes here";
            Assert.AreEqual("Some description goes here", parameter.Description, "Description does not match");
            parameter.Name = "Some name";
            Assert.AreEqual("Some name", parameter.Name, "Name does not match");
            Assert.AreEqual("Some name", parameter.DisplayName, "DisplayName does not match");
            parameter.DisplayName = "Another name";
            Assert.AreEqual("Another name", parameter.DisplayName, "DisplayName does not match");

            var defaultValue = "daDefault";
            var clientValue  = "daDefaultForDaClient";

            parameter.DefaultValue = defaultValue;
            Assert.AreEqual(defaultValue, parameter.DefaultValue);
            Assert.AreEqual(defaultValue, parameter.ClientDefaultValue);
            parameter.ClientDefaultValue = clientValue;
            Assert.AreEqual(clientValue, parameter.ClientDefaultValue);
        }
コード例 #2
0
ファイル: ActionSelectList.cs プロジェクト: cnboker/autorobo
        public override bool Parse(ActionBuilder.ActionParameter parameter)
        {
            base.Parse(parameter);

            SelectParameter sp = parameter as SelectParameter;

            ByValue = sp.ByValue;
            var selectedElement = parameter.Element as IHTMLSelectElement;

            if (selectedElement == null)
            {
                return(false);
            }
            //var optionElements = selectedElement.options as mshtml.HTMLSelectElementClass;
            //if (optionElements == null) return false;
            //foreach (IHTMLOptionElement option in selectedElement)
            for (int i = 0; i < selectedElement.length; i++)
            {
                IHTMLOptionElement option = selectedElement.item(i, i) as IHTMLOptionElement;
                if (option.selected)
                {
                    SelectedValue = option.value;
                    SelectedText  = option.text;
                    break;
                }
            }
            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Write a node.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="target"></param>
        public override void Write(XmlWriter writer, object target)
        {
            if (isList)
            {
                var list = target as IEnumerable <NameValuePair>;

                if (list == null)
                {
                    SelectParameter parameter = target as SelectParameter;
                    if (parameter != null)
                    {
                        list = parameter.DataValues;
                    }
                }
                if (list != null)
                {
                    writer.WriteStartElement(base.Attribute.Name);
                    foreach (var value in list)
                    {
                        WriteValue(writer, value, "value");
                    }
                    writer.WriteEndElement();
                }
            }
            else
            {
                var value = (target as NameValuePair);
                if (value != null)
                {
                    WriteValue(writer, value, base.Attribute.Name);
                }
            }
        }
コード例 #4
0
        public async Task <ActionResult <IEnumerable <Account> > > Get(
            AccountTypeParameter type,
            ContractKindParameter kind,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "balance", "firstActivity", "lastActivity", "numTransactions", "numContracts"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            #region optimize
            if (kind?.Eq != null && type == null)
            {
                type = new AccountTypeParameter {
                    Eq = 2
                }
            }
            ;
            #endregion

            if (select == null)
            {
                return(Ok(await Accounts.Get(type, kind, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Accounts.Get(type, kind, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Accounts.Get(type, kind, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Accounts.Get(type, kind, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Accounts.Get(type, kind, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
コード例 #5
0
        public void IsRequiredWithBlank()
        {
            SelectParameter parameter = new SelectParameter();

            parameter.Name       = "Test";
            parameter.IsRequired = true;
            Exception[] results = parameter.Validate(string.Empty);
            Assert.AreEqual(1, results.Length, "Number of exceptions does not match");
            Assert.AreEqual("Value of 'Test' is required", results[0].Message, "Exception message does not match");
        }
コード例 #6
0
        public void DefaultValueChecksAllowedValues()
        {
            var parameter = new SelectParameter();

            parameter.DataValues = new NameValuePair[]
            {
                new NameValuePair("name1", "value1"),
                new NameValuePair("name2", "value2")
            };
            parameter.DefaultValue = "value2";
            Assert.AreEqual("name2", parameter.ClientDefaultValue);
        }
コード例 #7
0
        public async Task <ActionResult <IEnumerable <Constant> > > Get(
            ExpressionParameter address,
            Int32Parameter creationLevel,
            TimestampParameter creationTime,
            AccountParameter creator,
            Int32Parameter refs,
            Int32Parameter size,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            [Range(0, 2)] int format    = 0)
        {
            #region validate
            if (sort != null && !sort.Validate("creationLevel", "size", "refs"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Constants.Get(address, creationLevel, creationTime, creator, refs, size, sort, offset, limit, format)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Constants.Get(address, creationLevel, creationTime, creator, refs, size, sort, offset, limit, select.Values[0], format)));
                }
                else
                {
                    return(Ok(await Constants.Get(address, creationLevel, creationTime, creator, refs, size, sort, offset, limit, select.Values, format)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Constants.Get(address, creationLevel, creationTime, creator, refs, size, sort, offset, limit, select.Fields[0], format)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Constants.Get(address, creationLevel, creationTime, creator, refs, size, sort, offset, limit, select.Fields, format)
                    }));
                }
            }
        }
コード例 #8
0
        public async Task <ActionResult <IEnumerable <BakingRight> > > Get(
            BakingRightTypeParameter type,
            AccountParameter baker,
            Int32Parameter cycle,
            Int32Parameter level,
            Int32NullParameter slots,
            Int32NullParameter priority,
            BakingRightStatusParameter status,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("level"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await BakingRights.Get(type, baker, cycle, level, slots, priority, status, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await BakingRights.Get(type, baker, cycle, level, slots, priority, status, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await BakingRights.Get(type, baker, cycle, level, slots, priority, status, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await BakingRights.Get(type, baker, cycle, level, slots, priority, status, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await BakingRights.Get(type, baker, cycle, level, slots, priority, status, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
コード例 #9
0
        public void ConvertReturnsOriginalIfNameNotFound()
        {
            var parameter = new SelectParameter();

            parameter.DataValues = new NameValuePair[]
            {
                new NameValuePair("name1", "value1"),
                new NameValuePair("name2", "value2")
            };
            var value = parameter.Convert("notFound");

            Assert.AreEqual("notFound", value);
        }
コード例 #10
0
        public void ConvertReturnsValueForName()
        {
            var parameter = new SelectParameter();

            parameter.DataValues = new NameValuePair[]
            {
                new NameValuePair("name1", "value1"),
                new NameValuePair("name2", "value2")
            };
            var value = parameter.Convert("name1");

            Assert.AreEqual("value1", value);
        }
コード例 #11
0
        public void CanGetSetDataValues()
        {
            var parameter  = new SelectParameter();
            var dataValues = new NameValuePair[]
            {
                new NameValuePair("one", "1"),
                new NameValuePair("two", "2"),
                new NameValuePair("three", "3")
            };

            parameter.DataValues = dataValues;
            Assert.AreSame(dataValues, parameter.DataValues);
        }
コード例 #12
0
        public void IsAllowedValue()
        {
            SelectParameter parameter = new SelectParameter();

            parameter.Name       = "Test";
            parameter.DataValues = new NameValuePair[] {
                new NameValuePair(string.Empty, "Dev"),
                new NameValuePair("Test", "Test"),
                new NameValuePair(null, "Prod")
            };
            Exception[] results = parameter.Validate("Dev");
            Assert.AreEqual(0, results.Length, "Number of exceptions does not match");
        }
コード例 #13
0
ファイル: BigMapsController.cs プロジェクト: baking-bad/tzkt
        public async Task <ActionResult <IEnumerable <BigMapKeyHistorical> > > GetHistoricalKeys(
            [Min(0)] int id,
            [Min(0)] int level,
            bool?active,
            JsonParameter key,
            JsonParameter value,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            MichelineFormat micheline   = MichelineFormat.Json)
        {
            #region validate
            if (sort != null && !sort.Validate("id"))
            {
                return(new BadRequest(nameof(sort), "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await BigMaps.GetHistoricalKeys(id, level, active, key, value, sort, offset, limit, micheline)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await BigMaps.GetHistoricalKeys(id, level, active, key, value, sort, offset, limit, select.Values[0], micheline)));
                }
                else
                {
                    return(Ok(await BigMaps.GetHistoricalKeys(id, level, active, key, value, sort, offset, limit, select.Values, micheline)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await BigMaps.GetHistoricalKeys(id, level, active, key, value, sort, offset, limit, select.Fields[0], micheline)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await BigMaps.GetHistoricalKeys(id, level, active, key, value, sort, offset, limit, select.Fields, micheline)
                    }));
                }
            }
        }
コード例 #14
0
ファイル: BigMapsController.cs プロジェクト: baking-bad/tzkt
        public async Task <ActionResult <IEnumerable <BigMap> > > GetBigMaps(
            AccountParameter contract,
            StringParameter path,
            BigMapTagsParameter tags,
            bool?active,
            Int32Parameter lastLevel,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            MichelineFormat micheline   = MichelineFormat.Json)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "ptr", "firstLevel", "lastLevel", "totalKeys", "activeKeys", "updates"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await BigMaps.Get(contract, path, tags, active, lastLevel, sort, offset, limit, micheline)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await BigMaps.Get(contract, path, tags, active, lastLevel, sort, offset, limit, select.Values[0], micheline)));
                }
                else
                {
                    return(Ok(await BigMaps.Get(contract, path, tags, active, lastLevel, sort, offset, limit, select.Values, micheline)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await BigMaps.Get(contract, path, tags, active, lastLevel, sort, offset, limit, select.Fields[0], micheline)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await BigMaps.Get(contract, path, tags, active, lastLevel, sort, offset, limit, select.Fields, micheline)
                    }));
                }
            }
        }
コード例 #15
0
        public void IsNotAllowedValue()
        {
            SelectParameter parameter = new SelectParameter();

            parameter.Name       = "Test";
            parameter.DataValues = new NameValuePair[] {
                new NameValuePair(string.Empty, "Dev"),
                new NameValuePair("Test", "Test"),
                new NameValuePair(null, "Prod")
            };
            Exception[] results = parameter.Validate("QA");
            Assert.AreEqual(1, results.Length, "Number of exceptions does not match");
            Assert.AreEqual("Value of 'Test' is not an allowed value", results[0].Message, "Exception message does not match");
        }
コード例 #16
0
        public async Task <ActionResult <IEnumerable <Commitment> > > Get(
            bool?activated,
            Int32NullParameter activationLevel,
            Int64Parameter balance,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("activationLevel", "balance"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Commitments.Get(activated, activationLevel, balance, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Commitments.Get(activated, activationLevel, balance, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Commitments.Get(activated, activationLevel, balance, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Commitments.Get(activated, activationLevel, balance, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Commitments.Get(activated, activationLevel, balance, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
コード例 #17
0
        public async Task <ActionResult <IEnumerable <Statistics> > > Get(
            Int32Parameter level,
            TimestampParameter timestamp,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            Symbols quote = Symbols.None)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "level", "cycle", "date"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Statistics.Get(StatisticsPeriod.None, null, level, timestamp, null, sort, offset, limit, quote)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Statistics.Get(StatisticsPeriod.None, null, level, timestamp, null, sort, offset, limit, select.Values[0], quote)));
                }
                else
                {
                    return(Ok(await Statistics.Get(StatisticsPeriod.None, null, level, timestamp, null, sort, offset, limit, select.Values, quote)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Statistics.Get(StatisticsPeriod.None, null, level, timestamp, null, sort, offset, limit, select.Fields[0], quote)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Statistics.Get(StatisticsPeriod.None, null, level, timestamp, null, sort, offset, limit, select.Fields, quote)
                    }));
                }
            }
        }
コード例 #18
0
ファイル: AccountsController.cs プロジェクト: baking-bad/tzkt
        public async Task <ActionResult <IEnumerable <HistoricalBalance> > > GetBalanceHistory(
            [Required][Address] string address,
            [Min(1)] int?step,
            SelectParameter select,
            SortParameter sort,
            [Min(0)] int offset         = 0,
            [Range(0, 10000)] int limit = 100,
            Symbols quote = Symbols.None)
        {
            #region validate
            if (sort != null && !sort.Validate("level"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await History.Get(address, step ?? 1, sort, offset, limit, quote)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await History.Get(address, step ?? 1, sort, offset, limit, select.Values[0], quote)));
                }
                else
                {
                    return(Ok(await History.Get(address, step ?? 1, sort, offset, limit, select.Values, quote)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await History.Get(address, step ?? 1, sort, offset, limit, select.Fields[0], quote)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await History.Get(address, step ?? 1, sort, offset, limit, select.Fields, quote)
                    }));
                }
            }
        }
コード例 #19
0
ファイル: RewardsController.cs プロジェクト: baking-bad/tzkt
        public async Task <ActionResult <IEnumerable <BakerRewards> > > GetBakerRewards(
            [Required][TzAddress] string address,
            Int32Parameter cycle,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            Symbols quote = Symbols.None)
        {
            #region validate
            if (sort != null && !sort.Validate("cycle"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Rewards.GetBakerRewards(address, cycle, sort, offset, limit, quote)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Rewards.GetBakerRewards(address, cycle, sort, offset, limit, select.Values[0], quote)));
                }
                else
                {
                    return(Ok(await Rewards.GetBakerRewards(address, cycle, sort, offset, limit, select.Values, quote)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Rewards.GetBakerRewards(address, cycle, sort, offset, limit, select.Fields[0], quote)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Rewards.GetBakerRewards(address, cycle, sort, offset, limit, select.Fields, quote)
                    }));
                }
            }
        }
コード例 #20
0
ファイル: VotingController.cs プロジェクト: baking-bad/tzkt
        public async Task <ActionResult <IEnumerable <Proposal> > > GetProposals(
            ProtocolParameter hash,
            Int32Parameter epoch,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "upvotes", "rolls"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Voting.GetProposals(hash, epoch, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Voting.GetProposals(hash, epoch, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Voting.GetProposals(hash, epoch, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Voting.GetProposals(hash, epoch, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Voting.GetProposals(hash, epoch, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
コード例 #21
0
ファイル: DelegatesController.cs プロジェクト: yepeek/tzkt
        public async Task <ActionResult <IEnumerable <Models.Delegate> > > Get(
            BoolParameter active,
            Int32Parameter lastActivity,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "stakingBalance", "balance", "numDelegators", "activationLevel", "deactivationLevel"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Accounts.GetDelegates(active, lastActivity, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Accounts.GetDelegates(active, lastActivity, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Accounts.GetDelegates(active, lastActivity, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Accounts.GetDelegates(active, lastActivity, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Accounts.GetDelegates(active, lastActivity, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
コード例 #22
0
        public async Task <ActionResult <IEnumerable <Cycle> > > Get(
            Int32Parameter snapshotIndex,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            Symbols quote = Symbols.None)
        {
            #region validate
            if (sort != null && !sort.Validate("index"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, quote)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, select.Values[0], quote)));
                }
                else
                {
                    return(Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, select.Values, quote)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, select.Fields[0], quote)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Cycles.Get(snapshotIndex, sort, offset, limit, select.Fields, quote)
                    }));
                }
            }
        }
コード例 #23
0
ファイル: QuotesController.cs プロジェクト: yepeek/tzkt
        public async Task <ActionResult <IEnumerable <Quote> > > Get(
            Int32Parameter level,
            DateTimeParameter timestamp,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("level"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Quotes.Get(level, timestamp, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Quotes.Get(level, timestamp, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Quotes.Get(level, timestamp, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Quotes.Get(level, timestamp, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Quotes.Get(level, timestamp, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
コード例 #24
0
        public async Task <ActionResult <IEnumerable <Software> > > Get(
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("firstLevel", "lastLevel", "blocksCount"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Software.Get(sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Software.Get(sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Software.Get(sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Software.Get(sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Software.Get(sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
コード例 #25
0
        public Uri GetFullUri()
        {
            var parameters = new List <string>();

            if (!FilterParameter.IsNullOrWhiteSpace())
            {
                parameters.Add(BuildParameter(StringConstants.FilterParameter, HttpUtility.UrlEncode(FilterParameter)));
            }

            if (!SelectParameter.IsNullOrWhiteSpace())
            {
                parameters.Add(BuildParameter(StringConstants.SelectParameter, SelectParameter));
            }

            if (!SkipParameter.IsNullOrWhiteSpace())
            {
                parameters.Add(BuildParameter(StringConstants.SkipParameter, SkipParameter));
            }

            if (!TakeParameter.IsNullOrWhiteSpace())
            {
                parameters.Add(BuildParameter(StringConstants.TopParameter, TakeParameter));
            }

            if (OrderByParameter.Any())
            {
                parameters.Add(BuildParameter(StringConstants.OrderByParameter, OrderByParameter.Join(",")));
            }

            if (!ExpandParameter.IsNullOrWhiteSpace())
            {
                parameters.Add(BuildParameter(StringConstants.ExpandParameter, ExpandParameter));
            }

            var builder = new UriBuilder(m_serviceBase);

            builder.Query = (string.IsNullOrEmpty(builder.Query) ? string.Empty : "&") + parameters.Join("&");

            var resultUri = builder.Uri;

            return(resultUri);
        }
コード例 #26
0
        public void GenerateClientDefaultLoadsFromAFile()
        {
            var sourceFile = Path.GetTempFileName();

            try
            {
                var lines = new string[]
                {
                    "Option #1",
                    "Option #2"
                };
                File.WriteAllLines(sourceFile, lines);
                var parameter = new SelectParameter();
                parameter.SourceFile = sourceFile;
                parameter.GenerateClientDefault();
                CollectionAssert.AreEqual(lines, parameter.AllowedValues);
            }
            finally
            {
                File.Delete(sourceFile);
            }
        }
コード例 #27
0
        protected virtual async void LoadData()
        {
            try
            {
                this.ActivityPresenter.Show("Searching...", ActivityStyle.SmallIndicatorWithText);

                QueryDescriptor queryDescriptor = new QueryDescriptor();
                queryDescriptor.FilterDescriptors.Add(new FilterDescriptor("Location", FilterOperator.IsEqualTo, this.Item.Location));
                queryDescriptor.PageDescriptor.PageIndex = 0;

                SelectParameter selectParameter = new SelectParameter();
                selectParameter.QueryDescriptor = queryDescriptor;

                ISelectResult <Property> selectResult = await this.Repository.GetAllAsync(selectParameter);

                SearchResult searchResult = new SearchResult();
                searchResult.Items    = selectResult;
                searchResult.Location = this.Item.Location;

                if (selectResult.ItemCount == 0)
                {
                    this.MessagePresenter.Show("No listing found near " + this.Item.Location);
                }
                else
                {
                    this.Item.ItemCount = selectResult.ItemCount;
                    this.SaveRecentSearch();
                    this.ShowSearchResult(searchResult);
                }
            }
            catch (Exception ex)
            {
                this.MessagePresenter.Show(ex.Message, "Search Failed");
            }
            finally
            {
                this.ActivityPresenter.Hide();
            }
        }
コード例 #28
0
        public async Task <ActionResult <Statistics> > GetCycles(SelectParameter select, Symbols quote = Symbols.None)
        {
            var level = new Int32Parameter {
                Eq = State.Current.Level
            };

            if (select == null)
            {
                return(Ok((await Statistics.Get(StatisticsPeriod.None, null, level, null, null, null, null, 1, quote)).FirstOrDefault()));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok((await Statistics.Get(StatisticsPeriod.None, null, level, null, null, null, null, 1, select.Values[0], quote)).FirstOrDefault()));
                }
                else
                {
                    return(Ok((await Statistics.Get(StatisticsPeriod.None, null, level, null, null, null, null, 1, select.Values, quote)).FirstOrDefault()));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok((await Statistics.Get(StatisticsPeriod.None, null, level, null, null, null, null, 1, select.Fields[0], quote)).FirstOrDefault()));
                }
                else
                {
                    return(Ok(new SelectionSingleResponse
                    {
                        Cols = select.Fields,
                        Vals = (await Statistics.Get(StatisticsPeriod.None, null, level, null, null, null, null, 1, select.Fields, quote)).FirstOrDefault()
                    }));
                }
            }
        }
コード例 #29
0
ファイル: AccountsController.cs プロジェクト: baking-bad/tzkt
        public async Task <ActionResult <IEnumerable <Account> > > Get(
            AccountTypeParameter type,
            ContractKindParameter kind,
            AccountParameter @delegate,
            Int64Parameter balance,
            BoolParameter staked,
            Int32Parameter lastActivity,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (@delegate != null)
            {
                if (@delegate.Eqx != null)
                {
                    return(new BadRequest($"{nameof(@delegate)}.eqx", "This parameter doesn't support .eqx mode."));
                }

                if (@delegate.Nex != null)
                {
                    return(new BadRequest($"{nameof(@delegate)}.nex", "This parameter doesn't support .nex mode."));
                }

                if (@delegate.Eq == -1 || @delegate.In?.Count == 0)
                {
                    return(Ok(Enumerable.Empty <Account>()));
                }
            }

            if (sort != null && !sort.Validate("id", "balance", "firstActivity", "lastActivity", "numTransactions", "numContracts"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            #region optimize
            if (kind?.Eq != null && type == null)
            {
                type = new AccountTypeParameter {
                    Eq = 2
                }
            }
            ;
            #endregion

            if (select == null)
            {
                return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
コード例 #30
0
        public async Task <ActionResult <IEnumerable <Block> > > Get(
            AccountParameter baker,
            Int32Parameter level,
            DateTimeParameter timestamp,
            Int32Parameter priority,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            Symbols quote = Symbols.None)
        {
            #region validate
            if (baker != null)
            {
                if (baker.Eqx != null)
                {
                    return(new BadRequest($"{nameof(baker)}.eqx", "This parameter doesn't support .eqx mode."));
                }

                if (baker.Nex != null)
                {
                    return(new BadRequest($"{nameof(baker)}.nex", "This parameter doesn't support .nex mode."));
                }

                if (baker.Eq == -1 || baker.In?.Count == 0)
                {
                    return(Ok(Enumerable.Empty <OriginationOperation>()));
                }
            }

            if (sort != null && !sort.Validate("id", "level", "priority", "validations", "reward", "fees"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Blocks.Get(baker, level, timestamp, priority, sort, offset, limit, quote)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Blocks.Get(baker, level, timestamp, priority, sort, offset, limit, select.Values[0], quote)));
                }
                else
                {
                    return(Ok(await Blocks.Get(baker, level, timestamp, priority, sort, offset, limit, select.Values, quote)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Blocks.Get(baker, level, timestamp, priority, sort, offset, limit, select.Fields[0], quote)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Blocks.Get(baker, level, timestamp, priority, sort, offset, limit, select.Fields, quote)
                    }));
                }
            }
        }