|
I did another test:
I renamed
CefSharp.Core.dll to something else.
This dll is listed in the references.
The resolve function was successfully triggered.
Okay, so the question is, how do I embed everything and create one stand-alone exe?
How can I embed all resources not only the dll's but everything needed in the exe?
This is what I originally wanted.
|
|
|
|
|
You can only embed .NET .DLL's. If it's a C/C++ library .DLL, it cannot be embedded into the executable.
The library .DLL's are not loaded through the .NET CLR binding mechanism, so they will not have a binding event triggered for them.
modified 21-Apr-20 10:21am.
|
|
|
|
|
I now have a net core api service up and running on a Linux box using Nginx as a reverse proxy server, I can call all of the controller methods that don't have parameters and they return collections of my custom classes. But I'm stuck on one get method that requires a custom class as an input parameter, the controller method code is below
[HttpGet]
[ActionName("GetBOM")]
public ActionResult<bomparam> GetBOM([FromBody] BOMParam bp)
{
// This calls my DAL which queries a database and returns the bp populated with various values
return businessLayer.APIGetBOM(bp);
}
What I can't figure out is how to pass a class instance as a parameter to the method using RestSharp
This is what I've tried
Hide Copy Code
RestClient client = new RestClient("http://IPOfRestService:Port/GetBOM");
RestRequest request = new RestRequest(Method.GET);
BOMParam bp = new BOMParam();
bp.ValveCode = "80044-08";
bp.Torque = 20;
bp.DirectFit = false;
bp.BarPressure = 6;
request.AddJsonBody(bp);
IRestResponse response = client.Execute(request);
I get a not found back in the response object.
Can't find anything googling so thought I'd try here
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
|
Hi Gerry, I followed that link and the only thing the guy was doing differently to me was issuing a Post whereas mine is a Get - apparently it's frowned upon to add a body to a Get request , so I modified my Controller and it worked - it's not returning what I expect but that's probably anther story - thanks for the heads up
Edit
Using the RestSharp deserializer doesn't map the property names that are in different case though , JsonSoft does
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
modified 19-Apr-20 7:30am.
|
|
|
|
|
How to get the status of files that are sent for Printing through VS 2015?
|
|
|
|
|
To monitor the status of a printer from an interactive application, add a reference to the System.Printing assembly, use the PrintServer class[^] to enumerate the print queues, and use the returned PrintQueue[^] instance to monitor the queue.
NB: This is not supported within a Windows Service or ASP.NET project.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
SELECT p.pcode, p.pdesc, b.brand, c.category, p.price p.qty
FROM tblProduct
as p inner join tblBrand
as b on b.id = p.bid inner join tblCategory
as c on c.id = p.cid
where p.pdesc like '%'
--------------------------------------
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
|
|
|
|
|
You're missing a comma between the last two columns:
SELECT p.pcode, p.pdesc, b.brand, c.category, p.price p.qty should be:
SELECT p.pcode, p.pdesc, b.brand, c.category, p.price, p.qty
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Im trying to make loadData to datagridview in c#. Is there something wrong on my code?
public void LoadRec()
{
try
{
int i = 0;
dgvProduct.Rows.Clear();
_sqlConn.Open();
_sqlCmd = new SqlCommand("SELECT p.pcode, p.pdesc, b.brand, c.category, p.price, p.qty FROM tblProduct as p inner join tblBrand as b on b.id = p.bid inner join tblCategory as c on c.id = p.cid where p.pdesc like '" + txtSearchProd.Text + "%'", _sqlConn);
_sqlDR = _sqlCmd.ExecuteReader();
while (_sqlDR.Read())
{
i++;
dgvProduct.Rows.Add(i, _sqlDR[0].ToString(), _sqlDR[1].ToString(), _sqlDR[2].ToString(), _sqlDR[3].ToString(), _sqlDR[4].ToString(), _sqlDR[5].ToString());
}
_sqlDR.Close();
_sqlConn.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
_sqlConn.Close();
}
|
|
|
|
|
Yes. Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Also, don't store connection, command, or data reader objects in class-level fields. Create them as local variables when they're required, and wrap them in using blocks.
using (var sqlConn = new SqlConnection("..."))
using (var sqlCmd = new SqlCommand("SELECT p.pcode, p.pdesc, b.brand, c.category, p.price, p.qty FROM tblProduct as p inner join tblBrand as b on b.id = p.bid inner join tblCategory as c on c.id = p.cid where p.pdesc like @SearchProd + '%'", sqlConn))
{
sqlCmd.Parameters.AddWithValue("@SearchProd", txtSearchProd.Text);
sqlConn.Open();
using (var sqlDR = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection))
{
while (sqlDR.Read())
{
i++;
dgvProduct.Rows.Add(i, sqlDR[0].ToString(), sqlDR[1].ToString(), sqlDR[2].ToString(), sqlDR[3].ToString(), sqlDR[4].ToString(), sqlDR[5].ToString());
}
}
}
Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
When I try to execute the code Sir, there is no data displayed on my datagrid.
I also try the to run these query on my sqlserver.
SELECT p.pcode, p.pdesc, b.brand, c.category, p.price, p.qty
FROM tblProduct
as p inner join tblBrand
as b on b.id = p.bid inner join tblCategory
as c on c.id = p.cid
where p.pdesc like '%'
but theres no data showed.
|
|
|
|
|
Then there is no matching data in your database.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Start by cutting it down and trying it in SSMS:
SELECT p.pcode, p.pdesc, b.brand, c.category, p.price, p.qty
FROM tblProduct p
INNER JOIN tblBrand b
ON b.id = p.bid
WHERE p.pdesc LIKE '%'
And see if you get any rows.
If you don't, remove the JOIN and see what p.pid values you do get, then look at tblBrand to see if they exist. Remember that an INNER JOIN requires a matching entry in BOTH tables to return ANY rows.
If you do, add the second JOIN and see what you get.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have two classes like this
public myclass1
{
public int Id {set;get;)
public myclass2 MyClass2{set;get;)
}
public myclass2
{
public int Id {set;get;}
public string Name {set;get;}
}
public list<myclass1> mylist = new List<myclass1>() ;
my list has been bonded to datagridview .
when displying the collection in the grid , the myclass1 is displaying the object name "DomaninName.myclass2"
how to display the propery "Name" of myclass2
|
|
|
|
|
you can overwrite the ToString function
|
|
|
|
|
thank you it works fine for me .
|
|
|
|
|
First, fix the compilation errors in your code: use of ')" where it should be '}', missing class keyword on class definitions, missing uppercase on List , that sort of thing.
So us code that works to demonstrate your problem - not a lump of crap your threw together and didn't check at all ...
You can display what you want as the cell content, just override ToStrign in your class:
public class myclass2
{
public int Id { set; get; }
public string Name { set; get; }
public override string ToString()
{
return $"{Id}:{Name}";
}
}
You can also set the column header text to something more human readable than the property name - just set the HeaderText property of the column:
myDataGridView.DataSource = mylist;
myDataGridView.Columns[1].HeaderText = "My other class";
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have two c# form apps which use openFileDialog. One displays the targa bitmap with the system thumbnail in the corner (app1) and the other displays the system thumbnail(app2). The one which fails to display the targa bitmap shows the option to create a new folder while the other does not offer that option.
App1 I created using Microsoft tutorial1 Create a picture Viewer
App2 is called TargaImage_demo downloaded from this site.
I have compared the two projects making sure they use the same .Net framework but I cannot see why one works as I want it to do while the other fails to display the bitmaps.
Does anyone know why there is a difference between the two openFileDialogs?
|
|
|
|
|
Don't post this here - if you got the code from an article, then there is a "Add a Comment or Question" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
At a guess, have you called EnableVisualStyles[^] in one application but not the other?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
OpenFileDialog has nothing to do with displaying the image at all.
An OFD is only concerned with one thing, returning a string containing the path to a file. That's it. Nothing else.
The code to display the image is somewhere else and is where the problem appears to be.
|
|
|
|
|
Hi all,
I have a project which is divided to two parts:
1/ The first one is TCP handling message from a pertinant connection(so connection should be always connected till user disconnect it).
2/ The second part is another application which process the messages recieved.
So please for the first on how can handle message from a connection already established and send it internaly to the second project and after that reply.
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
THis is a broad subject with no real detail provided, and we can't just tell you what to do, because we have no idea what stage you are at already. Heck, we don't even know if the "second application" is a separate process from the first - and that's unbelievably relevant!
So answer the three questions above, and remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Dear all,
I have two applications:
Console one it server for Tcp pertinant socket :
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.IO;
namespace Asychn_Server
{
public class StateObject
{
public Socket workSocket = null;
public const int BufferSize = 1024;
public byte[] buffer = new byte[BufferSize];
public StringBuilder sb = new StringBuilder();
}
public class AsynchronousSocketListener
{
public static ManualResetEvent allDone = new ManualResetEvent(false);
public AsynchronousSocketListener()
{
}
public static void StartListening()
{
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);
Socket listener = new Socket(ipAddress.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
try
{
listener.Bind(localEndPoint);
listener.Listen(100);
while (true)
{
allDone.Reset();
Console.WriteLine("Waiting for a connection...");
listener.BeginAccept(
new AsyncCallback(AcceptCallback),
listener);
allDone.WaitOne();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Console.WriteLine("\nPress ENTER to continue...");
Console.Read();
}
public static void AcceptCallback(IAsyncResult ar)
{
allDone.Set();
Socket listener = (Socket)ar.AsyncState;
Socket handler = listener.EndAccept(ar);
StateObject state = new StateObject();
state.workSocket = handler;
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReadCallback), state);
}
public static void ReadCallback(IAsyncResult ar)
{
String content = String.Empty;
StateObject state = (StateObject)ar.AsyncState;
Socket handler = state.workSocket;
int bytesRead = handler.EndReceive(ar);
if (bytesRead > 0)
{
state.sb.Append(Encoding.ASCII.GetString(
state.buffer, 0, bytesRead));
content = state.sb.ToString();
log("Socket status : " + handler.Connected);
log("From socket : " + content);
Send(handler, content);
log("Socket status : " + handler.Connected);
}
}
private static void Send(Socket handler, String data)
{
byte[] byteData = Encoding.ASCII.GetBytes(data);
handler.BeginSend(byteData, 0, byteData.Length, 0,
new AsyncCallback(SendCallback), handler);
}
private static void SendCallback(IAsyncResult ar)
{
try
{
Socket handler = (Socket)ar.AsyncState;
int bytesSent = handler.EndSend(ar);
log("TO socket : " + bytesSent + " -As reply");
log("Socket status send: " + handler.Connected);
allDone.Set();
log("Socket status send2: " + handler.Connected);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static int Main(String[] args)
{
StartListening();
return 0;
}
public static void log(string strLog)
{
StreamWriter log;
FileStream fileStream = null;
DirectoryInfo logDirInfo = null;
FileInfo logFileInfo;
string logFilePath = "C:\\Logs\\";
logFilePath = logFilePath + "LogServer-" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt";
logFileInfo = new FileInfo(logFilePath);
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
if (!logDirInfo.Exists) logDirInfo.Create();
if (!logFileInfo.Exists)
{
fileStream = logFileInfo.Create();
}
else
{
fileStream = new FileStream(logFilePath, FileMode.Append);
}
log = new StreamWriter(fileStream);
log.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + ": " + strLog);
log.Close();
}
}
}
And client one as Desktop Application:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
namespace Asynch_client_form_2
{
public partial class Form1 : Form
{
private const int port = 11000;
private static ManualResetEvent connectDone =
new ManualResetEvent(false);
private static ManualResetEvent sendDone =
new ManualResetEvent(false);
private static ManualResetEvent receiveDone =
new ManualResetEvent(false);
private static String response = String.Empty;
private static Socket client;
private void ConnectBtn_Click(object sender, EventArgs e)
{
try
{
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
client = new Socket(ipAddress.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
client.BeginConnect(remoteEP,
new AsyncCallback(ConnectCallback), client);
connectDone.WaitOne();
}
catch (Exception ex)
{
ExceptionTextBox.Text = ex.Message;
}
}
private void SendBtn_Click(object sender, EventArgs e)
{
try
{
Send(client, "MY message");
sendDone.WaitOne();
Receive(client);
MsgTextBox.Text = response;
}
catch (Exception ex)
{
ExceptionTextBox.Text = ex.Message;
}
}
private static void ConnectCallback(IAsyncResult ar)
{
try
{
Socket client = (Socket)ar.AsyncState;
client.EndConnect(ar);
connectDone.Set();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
private void DisConnectBtn_Click(object sender, EventArgs e)
{
client.Shutdown(SocketShutdown.Both);
client.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public Form1()
{
InitializeComponent();
}
private static void Receive(Socket client)
{
try
{
StateObject state = new StateObject();
state.workSocket = client;
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
}
catch (Exception e)
{
log(e.ToString());
}
}
private static void ReceiveCallback(IAsyncResult ar)
{
try
{
StateObject state = (StateObject)ar.AsyncState;
Socket client = state.workSocket;
int bytesRead = client.EndReceive(ar);
if (bytesRead > 0)
{
state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
}
else
{
if (state.sb.Length > 1)
{
response = state.sb.ToString();
log("Reply : " + response);
}
receiveDone.Set();
}
}
catch (Exception e)
{
log(e.ToString());
}
}
private static void Send(Socket client, String data)
{
byte[] byteData = Encoding.ASCII.GetBytes(data);
client.BeginSend(byteData, 0, byteData.Length, 0,
new AsyncCallback(SendCallback), client);
}
private static void SendCallback(IAsyncResult ar)
{
try
{
Socket client = (Socket)ar.AsyncState;
int bytesSent = client.EndSend(ar);
sendDone.Set();
}
catch (Exception e)
{
log (e.ToString());
}
}
public static void log(string strLog)
{
StreamWriter log;
FileStream fileStream = null;
DirectoryInfo logDirInfo = null;
FileInfo logFileInfo;
string logFilePath = "C:\\Logs\\";
logFilePath = logFilePath + "LogClient-" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt";
logFileInfo = new FileInfo(logFilePath);
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
if (!logDirInfo.Exists) logDirInfo.Create();
if (!logFileInfo.Exists)
{
fileStream = logFileInfo.Create();
}
else
{
fileStream = new FileStream(logFilePath, FileMode.Append);
}
log = new StreamWriter(fileStream);
log.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + ": " + strLog);
log.Close();
}
}
}
In Client i need to press connect in order to estabish socket
and after that press send bouton to send messages without disconnecting socket.
with this code i couldn't handle reply for my message from server.
Can someone help me please
|
|
|
|
|