protected override void Context() { base.Context(); _oldProjectMetaData = A.Fake <ProjectMetaData>(); A.CallTo(() => _projectToProjectMetaDataMapper.MapFrom(_project)).Returns(_projectMetaData); _listOfProjectsInDatabase.Add(_oldProjectMetaData); }
public IPKSimProject MapFrom(ProjectMetaData projectMetaData) { var project = new PKSimProject { Name = projectMetaData.Name, Description = projectMetaData.Description }; //Observed data needs to be loaded first into project projectMetaData.AllObservedData.Each(x => project.AddObservedData(mapFrom(x))); projectMetaData.BuildingBlocks.Each(x => project.AddBuildingBlock(mapFrom(x))); //we need a shared context for all object referencing observed data and simulations using (var context = _serializationContextFactory.Create(project.AllObservedData, project.All <ISimulation>())) { var localContext = context; projectMetaData.ParameterIdentifications.Each(x => project.AddParameterIdentification(mapFrom(x, localContext))); projectMetaData.SensitivityAnalyses.Each(x => project.AddSensitivityAnalysis(mapFrom(x, localContext))); } projectMetaData.SimulationComparisons.Each(x => project.AddSimulationComparison(mapFrom(x))); //Once reference to dynamic meta data was added, deserialize the project itself _serializationManager.Deserialize(project, projectMetaData.Content.Data); //if the project DB Version is the same as the current project, the project did not change if (projectMetaData.Version == ProjectVersions.Current) { project.HasChanged = false; } return(project); }
protected override void Context() { base.Context(); _orgMetaData = new ProjectMetaData(); _session = A.Fake <ISession>(); _orgMetaData.Version = 1; }
public override void GlobalContext() { base.GlobalContext(); sut = new ProjectMetaData { Name = "Project", Id = 1 }; _observedDataMetaData = new ObservedDataMetaData { Id = "DataRepo", DataRepository = new DataRepositoryMetaData { Id = "DataRepo", Name = "DataRepo" } }; sut.AddObservedData(_observedDataMetaData); using (var session = _sessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { session.Save(sut); transaction.Commit(); } using (var session = _sessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { var projectFromDb = session.Get <ProjectMetaData>(sut.Id); projectFromDb.AllObservedData.Clear(); transaction.Commit(); } }
public async Task <bool> SaveProject(ProjectMetaData metaData) { var savedFolder = await save.SaveProject(_storageFolder, _strokes, metaData, components); if (savedFolder != null) { _storageFolder = savedFolder; } return(true); }
public void should_create_the_database_schema() { using (var session = _sessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { var projectMetaData = new ProjectMetaData { Id = 1, Name = "toto" }; session.Save(projectMetaData); transaction.Commit(); } }
protected override void Context() { _simulationMapper = A.Fake <ISimulationMetaDataToSimulationMapper>(); _entitySerializer = A.Fake <ICompressedSerializationManager>(); _serializationContextFactory = A.Fake <ISerializationContextFactory>(); sut = new ProjectMetaDataToProjectMapper(_simulationMapper, _entitySerializer, _serializationContextFactory); _projectMetaData = new ProjectMetaData(); _simulationComparisonMetaData = new IndividualSimulationComparisonMetaData { Id = "ComparisonData" }; }
public ProjectMetaData MapFrom(IMoBiProject project) { var projectMetaData = new ProjectMetaData { Name = project.Name, Description = project.Description }; serializeContent(projectMetaData, project); project.AllBuildingBlocks().Each(x => projectMetaData.AddChild(mapFrom(x))); project.Simulations.Each(x => projectMetaData.AddChild(mapFrom(x))); project.Charts.Each(x => projectMetaData.AddChild(mapFrom(x))); project.AllParameterAnalysables.Each(x => projectMetaData.AddChild(mapFrom(x))); return(projectMetaData); }
public ProjectMetaData MapFrom(PKSimProject project) { var projectMetaData = new ProjectMetaData(); project.All <IPKSimBuildingBlock>().Each(x => projectMetaData.AddBuildingBlock(mapFrom(x))); project.AllSimulationComparisons.Each(x => projectMetaData.AddSimulationComparison(mapFrom(x))); project.AllParameterIdentifications.Each(x => projectMetaData.AddParameterIdentification(mapFrom(x))); project.AllSensitivityAnalyses.Each(x => projectMetaData.AddSensitivityAnalysis(mapFrom(x))); project.AllObservedData.Each(x => projectMetaData.AddObservedData(mapFrom(x))); projectMetaData.Name = project.Name; projectMetaData.Description = project.Description; projectMetaData.Content.Data = _serializationManager.Serialize(project); _metaData = null; return(projectMetaData); }
protected override void Context() { _project = A.Fake <PKSimProject>(); _session = A.Fake <ISession>(); _projectMetaData = new ProjectMetaData { Id = 1 }; _listOfProjectsInDatabase = new List <ProjectMetaData>(); _projectToProjectMetaDataMapper = A.Fake <IProjectToProjectMetaDataMapper>(); _projectMetaDataToProjectMapper = A.Fake <IProjectMetaDataToProjectMapper>(); A.CallTo(() => _session.BeginTransaction()).Returns(A.Fake <ITransaction>()); var criteria = A.Fake <ICriteria>(); A.CallTo(() => _session.CreateCriteria <ProjectMetaData>()).Returns(criteria); A.CallTo(() => criteria.List <ProjectMetaData>()).Returns(_listOfProjectsInDatabase); sut = new ProjectPersistor(_projectToProjectMetaDataMapper, _projectMetaDataToProjectMapper); }
public override void GlobalContext() { base.GlobalContext(); _projectMetaData = new ProjectMetaData { Name = "Project" }; _simulationMetaData = new SimulationMetaData { Id = "PopSim", SimulationMode = SimulationMode.Population, Name = "Sim" }; _simulationMetaData.SimulationResults = DomainHelperForSpecs.CreateSimulationResults(_numberOfIndividuals, numberOfPaths: 2); _projectMetaData.AddBuildingBlock(_simulationMetaData); using (var session = _sessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { session.Save(_projectMetaData); transaction.Commit(); } }
public override void GlobalContext() { base.GlobalContext(); _projectMetaData = new ProjectMetaData { Name = "Project" }; _simulationMetaData = new SimulationMetaData { Id = "Id", SimulationMode = SimulationMode.Individual, Name = "Sim" }; _simulationChartMetaData = new SimulationChartMetaData { Id = "Chart", Name = "Chart" }; _simulationMetaData.Charts.Add(_simulationChartMetaData); _projectMetaData.AddBuildingBlock(_simulationMetaData); //save project once using (var session = _sessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { session.Save(_projectMetaData); transaction.Commit(); } //then delete chart to simulation lazy loading _simulationMetaData.Charts.Clear(); _simulationMetaData.Content.Data = null; _simulationMetaData.IsLoaded.ShouldBeFalse(); //update project again. The charts should not be clear using (var session = _sessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { var projectMetaData = session.CreateCriteria <ProjectMetaData>().List <ProjectMetaData>().First(); projectMetaData.UpdateFrom(_projectMetaData, session); transaction.Commit(); } }
public IMoBiProject MapFrom(ProjectMetaData projectMetaData) { try { // deserialization is a three stage process. First we need to load the observed data // then all other entities and finish with the project charts using (var serializationContext = _serializationContextFactory.Create()) { _project = deserializeContent <IMoBiProject>(projectMetaData.Content, serializationContext); _project.Name = projectMetaData.Name; _project.Description = projectMetaData.Description; //add observed data to global addObservedDataToSerializationContext(serializationContext); //load simulation first foreach (var simulationMetaData in projectMetaData.Simulations) { addSimulationToProject(simulationMetaData, serializationContext); } //then load the rest of the entities foreach (var entityMetaData in projectMetaData.Children) { addEntityToProject(entityMetaData, serializationContext); } _deserializedReferenceResolver.ResolveFormulaAndTemplateReferences(_project, _project); return(_project); } } finally { _project = null; } }
public void PostSave(QASystem tis, TestResult tr, XmlRepositoryItem xmlRepoItem, ProjectMetaData projectMetaData, ITISExtenderState state) { // do nothing }
private static void saveProject(ISession session, ProjectMetaData projectMetaData) { session.Save(projectMetaData); }
public async Task <ContentDialogResult> OpenNewProject(ProjectMetaData metaData) { return(await save.ConfirmSave(_strokes, _storageFolder, metaData, components)); }
public async Task <MainCanvasParams> OpenExistingProject(ProjectMetaData metaData) { return(await save.OpenProject(_strokes, _storageFolder, metaData, components)); }
private IMoBiProject projectFrom(ProjectMetaData projectMetaData) { return(_projectMetaDataToProjectMapper.MapFrom(projectMetaData)); }
public void SaveAsImage(double width, double height, ProjectMetaData metaData, Canvas recognitionCanvas) { save.SaveAsImage(width, height, _strokes, metaData, recognitionCanvas); }
/// <summary> /// /// </summary> /// <param name="xml"></param> /// <param name="senderType"></param> /// <param name="fileID"></param> /// <param name="updateRB"></param> /// <param name="updateDoR"></param> /// <param name="sendToHandScoring"></param> /// <param name="ignoreHandscoringDuplicates"></param> /// <param name="emailAlertForWarnings"></param> /// <returns></returns> public QAResult ReceiveTestResult(XmlDocument xml, XmlRepositoryItem xmlRepoItem) { DateTime startDateTime = DateTime.Now; QAResult result = QAResult.Success; ArchiveDB ar = new ArchiveDB(); TestResult tr = null; bool isFatal = false; bool isValid = false; XMLAdapter adapter; SendToModifiers sendToModifiers = null; long? archivedFileID = null; long? dorRecordId = null; // these config settings may be overridden or modified below for this test. ProjectMetaData projectMetaData = new ProjectMetaData(); ITISExtender tisExtender = ServiceLocator.Resolve <ITISExtender>() ?? new NullTISExtender(); ITISExtenderState tisExtenderState = tisExtender.CreateStateContainer(); ITestResultSerializerFactory serializerFactory = ServiceLocator.Resolve <ITestResultSerializerFactory>(); if (serializerFactory == null) { throw new ApplicationException("Must register an ITestResultSerializerFactory with the ServiceLocator."); } try { xmlRepositoryBL = new BL.XmlRepository(QASystemConfigSettings.Instance.LongDbCommandTimeout); adapter = serializerFactory.CreateDeserializer(xml); tr = adapter.CreateTestResult(_tc, out isValid, true); if (tr != null) { // set the project metadata based on the current project (set in the parser) projectMetaData.SetProjectMetaData(tr.ProjectID); // if the opp is null, we can't process the file if (tr.Opportunity == null) { result = QAResult.FailValidation; ar.SaveResultExceptions(tr, adapter.ValidationRecords, xmlRepoItem.FileID); return(result); } //merge item scores from outside vendor if necessary bool qaProjectChanged = false; if (projectMetaData.mergeItemScores && adapter.MergeScores(tr, out qaProjectChanged)) { SetArchiveStrategy(ArchiveStrategy.ArchiveAndInsert); } // if the project changed, refresh the metadata if (qaProjectChanged) { projectMetaData.SetProjectMetaData(tr.ProjectID); } //PRESCORE: tisExtender.PreScore(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); //SCORE: if (tisExtender.ShouldScore(this, adapter, tr, projectMetaData, tisExtenderState)) { if (tr.AddScores(_tc)) { SetArchiveStrategy(ArchiveStrategy.ArchiveAndInsert); } } //COMPLETENESS STATUS: tr.Opportunity.Completeness = !tr.IsComplete() ? "Partial" : "Complete"; // Validation section. This checks the xml file against several business rules. // If validation fails, the file is moved to a failed files directory. List <ValidationRecord> vrs = new List <ValidationRecord>(); tr.ValidationRecords = adapter.ValidationRecords; if (tr.ValidationRecords.Count == 0) { //POSTSCORE: tisExtender.PostScore(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); // if the startdate is null in the file, it will be set to the statusDate. // Make sure we archive it so that we have a record of the unmodified file. if (tr.Opportunity.OriginalStartDate == DateTime.MinValue) { SetArchiveStrategy(ArchiveStrategy.ArchiveAndInsert); } switch (archiveStrategy) { case ArchiveStrategy.ArchiveAndInsert: //Change the status of old XML file to Arcvhive //insert the new XML file with status as Pprocessing //get the new File id archivedFileID = xmlRepoItem.FileID; xmlRepoItem.FileID = xmlRepositoryBL.InsertAndArchiveXML(xmlRepoItem.FileID, BL.XmlRepository.Location.processing, tr.ToXml(serializerFactory)); break; case ArchiveStrategy.UpdateOriginalFile: // just update the contents of the existing file w/o archiving xmlRepositoryBL.UpdateFileContent(xmlRepoItem.FileID, tr.ToXml(serializerFactory)); break; } vrs = tisExtender.Validate(this, tr, xmlRepoItem, projectMetaData, tisExtenderState, out isFatal, out sendToModifiers); tr.Acknowledged = true; if (((tr.Testee.EntityKey < 0 || tr.Opportunity.OpportunityNumber < 0) && !tr.Opportunity.IsDiscrepancy) || tr.Opportunity.StatusDate == null || tr.ValidationRecords.Count > 0 || isFatal) { // Update db with message messages... ar.SaveResultExceptions(tr, tr.ValidationRecords, xmlRepoItem.FileID); // If fatal then save exception and move to failed folder if (isFatal) { result = QAResult.FailValidation; //AM 8/13/2010: changed this; 1 email will be sent at the end with all // warnings (and errors too if there were any) if emailAlertForWarnings = true // and there were warnings to send. ar.SaveResultExceptions(tr, vrs, xmlRepoItem.FileID); //ar.SaveResultExceptions(tr, vrs, destinationFile, fileName, emailAlertForWarnings); return(result); } } //AM 8/13/2010: same comment as above ar.SaveResultExceptions(tr, vrs, xmlRepoItem.FileID); //ar.SaveResultExceptions(tr, vrs, destinationFile, fileName, emailAlertForWarnings); } else // If there are some XML validation errors then save exception and move to exception folder { result = QAResult.FailValidation; ar.SaveResultExceptions(tr, adapter.ValidationRecords, xmlRepoItem.FileID); return(result); } } else // tr == null { result = QAResult.FailValidation; ar.SaveResultExceptions(tr, adapter.ValidationRecords, xmlRepoItem.FileID); return(result); } // Update the test results after validation has been completed. try { if (isValid) { //PREROUTE: tisExtender.PreRoute(this, adapter, tr, xmlRepoItem, projectMetaData, sendToModifiers, tisExtenderState); // Update XML destinations in case some business rule modified it if (sendToModifiers != null) { foreach (KeyValuePair <SendTo, bool> sendInfo in (SendToModifiersTyped)sendToModifiers) { switch (sendInfo.Key) { case SendTo.DoR: projectMetaData.updateDoR = sendInfo.Value; break; case SendTo.Handscoring: projectMetaData.sendToHandScoring = sendInfo.Value; break; case SendTo.RB: projectMetaData.updateRB = sendInfo.Value; break; } } } if (projectMetaData.updateDoR) { try { List <Target> dorTarget = Target.GetOrderedTargets(tr.ProjectID, Target.TargetClass.DoR); if (dorTarget != null && dorTarget.Count == 1) { dorTarget[0].Send(tr, delegate(object o) { dorRecordId = (long)o; }, projectMetaData.doRAdminID); } } catch (Exception ex) { throw new QAException(String.Format("DoR update failed for fileId: {0}, Message: {1}", xmlRepoItem.FileID, ex.Message), QAException.ExceptionType.General, ex); } } //send to configured Handscoring targets ItemScoringManager.Instance.Send(tr, sendToModifiers); // send to configured targets in order (incl RB) foreach (Target t in Target.GetOrderedTargets(tr.ProjectID, Target.TargetClass.General)) { if (!sendToModifiers.ShouldSend(t.Name)) { continue; } ITargetResult targetResult = t.Send(tr); if (targetResult.Sent) { Logger.Log(true, String.Format("Sent data for FileId: {0} to Target: {1} ({2}).", xmlRepoItem.FileID, t.Name, targetResult.ID ?? "<unspecified>"), EventLogEntryType.Information, false, true); } } //POSTROUTE: tisExtender.PostRoute(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); } // Check if this test need to be merged with something else try { TDSQASystemAPI.TestMerge.TestMerge testMerge = TestMergeConfiguration.Instance.GetTestMerge(tr.Name); if (testMerge != null) { testMerge.CreateCombinedTest(_tc, tr, serializerFactory); } } catch (Exception ex) { throw new QAException(String.Format("TestMerge operation failed for fileId: {0}, Message: {1}", xmlRepoItem.FileID, ex.Message), QAException.ExceptionType.General, ex); } } catch (QAException qae) { //TODO: result = QAResult.FailUpdate; string message = qae.GetExceptionMessage(true); if (message.StartsWith("DoR")) { ar.SaveResultExceptions(tr, "DoR update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else if (message.StartsWith("Handscoring")) { ar.SaveResultExceptions(tr, "Handscoring update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else if (message.StartsWith("TestMerge")) { ar.SaveResultExceptions(tr, "Test merge operation failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else if (message.StartsWith("AutoAppeal")) { ar.SaveResultExceptions(tr, "AutoAppeal failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } else { ar.SaveResultExceptions(tr, "Response Bank update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); } return(result); } catch (Exception ex) { result = QAResult.FailUpdate; string message = ex.GetExceptionMessage(true); ar.SaveResultExceptions(tr, "Response Bank update failed: ", message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); return(result); } // Log to TestOpportunityStatus, Update the TDS_QC database, and possibly send to TIS if (tr != null) { try { // Log to TestOpportunityStatus, Update the TDS_QC database ar.SaveResultInfo(tr, xmlRepoItem.FileID, tr.Testee.IsDemo, dorRecordId, archivedFileID, projectMetaData.updateRB); } catch (Exception ex) { result = QAResult.FailUpdate; string message = ex.GetExceptionMessage(true); ar.SaveResultExceptions(tr, "Archive ", ex.Message, xmlRepoItem.FileID); Logger.Log(true, message, EventLogEntryType.Error, false, true); return(result); } //POSTSAVE: tisExtender.PostSave(this, tr, xmlRepoItem, projectMetaData, tisExtenderState); } result = QAResult.Success; } catch (Exception ex) { result = QAResult.Unknown; string message = ex.GetExceptionMessage(true); if (tr != null) { ar.SaveResultExceptions(tr, "QA System Exception:", message, xmlRepoItem.FileID); } else { ar.SaveResultExceptions("QA System Exception:", message, xmlRepoItem.FileID); } Logger.Log(true, message, EventLogEntryType.Error, false, true); } finally { if (!(tr == null || tr.Opportunity == null)) { // We don't want to call back to TDS for scanned paper tests, since they did not originate from TDS. // Just skip w/o logging. if (!tr.Mode.Equals("scanned")) { Boolean accepted = true; string message = null; if (result == QAResult.FailUpdate || result == QAResult.FailValidation || result == QAResult.Unknown || !(tr.PassedAllValidations())) { accepted = false; if (result == QAResult.FailUpdate) { message = "failed validation"; } else if (result == QAResult.FailValidation) { message = "failed while either updating the Response Bank, storing data into the DoR, or invoking the Handscoring webservice"; } else if (result == QAResult.Unknown) { message = "An unknown exception occurred"; } else if (!(tr.PassedAllValidations())) { message = "Failed rules validation"; } } IAcknowledgementTargetFactory ackTargetFactory = AIR.Common.ServiceLocator.Resolve <IAcknowledgementTargetFactory>(); if (ackTargetFactory != null) // ok not to acknowledge I suppose { IAcknowledgementTarget ackTarget = ackTargetFactory.SelectTarget(xmlRepoItem); try { if (ackTarget == null || !ackTarget.Send(new Message(tr.Opportunity.Key, accepted, message), xmlRepoItem)) { Logger.Log(true, String.Format("Acknowledgement not sent for fileID: {0}", xmlRepoItem.FileID), EventLogEntryType.Information, false, true); } } catch (Exception ex) { // allow these to be treated as warnings or errors. If TreatAcknowledgementFailureAsError is set to true, // a failure to send an ACK will result in the file being dumped into the reject bin. // Default behavior is to treat these as warnings. We generally don't want to fail a file just because // we can't send the ACK. Note also that a combo may already have been created (if applicable). bool treatAckfailureAsError = false; if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["TreatAcknowledgementFailureAsError"]) && Convert.ToBoolean(ConfigurationManager.AppSettings["TreatAcknowledgementFailureAsError"])) { treatAckfailureAsError = true; } // if the file would have otherwise succeeded and there was an exception while attempting to send the ACK and // we're not treating these as warnings, fail the file. if (treatAckfailureAsError && result == QAResult.Success) { result = QAResult.Unknown; } Logger.Log(true, String.Format("Could not send acknowledgement for fileID: {0}, Exception: {1}", xmlRepoItem.FileID, ex.GetExceptionMessage(true)), treatAckfailureAsError ? EventLogEntryType.Error : EventLogEntryType.Warning, false, true); } } } } //Move file to appropriate folder based on the QAResult and log the status accordingly. LogAndCleanup(result, xmlRepoItem.FileID, tr, startDateTime); } return(result); }
public bool ShouldScore(QASystem tis, XMLAdapter adapter, TestResult tr, ProjectMetaData projectMetaData, ITISExtenderState state) { return(true); }
public void PreRoute(QASystem tis, XMLAdapter adapter, TestResult tr, XmlRepositoryItem xmlRepoItem, ProjectMetaData projectMetaData, SendToModifiers sendToModifiers, ITISExtenderState state) { // do nothing }
public List <ValidationRecord> Validate(QASystem tis, TestResult tr, XmlRepositoryItem xmlRepoItem, ProjectMetaData projectMetaData, ITISExtenderState state, out bool isFatal, out SendToModifiers sendToModifiers) { isFatal = false; sendToModifiers = new SendToModifiers(); return(new List <ValidationRecord>()); }