Yeah I say, its a super day!
Lets all eat hay and be super gay!
Because we all get to stay and play!
In the same way we all did the last several days!
All just because people love to say, ITS NOT OUR FAULT!
Yeah I say, its a super day!
Lets all eat hay and be super gay!
Because we all get to stay and play!
In the same way we all did the last several days!
All just because people love to say, ITS NOT OUR FAULT!
byte[] stringBuffer = Encoding.ASCII.GetBytes(key);
If you need to programmatically check to see if a web page or web service is active before you redirect a user or make a call you can use the HttpWebRequest object to make a call to a URL and get back the HttpWebResponse. Through the HttpWebResponse you can then check the HttpStatusCode to see if it is OK or an # of other statuses base on what you are looking for.
private void CheckUrl()
{
const string SERVICE_URL =
"https://www.google.com";
WebRequest testRequest = WebRequest.Create(SERVICE_URL);
testRequest.Proxy = null;
HttpWebResponse testResponse = (HttpWebResponse)testRequest.GetResponse();
if (testResponse.StatusCode != HttpStatusCode.OK)
{
throw new Exception(
"Unable to hit Google.");,
}
}
When accuracy is extremely important to you, you cannot rely on the standard DateTime or TimeSpan objects built into the .Net Framework. For real accuracy you need to go to the operating system itself. Here is a class which utilizes the operating system to count passing time.
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Threading;
namespace IPPoke.Library.Utilities
{
public class HiPerformanceTimer
{
#region Private Fields
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceCounter(
out long lpPerformanceCount);
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceFrequency(
out long lpFrequency);
private long _startTime, _stopTime;
private readonly long _freq;
#endregion
#region Initializers
///
/// Initializes a new instance of the class.
///
public HiPerformanceTimer()
{
_startTime = 0;
_stopTime = 0;
if (QueryPerformanceFrequency(out _freq) == false)
{
throw new Win32Exception();
}
}
#endregion
#region Public Methods
///
/// Starts this timer instance.
///
public void Start()
{
Thread.Sleep(0);
QueryPerformanceCounter(out _startTime);
}
///
/// Stops this timer instance.
///
public void Stop()
{
QueryPerformanceCounter(out _stopTime);
}
///
/// Gets the duration of the timer in seconds.
///
/// The duration in seconds.
public double Duration
{
get
{
return (_stopTime - _startTime) / (double) _freq;
}
}
#endregion
}
}
Based on the default font size of the browser the ’em’ is used simply as a multiplier. For example lets say the default font size is 16px (the most common browser default size) and you wanted the H1 tag to be twice that size you would simply set the font-size of the H1 tag to 2em which would effectively set the height of the text to 32px.
A good practice which allows you to more reliably set text size in your design is to first set the default browser text size to something which you can easily multiply by. If the common default browser text size is 16px we could scale it down to 10px which is extremely easy to multiply by. We can do this bey setting the default font-size to 62.5%. After doing this we can then use multipliers of 10 to get our text to the sizes we want. So now if we wanted our H1 tag to be 15px we could simply set the font-size to 1.5em.
Why mess with em values. Because we are no longer hard coding our text to exact pixel sizes. Instead all of our text is now relative to the browser’s current default font-size which we can then alter to grow or shrink all of the text on our page.
If you need to create a universal timestamp which can be sent between servers which may live in different timezones the best way to do this is to make sure you are using the Universal Time standard or UTC. Once you are using the UTC all servers evaluating the timestamp will be able to read in the UTC time and compare it against their UTC and determine if the timestamp has exceeded its limit.
Another issue along the same lines was the service we were calling was not only looking for a UTC time for its timestamps but also wanted that time in the form of milliseconds. Unfortunately there is no built in method on the DateTime Object for converting the current time to milliseconds. In order to get around this you have to do a trick using the total ticks from the DateTime object and then using a property of the TimeSpan object called TicksPerMillisecond. If you divide the ticks by the TicksPerMillisecond property you get the total miliseconds for the current time.
Example: