Beispiel #1
0
        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);
        }
Beispiel #2
0
        /**Get a photo record (this synchronous file base64 content)
         * @param docId
         * @param onErr
         * @return response
         */
        public AlbumResp selectPhotoRec(string docId, ErrorCtx err = null)
        {
            ErrorCtx    errHandler = err == null ? errCtx : err;
            AnsonHeader header     = client.Header().act("album.c#", "synch", "c/photo", "multi synch");

            AlbumReq req = new AlbumReq().selectPhoto(docId);

            AlbumResp resp = null;

            try
            {
                AnsonMsg q = client.UserReq(uri, new AlbumPort(AlbumPort.album), req)
                             .Header(header);

                resp = (AlbumResp)client.Commit(q, errCtx);
            }
            catch (Exception e) {
                if (e is AnsonException || e is SemanticException)
                {
                    errHandler.onError(new MsgCode(MsgCode.exSemantic), e.Message + " " + e.Source == null ? "" : e.Source.GetType().Name);
                }
                else
                {
                    errHandler.onError(new MsgCode(MsgCode.exIo), e.Message + " " + e.Source == null ? "" : e.Source.GetType().Name);
                }
            }
            return(resp);
        }
Beispiel #3
0
        public AnsonResp Commit(AnsonMsg req, ErrorCtx err = null)
        {
            HttpServClient  httpClient = new HttpServClient();
            Task <AnsonMsg> tmsg       = httpClient.Post(AnClient.ServUrl((Port)req.port), req);

            tmsg.Wait();
            AnsonMsg msg  = tmsg.Result;
            MsgCode  code = msg.code;

            if (MsgCode.ok != code.code)
            {
                if (err != null)
                {
                    err.onError(code, ((AnsonResp)msg.Body(0)).Msg());
                }
                else
                {
                    Debug.WriteLine("Error: code: {0}\nerror: {1}",
                                    code, msg.ToString());
                }
            }

            return((AnsonResp)msg.Body(0));
        }
Beispiel #4
0
        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);
        }