コード例 #1
0
ファイル: ServiceController.cs プロジェクト: jorik041/odata
        public ServiceController(UserService svc)
            : base(UITableViewStyle.Grouped)
        {
            try {
                Title = svc.Name;

                Service = svc;

                _queries = new DialogSection ("Queries");

                _feeds = new List<DialogSection> ();
                _feeds.Add (new DialogSection ("Feeds"));

                _loadingSection = new DialogSection ();
                _loadingElement = new LoadingElement ();
                _loadingElement.Start ();
                _loadingSection.Add (_loadingElement);

                Sections.AddRange (_feeds);

                Sections.Add (_loadingSection);

                NavigationItem.RightBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Add, HandleAddButton);

            } catch (Exception error) {
                Log.Error (error);
            }
        }
コード例 #2
0
ファイル: AddController.cs プロジェクト: jorik041/odata
        public AddController(Action doneAction)
            : base(UITableViewStyle.Grouped)
        {
            try {

                Title = "Add Service";

                _doneAction = doneAction;

                _nameElement = new TextFieldElement ("Name", "Display Name", 70);
                _nameElement.TextField.AutocapitalizationType = UITextAutocapitalizationType.Words;

                _urlElement = new TextFieldElement ("URL", "http://", 70);
                _urlElement.TextField.AutocapitalizationType = UITextAutocapitalizationType.None;
                _urlElement.TextField.KeyboardType = UIKeyboardType.Url;
                _urlElement.TextField.AutocorrectionType = UITextAutocorrectionType.No;

                var sec = new DialogSection ();
                sec.Add (_nameElement);
                sec.Add (_urlElement);

                Sections.Add (sec);

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

            } catch (Exception error) {
                Log.Error (error);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
ファイル: DataViewController.cs プロジェクト: jorik041/odata
        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);
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
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();
        }
コード例 #7
0
ファイル: QueryController.cs プロジェクト: jorik041/odata
        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);
            }
        }
コード例 #8
0
ファイル: DataViewController.cs プロジェクト: jorik041/odata
        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);
            }
        }
コード例 #9
0
ファイル: DataViewController.cs プロジェクト: jorik041/odata
        void GetMore()
        {
            if (!PagingEnabled && _numGets > 0) {
                return;
            }

            if (PagingEnabled) {
                Sections.Remove (_moreSection);
                TableView.ReloadData ();
            }

            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;

            App.RunInBackground (delegate {

                var atom = "";

                try {
                    var q = new Dictionary<string, object> ();

                    AddToQuery (q);

                    if (PagingEnabled) {
                        q["$skip"] = _index;
                        q["$top"] = NumEntitiesPerRequest;
                    }

                    try {

                        atom = Http.Get (Url + "?" + Http.MakeQueryString (q));

                    } catch (System.Net.WebException nex) {
                        var hr = nex.Response as System.Net.HttpWebResponse;
                        if (hr.StatusDescription.ToLowerInvariant ().IndexOf ("not implemented") >= 0 && PagingEnabled) {

                            //
                            // Try without paging
                            //
                            q.Remove ("$skip");
                            q.Remove ("$top");
                            atom = Http.Get (Url + "?" + Http.MakeQueryString (q));
                            PagingEnabled = false;
                        }
                    }

                    _numGets++;

                    if (PagingEnabled) {
                        _index += NumEntitiesPerRequest;
                    }
                } catch (Exception netError) {
                    Console.WriteLine (netError);
                    App.RunInForeground (delegate { _netError.ShowError (netError); });
                    return;
                }

                var ents = EntitySet.LoadFromAtom (atom);

                App.RunInForeground (delegate {

                    UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;

                    if (_loadSection != null) {
                        _loadElement.Stop ();
                        Sections.Remove (_loadSection);
                    }

                    foreach (var e in ents) {

                        var sec = new DialogSection (e.Title, e.Author);

                        foreach (var prop in e.Properties) {
                            sec.Add (new PropertyElement (e, prop));
                        }

                        foreach (var link in e.Links) {
                            if (link.Rel == "edit")
                                continue;
                            sec.Add (new LinkElement (Feed, link));
                        }

                        Sections.Add (sec);

                    }

                    if (PagingEnabled && ents.Count >= NumEntitiesPerRequest) {
                        Sections.Add (_moreSection);
                    }

                    TableView.ReloadData ();

                });

            });
        }
コード例 #10
0
ファイル: ServiceController.cs プロジェクト: jorik041/odata
 void RemoveLoading()
 {
     UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
     if (_loadingSection != null) {
         _loadingElement.Stop ();
         Sections.Remove (_loadingSection);
         _loadingSection = null;
     }
 }
コード例 #11
0
ファイル: ServiceController.cs プロジェクト: jorik041/odata
        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 ();
        }
コード例 #12
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);
            }
        }
コード例 #13
0
        void GetMore()
        {
            if (!PagingEnabled && _numGets > 0)
            {
                return;
            }

            if (PagingEnabled)
            {
                Sections.Remove(_moreSection);
                TableView.ReloadData();
            }

            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;

            App.RunInBackground(delegate {
                var atom = "";

                try {
                    var q = new Dictionary <string, object> ();

                    AddToQuery(q);

                    if (PagingEnabled)
                    {
                        q["$skip"] = _index;
                        q["$top"]  = NumEntitiesPerRequest;
                    }

                    try {
                        atom = Http.Get(Url + "?" + Http.MakeQueryString(q));
                    } catch (System.Net.WebException nex) {
                        var hr = nex.Response as System.Net.HttpWebResponse;
                        if (hr.StatusDescription.ToLowerInvariant().IndexOf("not implemented") >= 0 && PagingEnabled)
                        {
                            //
                            // Try without paging
                            //
                            q.Remove("$skip");
                            q.Remove("$top");
                            atom          = Http.Get(Url + "?" + Http.MakeQueryString(q));
                            PagingEnabled = false;
                        }
                    }

                    _numGets++;

                    if (PagingEnabled)
                    {
                        _index += NumEntitiesPerRequest;
                    }
                } catch (Exception netError) {
                    Console.WriteLine(netError);
                    App.RunInForeground(delegate { _netError.ShowError(netError); });
                    return;
                }

                var ents = EntitySet.LoadFromAtom(atom);

                App.RunInForeground(delegate {
                    UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;

                    if (_loadSection != null)
                    {
                        _loadElement.Stop();
                        Sections.Remove(_loadSection);
                    }

                    foreach (var e in ents)
                    {
                        var sec = new DialogSection(e.Title, e.Author);

                        foreach (var prop in e.Properties)
                        {
                            sec.Add(new PropertyElement(e, prop));
                        }

                        foreach (var link in e.Links)
                        {
                            if (link.Rel == "edit")
                            {
                                continue;
                            }
                            sec.Add(new LinkElement(Feed, link));
                        }

                        Sections.Add(sec);
                    }

                    if (PagingEnabled && ents.Count >= NumEntitiesPerRequest)
                    {
                        Sections.Add(_moreSection);
                    }

                    TableView.ReloadData();
                });
            });
        }