Пример #1
0
        public NetworkTablesRoot(
            [Import] INetworkTablesInterface ntInterface,
            [Import] IRootTablesList rootTablesList,
            [Import] IConnectionPrompts prompts,
            [ImportMany] IEnumerable <Lazy <IRootTableProcessorFactory, IDashboardTypeMetadata> > rootTableFactories,
            [ImportMany] IEnumerable <Lazy <IViewProcessorFactory, ICustomViewFactoryMetadata> > customViewFactories)
        {
            this.rootTableFactories = rootTableFactories;
            this.ntInterface        = ntInterface;
            this.rootTablesList     = rootTablesList;

            foreach (var factory in customViewFactories)
            {
                CustomViews.Add(new CustomViewEntry(factory.Metadata.Name, new Command(() =>
                                                                                       CurrentlyViewedRootTable.AddViewProcessorToView($"{factory.Metadata.Name}_{Guid.NewGuid()}", factory.Value.Create()))));
            }

            ntInterface.OnClientConnectionAttempt += (obj, args) => SetupRootTables();
            ntInterface.OnConnectionStatus        += (obj, args) => Connected = args.Connected;
            ntInterface.OnDisconnect += (obj, args) => Connected = false;

            ConnectToRoboRioCommand = new Command(() =>
            {
                var team = prompts.PromptTeamNumber();
                if (team != null)
                {
                    ntInterface.Disconnect();
                    ntInterface.ConnectToTeam(team.Value);
                }
            });

            ConnectToServerCommand = new Command(() =>
            {
                var server = prompts.PromptServerName();
                if (server != null)
                {
                    ntInterface.Disconnect();
                    ntInterface.ConnectToServer(server);
                }
            });

            SetupRootTables();
        }
Пример #2
0
 public static void ConnectToServer(this INetworkTablesInterface nt, string server)
 {
     nt.ConnectToServer(server, NetworkTables.NetworkTable.DefaultPort);
 }