private async void Login_Click(object sender, RoutedEventArgs e)
        {
            if (AuthKey.Text == "")
            {
                MessageDialog msg = new MessageDialog("Please Enter the Authorization Token");
                await msg.ShowAsync();

                return;
            }
            LoginStack.Visibility  = Visibility.Collapsed;
            LoadingGrid.Visibility = Visibility.Visible;
            status = await DataManager.LoginAsync(AuthKey.Text);

            if (status == DataManager.StatusCode.Success)
            {
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                localSettings.Values["authToken"] = AuthKey.Text;

                this.Frame.Navigate(typeof(Home));
            }
            else
            {
                LoadingGrid.Visibility = Visibility.Collapsed;
                LoginStack.Visibility  = Visibility.Visible;
                MessageDialog dialog = new MessageDialog(DataManager.proj.name);
                await dialog.ShowAsync();
            }
        }
        public async void refresh()
        {
            DataManager.StatusCode status = await DataManager.RefreshAsync();

            if (!(await BlynkLibrary.NetworkService.BlynkService.IsInternet()))
            {
                StatusText.Text = "Offline";
            }
            else if (status != DataManager.StatusCode.Success)
            {
                StatusText.Text = "Offline";
            }
            else
            {
                StatusText.Text = "Online";
            }
            currentDevice = DataManager.navDevice;
            pinData       = DataManager.proj.pinsStorage;
            string id = currentDevice.id.ToString();
            IEnumerable <KeyValuePair <string, string> > k = pinData.Where(a => a.Key.Contains(id + "-"));

            pinsStorage = k.ToList();
            start();
        }
Beispiel #3
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected async override void OnLaunched(LaunchActivatedEventArgs e)
        {
            //IPropertySet roamingProperties = Application.Current.RoamingSettings.Values();
            RoamingObjectStorageHelper roamingProperties = new RoamingObjectStorageHelper();
            //IPropertySet roamingProperties = Windows.Storage.ApplicationData.Current.RoamingSettings.Values;
            Frame rootFrame = Window.Current.Content as Frame;

            Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;
            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            var k = roamingProperties.KeyExists("HasBeenHereBefore");

            if (roamingProperties.KeyExists("HasBeenHereBefore"))
            {
                try
                {
                    var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                    authToken = localSettings.Values["authToken"].ToString();
                }
                catch
                {
                    if (e.PrelaunchActivated == false)
                    {
                        if (rootFrame.Content == null)
                        {
                            // When the navigation stack isn't restored navigate to the first page,
                            // configuring the new page by passing required information as a navigation
                            // parameter
                            rootFrame.Navigate(typeof(MainPage), e.Arguments);
                        }
                        // Ensure the current window is active
                        Window.Current.Activate();
                    }
                }

                if (e.PrelaunchActivated == false)
                {
                    if (rootFrame.Content == null)
                    {
                        // When the navigation stack isn't restored navigate to the first page,
                        // configuring the new page by passing required information as a navigation
                        // parameter
                        DataManager.StatusCode res = await DataManager.LoginAsync(authToken);

                        if (res == DataManager.StatusCode.NoInternet)
                        {
                        }
                        if (res == DataManager.StatusCode.Success)
                        {
                            rootFrame.Navigate(typeof(Home), e.Arguments);
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(MainPage), e.Arguments);
                            MessageDialog dialog = new MessageDialog("No Pre-stored data found, please connect to the internet");
                            await dialog.ShowAsync();
                        }
                    }
                    // Ensure the current window is active
                    Window.Current.Activate();
                }
            }
            else
            {
                // The First Time App Starts Case
                //roamingProperties["HasBeenHereBefore"] = bool.TrueString;
                roamingProperties.Save("HasBeenHereBefore", true);
                rootFrame.Navigate(typeof(Welcome), e.Arguments);
                Window.Current.Activate();
            }
        }