public static void AddReturnValueToEachProcedure(this ProcedureFactory factory) { foreach (DataSItem item in factory.Procedures.Values) { item.AddReturnParam(CustomSqlTypes.Int); } }
public static Task <bool> WriteToFileAsync(this ProcedureFactory factory, string filepath, DbAgent agent = null) { return(Task.Factory.StartNew(() => { return WriteFactoryFile(factory, filepath, agent); })); }
public void LoadFromObject1() { //Create the person Person person = new Person() { FirstName = "John", LastName = "Doe", Email = "*****@*****.**" }; //Get the procedure Procedure proc = ProcedureFactory.GetProcedure("open", "POST_PERSON"); //Load the parameters from the object proc.LoadFromObject <Person>(person); //Execute the result - procedures returns the newly created object Person result = proc.ExecuteJson <Person>(); Assert.AreNotEqual(result.PersonId, person.PersonId); Assert.AreEqual(result.FirstName, person.FirstName); Assert.AreEqual(result.LastName, person.LastName); Assert.AreEqual(result.Email, person.Email); Assert.AreEqual(proc.ReturnValue <int>(), 200); Assert.AreEqual(proc.GetValue <long>("sqlErrorId"), 0); Assert.AreEqual(proc.GetValue <string>("messageResult"), null); }
public void PostPersonDuplicates() { //Generic setters provide additional validation Procedure procGood = ProcedureFactory.GetProcedure("open", "POST_PERSON"); procGood.SetValue <string>("firstName", "a"); procGood.SetValue <string>("lastName", "a"); procGood.SetValue <string>("email", "*****@*****.**"); procGood.ExecuteJson <Person>(); Procedure procBad = ProcedureFactory.GetProcedure("open", "POST_PERSON"); procBad.SetValue <string>("firstName", "a"); procBad.SetValue <string>("lastName", "a"); procBad.SetValue <string>("email", "*****@*****.**"); procBad.ExecuteJson <Person>(); Assert.AreEqual(procGood.GetValue <int>("RETURN_VALUE"), 200); Assert.AreEqual(procGood.GetValue <long>("SQL_ERROR_ID"), 0); Assert.AreEqual(procGood.GetValue <string>("MESSAGE_RESULT"), null); Assert.AreEqual(procBad.GetValue <int>("RETURN_VALUE"), 409); Assert.AreEqual(procBad.GetValue <long>("SQL_ERROR_ID"), 0); Assert.AreNotEqual(procBad.GetValue <string>("MESSAGE_RESULT"), null); }
public AnimalCentre() { animalFactory = new AnimalFactory(); hotelFactory = new HotelFactory(); procedureFactory = new ProcedureFactory(); hotel = hotelFactory.CreateHotel(); }
public void ClearData() { Procedure procedure = ProcedureFactory.GetProcedure("open", "CLEAR_DATA"); procedure.ExecuteNonQuery(); Assert.AreEqual(procedure.ReturnValue <int>(), 200); }
public AnimalCentre() { this.animalFactory = new AnimalFactory(); this.procedureFactory = new ProcedureFactory(); this.hotel = new Hotel(); this.procedures = new Dictionary <string, List <IAnimal> >(); }
/// <summary>Utilizes ObjectPropertyToParameterNameMapping to set the values of the parameters in the procedure</summary> /// <typeparam name="T">Type of object containing the values.</typeparam> /// <param name="value">Object containing values.</param> public void LoadFromObject <T>(T value) { ObjectPropertyToParameterNameMapping[] mappings = ProcedureFactory.GetParameterMapping <T>(_procedureName); for (int idx = 0, len = mappings.Length; idx != len; idx++) { mappings[idx].SetValue(value, this); } }
public void PostOrder1() { string Json = "{'personId': 1, 'orderName': 'my first order', 'orderItems': [{'name': 'pizza', 'comments': 'Extra Cheese Please'},{'name': 'italian sandwich', 'comments': 'No peppers'}]}"; Procedure procedure = ProcedureFactory.GetRestProcedure("POST", "trusted", "ORDER"); procedure.LoadFromJson(Json); string result = procedure.ExecuteJson(); }
public HttpResponseMessage Get(string specificName) { Procedure proc = ProcedureFactory.GetRestProcedure("GET", _specificSchema, specificName); proc.LoadFromQuery(Request.GetQueryNameValuePairs()); string Json = proc.ExecuteJson(); return(ProcessProcedureResult(Json, proc)); }
public AnimalCentre() { hotel = new Hotel(); procedures = new Dictionary <string, Procedure>(); ownedAnimals = new Dictionary <string, List <IAnimal> >(); this.animalfactory = new AnimalFactory(); procedureFactory = new ProcedureFactory(); key = ""; }
private async Task LoadProcedures(DbAgent agent) { Stopwatch sw = new Stopwatch(); sw.Start(); _currentFactory = await SqlManager.GetProceduresFactoryAsync(agent); sw.Stop(); Console.WriteLine("GetProceduresFactoryAsync - Time : " + sw.ElapsedMilliseconds.ToString()); }
public async Task <HttpResponseMessage> Delete(string specificName) { string requestJson = await Request.Content.ReadAsStringAsync(); Procedure proc = ProcedureFactory.GetRestProcedure("DELETE", _specificSchema, specificName); proc.LoadFromJson(requestJson); proc.ExecuteNonQuery(); return(ProcessProcedureResult(null, proc)); }
public async Task <HttpResponseMessage> Put(string specificName) { string requestJson = await Request.Content.ReadAsStringAsync(); Procedure proc = ProcedureFactory.GetRestProcedure("PUT", _specificSchema, specificName); proc.LoadFromJson(requestJson); string Json = proc.ExecuteJson(); return(ProcessProcedureResult(Json, proc)); }
public void GetPersonObjectJson2() { Procedure procedure = ProcedureFactory.GetProcedure("open", "PERSON_BY_ID"); procedure.SetValue <int>("PERSON_ID", 1); string result = procedure.ExecuteReaderAsJson <Person>(); Assert.AreNotEqual(result, null); Assert.AreEqual(procedure.GetValue <long>("SQL_ERROR_ID"), 0); Assert.AreEqual(procedure.GetValue <string>("MESSAGE_RESULT"), null); }
public void GetPersonObject() { Procedure procedure = ProcedureFactory.GetProcedure("open", "PERSON_BY_ID"); procedure.SetValue <int>("PERSON_ID", 1); Person person = procedure.ExecuteReader <Person>(); Assert.AreEqual(person.PersonId, 1); Assert.AreEqual(procedure.GetValue <long>("SQL_ERROR_ID"), 0); Assert.AreEqual(procedure.GetValue <string>("MESSAGE_RESULT"), null); }
//used public static bool WriteFactoryFile(this ProcedureFactory factory, string filepath, DbAgent agent = null) { bool result = false; SettingsHelperManager.CreateDocumentTemplate(filepath); DbCommandManagar.SetConfiguration(filepath); DbCommandManagar.LoadDocument(); _tempDoc.Load(filepath); result = DbCommandManagar.AddFactory(factory); return(result); }
public static async Task <ProcedureFactory> GetProceduresFactoryAsync(DbAgent agent = null) { ProcedureFactory fact = new ProcedureFactory(); Dictionary <string, DataSItem> procedures = await GetAllSqlProceduresAsync(agent); foreach (DataSItem value in procedures.Values) { value.FillPRocedureParamsFromSQLAgent(agent); } fact.SetProcedures(procedures); return(fact); }
//Builds a list using reflection. private List <T> buildListReflection <T>(SqlDataReader rdr) { List <T> result = new List <T>(); ReaderColumnToObjectPropertyMapping[] columnMappings = ProcedureFactory.GetReaderColumnToObjectPropertyMappings <T>(_procedureName, rdr); while (rdr.Read()) { T item = Activator.CreateInstance <T>(); for (int idx = 0, len = columnMappings.Length; idx != len; idx++) { columnMappings[idx].SetValue(item, rdr); } result.Add(item); } return(result); }
public void LoadFromParameters2() { //Generic setters provide additional validation Procedure proc = ProcedureFactory.GetProcedure("open", "POST_PERSON"); proc.SetValue <string>("firstName", "Mike"); proc.SetValue <string>("lastName", "Quick"); proc.SetValue <string>("email", "*****@*****.**"); //returning json string result = proc.ExecuteJson(); Assert.AreNotEqual(result, null); Assert.AreEqual(proc.ReturnValue <int>(), 200); Assert.AreEqual(proc.GetValue <long>("sqlErrorId"), 0); Assert.AreEqual(proc.GetValue <string>("messageResult"), null); }
public void LoadFromObject2() { Person person = new Person() { FirstName = "Jack", LastName = "Be", Email = "*****@*****.**" }; Procedure proc = ProcedureFactory.GetProcedure("open", "POST_PERSON"); proc.LoadFromObject <Person>(person); Person result = proc.ExecuteJson <Person>(); Assert.AreNotEqual(result.PersonId, person.PersonId); Assert.AreEqual(result.FirstName, person.FirstName); Assert.AreEqual(result.LastName, person.LastName); Assert.AreEqual(result.Email, person.Email); Assert.AreEqual(proc.ReturnValue <int>(), 200); Assert.AreEqual(proc.GetValue <long>("sqlErrorId"), 0); Assert.AreEqual(proc.GetValue <string>("messageResult"), null); }
public static void Main(string[] args) { var hotel = new Hotel(); var animalFactory = new AnimalFactory(); var procedureFactory = new ProcedureFactory(); AnimalCentree animalCentre = new AnimalCentree(hotel, animalFactory, procedureFactory); var commandParser = new CommandParser(); var dataWriter = new ConsoleDataWriter(); var dataReader = new ConsoleDataReader(); var engine = new Engine( animalCentre, commandParser, dataReader, dataWriter); engine.Run(); }
public void LoadFromParameters1() { Person person = new Person() { FirstName = "Bill", LastName = "Buzz", Email = "*****@*****.**" }; Procedure proc = ProcedureFactory.GetProcedure("open", "POST_PERSON"); proc["firstName"] = person.FirstName; proc["lastName"] = person.LastName; proc["email"] = person.Email; //returning person Person result = proc.ExecuteJson <Person>(); Assert.AreNotEqual(result.PersonId, person.PersonId); Assert.AreEqual(result.FirstName, person.FirstName); Assert.AreEqual(result.LastName, person.LastName); Assert.AreEqual(result.Email, person.Email); Assert.AreEqual(proc.ReturnValue <int>(), 200); Assert.AreEqual(proc.GetValue <long>("sqlErrorId"), 0); Assert.AreEqual(proc.GetValue <string>("messageResult"), null); }
/// <summary>Sets the parameters values from Json. Note that when the Json provides a list the parameter must have a user defined table type as the parameter.</summary> /// <param name="Json">Json string.</param> public void LoadFromJson(string Json) { using (var rdr = new JsonTextReader(new StringReader(Json))) { string propertyName = null; object propertyValue = null; while (rdr.Read()) { JsonToken tkn = rdr.TokenType; if (tkn == JsonToken.PropertyName) { propertyName = rdr.Value.ToString(); continue; } if (isTokenValue(tkn)) { propertyValue = rdr.Value; SetValue <object>(propertyName, propertyValue); propertyName = null; propertyValue = null; continue; } if (tkn == JsonToken.StartArray) { Parameter parameter = GetParameter(propertyName); DataTable dataTable = ProcedureFactory.GetDataTable(parameter.DataTypeName); DataRow dataRow = null; string columnName = null; object columnValue = null; while (rdr.Read()) { JsonToken child = rdr.TokenType; if (child == JsonToken.StartObject) { dataRow = dataTable.NewRow(); continue; } if (child == JsonToken.PropertyName) { columnName = rdr.Value.ToString().ToUnderscore(); continue; } if (isTokenValue(child)) { columnValue = rdr.Value; dataRow[columnName] = columnValue; continue; } if (child == JsonToken.EndObject) { dataTable.Rows.Add(dataRow); continue; } if (child == JsonToken.EndArray) { SetValue <object>(propertyName, dataTable); propertyName = null; propertyValue = null; break; } } } } } }
public static Task AddReturnValueToEachProcedureAsync(this ProcedureFactory factory) { return(Task.Factory.StartNew(() => AddReturnValueToEachProcedure(factory))); }