Exemplo n.º 1
0
        TimeSpan UpdateNextShare()
        {
            ShareMessage sh = null;
            Message      m  = null;

            using (var repo = new Repo()) {
                sh = repo.Table <ShareMessage>().Where(s => s.Status == ShareMessageStatus.Unsent).FirstOrDefault();
                if (sh != null)
                {
                    m = repo.Table <Message>().Where(mm => mm.Id == sh.MessageId).FirstOrDefault();
                }

                if (sh == null)
                {
                    // Nothing to do
                    return(TimeSpan.FromMinutes(1));
                }

                if (sh != null && m == null)
                {
                    // Missing the message, must have been deleted
                    sh.Status = ShareMessageStatus.Abandoned;
                    repo.Update(sh);
                    return(TimeSpan.FromSeconds(2));
                }
            }


            //
            // Ready to send!
            //
            var post = new Dictionary <string, string>();

            post["url"]   = m.Url;
            post["title"] = m.Subject;
            post["from"]  = sh.From;
            post["to"]    = sh.To;

            try {
                Http.Post("http://lcarsreader.com/Share/Send", post);

                sh.Status = ShareMessageStatus.Sent;
                using (var repo = new Repo()) {
                    repo.Update(sh);
                }
                Console.WriteLine("SU: Successfully posted share for " + m.Subject);
                return(TimeSpan.FromSeconds(2));
            }
            catch (Exception ex) {
                Console.WriteLine("SU: ERROR: " + ex.Message);
                return(TimeSpan.FromMinutes(1));
            }
        }
Exemplo n.º 2
0
        public override void ViewDidLoad()
        {
            try {
                TitleLabel.Font = Theme.HugeFont;
                TitleLabel.Text = "EMAIL";

                _info = Repo.Foreground.Table <ShareInfo> ().FirstOrDefault();
                if (_info == null)
                {
                    _info = new ShareInfo {
                        From = UIDevice.CurrentDevice.Name, To = ""
                    };
                    Repo.Foreground.Insert(_info);
                }

                var y = TitleLabel.Frame.Bottom + App.Inst.LabelGap;
                _form = new Form(_info, new RectangleF(TitleLabel.Frame.Left, y, View.Frame.Width, View.Frame.Height - y));
                _form.ConfirmButtonText = "SHARE";
                _form.ShowCancelButton  = true;

                _form.OnCancel += delegate {
                    try {
                        App.Inst.PopDialog();
                    } catch (Exception error) {
                        Log.Error(error);
                    }
                };
                _form.OnOK += delegate {
                    try {
                        Repo.Foreground.Update(_info);

                        var sh = new ShareMessage {
                            From = _info.From, To = _info.To, Comment = "", MessageId = Message.Id, Status = ShareMessageStatus.Unsent
                        };
                        Repo.Foreground.Insert(sh);

                        ShareUpdater.SetSharesChanged();

                        App.Inst.PopDialog();
                    } catch (Exception error) {
                        Log.Error(error);
                    }
                };

                View.AddSubview(_form);
            } catch (Exception error) {
                Log.Error(error);
            }
        }
Exemplo n.º 3
0
        public override void ViewDidLoad()
        {
            try {
                TitleLabel.Font = Theme.HugeFont;
                TitleLabel.Text = "EMAIL";

                _info = Repo.Foreground.Table<ShareInfo> ().FirstOrDefault ();
                if (_info == null) {
                    _info = new ShareInfo { From = UIDevice.CurrentDevice.Name, To = "" };
                    Repo.Foreground.Insert (_info);
                }

                var y = TitleLabel.Frame.Bottom + App.Inst.LabelGap;
                _form = new Form (_info, new RectangleF (TitleLabel.Frame.Left, y, View.Frame.Width, View.Frame.Height - y));
                _form.ConfirmButtonText = "SHARE";
                _form.ShowCancelButton = true;

                _form.OnCancel += delegate {
                    try {
                        App.Inst.PopDialog ();
                    } catch (Exception error) {
                        Log.Error (error);
                    }
                };
                _form.OnOK += delegate {
                    try {
                        Repo.Foreground.Update (_info);

                        var sh = new ShareMessage { From = _info.From, To = _info.To, Comment = "", MessageId = Message.Id, Status = ShareMessageStatus.Unsent };
                        Repo.Foreground.Insert (sh);

                        ShareUpdater.SetSharesChanged ();

                        App.Inst.PopDialog ();

                    } catch (Exception error) {
                        Log.Error (error);
                    }
                };

                View.AddSubview (_form);
            } catch (Exception error) {
                Log.Error (error);
            }
        }