Ejemplo n.º 1
0
        public ConnectedViewModel(Action OnDisconnect)
        {
            homeTab     = new();
            imagesTab   = new();
            profileTab  = new();
            postTab     = new(() => VM = profileTab);
            settingsTab = new(OnDisconnect);

            _vm         = homeTab;
            HomeTab     = new RelayCommand((object?_) => { VM = homeTab; });
            PostTab     = new RelayCommand((object?_) => { VM = postTab; });
            ImagesTab   = new RelayCommand((object?_) => { VM = imagesTab; });
            ProfileTab  = new RelayCommand((object?_) => { VM = profileTab; });
            SettingsTab = new RelayCommand((object?_) => { VM = settingsTab; });
        }
Ejemplo n.º 2
0
        public async void OnConnect(string folder, IPEndPoint endpoint)
        {
            var             file = Path.Combine(folder, "client.identity");
            PrivateIdentity identity;

            if (!Env.CheckFile(file))
            {
                if (!Env.Confirm($"No identity was found at {file}. Do you want to create a new one?"))
                {
                    return;
                }
                identity = PrivateIdentity.Create();
                var hex = Transcoder.HexFromBytes(PrivateIdentity.Export(identity));
                await Env.WriteFile(file, hex);
            }
            else
            {
                var hex    = Transcoder.BytesFromHex(await Env.ReadFile(file));
                var result = PrivateIdentity.Import(hex);
                if (result.IsError)
                {
                    Env.Alert("Could not load identity!!");
                    return;
                }
                identity = result.Value;
            }

            APITranslatorClient nodeConnection;

            try
            {
                nodeConnection = await APITranslatorClient.CreateAndConnect(new APITranslatorClient.ConnectionArgs
                {
                    Self     = identity,
                    ServerID = identity.ID,
                    Address  = endpoint.Address,
                    Port     = endpoint.Port
                });
            }
            catch
            {
                Env.Alert("Unable to connect to your node!");
                return;
            }

            Resources = new ResourceManager(identity, nodeConnection, OnDisconnect);
            VM        = new ConnectedViewModel(OnDisconnect);
        }
Ejemplo n.º 3
0
 public void OnDisconnect()
 {
     VM = startup;
     Resources.Dispose();
 }
Ejemplo n.º 4
0
 public ViewModel()
 {
     _vm = startup = new StartupViewModel(OnConnect, OnQuit);
 }