示例#1
0
        /// <summary>
        /// Submit transaction requist to jserv. This method is synchronized - not returned until callbacks been called.
        /// </summary>
        /// <param name="req"></param>
        /// <param name="onOk"></param>
        /// <param name="onErr"></param>
        public void CommitAsync(AnsonMsg req, OnOk onOk, OnError onErr = null, CancellationTokenSource waker = null)
        {
            Task t = Task.Run(async delegate
            {
                try
                {
                    HttpServClient httpClient = new HttpServClient();
                    AnsonMsg msg = await httpClient.Post(AnClient.ServUrl((Port)req.port), req);
                    MsgCode code = msg.code;

                    if (MsgCode.ok == code.code)
                    {
                        onOk.ok((AnsonResp)msg.Body(0));
                    }
                    else
                    {
                        if (onErr != null)
                        {
                            onErr.err(code, ((AnsonResp)msg.Body(0)).Msg());
                        }
                        else
                        {
                            Debug.WriteLine("Error: code: {0}\nerror: {1}",
                                            code, msg.ToString());
                        }
                    }
                }
                catch (Exception _) { }
                finally { if (waker != null)
                          {
                              waker.Cancel();
                          }
                }
            });
        }
示例#2
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);
        }
示例#3
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));
            }
        }
示例#4
0
        public async Task Commit_async(AnsonMsg req, OnOk onOk, OnError onErr = null)
        {
            HttpServClient httpClient = new HttpServClient();
            AnsonMsg       msg        = await httpClient.Post(AnClient.ServUrl((Port)req.port), req);

            MsgCode code = msg.code;

            if (AnClient.console)
            {
                System.Console.Out.WriteLine(msg.ToString());
            }

            if (MsgCode.ok == code.code)
            {
                onOk.ok((AnsonResp)msg.Body(0));
            }
            else
            {
                if (onErr != null)
                {
                    onErr.err(code, ((AnsonResp)msg.Body(0)).Msg());
                }
                else
                {
                    System.Console.Error.WriteLine("code: {0}\nerror: {1}",
                                                   code, msg.ToString());
                }
            }
        }
示例#5
0
 public void OnOkCallback()
 {
     if (ConfirmLoading)
     {
         ShowLoading();
     }
     OnOk?.Invoke(this);
 }
示例#6
0
        private void OkCreate(object sender, RoutedEventArgs e)
        {
            List <int> IDs = new List <int>();

            Common.UIElementCollectionToList(users.Children).Where((x) => ((CCheckUserItem)x).Selected).ToList().ForEach((x) => IDs.Add(((CCheckUserItem)x).User.ID));
            clin.Client.CreateGroup(groupName.Text, IDs.ToArray());
            OnOk?.Invoke();
        }
示例#7
0
        public override void HandleMediation()
        {
            base.HandleMediation();

            okButton.OnClick.AddListener(() => OnOk.Dispatch());
            yesButton.OnClick.AddListener(() => OnYes.Dispatch());
            noButton.OnClick.AddListener(() => OnNo.Dispatch());
        }
示例#8
0
        private void CloseFn(string output = null)
        {
            if (output != null && output.Length > 0)
            {
                OnOk?.Invoke(output);
            }

            Close();
        }
示例#9
0
        public InputDialogViewModel()
        {
            DialogOk = new Command(() =>
            {
                OnOk?.Invoke(this, null);
            });

            DialogCancel = new Command(() =>
            {
                OnCancel?.Invoke(this, null);
            });
        }
示例#10
0
 /// <summary>
 /// Triggers on ok
 /// </summary>
 public void Ok(Object sender, EventArgs e)
 {
     if (Directory.Exists(ProjectLocation.Text))
     {
         OnOk?.Invoke(ProjectName.Text, ProjectLocation.Text);
         CloseForm();
     }
     else
     {
         ShowError("Location does not exist, or is invalid.\nPlease check the project save location and try again.");
     }
 }
