示例#1
0
        public DocsReq blockStart(IFileDescriptor file, SessionInf usr)
        {
            this.device = usr.device;
            if (LangExt.isblank(this.device, new string[] { ".", "/" }))
            {
                throw new SemanticException("File to be uploaded must come with user's device id - for distinguish files. {0}", file.fullpath());
            }

            this.clientpath = file.fullpath();
            this.docName    = file.clientname();
            this.createDate = file.Cdate();
            this.blockSeq   = 0;

            this.a = A.blockStart;
            return(this);
        }
示例#2
0
 public SyncRec(IFileDescriptor p)
 {
     this.clientpath = p.fullpath();
     this.filename   = p.clientname();
     this.cdate      = p.Cdate();
 }
示例#3
0
 /**Create a photo. Use this for small file.
  * @param file
  * @param usr
  * @return album request
  * @throws IOException
  * @throws SemanticException
  */
 public AlbumReq createPhoto(IFileDescriptor file, SessionInf usr)
 {
     return(createPhoto(null, file.fullpath()));
 }
示例#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);
        }