/*
         * Application does not have GSM or WLAN network.
         * Show message about that and disable notification sending
         * Request to authenticate
         * */
        private void ShowNoNetwork()
        {
            InformationNote.ShowMessage("No network. Enable network and try again");

            // Request new authentication
            MainPageModel.Authenticated = false;

            // Disable notification
            SetNotificationEnabled(false);
            UiStateToStopped(true);
        }
        /*
         * HTTPS request done. Handle response
         * */
        private void RequestDoneEvent(RequestState requestState)
        {
            Dispatcher.BeginInvoke(() =>
            {
                switch (requestState.HttpEngineState)
                {
                case HttpEngineState.EAuthenticate:
                    {
                        if (requestState.RequestPassed)
                        {
                            // Authenticated first time
                            if (!MainPageModel.Authenticated)
                            {
                                if (_startSeekingDelayTimer == null || !_startSeekingDelayTimer.IsEnabled)
                                {
                                    InformationNote.ShowMessage("Connected");
                                }
                            }
                            MainPageModel.Authenticated = true;
                        }
                        break;
                    }

                case HttpEngineState.ESendNotification:
                    {
                        if (requestState.RequestPassed)
                        {
                            InformationNote.ShowMessage("Alert sent");
                        }
                        else
                        {
                            InformationNote.ShowMessage("Sending alert failed!");
                        }
                        break;
                    }

                default:
                    {
                        break;
                    }
                }

                // General error
                if (!requestState.RequestPassed)
                {
                    ShowNoNetwork();
                }
            });
        }
        /*
         * Ovi account id reveiced from popup
         * */
        private void OviUsernameReceivedEvent(string username, bool save)
        {
            this.ApplicationBar.IsVisible = true;

            _screensaverControl.StartScreenSaverTimer();

            MainPageModel.OviAccountId = username;

            // Account was no given
            if (MainPageModel.OviAccountId.Length < 1)
            {
                MainPageModel.Authenticated = false;
                // Disable notification
                SetNotificationEnabled(false);
                UiStateToStopped(true);
                // Store username into isolated storage if wanted
                StoreUsername(MainPageModel.OviAccountId, save);
                InformationNote.ShowMessage("No Nokia Account ID given. Cannot send notifications.");
                return;
            }

            // Add "@ovi.com" at the end of account
            if (username.Contains("@"))
            {
                MainPageModel.OviAccountId = username.Remove(username.IndexOf("@"));
                MainPageModel.OviAccountId = MainPageModel.OviAccountId + "@ovi.com";
            }
            else
            {
                MainPageModel.OviAccountId = MainPageModel.OviAccountId + "@ovi.com";
            }

            // Store username into isolated storage if wanted
            StoreUsername(MainPageModel.OviAccountId, save);

            // Login into Notification Service if network exists
            if (isNetwork())
            {
                // Make HTTPS digest authentication into service
                if (!MainPageModel.Authenticated)
                {
                    AuthenticateByPing();
                }
            }
            else
            {
                ShowNoNetwork();
            }
        }
        /*
         * Countdown from 3 to 0 before starting monitoring
         * */
        private void SeekingDelayTimer_Tick(object sender, EventArgs e)
        {
            _startSeekingIndex--;

            string message = String.Format("Monitoring starts in {0}...", _startSeekingIndex);

            InformationNote.UpdateMessageText(message);

            if (_startSeekingIndex <= 0)
            {
                _startSeekingDelayTimer.Stop();

                InformationNote.HideMessage();
                SetNotificationEnabled(true);

                InformationNote.ShowMessage("Monitoring");
            }
        }
        /*
         * Leave xaml page
         * */
        override protected void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            _screensaverControl.StopScreenSaverTimer();

            // Disable notification
            SetNotificationEnabled(false);
            UiStateToStopped(true);

            // If this is a back navigation, the page will be discarded, so there
            // is no need to save state.
            if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back)
            {
                StorePageState();
            }

            // Stop monitoring countdown timer
            if (_startSeekingDelayTimer != null)
            {
                _startSeekingDelayTimer.Stop();
            }
            InformationNote.HideMessage();

            // Disable camera
            EnableCamera(false);

            // Stop radio playing loop
            if (_radioTimer != null)
            {
                _radioTimer.Stop();
            }
            _radioTimer = null;

            // Free events handling
            CameraViewfinder.AlertEvent      -= new CameraViewfinder.Alert(CameraViewfinder_AlertEvent);
            _notifServerApi.RequestDoneEvent -= new NotifServerApi.RequestDoneDelegate(RequestDoneEvent);

            base.OnNavigatingFrom(e);
        }
