static void Main(string[] args) { var menu = new EasyConsole.Menu() .Add("Crash", Crash) .Add("Quit", () => Environment.Exit(0)); while (true) { menu.Display(); Console.WriteLine(); Console.WriteLine("------------"); } }
public static void Main() { var MainMenu = new EasyConsole.Menu() .Add("Persistence using C#", () => SharpWMIPersist()) .Add("Persistence using WMIC", () => InvokeWMIC()) .Add("Persistence using Powershell CIM cmdlets", () => PoshCIM()) .Add("Persistence using Powershell WMI cmdlets", () => PoshWMI()) .Add("Persistence using mofcomp.exe", () => MofComp()) .Add("Persistence using Empire's persistence/elevated/wmi", () => InvokeEmpire()) .Add("Get Rid of the components", () => Cleaner()); MainMenu.Display(); }
static void Main(string[] args) { //Console.ForegroundColor = ConsoleColor.Cyan; bool showMenu = true; while (showMenu) { showMenu = MainMenu(); } var menu = new EasyConsole.Menu(); menu.Display(); }
static void Main() { while (true) { Console.WriteLine("Press select message type..."); var menu = new EasyConsole.Menu() .Add("Send Message Earth and Mars", MarsMessage) .Add("Send Message Earth and Saturn", SaturnMessage) //.Add("Publish Simple Message", SimpleMessage) ; menu.Display(); Console.WriteLine("message send..."); } }
private static void StartingMenu() { var menu = new Menu() .Add("Set bot token", SetBotToken) .Add("Set General Managers order", SetGmOrder) .Add("Set VNC role name", SetVncRoleName) .Add("Set host position", SetHostPosition) .Add("Set whether save requests should be deleted", SetDeleteSaveRequest) .Add("Set how long a save takes", SetMillisecondsToSave) .Add("Set the save announce channel", SetSaveAnnounceChannel) .Add("Set bot request channel", SetSaveRequestChannel) .Add("Set save location", SetSaveLocation) .Add("Set game exe location", SetGameLocation) .Add("Set save prefix", SetSavePrefix) .Add("Set rolling save amount", SetRollingSaveAmount) .Add("Set default sim length", SetDefaultSimLength) .Add("Set click positions", SetClickPositions) .Add("View settings", View) .Add("Save settings", Save); menu.Display(); }
static void PromptParametersAndDeploy() { try { ConsoleUtils.WriteHeader("MarketplaceDeployConsole started"); Console.WriteLine("Select a plugin to deploy"); SavedDeployments SavedDeployments = Properties.Settings.Default.SavedDeployments ?? new SavedDeployments(); // Clear out invalid paths SavedDeployments.PluginParams.RemoveAll(Params => !Directory.Exists(Params.PluginPath)); Properties.Settings.Default.SavedDeployments = SavedDeployments; Properties.Settings.Default.Save(); // Build menu EasyConsole.Menu Menu = new EasyConsole.Menu(); foreach (DeployParams Params in SavedDeployments.PluginParams) { string PluginName = DeployUtils.FindPluginName(Params.PluginPath); string ProjectName = DeployUtils.FindHostProjectName(Params.PluginPath); Menu.Add(ProjectName + "/" + PluginName, () => { // Selected existing plugin DeployParams UseParams = Params; ConsoleUtils.WriteHeader("Deploying " + DeployUtils.FindPluginName(Params.PluginPath)); Console.WriteLine("Last used parameters were"); Console.WriteLine(); Console.WriteLine(UseParams.PrintParameters()); Console.WriteLine(); bool Reuse = ConsoleUtils.PromptBool("Use these again?", true); if (!Reuse) { UseParams = PromptParams(UseParams); } SaveParams(Params); Deploy.RunDeployment(Params); }); } Menu.Add("New", () => { string SelectDirectoryPrompt = "Select plugin directory within its example/host project"; Console.WriteLine(SelectDirectoryPrompt); FolderBrowserDialog Dialog = new FolderBrowserDialog(); Dialog.Description = SelectDirectoryPrompt; Dialog.SelectedPath = Properties.Settings.Default.PluginPath; if (Dialog.ShowDialog() == DialogResult.OK) { DeployParams Params = new DeployParams(); Params.PluginPath = Dialog.SelectedPath; Properties.Settings.Default.PluginPath = Dialog.SelectedPath; Properties.Settings.Default.Save(); ConsoleUtils.WriteHeader("Deploying " + DeployUtils.FindPluginName(Params.PluginPath)); Params = PromptParams(Params); SaveParams(Params); Deploy.RunDeployment(Params); } }); Menu.Display(); } catch (Exception Ex) { ConsoleUtils.WriteHeader("Encountered exception"); Console.WriteLine(Ex.GetType()); Console.WriteLine(Ex.Message); Console.WriteLine(Ex.StackTrace); Console.WriteLine(Ex.ToString()); } }
static void Main(string[] args) { var salir = false; var menu = new EasyConsole.Menu() .Add("Ex1", () => { Alumno alumno = new Alumno("Weixin", 24); alumno.Imprimir(); alumno.MayorDeEdad(); }) .Add("Ex2", () => { Empleado empleado = new Empleado("A", 1000.50); empleado.ImprimirDatos(); empleado.PagarImpuesto(); }) .Add("Ex3", () => { Operaciones op = new Operaciones(10, 5); op.suma(); op.resta(); op.multiplicar(); op.dividir(); }) .Add("Ex4", () => { PruebaPersona.Inicio(); }) .Add("Ex5", () => { Libro.Inicio(); }) .Add("Ex6", () => { Coche.Inicio(); }) .Add("Ex7", () => { Person p = new Person("Weixin", 24, "123456789B", "M", 45, 160); p.Imprimir(); }) .Add("Ex8", () => { Password psw = new Password(10); }) .Add("Ex9", () => { Electrodomestico el = new Electrodomestico(20, "Negro", 'B', 10); el.Imprimir(); }) .Add("Ex10", () => { Serie serie = new Serie("Yanxi Palace: Princess Adventures", "Chinese Drama", "Netflix", 1); Console.WriteLine(serie); }) .Add("Salir", () => salir = true); while (!salir) { menu.Display(); } }
public static void Main(string[] args) { PublicLibrary.Init(); StandardMessages.WelcomeImage(); var menu = new EasyConsole.Menu() .Add("Catalog", () => { StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("View all the books", () => { Catalog.Instance.GetBookList(); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Search a book", () => //supermenu { StandardMessages.PressKeyToContinue(); }) .Add("Search a book through ID", () => //submenu { StandardMessages.WriteInputBelow(); Catalog.Instance.SearchBookByID(Console.ReadLine()); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Search a book through ISBN", () => //submenu { StandardMessages.WriteInputBelow(); Catalog.Instance.SearchBookByIsbn(Console.ReadLine()); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Search a book by the name of the author", () => //submenu { StandardMessages.WriteInputBelow(); var searchRes = Catalog.Instance.SearchBookByAuthor(Console.ReadLine()); Console.WriteLine(searchRes.First().ISBN); StandardMessages.ResultsCount(searchRes.Count()); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Search a book by title", () => //submenu { StandardMessages.WriteInputBelow(); Catalog.Instance.SearchBookByTitle(Console.ReadLine()); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Library information", () => { Console.WriteLine($"This is the very elaborate information page of the library system."); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Login", () => { StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Help", () => { Console.WriteLine($"This is the very elaborate help page of the library system."); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) //these are accessible only when logged in .Add("Delete a single book from the catalog", () => { Console.WriteLine($"Please input the ID of the book that you want to delete from the catalog."); string input = Console.ReadLine(); if (StandardMessages.AreYouSure().Equals(true)) { Catalog.Instance.RemoveBook(input); } StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Delete all books from the catalog", () => { if (StandardMessages.AreYouSure().Equals(true)) { Catalog.Instance.DeleteAllBooks(); } StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Add a new book to the catalog", () => //needs attention!! { //Catalog.Instance.AddNewBook(); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Add an existing book to the catalog", () => { Catalog.Instance.AddExistingBook(Console.ReadLine()); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Create a backup of the books", () => { Console.WriteLine(@"Choose a filepath, for an instance ''.\Backups\Bookbackup2.json''"); BackUp.Create(Console.ReadLine()); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Load a backup of the books to the current program.", () => { Console.WriteLine(@"Choose a filepath, for an instance ''.\Backups\Bookbackup2.json''"); BackUp.RestoreFromBackup <List <Book> >(Console.ReadLine()); StandardMessages.PressAnyKey(); StandardMessages.PressKeyToContinue(); }) .Add("Exit", () => { Environment.Exit(0); }); //.Add("Exit", () => // { // Environment.Exit(0); // }) while (true) { menu.Display(); } // StandardMessages.WelcomeImage(); // StandardMessages.PressAnyKey(); string StrBooks = DataOperator.ReadFromFile(Constants.BooksDataFile); Console.WriteLine(StrBooks); List <Book> BookList = new List <Book>(); BookList = DataOperator.DeserializeJson <List <Book> >(StrBooks); BookList.First().ShowBookProp(); Catalog.Instance.SetBookList(BookList); //DataOperator.WriteToFile(StrBooks, Constants.bookbackup2); Console.WriteLine($"making a book by rocky"); Book testbook = new BookBuilder() .WithAuthorName("Rocky Dexter") .WithTitle("Love for Jordan") .WithYear(2009) .WithPages(5) .WithLanguage("bird") .WithImageLink("linklink") .WithLink("link") .WithISBN("34023529852") .WithCountry("Netherlands") .CreateBook(); Console.WriteLine($"adding the rocky book to the list of books"); Catalog.Instance.AddNewBook(testbook); Console.WriteLine($"showing some props of the book as first book from the list"); Catalog.Instance.GetBookList().Last().ShowBookProp(); Console.WriteLine($"Now making a backup instance"); BackUp firstbackup = new BackUp(); Console.WriteLine($"now writing the serialised booklist to a file (making a backup)"); BackUp.Create(Constants.bookbackup2); Console.WriteLine($"Showing props from restored backup list"); BackUp.RestoreFromBackup <List <Book> >(Constants.bookbackup2).First().ShowBookProp(); //List<Book> newbooklist = new List<Book>(); //newbooklist = DataOperator.Load<Book>("Data\\Books.json"); //BackUp firstbackup = new BackUp(); //firstbackup.Create(BackUp.backupnum.Backupnumber2); /*List<Book> testlist= new List<Book>(); * * testlist.Add(testbook); * firstbackup.TempCreateWritebackup(testlist);*/ Console.WriteLine("I guess it worked"); StandardMessages.PressAnyKey(); Console.ReadLine(); /*Console.WriteLine("Welcome User"); * //catalog.LoadBookFile(@"Data\Books.json"); * Book abc = new Book(); * foreach (Book bk in Catalog.Instance.SearchBookByAuthor("Andersen")) * { * Console.WriteLine("Found a book :)"); * bk.ShowBookProp(); * abc = bk; * } * * Console.Write("before..."); * Console.ReadLine(); * * catalog.RemoveBook(catalog.SearchBookByID(abc.ID).ID); * * Console.Write("after..."); * Console.ReadLine();*/ /* * foreach (Book bk in catalog.SearchBookByAuthor("Andersen")) * { * Console.WriteLine("Found a book :)"); * bk.ShowBookProp(); * } * Console.Write(">"); * Console.ReadLine(); * * BookBuilder Noordhoff = new BookBuilder(); * Book JRaf_see_stuff = Noordhoff * .WithAuthorName("JRAF") * //.WithAvailability(true) * .WithCountry("Netherlands") * .WithLanguage("English") * .WithPages(250) * .WithYear(2018) * .WithTitle("A whole life") * .WithImageLink("home") * .CreateBook(); * * Book new_book_one = new BookBuilder() * .WithAuthorName("Vincent Van Andersen") * .WithCountry("Netherlands") * .WithLanguage("English") * .WithPages(250) * .WithYear(2018) * .WithTitle("A whole life of me") * .WithImageLink("home") * .CreateBook(); * * Book new_book_two = new BookBuilder() * .WithAuthorName("Vincent v. Andersen") * .WithCountry("Netherlands") * .WithLanguage("English") * .WithPages(250) * .WithYear(2018) * .WithTitle("A whole life of me") * .WithImageLink("home") * .CreateBook(); * * JRaf_see_stuff.ShowBookProp(); * * Console.Write(">"); * Console.ReadLine(); * * catalog.AddNewBook(JRaf_see_stuff); * * Console.WriteLine("Looking for freshly added book :)"); * foreach (Book book in catalog.SearchBookByAuthor("JRaf")) * { * Console.WriteLine("Found a book :)"); * book.ShowBookProp(); * } * */ Console.Write(">"); Console.ReadLine(); }
public bool Show() { bool Result = false; int tNum = -1; // Instance of widgets // Label lblInfo = new Label(); // Button btnConnect = new Button(); // Button btnRefresh = new Button(); // ListViewGroup listViewGroup = new ListViewGroup("Consoles", HorizontalAlignment.Left); // ListView listView = new ListView(); // Form formList = new Form(); // Create our button connect // btnConnect.Location = new Point(12, 254); // btnConnect.Name = "btnConnect"; // btnConnect.Size = new Size(198, 23); // btnConnect.TabIndex = 1; // btnConnect.Text = strTraduction("btnConnect"); // btnConnect.UseVisualStyleBackColor = true; // btnConnect.Enabled = false; // btnConnect.Click += (sender, e) => // { // if(tNum > -1) // { // if (Api.ConnectTarget(data[tNum].Ip)) // { // Api.setTargetName(data[tNum].Name); // Result = true; // } // else Result = false; // formList.Close(); // } // else // MessageBox.Show(strTraduction("errorSelect"), strTraduction("errorSelectTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); // }; // Create our button refresh // btnRefresh.Location = new Point(216, 254); // btnRefresh.Name = "btnRefresh"; // btnRefresh.Size = new Size(86, 23); // btnRefresh.TabIndex = 1; // btnRefresh.Text = strTraduction("btnRefresh"); // btnRefresh.UseVisualStyleBackColor = true; // btnRefresh.Click += (sender, e) => // { // tNum = -1; // listView.Clear(); // lblInfo.Text = strTraduction("selectGrid"); // btnConnect.Enabled = false; // data = Api.CCAPI.GetConsoleList(); // int sizeD = data.Count(); // for (int i = 0; i < sizeD; i++) // { // ListViewItem item = new ListViewItem(" " + data[i].Name + " - " + data[i].Ip); // item.ImageIndex = 0; // listView.Items.Add(item); // } // }; // Create our list view // listView.Font = new Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); // listViewGroup.Header = "Consoles"; // listViewGroup.Name = "consoleGroup"; // listView.Groups.AddRange(new ListViewGroup[] {listViewGroup}); // listView.HideSelection = false; // listView.Location = new Point(12, 12); // listView.MultiSelect = false; // listView.Name = "ConsoleList"; // listView.ShowGroups = false; // listView.Size = new Size(290, 215); // listView.TabIndex = 0; // listView.UseCompatibleStateImageBehavior = false; // listView.View = View.List; // listView.ItemSelectionChanged += (sender, e) => // { // tNum = e.ItemIndex; // btnConnect.Enabled = true; // string Name, Ip = "?"; // if (data[tNum].Name.Length > 18) // Name = data[tNum].Name.Substring(0, 17) + "..."; // else Name = data[tNum].Name; // if (data[tNum].Ip.Length > 16) // Ip = data[tNum].Name.Substring(0, 16) + "..."; // else Ip = data[tNum].Ip; // lblInfo.Text = strTraduction("selectedLbl") + " " + Name + " / " + Ip; // }; // Create our label // lblInfo.AutoSize = true; // lblInfo.Location = new Point(12, 234); // lblInfo.Name = "lblInfo"; // lblInfo.Size = new Size(158, 13); // lblInfo.TabIndex = 3; // lblInfo.Text = strTraduction("selectGrid"); // Create our form // formList.MinimizeBox = false; // formList.MaximizeBox = false; // formList.ClientSize = new Size(314, 285); // formList.AutoScaleDimensions = new SizeF(6F, 13F); // formList.AutoScaleMode = AutoScaleMode.Font; // formList.FormBorderStyle = FormBorderStyle.FixedSingle; // formList.StartPosition = FormStartPosition.CenterScreen; // formList.Text = strTraduction("formTitle"); // formList.Controls.Add(listView); // formList.Controls.Add(lblInfo); // formList.Controls.Add(btnConnect); // formList.Controls.Add(btnRefresh); // Start to update our list // ImageList imgL = new ImageList(); // imgL.Images.Add(Resources.ps3); // listView.SmallImageList = imgL; // int sizeData = data.Count(); // for (int i = 0; i < sizeData; i++) // { // ListViewItem item = new ListViewItem(" " + data[i].Name + " - " + data[i].Ip); // item.ImageIndex = 0; // listView.Items.Add(item); // } data = Api.CCAPI.GetConsoleList(); var menu = new EasyConsole.Menu(); data.ForEach( console => menu.Add(" " + console.Name + " - " + console.Ip, () => { if (Api.ConnectTarget(console.Ip)) { Api.setTargetName(console.Name); Result = true; } }) ); menu.Display(); // If there are more than 0 targets we show the form // Else we inform the user to create a console. // if (sizeData > 0) // formList.ShowDialog(); // else // { // Result = false; // formList.Close(); // throw new Exception(strTraduction("noConsole")); // //MessageBox.Show(), strTraduction("noConsoleTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); // } return(Result); }
static void Main(string[] args) { // starting the menu. bool continuteToNext = true; menu = new EasyConsole.Menu() .Add("Exit", () => { continuteToNext = false; }) .Add("Connect", () => { Com.Connect(); Console.WriteLine("Connected to remote."); }) .Add("Listen", () => { Com.Listen(); Console.WriteLine("Listening for connections."); }) .Add("Flip logging", () => { Com.DoLogging = !Com.DoLogging; Console.WriteLine("Logging is " + (Com.DoLogging ? "ON" : "OFF")); }) .Add("Send warning command to client.", () => { Console.WriteLine("Write something to log <enter for default log>:"); string theWarning = Console.ReadLine(); if (theWarning == null || theWarning.Length == 0) { theWarning = "[Somekinda default warning...]"; } NPMessage rsp = Com.Send(NPMessageType.Warning, theWarning, (NPMessageNamepathData)null); if (rsp == null) { return; } Console.WriteLine("Expose has responded with: " + rsp.Text == null ? "[UNKNOWN!]" : rsp.Text); }) .Add("Send simple set", () => { Console.WriteLine("Waht is the property to set (string)? [<enter> = 'TestString']"); string theprop = Console.ReadLine(); Console.WriteLine("Waht is the value to set (string)? [<enter> = 'Lama?']"); string thevalue = Console.ReadLine(); Com.Send(NPMessageType.Set, "", new NPMessageNamepathData( theprop == "" ? "TestString" : theprop, thevalue == "" ? "Lama?" : thevalue)); }) .Add("Send test matrix", () => { Console.WriteLine("Waht is the property to set (string)? [<enter> = 'TestMatrix']"); string theprop = Console.ReadLine(); Console.WriteLine("MatirixSize a*a, a= ? [<enter> = '1000']"); string thevalue = Console.ReadLine(); int a = int.TryParse(thevalue, out a) ? a : 1000; theprop = theprop == "" ? "TestMatrix" : theprop; Array mat = MakeLargeNumericMatrix <double>(a); Com.Send(NPMessageType.Set, "", new NPMessageNamepathData(theprop, mat), true); Console.WriteLine("Updating " + theprop + " with matrix of length " + mat.Length); }) .Add("Send repeating large matrix until stopped.", () => { Console.WriteLine("Waht is the property to set (string)? [<enter> = 'TestMatrix']"); string theprop = Console.ReadLine(); Console.WriteLine("MatirixSize a*a, a= ? [<enter> = '1000']"); string thevalue = Console.ReadLine(); int a = int.TryParse(thevalue, out a) ? a : 1000; theprop = theprop == "" ? "TestMatrix" : theprop; Console.WriteLine("Starting continues updates of " + theprop + " with matrix of length " + a * a); bool isRunning = true; Task.Run(() => { while (isRunning) { Array mat = MakeLargeNumericMatrix <double>(a); Com.Send(NPMessageType.Set, "", new NPMessageNamepathData(theprop, mat), true); Console.WriteLine("Send success."); } }); Console.WriteLine("Any key to stop."); Console.ReadKey(); isRunning = false; }) .Add("Send Bing and small", () => { Console.WriteLine("Sending big and small data to check data sync."); Console.WriteLine("Send big (no need for response)."); Com.Send(NPMessage.FromValue(new double[10000], NPMessageType.Set, "big")); Console.WriteLine("Send small (need for response)."); Com.Send(NPMessage.FromValue("", NPMessageType.Invoke, "small"), true); }) .Add("Send fast large matrix to update, (Fail on labview?)", () => { Console.WriteLine("Waht is the property to set (string)? [<enter> = 'TestMatrix']"); string theprop = Console.ReadLine(); Console.WriteLine("Delay between sends [ms] ? [<enter> = '100']"); string thevalue = Console.ReadLine(); Console.WriteLine("# of messages to send ? [<enter> = '100']"); string thecount = Console.ReadLine(); int dt = int.TryParse(thevalue, out dt) ? dt : 100; int n = int.TryParse(thecount, out n) ? n : 100; bool isRunning = true; int sentCount = 0; Task.Run(() => { while (isRunning) { System.Threading.Thread.Sleep(dt); Array mat = MakeLargeNumericMatrix <double>(1000); Com.Send(NPMessageType.Set, "", new NPMessageNamepathData(theprop, mat), false); sentCount++; if (sentCount > n) { Console.WriteLine("Completed send of " + sentCount + " messages"); isRunning = false; } } }); Console.WriteLine("Any key to stop."); Console.ReadKey(); isRunning = false; Console.WriteLine("Sent " + sentCount + " messages."); }) .Add("Flip set silent mode", () => { SilentSetMode = !SilentSetMode; SilentSetModeCount = 0; Console.WriteLine("Silent set moe: " + SilentSetMode); }) .Add("Test get response: ", () => { Console.WriteLine("Waht is the property to get? [<enter> = 'TestString']"); string theprop = Console.ReadLine(); if (theprop.Length == 0) { theprop = "TestString,TestMatrix"; } string[] props = theprop.Split(',').Select(p => p.Trim()).ToArray(); NPMessage rsp = Com.Get(props); // printing the information gathered. if (rsp == null || rsp.NamePaths == null) { Console.WriteLine("Property '" + theprop + "' not found."); } else { Console.WriteLine("Got Property '" + theprop + "':"); foreach (var npd in rsp.NamePaths) { Console.WriteLine("\t" + npd.Namepath + "(" + npd.Value.GetType() + "): " + npd.Value); } } }) .Add("Test multiple connection clients", () => { var clientA = new CSCom.CSCom(); var clientB = new CSCom.CSCom(); clientA.Connect(); Console.WriteLine("Connected client A."); clientB.Connect(); Console.WriteLine("Connected client B."); clientA.Send(NPMessage.FromValue(new byte[200]), true); Console.WriteLine("Send client a ok."); clientB.Send(NPMessage.FromValue(new byte[200]), true); Console.WriteLine("Send client b ok."); Console.WriteLine("Press any key to disconnect..."); Console.ReadKey(); clientA.Stop(); clientB.Stop(); }) .Add("Test websocket client server", () => { Console.WriteLine("Client server test"); WebsocketPipe.WebsocketPipeWS server = new WebsocketPipe.WebsocketPipeWS(new Uri("ws://localhost:50001/CSCom")); WebsocketPipe.WebsocketPipeWS client = new WebsocketPipe.WebsocketPipeWS(new Uri("ws://localhost:50001/CSCom")); int smsgIdx = 0, cmsgIdx = 0; Action <string, int, byte[]> pnt = (caller, idx, data) => { Console.WriteLine(caller + " recived msg (#" + idx + "), with " + (data == null ? 0 : data.Length) + " bytes"); }; server.MessageRecived += (s, e) => { pnt("server", smsgIdx, e.Data); smsgIdx++; }; client.MessageRecived += (s, e) => { pnt("client", cmsgIdx, e.Data); cmsgIdx++; }; server.Listen(); client.Connect(); byte[] bigdata = new byte[10000]; byte[] smalldata = new byte[1]; Console.WriteLine("Connected."); Console.WriteLine("Sending from client:"); int n = 5; for (int i = 0; i < n; i++) { client.Send(bigdata); client.Send(smalldata); } System.Threading.Thread.Sleep(1000); Console.WriteLine("Sending from server:"); for (int i = 0; i < n; i++) { server.Send(bigdata); server.Send(smalldata); } System.Threading.Thread.Sleep(1000); client.Stop(); server.Stop(); }) .Add("Test websocket pipe client server", () => { Console.WriteLine("Client server test"); WebsocketPipe.WebsocketPipe <byte[]> server = new WebsocketPipe.WebsocketPipe <byte[]>(new Uri("ws://localhost:50001/CSCom")); WebsocketPipe.WebsocketPipe <byte[]> client = new WebsocketPipe.WebsocketPipe <byte[]>(new Uri("ws://localhost:50001/CSCom")); server.Timeout = 1000; client.Timeout = 1000; int smsgIdx = 0, cmsgIdx = 0; object loglock = new object(); Action <string, int, byte[], int> pnt = (caller, idx, data, inblock) => { Console.WriteLine(caller + " recived msg (#" + idx + "), with " + (data == null ? 0 : data.Length) + " bytes, " + inblock + " in block"); }; server.MessageRecived += (s, e) => { lock (loglock) { pnt("server", smsgIdx, e.Message, e.NumberOfMessagesInBlock); smsgIdx++; } }; client.MessageRecived += (s, e) => { lock (loglock) { pnt("client", cmsgIdx, e.Message, e.NumberOfMessagesInBlock); cmsgIdx++; } }; server.Listen(); System.Threading.Thread.Sleep(10); client.Connect(); System.Threading.Thread.Sleep(10); byte[] bigdata = new byte[1000000]; byte[] smalldata = new byte[1]; Console.WriteLine("Connected."); Console.WriteLine("Sending from client:"); int n = 5; for (int i = 0; i < n; i++) { client.Send(bigdata); client.Send(smalldata); } Console.WriteLine("Completed sending, waiting for recive."); while (smsgIdx < n) { System.Threading.Thread.Sleep(10); } System.Threading.Thread.Sleep(10); Console.WriteLine("Sending from server:"); for (int i = 0; i < n; i++) { server.Send(bigdata); server.Send(smalldata); } Console.WriteLine("Completed sending, waiting for recive."); while (cmsgIdx < n) { System.Threading.Thread.Sleep(10); } System.Threading.Thread.Sleep(10); Console.WriteLine("Complete. Closing."); client.Stop(); server.Stop(); client.Dispose(); server.Dispose(); }) .Add("Test memory mapped file stack", () => { WebsocketPipe.MemoryMappedBinaryStack stack = new WebsocketPipe.MemoryMappedBinaryStack("Lama this stack"); List <byte[]> els = new List <byte[]>(); int n = 100; Random rn = new Random(); int totalSize = 0; Console.WriteLine("Writing arrays of sizes:"); for (int i = 0; i < n; i++) { byte[] ar = new byte[rn.Next(1000000)]; totalSize += ar.Length; els.Add(ar); Console.Write((i == 0 ? "" : ", ") + ar.Length); } Console.WriteLine(); Stopwatch watch = new Stopwatch(); watch.Start(); //stack.Lock(); foreach (byte[] ar in els) { stack.Push(ar); } //stack.UnLock(); watch.Stop(); Console.WriteLine(); Console.WriteLine("Pushed total of " + totalSize + " [bytes] in " + els.Count + " elements in [ms]: " + watch.Elapsed.TotalMilliseconds); Console.WriteLine("Reading..."); watch.Reset(); watch.Start(); //stack.Lock(); for (int i = 0; i < els.Count; i++) { byte[] read = stack.Pop(); byte[] shouldBe = els[els.Count - i - 1]; Console.WriteLine("read " + read.Length + " ?= " + shouldBe.Length + " " + (read.Length == shouldBe.Length ? "OK" : "ERROR")); } //stack.UnLock(); Console.WriteLine("Read total of " + totalSize + " [bytes] in " + els.Count + " elements in [ms]: " + watch.Elapsed.TotalMilliseconds); watch.Reset(); watch.Start(); stack.Push(els.ToArray()); watch.Stop(); Console.WriteLine("Multipush same array in [ms] " + watch.Elapsed.TotalMilliseconds); watch.Reset(); watch.Start(); byte[][] readEls = stack.Empty().Reverse().ToArray(); watch.Stop(); Console.WriteLine("Multipop (empty) same array in [ms] " + watch.Elapsed.TotalMilliseconds); int errored = 0; for (int i = 0; i < els.Count; i++) { byte[] read = readEls[i]; byte[] shouldBe = els[i]; if (read.Length != shouldBe.Length) { Console.WriteLine("read " + read.Length + " ?= " + shouldBe.Length + " -> ERROR"); errored++; } } Console.WriteLine(errored + " errors found."); stack.Dispose(); }) .Add("Test memory mapped file queue", () => { WebsocketPipe.MemoryMappedBinaryQueue queue = new WebsocketPipe.MemoryMappedBinaryQueue("Lama this stack"); List <byte[]> els = new List <byte[]>(); int n = 100; Random rn = new Random(); int totalSize = 0; Console.WriteLine("Writing arrays of sizes:"); for (int i = 0; i < n; i++) { byte[] ar = new byte[rn.Next(1000000)]; ar[0] = 1; totalSize += ar.Length; els.Add(ar); Console.Write((i == 0 ? "" : ", ") + ar.Length); } Console.WriteLine(); Stopwatch watch = new Stopwatch(); watch.Start(); //stack.Lock(); foreach (byte[] ar in els) { queue.Enqueue(ar); } //stack.UnLock(); watch.Stop(); Console.WriteLine(); Console.WriteLine("Pushed total of " + totalSize + " [bytes] in " + els.Count + " elements in [ms]: " + watch.Elapsed.TotalMilliseconds); Console.WriteLine("Reading..."); watch.Reset(); watch.Start(); //stack.Lock(); for (int i = 0; i < els.Count; i++) { byte[] read = queue.Dequeue(); byte[] shouldBe = els[i]; Console.WriteLine("read " + read.Length + " ?= " + shouldBe.Length + " " + (read.Length == shouldBe.Length ? "OK" : "ERROR")); } //stack.UnLock(); Console.WriteLine("Read total of " + totalSize + " [bytes] in " + els.Count + " elements in [ms]: " + watch.Elapsed.TotalMilliseconds); watch.Reset(); watch.Start(); queue.Enqueue(els.ToArray()); watch.Stop(); Console.WriteLine("Multipush same array in [ms] " + watch.Elapsed.TotalMilliseconds); watch.Reset(); watch.Start(); byte[][] readEls = queue.Empty().ToArray(); watch.Stop(); Console.WriteLine("Multipop (empty) same array in [ms] " + watch.Elapsed.TotalMilliseconds); int errored = 0; for (int i = 0; i < els.Count; i++) { byte[] read = readEls[i]; byte[] shouldBe = els[i]; if (read.Length != shouldBe.Length) { Console.WriteLine("read " + read.Length + " ?= " + shouldBe.Length + " -> ERROR"); errored++; } } Console.WriteLine(errored + " errors found."); queue.Dispose(); }) .Add("Open matlab file", () => { System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Filter = "Matlab Files|*.m"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { CSCom.CSCom.OpenMatlabFile(ofd.FileName); } }) .Add("Test event dispatch", () => { var last = DateTime.Now; int delay = 1000; DelayedEventDispatch dispatch = new DelayedEventDispatch(); dispatch.Ready += (s, e) => { DateTime now = DateTime.Now; if ((now - last).TotalMilliseconds < delay) { Console.WriteLine("Dispatch error."); } else { Console.WriteLine("Dispatch"); } last = now; }; for (int i = 0; i < 10000; i++) { dispatch.Trigger(delay); if (i % 2 == 0) { System.Threading.Thread.Sleep(1); } } Console.WriteLine("ok"); }); Com.MessageRecived += On_MessageRecived; Com.Log += Client_Log; while (continuteToNext) { menu.Display(); if (!continuteToNext) { break; } //Console.WriteLine("Press q to exit or any other key to continue."); //continuteToNext = Console.ReadKey(true).Key != ConsoleKey.Q; } Console.WriteLine("Any key to exit..."); Console.ReadKey(); }