private void UploadData(List <byte[]> arrayRecordsToSend, string motorIP, string contentType, string instructionCode) { int count = arrayRecordsToSend.Count; int index = 0; HDriveInformation.HDriveData currentDrive = new HDriveInformation.HDriveData(motorIP, "", 0, 0, 0, 0, 0, ""); _updatedHDrives.Add(currentDrive); foreach (byte[] t in arrayRecordsToSend) { bool success = SendData(t, motorIP, contentType, instructionCode, motorIP + ": portion " + index + " of " + (count - 1) + " -> "); if (!success) { _debugConsoleText = "Abord update \n\r" + _debugConsoleText; return; } // Update progres bar currentDrive.Progress = (int)((index - 1) * 100.0 / count); // Increment progress ++index; Thread.Sleep(50); } _updatedHDrives.Remove(currentDrive); if (instructionCode.ToLower().Contains("fir")) { _statusLabelText = "Switching application"; // Switch to new firmware// Create a new WebRequest Object to the mentioned URL. WebRequest myWebRequest = WebRequest.Create("http://" + motorIP + "/getData.cgi?swi"); // Set the 'Timeout' property in Milliseconds. myWebRequest.Timeout = 1000; // This request will throw a WebException if it reaches the timeout limit before it is able to fetch the resource. try { WebResponse myWebResponse = myWebRequest.GetResponse(); myWebResponse.Close(); } catch (Exception err) { Console.WriteLine(err); } myWebRequest.Abort(); _statusLabelText = "Uploading Firmware finished"; } else if (instructionCode.ToLower().Contains("fil")) { _statusLabelText = "Restarting drive"; RestartDrive(motorIP); _statusLabelText = "Uploading Webpage finished"; } }
private void NewHDriveFound(HDriveInformation.HDriveData data) { _gridViewVisibility = true; _foundHdrives.Add(data); _debugConsoleText = " HDrive found: " + data.Ip + "\r\n" + _debugConsoleText; }