Exemple #1
0
        // Event handlers for Debug tab
        private void Debug_DeleteButton_Click(object sender, EventArgs e)
        {
            // clear the record queue
            RequestQueue.DeleteQueue(RequestQueue.UserQueue);
            RequestQueue.DeleteQueue(RequestQueue.SystemQueue);

            // re-render the debug tab
            RenderDebugPanel();
        }
Exemple #2
0
        public void EraseAllData()
        {
            foreach (var tl in Folders)
                StorageHelper.DeleteFolder(tl);
            StorageHelper.WriteConstants(null);
            StorageHelper.WriteDefaultFolderID(null);
            StorageHelper.WriteItemTypes(null);
            StorageHelper.WriteTags(null);
            StorageHelper.WriteFolders(null);
            StorageHelper.WriteUserCredentials(null);
            RequestQueue.DeleteQueue(RequestQueue.UserQueue);
            RequestQueue.DeleteQueue(RequestQueue.SystemQueue);

            IsDataLoaded = false;
            LastNetworkOperationStatus = false;
            if (FolderDictionary != null)
                FolderDictionary.Clear();

            LoadData();
        }
Exemple #3
0
        public void DebugPage()
        {
            TraceHelper.AddMessage("Debug: constructor");

            // render URL and status
            var serviceUrl = new EntryElement("URL", "URL to connect to", WebServiceHelper.BaseUrl);
            var service    = new Section("Service")
            {
                serviceUrl,
                new StringElement("Store New Service URL", delegate
                {
                    serviceUrl.FetchValue();
                    // validate that this is a good URL before storing it (a bad URL can hose the phone client)
                    Uri uri = null;
                    if (Uri.TryCreate(serviceUrl.Value, UriKind.RelativeOrAbsolute, out uri) &&
                        (uri.Scheme == "http" || uri.Scheme == "https"))
                    {
                        WebServiceHelper.BaseUrl = serviceUrl.Value;
                    }
                    else
                    {
                        serviceUrl.Value = WebServiceHelper.BaseUrl;
                    }
                }),
                new StringElement("Connected", App.ViewModel.LastNetworkOperationStatus.ToString()),
            };

            // render user queue
            var userQueue = new Section("User Queue");

            userQueue.Add(new StringElement(
                              "Clear Queue",
                              delegate
            {
                RequestQueue.DeleteQueue(RequestQueue.UserQueue);
                userQueue.Clear();
            }));

            List <RequestQueue.RequestRecord> requests = RequestQueue.GetAllRequestRecords(RequestQueue.UserQueue);

            if (requests != null)
            {
                foreach (var req in requests)
                {
                    string typename;
                    string reqtype;
                    string id;
                    string name;
                    RequestQueue.RetrieveRequestInfo(req, out typename, out reqtype, out id, out name);
                    var sse = new StyledStringElement(String.Format("  {0} {1} {2} (id {3})", reqtype, typename, name, id))
                    {
                        Font = UIFont.FromName("Helvetica", UIFont.SmallSystemFontSize),
                    };
                    userQueue.Add(sse);
                }
            }

            // render system queue
            var systemQueue = new Section("System Queue");

            systemQueue.Add(new StringElement(
                                "Clear Queue",
                                delegate
            {
                RequestQueue.DeleteQueue(RequestQueue.SystemQueue);
                systemQueue.Clear();
            }));

            requests = RequestQueue.GetAllRequestRecords(RequestQueue.SystemQueue);
            if (requests != null)
            {
                foreach (var req in requests)
                {
                    string typename;
                    string reqtype;
                    string id;
                    string name;
                    RequestQueue.RetrieveRequestInfo(req, out typename, out reqtype, out id, out name);
                    var sse = new StyledStringElement(String.Format("  {0} {1} {2} (id {3})", reqtype, typename, name, id))
                    {
                        Font = UIFont.FromName("Helvetica", UIFont.SmallSystemFontSize),
                    };
                    systemQueue.Add(sse);
                }
            }

            var traceMessages = new Section("Trace Messages");

            traceMessages.Add(new StringElement(
                                  "Clear Trace",
                                  delegate
            {
                TraceHelper.ClearMessages();
                traceMessages.Clear();
            }));
            traceMessages.Add(new StringElement(
                                  "Send Trace",
                                  delegate
            {
                TraceHelper.SendMessages(App.ViewModel.User);
            }));
            foreach (var m in TraceHelper.GetMessages().Split('\n'))
            {
                // skip empty messages
                if (m == "")
                {
                    continue;
                }

                // create a new (small) string element with a detail indicator which
                // brings up a message box with the entire message
                var sse = new StyledStringElement(m)
                {
                    Accessory = UITableViewCellAccessory.DetailDisclosureButton,
                    Font      = UIFont.FromName("Helvetica", UIFont.SmallSystemFontSize),
                };
                string msg = m;                  // make a copy for the closure below
                sse.AccessoryTapped += delegate
                {
                    var alert = new UIAlertView("Detail", msg, null, "Ok");
                    alert.Show();
                };
                traceMessages.Add(sse);
            }
            ;

            var root = new RootElement("Debug")
            {
                service,
                userQueue,
                systemQueue,
                traceMessages,
            };

            var dvc = new DialogViewController(root, true);

            dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground);
            this.PushViewController(dvc, true);
            //this.NavigationController.PushViewController (dvc, true);
        }
