private bool ParseWebSocketURL() { string url = txtbox_WSServerURL.Text; string[] parts = url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); // Should be something like {"ws:", "127.0.0.1", "route" [, ...] } if (parts.Length < 3) { Logger.Error("Please add a route to the websocket url, like \"/Bridge\""); return(false); } else if (!parts[0].Equals("ws:", StringComparison.InvariantCultureIgnoreCase)) { Logger.Error("WebSocket URL must start with \"ws:\""); return(false); } else if (!Machina.Net.Net.ValidateIPv4Port(parts[1])) { Logger.Error("Invalid IP:Port address \"" + parts[1] + "\""); return(false); } wssvURL = parts[0] + "//" + parts[1]; wssvBehavior = "/" + String.Join("/", parts, 2, parts.Length - 2); Logger.Debug("WebSocket server URL: " + wssvURL); Logger.Debug("WebSocket server route: " + wssvBehavior); return(true); }
private void cbx_FollowPointer_Unchecked(object sender, RoutedEventArgs e) { if (dc != null) { Logger.Debug("Follow program pointer deactivated."); dc.queueFollowPointer = false; } }
protected override void OnClose(CloseEventArgs e) { //base.OnClose(e); Logger.Debug($"WS client disconnected: {e.Code} {e.Reason}"); Logger.Warning("Client \"" + _clientName + "\" disconnected..."); _parent._connectedClients.Remove(_clientName); //_parent.UpdateClientBox(); _parent.uiContext.Post(x => { _parent.UpdateClientBox(); }, null); _parent.wssv.WebSocketServices.Broadcast($"{{\"event\":\"client-disconnected\",\"user\":\"clientname\"}}"); }
// Figures out if auto-scroll, and deactivates follow pointer if not private void QueueScroller_ScrollChanged(object sender, ScrollChangedEventArgs e) { // Figure out if this was related to auto scrolling if (e.VerticalChange == 0.0 || e.ExtentHeight == 0 || e.ExtentHeightChange > 0) { return; } if (isUserScroll && dc.queueFollowPointer) { Logger.Debug("Manual scroll detected, deactivating 'Follow Pointer'."); dc.queueFollowPointer = false; cbx_FollowPointer.IsChecked = false; cbx_FollowPointer_Unchecked(null, null); } isUserScroll = true; }
internal void DownloadDrivers() { Logger.Info("Downloading Machina Drivers for " + _robotBrand + " robot on " + txtbox_IP.Text + ":" + txtbox_Port.Text); // Create a fake robot not to interfere with the main one Robot driverBot = Robot.Create(_robotName, _robotBrand); driverBot.ControlMode(ControlType.Online); var parameters = new Dictionary <string, string>() { { "HOSTNAME", txtbox_IP.Text }, { "PORT", txtbox_Port.Text } }; var files = driverBot.GetDeviceDriverModules(parameters); // Clear temp folder string path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "machina_modules"); //https://stackoverflow.com/a/1288747/1934487 System.IO.DirectoryInfo di = new DirectoryInfo(path); if (di.Exists) { Logger.Debug("Clearing " + path); foreach (FileInfo file in di.GetFiles()) { Logger.Debug("Deleting " + file.FullName); file.Delete(); } foreach (DirectoryInfo dir in di.GetDirectories()) { Logger.Debug("Deleting " + dir.FullName); dir.Delete(true); } } else { di.Create(); Logger.Debug("Created " + path); } // Save temp files foreach (var pair in files) { string filename = pair.Key; string content = pair.Value; string filepath = System.IO.Path.Combine(path, filename); try { System.IO.File.WriteAllText(filepath, content, Encoding.ASCII); } catch { Logger.Error("Could not save " + filename + " to " + filepath); Logger.Error("Could not download drivers"); return; } Logger.Debug("Saved module to " + filepath); } // Zip the file string zipPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "machina_modules.zip"); System.IO.FileInfo fi = new FileInfo(zipPath); if (fi.Exists) { fi.Delete(); Logger.Debug("Deleted previous " + zipPath); } ZipFile.CreateFromDirectory(path, zipPath); Logger.Debug("Zipped files to " + zipPath); // Prompt file save dialog: https://www.wpf-tutorial.com/dialogs/the-savefiledialog/ SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Zip file (*.zip)|*.zip"; saveFileDialog.DefaultExt = "zip"; saveFileDialog.AddExtension = true; saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); saveFileDialog.FileName = "machina_modules.zip"; if (saveFileDialog.ShowDialog() == true) { fi = new FileInfo(saveFileDialog.FileName); if (fi.Exists) { fi.Delete(); Logger.Debug("Deleted previous " + saveFileDialog.FileName); } File.Copy(zipPath, saveFileDialog.FileName); Logger.Debug("Copied " + zipPath + " to " + saveFileDialog.FileName); Logger.Info("Drivers saved to " + saveFileDialog.FileName); } }
private void Bot_MotionUpdate(object sender, MotionUpdateArgs args) { Logger.Debug(args.ToString()); }
private void Wscl_OnOpen(object sender, EventArgs e) { Logger.Debug("Opened WS client connection: "); }
private void Wscl_OnClose(object sender, CloseEventArgs e) { Logger.Debug("Closed WS client connection: " + e.Code + " " + e.Reason); }