private static void FindUpdateFileCallback(IAsyncResult ar) { ComObject state = (ComObject)ar.AsyncState; Socket handler = state.WorkSocket; int bytesRead = handler.EndReceive(ar); if (bytesRead > 0) { var receiveData = state.Buffer.Take(bytesRead).ToArray(); var dataList = PacketUtils.SplitBytes(receiveData, PacketUtils.ClientFindFileInfoTag()); if (dataList != null && dataList.Any()) { var request = PacketUtils.GetData(PacketUtils.ClientFindFileInfoTag(), dataList.FirstOrDefault()); string str = System.Text.Encoding.UTF8.GetString(request); var infos = str.Split('_'); var productName = infos[0]; var revitVersion = infos[1]; var currentVersion = infos[2]; var updatefile = ServerFileUtils.GetLatestFilePath(productName, revitVersion, currentVersion); if (string.IsNullOrEmpty(updatefile) || !File.Exists(updatefile)) { return; } _serverPath = updatefile; FoundUpdateFileResponse(handler); } } }
public HttpResponseMessage GetInfo(ClientBasicInfo clientBasicInfo) { var productName = clientBasicInfo.ProductName; var revitVersion = clientBasicInfo.RevitVersion; var currentProductVersion = clientBasicInfo.CurrentProductVersion; //ProductName_RevitVersion_OldProductVersion_NewProductVersion var latestFilePath = ServerFileUtils.GetLatestFilePath(productName, revitVersion, currentProductVersion); if (string.IsNullOrEmpty(latestFilePath) || !File.Exists(latestFilePath)) { return(null); } var latestFile = new FileInfo(latestFilePath); var downloadInfo = new DownloadFileInfo() { LatestProductVersion = ServerFileUtils.GetLatestVersion(Path.GetFileNameWithoutExtension(latestFilePath)), DownloadFileMd5 = Md5Utils.GetFileMd5(latestFilePath), DownloadFileTotalSize = latestFile.Length }; HttpResponseMessage response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(downloadInfo), Encoding.GetEncoding("UTF-8"), "application/json") }; return(response); }