Exemple #1
0
        public static bool IsLoggedIn()
        {
            if (!SPUtility.IsConnected())
            {
                GetLoggedInToken();

                MasterInfo userInfo = App.DAUtil.GetMasterInfoByName(App.USER_INFO_KEY);
                if (userInfo != null)
                {
                    var spData = JsonConvert.DeserializeObject <UserInfo>(userInfo.content, new JsonSerializerSettings {
                        DateParseHandling = DateParseHandling.None
                    });
                    if (spData != null)
                    {
                        App.CurrentUser = new Model.User {
                            Name = spData.GivenName + " " + spData.FamilyName, Email = spData.DisplayableId
                        }
                    }
                    ;
                }
            }

            if (App.GraphAuthentication == null)
            {
                return(false);
            }

            //For offline fuctionality
            if (App.GraphAuthentication != null && !SPUtility.IsConnected())
            {
                return(true);
            }

            return(SPUtility.IsConnected() && App.GraphAuthentication.ExpiresOn > DateTime.UtcNow);
        }
Exemple #2
0
        public static async Task<string[]> GetAirCraftRegistrations()
        {
            MasterInfo mInfo = null;
            if (!SPUtility.IsConnected())
            {
                mInfo = App.DAUtil.GetMasterInfoByName("AircraftRegistrations");
            }
            else
            {
                try
                {
                    var client = await OAuthHelper.GetHTTPClientAsync();
                    var url = GetListURL(ReportType.AircraftRegistration);
                    var response = await client.GetStringAsync(url);
                    if (response != null)
                    {
                        mInfo = new MasterInfo { Name = "AircraftRegistrations", content = response };
                        App.DAUtil.RefreshMasterInfo(mInfo);
                    }
                }
                catch (Exception ex)
                {
                    mInfo = App.DAUtil.GetMasterInfoByName("AircraftRegistrations");
                }
            }

            if (mInfo != null)
            {
                var stations = JsonConvert.DeserializeObject<SPData>(mInfo.content);
                return stations.d.results.Select(x => x.Aircraft_x0020_Registration).ToArray();
            }

            return null;
        }
Exemple #3
0
        public static async Task<List<PeoplePicker>> GetUsersForPicker()
        {
            if (!SPUtility.IsConnected())
            {
                return GetUsers();
            }

            var client = await OAuthHelper.GetHTTPClientAsync();

            try
            {
                var response = await client.GetStringAsync(ClientConfiguration.Default.SPRootURL + "web/siteusers?");
                if (response != null)
                {
                    App.DAUtil.RefreshMasterInfo(new MasterInfo { Name = "Users", content = response });
                    return ResponseToUsers(response);

                }
            }
            catch (Exception ex)
            {
                return GetUsers();
            }

            return null;
        }
Exemple #4
0
        private async Task DataBind()
        {
            if (!SPUtility.IsConnected())
            {
                return;
            }

            Items.Clear();

            IsBusy = true;
            var data = await GetTasks();

            IsBusy = false;
            if (data != null)
            {
                foreach (var item in data)
                {
                    Items.Add(item);
                }

                ToggleVisibility();
            }
            else
            {
            }
        }
