public Task <RPResult> SendAndReceiveAsync(RPCall call) { RPResult result = new RPResult(); switch (call.procedureName) { case "CommandContact": result.dt = th.GetTestPersonDataTable(); break; case "CommandUpsert": result.success = 1; break; case "CommandGetCompanies": result.dt = th.GetTestCompanyDataTable(); break; default: break; } var tcs = new TaskCompletionSource <RPResult>(); tcs.SetResult(result); return(tcs.Task); }
public RPResult Execute(RPCall call) { RPResult result = new RPResult(); result.success = DatabaseFactory.Factory().DeleteCompany(Int32.Parse(call.procedureArgs[0])); return(result); }
public RPResult Execute(RPCall call) { RPResult test = new RPResult(); test.count = 12345; return(test); }
/// <summary> /// Handles incoming requests. /// </summary> /// <param name="ctx">The HttpListenerContext returned by the HttpListener</param> public void HandleConnection(IHttpConnection con) { try { StreamReader msg = con.GetClientData(); try{ RPCall clientCall = Deserialize(msg); ICommand requestedCommand; if (!CommandDictionary.Instance.GetCommand(clientCall.procedureName, out requestedCommand)) { // Wahrscheinlich besser eine eigene Exception zu schreiben und 404 zurückgeben. throw new InvalidOperationException(); } RPResult result = requestedCommand.Execute(clientCall); byte[] buffer = Encoding.UTF8.GetBytes(Serialize(result)); con.SendReponseData(buffer); } catch (Exception ex) { // Deserialization did not work aborting. if (ex is InvalidOperationException || ex is ArgumentNullException) { Console.WriteLine(ex.Message); con.SendErrorCode(500); return; } throw; } } catch (HttpListenerException ex) { // Can't really do anything at this point. Console.WriteLine(ex.Message); return; } }
string Serialize(RPCall call) { StringWriter writer = new StringWriter(); _RPCallSerializer.Serialize(writer, call); return(writer.ToString()); }
public RPResult Execute(RPCall call) { RPResult result = new RPResult(); result.success = DatabaseFactory.Factory().UpsertInvoice(call.dt); return(result); }
public RPResult Execute(RPCall call) { RPResult result = new RPResult(); result.dt = DatabaseFactory.Factory().GetCompany(Int32.Parse(call.procedureArgs[0])); result.dt.TableName = "Company"; return(result); }
internal async Task <RPResult> UpsertInvoice(Invoice invoice) { RPCall call = new RPCall("CommandUpsertInvoice"); call.dt = Invoice.CreateTable(); call.dt.Rows.Add(invoice.ToDataRow(call.dt)); return(await _client.SendAndReceiveAsync(call)); }
public void CommandGetCompaniesReturnsCorrectTable() { RPCall call = new RPCall(); CommandGetCompanies com = new CommandGetCompanies(); RPResult ret = com.Execute(call); Assert.AreEqual(ret.dt.TableName, "Companies"); Assert.IsTrue(TestHelper.CompareDataTables(ret.dt, _th.GetTestCompanyDataTable())); }
public void CommandUpsertIsSuccessful() { RPCall call = new RPCall(); call.dt = _th.GetTestPersonDataTable(); CommandUpsert com = new CommandUpsert(); RPResult ret = com.Execute(call); Assert.AreEqual(1, ret.success); }
public void CommandGetCompanyReturnsCorrectTable() { RPCall call = new RPCall(); call.procedureArgs = new string[] { "1" }; CommandGetCompany com = new CommandGetCompany(); RPResult ret = com.Execute(call); Assert.IsTrue(TestHelper.CompareDataTables(ret.dt, _th.GetTestCompanyDataTable())); }
/// <summary> /// Search for a specific contact. /// </summary> /// <param name="name">The contacts name</param> /// <returns></returns> public async Task <RPResult> SearchContactsAsync(string name) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException(); } RPCall call = new RPCall("CommandContact"); call.procedureArgs = new string[] { name }; return(await _client.SendAndReceiveAsync(call)); }
public void CommandDeleteCompaniesDeletesCorrectAmount() { RPCall call = new RPCall(); call.procedureArgs = new string[] { "1" }; CommandDeleteCompany com = new CommandDeleteCompany(); RPResult ret = com.Execute(call); Assert.AreEqual(1, ret.success); }
public RPResult Execute(RPCall call) { List <Contact> companies = DatabaseFactory.Factory().GetCompanies(); ContactListConverter conv = new ContactListConverter(); RPResult ret = new RPResult(); ret.dt = (DataTable)conv.ConvertTo(null, null, companies, typeof(DataTable)); ret.dt.TableName = "Companies"; return(ret); }
public async Task <RPResult> SearchInvoicesAsync(InvoiceSearchData data) { BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(); binaryFormatter.Serialize(memoryStream, data); RPCall call = new RPCall("CommandInvoice", memoryStream.GetBuffer()); return(await _client.SendAndReceiveAsync(call)); }
public async Task <RPResult> SendAndReceiveAsync(RPCall call) { StringContent sendCall = new StringContent(Serialize(call).ToString()); HttpResponseMessage response = await _client.PostAsync("http://localhost:12345/", sendCall); response.EnsureSuccessStatusCode(); string resultString = await response.Content.ReadAsStringAsync(); RPResult result = Deserialize(resultString); return(result); }
public void CommandContactReturnsCorrectTable() { RPCall call = new RPCall(); call.procedureArgs = new string[] { "Max" }; CommandContact com = new CommandContact(); RPResult ret = com.Execute(call); Assert.AreEqual(ret.dt.TableName, "Contacts"); Assert.IsTrue(TestHelper.CompareDataTables(ret.dt, _th.GetTestPersonDataTable())); }
public RPResult Execute(RPCall call) { if (call.procedureArgs == null || call.procedureArgs.Length < 1) { throw new InvalidOperationException(); } List <Contact> contacts = DatabaseFactory.Factory().SearchContacts(call.procedureArgs[0]); ContactListConverter conv = new ContactListConverter(); RPResult retVal = new RPResult(); retVal.dt = (DataTable)conv.ConvertTo(null, null, contacts, typeof(DataTable)); retVal.dt.TableName = "Contacts"; return(retVal); }
/// <summary> /// Send a Contact object to be updated or Inserted /// into the database if it does not already exist. /// </summary> /// <param name="contact">The contact to be inserted or updated</param> /// <returns> /// A RPResult object its success field determines /// wether the query was successful(1) or not(0). /// </returns> public async Task <RPResult> SendContactAsync(Contact contact) { if (contact == null) { throw new ArgumentNullException(); } RPCall call = new RPCall("CommandUpsert"); List <Contact> temp = new List <Contact>() { contact }; ContactListConverter conv = new ContactListConverter(); call.dt = (DataTable)conv.ConvertTo(null, null, temp, typeof(DataTable)); return(await _client.SendAndReceiveAsync(call)); }
public RPResult Execute(RPCall call) { try { List <Contact> contact = CreateContactList(call.dt); DatabaseFactory.Factory().UpsertContact(contact[0]); RPResult retVal = new RPResult(); retVal.success = 1; return(retVal); } catch (Exception ex) { if (ex is InvalidOperationException || ex is ArgumentNullException) { RPResult retval = new RPResult(); retval.success = 0; return(retval); } throw; } }
public RPResult Execute(RPCall call) { List <Invoice> invoices = null; DataTable table = null; if ((call.Buffer == null || call.Buffer.Length < 1) && (call.procedureArgs == null || call.procedureArgs.Length < 1)) { throw new InvalidOperationException(); } else if (call.Buffer != null) { BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(call.Buffer); InvoiceSearchData data = (InvoiceSearchData)binaryFormatter.Deserialize(memoryStream); invoices = DatabaseFactory.Factory().SearchInvoices(data); } else { invoices = DatabaseFactory.Factory().SearchInvoices(Int32.Parse(call.procedureArgs[0])); } table = Invoice.CreateTable(); foreach (Invoice invoice in invoices) { table.Rows.Add(invoice.ToDataRow(table)); } table.AcceptChanges(); RPResult retVal = new RPResult(); retVal.dt = table; retVal.dt.TableName = "Invoices"; return(retVal); }
internal async Task <RPResult> DeleteCompany(int p) { RPCall call = new RPCall("CommandDeleteCompany", new string[] { p.ToString() }); return(await _client.SendAndReceiveAsync(call)); }
RPCall Deserialize(StreamReader reader) { RPCall call = (RPCall)_RPCallSerializer.Deserialize(reader); return(call); }
internal async Task <RPResult> SearchCompany(int p, string company) { RPCall call = new RPCall("CommandSearchCompany", new string[] { p.ToString(), company }); return(await _client.SendAndReceiveAsync(call)); }
public async Task <RPResult> SearchContactInvoicesAsync(int id) { RPCall call = new RPCall("CommandInvoice", new string[] { id.ToString() }); return(await _client.SendAndReceiveAsync(call)); }
/// <summary> /// Returns all available companies /// </summary> /// <returns>A RPResult with the companies in its "dt" field</returns> public async Task <RPResult> GetCompaniesAsync() { RPCall call = new RPCall("CommandGetCompanies"); return(await _client.SendAndReceiveAsync(call)); }
internal async Task <RPResult> SetCompany(int?id) { RPCall call = new RPCall("CommandSetCompany", new string[] { id.Value.ToString() }); return(await _client.SendAndReceiveAsync(call)); }