|
I seem to recall a Google blog post (though I can't find it again) that said they leave themselves open to ICMP on purpose specifically so that people can use them to test Internet Access.
Also, Microsoft uses a similar idea for the Network Connectivity Icon in Windows. See http://blog.superuser.com/2011/05/16/windows-7-network-awareness/[^]
I don't know exactly what URL Apple uses but my iPod touch does the same thing.
|
|
|
|
|
Thank you, you answered some remaining questions I still had on the topic.
|
|
|
|
|
|
I just got this from someone else's project:
internal static bool IsInternetConnected(string webSite)
{
bool flag;
string str;
try
{
if (webSite == null)
{
str = "www.google.com";
}
else
{
str = webSite;
}
webSite = str;
Dns.GetHostEntry(webSite);
flag = true;
}
catch
{
flag = false;
}
return flag;
}
I think a little more than DNS is required to check internet connectivity.
|
|
|
|
|
I have to say that just checking for one web address is pretty poor!
In order to determine if an internet end point is available, check to see if the connection is there (via Ping, or what ever) and this if the timeout (only needs to be short) fails, then try the next node that will serve the desired result. once you have run out of nodes to check then you are offline. You may wish to try again later...
There may be blips at an endpoint caused by many events (power outage, load balancers, etc) which could (and do) lead to momentary drop outs. It is just that most browsers have quite a good timeout that they "just work" and the end user notices only a slightly slower page load than some drastic moment at a data centre!
But then I could be wrong!
|
|
|
|
|
Ladies and Gentlemen!
Direct, from the wonders of Q&A (no, names, no embarrassment - although it is most definately deserved):
SqlDataAdapter dad = new SqlDataAdapter("Select * from esrdat where esrdat_date between '" + Convert.ToDateTime(dateTimePicker1.Value) + "' and '" + Convert.ToDateTime(dateTimePicker2.Value) + "'", con);
Here, for your delectation we have:
1) Take a valid DateTime
2) Use a default conversion to a string
3) Convert it back to a DateTime
4) Then pass that (converted back to a string via another default conversion) to SQL
But in the local format, rather than anything SQL is expecting, which is ISO format.
Twice.
And it's in Q&A because SQL doesn't like the date format it eventually gets passed...
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Where's the first conversion? Is dateTimePicker.Value not a DateTime?
By the way I hope you answered the question as well as posting it here because that seems like newbie ignorance that deserves illumination.
|
|
|
|
|
You are right, I am wrong - somebody went to the work of adding a DateTime convertion routine that accepts a DateTime, and returns it, unchanged! (I suspect I would have deliberately omitted it, or thrown an exception if you tried to use it, just for being silly)
And yes I did.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
And let's add not using SQL parameters to avoid most of this to the list
I'm invincible, I can't be vinced
|
|
|
|
|
See? That's one of the problems with giving newbies a "Convert" class; they think they need it all the frickin' time -- they don't learn what it does or what alternatives there are.
|
|
|
|
|
And that's what I always say: Let them learn with an old school single board computer. Take away all fancy frameworks and operating systems and let them discuss things directly with the processor for a while. By the time we give them any compilers, they will already have gotten used to using that grey mass in their heads for other things than keeping the ears apart.
I'm invincible, I can't be vinced
|
|
|
|
|
...Or they run away screaming. win-win
|
|
|
|
|
In my experience, once you turn them into embedded programmers, they always think they have to roll their own. We've got a guy in our group like that. We're constantly having to tell him "No, just use class Mousetrap . Yes, yours is cool and all, but we've got lots of time on Mousetrap , plus it works with the rest of the architecture. No, yours doesn't."
Software Zen: delete this;
|
|
|
|
|
Making database queries in the presentation layer!!
"You get that on the big jobs."
|
|
|
|
|
So this is an approach that proved so successful that it was made into a standard. You're writing a shared library and you're concerned to ensure future compatibility across services. Problems include:
* How to support non built-in types? (e.g. MyCustomType)
* How to support float, int, double, etc?
* How to prevent constantly updating interfaces from complicating builds?
Best approach? Well, how about you convert all your arguments into Strings to transfer across the wire and then convert them back.
Every method has the following signature:
public String[] doSomething(String[] args, String userId)
Then you have a static library that allows:
TypeUtils.stringify(Object object);
Object obj = TypeUtils.fromString(String string, String fromType);
Easy. (Note you may need to cast the object returned from TypeUtils.fromString(). User id is there to ensure security, obviously. You don't have to use the TypeUtils but you are encouraged to, for convenience.
This way, when you swap args[2] and args[3], or when you introduce a new argument at the end, you don't have to declare a new version of the interface.
Simply keep the same version interface jar throughout and require everyone to use the very latest implementation.
This is why I don't program
|
|
|
|
|
I slowly begin to understand why C or C++ used to have no string datatype. It takes deep wisdom to weigh the problems from leaving it out against those that arise when that datatype gets into the wrong hands.
I'm invincible, I can't be vinced
|
|
|
|
|
I have become convinced that programming languages that offer String types should declare them as abstract and/or force you to typedef them before you can use them.
"String userid" would not be allowed.
Something like
"typedef String Userid" would be required first.
Declaration then becomes:
Userid userid;
All of the APIs would them end up with compile time checking for Userid and any mismatches would be compile errors.
A lot of this thinking comes from a security angle.
In a web app:
String userInputWithPossibleInjectionAttacks;
is the same type as
String afterApplyingSanitationRules;
Which String are you storing in your user comment database?
Eventually in programs, each variable's "content" will have history/ACLs associated with it like we have for files on file systems.
They just have not invented this programming language yet... but anyone who deals with user supplied data from outside (or even inside) their organization needs stuff like this.
|
|
|
|
|
They kind-of have that already. You might say
public class UserID : String { }
|
|
|
|
|
That is the modern way of doing it, it even has an approved name: JSON! Except that, by default, in JSON certain types of object (e.g. functions, RegExps) are not supported and some have ambiguous mappings (e.g. Date literals can be identical to certain String literals). JSON, therefore, has an implicit advantage in unusability over your method - it adds ambiguity and complexity for no net benefit; surely this is how all constructs should be.
|
|
|
|
|
Well, I feel stupid now. You mean that architect was visionary?
|
|
|
|
|
jsc42 wrote: it even has an approved name: JSON!
I always thought that it was called SDD (String Driven Development)
Oxfords English < Official CCC Players Dictionary
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
I had to deal with that sort of thing on my last assignment, in VB of course.
|
|
|
|
|
It's surprising how many people try to create their own solutions to problems which already have established and well-behaving solutions :S.
modified 6-Apr-21 21:01pm.
|
|
|
|
|
Quote: It's surprising how many people try to create their own solutions to problems which already have established and well-behaving solutions :S.
Bear in mind that it's difficult, no ... impossible ... to keep up with all the available technology. I don't know how many times I've "invented" something only to find out later that someone else already did it (invariably, in a better way
|
|
|
|
|
Very true, that's why I used "established". In this case WS* and more recently various RESTful standards (see for example OData) try to address this problem since 2003 (while other frameworks tried than even during the 90s)... It's quite natural for someone with a bit of experience to go search there first to see if they can use one prepared solution or at least get inspiration from.
Of course, having a general grasp on where to search the answer on a problem is one of the most important skills of an architect/developper, and it's not something all people enjoy doing (some people for example prefer the pleasure and control of building something themselves, while others prefer to experiment with a lot of things others invented).
modified 6-Apr-21 21:01pm.
|
|
|
|