Exemple #5
0
        public App()
        {
            InitializeComponent();
            attachments.CollectionChanged += Attachments_CollectionChanged;

            try
            {
                var eValue = DAUtil.GetAll <OfflineItem>("OfflineItem");
                if (eValue != null && eValue.Count > 0)
                {
                    App.offlineItems = new ObservableCollection <OfflineItem>(eValue);
                }

                MessagingCenter.Subscribe <object>(this, EVENT_LAUNCH_MAIN_PAGE, SetMainPageAsRootPage);
                MessagingCenter.Subscribe <object>(this, EVENT_LAUNCH_MULTIFACTOR_PAGE, SetMultiFactorAuthenticationPage);

                if (SPUtility.IsConnected())
                {
                    MainPage = new MultiFactorLogin();
                }
                else
                {
                    var graphResponse = App.DAUtil.GetMasterInfoByName(GRAPH_AUTH_RESULT_KEY);
                    var spResponse    = App.DAUtil.GetMasterInfoByName(SHAREPOINT_AUTH_RESULT_KEY);
                    if (graphResponse == null || spResponse == null)
                    {
                        MainPage = new MultiFactorLogin();
                    }
                    else
                    {
                        OAuthHelper.GetLoggedInToken();

                        var uInfo = App.DAUtil.GetMasterInfoByName(USER_INFO_KEY);
                        if (uInfo != null)
                        {
                            var obj = JsonConvert.DeserializeObject <UserInfo>(uInfo.content, new JsonSerializerSettings {
                                DateParseHandling = DateParseHandling.None
                            });
                            if (obj != null)
                            {
                                App.CurrentUser = new User
                                {
                                    Id    = obj.UniqueId,
                                    Name  = obj.GivenName + " " + obj.FamilyName,
                                    Email = obj.DisplayableId
                                };
                            }
                        }

                        MainPage = new StartPage();
                    }
                }
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }
        }
        private async Task <bool> DataBind(string fPath)
        {
            if (!SPUtility.IsConnected())
            {
                return(false);
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                IsBusy = true;
            });

            List <DataContracts.Result> dataSource = new List <Result>();
            var folders = await GetDocuments(fPath, false);

            if (folders != null)
            {
                foreach (var item in folders)
                {
                    item.Icon = "folder.png";
                    if (!string.IsNullOrEmpty(fPath) || (item.Name == "Safety Security Critical Information" || item.Name == "NCT Controlled Manuals Library"))
                    {
                        dataSource.Add(item);
                    }
                }
            }

            if (!string.IsNullOrEmpty(fPath))
            {
                //Retrive files
                var files = await GetDocuments(fPath, true);

                if (files != null)
                {
                    foreach (var item in files)
                    {
                        item.Icon = "file.png";
                    }
                    dataSource.AddRange(files);
                }
            }

            documentList.ItemsSource = dataSource;
            tBarItemBackBtn.Text     = fPath != RootFolder ? "Back" : "";
            Device.BeginInvokeOnMainThread(() =>
            {
                FolderPath = fPath;

                string[] ps = fPath.Split('/');
                Title       = ps[ps.Length - 1];

                IsBusy = false;
            });

            return(true);
        }
Exemple #7
0
        public static async Task<List<OperatingPlan>> GetOperatingPlans()
        {
            MasterInfo mInfo = null;
            if (!SPUtility.IsConnected())
            {
                mInfo = App.DAUtil.GetMasterInfoByName("OperatingPlans");
            }
            else
            {
                try
                {
                    var client = await OAuthHelper.GetHTTPClientAsync();
                    var response = await client.GetStringAsync(GetListURL(ReportType.OperationPlan));
                    if (response != null)
                    {
                        mInfo = new MasterInfo { Name = "OperatingPlans", content = response };
                        App.DAUtil.RefreshMasterInfo(mInfo);
                    }
                }
                catch (Exception)
                {
                    mInfo = App.DAUtil.GetMasterInfoByName("OperatingPlans");
                }
            }

            if (mInfo != null)
            {
                var stations = await GetStations();

                try
                {
                    var oPlans = JsonConvert.DeserializeObject<SPData>(mInfo.content, new JsonSerializerSettings
                    {
                        DateParseHandling = DateParseHandling.None,
                        NullValueHandling = NullValueHandling.Ignore,
                        MissingMemberHandling = MissingMemberHandling.Ignore
                    });
                    return oPlans.d.results.Select(x => new OperatingPlan
                    {
                        FlighNumber = x.Flight_x0020_Number,
                        ArrivalStationId = Convert.ToString(x.Arrival_x0020_StationId),
                        DepartureStationId = Convert.ToString(x.Departure_x0020_StationId),

                        ArrivalStation = stations[Convert.ToString(x.Arrival_x0020_StationId)],
                        DepartureStation = stations[Convert.ToString(x.Departure_x0020_StationId)]
                    }).ToList();
                }
                catch (Exception ex)
                {

                }
            }

            return null;
        }
 protected override async void OnAppearing()
 {
     if (SPUtility.IsConnected())
     {
         lblLoading.Text    = "Authenticating...";
         btnLogin.IsVisible = false;
         await PerformLoginAsync();
     }
     else
     {
         IsBusy             = false;
         btnLogin.IsVisible = true;
         lblLoading.Text    = "Network not connected to internet.";
     }
 }