示例#11
0
        private DialogOptions BuildDialogOptions()
        {
            DialogOptions options = new DialogOptions()
            {
                OnClosed       = AfterClose,
                BodyStyle      = BodyStyle,
                CancelText     = CancelText,
                Centered       = Centered,
                Closable       = Closable,
                Draggable      = Draggable,
                DragInViewport = DragInViewport,
                CloseIcon      = CloseIcon,
                ConfirmLoading = ConfirmLoading,
                DestroyOnClose = DestroyOnClose,
                Footer         = Footer,
                ForceRender    = ForceRender,

                GetContainer = GetContainer,
                Keyboard     = Keyboard,
                Mask         = Mask,
                MaskClosable = MaskClosable,
                MaskStyle    = MaskStyle,

                OkText        = OkText,
                OkType        = OkType,
                Title         = Title,
                Width         = Width,
                WrapClassName = WrapClassName,
                ZIndex        = ZIndex,
                OnCancel      = async(e) =>
                {
                    if (OnCancel.HasDelegate)
                    {
                        await OnCancel.InvokeAsync(e);
                    }
                },
                OnOk = async(e) =>
                {
                    if (OnOk.HasDelegate)
                    {
                        await OnOk.InvokeAsync(e);
                    }
                },
                OkButtonProps = OkButtonProps,

                CancelButtonProps = CancelButtonProps,
                Rtl = Rtl
            };

            return(options);
        }
示例#12
0
        /// <summary>
        /// Upload files to "a_attaches" table. Before files been saved, all files attached to
        /// the recid will been deleted. (This is supported by the semantic-DA samantics configuration)
        /// <p><b>FIXME:</b></p>
        /// this method used 2 round of memory copy, should implemented in stream style
        /// </summary>
        /// <param name="files"></param>
        /// <param name="uri">see {@link https://odys-z.github.io/Anclient/guide/func-uri.html Anclient doc}</param>
        /// <param name="busiTbl">business table to which file is attached, e.g. "a_users"</param>
        /// <param name="recid">business record Id to which file is owned, e.g. "admin"</param>
        public void AttachFiles(List <string> files, string uri, string busiTbl, string recid,
                                OnOk onOk, OnError onErr)
        {
            AnsonMsg    jmsg = Delete(uri, "a_attaches");
            AnUpdateReq del  = (AnUpdateReq)jmsg.Body(0);

            del.WhereEq("busiTbl", busiTbl)
            .WhereEq("busiId", recid);

            foreach (string file in files)
            {
                byte[] f   = File.ReadAllBytes(file);
                string fn  = Path.GetFileName(file);
                string b64 = AESHelper.Encode64(f);
                del.Post(AnInsertReq
                         .formatInsertReq(null, null, "a_attaches")
                         .Cols("attName", "busiId", "busiTbl", "uri")
                         .Nv("attName", fn)
                         .Nv("busiId", recid)
                         .Nv("busiTbl", busiTbl)
                         .Nv("uri", b64));
            }

            jmsg.Header(Header());

            // Console(jmsg);

            /*
             * Commit(jmsg,
             *  (data) => {
             *      if (MsgCode.ok == code.code)
             *          if (onOk != null)
             *              onOk(code, (AnsonResp)data.Body(0));
             *          else Utils.Logi(code.ToString());
             *      else if (onErr != null)
             *              onErr(code, (AnsonResp)data.Body(0));
             *          else
             *              Utils.Warn(data.ToString());
             *  },
             *  onErr: (c, err) => {
             *      if (onErr != null)
             *          onErr(c, err);
             *      else
             *          Utils.Warn(string.Format(@"code: {0}, error: {1}", c, err.Msg()));
             *  });
             */
            Commit_async(jmsg, onOk, onErr);
        }
示例#13
0
        protected override void Run()
        {
            MessageBoxResult result = System.Windows.MessageBox.Show(Window.GetWindow(this), Message, Title, Buttons, Image, DefaultButton);

            Reset();
            OnResult?.ExecuteIfPossible(result);
            switch (result)
            {
            case MessageBoxResult.OK: OnOk?.ExecuteIfPossible(null); break;

            case MessageBoxResult.Cancel: OnCancel?.ExecuteIfPossible(null); break;

            case MessageBoxResult.Yes: OnYes?.ExecuteIfPossible(null); break;

            case MessageBoxResult.No: OnNo?.ExecuteIfPossible(null); break;
            }
        }
