private void Update() { List <string> lstFile = null; lstFile = FTPAction.getListFiles(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, AppConfig.releaseLocation, string.Empty); if (lstFile != null) { if (lstFile.Count > 0) { //Backup các file cũ if (!Directory.Exists(Application.StartupPath + "/tmp")) { Directory.CreateDirectory(Application.StartupPath + "/tmp"); } int index = 0; foreach (var item in lstFile) { SetStatustoLable(lb_process, "Backup file: " + item); SetProcessBar(progress_update, 60 * ((index * 2) / (lstFile.Count * 2))); //Backup các file cũ try { File.Copy(Application.StartupPath + "/" + item, Application.StartupPath + "/tmp/" + item); File.Delete(Application.StartupPath + "/" + item); } catch { } SetStatustoLable(lb_process, "Get file: " + item); SetProcessBar(progress_update, 60 * ((index * 2 + 1) / (lstFile.Count * 2))); //Get các file mới if (!FTPAction.getFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, AppConfig.releaseLocation, item, Application.StartupPath, item)) { SetStatustoLable(lb_process, "Rollback previous Version"); SetProcessBar(progress_update, 0); //Rollback phiên bản cũ Rollback(); SetStatustoLable(lb_process, "UpdateFail"); SetProcessBar(progress_update, 0); throw new Exception("Lỗi trong quá trình lấy file"); } index++; } SetStatustoLable(lb_process, "Delete tmp file"); SetProcessBar(progress_update, 60); DeleteTmp(); SetStatustoLable(lb_process, "UpdateSucess"); SetProcessBar(progress_update, 100); } else { throw new Exception("Không có file nào để update"); } } else { throw new Exception("Không thể kết nối đến server FTP"); } }
public void DeleteFileCollection(Web_Collections_Model Obj) { List <string> lstImage = FTPAction.getListFiles(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id, string.Empty); foreach (var item in lstImage) { FTPAction.deleteFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id, item); } FTPAction.deleteDirectory(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id); }
private void LoadImageAttach() { List <string> lstImage = FTPAction.getListFiles(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id, string.Empty); foreach (var item in lstImage) { if (item == Obj.featureimage) { continue; } var ImageItem = new ImageAttachModel() { IsLocal = false, Link = AppConfig.WebUrl + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id + "/" + item }; pn_imageattach.AddImage(ImageItem); if (action != Resources.EnumClass.CollectionsAction.Detail) { Obj.content = Obj.content.Replace(ImageItem.Link, "[~" + ImageItem.id.ToString() + "]"); } } }