public DocsResp del(string device, string clientpath) { AlbumReq req = new AlbumReq().del(device, clientpath); DocsResp resp = null; try { AnsonHeader header = client.Header().act("album.c#", "del", "d/photo", ""); AnsonMsg q = client.UserReq(uri, new AlbumPort(AlbumPort.album), req) .Header(header); resp = (DocsResp)client.Commit(q, errCtx); } catch (Exception e) { if (e is AnsonException || e is SemanticException) { errCtx.onError(new MsgCode(MsgCode.exSemantic), e.Message + " " + e.Source == null ? "" : e.Source.GetType().Name); } else { errCtx.onError(new MsgCode(MsgCode.exIo), e.Message + " " + e.Source == null ? "" : e.Source.GetType().Name); } } return(resp); }
/// <summary> /// Asynchronously synchronize photos /// </summary> /// <param name="photos"></param> /// <param name="user"></param> /// <param name="onOk"></param> /// <param name="onErr"></param> /// <exception cref="SemanticException"></exception> /// <exception cref="SemanticException"></exception> /// <exception cref="IOException"></exception> /// <exception cref="AnsonException"></exception> public void asyncPhotos(List <IFileDescriptor> photos, SessionInf user, OnOk onOk, OnError onErr) { DocsResp resp = null; try { AnsonHeader header = client.Header().act("album.c#", "synch", "c/photo", "multi synch"); List <DocsResp> reslts = new List <DocsResp>(photos.Count); foreach (IFileDescriptor p in photos) { AlbumReq req = new AlbumReq() .createPhoto(p, user); AnsonMsg q = client.UserReq(uri, new AlbumPort(AlbumPort.album), req) .Header(header); Task <AnsonResp> tresp = (Task <AnsonResp>)client.Commit_async(q, null, onErr); tresp.Wait(); reslts.Add((DocsResp)tresp.Result); } onOk.ok(resp); } catch (Exception e) { onErr.err(new MsgCode(MsgCode.exIo), string.Format("%s, %s", e.GetType().Name, e.Message)); } }
/// <summary> /// Asynchronously query synchronizing records. /// </summary> /// <param name="files"></param> /// <param name="page"></param> /// <param name="onOk"></param> /// <param name="onErr"></param> /// <returns>this</returns> public AlbumClientier asyncQuerySyncs(IList <IFileDescriptor> files, SyncingPage page, OnOk onOk, OnError onErr) { Task.Run(() => { DocsResp resp = null; try { AnsonHeader header = client.Header().act("album.c#", "query", "r/states", "query sync"); List <DocsResp> reslts = new List <DocsResp>(files.Count); AlbumReq req = (AlbumReq) new AlbumReq().Syncing(page).A(A.selectSyncs); for (int i = page.start; i < page.end & i < files.Count; i++) { IFileDescriptor p = files[i]; req.querySync(p); } AnsonMsg q = client.UserReq(uri, new AlbumPort(AlbumPort.album), req) .Header(header); resp = (DocsResp)client.Commit(q, errCtx); reslts.Add(resp); onOk.ok(resp); } catch (Exception e) { onErr.err(new MsgCode(MsgCode.exIo), uri, new string[] { e.GetType().Name, e.Message }); } }); return(this); }
public void proc(int listIndx, int totalBlocks, AnsonResp blockResp) { Label lbl = new Label(); DocsResp resp = (DocsResp)blockResp; string msg = string.Format("{0} / {1} {2} {3,:P1}", listIndx, totalBlocks, resp.clientname(), (float)resp.blockSeq() / totalBlocks); ui.Text = msg; }
public AlbumClientier asyncVideos(IList <IFileDescriptor> videos, SessionInf user, OnProcess onProc, OnOk onOk, OnError onErr) { Task.Run(() => { try { IList <DocsResp> reslts = syncVideos(videos, user, onProc); DocsResp resp = new DocsResp(); resp.Data()["results"] = reslts; onOk.ok(resp); } catch (Exception e) { onErr.err(new MsgCode(MsgCode.exIo), uri, new string[] { e.GetType().Name, e.Message }); } }); return(this); }
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); }