示例#14
0
        protected override void OnInitDocument(Document document)
        {
            //add interactivity to the HTML.

            var okButton     = (HtmlButtonElement)document.GetElementById("ok");
            var cancelButton = (HtmlButtonElement)document.GetElementById("cancel");

            cancelButton.OnClick += arg =>
            {
                BeginInvoke(new Action(() => OnCancel?.Invoke(this, EventArgs.Empty)));
                return(true);
            };
            okButton.OnClick += arg =>
            {
                Login    = ((HtmlInputElement)document.GetElementById("username")).Value;
                Password = ((HtmlInputElement)document.GetElementById("password")).Value;
                BeginInvoke(new Action(() => OnOk?.Invoke(this, EventArgs.Empty)));
                return(true);
            };
        }
示例#15
0
 public SessionClient openLink(String clientUri, OnOk onLink, OnError onBroken, int msInterv = 3000 * 60)
 {
     return(this);
 }
示例#16
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);
        }
示例#17
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);
 }
示例#18
0
#pragma warning restore 649

        private DialogOptions BuildDialogOptions()
        {
            DialogOptions options = new DialogOptions()
            {
                OnClosed       = AfterClose,
                BodyStyle      = BodyStyle,
                CancelText     = CancelText ?? Locale.CancelText,
                Centered       = Centered,
                Closable       = Closable,
                Draggable      = Draggable,
                DragInViewport = DragInViewport,
                CloseIcon      = CloseIcon,
                ConfirmLoading = ConfirmLoading,
                Footer         = Footer,

                GetContainer = GetContainer,
                Keyboard     = Keyboard,
                Mask         = Mask,
                MaskClosable = MaskClosable,
                MaskStyle    = MaskStyle,

                OkText        = OkText ?? Locale.OkText,
                OkType        = OkType,
                Title         = Title,
                TitleTemplate = TitleTemplate,
                Width         = Width,
                WrapClassName = WrapClassName,
                ZIndex        = ZIndex,
                OnCancel      = async(e) =>
                {
                    var args = new ModalClosingEventArgs(e, false);

                    var modalTemplate = (ModalRef as IFeedbackRef)?.ModalTemplate;
                    if (modalTemplate != null)
                    {
                        await modalTemplate.OnFeedbackCancelAsync(args);
                    }
                    if (!args.Cancel)
                    {
                        await(ModalRef?.OnCancel?.Invoke() ?? Task.CompletedTask);

                        if (OnCancel.HasDelegate)
                        {
                            await OnCancel.InvokeAsync(e);
                        }
                    }
                },
                OnOk = async(e) =>
                {
                    var args = new ModalClosingEventArgs(e, false);

                    var modalTemplate = (ModalRef as IFeedbackRef)?.ModalTemplate;
                    if (modalTemplate != null)
                    {
                        await modalTemplate.OnFeedbackOkAsync(args);
                    }
                    if (!args.Cancel)
                    {
                        await(ModalRef?.OnOk?.Invoke() ?? Task.CompletedTask);

                        if (OnOk.HasDelegate)
                        {
                            await OnOk.InvokeAsync(e);
                        }
                    }
                    else
                    {
                        ConfirmLoading = false;
                        await InvokeStateHasChangedAsync();
                    }
                },
                OkButtonProps = OkButtonProps,

                CancelButtonProps = CancelButtonProps,
                Rtl           = Rtl,
                MaxBodyHeight = MaxBodyHeight
            };

            return(options);
        }
示例#19
0
 private void _ok(object obj)
 {
     OnOk?.Invoke(this, EventArgs.Empty);
 }
 protected virtual bool CanOK(object parameter)
 {
     return(IsModified && OnOk?.Invoke(this) != false);
 }
示例#21
0
 protected void HandleOk(MouseEventArgs e)
 {
     Console.WriteLine(e);
     OnOk.InvokeAsync(SelectedIcon);
     _visible = false;
 }
示例#22
0
 private void _ok(object obj)
 {
     SaveToModel();
     OnOk?.Invoke(this, EventArgs.Empty);
 }
示例#23
0
 private void InvokeOnOk()
 {
     OnOk?.Invoke(this, EventArgs.Empty);
 }
示例#24
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     OnOk?.Invoke(this, new OnOkEventArgs(TopicName, Message));
 }
示例#25
0
 public static void Open(float speed, OnOk onOk)
 {
     var window = EditorWindow.GetWindow<AdjustSpeedWindow>();
     window.speed = speed;
     window.onOk = onOk;
 }