Beispiel #1
0
        public bool GetRecordList(ViewModel.UserAccountView UserAccountView, ViewModel.Presenter Presenter)
        {
            FhirApi          FhirApi          = new FhirApi(FhirGatewayEndpoint);
            ApiRequestHeader ApiRequestHeader = new ApiRequestHeader(UserAccountView.AccessToken, this.ApplicationStore.App_id, this.ApplicationStore.App_Version);

            FhirApi.ApiRequestHeader = ApiRequestHeader;

            RecordListResponse RecordListResponse = FhirApi.GetRecordList();

            if (RecordListResponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                if (RecordListResponse.Format == FhirApi.FhirFormat.Xml)
                {
                    Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.Xml;
                }
                else if (RecordListResponse.Format == FhirApi.FhirFormat.Json)
                {
                    Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.Json;
                }
                else
                {
                    Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.None;
                }
                Presenter.TextEditorViewModel.Text = RecordListResponse.Body;
                Presenter.CurrentUserAccount.UserAccountRecordList = new System.Collections.ObjectModel.ObservableCollection <ViewModel.UserAccountRecord>();
                foreach (var Person in RecordListResponse.ApiRelatedPersonList)
                {
                    var RecordItem = new ViewModel.UserAccountRecord();
                    RecordItem.Family = Person.Family;
                    RecordItem.Given  = Person.Given;
                    RecordItem.Ihi    = Person.Ihi;
                    RecordItem.RelationshipTypeDescription = Person.RelationshipDescription;
                    Presenter.CurrentUserAccount.UserAccountRecordList.Add(RecordItem);
                }
                if (Presenter.CurrentUserAccount != null && Presenter.CurrentUserAccount.UserAccountRecordList != null && Presenter.CurrentUserAccount.UserAccountRecordList.Count > 0)
                {
                    Presenter.CurrentUserAccount.SelectedUserAccountRecord = Presenter.CurrentUserAccount.UserAccountRecordList[0];
                }
                return(true);
            }
            else
            {
                if (RecordListResponse.ErrorResponse != null)
                {
                    Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.None;
                    Presenter.TextEditorViewModel.Text       = RecordListResponse.ErrorResponse.Description;
                    return(false);
                }
                else
                {
                    Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.None;
                    Presenter.TextEditorViewModel.Text       = $"Unknown Error, Status code {RecordListResponse.StatusCode.ToString()}";
                    return(false);
                }
            }
        }
Beispiel #2
0
 public void SetCurrentUserAcccount(ViewModel.UserAccountView UserAccountView)
 {
     this.CurrectUserAccount = new UserAccount();
     this.CurrectUserAccount.AccessExpires     = UserAccountView.AccessExpires;
     this.CurrectUserAccount.AccessToken       = UserAccountView.AccessToken;
     this.CurrectUserAccount.AuthorisationCode = UserAccountView.AuthorisationCode;
     this.CurrectUserAccount.RefreshExpires    = UserAccountView.RefreshExpires;
     this.CurrectUserAccount.RefreshToken      = UserAccountView.RefreshToken;
     this.CurrectUserAccount.Scope             = UserAccountView.Scope;
     this.CurrectUserAccount.Username          = UserAccountView.Username;
 }
