Пример #1
0
        protected override void OnCreate(Bundle bundle)
        {
            OMGITServiceClient _client;
            EndpointAddress    EndPoint = new EndpointAddress("https://webapps.oregonmed.net/OMGITWebservices/OMGMobileServices.svc");
            BasicHttpBinding   binding  = CreateBasicHttp();

            _client = new OMGITServiceClient(binding, EndPoint);
            _client.AddLogMessageTickerAppAsync("Reached OnCreate", string.Empty);
            base.OnCreate(bundle);

            /*
             *                 //To Do - acknowledge the message with a web service call to
             *  BasicHttpBinding binding = new BasicHttpBinding
             *  {
             *      Name = "basicHttpBinding",
             *      MaxBufferSize = 2147483647,
             *      MaxReceivedMessageSize = 2147483647
             *  };
             *  TimeSpan timeout = new TimeSpan(0, 0, 30);
             *  binding.SendTimeout = timeout;
             *  binding.OpenTimeout = timeout;
             *  binding.ReceiveTimeout = timeout;
             */


            global::Xamarin.Forms.Forms.Init(this, bundle);

            string confirmToken = this.Intent.GetStringExtra("confirmToken");
            string alertMessage = this.Intent.GetStringExtra("alertMessage");

            if (confirmToken != null && alertMessage != null)
            {
                LoadApplication(new App(alertMessage));
                _client.AcknowledgeNotificationAsync(confirmToken, GlobalData.loginData);
            }
            else
            {
                LoadApplication(new App());
            }

            try
            {
                // Check to ensure everything's setup right
                GcmClient.CheckDevice(this);
                GcmClient.CheckManifest(this);

                // Register for push notifications
                System.Diagnostics.Debug.WriteLine("Registering...");
                GcmClient.Register(this, PushHandlerBroadcastReceiver.SENDER_IDS);
            }
            catch (Java.Net.MalformedURLException)
            {
                CreateAndShowDialog("There was an error creating the Mobile Service. Verify the URL", "Error");
            }
            catch (Exception e)
            {
                CreateAndShowDialog(e.Message, "Error");
            }
        }
