public override async Task<Connections> GetConnections() { if (isPrePairedDevice) { PeerFinder.AlternateIdentities["Bluetooth:Paired"] = ""; } try { var devices = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort); var peers = await DeviceInformation.FindAllAsync(devices); var connections = new Connections(); foreach (var peer in peers) { connections.Add(new Connection(peer.Name, peer)); } return connections; } catch (Exception e) { return null; } }
public override async Task<Connections> GetConnections() { var identifyingSubstring = "VID_2341"; try { var devices = SerialDevice.GetDeviceSelector(); var peers = await DeviceInformation.FindAllAsync(devices); var connections = new Connections(); foreach (var peer in peers) { if (peer.Name.Contains(identifyingSubstring) || peer.Id.Contains(identifyingSubstring)) { connections.Add(new Connection(peer.Name, peer)); } } return connections; } catch (Exception) { return null; } }
public override async Task<Connections> GetConnections() { if (isPrePairedDevice) { PeerFinder.AlternateIdentities["Bluetooth:Paired"] = ""; } try { PeerFinder.AllowBluetooth = true; PeerFinder.AllowWiFiDirect = true; PeerFinder.DisplayName = "Virtual Shields"; PeerFinder.Role = PeerRole.Peer; if (!isPrePairedDevice) { PeerFinder.Start(); } var peers = await PeerFinder.FindAllPeersAsync(); var connections = new Connections(); foreach (var peer in peers) { connections.Add(new Connection(peer.DisplayName, peer)); } return connections; } catch (Exception) { return null; } }
public void AddConnection(string container, IDictionary <string, object> connectionDef) { if (!Connections.ContainsKey(container)) { Connections.Add(container, new List <IDictionary <string, object> >()); } // connectionDef.Add("name", Name); Connections[container].Add(connectionDef); }
private void Connect(Stream stream) { var connection = new Connection(stream); connection.MessageReceived += connection_MessageReceived; connection.ScriptReceived += connection_ScriptReceived; connection.Disconnected += connection_Disconnected; Connections.Add(connection); }
/// <summary> /// Mutates a random link whithin the neural network. /// </summary> public void MutateLink() { int from; int to; Stopwatch sw = new Stopwatch(); sw.Start(); do { rand = new Random(Guid.NewGuid().GetHashCode()); do { rand = new Random(Guid.NewGuid().GetHashCode()); from = rand.Next(Neurons.Count()); } while (from > NumInputs - 1 && from < NumInputs + NumOutputs); do { rand = new Random(Guid.NewGuid().GetHashCode()); to = rand.Next(NumInputs, Neurons.Count()); } while (to == from || to < NumInputs || (to < from && to >= NumInputs + NumOutputs)); if (sw.ElapsedMilliseconds > 10) { return; } } while (Connections.Contains(new Tuple <int, int>(from, to))); if (Neurons.TryGetValue(to, out Neuron toNeuron)) { if (Neurons.TryGetValue(from, out Neuron fromNeuron)) { Tuple <int, int> fromToPair = new Tuple <int, int>(from, to); Connection conn; if (InnovationNumbers.ContainsKey(fromToPair)) { lock (InnovationNumbers) { InnovationNumbers.TryGetValue(fromToPair, out int innoNumber); conn = new Connection(innoNumber, fromNeuron, rand.NextDouble() * 4 - 2); } } else { lock (InnovationNumbers) { conn = new Connection(InnovationNumbers.Count(), fromNeuron, rand.NextDouble() * 4 - 2); InnovationNumbers.Add(new Tuple <int, int>(from, to), InnovationNumbers.Count()); } } Connections.Add(fromToPair); toNeuron.AddConnection(conn.ID, conn); } } }
private void Add() { var connectionViewModel = new ConnectionViewModel { IsEditing = true }; Connections.Add(connectionViewModel); SelectedConnection = connectionViewModel; }
public static IEventReader <T> MergeWith <T>(this IEventReader <T> reader, params IEventReader <T>[] others) { if (reader == null || others == null || others.Any(s => s == null)) { throw new ArgumentException("Null streams in merge"); } return(new AnonymousEventReader <T>((Action <T> reaction) => { var disp = new Connections(others.Length + 1); disp.Add(reader.Subscribe(reaction)); foreach (var other in others) { disp.Add(other.Subscribe(reaction)); } return disp; })); }
private void ModifyDefaultOutput() { if (Connections.All(c => c.Name != "output")) { Connections.Add(this.GetDefaultOf <TflConnection>(c => { c.Name = "output"; c.Provider = "internal"; })); } }
private async void Refresh() { IsRefreshing = true; Connections.Clear(); (await Connection.GetActiveTcpConnectionsAsync()).ForEach(x => Connections.Add(x)); IsRefreshing = false; }
private void OnConnectionAccepted(object sender, TcpConnectionEventArgs e) { if (e.AcceptedConnection == null) { return; } SessionManager.GetInstance().NewSession(e.AcceptedConnection); Connections.Add(e.AcceptedConnection); }
public override void Start() { Connections.Add( Plugin.Server.OnUpdateEvent.Connect(Update), Plugin.Server.OnCheckIfModeCanStartEvent.Connect(OnCheckIfModeCanStart), Plugin.Server.OnNeedToSyncLateClientToGameMode.Connect(OnNeedToSyncLateClientToGameMode), Plugin.Server.OnModeStartedEvent.Connect(OnModeStarted), Plugin.OnCheckIfLevelCanAdvanceEvent.Connect(OnCheckIfLevelCanAdvance) ); }
void PreValidateDefaultOutput() { if (Connections.All(c => c.Name != "output")) { Connections.Add(this.GetDefaultOf <Connection>(c => { c.Name = "output"; c.Provider = "internal"; })); } }
/// <summary> /// Create a MetaConnection in the source /// </summary> public MetaConnection AddConnection() { MetaConnection result = MetaConnection.Create(this); result.ConnectionString = DefaultConnectionString; result.Name = Helper.GetUniqueName(result.Name, (from i in Connections select i.Name).ToList()); Connections.Add(result); return(result); }
public void StartListening() { var ipAddress = IPAddress.Parse("127.0.0.1"); var localEndPoint = new IPEndPoint(ipAddress, 8080); var listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { listener.Bind(localEndPoint); listener.Listen(10); while (true) { var handler = listener.Accept(); if (!Connections.Any(socket => socket.Equals(handler))) { var syncFilesAction = new SyncFilesAction(Directory); var teste = FileHelper.Serialize(syncFilesAction); handler.Send(FileHelper.Serialize(syncFilesAction)); Connections.Add(handler); new Thread(() => { var client = handler; while (true) { try { var bytes = new Byte[1024]; client.Receive(bytes); var action = (FileAction)FileHelper.Deserialize(bytes); ExecuteAction(action); SendActionToOthers(action, client); } catch (SocketException e) { client.Shutdown(SocketShutdown.Both); client.Close(); Connections.Remove(client); break; } } }).Start(); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
private void FillConnectors(DescriptorBase accessDescriptor) { var conn = accessDescriptor.GetConnectors(this); foreach (var c in conn) { var assignment = (IAssignment)Activator.CreateInstance(GetAssignmentsType()); assignment.SetConnector(c); Connections.Add(assignment); } }
public virtual void AddConnection(CNodeConnectionViewModel newConnection, CPinViewModel otherPin) { int prevConnectionCount = Connections.Count; Connections.Add(newConnection); if (prevConnectionCount == 0) { RaisePropertyChanged("PinInnerColor"); RaisePropertyChanged("IsConnected"); } }
public void AddConnection(Node node) { double CatetA = Math.Abs(Coordinate.X - node.Coordinate.X); double CatetB = Math.Abs(Coordinate.Y - node.Coordinate.Y); double Distance = Math.Sqrt(Math.Pow(CatetA, 2) + Math.Pow(CatetB, 2)); Tuple <Node, double> Connection = new Tuple <Node, double>(node, Distance); Connections.Add(Connection); }
internal object OnConnectionDragStarted(OutputConnectorViewModel sourceConnector, Point currentDragPoint) { var connection = new ConnectionViewModel(sourceConnector) { FromPosition = currentDragPoint }; Connections.Add(connection); return(connection); }
/// <summary> /// Adds a connection. /// </summary> /// <param name="IfaceName">Name of the interface where the connection should be added.</param> /// <param name="Con">The connection to be added.</param> public void AddConnection(string IfaceName, Connection Con) { if (HasInterface(IfaceName)) { Connections.Add(IfaceName, Con); } else { Debug.Assert(false, "Interface: " + IfaceName + " nicht vorhanden, aber es soll eine Verbindung daran gesetzt werden."); } }
private void listenForClientRecievedEvent() { while (true) { TcpConnection connection = new TcpConnection(TcpListener.AcceptTcpClient()); Connections.Add(connection); OnClientConnected(new TcpServerClientConnectedEventArgs { TcpConnection = connection }); } }
public static int PopulateConnections() { var connectionsCreated = 0; for (int i = Connections.Count; i < dbSettings.ShardingFactor; i++) { Connections.Add(GenerateSqlConnection(i)); connectionsCreated++; } return(connectionsCreated); }
public static void InitializeConnection(bool EF) { if (EF) { EFProductRepository Entity = new EFProductRepository(); Connections.Add(Entity); EmailOrderProcessor Order = new EmailOrderProcessor(GlobalConfig.emailSettings); OrderConnections.Add(Order); } }
/// <summary> /// Add a default MetaConnection to the source /// </summary> public void AddDefaultConnection(Repository repository) { if (Connections.Count == 0) { //Add default connection MetaConnection connection = MetaConnection.Create(this); connection.ConnectionString = repository.Configuration.DefaultConnectionString; Connections.Add(connection); ConnectionGUID = connection.GUID; } }
public void AddConnection(ProxyConnection connection) { lock (Connections) { Connections.Add(connection); if (Connections.Count == 1) { Start(); } } }
/// <summary> /// Create a MetaConnection in the source /// </summary> public MetaConnection AddConnection() { MetaConnection result = MetaConnection.Create(this); result.ConnectionString = Repository.Configuration.DefaultConnectionString; result.DatabaseType = ConnectionStringEditor.GetDatabaseType(result.ConnectionString); result.Name = Helper.GetUniqueName(result.Name, (from i in Connections select i.Name).ToList()); Connections.Add(result); return(result); }
private void AddFileConnection(ConnectionManager conn) { Connections connections = connService.GetConnections(); ConnectionManager fileConn = connections.Add("FILE"); fileConn.ConnectionString = conn.ConnectionString; fileConn.Name = CommonUtils.GetNewConnectionName(connections, this.componentMetadata.Name + " - " + conn.Name); connService.AddConnectionToPackage(fileConn); this.componentMetadata.RuntimeConnectionCollection[0].ConnectionManagerID = fileConn.ID; }
/// <summary> /// Searches through the tech tree and creates new connection models /// for each child-to-parent relationship. Connection models are stored /// in <see cref="Connections"/>. /// </summary> public void LinkNodes() { Connections.Clear(); foreach (var node in TechTree) { foreach (var parent in node.Parents) { Connections.Add(new ConnectionViewModel(node, parent)); } } }
void AddEditableItem() { if (Connections.FirstOrDefault(c => c.CanEdit == true) == null) { List <IPAddress> addresses = Platform.GetPCAddresses(); Connections.Add(new ConnectionVM() { Name = "Network", Address = addresses.Count > 0 ? addresses[0].ToString() : "127.0.0.1", Target = Platform.Type.Unknown, CanDelete = false, CanEdit = true }); } }
public static bool EstablishMainConnection() { if (Connections.Count > 0) { return(false); } else { Connections.Add(GenerateSqlConnection(0)); return(true); } }
public override void AddConnection(IRCConnection conn) { if (conn == null) { throw new ArgumentNullException(nameof(conn)); } lock (Sync) { Connections.Add(conn.Socket, conn); Sockets.Add(conn, conn.Socket); base.AddConnection(conn); } }
public PoolObject <MySqlConnection> RentConnection() { return(new PoolObject <MySqlConnection>(Connections.Take(), obj => { if (obj.State != ConnectionState.Open) { throw new Exception("MySqlConnection state has broken"); } Connections.Add(obj); })); }
public void AddConnection(MarkovEdge edge) { TotalAdded++; var existingConnection = Connections.FirstOrDefault(c => c.IsConnectedTo(edge.TargetData)); if (existingConnection != null) { existingConnection.Probability += (1.0 / TotalAdded); } edge.Probability = 1.0 / TotalAdded; Connections.Add(edge); }
private void RefreshDeviceList() { //invoke the listAvailableDevicesAsync method of BluetoothSerial. Since it is Async, we will wrap it in a Task and add a llambda to execute when finished BluetoothSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>().ContinueWith( listTask => { //store the result and populate the device list on the UI thread var action = Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler( () => { _connections = new Connections(); foreach( DeviceInformation device in listTask.Result ) { _connections.Add( new Connection( device.Name, device ) ); } connectList.ItemsSource = _connections; } ) ); } ); }
public override async Task<Connections> GetConnections() { var connections = new Connections(); foreach (var client in clients) { if (client.Value != null && client.Value.Source != null) { var peer = client.Value.Source as RemotePeer; if (peer != null) { if (DateTime.Now.Subtract(peer.Pinged).TotalSeconds > 15) { continue; } } connections.Add(client.Value); } } await Task.FromResult(false); return connections; }
private async void PopulateList() { Connections list; if (this.service == null) { return; } try { list = await this.service.GetConnections(); if (list == null || list.Count == 0) { this.appSettings.ConnectionList.Clear(); return; } } catch (Exception ex) { App.Telemetry.TrackException(ex); return; } if (!list.Any()) { await this.dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { App.Telemetry.TrackEvent("VirtualShieldConnectionEnumerationFail"); }); return; } var connections = new Connections(); foreach (var item in list) { connections.Add(item); } await this.dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { this.appSettings.ConnectionList = connections; App.Telemetry.TrackEvent("VirtualShieldConnectionEnumerationSuccess"); }); }
/// <summary> /// Refreshes the connections from the available device sources /// </summary> /// <returns>Collection of connection objects available to the app</returns> public async Task<Connections> RefreshConnections() { Connections connections = new Connections(); connections.Clear(); await BluetoothSerial.listAvailableDevicesAsync().AsTask().ContinueWith( listTask => { listTask.Result.ForEach( d => connections.Add(new Connection(d.Name, d, ConnectionType.BluetoothSerial))); }); await UsbSerial.listAvailableDevicesAsync().AsTask().ContinueWith( listTask => { listTask.Result.ForEach( d => connections.Add(new Connection(d.Name, d, ConnectionType.UsbSerial))); }); string previousConnection = App.CurrentAppSettings.PreviousConnectionName; if (this.CurrentConnection == null && !string.IsNullOrEmpty(previousConnection) && connections.Any(c => c.DisplayName == App.CurrentAppSettings.PreviousConnectionName)) { await this.Connect( connections.FirstOrDefault( c => c.DisplayName == App.CurrentAppSettings.PreviousConnectionName)); } return connections; }
private static void ResetFlatFileConnectionManager(string flatfile, string rowdelim, string coldelim, string variable, string text_qual, Connections conn) { cm_flat_file = conn.Add("FLATFILE"); cm_flat_file.SetExpression("ConnectionString", variable); IDTSConnectionManagerFlatFile100 cmff = cm_flat_file.InnerObject as IDTSConnectionManagerFlatFile100; // design time wrapper, so we have easy access to all the goodies. cmff = cm_flat_file.InnerObject as IDTSConnectionManagerFlatFile100; //cm_flat_file.ConnectionString = flatfile; cm_flat_file.Name = "flatfile_bot"; cm_flat_file.Properties["Format"].SetValue(cm_flat_file, "Delimited"); cmff.TextQualifier = text_qual; cmff.ColumnNamesInFirstDataRow = true; cmff.RowDelimiter = rowdelim; cmff.HeaderRowDelimiter = rowdelim; }
private async void PopulateList() { Connections list; try { list = await service.GetConnections(); if (list == null) { appSettings.ConnectionList.Clear(); return; } } catch (Exception ex) { //ConnectMessage.Text = "Service not available or supported."; telemetry.TrackException(ex); return; } if (!list.Any()) { await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { //ConnectMessage.Text = // "No devices found."; telemetry.TrackEvent("VirtualShieldConnectionEnumerationFail"); }); return; } var connections = new Connections(); foreach (var item in list) { connections.Add(item); } appSettings.ConnectionList = connections; telemetry.TrackEvent("VirtualShieldConnectionEnumerationSuccess"); }
private void RefreshDeviceList() { //invoke the listAvailableDevicesAsync method of the correct Serial class. Since it is Async, we will wrap it in a Task and add a llambda to execute when finished Task<DeviceInformationCollection> task = null; if( ConnectionMethodComboBox.SelectedItem == null ) { ConnectMessage.Text = "Select a connection method to continue."; return; } switch( ConnectionMethodComboBox.SelectedItem as String ) { default: case "Bluetooth": ConnectionList.Visibility = Visibility.Visible; NetworkConnectionGrid.Visibility = Visibility.Collapsed; //create a cancellation token which can be used to cancel a task cancelTokenSource = new CancellationTokenSource(); cancelTokenSource.Token.Register( () => OnConnectionCancelled() ); task = BluetoothSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>( cancelTokenSource.Token ); break; case "USB": ConnectionList.Visibility = Visibility.Visible; NetworkConnectionGrid.Visibility = Visibility.Collapsed; //create a cancellation token which can be used to cancel a task cancelTokenSource = new CancellationTokenSource(); cancelTokenSource.Token.Register( () => OnConnectionCancelled() ); task = UsbSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>( cancelTokenSource.Token ); break; case "Network": ConnectionList.Visibility = Visibility.Collapsed; NetworkConnectionGrid.Visibility = Visibility.Visible; ConnectMessage.Text = "Enter a host and port to connect"; task = null; break; } if( task != null ) { //store the returned DeviceInformation items when the task completes task.ContinueWith( listTask => { //store the result and populate the device list on the UI thread var action = Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler( () => { Connections connections = new Connections(); var result = listTask.Result; if( result == null || result.Count == 0 ) { ConnectMessage.Text = "No items found."; } else { foreach( DeviceInformation device in result ) { connections.Add( new Connection( device.Name, device ) ); } ConnectMessage.Text = "Select an item and press \"Connect\" to connect."; } ConnectionList.ItemsSource = connections; } ) ); } ); } }
private void RefreshDeviceList() { //invoke the listAvailableDevicesAsync method of the correct Serial class. Since it is Async, we will wrap it in a Task and add a llambda to execute when finished Task<DeviceInformationCollection> task = null; if( ConnectionMethodComboBox.SelectedItem == null ) { ConnectMessage.Text = "Select a connection method to continue."; return; } switch( ConnectionMethodComboBox.SelectedItem as String ) { default: case "Bluetooth": ConnectionList.Visibility = Visibility.Visible; DevicesText.Visibility = Visibility.Visible; NetworkHostNameTextBox.IsEnabled = false; NetworkPortTextBox.IsEnabled = false; BaudRateComboBox.IsEnabled = true; NetworkHostNameTextBox.Text = ""; NetworkPortTextBox.Text = ""; BLESchemaComboBox.IsEnabled = false; //create a cancellation token which can be used to cancel a task cancelTokenSource = new CancellationTokenSource(); cancelTokenSource.Token.Register( () => OnConnectionCancelled() ); task = BluetoothSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>( cancelTokenSource.Token ); break; case "BLE": ConnectionList.Visibility = Visibility.Visible; DevicesText.Visibility = Visibility.Visible; NetworkHostNameTextBox.IsEnabled = false; NetworkPortTextBox.IsEnabled = false; BaudRateComboBox.IsEnabled = false; NetworkHostNameTextBox.Text = ""; NetworkPortTextBox.Text = ""; BLESchemaComboBox.IsEnabled = true; //create a cancellation token which can be used to cancel a task cancelTokenSource = new CancellationTokenSource(); cancelTokenSource.Token.Register(() => OnConnectionCancelled()); task = BleSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>(cancelTokenSource.Token); break; case "USB": ConnectionList.Visibility = Visibility.Visible; DevicesText.Visibility = Visibility.Visible; NetworkHostNameTextBox.IsEnabled = false; NetworkPortTextBox.IsEnabled = false; BaudRateComboBox.IsEnabled = true; NetworkHostNameTextBox.Text = ""; NetworkPortTextBox.Text = ""; BLESchemaComboBox.IsEnabled = false; //create a cancellation token which can be used to cancel a task cancelTokenSource = new CancellationTokenSource(); cancelTokenSource.Token.Register( () => OnConnectionCancelled() ); task = UsbSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>( cancelTokenSource.Token ); break; case "Network": ConnectionList.Visibility = Visibility.Collapsed; DevicesText.Visibility = Visibility.Collapsed; NetworkHostNameTextBox.IsEnabled = true; NetworkPortTextBox.IsEnabled = true; BaudRateComboBox.IsEnabled = false; BLESchemaComboBox.IsEnabled = false; ConnectMessage.Text = "Enter a host and port to connect."; // Last working host and port is persisted across sessions. Retrieve this data. var host = ApplicationData.Current.LocalSettings.Values[SETTINGS_HOST]; var port = ApplicationData.Current.LocalSettings.Values[SETTINGS_PORT]; if (host != null && port != null) { NetworkHostNameTextBox.Text = host.ToString(); NetworkPortTextBox.Text = port.ToString(); } else { NetworkHostNameTextBox.Text = ""; NetworkPortTextBox.Text = ""; } task = null; break; } if( task != null ) { //store the returned DeviceInformation items when the task completes task.ContinueWith( listTask => { //store the result and populate the device list on the UI thread var action = Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler( () => { Connections connections = new Connections(); var result = listTask.Result; if( result == null || result.Count == 0 ) { ConnectMessage.Text = "No items found."; ConnectionList.Visibility = Visibility.Collapsed; } else { foreach( DeviceInformation device in result ) { connections.Add( new Connection( device.Name, device ) ); } ConnectMessage.Text = "Select an item and press \"Connect\" to connect."; } ConnectionList.ItemsSource = connections; } ) ); } ); } }