예제 #1
0
 private void ServerOnClientDisconnected(SpreadsheetWindow spreadsheetWindow)
 {
     if (spreadsheetWindow.Disposing || spreadsheetWindow.IsDisposed)
     {
         return;
     }
     MessageBox.Show("Disconnected from server", "Disconnect", MessageBoxButtons.OK, MessageBoxIcon.Error);
     spreadsheetWindow.Invoke(new Test(spreadsheetWindow.Close));
 }
예제 #2
0
        /// <summary>
        /// Runs a form in this application context
        /// </summary>
        /// <param name="textReader"></param>
        public void RunNew(string ipaddress, string spreadsheetName)
        {
            var server = new ServerConnection();

            // Create the window and the controller
            SpreadsheetWindow spreadsheetWindow = new SpreadsheetWindow();
            var controller = new Controller(spreadsheetWindow, server, spreadsheetName);

            server.MessageReceived += s => spreadsheetWindow.Invoke(new Test(() => { controller.MessageReceived(s); }));

            server.ClientDisconnected += () =>
            {
                ServerOnClientDisconnected(spreadsheetWindow);
            };

            // One more form is running
            spreadsheetWindowCount++;

            // When this form closes, we want to find out
            spreadsheetWindow.FormClosed += (o, e) =>
            {
                spreadsheetWindow.Dispose();
                Task.Run(() => { server.Disconnect(); });
                if (--spreadsheetWindowCount <= 0)
                {
                    RunLauncher();
                }
            };
            if (!IsUnitTest)
            {
                // Run the form
                spreadsheetWindow.Show();
            }

            server.Connect(ipaddress, spreadsheetName);
        }