public static void DownloadMissingFilesNew(InstallationDataModel version) { _client = new TcpClient(_ip, _port); if (version.MissingFiles.Count == 0) { version = ChecksumTool.RecheckVersion(version); RequestVersionMissingFiles(ref version); } DownloadProgressEventArgs args = new DownloadProgressEventArgs(); PatchDataModel model = new PatchDataModel() { RequestType = PatchNetworkRequest.DownloadFiles, InstalledVersion = new InstallationDataModel { VersionName = version.VersionName, VersionBranch = version.VersionBranch, MissingFiles = version.MissingFiles } }; args.Version = version.VersionBranch; args.TotalSize = version.TotalSize; ConnectionHandler.SendObject(model, _client); _downloadingFiles = true; //While there's still files missing and there's still an active connection while (version.MissingFiles.Count > 0 && ConnectionHandler.Connected(_client)) { if (_client.GetStream().DataAvailable) { //Raise download progress event args.NextFileName = version.MissingFiles[0].FilePath; OnDownloadProgress(args); //Handle incoming file // await ConnectionHandler.ReadFileAsync(_client, version.MissingFiles[0].FilePath, InstallPath + '/' + version.VersionName); ConnectionHandler.ReadFileStream(_client, version.MissingFiles[0].FilePath, version.MissingFiles[0].Size, version.InstallPath); Console.WriteLine(ConsoleExtension.AddTimestamp(version.MissingFiles[0].FilePath + " downloaded")); args.DownloadedTotal += version.MissingFiles[0].Size; lock (version) version.MissingFiles.RemoveAt(0); } } _downloadingFiles = false; Console.WriteLine(ConsoleExtension.AddTimestamp("All missing files received!")); version = ChecksumTool.RecheckVersion(version); RequestVerifyVersion(ref version); _client.GetStream().Close(); _client.Close(); DownloadDone?.Invoke(version); }
/// <summary> /// Generates model data for each version installed on the path /// </summary> //public static void UpdateCurrentInstallations () { // InstalledVersions = ChecksumTool.GetInstalledVersions(InstallPath); //} /// <summary> /// Listens for responses from the patching service after connecting /// </summary> private static PatchDataModel ReadServerResponse() { while (ConnectionHandler.Connected(_client)) { if (_client.GetStream().DataAvailable) { PatchDataModel data = JsonConvert.DeserializeObject <PatchDataModel>(ConnectionHandler.ReadMessage(_client.GetStream())); return(data); } Thread.Sleep(16); } return(null); }
public void HandleClientConnection(TcpClient client) { //While the client is still connected, await communication while (ConnectionHandler.Connected(client)) { //Wait for data from client if (client.GetStream().DataAvailable) { Console.WriteLine(ConsoleExtension.AddTimestamp("Recieving request")); PatchDataModel data = JsonConvert.DeserializeObject <PatchDataModel>(ConnectionHandler.ReadMessage(client.GetStream())); switch (data.RequestType) { case PatchNetworkRequest.AvailableVersions: SendAvailableVersions(client); Console.WriteLine(ConsoleExtension.AddTimestamp("Versions send to client")); break; case PatchNetworkRequest.VerifyVersion: SendVersionVerification(client, data); break; case PatchNetworkRequest.MissingFiles: SendMissingFilesList(client, data); break; case PatchNetworkRequest.DownloadFile: SendFileToClient(client, data); break; case PatchNetworkRequest.DownloadFiles: SendFilesToClientStream(client, data); break; case PatchNetworkRequest.TestConnection: SendTestConnectionResponse(client); Console.WriteLine(ConsoleExtension.AddTimestamp("Send test response to client")); break; } } Thread.Sleep(30); } lock (clients) { clients.Remove(client); Console.WriteLine(ConsoleExtension.AddTimestamp("Client disconnected")); } }
public static List <InstallationDataModel> CompleteCheck(string[] paths) { //Update local installations for (int i = 0; i < paths.Length; i++) { InstalledVersions.Add(ChecksumTool.GetInstalledVersion(paths[i])); } //Establish connection to server _client = new TcpClient(_ip, _port); if (ConnectionHandler.Connected(_client)) { InstalledVersions = CompareLocalVersionsToServerVersions(InstalledVersions); } _client.GetStream().Close(); _client.Close(); return(InstalledVersions); }