Ejemplo n.º 1
0
        /// <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));
            }
        }
Ejemplo n.º 2
0
        public DocsReq blockEnd(DocsResp resp, SessionInf usr)
        {
            this.device = usr.device;

            this.blockSeq = resp.blockSeqReply;

            this.docId      = resp.RecId();
            this.clientpath = resp.Fullpath();

            this.a = A.blockEnd;
            return(this);
        }
Ejemplo n.º 3
0
        public DocsReq blockAbort(DocsResp startAck, SessionInf usr)
        {
            this.device = usr.device;

            this.blockSeq = startAck.blockSeqReply;

            this.docId      = startAck.RecId();
            this.clientpath = startAck.Fullpath();

            this.a = A.blockAbort;
            return(this);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        //public DocsReq blockUp(long sequence, DocsResp resp, StringBuilder b64, SessionInf usr) throws SemanticException {
        //	string uri64 = b64.toString();
        //	return blockUp(sequence, resp, uri64, usr);
        //}

        public DocsReq blockUp(long sequence, DocsResp resp, string s64, 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");
            }

            this.blockSeq = sequence;

            this.docId      = resp.RecId();
            this.clientpath = resp.Fullpath();
            this.uri64      = s64;

            this.a = A.blockUp;
            return(this);
        }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
        public List <AlbumResp> syncPhotos(List <IFileDescriptor> photos, SessionInf user)
        {
            AnsonHeader header = client.Header().act("album.c#", "synch", "c/photo", "multi synch");

            List <AlbumResp> reslts = new List <AlbumResp>(photos.Count);

            foreach (IFileDescriptor p in photos)
            {
                AlbumReq req = new AlbumReq()
                               .Device(user.device)
                               .createPhoto(p, user);

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

                AlbumResp resp = (AlbumResp)client.Commit(q, errCtx);

                reslts.Add(resp);
            }
            return(reslts);
        }
Ejemplo n.º 8
0
 /// <summary>Session login response from server.</summary>
 /// <paramref name="sessionInfo"></paramref>
 public SessionClient(SessionInf sessionInfo)
 {
     this.ssInf = sessionInfo;
 }
Ejemplo n.º 9
0
 public SessionClient(SessionInf ssInf)
 {
 }
Ejemplo n.º 10
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()));
 }
Ejemplo n.º 11
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);
        }