private void AfterReceive(IAsyncResult ar) { byte[] received; string receivedStr; ThisDevice clObject = (ThisDevice)ar.AsyncState; try { received = udpCli.EndReceive(ar, ref iPep); receivedStr = Encoding.UTF8.GetString(received); clObject.ipEp = iPep; clObject.data = receivedStr; //Console.WriteLine(clObject.Data); if (receivedStr == "DISCOVER_XSTREAM_SERVER") { Console.WriteLine("RECV_" + receivedStr); data = Encoding.ASCII.GetBytes("DISCOVER_XSTREAM_CLIENT"); Console.WriteLine("SEND_DISCOVER_XSTREAM_CLIENT"); udpCli.Send(data, data.Length, iPep); } else if (receivedStr == "ADD_SUCCESS") { Console.WriteLine("RECEIVE_ADD_SUCCESS"); ConnectedDevices.ManipClientObject(clObject); } else if (receivedStr == "REMOVE_THIS_DEVICE") { Console.WriteLine("RECEIVE_REMOVE_THIS_CLIENT"); ConnectedDevices.ManipClientObject(clObject); } Console.WriteLine("True"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("False"); } if (!bWorker.CancellationPending) { try { Console.WriteLine(iPep.Address.ToString()); //AvailableDevices.ManipThisDevice(clObject); bWorker.ReportProgress(0, clObject); ThisDevice cliObj = new ThisDevice(); data = new byte[1024]; iPep = new IPEndPoint(IPAddress.Any, 8810); cliObj.ipEp = iPep; Console.WriteLine("Beginning receive"); udpCli.BeginReceive(new AsyncCallback(AfterReceive), cliObj); } catch (Exception expc) { MessageBox.Show(expc.Message); } } }
public void AddClient(UdpClient udpCli, ThisDevice clObject) { Console.WriteLine("RECV_DISCOVER_XSTREAM_RESPONSE"); byte[] response = Encoding.ASCII.GetBytes("ADD_XSTREAM_CLIENT"); udpCli.Send(response, response.Length, clObject.ipEp); Console.WriteLine("SEND_ADD_XSTREAM_CLIENT"); }
private void BWorker_DoWork(object sender, DoWorkEventArgs e) { try { IPEndPoint iPepBroadcast = new IPEndPoint(IPAddress.Broadcast, 8810); data = Encoding.ASCII.GetBytes("DISCOVER_XSTREAM_CLIENT"); Console.WriteLine("SEND_DISCOVER_XSTREAM_CLIENT"); udpCli.Send(data, data.Length, iPepBroadcast); } catch (Exception excp) { MessageBox.Show(excp.Message); } try { e.Cancel = false; ThisDevice cliObj = new ThisDevice(); cliObj.ipEp = iPep; udpCli.BeginReceive(new AsyncCallback(AfterReceive), cliObj); while (!bWorker.CancellationPending) { continue; } e.Cancel = true; } catch (Exception exc) { MessageBox.Show(exc.Message); } }
private void MetTile_Click(object sender, System.EventArgs e) { try { MetroTile metTile = (MetroTile)sender; ThisDevice clObject = (ThisDevice)metTile.Tag; AddClient(udpCli, clObject); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public DevicePresenter([NotNull] ApplicationPresenter applicationPresenter, [NotNull] DeviceView view, [NotNull] RealDevice realDevice) : base(view, "ThisDevice.HeaderString", realDevice, applicationPresenter) { _realDevice = realDevice; DeviceCategoryPickerPresenter = new DeviceCategoryPickerPresenter(Sim, _realDevice.DeviceCategory, view.DeviceCategoryPicker1); view.DeviceCategoryPicker1.DataContext = DeviceCategoryPickerPresenter; DeviceCategoryPickerPresenter.Select(); DeviceCategoryPickerPresenter.PropertyChanged += DcpOnPropertyChanged; _timeProfileTypes.Add(TimeProfileType.Relative); _timeProfileTypes.Add(TimeProfileType.Absolute); var u = ThisDevice.CalculateUsedIns(Sim); _usedIns.SynchronizeWithList(u); }
public static ThisDevice Deserialize(Byte[] buffer) { ThisDevice thisDevice = new ThisDevice(); try { str = new MemoryStream(buffer); thisDevice = (ThisDevice)formatter.Deserialize(str); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(thisDevice); }
public static byte[] Serialize(ThisDevice thisDevice) { byte[] binString = { }; try { formatter.Serialize(str, thisDevice); binString = str.ToArray(); foreach (var item in binString) { Console.Write(item); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(binString); }
private void BWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { ThisDevice cObj = (ThisDevice)e.UserState; if (ConnectedDevices.UpdateFlag == 1) { tilesPanel.Controls.Clear(); Console.WriteLine("Updating"); foreach (var item in ConnectedDevices.ListClient) { metTile = new MetroTile(); metTile.Tag = item; metTile.Text = item.ToString(); metTile.Click += MetTile_Click; tilesPanel.Controls.Add(metTile); } ConnectedDevices.UpdateFlag = 0; } }
private void BWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { ThisDevice cObj = (ThisDevice)e.UserState; if (ConnectedDevices.UpdateFlag == 0 && cObj.flag == 1) { Console.Write("\n" + cObj.data); } else if (ConnectedDevices.UpdateFlag == 1) { //availFlowControl.Controls.Clear(); MessageBox.Show("Updating"); foreach (var item in ConnectedDevices.ListClient) { metTile = new MetroTile(); metTile.Tag = item; metTile.Text = item.ToString(); //metTile.Click += MetTile_Click; //addedFlowControl.Controls.Add(metTile); } ConnectedDevices.UpdateFlag = 0; } }
public static List <DEVICECATEGORY> DeviceListConveter(String[] Devices) { if (Devices == null || Devices.Count() == 0) { return(null); } List <DEVICECATEGORY> TempList = new List <DEVICECATEGORY>(); List <DEVICECATEGORY> AllDeviceName = Enum.GetValues(typeof(DEVICECATEGORY)).Cast <DEVICECATEGORY>().ToList(); foreach (DEVICECATEGORY ThisDevice in AllDeviceName) { foreach (String DeviceStr in Devices) { if (ThisDevice.ToString() == DeviceStr) { TempList.Add(ThisDevice); } } } return(TempList); }
async void Handle_LoginClicked(object sender, System.EventArgs e) { if (string.IsNullOrEmpty(viewModel.TenancyName)) { viewModel.Message = "Please enter valid campus key"; return; } if (string.IsNullOrEmpty(viewModel.UsernameOrEmailAddress)) { viewModel.Message = "Please enter valid Username"; return; } if (string.IsNullOrEmpty(viewModel.Password)) { viewModel.Message = "Please enter valid password"; return; } viewModel.IsBusy = true; viewModel.Message = "Attempting to log in"; var creds = await Authentication.AttemptToAuthenticate(viewModel.UsernameOrEmailAddress, viewModel.Password, viewModel.TenancyName); if (creds.IsAuthenticated) { if (Settings.IsRegistered) { string longlat = await ThisDevice.GetLongLatString(); viewModel.Message = "Log in successful, registering device"; creds = await Authentication.Register(new Credentials() { Username = creds.Username, Password = creds.Password, TenancyName = creds.TenancyName, IpAddress = ThisDevice.GetLocalIPAddress(), MAC = ThisDevice.GetMAC(), Version = ThisDevice.GetOSVersion(), Device = ThisDevice.GetDescription(), GeoLocation = longlat }); viewModel.Message = "Device registered"; //save info permanently Settings.IsRegistered = true; Settings.TenancyName = creds.TenancyName; Settings.Username = creds.Username; Settings.Password = creds.Password; Settings.IsRegistered = creds.IsRegistered; viewModel.IsBusy = false; viewModel.Message = "Going to dashbaord"; } await Navigation.PushAsync(new Dashboard()); //i don't want the user to be able to go back to this page Navigation.RemovePage(this); } else { viewModel.Message = "Log in failed"; } viewModel.IsBusy = false; }