示例#6
0
    public override void OnInspectorGUI()
    {
        InformationNote inMyScript = (InformationNote)target;

        if (!inMyScript.isReady)
        {
            // User adding Input text in the inspector

            switch (selectedValue)
            {
            case 0:
                if (EditorGUILayout.Toggle(inMyScript.isReady))
                {
                    inMyScript.SwitchToggle();                                                                                    // Toggle
                }
                {
                    EditorGUILayout.LabelField("");                                         // A space
                    EditorGUILayout.LabelField(inMyScript.TextInfo);                        // A small line text
                    EditorGUILayout.LabelField("");                                         // A space
                }
                break;

            case 1:
                if (GUILayout.Button(buttonText))
                {
                    inMyScript.SwitchToggle();                                      //
                }
                {
                    buttonText = "INFO";
                    EditorGUILayout.LabelField("");                                         // A space
                    EditorGUILayout.HelpBox(inMyScript.TextInfo, MessageType.None);         // This is a small box
                    EditorGUILayout.LabelField("");                                         // A space
                }
                break;

            case 2:
                goto default;    // same as default

            case 3:
                if (GUILayout.Button(buttonText))
                {
                    inMyScript.SwitchToggle();
                }
                {
                    buttonText = "ALERT";
                    EditorGUILayout.LabelField("");                                         // A space
                    EditorGUILayout.HelpBox(inMyScript.TextInfo, MessageType.Warning);      // This is a Warning box
                    EditorGUILayout.LabelField("");                                         // A space
                }
                break;

            case 4:
                if (GUILayout.Button(buttonText))
                {
                    inMyScript.SwitchToggle();                                       //
                }
                {
                    buttonText = "ERROR";
                    EditorGUILayout.LabelField("");                                         // A space
                    EditorGUILayout.HelpBox(inMyScript.TextInfo, MessageType.Error);        // This is a Error box
                    EditorGUILayout.LabelField("");                                         // A space
                }
                break;

            default:
                if (GUILayout.Button(buttonText))
                {
                    inMyScript.SwitchToggle();                                              // Button
                }
                {
                    buttonText = "README";
                    EditorGUILayout.LabelField("");                                         // A space
                    EditorGUILayout.HelpBox(inMyScript.TextInfo, MessageType.Info);         // This is a help box
                    EditorGUILayout.LabelField("");                                         // A space
                }
                break;
            }
        }
        else
        {
            // Visualisation of final text in the inspector.

            buttonText = "LOCK";

            // Display [ LOCK ] Button and switch if is press
            if (GUILayout.Button(buttonText))
            {
                inMyScript.SwitchToggle();
            }


            // [ Input text ]
            inMyScript.TextInfo = EditorGUILayout.TextArea(inMyScript.TextInfo);


            // selection
            selectedValue = EditorGUILayout.IntPopup("Text Type :", selectedValue, displayOptions, finalDisplayOption);

            // warning
            EditorGUILayout.HelpBox(" Press LOCK at the top when finish. ", MessageType.Warning); // A Warning box
        }
    }
 /*
  * Make HTTPS digest authentication into Notifications service
  * */
 private void AuthenticateByPing()
 {
     InformationNote.ShowStaticMessage("Connecting...");
     _notifServerApi.RequestPing(App.ServiceId, App.ServiceSecret, NotifServerApi.PING_URI);
 }