public async static Task getSystemVersions(cServer ShareServer) { if (XMLSystemState == null) { using (var ftp = new cFTP(ShareServer, "APPS_CS")) { var Item = new DirectoryItem() { Server = ShareServer, IsDirectory = false, Name = "systems.xml", BaseUri = new UriBuilder("ftp://" + ShareServer.IP.ToString() + "/APPS_CS").Uri }; try { await ftp.DownloadItemAsync(Item, LOCAL_PATH + "systems.xml"); } catch (Exception ex) { //debugBox.AppendText(ex.Message); } XMLSystemState = XDocument.Load(LOCAL_PATH + "systems.xml"); } } }
//public bool CheckUpdateSync() //{ // bool _clean = true; // //_clean = readDir("/APPS_CS/", Code.ToLower()); // using (var client = new SftpClient(ShareServer.IP.ToString(), ShareServer.User, ShareServer.Password)) // { // client.Connect(); // _clean = readDirSSH(client,"/APPS_CS/", Code.ToLower(),true); // } // return _clean; //} private async Task <bool> readDir(string basePath, string relativePath) { bool _clean = true; List <DirectoryItem> list; using (var ftp = new cFTP(ShareServer, basePath + relativePath)) { list = await ftp.GetDirectoryList("", getDateTimes : true); } list.Where(x => x.IsDirectory).ToList().ForEach(async a => { _clean = (await readDir(basePath, relativePath + "/" + a.Name) && _clean); }); list.Where(x => !x.IsDirectory).ToList().ForEach(a => { if (Exists(LOCAL_PATH + relativePath + "/" + a.Name)) { if (GetLastWriteTime(LOCAL_PATH + relativePath + "/" + a.Name) != a.DateCreated) { UpdateList.Add(new cUpdateListItem() { AppBotCode = this.Code, AppPath = this.LocalPath, //ServerPath = basePath + relativePath + "/" + a.Name, LocalPath = LOCAL_PATH + relativePath + "/" + a.Name, Item = a, Status = LogonItemUpdateStatus.PENDING }); _clean = false; } } else { UpdateList.Add(new cUpdateListItem() { AppBotCode = this.Code, AppPath = this.LocalPath, //ServerPath = basePath + relativePath + "/" + a.Name, LocalPath = LOCAL_PATH + relativePath + "/" + a.Name, Item = a, Status = LogonItemUpdateStatus.PENDING }); _clean = false; } }); return(_clean); }
public async Task Run() { Updater.RunningTasks++; try { using (var ftp = new cFTP(Values.ShareServerList[Values.COD3], "")) { await ftp.DownloadItemAsync(UpdateItem.Item, UpdateItem.LocalPath.Replace("\\", "/")); } UpdateItem.Status = LogonItemUpdateStatus.UPDATED; Updater.SendMessage("PROGRESS", false, UpdateItem.AppBotCode); /* * item.Parent.ChangeProgress(item.Parent.ProgressValue + 1); * * if (item.Parent.UpdatedItems.Count == item.Parent.Items.Count()) * { * item.Parent.SetStatus(AppBotStatus.UPDATED); * } */ if (UpdateItem.zipFile) //if its special unzip it { try { var _localPath = Path.GetDirectoryName(UpdateItem.AppPath); if (Directory.Exists(_localPath)) { Directory.Delete(_localPath, true); } //await (Task.Run(() => ZipFile.ExtractToDirectory(item.LocalPath, Values.LOCAL_PATH))); using (ZipArchive archive = ZipFile.OpenRead(UpdateItem.LocalPath)) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.FullName.Substring(entry.FullName.Length - 1, 1) == "/") { Directory.CreateDirectory(Path.Combine(Values.LOCAL_PATH, entry.FullName)); } else { entry.ExtractToFile(Path.Combine(Values.LOCAL_PATH, entry.FullName)); } } } File.Delete(UpdateItem.LocalPath); } catch (Exception ex) { Updater.SendError(string.Format("Error {0}\n", ex.Message), true, UpdateItem.AppBotCode); UpdateItem.Status = LogonItemUpdateStatus.ERROR; } } Updater.SendMessage("UPDATED", false, UpdateItem.AppBotCode); } catch (WebException ex) { Updater.SendError(string.Format("Error {0}\n", ex.InnerException.Message), true, UpdateItem.AppBotCode); UpdateItem.Status = LogonItemUpdateStatus.ERROR; /* * CTWin.MsgError(ex.Message + "\n" + ex.InnerException.Message); * if (null != item) * { * item.Status = LogonItemUpdateStatus.ERROR; * item.Parent.SetStatus(AppBotStatus.ERROR); * } */ } catch (InvalidOperationException ex) { Updater.SendError(string.Format("Error {0}\n", ex.InnerException.Message ?? ex.Message), true, UpdateItem.AppBotCode); UpdateItem.Status = LogonItemUpdateStatus.ERROR; /* * CTWin.MsgError(ex.InnerException.Message ?? ex.Message); * if (debug != null) * { * AppendDebugText(string.Format("Thread {0} Done.\n", NumThread)); * Values.ActiveThreads--; * if (Values.ActiveThreads == 1) * break; * this.Dispose(); * } */ System.Threading.Thread.Sleep(500); } catch (Exception ex) { Updater.SendError(string.Format("Error {0}\n", ex.InnerException.Message ?? ex.Message), true, UpdateItem.AppBotCode); UpdateItem.Status = LogonItemUpdateStatus.ERROR; /* * CTWin.MsgError(ex.InnerException.Message ?? ex.Message); * if (debug != null) * { * AppendDebugText(string.Format("Thread {0} Waiting {1}\n", NumThread, ex.Message)); * } */ System.Threading.Thread.Sleep(500); } Updater.RunningTasks--; }