示例#1
0
        public override ViewVariablesBlob DataRequest(ViewVariablesRequest messageRequestMeta)
        {
            if (!(messageRequestMeta is ViewVariablesRequestMembers))
            {
                return(null);
            }

            var dataList = new List <ViewVariablesBlobMembers.MemberData>();
            var blob     = new ViewVariablesBlobMembers
            {
                Members = dataList
            };

            foreach (var property in Session.ObjectType.GetAllProperties())
            {
                var attr = property.GetCustomAttribute <ViewVariablesAttribute>();
                if (attr == null)
                {
                    continue;
                }

                dataList.Add(new ViewVariablesBlobMembers.MemberData
                {
                    Editable      = attr.Access == VVAccess.ReadWrite,
                    Name          = property.Name,
                    Type          = property.PropertyType.AssemblyQualifiedName,
                    TypePretty    = property.PropertyType.ToString(),
                    Value         = property.GetValue(Session.Object),
                    PropertyIndex = _members.Count
                });
                _members.Add(property);
            }

            foreach (var field in Session.ObjectType.GetAllFields())
            {
                var attr = field.GetCustomAttribute <ViewVariablesAttribute>();
                if (attr == null)
                {
                    continue;
                }

                dataList.Add(new ViewVariablesBlobMembers.MemberData
                {
                    Editable      = attr.Access == VVAccess.ReadWrite,
                    Name          = field.Name,
                    Type          = field.FieldType.AssemblyQualifiedName,
                    TypePretty    = field.FieldType.ToString(),
                    Value         = field.GetValue(Session.Object),
                    PropertyIndex = _members.Count
                });
                _members.Add(field);
            }

            dataList.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));

            foreach (var data in dataList)
            {
                data.Value = MakeValueNetSafe(data.Value);
            }

            return(blob);
        }
        private async void _tabsOnTabChanged(int tab)
        {
            if (_serverLoaded || tab != TabServerComponents && tab != TabServerVars)
            {
                return;
            }

            _serverLoaded = true;

            if (_entitySession == null)
            {
                try
                {
                    _entitySession =
                        await ViewVariablesManager.RequestSession(new ViewVariablesEntitySelector(_entity.Uid));
                }
                catch (SessionDenyException e)
                {
                    var text = $"Server denied VV request: {e.Reason}";
                    _serverVariables.AddChild(new Label {
                        Text = text
                    });
                    _serverComponents.AddChild(new Label {
                        Text = text
                    });
                    return;
                }

                _membersBlob = await ViewVariablesManager.RequestData <ViewVariablesBlobMembers>(_entitySession, new ViewVariablesRequestMembers());
            }

            var otherStyle = false;

            foreach (var propertyData in _membersBlob.Members)
            {
                var propertyEdit = new ViewVariablesPropertyControl();
                propertyEdit.SetStyle(otherStyle = !otherStyle);
                var editor = propertyEdit.SetProperty(propertyData);
                editor.OnValueChanged += o =>
                                         ViewVariablesManager.ModifyRemote(_entitySession, new object[] { new ViewVariablesMemberSelector(propertyData.PropertyIndex) }, o);
                if (editor is ViewVariablesPropertyEditorReference refEditor)
                {
                    refEditor.OnPressed += () =>
                                           ViewVariablesManager.OpenVV(
                        new ViewVariablesSessionRelativeSelector(_entitySession.SessionId,
                                                                 new object[] { new ViewVariablesMemberSelector(propertyData.PropertyIndex) }));
                }

                _serverVariables.AddChild(propertyEdit);
            }

            var componentsBlob = await ViewVariablesManager.RequestData <ViewVariablesBlobEntityComponents>(_entitySession, new ViewVariablesRequestEntityComponents());

            _serverComponents.DisposeAllChildren();
            componentsBlob.ComponentTypes.Sort();
            foreach (var componentType in componentsBlob.ComponentTypes.OrderBy(t => t.Stringified))
            {
                var button = new Button {
                    Text = componentType.Stringified, TextAlign = Button.AlignMode.Left
                };
                button.OnPressed += args =>
                {
                    ViewVariablesManager.OpenVV(
                        new ViewVariablesComponentSelector(_entity.Uid, componentType.Qualified));
                };
                _serverComponents.AddChild(button);
            }
        }