|
minor quibbles: while I am aware of the newer features:
where T : Enum
use of 'default
they are not as simple to use as one might expect:
1. where T : struct, Enum ... fails without 'struct, and 'struct must precede 'Enum
2. 'default cannot be used directly ... WeekDays.Default throws an error ... however this will work:
((WeekDays) default).ToEnum<weekdays>("friday", true);
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
BillWoodruff wrote: 1. where T : struct, Enum ... fails without 'struct, and 'struct must precede 'Enum
Yes, for some odd reason an Enum constraint doesn't automatically imply a struct constraint.
As a result, it's possible to use where TEnum : class, Enum , which will compile but can never be satisfied.
But it's still better than not having the constraint.
BillWoodruff wrote: 2. 'default cannot be used directly ... WeekDays.Default throws an error
The default literal can be assigned to a variable of any type, or used as the default value of an optional parameter of any type.
It doesn't add a new member to the enum, so WeekDays.default won't work if the WeekDays enum doesn't already contain a default entry.
If you want to use the default value without assigning to a variable, you can use default(WeekDays) instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
reading between the lines, i almost had the feeling you thought theses comments were relevant
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
I have a couple of static methods that attempt to establish the correct enum value from the specified string (or int). I use them when loading data from a source that could potentially be corrupted by manual modifications by fat-fingered idiot users.
public static T IntToEnum<T>(int value, T defaultValue)
{
T enumValue = (Enum.IsDefined(typeof(T), value)) ? (T)(object)value : defaultValue;
return enumValue;
}
public static T StringToEnum<T>(string value, T defaultValue)
{
T enumValue = (Enum.IsDefined(typeof(T), value)) ? (T)Enum.Parse(typeof(T), value) : defaultValue;
return enumValue;
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
i would not use Enum.IsDefined: [^], [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
I've never had a problem with that code.
It should return false if the spelling/case is wrong.
If it makes you feel more comfortable, you could change the code to use enum.TryParse instead of enum.Parse .
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 22-Apr-20 13:59pm.
|
|
|
|
|
I share information with no expectation anyone will use it. Since this is a language discussion forum, not QA, I believe "going deep" is appropriate.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 23-Apr-20 4:20am.
|
|
|
|
|
I wasn't complaining.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I didn't interpret your response as complaining ... my crystal ball can't read Texan minds
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Does anyone know how to add the sas.dll to a c# app?
|
|
|
|
|
Yes.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Succinct.
To the point.
Accurate.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Hi all, I have a net core WebAPI running on a Linux box on my local LAN it all works as expected until I try to access it from outside my Lan.
What I've done
Forwarded the listening port on my router to the local ip and port on my Lan where the WebAPI resides.
Result when calling a controller method
404 not found, the API is using Nginx as a reverse proxy and I'm thinking maybe this is not configured to accept requests from the outside ( but this a guess ) - any ideas guys ?
Please let me know if I haven't supplied enough information
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
modified 21-Apr-20 7:50am.
|
|
|
|
|
You shouldn't need to configure anything on your WebAPI to make it work externally vs Internally.
If the endpoint your trying to hit works from the local lan, then it should work from any source that hit's the correct API, if your getting a 404 AND your sure the traffic is getting from the outside to the inside and actually hitting your web API then it's because the routing in the dotnet app is not working.
If the traffic is getting to the internal IP, but NOT being redirected to the WebAPI, then the problem is with your forwarding server, most likely the server is trying to handle the request instead of proxying it out to the required destination.
The FIRST thing to check is the log files for your proxy forwarder, if your using Nginx then these should normally be in something like /var/log/nginx on a linux server (Can't help if it's winyhoos sorry), you should try "tail -f <logfilename>" in an ssh window while you throw a request at the IP so you can see it in real time.
If the access log shows activity, then you don't have your proxy forward configured correctly, but you don't have any config errors either.
If the error log shows activity, then you have a configuration error and the error log should tell you what to do.
My gut feeling from your description is that your going to see activity on your access log, not on your error log....
But I'll leave that until your reply....
Shawty
|
|
|
|
|
Hi Peter - I figured it out - I was forwarding to the wrong port - I wrongly thought I should forward to the port my service runs on - but of course nginx is in the mix and listens on port 80 - I added another http server {} block to my nginx config file which listens for the remote port and bingo it worked. I need to study what you sent me.
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
Glad you got it sorted
This stuff was my bread and butter for quite a few years from 2004 to 2009, I worked primarily as a network infrastructure engineer here in the UK for one of the large 4 Mobile Telco companies
Fun times.....
|
|
|
|
|
Just for completeness I'd like to deploy it to a public server ( another thing I've never done ) as I have ideas about adding something similar to one of my paying apps - any recommendations on a host and how to go about it ? Once again thanks for your help
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
I host most of my external apps on Linode.
You basically get a VM to do with as you please, the cost is about $20 per month for the lowest offering which is plenty powerful enough to run a few dotnet core apps with PostgreSQL as a DB and nginx as the front end proxy.
You get 3TB monthly allowance, and if you run over it's a pay as you use model at something like 1c for every 1000mb you go over...
I generally run Ubuntu on the ones I set up, what I tend to do is build a VM inside my own DC with the same specs as the linode, furnish said VM with Jenkins, dotnet core and nginx.
I then set Jenkins up to check my git server, and every time I check in, Jenkins builds and deploys the dotnet core app to the same VM, one I'm happy the built one's working I manually run the second job on jenkins which takes the deployed service pushes it to a separate GIT server, that the Linode VM is monitoring, when it sees a new build, it pulls that ready built to the linode, and deploys it.
With this process, I can basically check a change in on my desktop using visual studio, wait a couple of minutes, validate the build on staging, then click a button in a web page and it's live in about 5 mins.
I can go from VS to live usually in about 30 mins.
|
|
|
|
|
Blimey way out of my league
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
I should probably write a Code Project Article about it
|
|
|
|
|
I think you should
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
Hi Peter, I have successfully installed my net core service on a Linode box and associated it with a domain name. I'm know looking at how I can push local changes to the service up to the linode box, you say you have yours monitoring GitHub - how do you do that ? Thanks for all your help
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
modified 27-Apr-20 3:01am.
|
|
|
|
|
I don't have it monitoring github, but it could be used to do so.
Basically though, it's quite simple.
Most people think that git/github is just for source code, but if you think outside the box, it's for anything that you want to keep track of "changes".
I have my own private git server, that I run under IIS using the fantastic, and free .NET Bono Git server software.
On my linode I use exactly the same process as I do on my build server, namely I have "Jenkins Continuous Integration Server" watching a specific git repo for changes, then reacting when it sees a change.
That reaction, is simply to shut down the running service, git pull the latest version to the linode server, then start the service back up.
The thing that's different about the git server it pulls from, is that, all that git server holds is the compiled binary. No source code, no nothing, just the files needed to run the app.
When ever the build server makes a successful build, it pushes the new build into the git repo holding the binary s, a minute or so later, jenkins running on the linode server detects this and does what it needs to to deploy the new version.
|
|
|
|
|
Hi Peter, I thought you'd gotten fed up with me pestering you That sounds a very neat way of deploying it - I didn't realise Jenkins works on a Linux box I've only ever used it for building nuget packages I'll check it out - thanks again
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|