Exemple #9
0
        public static async Task <Model.User> GetUserInfo()
        {
            var uInfo = App.DAUtil.GetMasterInfoByName("UserInfo");

            if (uInfo != null)
            {
                var obj = JsonConvert.DeserializeObject <UserInfo>(uInfo.content, new JsonSerializerSettings {
                    DateParseHandling = DateParseHandling.None
                });
                if (obj != null)
                {
                    App.CurrentUser = new Model.User
                    {
                        Id    = obj.UniqueId,
                        Name  = obj.GivenName + " " + obj.FamilyName,
                        Email = obj.DisplayableId,
                    };
                }
            }

            if (!SPUtility.IsConnected())
            {
                return(null);
            }

            try
            {
                var userInfo = App.GraphAuthentication?.UserInfo;
                App.DAUtil.RefreshMasterInfo(new MasterInfo {
                    Name = App.USER_INFO_KEY, content = JsonConvert.SerializeObject(userInfo)
                });
                if (App.GraphAuthentication?.UserInfo != null)
                {
                    App.CurrentUser = new Model.User
                    {
                        Id           = userInfo.UniqueId,
                        Name         = userInfo.GivenName + " " + userInfo.FamilyName,
                        Email        = userInfo.DisplayableId,
                        PictureBytes = await GetPicture()
                    };
                }
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
        protected async void BindMORPicker()
        {
            if (!SPUtility.IsConnected())
            {
                BindMORSavedInfo();
                return;
            }

            var client = await OAuthHelper.GetHTTPClientAsync();

            if (client == null)
            {
                return;
            }
            try
            {
                string url    = SPUtility.GetListURL(ReportType.MORType);
                var    result = await client.GetStringAsync(url);

                if (result != null)
                {
                    App.DAUtil.RefreshMasterInfo(new MasterInfo {
                        content = result, Name = "MORItems"
                    });
                    var spData = JsonConvert.DeserializeObject <SPData>(result, new JsonSerializerSettings {
                        DateParseHandling = DateParseHandling.None
                    });

                    foreach (var val in spData.d.results)
                    {
                        MORpicker.Items.Add(val.Title);
                    }

                    SetMORPickerValue();
                }
            }
            catch (Exception ex)
            {
                BindMORSavedInfo();
                var msg = "Unable to fetch MOR items: " + ex.Message;
                await DisplayAlert("Error", msg, "Ok");
            }
        }
Exemple #11
0
        private async void iataPicker_Changed(object sender, EventArgs e)
        {
            ToggleBusy(true);

            var SelectedValue = iataPicker.Items.ElementAt(iataPicker.SelectedIndex);

            if (!SPUtility.IsConnected())
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    DependencyService.Get <IMessage>().ShortAlert("No active internet connection was found!");
                });

                ToggleBusy(false);
                return;
            }

            await BindStationInfoByIATA(SelectedValue);

            ToggleBusy(false);
        }
Exemple #12
0
        public static async Task<Dictionary<string, string>> GetStations(bool isOpen = false)
        {
            MasterInfo mInfo = null;
            if (!SPUtility.IsConnected())
            {
                mInfo = App.DAUtil.GetMasterInfoByName("Stations");
            }
            else
            {
                try
                {
                    var client = await OAuthHelper.GetHTTPClientAsync();
                    string url = GetListURL(ReportType.SationInfo);
                    if (isOpen)
                    {
                        url += "?$filter=Status eq 'Open'";
                    }

                    var response = await client.GetStringAsync(url);
                    if (response != null)
                    {
                        mInfo = new MasterInfo { Name = "Stations", content = response };
                        App.DAUtil.RefreshMasterInfo(mInfo);
                    }
                }
                catch (Exception)
                {
                    mInfo = App.DAUtil.GetMasterInfoByName("Stations");
                }
            }

            if (mInfo != null)
            {
                var stations = JsonConvert.DeserializeObject<SPData>(mInfo.content);
                return stations.d.results.Select(x => new { Key = x.Id.ToString(), Value = x.IATA_x0020_Code }).ToDictionary(v => v.Key, v => v.Value);
            }

            return null;
        }
Exemple #13
0
        public Login()
        {
            InitializeComponent();

            Username.Keyboard = Keyboard.Create(KeyboardFlags.None);
            Password.Keyboard = Keyboard.Create(KeyboardFlags.None);

            BindingContext = this;
            IsBusy         = true;
            var userCredentials = App.DAUtil.GetMasterInfoByName("UserCredentials");

            if (SPUtility.IsConnected() && userCredentials != null)
            {
                var    cred  = JsonConvert.DeserializeObject <dynamic>(userCredentials.content);
                string uName = cred.Username;
                string pwd   = cred.Password;

                Username.Text = uName;
                Password.Text = pwd;

                // Login_OnClicked(btnLogin, null);
            }
        }
 private bool CheckConnection()
 {
     return(SPUtility.IsConnected());
 }