Exemple #1
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            using (var repo = new Repo ()) {
                repo.Initialize ();

                //
                // Load initial data
                //
                var services = repo.GetActiveServices();
                if (services.Count == 0) {

                    repo.InsertDefaultServices();

                }
            }

            _services = new ServicesController ();
            _nav = new UINavigationController (_services);

            window.AddSubview (_nav.View);

            window.MakeKeyAndVisible ();

            return true;
        }
Exemple #2
0
        public DataViewController(UserQuery query, string url)
            : base(UITableViewStyle.Grouped)
        {
            try {
                Query = query;
                Url = url;
                Title = Query.Name;

                PagingEnabled = true;
                NumEntitiesPerRequest = 20;
                _index = 0;

                _loadSection = new DialogSection ();
                _loadElement = new LoadingElement ();
                _loadSection.Add (_loadElement);
                _loadElement.Start ();
                Sections.Add (_loadSection);

                _moreSection = new DialogSection ();
                _moreSection.Add (new ActionElement ("More", GetMore));

                if (PagingEnabled) {
                    Sections.Add (_moreSection);
                }

                using (var repo = new Repo ()) {
                    Feed = repo.GetFeed (query.FeedId);
                }

                if (Query.Id > 0) {
                    NavigationItem.RightBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Edit, HandleEdit);
                }

                GetMore ();

            } catch (Exception error) {
                Log.Error (error);
            }
        }
Exemple #3
0
        public QueryController(UserService service, UserQuery query)
            : base(UITableViewStyle.Grouped)
        {
            try {

                QueryId = query.Id;

                Title = query.Name;

                if (query.Name.Length == 0) {
                    Title = "Add Query";
                }

                _nameElement = new TextFieldElement ("Name", "Display Name", 70);
                _nameElement.Value = query.Name;
                _nameElement.TextField.AutocapitalizationType = UITextAutocapitalizationType.Words;
                _nameElement.TextField.AllEditingEvents += HandleNameElementTextFieldAllEditingEvents;

                using (var repo = new Repo ()) {
                    _feedElement = new QueryFeedElement (service, repo.GetFeed (query.FeedId));
                }

                _filterElement = new TextViewElement ("Filter", 44 * 2);
                _filterElement.TextView.Font = UIFont.FromName ("Courier-Bold", 16);
                _filterElement.TextView.AutocorrectionType = UITextAutocorrectionType.No;
                _filterElement.TextView.ContentInset = new UIEdgeInsets (0, 0, 0, 0);
                _filterElement.TextView.Changed += delegate {
                    try {
                        if (_filterElement.TextView.Text.Contains ("\n")) {
                            _filterElement.TextView.Text = _filterElement.TextView.Text.Replace ("\n", " ").Trim ();
                            _filterElement.TextView.ResignFirstResponder ();
                        }
                    } catch (Exception err) {
                        Log.Error (err);
                    }
                };
                _filterElement.Value = query.Filter;

                _orderbyElement = new TextFieldElement ("Order", "Orderby Expression", 70);
                _orderbyElement.Value = query.OrderBy;

                var sec = new DialogSection ();
                sec.Add (_nameElement);
                sec.Add (_feedElement);
                sec.Add (_filterElement);
                sec.Add (_orderbyElement);

                Sections.Add (sec);

                _helpElement = new ActionElement ("Query Help", delegate {
                    var b = new BrowserController ("Query Help", System.IO.File.ReadAllText ("QueryHelp.html"));
                    NavigationController.PushViewController (b, true);
                });
                _helpSec = new DialogSection ();
                _helpSec.Add (_helpElement);
                Sections.Add (_helpSec);

                _propsSec = new DialogSection ("Properties");

                if (QueryId > 0) {
                    var delElement = new ActionElement ("Delete Query", delegate {
                        _deleteAlert = new UIAlertView ("", "Are you sure you wish to delete the query " + Name + "?", null, "Cancel", "Delete");
                        _deleteAlert.Clicked += Handle_deleteAlertClicked;
                        _deleteAlert.Show ();
                    });
                    var csec = new DialogSection ();
                    csec.Add (delElement);
                    Sections.Add (csec);
                }

                NavigationItem.LeftBarButtonItem = new UIBarButtonItem ("Cancel", UIBarButtonItemStyle.Bordered, HandleCancelButton);
                NavigationItem.RightBarButtonItem = new UIBarButtonItem ("Done", UIBarButtonItemStyle.Done, HandleDoneButton);

            } catch (Exception error) {
                Log.Error (error);
            }
        }