Beispiel #3
0
        public bool GetRefeashToken(ViewModel.UserAccountView ViewCurrentUserAccount)
        {
            //If the Access token expires in 1 hour get a new one.
            if (ViewCurrentUserAccount.AccessExpires < DateTime.Now.AddHours(1))
            {
                if (!string.IsNullOrWhiteSpace(ViewCurrentUserAccount.RefreshToken))
                {
                    FhirApi FhirApi             = new FhirApi(FhirGatewayEndpoint);
                    var     RefreshTokenRequest = new RefreshTokenRequest();
                    RefreshTokenRequest.Client_id     = ApplicationStore.App_id;
                    RefreshTokenRequest.Client_secret = ApplicationStore.App_secret;
                    RefreshTokenRequest.RefreshToken  = ViewCurrentUserAccount.RefreshToken;

                    TokenResponse TokenResponse = FhirApi.GetRefreshToken(RefreshTokenRequest);
                    if (TokenResponse.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        ViewCurrentUserAccount.AccessExpires  = TokenResponse.AccessExpires;
                        ViewCurrentUserAccount.AccessToken    = TokenResponse.AccessToken;
                        ViewCurrentUserAccount.RefreshExpires = TokenResponse.RefreshExpires;
                        ViewCurrentUserAccount.RefreshToken   = TokenResponse.RefreshToken;
                        ViewCurrentUserAccount.Scope          = TokenResponse.Scope;
                        if (ApplicationStore.UserList.SingleOrDefault(x => x.Username == ViewCurrentUserAccount.Username) != null)
                        {
                            var TargetAccount = ApplicationStore.UserList.SingleOrDefault(x => x.Username == ViewCurrentUserAccount.Username);
                            TargetAccount.AccessExpires  = ViewCurrentUserAccount.AccessExpires;
                            TargetAccount.AccessToken    = ViewCurrentUserAccount.AccessToken;
                            TargetAccount.RefreshExpires = ViewCurrentUserAccount.RefreshExpires;
                            TargetAccount.RefreshToken   = ViewCurrentUserAccount.RefreshToken;
                            TargetAccount.Scope          = ViewCurrentUserAccount.Scope;
                            SaveApplicationStore();
                        }
                        return(true);
                    }
                    else
                    {
                        if (TokenResponse.ErrorResponse != null)
                        {
                            this.ErrorMessage = $"Refresh Token request failed with message: Http Status: {TokenResponse.StatusCode.ToString()}, Error: {TokenResponse.ErrorResponse.Error}, ErrorMessage: {TokenResponse.ErrorResponse.Description}";
                        }
                        else
                        {
                            this.ErrorMessage = $"Refresh Token request failed with no error message returned message, http status was: {TokenResponse.StatusCode.ToString()}";
                        }
                        return(false);
                    }
                }
                else
                {
                    throw new FormatException($"No CurrectUserAccount.AuthorisationCode found for access token request.");
                }
            }
            return(true);
        }
Beispiel #4
0
        private UserAccountView ConvertToUserAccountView(DataStore.UserAccount UserAccount)
        {
            var UserAccountView = new UserAccountView();

            UserAccountView.AccessExpires     = UserAccount.AccessExpires;
            UserAccountView.AccessToken       = UserAccount.AccessToken;
            UserAccountView.AuthorisationCode = UserAccount.AuthorisationCode;
            UserAccountView.RefreshExpires    = UserAccount.RefreshExpires;
            UserAccountView.RefreshToken      = UserAccount.RefreshToken;
            UserAccountView.Scope             = UserAccount.Scope;
            UserAccountView.Username          = UserAccount.Username;
            return(UserAccountView);
        }
Beispiel #5
0
        public void UpdateView(ViewModel.Presenter Presenter)
        {
            Presenter.Client_id     = ApplicationStore.App_id;
            Presenter.Client_secret = ApplicationStore.App_secret;

            foreach (var x in this.ApplicationStore.UserList)
            {
                var User = new ViewModel.UserAccountView()
                {
                    AccessExpires     = x.AccessExpires,
                    AccessToken       = x.AccessToken,
                    AuthorisationCode = x.AuthorisationCode,
                    RefreshExpires    = x.RefreshExpires,
                    RefreshToken      = x.RefreshToken,
                    Scope             = x.Scope,
                    Username          = x.Username
                };
                Presenter.AddUserAccountViewList.Add(User);
            }
            if (Presenter.UserAccountViewList.Count > 0)
            {
                Presenter.CurrentUserAccount = Presenter.UserAccountViewList[0];
            }
        }