public string download(string uri, IPort port, DocsReq body, string localpath, string[] act = null) { if (port == null) { throw new AnsonException("AnsonMsg<DocsReq> needs port explicitly specified."); } // let header = Protocol.formatHeader(this.ssInf); body.Uri(uri); if (act != null && act.Length > 0) { header.act(act); } AnsonMsg msg = new AnsonMsg(port.name) .Header(header) .Body(body, uri); if (AnClient.verbose) { Utils.Logi(msg.ToString()); } HttpServClient httpClient = new HttpServClient(); return(httpClient.streamdown(AnClient.ServUrl(port), msg, localpath)); }
public IList <DocsResp> syncVideos(IList <IFileDescriptor> videos, SessionInf user, OnProcess proc, ErrorCtx onErr = null) { ErrorCtx errHandler = onErr == null ? errCtx : onErr; DocsResp resp = null; try { AnsonHeader header = client.Header().act(new string[] { "album.c#", "synch", "c/photo", "multi synch" }); IList <DocsResp> reslts = new List <DocsResp>(videos.Count); for (int px = 0; px < videos.Count; px++) { IFileDescriptor p = videos[px]; DocsReq req = new DocsReq() .blockStart(p, user); AnsonMsg q = client.UserReq(uri, new AlbumPort(AlbumPort.album), req) .Header(header); resp = (DocsResp)client.Commit(q, errHandler); // stringchainId = resp.chainId(); string pth = p.fullpath(); if (pth != resp.Fullpath()) { Utils.Warn("resp not reply with exactly the same path: %s", resp.Fullpath()); } int totalBlocks = (int)((new FileInfo(pth).Length + 1) / blocksize); if (proc != null) { proc.proc(px, totalBlocks, resp); } int seq = 0; FileStream ifs = File.Create(p.fullpath()); try { string b64 = AESHelper.Encode64(ifs, blocksize); while (b64 != null) { req = new DocsReq().blockUp(seq, resp, b64, user); seq++; q = client.UserReq(uri, new AlbumPort(AlbumPort.album), req) .Header(header); resp = (DocsResp)client.Commit(q, errHandler); if (proc != null) { proc.proc(px, totalBlocks, resp); } b64 = AESHelper.Encode64(ifs, blocksize); } req = new DocsReq().blockEnd(resp, user); q = client.UserReq(uri, new AlbumPort(AlbumPort.album), req) .Header(header); resp = (DocsResp)client.Commit(q, errHandler); if (proc != null) { proc.proc(px, totalBlocks, resp); } } catch (Exception ex) { Utils.Warn(ex.Message); req = new DocsReq().blockAbort(resp, user); req.A(DocsReq.A.blockAbort); q = client.UserReq(uri, new AlbumPort(AlbumPort.album), req) .Header(header); resp = (DocsResp)client.Commit(q, errHandler); if (proc != null) { proc.proc(px, totalBlocks, resp); } throw ex; } finally { ifs.Close(); } reslts.Add(resp); } return(reslts); } catch (Exception e) { errHandler.onError(new MsgCode(MsgCode.exIo), e.GetType().Name + " " + e.Message); } return(null); }