|
127.0.0.1 and localhost are the same thing.
And neither is going to connect to anything but the box, the exact box, that originated the request.
For the internet an actual addressable IP must be public. Local networks can use private IP addresses.
HTTP uses IP addresses. Host names just are resolved to a IP address.
If the above is new to you then you can start by reading the following
IP address - Wikipedia[^]
|
|
|
|
|
It's not new.
The console won't accept wildcards
http: is not allowed. So, if the console requires a port #, and we are not allowed to use a static port #, then I don't see how this can work.
The question still is, how is there sample app doing it? If their app's redirectURI is 127.0.0.1 (according to the credentials JSON), and the client code is using a random port, then how does it work??
[UPDATE]
For some reason I can't explain, this now works
string listenerURI = $"http ://127.0.0.1:{GetRandomUnusedPort()}/";
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
modified 27-Jun-23 13:15pm.
|
|
|
|
|
|
Hey guys,
i was facing an error on my logging today which made me struggle a bit.
To clarify the issue i wanted to know if anyone knows such things happen on a regular basis or is just bad luck.
We are within a REST Endpoint where multiple users fire requests to, the Endpoint will then process all these requests async and return the results.
There problem happened here (i narrowed it down to the important parts and underlined them):
private ProjectInformationBase? GetProjectBaseByDevelopmentProject(Guid idProject)
{
const string getProject = "SELECT * FROM Projects WHERE idProject = @idProject";
var getProjectCommand = new SqlCommand(getProject, DbConnection);
getProjectCommand.Parameters.Add("@idProject", SqlDbType.UniqueIdentifier).Value = idProject;
var projectData = getProjectCommand.ReadDataByCommand();
if (projectData.Rows.Count == 1)
{
return new ProjectInformationBase
{
IdProjectInformationBase = (Guid)projectData.Rows[0]["idProject"],
};
}
return null;
}
private ProjectInformationBase? GetProjectBaseByEcrProject(Guid idProject)
{
const string getEcrProject = "SELECT * FROM EcrProject WHERE ecrIdProject = @idProject";
var getEcrProjectCommand = new SqlCommand(getEcrProject, DbConnection);
getEcrProjectCommand.Parameters.Add("@ecrIdProject", SqlDbType.UniqueIdentifier).Value = idProject;
var projectData = getEcrProjectCommand.ReadDataByCommand();
if (projectData.Rows.Count == 1)
{
try
{
return new ProjectInformationBase
{
IdProjectInformationBase = (Guid)projectData.Rows[0]["ecrIdProject"],
};
}
catch (Exception e)
{
throw;
}
}
return null;
}
On the log it said the column "idProject" wasn't found, which looks to me like it was using the wrong method / sql request or dataTable "projectData". Honestly i thought since they get created and populated each time they should be "threadsafe" and not interfere with each other.
Anyone care to explain what could have happened here?
*Edit**Also filled in the blank code lines*
Please note that the "DbConnection" is defined within the class and the class is registered as Singleton.
I could not come up with a better title, but to explain what i mean by that.
The error produced was, that within the Method for getting the Development Project, the result table did not contain a column with "idProject". This error should never happen, because we only read if we have exactly 1 row and the table on the SQL Server hasn't been changed for ages, nor are there null rows inside.
What I thought of now is that if both methods being executed, for some magical reason it could happen, because of the same names for variables within both of these methods, that the development project retrieval gets the result table of the ecr project which obviously does not contain that "idProject" column.
I have no other explanation for that issue, therefore I wanted to know if someone else could have an idea where it possibly could go wrong instead.
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
modified 21-Jun-23 5:15am.
|
|
|
|
|
Where is getProjectCommand defined, and what does the ReadDataByCommand method look like?
Is there a reason you're using SELECT * FROM ... instead of specifying the list of columns you want to load? That usually leads to performance problems, where you're loading more data that you actually need.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The Command is defined in that "..." area, i just didn't want to bloat all the code inside.
ReadDataByCommand is a simple extension:
public static DataTable ReadDataByCommand(this SqlCommand command, bool mapResultsToDatabase = true)
{
try
{
using (var sqlDataAdapter = new SqlDataAdapter(command))
{
var resultTable = new DataTable();
if (mapResultsToDatabase)
{
sqlDataAdapter.FillSchema(resultTable, SchemaType.Mapped);
}
sqlDataAdapter.Fill(resultTable);
return resultTable;
}
}
catch (SqlException ex)
{
var exNew = new Exception(command.BuildErrorMessage(), ex);
throw exNew;
}
catch (InvalidOperationException ex)
{
var exNew = new Exception(command.BuildErrorMessage(), ex);
throw exNew;
}
catch (Exception ex)
{
var exNew = new Exception(command.BuildErrorMessage(), ex);
throw exNew;
}
}
I am loading all columns because i'll need all in the future, for testing purposes we just read out one yet.
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
|
|
|
|
|
Nothing obviously wrong there. However:
Quote: Please note that the "DbConnection" is defined within the class and the class is registered as Singleton.
That's a really bad idea. Every request will be fighting to use the same connection instance.
Instead, create the connection when you need it, and wrap it in a using block to ensure it's always disposed of properly when you've finished with it.
Connection pooling[^] will automatically take care of keeping a pool of database connections hanging around in case you're worried about the cost of creating the connection.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I do know and found that out earlier, i think this is actually the only place where those two methods will do this. So you think it could be related to that?
Because I had worse issues in the past and then decided that each time a request to the SQL Server gets fired we will create a new connection, with the exception of queries that need to be done one after another in a single method.
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
|
|
|
|
|
The SqlConnection class isn't thread-safe. If you're storing a single connection instance in a field of a singleton class, and then using that for queries across multiple threads, I wouldn't be surprised if the queries ended up with some cross-contamination.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
After reading that, i must admit, yes. I have no other words to describe my feelings right now
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
|
|
|
|
|
OK but can you expand on what you mean by "threading related naming and usage of const" though?
The var projectData in each method are completely unrelated by the way. They're different variables, having the same name doesn't have any meaning except to humans who read the source code.
|
|
|
|
|
I'll update that in the initial post.
I would assume so too, because everything is only declared and instantiated in each method separately. Nonetheless I had this strange behavior.
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
|
|
|
|
|
I think the usual convention is to "capitalize" column names in the database; to avoid the confusion you're experiencing with similar looking "variables".
I would think the "data base column definitions" should be looked at. Maybe somebody changed them when you weren't looking. There's nothing to indicate you're actually accessing the correct database or table (connection strings).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Expanding a bit more on why more than one DBConnection is needed.
This is not just a feature of the class. Rather it is the nature of the connection to the database itself.
For example most if not all databases have an explicit 'transaction' (in some definition of that word) when a statement runs across the connection. Regardless of whether the transaction type is changed by the code. And this is tied to the connection itself.
So for example a long running query (seconds hopefully and not minutes) has transaction type X. Then you attempt to use it in another process thread where you want to change the transaction type to Y. And then you send that second statement down the same connection. Which transaction is then in play.
Why do they do it that way? Because if the connection is lost the database must decide whether the currently running statement succeeded or failed. And different database DO decide that differently. Some decide it success which means they might commit a transaction. Others deem it a failure, so the fail the transaction.
|
|
|
|
|
Yep, you are absolutely right. I already was able to "reconstruct" that behavior and it is simply the lack of connections established that leads to this problem. So basically each time i need to do a query which is not part of a greater transaction we open up another connection. Issue solved
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
|
|
|
|
|
I've brought up the FontDialog to select the font for my custom terminal windows (3 terminal windows in 1 app). The FontDialog doesn't show this installed "Terminal" font. Can anyone give me some pointers to enable me to use this font?
Thanks!
|
|
|
|
|
Quote: Cascadia Code is a new monospaced font from Microsoft that provides a fresh experience for command-line applications and text editors. Cascadia Code was developed alongside Windows Terminal. This font is most recommended to be used with terminal applications and text editors such as Visual Studio and Visual Studio Code.
Windows Terminal Cascadia Code | Microsoft Learn
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Myself I am more curious as to the original question - why doesn't it show up.
How do you know it is installed? On my Windows 10 box I looked in the C:\Windows\Fonts folder and also via the Control Panel. It is there.
Also when I open Notepad I can see it there also.
Presumably you are using the default ctor when you create the FontDialog(). When I look at the docs the default suggests that it should load all of the Fonts.
Given that I have not tried it but could it just be somewhere else in the list?
|
|
|
|
|
'Terminal' is an old style bitmap font. Characters are drawn as white and black pixels in a fixed size rectangle, e.g. 7×11 pixels. The character size depends on the resolution (DPI) of your screen. You can identify Terminal as a bitmap font by the filename extension .fon. You will see a number of other .fon files in the Fonts directory, but note that the file name may be different from the font name, and each variation (bold, italics etc.) is in a different file. Some bitmap fonts also have different size variants.
Bitmap fonts are not scalable, except by integer factors, by drawing each pixel in the character definition as a 2×2 or 3×3 block of identical pixels. In large sizes, characters look as if shaped from Lego bricks.
All modern font formats (i.e. from Windows 3.1 and later) Bezier curves to describe the outline of a character. Bezier curves are continuous functions that can be scaled up and down with no resolution issues.
Bitmap fonts were suitable when almost all screens were 600×800 pixels, high resolution ones were 800×1024. Today, 7×11 pixels on a smartphone display is a tiny little speck. So most software consider un-scalable fonts an outdated technology, dropping support for it. (Compare it to character encoding: Old time editors could save your text in 7-bit ASCII with even, odd or no parity. I haven't seen that option for thirty years!)
Windows has APIs for enumerating all fonts, including bitmap ones, and support for them is still provided. You may use them in your own application, and you may provide a font selector displaying them as alternatives. The enumeration functions have filtering options, and if you want to further limit the options, the returned info contains a lot of properties that you may test before adding them to your font select dialog.
The only significant advantage of bitmap fonts is that rendering is super fast. If you run an 8-bit embedded system with a 48×160 pixels display, and the single button cell should should last for a year, then bitmap fonts are for you. Otherwise: Probably not. It makes sense for Windows and Windows applications to drop support for them. (Windows itself still has support, but user interfaces may skip bitmap fonts, as being obsolete.)
|
|
|
|
|
You don't want to use Terminal.
It is a 40-year-old bitmap "font" that does not support Unicode and is not scalable. It's basically a bunch of bitmap images with characters at different sizes. If you try to use a size that doesn't exist, you get a scaled up or down version (done badly!) to the required size.
You cannot turn the font back on as it, and all the other bitmap fonts, have been deprecated. They are still distributed with Windows for backward compatibility, but the FontDialog provided by the system (which the .NET class of the same name wraps) will not show them.
Any old code that uses the old fonts has to include specific code to be able to use them. It is not the same as code used to day to use an of the scalable font types.
The suggested replacement for Terminal is Consolas.
|
|
|
|
|
Very interesting!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Dave Kreskowiak wrote: but the FontDialog provided by the system (which the .NET class of the same name wraps) will not show them.
That would answer the original question then.
|
|
|
|
|
Just for nitpicking: Even if the system FontDialog doesn't show 'Terminal', the OP may very well be 'enabled to use this font', as he were asking. You can't force the system FontDialog box to show it, but you can write your own FontDialog, including all the alternatives that you would like to appear.
|
|
|
|
|
Hi, I have the following get / set class,...
internal class PostSections
{
public string title { get; set; }
public string[] highlight { get; set; }
public string[] highlight2 { get; set; }
public bool highlightFirstWord { get; set; }
public bool sendToValidation { get; set; }
public string startDate { get; set; }
public string endDate { get; set; }
public Sectionquery[] sectionQueries { get; set; }
}
public class Sectionquery
{
public string id { get; set; }
public string name { get; set; }
public string[] keywords { get; set; }
public bool active { get; set; }
}
I can set the values for 'title', 'highlight' etc., but I cannot work out how to reference and set the values for items within the 'Sectionquery' class, eg: id, name, keywords and active.
Here's my code,...
var newPost = new PostSections()
{
title = "Title of Book",
highlight = list.ToArray(),
highlight2 = list.ToArray(),
highlightFirstWord = false,
sendToValidation = false,
startDate = "2022-11-22T00:00:00.000Z",
endDate = "2022-11-22T00:00:00.000Z",
sectionQueries = new Sectionquery[] { }
};
Using the above, my API call works, however I need to set values within that Sectionquery before calling the API. How to I reference them?
Hope my question's clear, thanks in advance.
|
|
|
|
|
Your array creating won't work - it creates an empty array (no elements) and an array can't be expanded or contracted.
Try doing the Sectionquery creating outside the PostSections instance creation: otherwise it gets confusing. The way I'd do it is to replace the array with a list to be more flexible:
internal class PostSections
{
public string title { get; set; }
public string[] highlight { get; set; }
public string[] highlight2 { get; set; }
public bool highlightFirstWord { get; set; }
public bool sendToValidation { get; set; }
public string startDate { get; set; }
public string endDate { get; set; }
public List<Sectionquery> sectionQueries { get; set; }
} That way, you can start by declaring the collection:
var queries = new List<Sectionquery>() And add your new items to it (even from a JSON / XML / CSV file or a database) without knowing in advance how many elements it needs.
Then just add your new items to it:
queries.Add(new SectionQuery() { ... });
queries.Add(new SectionQuery() { ... });
... And then change your PostSection instance creation to suit:
var newPost = new PostSections()
{
title = "Title of Book",
highlight = list.ToArray(),
highlight2 = list.ToArray(),
highlightFirstWord = false,
sendToValidation = false,
startDate = "2022-11-22T00:00:00.000Z",
endDate = "2022-11-22T00:00:00.000Z",
sectionQueries = queries
}; Make sense?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|