private void _ic_Notified(CVResult result, object obj) { if (result == CVResult.ResourceOperationResponded) { if (obj is ResourcePt) { ResourcePt r = obj as ResourcePt; if (r.service == 4) { if (r.success == 0) { string tempPathfile = Kits.GetTempPathfile(r.name); string pathfile = _dc.GetFtpPathfileWithoutRemoteDirectory(r.pathfile); DownloadDataItem ddi = new DownloadDataItem() { Source = pathfile, Target = tempPathfile, Id = r.objectid, Crc = r.crc }; _dc.Add(ddi); } else { Notified?.Invoke(CVResRequestResult.SourceNotFound, r.msg); } } } } }
private void DownloadDirectory(object o) { string pathname = o as string; //获取当前目录所有文件 GetFilesItem gfi = new GetFilesItem { Target = _dc.GetFtpPathfile(pathname) }; _dc.Execute(gfi); if (gfi.Success == false) { Notified?.Invoke(CVRDownloadResult.SourceHappened, gfi.Target); return; } foreach (FileInfoItem fii in gfi.Files) { if (_excludedItems.Contains(fii.Name)) { continue; } string remote = _dc.GetFtpPathfile(Path.Combine(pathname, fii.Name)); DownloadDataItem ddi = new DownloadDataItem { Source = remote, Target = _dc.GetDrivePathfile(Path.Combine(_temp, Path.Combine(pathname, fii.Name))) }; string dir = (new FileInfo(ddi.Target)).DirectoryName; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } _requestedCount++; _dc.Add(ddi); } //获取当前目录所有子目录 GetDirectoriesItem gdi = new GetDirectoriesItem { Target = _dc.GetFtpPathfile(pathname) }; _dc.Execute(gdi); foreach (FileInfoItem fii in gdi.Directories) { DownloadDirectory(Path.Combine(pathname, fii.Name)); } }
private void _dc_Ended(IDataOpItem item) { if (item is DownloadDataItem) { DownloadDataItem ddi = item as DownloadDataItem; if (ddi.Success) { if (_excludedItems.Contains(Kits.GetFilename(ddi.Target))) { return; } _downedCount++; //unpackage string target = ddi.Target.Replace(@"\" + _temp, ""); string dir = (new FileInfo(target)).DirectoryName; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } try { int l = ResourcePackage.Unpackage(ddi.Target, target); Notified?.Invoke(CVRDownloadResult.Finished, new FinishedItem { Name = target, Length = l }); } catch { Notified?.Invoke(CVRDownloadResult.UnpackageHappened, target); } if (_requestedCount == _downedCount) { string targetemp = Path.Combine(Target, _temp); if (Directory.Exists(targetemp)) { Kits.DeleteDirectory(targetemp); } Notified?.Invoke(CVRDownloadResult.Completed, _downedCount); } } else { Notified?.Invoke(CVRDownloadResult.DownloadHappened, ddi.Source); } } }
private void _dc_Ended(IDataOpItem item) { if (item is DownloadDataItem) { DownloadDataItem ddi = item as DownloadDataItem; if (ddi.Success) { string crc = FileMD5.Create(ddi.Target); if (crc == ddi.Crc) { string localPathfile = _dc.GetLocalPathfile(ddi.Source); try { if (LocalFile) { ResourcePackage.Unpackage(ddi.Target, localPathfile); Notified?.Invoke(CVResRequestResult.RequestFileSucceed, localPathfile); } else { byte[] buff = ResourcePackage.Unpackage(File.ReadAllBytes(ddi.Target)); Notified?.Invoke(CVResRequestResult.RequestDataSucceed, buff); } } catch (NullReferenceException) { Notified?.Invoke(CVResRequestResult.UnpackageFailed, localPathfile); } catch (IOException) { Notified?.Invoke(CVResRequestResult.WriteFailed, localPathfile); } } else { Notified?.Invoke(CVResRequestResult.CrcFailded, ddi.Message); } } else { Notified?.Invoke(CVResRequestResult.DownloadFailed, ddi.Message); } } }
private void _ic_Notified(CVResult r, object o) { if (r == CVResult.TableQueryReceived) { if (o is QueryResultPt) { QueryResultPt qrp = o as QueryResultPt; if (qrp.token == _token) { if (qrp.success == 0) { TableXmlWrapper txw = new TableXmlWrapper(qrp); _curNum = txw.Count; _curIndex = 0; _pageCount = txw.Count / _pageSize + (txw.Count % _pageSize == 0 ? 0 : 1); foreach (XmlNode xn in txw.Nodes) { ResXmlNodeParser rxnp = new ResXmlNodeParser(xn); string pathfile = rxnp.Pathfile.Remove(0, 1); string file = pathfile.Replace(_dc.RemoteDirectory + @"/", ""); string source = @"ftp://" + _dc.Ip + @"/" + pathfile; string target = Path.Combine(_dc.LocalDirectory, file).Replace("/", @"\"); DateTime tdt = File.Exists(target) ? File.GetLastWriteTime(target) : DateTime.MinValue; if (!Kits.DateTimeEqual(rxnp.Lastwrite, tdt)) { if (UseMemory) { DownloadMemoryItem dmi = new DownloadMemoryItem { Id = rxnp.Id, Source = source, Target = target, Crc = rxnp.Crc, Tag = rxnp.Name }; _dc.Add(dmi); } else { DownloadDataItem ddi = new DownloadDataItem { Id = rxnp.Id, Source = source, Target = target, Crc = rxnp.Crc, Tag = rxnp.Name }; _dc.Add(ddi); } } else { Notified?.Invoke(CVResDownloadResult.ExistedTarget, target); if (++_curIndex >= _curNum) { if (++_pageNo >= _pageCount) { Completed?.Invoke(); } } } } } else { Notified?.Invoke(CVResDownloadResult.RequestResourceFailed, qrp.msg); } } } } }