public IAsyncAction CloseAsync() { return(Task.Run(async() => { await BodyIndexReader?.CloseAsync(); BodyIndexReader?.Dispose(); BodyIndexReader = null; await BodyReader?.CloseAsync(); BodyReader?.Dispose(); BodyReader = null; await ColorReader?.CloseAsync(); ColorReader?.Dispose(); ColorReader = null; await DepthReader?.CloseAsync(); DepthReader?.Dispose(); DepthReader = null; AudioReader?.Close(); AudioReader?.Dispose(); AudioReader = null; _mediaCapture?.Dispose(); _mediaCapture = null; _networkClient?.CloseConnection(); _networkClient = null; _networkServer?.CloseConnection(); _networkServer = null; }).AsAsyncAction()); }
private void SOSButton_Clicked(object sender, EventArgs e) { NetworkClient client = new NetworkClient(); client.ConnectToServer(); client.SendSOSSignal(); client.CloseConnection(); }
private void btnLogout_Click(object sender, EventArgs e) { _client.SetListener(null); if (_client.Disconnect()) { _client.CloseConnection(); } _client = null; UserClosing = false; _dbInterface.UnmarkAsDefault(_account); Close(); }
private async void LoginButton_OnClicked(object sender, EventArgs e) { //var login = LoginText.Text; //if (App.Current.Properties.ContainsKey("Login")) //{ // if (login == "a") // { // SideTab worker1 = new SideTab(); // Application.Current.MainPage = new NavigationPage(worker1); // } //} //else //{ // App.Current.Properties.Add("Login", login); // if (login == "a") // { // SideTab worker1 = new SideTab(); // Application.Current.MainPage = new NavigationPage(worker1); // } //} string login = LoginText.Text; string password = entry3.Text; if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { return; } NetworkClient client = new NetworkClient(); client.ConnectToServer(); bool isAuth = client.SendAuthentificationRequest(new string[] { login, password }); client.CloseConnection(); if (isAuth) { client = new NetworkClient(); client.ConnectToServer(); BuilderData.builderID = client.GetPersonalID(login); CheckBuilderData(client.GetBuilderInfoByID()); client.CloseConnection(); Application.Current.MainPage = new SideTab(); await Navigation.PopToRootAsync(true); } }
private void Button_Clicked_1(object sender, EventArgs e) { var item = BuildingsList.SelectedItem as Buildings; BuilderData.constructionID = item.BuildingsID; NetworkClient client = new NetworkClient(); client.ConnectToServer(); client.SetConstructionToBuilder(); client.CloseConnection(); ConstructionData.isChoosen = true; ConstructionData.constructionName = item.Name; ConstructionData.constructionAddress = item.Adress; constrTitle.Text = ConstructionData.constructionName; constrAddress.Text = ConstructionData.constructionAddress; }
private void EndDay_Clicked(object sender, EventArgs e) { ButtonDS.IsVisible = true; ButtonED.IsVisible = false; SOSbutton.IsVisible = false; OnWork.IsVisible = false; alive = false; NetworkClient client = new NetworkClient(); client.ConnectToServer(); client.SendEndWorkRequest(); client.CloseConnection(); mStopWatch.Stop(); //OnWork.Text = Timer.DisableStopwatch(); //CheckAcceleration.DisableAccelerator(); }
private void StartDay_Clicked(object sender, EventArgs e) { if (!ConstructionData.isChoosen) { ErrorText.Text = "Выберите стройку и попробуйте ещё раз!"; ErrorText.IsVisible = true; return; } ErrorText.IsVisible = false; ButtonDS.IsVisible = false; ButtonED.IsVisible = true; SOSbutton.IsVisible = true; OnWork.IsVisible = true; CheckGeolocation(); NetworkClient client = new NetworkClient(); client.ConnectToServer(); client.SendStartWorkRequest(); client.CloseConnection(); //CheckAcceleration.ToggleAccelerator(); //OnWork.Text=Timer.ToogleStopwatch(); if (!mStopWatch.IsRunning) { mStopWatch.Start(); } Device.StartTimer(TimeSpan.FromSeconds(1), () => { // Do something OnWork.Text = mStopWatch.Elapsed.ToString(); return(true); // True = Repeat again, False = Stop the timer }); }
private void UpdateBuildings() { NetworkClient client = new NetworkClient(); client.ConnectToServer(); string[] dataBuildings = client.GetBuilderConstructions(); client.CloseConnection(); _buildings.Clear(); if (dataBuildings.Length > 0) { for (int i = 0; i < dataBuildings.Length; i++) { string[] construction = dataBuildings[i].Split(new string[] { "<;>" }, StringSplitOptions.None); _buildings.Add(new Buildings() { BuildingsID = int.Parse(construction[0]), Adress = construction[1], Name = construction[2] }); } } }
private async void CheckGeolocation() { try { var request = new GeolocationRequest(GeolocationAccuracy.Medium, TimeSpan.FromSeconds(2)); cts = new CancellationTokenSource(); var location = await Geolocation.GetLocationAsync(request, cts.Token); if (location != null) { BuilderData.geoLocation = location.Latitude + " " + location.Longitude; NetworkClient client = new NetworkClient(); client.ConnectToServer(); client.SetBuilderLastGeoLocation(); client.CloseConnection(); } } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception } catch (FeatureNotEnabledException fneEx) { // Handle not enabled on device exception } catch (PermissionException pEx) { // Handle permission exception } catch (Exception ex) { // Unable to get location } }
/// <summary> /// Load the image from server /// </summary> /// <param name="ipAddr">the ip address of the server</param> /// <param name="port">the port number of the server</param> /// <param name="imageIdx">the index of image to be loaded</param> public async void LoadImage(string ipAddr, int port, int imageIdx) { // Set the sprite image to be the "loading image" so that user can tell if a new image is loading LoadDefaultImage(); // Connect to the server NetworkClient client = new NetworkClient(); await client.ConnectToServer(ipAddr, port); // Send request byte[] c1 = System.Text.Encoding.ASCII.GetBytes("GET XRAY\n"); // header protocol byte[] c2 = BitConverter.GetBytes(imageIdx); // image index byte[] c3 = System.Text.Encoding.ASCII.GetBytes("\n"); // header protocol byte[] command = new byte[c1.Length + c2.Length + c3.Length]; // [Note] Use BlockCopy will be faster than Copy System.Buffer.BlockCopy(c1, 0, command, 0, c1.Length); System.Buffer.BlockCopy(c2, 0, command, c1.Length, c2.Length); System.Buffer.BlockCopy(c3, 0, command, c1.Length + c2.Length, c3.Length); bool success = await client.sendRequest(command); // If request sends successfully, read the response if (success) { // [Note] We should read "OK\n[sizeof(ULONG)][fileData]" // In the server, sizeof(ULONG) == 4 // 1, read "OK\n[sizeof(ULONG)]" int ShouldReadLen = 3 + 4; byte[] buffer = new byte[ShouldReadLen]; int rlen = await client.readData(ShouldReadLen, buffer); int fileSize = -1; // The size of the image file. If fileSize == -1, we don't do any reading if (rlen == ShouldReadLen) { // First read 3 bytes to see if the response is "OK\n" int hsize = 3; byte[] header = new byte[hsize]; Array.Copy(buffer, header, hsize); string hstr = System.Text.Encoding.UTF8.GetString(header); if (hstr == "OK\n") { fileSize = BitConverter.ToInt32(buffer, hsize); } else { Debug.Log("ImageBlock::LoadImage: Server response has error\n" + System.Text.Encoding.UTF8.GetString(buffer)); } } // 2, Read "[fileData]" if (fileSize != -1) { byte[] imageBuf = new byte[fileSize]; rlen = await client.readData(fileSize, imageBuf); if (rlen == fileSize) { Texture2D t = new Texture2D(4, 4); t.LoadImage(imageBuf); GenerateSprite(t); } } } // Close connection client.CloseConnection(); }
private async void Registration_Clicked(object sender, EventArgs e) { bool notEmptyFields = true; if (string.IsNullOrEmpty(EnPhone.Text)) { notEmptyFields = false; EnPhone.BackgroundColor = Color.FromHex("#FC4444"); } else { EnPhone.BackgroundColor = Color.White; } if (string.IsNullOrEmpty(EnMail.Text)) { notEmptyFields = false; EnMail.BackgroundColor = Color.FromHex("#FC4444"); } else { EnMail.BackgroundColor = Color.White; } if (string.IsNullOrEmpty(EnPass.Text)) { notEmptyFields = false; EnPass.BackgroundColor = Color.FromHex("#FC4444"); } else { EnPass.BackgroundColor = Color.White; } if (string.IsNullOrEmpty(EnSurname.Text)) { notEmptyFields = false; EnSurname.BackgroundColor = Color.FromHex("#FC4444"); } else { EnSurname.BackgroundColor = Color.White; } if (string.IsNullOrEmpty(EnName.Text)) { notEmptyFields = false; EnName.BackgroundColor = Color.FromHex("#FC4444"); } else { EnName.BackgroundColor = Color.White; } if (string.IsNullOrEmpty(EnOtch.Text)) { notEmptyFields = false; EnOtch.BackgroundColor = Color.FromHex("#FC4444"); } else { EnOtch.BackgroundColor = Color.White; } if (string.IsNullOrEmpty(EnFirma.Text)) { notEmptyFields = false; EnFirma.BackgroundColor = Color.FromHex("#FC4444"); } else { EnFirma.BackgroundColor = Color.White; } if (notEmptyFields) { NetworkClient client = new NetworkClient(); client.ConnectToServer(); string[] regData = new string[] { EnName.Text, EnSurname.Text, EnOtch.Text, EnPhone.Text, EnFirma.Text, EnMail.Text, EnPass.Text }; bool result = client.SendRegisterRequest(regData); client.CloseConnection(); if (result) { await Navigation.PopAsync(); } } }