Esempio n. 1
0
        public AlbumClientier getSettings(OnOk onOk, OnError onErr)
        {
            Task.Run(() =>
            {
                try
                {
                    AnsonHeader header = client
                                         .Header()
                                         .UsrAct("album.c#", "profile", "r/settings", "load profile");

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

                    client.CommitAsync(q, onOk, onErr);
                }
                catch (Exception e)
                {
                    onErr.err(new MsgCode(MsgCode.exIo), string.Format("%s\n%s", e.GetType().Name, e.Message));
                }
            });

            return(this);
        }
Esempio n. 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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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));
            }
        }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
 public AnsonHeader Header()
 {
     if (header == null)
     {
         header = new AnsonHeader(ssInf.ssid, ssInf.uid);
     }
     return(header);
 }
Esempio n. 7
0
        public AnsonMsg Delete(string uri, string tbl, string[] act = null)
        {
            AnUpdateReq itm  = AnUpdateReq.formatDelReq(uri, null, tbl);
            AnsonMsg    jmsg = UserReq(uri, new Port(Port.update), act, itm);

            AnsonHeader header = new AnsonHeader(ssInf.ssid, ssInf.uid);

            if (act != null && act.Length > 0)
            {
                header.act(act);
            }

            return(jmsg.Header(header));
        }
Esempio n. 8
0
        public AlbumResp insertPhoto(string collId, string fullpath, string clientname)
        {
            AlbumReq req = new AlbumReq(uri)
                           .createPhoto(collId, fullpath)
                           .photoName(clientname);

            req.A(A.insertPhoto);

            AnsonHeader header = client.Header().act("album.c#", "create", "c/photo", "create photo");
            AnsonMsg    q      = client.UserReq(uri, new AlbumPort(AlbumPort.album), req)
                                 .Header(header);

            return((AlbumResp)client.Commit(q, errCtx));
        }
Esempio n. 9
0
        public AnsonMsg Insert(string uri, string tbl, string[] act = null)
        {
            AnInsertReq itm  = AnInsertReq.formatInsertReq(null, tbl, uri);
            AnsonMsg    jmsg = UserReq(uri, new Port(Port.insert), act, itm);

            AnsonHeader header = new AnsonHeader(ssInf.ssid, ssInf.uid);

            if (act != null && act.Length > 0)
            {
                header.act(act);
            }

            return(jmsg.Header(header)
                   .Body(itm, uri));
        }
Esempio n. 10
0
        public AnsonMsg Update(string conn, string tbl, string[] act = null)
        {
            AnUpdateReq itm  = AnUpdateReq.FormatUpdateReq(conn, null, tbl);
            AnsonMsg    jmsg = UserReq(new Port(Port.update), act, itm);

            AnsonHeader header = new AnsonHeader(ssInf.ssid, ssInf.uid);

            if (act != null && act.Length > 0)
            {
                header.act(act);
            }

            return(jmsg.Header(header)
                   );    //.Body(itm);
        }
Esempio n. 11
0
        public void TestMenu(string s, string roleId)
        {
            AnDatasetReq req = new AnDatasetReq(null, "sys-sqlite");

            string      t      = "menu";
            AnsonHeader header = client.Header()
                                 .UsrAct("SemanticClientTest", "init", t,
                                         "test jclient.java loading menu from menu.sample");

            AnsonMsg jmsg = client.UserReq(new Port(Port.echo), null, req);

            jmsg.Header(header);

            client.Console(jmsg);

            client.Commit(jmsg, (code, data) => {
                IList rses = (IList)((AnDatasetResp)data.Body()?[0]).Forest();
                Utils.Logi(rses);;
            });
        }
Esempio n. 12
0
        /// <summary>Format a query request object, including all information for
        /// construct a "select" statement.</summary>
        /// <param name="uri"></param>
        /// <param name="tbl"></param>
        /// <param name="alias">main table alias</param>
        /// <param name="page">page, -1 for no paging at server side.</param>
        /// <param name="size"></param>
        /// <param name="funcId">current function ID</param>
        /// <returns>formatted query object</returns>
        public AnsonMsg query(string uri, string tbl, string alias,
                              int page, int size, string funcId = null)
        {
            AnsonMsg msg = new AnsonMsg((IPort) new Port(Port.query), null);

            AnsonHeader header = new AnsonHeader(ssInf.ssid, ssInf.uid);

            if (funcId != null && funcId.Length > 0)
            {
                header.UsrAct(funcId, "query", "R", "test");
            }

            msg.Header(header);

            AnQueryReq itm = AnQueryReq.formatReq(uri, msg, tbl, alias);

            msg.Body(itm, uri);
            itm.Page(page, size);

            return(msg);
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }