public bool storeTest(Test test) { if (Authenticated_AorC()) { try { Movement.Database.User newUser = new Movement.Database.User(test.user.userID); Movement.Database.Patient newPatient = new Movement.Database.Patient(test.patient.ID); Movement.Database.TestScript newScript = new Movement.Database.TestScript(test.script.scriptID); IEnumerable <Movement.Database.TestDataSample> data; data = test.data.ConvertAll <TestDataSample>(new Converter <Data, TestDataSample>( delegate(Data filler) { return(new TestDataSample(filler.time, filler.x, filler.y, filler.pressure)); })); Movement.Database.Test.CreateTest(newUser, newPatient, test.hand, newScript, test.mode, data, test.avg_X, test.avg_Y, test.rotation); return(true); } catch (Exception e) { Log(e); return(false); } } else { throw new UnauthorizedAccessException("You are not authorized to perform that action!"); } }
public Script getScript(ScriptInfo script) { if (Authenticated_AorC()) { try { Movement.Database.TestScript test = new Movement.Database.TestScript(script.scriptID); Script newScript = new Script(); newScript.scriptData = test.ScriptData; newScript.scriptID = test.ScriptID; newScript.type = test.ScriptType.Name; newScript.version = test.Version; return(newScript); } catch (Exception e) { Log(e); return(new Script()); } } else { throw new UnauthorizedAccessException("You are not authorized to perform that action!"); } }
/// <summary> /// This function searches a database for a script that matches an ID and retrieves that script /// </summary> /// <returns>The script corresponding to ID</returns> private ScriptInfo getScriptData(int ID) { try { //using a test script ID not testScriptType ID Movement.Database.TestScript script = new Movement.Database.TestScript(ID); Movement.Database.TestScriptType test = script.ScriptType; ScriptInfo newScript = new ScriptInfo(); newScript.name = test.Name; newScript.description = test.Description; newScript.scriptID = test.GetLatestScript().ScriptID; newScript.versionID = test.GetLatestScript().Version; return(newScript); } catch (Exception e) { Log(e); return(new ScriptInfo()); } }
public bool storeTest(Test test) { if (Authenticated_AorC()) { try { Movement.Database.User newUser = new Movement.Database.User(test.user.userID); Movement.Database.Patient newPatient = new Movement.Database.Patient(test.patient.ID); Movement.Database.TestScript newScript = new Movement.Database.TestScript(test.script.scriptID); IEnumerable<Movement.Database.TestDataSample> data; data = test.data.ConvertAll<TestDataSample>(new Converter<Data, TestDataSample>( delegate(Data filler) { return new TestDataSample(filler.time, filler.x, filler.y, filler.pressure); })); Movement.Database.Test.CreateTest(newUser, newPatient, test.hand, newScript, test.mode, data, test.avg_X, test.avg_Y, test.rotation); return true; } catch(Exception e) { Log(e); return false; } } else { throw new UnauthorizedAccessException("You are not authorized to perform that action!"); } }
public Script getScript(ScriptInfo script) { if (Authenticated_AorC()) { try { Movement.Database.TestScript test = new Movement.Database.TestScript(script.scriptID); Script newScript = new Script(); newScript.scriptData = test.ScriptData; newScript.scriptID = test.ScriptID; newScript.type = test.ScriptType.Name; newScript.version = test.Version; return newScript; } catch (Exception e) { Log(e); return new Script(); } } else { throw new UnauthorizedAccessException("You are not authorized to perform that action!"); } }
/// <summary> /// This function searches a database for a script that matches an ID and retrieves that script /// </summary> /// <returns>The script corresponding to ID</returns> private ScriptInfo getScriptData(int ID) { try { //using a test script ID not testScriptType ID Movement.Database.TestScript script = new Movement.Database.TestScript(ID); Movement.Database.TestScriptType test = script.ScriptType; ScriptInfo newScript = new ScriptInfo(); newScript.name = test.Name; newScript.description = test.Description; newScript.scriptID = test.GetLatestScript().ScriptID; newScript.versionID = test.GetLatestScript().Version; return newScript; } catch (Exception e) { Log(e); return new ScriptInfo(); } }
/// <summary> /// Creates and stores a new test. /// </summary> /// <param name="user">The user that administered the test.</param> /// <param name="patient">The patient that took the test.</param> /// <param name="hand">The hand that the test was taken with.</param> /// <param name="script">The script used to run the test.</param> /// <param name="mode">The mode that the test was run in.</param> /// <param name="data">The data collected during the test.</param> /// <param name="meanX">The average x-coordinate of all the data collected.</param> /// <param name="meanY">The average y-coordinate of all the data collected.</param> /// <param name="rotation">The number of degrees that the test was rotated (from the positive x-axis) when taken.</param> /// <returns>The created test.</returns> public static Test CreateTest( User user, Patient patient, char hand, TestScript script, char mode, IEnumerable <TestDataSample> data, double meanX, double meanY, short rotation) { int TestID = -1; //create an analyzer Analyzer DataAnalyzer = new Analyzer( meanX, meanY, new ScriptEngine(script.ScriptData).Path); using (DbConnection Connection = GetAsyncConnection()) { Connection.Open(); //begin a transaction so that creation is atomic DbTransaction Transaction = Connection.BeginTransaction(); try { //create the test TestID = Execute(Connection, Transaction, "STORE_TEST_RESULTS", "@scriptID", script.ScriptID, "@patientID", patient.PatientID, "@userID", user.UserID, "@hand", hand, "@mode", mode, "@rotation", rotation); //prepare the add-sample command ahead of time for efficiency DbCommand AddSampleCommand = PrepareCommand(Connection, Transaction, "ADD_TEST_SAMPLE"); AddSampleCommand.Parameters["@testID"].Value = TestID; int O_X = AddSampleCommand.Parameters.IndexOf("@x"), //determine the parameter indices ahead of time for efficiency O_Y = AddSampleCommand.Parameters.IndexOf("@y"), O_P = AddSampleCommand.Parameters.IndexOf("@p"), O_T = AddSampleCommand.Parameters.IndexOf("@t"); IAsyncResult AddSampleHandle = null; //store and analyze samples in parallel foreach (TestDataSample s in data) { //modify the prepared procedure arguments AddSampleCommand.Parameters[O_X].Value = s.X; AddSampleCommand.Parameters[O_Y].Value = s.Y; AddSampleCommand.Parameters[O_P].Value = s.Pressure; AddSampleCommand.Parameters[O_T].Value = s.Time; //finish the last procedure execution EndExecute(AddSampleHandle); //start the next procedure execution AddSampleHandle = BeginExecute(AddSampleCommand); //perform analysis on the sample DataAnalyzer.AnalyzeSample(s.Time, s.X, s.Y, s.Pressure); } EndExecute(AddSampleHandle); //store the analysis TestAnalysis.StoreAnalysis( Connection, Transaction, TestID, DataAnalyzer.CurrentAnalysis); Transaction.Commit(); } catch (Exception e) { Transaction.Rollback(); throw e; } } return(new Test(TestID)); }