Пример #1
0
        public ChatPage(MainWindow _mainWindow, string name, string remoteUsers, bool debugModeOn, int externalPort, string chat)
        {
            InitializeComponent();

            string location            = System.Reflection.Assembly.GetEntryAssembly().Location;
            string executableDirectory = System.IO.Path.GetDirectoryName(location);
            string relativePath        = @"..\..\..\bobc";
            string fullPath            = System.IO.Path.GetFullPath(relativePath);

            int _internalPort = BobcDesktopUtils.GetAvaliablePort(25001, 45000);

            erlNode = new Process();
            erlNode.StartInfo.WorkingDirectory      = string.Format(fullPath);
            erlNode.StartInfo.FileName              = "cmd.exe";
            erlNode.StartInfo.CreateNoWindow        = !debugModeOn;
            erlNode.StartInfo.RedirectStandardInput = true;
            erlNode.StartInfo.UseShellExecute       = false;
            erlNode.Start();
            erlNode.StandardInput.WriteLine($"start.bat {name} {_internalPort} {externalPort} \"{remoteUsers}\" \"{chat}\"");


            mainWindow = _mainWindow;

            messages = new ObservableCollection <string> {
            };

            MessagesHolder.ItemsSource = messages;

            internalPort = _internalPort;

            ws            = new WebSocket($"ws://localhost:{internalPort}/websocket");
            ws.OnMessage += Ws_OnMessage;
            ws.OnClose   += Ws_OnClose;
            ws.Connect();
        }
        private async Task <bool> validateUserAsync(string login, string password)
        {
            HttpClient httpClient = mainWindow.httpClient;
            var        postParams = new Dictionary <string, string>
            {
                { "login", login },
                { "password", password }
            };
            var content  = new FormUrlEncodedContent(postParams);
            var response = await httpClient.PostAsync("http://localhost:9090/signin", content);

            var responseStringJson = await response.Content.ReadAsStringAsync();

            string responseString = BobcDesktopUtils.FromJson <string>(responseStringJson);

            if (responseString == "ok")
            {
                return(true);
            }
            else
            {
                MessageBox.Show(responseString);
                return(false);
            }
        }
Пример #3
0
 private void Ws_OnMessage(object sender, MessageEventArgs e)
 {
     App.Current.Dispatcher.Invoke((Action) delegate
     {
         string MessageString = e.Data;
         dynamic MesgObj      = BobcDesktopUtils.FromJson(MessageString);
         string msgString     = $"{MesgObj.from}: {MesgObj.msg}          {MesgObj.time}";
         messages.Add(msgString);
     });
 }
Пример #4
0
        private async void ConnectButton_Click(object sender, RoutedEventArgs e)
        {
            bool       debugModeOn = (bool)DebugMode.IsChecked;
            string     chatroomId  = ChatroomBox.Text;
            HttpClient client      = mainWindow.httpClient;


            int externalPort = BobcDesktopUtils.GetAvaliablePort(10000, 25000);

            var responseString = await client.GetStringAsync($"http://localhost:9090/connect/{chatroomId}/{externalPort}");


            dynamic reply = BobcDesktopUtils.FromJson(responseString);

            if (reply.status == "ok")
            {
                string RemoteUsers = BobcDesktopUtils.ToJson(reply.user_list);
                mainWindow.OpenPage(new ChatPage(mainWindow, name, RemoteUsers, debugModeOn, externalPort, chatroomId));
            }
        }