示例#1
0
 public async void ListUpdate(ListResponse response)
 {
     Device.BeginInvokeOnMainThread(() =>
     {
         _typeCell.Text = response.Node.GetConfig("type").String;
     });
     await response.Close();
 }
        private void ListCallback(ListResponse response)
        {
            _invokeButton.IsEnabled = true;
            var parameters = response.Node.Parameters;
            var columns    = response.Node.Columns;

            _invokePermission = response.Node.Invokable;

            if (parameters != null)
            {
                foreach (var param in parameters)
                {
                    Cell     cell         = null;
                    var      name         = param["name"].Value <string>();
                    var      type         = param["type"].Value <string>();
                    string[] typeParams   = new string[0];
                    var      bracketIndex = type.IndexOf('[');
                    if (bracketIndex != -1)
                    {
                        type       = type.Substring(0, bracketIndex);
                        typeParams = param["type"].Value <string>().Substring(bracketIndex + 1).TrimEnd(new char[] { ']' }).Split(',');
                    }
                    switch (type)
                    {
                    case "string":
                    {
                        cell = new EntryCell
                        {
                            Label = name
                        };
                        break;
                    }

                    case "int":
                    case "number":
                    {
                        cell = new EntryCell
                        {
                            Label    = name,
                            Keyboard = Keyboard.Numeric
                        };
                        break;
                    }

                    case "bool":
                    {
                        cell = new SwitchCell
                        {
                            Text = name
                        };
                        break;
                    }

                    case "enum":
                        cell = new PickerCell(new List <string>(typeParams))
                        {
                            Label = name
                        };
                        break;

                    case "binary":
                    case "group":
                    case "dynamic":
                    {
                        cell = new EntryCell
                        {
                            Label = name
                        };
                        break;
                    }

                    default:
                    {
                        Debug.WriteLine(string.Format("Unknown type: {0}", type));
                    }
                    break;
                    }
                    if (cell != null)
                    {
                        _parameterCells.Add(name, cell);
                        Device.BeginInvokeOnMainThread(() => _parametersSection.Add(cell));
                    }
                }
                if (parameters.Count > 0)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        _tableRoot.Add(_parametersSection);
                    });
                }
            }

            if (columns != null)
            {
                foreach (var column in columns)
                {
                    var name = columns["name"].Value <string>();
                    var type = columns["type"].Value <string>();
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Cell cell;
                        switch (type)
                        {
                        case "string":
                        case "binary":
                        case "dynamic":
                            {
                                cell = new EntryCell
                                {
                                    IsEnabled = false,
                                    Label     = name
                                };
                                break;
                            }

                        case "number":
                        case "int":
                            {
                                cell = new EntryCell
                                {
                                    IsEnabled = false,
                                    Label     = name
                                };
                                break;
                            }

                        case "bool":
                            {
                                cell = new SwitchCell
                                {
                                    IsEnabled = false,
                                    Text      = name
                                };
                                break;
                            }

                        default:
                            {
                                throw new Exception(string.Format("Unknown type: {0}", column.Type));
                            }
                        }
                        if (cell != null)
                        {
                            _columnCells.Add(cell);
                            Device.BeginInvokeOnMainThread(() => _columnsSection.Add(cell));
                        }
                    });
                }
                if (columns.Count > 0)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        _tableRoot.Add(_columnsSection);
                    });
                }
            }

            response.Close();
        }