Пример #2
0
        private async void Submit_Clicked(object sender, EventArgs e)
        {
            submit.IsEnabled = false;

            if (Application.Current.Properties.ContainsKey("DeviceToken"))
            {
                string DeviceToken = Application.Current.Properties["DeviceToken"] as string;
            }

            try
            {
                _client = new OMGITServiceClient(binding, EndPoint);
                _client.AddLogMessageTickerAppAsync("Reached Submit_Clicked", "test");

                var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

                if (status == PermissionStatus.Granted)
                {
                    var locator = CrossGeolocator.Current;
                    locator.DesiredAccuracy = 50;

                    var position = await locator.GetPositionAsync(timeoutMilliseconds : 10000);

                    latitude  = position.Latitude.ToString();
                    longitude = position.Longitude.ToString();
                    altitude  = position.Altitude.ToString();

                    Debug.WriteLine("Position Status: {0}", position.Timestamp);
                    Debug.WriteLine("Position Latitude: {0}", position.Latitude);
                    Debug.WriteLine("Position Longitude: {0}", position.Longitude);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to get location, may need to increase timeout: " + ex);
            }

            OMGITWebServices.OMGLoginData loginData = new OMGITWebServices.OMGLoginData();
            loginData.UserName = usernameEntry.Text.Trim().ToLower();
            loginData.Password = passwordEntry.Text;
            string alertMessage = alert.Text;

            loginData.OMGAppID  = Constants.AppName;
            loginData.Altitude  = altitude;
            loginData.Latitude  = latitude;
            loginData.Longitude = longitude;
            if (Device.OS == TargetPlatform.iOS)
            {
                loginData.MobilePlatform = "iOS";
            }
            else if (Device.OS == TargetPlatform.Android)
            {
                loginData.MobilePlatform = "Android";
            }
            else
            {
                loginData.MobilePlatform = "Unknown Platform";
            }
            loginData.PhoneIdentifier = DependencyService.Get <IGetDeviceInfo>().GetDeviceInfo();


            if (keepLoggedInSwitch.IsToggled)
            {
                loginData.CreateAuthToken = true;
            }

            GlobalData.SetLoginData(loginData);

            await Task.Run(() =>
            {
                _client = new OMGITServiceClient(binding, EndPoint);
                _client.LoginAsync(loginData);
                _client.LoginCompleted += ClientOnLoginCompleted;
            });


            try
            {
                while (returnMessage.ErrorMessage == null)
                {
                    continue;
                }

                if (returnMessage.Success)
                {
                    if (keepLoggedInSwitch.IsToggled)
                    {
                        var data  = loginData.UserName;
                        var salt  = Crypto.CreateSalt(16);
                        var bytes = Crypto.EncryptAes(returnMessage.AuthToken, data, salt);

                        Application.Current.Properties["LastLoggedInUser"]           = loginData.UserName;
                        Application.Current.Properties[loginData.UserName + "Token"] = bytes;
                        Application.Current.Properties[loginData.UserName + "Salt"]  = salt;
                        await Application.Current.SavePropertiesAsync();
                    }
                    OMGITWebServices.OMGInstallationData installData = new OMGITWebServices.OMGInstallationData();
                    if (Application.Current.Properties.ContainsKey("DeviceToken"))
                    {
                        installData.DeviceToken = Application.Current.Properties["DeviceToken"] as string;
                    }

                    installData.Username        = loginData.UserName;
                    installData.OperatingSystem = loginData.MobilePlatform;

                    await Task.Run(() =>
                    {
                        _client = new OMGITServiceClient(binding, EndPoint);
                        _client.RegisterForNotificationsAsync(installData);
                        _client.RegisterForNotificationsCompleted += ClientOnRegisterCompleted;
                    });

                    if (loginData.UserName == "hfowler" || loginData.UserName == "dfowler" || loginData.UserName == "sliu" || loginData.UserName == "khellwege")
                    {
                        if (alertMessage != "")
                        {
                            await Navigation.PushModalAsync(new AdminMainPage(alertMessage));
                        }
                        else
                        {
                            await Navigation.PushModalAsync(new AdminMainPage());
                        }
                    }
                    else
                    {
                        if (alertMessage != "")
                        {
                            await Navigation.PushModalAsync(new TickerDisplayPage(alertMessage));
                        }
                        else
                        {
                            await Navigation.PushModalAsync(new TickerDisplayPage());
                        }
                    }
                }
                else
                {
                    if (incorrectPasswords == 0)
                    {
                        Label errorMessage = new Label {
                            Text = returnMessage.ErrorMessage, TextColor = Color.Red, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, BackgroundColor = Color.White
                        };
                        loginForm.Children.Add(errorMessage);
                    }
                    returnMessage.ErrorMessage = null;
                    incorrectPasswords        += 1;
                    submit.IsEnabled           = true;
                }
            }

            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
Пример #3
0
        public App(string alertMessage)
        {
            OMGITServiceClient _client;
            EndpointAddress    EndPoint = new EndpointAddress("https://webapps.oregonmed.net/OMGITWebservices/OMGMobileServices.svc");
            BasicHttpBinding   binding  = CreateBasicHttp();

            _client = new OMGITServiceClient(binding, EndPoint);
            _client.AddLogMessageTickerAppAsync("Reached App tickerPage overload", "Contains Last Log in: " + Application.Current.Properties.ContainsKey("LastLoggedInUser").ToString());
            byte[] token     = null;
            byte[] salt      = null;
            string username  = string.Empty;
            string authToken = string.Empty;

            OMGITWebServices.OMGAuthTokenData atd = new OMGITWebServices.OMGAuthTokenData();

            if (Application.Current.Properties.ContainsKey("LastLoggedInUser"))
            {
                username     = Application.Current.Properties["LastLoggedInUser"] as string;
                atd.UserName = username;
                _client.AddLogMessageTickerAppAsync("Last Logged In User:"******"Token"))
                {
                    token = Application.Current.Properties[username + "Token"] as byte[];
                }

                //Check to make sure a salt exists for the last logged in user
                if (Application.Current.Properties.ContainsKey(username + "Salt"))
                {
                    salt = Application.Current.Properties[username + "Salt"] as byte[];
                }

                //If both the token and salt exist decrypt the token
                if (token != null && salt != null)
                {
                    authToken     = Crypto.DecryptAes(token, username, salt);
                    atd.AuthToken = authToken;
                }
            }

            atd.MobilePlatform  = Device.OS.ToString();
            atd.OMGAppID        = Constants.AppName;
            atd.PhoneIdentifier = DependencyService.Get <IGetDeviceInfo>().GetDeviceInfo();
            _client.ValidateAuthenticationTokenAsync(atd);
            _client.ValidateAuthenticationTokenCompleted += completedValidation;

            while (orm.ErrorMessage == "None" || orm.ErrorMessage == null)
            {
                continue;
            }
            //If the token is a valid non-expired token open the TickerDisplayPage page if not open the Login page

            if (orm.Success)
            {
                if (username == "hfowler" || username == "dfowler" || username == "sliu" || username == "khellwege")
                {
                    MainPage = new NavigationPage(new AdminMainPage(alertMessage));
                }
                else
                {
                    MainPage = new NavigationPage(new TickerDisplayPage(alertMessage));
                }
            }
            else
            {
                // The root page of your application
                MainPage = new NavigationPage(new LoginPage(alertMessage));
            }
        }