Exemple #4
0
        void RefreshProps()
        {
            Sections.Remove (_propsSec);

            if (_feedElement.Value != null) {

                Sections.Insert (Sections.IndexOf(_helpSec), _propsSec);

                if (_metaDoc == null || _metaDoc.BaseUrl != _feedElement.Value.BaseUrl) {
                    using (var repo = new Repo ()) {
                        _metaDoc = repo.FindMetadataDocument (_feedElement.Value.BaseUrl, _feedElement.Value.ServiceId);
                    }
                }

                _propsSec.Clear ();
                if (_metaDoc != null) {

                    var ent = _metaDoc.Metadata.FindEntityTypeForEntitySet (_feedElement.Value.Name);
                    if (ent != null) {

                        foreach (var p in ent.Properties) {

                            if (p.IsBasicType) {
                                _propsSec.Add (new PropertyElement (p.Name, p.TypeFullName));
                            }
                            else {
                                var cent = _metaDoc.Metadata.FindEntityType(p.TypeFullName);
                                if (cent != null) {
                                    foreach (var cp in cent.Properties) {
                                        if (cp.IsBasicType) {
                                            _propsSec.Add (new PropertyElement (p.Name +"/" + cp.Name, cp.TypeFullName));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            TableView.ReloadData ();
        }
Exemple #5
0
        void Handle_deleteAlertClicked(object sender, UIButtonEventArgs e)
        {
            try {
                if (e.ButtonIndex == 1) {
                    using (var repo = new Repo ()) {
                        repo.DeleteQuery (QueryId);
                    }
                    DismissModalViewControllerAnimated (true);
                }

            } catch (Exception error) {
                Log.Error (error);
            }
        }
Exemple #6
0
        void HandleDoneButton(object sender, EventArgs e)
        {
            try {

                var service = new UserService {
                    Name = _nameElement.Value.Trim (),
                    ServiceRootUri = _urlElement.Value.Trim ()
                };

                if (service.Name.Length > 0 && service.ServiceRootUri.Length > 0) {

                    using (var repo = new Repo ()) {
                        repo.Add (service);
                    }

                    DismissModalViewControllerAnimated (true);

                    _doneAction ();

                } else {

                    _noAlert = new UIAlertView ("", "Please completely fill in the form to add the service.", null, "OK");
                    _noAlert.Show ();

                }

            } catch (Exception error) {
                Log.Error (error);
            }
        }
Exemple #7
0
        void HandleEdit(object sender, EventArgs e)
        {
            try {

                UserService service = null;

                using (var repo = new Repo()) {
                    service = repo.GetService(Query.ServiceId);
                }

                var editC = new QueryController (service, Query);
                var navC = new UINavigationController (editC);

                editC.Done += delegate {

                    editC.DismissModalViewControllerAnimated (true);

                    Query.Filter = editC.Filter;
                    Query.FeedId = editC.Feed.Id;
                    Query.Name = editC.Name;
                    Query.OrderBy = editC.OrderBy;

                    using (var repo = new Repo ()) {
                        repo.Save (Query);
                    }

                    _numGets = 0;
                    _index = 0;
                    Sections.Clear ();

                    _loadSection = new DialogSection ();
                    _loadSection.Add (_loadElement);
                    _loadElement.Start ();
                    Sections.Add (_loadSection);

                    GetMore ();
                };

                NavigationController.PresentModalViewController (navC, true);

            } catch (Exception error) {
                Log.Error (error);
            }
        }
Exemple #8
0
 public override void OnSelected(DialogViewController sender, NSIndexPath indexPath)
 {
     UserFeed feed = null;
     using (var repo = new Repo()) {
         feed = repo.GetFeed(Query.FeedId);
     }
     var c = new DataViewController(Query, feed.Url);
     sender.NavigationController.PushViewController(c, true);
 }
Exemple #9
0
        void LoadData(bool forceFeeds)
        {
            //
            // Load the data
            //
            List<UserQuery> queries = null;
            List<UserFeed> feeds = null;

            using (var repo = new Repo ()) {
                queries = repo.GetQueries (Service);

                feeds = repo.GetFeeds (Service);

                feeds.Sort ((x, y) => x.Category.CompareTo (y.Category));

                if (feeds.Count == 0 || Service.ShouldUpdateFeeds || forceFeeds) {
                    BeginDownloadFeeds ();
                }
            }

            //
            // Update the UI
            //
            if (feeds.Count > 0) {
                RemoveLoading ();
                foreach (var f in _feeds) {
                    Sections.Remove (f);
                }

                DialogSection feedSection = null;

                foreach (var f in feeds) {

                    if (feedSection == null || feedSection.Header != f.Category) {
                        feedSection = new DialogSection (f.Category);
                        _feeds.Add (feedSection);
                        Sections.Add (feedSection);
                    }

                    var e = new FeedElement (Service, f, UITableViewCellAccessory.DisclosureIndicator);
                    e.Selected += delegate { PushDataViewController (e.Feed); };
                    feedSection.Add (e);

                }
            }

            _queries.Clear ();
            foreach (var q in queries) {

                var e = new QueryElement (q);
                _queries.Add (e);

            }
            if (queries.Count > 0 && !Sections.Contains (_queries)) {
                Sections.Insert (0, _queries);
            }

            TableView.ReloadData ();
        }
Exemple #10
0
        void HandleAddButton(object sender, EventArgs e)
        {
            try {

                var addC = new QueryController (Service, new UserQuery());
                var navC = new UINavigationController (addC);

                addC.Done += delegate {

                    var q = new UserQuery {
                        Filter = addC.Filter,
                        FeedId = addC.Feed.Id,
                        Name = addC.Name,
                        OrderBy = addC.OrderBy,
                        ServiceId = Service.Id
                    };

                    using (var repo = new Repo ()) {
                        repo.Add (q);
                    }

                    addC.DismissModalViewControllerAnimated (true);
                };

                NavigationController.PresentModalViewController (navC, true);

            } catch (Exception error) {
                Log.Error (error);
            }
        }
Exemple #11
0
        void BeginDownloadFeeds()
        {
            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;

            App.RunInBackground (delegate {

                Exception netError = null;

                using (var repo = new Repo ()) {

                    try {
                        var doc = new ServiceDocument (Service.ServiceRootUri);
                        var fs = doc.Feeds;

                        var feeds = new List<UserFeed> ();
                        foreach (var f in fs) {
                            feeds.Add (new UserFeed (f));
                        }

                        var metaDocs = new List<UserMetadataDocument> ();
                        foreach (var m in doc.Metadata) {
                            metaDocs.Add (new UserMetadataDocument (m));
                        }

                        repo.UpdateFeeds (feeds, Service);
                        repo.UpdateMetadataDocuments (metaDocs, Service);

                        Service.LastFeedUpdateTime = DateTime.UtcNow;

                        repo.Save (Service);
                    } catch (Exception ex) {
                        netError = ex;
                    }
                }

                if (netError != null) {
                    App.RunInForeground (delegate {
                        RemoveLoading ();
                        _netError.ShowError (netError);
                    });
                } else {
                    App.RunInForeground (delegate {
                        RemoveLoading ();
                        LoadData (false);
                    });
                }
            });
        }