Exemple #4
0
        private void VerifyUserCallback(User user, HttpStatusCode?code)
        {
            // run this on the UI thread
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // if the user did not get returned, the operation could not have been successful
                if (code == HttpStatusCode.OK && user == null)
                {
                    code = HttpStatusCode.ServiceUnavailable;
                }
                switch (code)
                {
                case HttpStatusCode.OK:
                    MessageBox.Show(String.Format("successfully connected to account {0}; data sync will start automatically.", Email.Text));
                    accountOperationSuccessful = true;
                    user.Synced = true;
                    // the server no longer echos the password in the payload so keep the local value when successful
                    if (user.Password == null)
                    {
                        user.Password = Password.Password;
                    }
                    App.ViewModel.User = user;
                    // prepare for sync by cleaning out the user queue and deleting the system queue ($ClientSettings comes from the server account)
                    RequestQueue.PrepareUserQueueForAccountConnect();
                    RequestQueue.DeleteQueue(RequestQueue.SystemQueue);
                    App.ViewModel.SyncWithService();
                    break;

                case HttpStatusCode.NotFound:
                    MessageBox.Show(String.Format("user {0} not found", Email.Text));
                    accountOperationSuccessful = false;
                    break;

                case HttpStatusCode.Forbidden:
                    MessageBox.Show(String.Format("incorrect password"));
                    accountOperationSuccessful = false;
                    break;

                case null:
                    MessageBox.Show(String.Format("couldn't reach the server"));
                    accountOperationSuccessful = false;
                    break;

                default:
                    MessageBox.Show(String.Format("did not successfully connect to account {0}", Email.Text));
                    accountOperationSuccessful = false;
                    break;
                }

                // update UI if successful
                if (accountOperationSuccessful)
                {
                    NotifyPropertyChanged("ConnectedMode");
                    NotifyPropertyChanged("CreateButtonText");
                    NotifyPropertyChanged("EnableButtons");
                    Email.IsEnabled    = false;
                    Password.IsEnabled = false;
                    // return to main page
                    TraceHelper.StartMessage("Settings: Navigate back");
                    NavigationService.GoBack();
                }
            });
        }
Exemple #5
0
        private void VerifyUserCallback(User user, HttpStatusCode?code)
        {
            this.BeginInvokeOnMainThread(() =>
            {
                string email = ((EntryElement)Email).Value;
                string pswd  = ((EntryElement)Password).Value;

                // if the user did not get returned, the operation could not have been successful
                if (code == HttpStatusCode.OK && user == null)
                {
                    code = HttpStatusCode.ServiceUnavailable;
                }
                switch (code)
                {
                case HttpStatusCode.OK:
                    MessageBox.Show(String.Format("successfully connected to account {0}; data sync will start automatically.", email));
                    accountOperationSuccessful = true;
                    user.Synced = true;
                    // the server no longer echos the password in the payload so keep the local value when successful
                    if (user.Password == null)
                    {
                        user.Password = pswd;
                    }
                    App.ViewModel.User = user;
                    // prepare the user queue and remove the system queue (the $ClientSettings will be lost because the server is authoritative)
                    RequestQueue.PrepareUserQueueForAccountConnect();
                    RequestQueue.DeleteQueue(RequestQueue.SystemQueue);
                    App.ViewModel.SyncWithService();
                    break;

                case HttpStatusCode.NotFound:
                    MessageBox.Show(String.Format("user {0} not found", email));
                    accountOperationSuccessful = false;
                    break;

                case HttpStatusCode.Forbidden:
                    MessageBox.Show(String.Format("incorrect password"));
                    accountOperationSuccessful = false;
                    break;

                case null:
                    MessageBox.Show(String.Format("couldn't reach the server"));
                    accountOperationSuccessful = false;
                    break;

                default:
                    MessageBox.Show(String.Format("did not successfully connect to account {0}", email));
                    accountOperationSuccessful = false;
                    break;
                }

                // update UI if successful
                if (accountOperationSuccessful)
                {
                    dvc.NavigationController.PopViewControllerAnimated(true);
                    CreateRoot();
                    dvc.ReloadData();
                }
                ResignFirstResponder();
            });
        }