From a7b4fc7be6dac8c4ff9ae7924eb499d7e2ac1453 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Tue, 10 Oct 2017 11:21:01 +0200 Subject: Removed packages, added Client project properly. --- Client/Client.csproj | 61 +++++++++++++ Client/MainWindow.cs | 35 +++++++ Client/Program.cs | 16 ++++ Client/Properties/AssemblyInfo.cs | 26 ++++++ Client/TcpChatClient.cs | 69 ++++++++++++++ Client/gtk-gui/MainWindow.cs | 179 ++++++++++++++++++++++++++++++++++++ Client/gtk-gui/generated.cs | 30 ++++++ Client/gtk-gui/gui.stetic | 187 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 603 insertions(+) create mode 100644 Client/Client.csproj create mode 100644 Client/MainWindow.cs create mode 100644 Client/Program.cs create mode 100644 Client/Properties/AssemblyInfo.cs create mode 100644 Client/TcpChatClient.cs create mode 100644 Client/gtk-gui/MainWindow.cs create mode 100644 Client/gtk-gui/generated.cs create mode 100644 Client/gtk-gui/gui.stetic (limited to 'Client') diff --git a/Client/Client.csproj b/Client/Client.csproj new file mode 100644 index 0000000..f0d2993 --- /dev/null +++ b/Client/Client.csproj @@ -0,0 +1,61 @@ + + + + {73154F68-BBEB-48FC-86C4-BB4909C1C7B4} + WinExe + v4.5 + Client + Client + + + true + full + false + bin\Debug + DEBUG; + 4 + x86 + + + true + bin\Release + 4 + x86 + + + + + False + + + False + + + False + + + False + + + False + + + False + + + + + + gui.stetic + + + + + + + + + + + + \ No newline at end of file diff --git a/Client/MainWindow.cs b/Client/MainWindow.cs new file mode 100644 index 0000000..22564ac --- /dev/null +++ b/Client/MainWindow.cs @@ -0,0 +1,35 @@ +using System; +using Gtk; +using Client; + +public partial class MainWindow : Gtk.Window +{ + TcpChatClient tcpChat; + + public MainWindow() : base(Gtk.WindowType.Toplevel) + { + Build(); + tcpChat = new TcpChatClient(); + tcpChat.PropertyChanged += (sender, args) => + outputTv.Buffer.Text = tcpChat.Log; + } + + protected void OnDeleteEvent(object sender, DeleteEventArgs a) + { + Application.Quit(); + a.RetVal = true; + } + + protected async void Connect(object sender, EventArgs e) + { + await tcpChat.Connect(ipEntry.Text, Int32.Parse(portEntry.Text)); + tcpChat.SendMessage($"{usernameEntry.Text} connected."); + } + + protected void SendMessage(object sender, EventArgs e) + { + string message = $"{usernameEntry.Text}: {messageEntry.Text}"; + tcpChat.SendMessage(message); + messageEntry.Text = ""; + } +} diff --git a/Client/Program.cs b/Client/Program.cs new file mode 100644 index 0000000..22bf2bb --- /dev/null +++ b/Client/Program.cs @@ -0,0 +1,16 @@ +using System; +using Gtk; + +namespace Client +{ + class MainClass + { + public static void Main(string[] args) + { + Application.Init(); + MainWindow win = new MainWindow(); + win.Show(); + Application.Run(); + } + } +} diff --git a/Client/Properties/AssemblyInfo.cs b/Client/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7614f1a --- /dev/null +++ b/Client/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Client")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("${AuthorCopyright}")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Client/TcpChatClient.cs b/Client/TcpChatClient.cs new file mode 100644 index 0000000..e9d4b54 --- /dev/null +++ b/Client/TcpChatClient.cs @@ -0,0 +1,69 @@ +using System; +using System.ComponentModel; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; + +namespace Client +{ + public class TcpChatClient : INotifyPropertyChanged + { + public int Port { get; set; } + + private string log; + public string Log + { + get + { + return log; + } + set + { + log = value; + OnPropertyChanged(); + } + } + public bool Status { get; set; } + private StreamReader sr; + private StreamWriter sw; + + public TcpChatClient() + { + } + + public async Task Connect(string ipAddress, int port) + { + TcpClient clientSocket = new TcpClient(ipAddress, port); + NetworkStream ns = clientSocket.GetStream(); + sr = new StreamReader(ns); + sw = new StreamWriter(ns); + sw.AutoFlush = true; + Status = true; + await ReceiveMessageAsync(); + } + + public void SendMessage(string message) + { + sw.WriteLine(message); + } + + private async Task ReceiveMessageAsync() + { + while (Status) + { + string message = await sr.ReadLineAsync(); + Log += $"{message}\n"; + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/Client/gtk-gui/MainWindow.cs b/Client/gtk-gui/MainWindow.cs new file mode 100644 index 0000000..f123796 --- /dev/null +++ b/Client/gtk-gui/MainWindow.cs @@ -0,0 +1,179 @@ + +// This file has been generated by the GUI designer. Do not modify. + +public partial class MainWindow +{ + private global::Gtk.VBox vbox2; + + private global::Gtk.HBox hbox2; + + private global::Gtk.Label usernameLabel; + + private global::Gtk.Entry usernameEntry; + + private global::Gtk.Label ipLabel; + + private global::Gtk.Entry ipEntry; + + private global::Gtk.Label portLabel; + + private global::Gtk.Entry portEntry; + + private global::Gtk.Button connectButton; + + private global::Gtk.ScrolledWindow GtkScrolledWindow; + + private global::Gtk.TextView outputTv; + + private global::Gtk.HBox hbox1; + + private global::Gtk.Entry messageEntry; + + private global::Gtk.Button sendButton; + + protected virtual void Build() + { + global::Stetic.Gui.Initialize(this); + // Widget MainWindow + this.Name = "MainWindow"; + this.Title = global::Mono.Unix.Catalog.GetString("TcpChat Client"); + this.WindowPosition = ((global::Gtk.WindowPosition)(4)); + this.BorderWidth = ((uint)(10)); + // Container child MainWindow.Gtk.Container+ContainerChild + this.vbox2 = new global::Gtk.VBox(); + this.vbox2.Name = "vbox2"; + this.vbox2.Spacing = 6; + // Container child vbox2.Gtk.Box+BoxChild + this.hbox2 = new global::Gtk.HBox(); + this.hbox2.Name = "hbox2"; + this.hbox2.Spacing = 6; + // Container child hbox2.Gtk.Box+BoxChild + this.usernameLabel = new global::Gtk.Label(); + this.usernameLabel.Name = "usernameLabel"; + this.usernameLabel.LabelProp = global::Mono.Unix.Catalog.GetString("Username:"); + this.hbox2.Add(this.usernameLabel); + global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.usernameLabel])); + w1.Position = 0; + w1.Expand = false; + w1.Fill = false; + // Container child hbox2.Gtk.Box+BoxChild + this.usernameEntry = new global::Gtk.Entry(); + this.usernameEntry.CanFocus = true; + this.usernameEntry.Name = "usernameEntry"; + this.usernameEntry.Text = global::Mono.Unix.Catalog.GetString("Marcin"); + this.usernameEntry.IsEditable = true; + this.usernameEntry.InvisibleChar = '•'; + this.hbox2.Add(this.usernameEntry); + global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.usernameEntry])); + w2.Position = 1; + // Container child hbox2.Gtk.Box+BoxChild + this.ipLabel = new global::Gtk.Label(); + this.ipLabel.Name = "ipLabel"; + this.ipLabel.LabelProp = global::Mono.Unix.Catalog.GetString("IP address:"); + this.hbox2.Add(this.ipLabel); + global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.ipLabel])); + w3.Position = 2; + w3.Expand = false; + w3.Fill = false; + // Container child hbox2.Gtk.Box+BoxChild + this.ipEntry = new global::Gtk.Entry(); + this.ipEntry.WidthRequest = 110; + this.ipEntry.CanFocus = true; + this.ipEntry.Name = "ipEntry"; + this.ipEntry.Text = global::Mono.Unix.Catalog.GetString("127.0.0.1"); + this.ipEntry.IsEditable = true; + this.ipEntry.InvisibleChar = '•'; + this.hbox2.Add(this.ipEntry); + global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.ipEntry])); + w4.Position = 3; + // Container child hbox2.Gtk.Box+BoxChild + this.portLabel = new global::Gtk.Label(); + this.portLabel.Name = "portLabel"; + this.portLabel.LabelProp = global::Mono.Unix.Catalog.GetString("Port:"); + this.hbox2.Add(this.portLabel); + global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.portLabel])); + w5.Position = 4; + w5.Expand = false; + w5.Fill = false; + // Container child hbox2.Gtk.Box+BoxChild + this.portEntry = new global::Gtk.Entry(); + this.portEntry.WidthRequest = 50; + this.portEntry.CanFocus = true; + this.portEntry.Name = "portEntry"; + this.portEntry.Text = global::Mono.Unix.Catalog.GetString("6789"); + this.portEntry.IsEditable = true; + this.portEntry.InvisibleChar = '•'; + this.hbox2.Add(this.portEntry); + global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.portEntry])); + w6.Position = 5; + // Container child hbox2.Gtk.Box+BoxChild + this.connectButton = new global::Gtk.Button(); + this.connectButton.CanFocus = true; + this.connectButton.Name = "connectButton"; + this.connectButton.UseUnderline = true; + this.connectButton.Label = global::Mono.Unix.Catalog.GetString("Connect"); + this.hbox2.Add(this.connectButton); + global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.connectButton])); + w7.Position = 6; + w7.Expand = false; + w7.Fill = false; + this.vbox2.Add(this.hbox2); + global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.vbox2[this.hbox2])); + w8.Position = 0; + w8.Expand = false; + w8.Fill = false; + // Container child vbox2.Gtk.Box+BoxChild + this.GtkScrolledWindow = new global::Gtk.ScrolledWindow(); + this.GtkScrolledWindow.Name = "GtkScrolledWindow"; + this.GtkScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1)); + // Container child GtkScrolledWindow.Gtk.Container+ContainerChild + this.outputTv = new global::Gtk.TextView(); + this.outputTv.CanFocus = true; + this.outputTv.Name = "outputTv"; + this.outputTv.Editable = false; + this.GtkScrolledWindow.Add(this.outputTv); + this.vbox2.Add(this.GtkScrolledWindow); + global::Gtk.Box.BoxChild w10 = ((global::Gtk.Box.BoxChild)(this.vbox2[this.GtkScrolledWindow])); + w10.Position = 1; + // Container child vbox2.Gtk.Box+BoxChild + this.hbox1 = new global::Gtk.HBox(); + this.hbox1.Name = "hbox1"; + this.hbox1.Spacing = 6; + // Container child hbox1.Gtk.Box+BoxChild + this.messageEntry = new global::Gtk.Entry(); + this.messageEntry.CanFocus = true; + this.messageEntry.Name = "messageEntry"; + this.messageEntry.IsEditable = true; + this.messageEntry.InvisibleChar = '•'; + this.hbox1.Add(this.messageEntry); + global::Gtk.Box.BoxChild w11 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.messageEntry])); + w11.Position = 0; + // Container child hbox1.Gtk.Box+BoxChild + this.sendButton = new global::Gtk.Button(); + this.sendButton.CanFocus = true; + this.sendButton.Name = "sendButton"; + this.sendButton.UseUnderline = true; + this.sendButton.Label = global::Mono.Unix.Catalog.GetString("Send"); + this.hbox1.Add(this.sendButton); + global::Gtk.Box.BoxChild w12 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.sendButton])); + w12.Position = 1; + w12.Expand = false; + w12.Fill = false; + this.vbox2.Add(this.hbox1); + global::Gtk.Box.BoxChild w13 = ((global::Gtk.Box.BoxChild)(this.vbox2[this.hbox1])); + w13.Position = 2; + w13.Expand = false; + w13.Fill = false; + this.Add(this.vbox2); + if ((this.Child != null)) + { + this.Child.ShowAll(); + } + this.DefaultWidth = 594; + this.DefaultHeight = 412; + this.Show(); + this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent); + this.connectButton.Clicked += new global::System.EventHandler(this.Connect); + this.sendButton.Clicked += new global::System.EventHandler(this.SendMessage); + } +} diff --git a/Client/gtk-gui/generated.cs b/Client/gtk-gui/generated.cs new file mode 100644 index 0000000..4842e95 --- /dev/null +++ b/Client/gtk-gui/generated.cs @@ -0,0 +1,30 @@ + +// This file has been generated by the GUI designer. Do not modify. +namespace Stetic +{ + internal class Gui + { + private static bool initialized; + + internal static void Initialize(Gtk.Widget iconRenderer) + { + if ((Stetic.Gui.initialized == false)) + { + Stetic.Gui.initialized = true; + } + } + } + + internal class ActionGroups + { + public static Gtk.ActionGroup GetActionGroup(System.Type type) + { + return Stetic.ActionGroups.GetActionGroup(type.FullName); + } + + public static Gtk.ActionGroup GetActionGroup(string name) + { + return null; + } + } +} diff --git a/Client/gtk-gui/gui.stetic b/Client/gtk-gui/gui.stetic new file mode 100644 index 0000000..204b8b1 --- /dev/null +++ b/Client/gtk-gui/gui.stetic @@ -0,0 +1,187 @@ + + + + .. + + + + + + + + TcpChat Client + CenterOnParent + 10 + + + + + 6 + + + + 6 + + + + Username: + + + 0 + True + False + False + + + + + + True + Marcin + True + + + + 1 + True + + + + + + IP address: + + + 2 + True + False + False + + + + + + 110 + True + 127.0.0.1 + True + + + + 3 + True + + + + + + Port: + + + 4 + True + False + False + + + + + + 50 + True + 6789 + True + + + + 5 + True + + + + + + True + TextOnly + Connect + True + + + + 6 + True + False + False + + + + + 0 + True + False + False + + + + + + In + + + + True + True + False + + + + + + 1 + True + + + + + + 6 + + + + True + True + + + + 0 + True + + + + + + True + TextOnly + Send + True + + + + 1 + True + False + False + + + + + 2 + True + False + False + + + + + + \ No newline at end of file -- cgit v1.2.3