/// <inheritdoc /> public DBResult <ResourceDelegate> Delete(ResourceDelegate resourceDelegate, bool commit) { this.logger.LogTrace($"Deleting resourceDelegate {JsonSerializer.Serialize(resourceDelegate)} from DB..."); DBResult <ResourceDelegate> result = new DBResult <ResourceDelegate>() { Status = DBStatusCode.Deferred, }; this.dbContext.ResourceDelegate.Remove(resourceDelegate); if (commit) { try { this.dbContext.SaveChanges(); result.Status = DBStatusCode.Deleted; } catch (DbUpdateConcurrencyException e) { result.Status = DBStatusCode.Concurrency; result.Message = e.Message; } } this.logger.LogDebug($"Finished deleting resourceDelegate from DB"); return(result); }
/// <inheritdoc /> public DBResult <ResourceDelegate> Insert(ResourceDelegate resourceDelegate, bool commit = true) { this.logger.LogTrace($"Inserting resource delegate to DB... {JsonSerializer.Serialize(resourceDelegate)}"); DBResult <ResourceDelegate> result = new DBResult <ResourceDelegate>() { Payload = resourceDelegate, Status = DBStatusCode.Deferred, }; this.dbContext.Add <ResourceDelegate>(resourceDelegate); if (commit) { try { this.dbContext.SaveChanges(); result.Status = DBStatusCode.Created; } catch (DbUpdateException e) { this.logger.LogError($"Error inserting resource delegate to DB with exception ({e.ToString()})"); result.Status = DBStatusCode.Error; result.Message = e.Message; } } this.logger.LogTrace($"Finished inserting resource delegate to DB... {JsonSerializer.Serialize(result)}"); return(result); }
private void WorkspaceManager_WorkspaceChanged(object sender, EventArgs e) { ResourceDelegate job = DecorateResource; Core.UserInterfaceAP.QueueJob(job, NewsFolders.Drafts); Core.UserInterfaceAP.QueueJob(job, NewsFolders.Outbox); }
// // Update is called once per frame // void Update () // { // // } public void Load(string name, ResourceDelegate completeDel) { if (GameDefines.USE_ASSET_BUNDLE) { // Parse the relative path string url = string.Empty; int version = -1; if (name.IndexOf("file://") == 0) { // Local download bundle url = name; version = -1; } else { name = name.Substring(name.LastIndexOf("/") + 1); url = GameDefines.GetUrlBase() + GetCachePath(name) + name + ".assetbundle"; version = GetCacheID(name); } LoadBundle(url, version, completeDel); } else { // Use the path relative to Resources LoadLocal(name, completeDel); } }
/// <summary> /// Constructs a new DependentModel based on a PatientModel. /// </summary> /// <param name="resourceDeleagate">The ResourceDelegate model.</param> /// <param name="patientModel">The Patien Model to be converted.</param> /// <returns>The Dependent Model.</returns> public static DependentModel CreateFromModels(ResourceDelegate resourceDeleagate, PatientModel patientModel) { return(new DependentModel() { OwnerId = resourceDeleagate.ResourceOwnerHdid, DelegateId = resourceDeleagate.ProfileHdid, ReasonCode = resourceDeleagate.ReasonCode, Version = resourceDeleagate.Version, DependentInformation = DependentInformation.FromPatientModel(patientModel), }); }
/// <summary> /// Opens the resource. /// </summary> /// <param name="tvi">The <see cref="TreeViewItem"/> containing the resource.</param> /// <param name="resource">The <see cref="Version"/>.</param> /// <remarks>Runs on a background thread.</remarks> private void OpenResource(Version resource) { string errorMessage; ResourceDelegate actCloseResource = CloseResource; if (!ExternalApplication.OpenFileWithDefaultApplication(resource.DataAsset, out errorMessage)) { MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } Dispatcher.BeginInvoke(actCloseResource, System.Windows.Threading.DispatcherPriority.Background, resource); }
/// <summary> /// Calls the specified delegate for every node in the view. /// </summary> /// <param name="resourceDelegate">The delegate to call.</param> public void ForEachNode(ResourceDelegate resourceDelegate) { if (_jetListView.Nodes.Count > 0) { IEnumerator enumerator = _jetListView.NodeCollection.EnumerateNodesForward(_jetListView.Nodes[0]); while (enumerator.MoveNext()) { JetListViewNode node = (JetListViewNode)enumerator.Current; resourceDelegate((IResource)node.Data); } } }
/// <summary> /// Handles the Click event of the BtnOpenSelected control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> /// <remarks>Runs on the UI thread.</remarks> private void BtnOpenSelected_Click(object sender, RoutedEventArgs e) { ResourceDelegate actOpenResource = OpenResource; if (ResourceTree.Selected == null) { MessageBox.Show("You must select a resource first."); return; } actOpenResource.BeginInvoke(ResourceTree.Selected, OpenResource_AsyncCallback, actOpenResource); ResourceTree.SetResourceTreeSelectedIndex(-1); }
private void LoadLocal(string name, ResourceDelegate completeDel) { Object obj = Resources.Load(name); string error = string.Empty; // Check the name is a level name? // if (null == obj) // { // error = "Cann't find " + name + " in local."; // } if (null != completeDel) { completeDel(obj, error); } }
private void LoadBundle(string url, int version, ResourceDelegate completeDel) { wwwLoaderMgr.Download(url, version, delegate(WWW www) { Object obj = null; if (string.IsNullOrEmpty(www.error)) { Debug.Log("[LoadBundle:End:], the version is " + version); obj = www.assetBundle.mainAsset; } else { Debug.Log("[LoadBundle:Error:] " + www.error); } if (null != completeDel) { completeDel(obj, www.error); } }); }
private IDependentService SetupMockDependentService(AddDependentRequest addDependentRequest, DBResult <ResourceDelegate> insertResult = null, RequestResult <PatientModel> patientResult = null) { var mockPatientService = new Mock <IPatientService>(); RequestResult <string> patientHdIdResult = new RequestResult <string>() { ResultStatus = Common.Constants.ResultType.Success, ResourcePayload = mockHdId }; if (addDependentRequest.PHN.Equals(mockPHN)) { // Test Scenario - Happy Path: HiId found for the mockPHN patientHdIdResult.ResultStatus = Common.Constants.ResultType.Success; patientHdIdResult.ResourcePayload = mockHdId; } if (patientResult == null) { patientResult = new RequestResult <PatientModel>(); // Test Scenario - Happy Path: Found HdId for the PHN, Found Patient. patientResult.ResultStatus = Common.Constants.ResultType.Success; patientResult.ResourcePayload = new PatientModel() { HdId = mockHdId, PersonalHealthNumber = mockPHN, FirstName = mockFirstName, LastName = mockLastName, Birthdate = mockDateOfBirth, Gender = mockGender, }; } mockPatientService.Setup(s => s.GetPatient(It.IsAny <string>(), It.IsAny <PatientIdentifierType>())).Returns(Task.FromResult(patientResult)); ResourceDelegate expectedDbDependent = new ResourceDelegate() { ProfileHdid = mockParentHdId, ResourceOwnerHdid = mockHdId }; if (insertResult == null) { insertResult = new DBResult <ResourceDelegate> { Status = DBStatusCode.Created }; } insertResult.Payload = expectedDbDependent; Mock <IResourceDelegateDelegate> mockDependentDelegate = new Mock <IResourceDelegateDelegate>(); mockDependentDelegate.Setup(s => s.Insert(It.Is <ResourceDelegate>(r => r.ProfileHdid == expectedDbDependent.ProfileHdid && r.ResourceOwnerHdid == expectedDbDependent.ResourceOwnerHdid), true)).Returns(insertResult); Mock <IUserProfileDelegate> mockUserProfileDelegate = new Mock <IUserProfileDelegate>(); mockUserProfileDelegate.Setup(s => s.GetUserProfile(mockParentHdId)).Returns(new DBResult <UserProfile>() { Payload = new UserProfile() }); Mock <INotificationSettingsService> mockNotificationSettingsService = new Mock <INotificationSettingsService>(); mockNotificationSettingsService.Setup(s => s.QueueNotificationSettings(It.IsAny <NotificationSettingsRequest>())); Mock <IConfigurationService> configServiceMock = new Mock <IConfigurationService>(); configServiceMock.Setup(s => s.GetConfiguration()).Returns(new ExternalConfiguration()); return(new DependentService( new Mock <ILogger <DependentService> >().Object, mockUserProfileDelegate.Object, mockPatientService.Object, mockNotificationSettingsService.Object, mockDependentDelegate.Object, configServiceMock.Object )); }
/// <inheritdoc /> public RequestResult <DependentModel> AddDependent(string delegateHdId, AddDependentRequest addDependentRequest) { this.logger.LogTrace($"Dependent hdid: {delegateHdId}"); int?maxDependentAge = this.configurationService.GetConfiguration().WebClient.MaxDependentAge; if (maxDependentAge.HasValue) { DateTime minimumBirthDate = DateTime.UtcNow.AddYears(maxDependentAge.Value * -1); if (addDependentRequest.DateOfBirth < minimumBirthDate) { return(new RequestResult <DependentModel>() { ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = "Dependent age exceeds the maximum limit", ErrorCode = ErrorTranslator.ServiceError(ErrorType.InvalidState, ServiceType.Patient) }, }); } } this.logger.LogTrace("Getting dependent details..."); RequestResult <PatientModel> patientResult = Task.Run(async() => await this.patientService.GetPatient(addDependentRequest.PHN, PatientIdentifierType.PHN).ConfigureAwait(true)).Result; if (patientResult.ResultStatus == ResultType.Error) { return(new RequestResult <DependentModel>() { ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = "Communication Exception when trying to retrieve the Dependent", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.Patient) }, }); } if (patientResult.ResultStatus == ResultType.ActionRequired) { return(new RequestResult <DependentModel>() { ResultStatus = ResultType.ActionRequired, ResultError = ErrorTranslator.ActionRequired(ErrorMessages.DataMismatch, ActionType.DataMismatch), }); } this.logger.LogDebug($"Finished getting dependent details...{JsonSerializer.Serialize(patientResult)}"); // Verify dependent's details entered by user if (patientResult.ResourcePayload == null || !this.ValidateDependent(addDependentRequest, patientResult.ResourcePayload)) { this.logger.LogDebug($"Dependent information does not match request: {JsonSerializer.Serialize(addDependentRequest)} response: {JsonSerializer.Serialize(patientResult.ResourcePayload)}"); return(new RequestResult <DependentModel>() { ResultStatus = ResultType.ActionRequired, ResultError = ErrorTranslator.ActionRequired(ErrorMessages.DataMismatch, ActionType.DataMismatch), }); } // Verify dependent has HDID if (string.IsNullOrEmpty(patientResult.ResourcePayload.HdId)) { return(new RequestResult <DependentModel>() { ResultStatus = ResultType.ActionRequired, ResultError = ErrorTranslator.ActionRequired(ErrorMessages.InvalidServicesCard, ActionType.NoHdId), }); } string json = JsonSerializer.Serialize(addDependentRequest.TestDate, addDependentRequest.TestDate.GetType()); JsonDocument jsonDoc = JsonDocument.Parse(json); // Insert Dependent to database var dependent = new ResourceDelegate() { ResourceOwnerHdid = patientResult.ResourcePayload.HdId, ProfileHdid = delegateHdId, ReasonCode = ResourceDelegateReason.COVIDLab, ReasonObjectType = addDependentRequest.TestDate.GetType().AssemblyQualifiedName, ReasonObject = jsonDoc, }; DBResult <ResourceDelegate> dbDependent = this.resourceDelegateDelegate.Insert(dependent, true); if (dbDependent.Status == DBStatusCode.Created) { this.logger.LogTrace("Finished adding dependent"); this.UpdateNotificationSettings(dependent.ResourceOwnerHdid, delegateHdId); return(new RequestResult <DependentModel>() { ResourcePayload = DependentModel.CreateFromModels(dbDependent.Payload, patientResult.ResourcePayload), ResultStatus = ResultType.Success, }); } else { this.logger.LogError("Error adding dependent"); return(new RequestResult <DependentModel>() { ResourcePayload = new DependentModel(), ResultStatus = ResultType.Error, ResultError = new RequestResultError() { ResultMessage = dbDependent.Message, ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationInternal, ServiceType.Database) }, }); } }