Overall though I’m not knocking Oracle on this, what is clear is that whether you chose Oracle or Microsoft as your preferred development platform, they both will do pretty much the same thing, it will probably come down to past preferences and political issues more than technical advantages…although I prefer Microsoft’s 😉
Programmatically Wake Up On Lan using .net
using
System;using
System.Collections.Generic;using
System.Text;using
System.Net;using
System.Net.Sockets;using
System.Globalization;Â
namespace
Utilities.Network{
/// <summary> /// Utility class to wake machines up that are configured to "Wake Up On Lan" /// </summary> /// <remarks>Code orginally written in VB from http://www.lucamauri.com/snippet/snip.aspx?id=6</remarks> public sealed class WakeUpOnLan{
/// <summary> /// Initialise using the default values /// </summary> /// <remarks>The default IPEndPoint transmit on port 7. Other choices for WOL are port 0 or 9</remarks> public WakeUpOnLan(){
this.endPoint = new IPEndPoint(IPAddress.Broadcast, 7);}
/// <summary> /// Initialise using a specific port /// </summary> /// <param name="port">A valid port number</param> /// <remarks>If the port number is invalid, the IPEndPoint is created to port 7. Ports normally used for WOL are 0, 7 or 9.</remarks> public WakeUpOnLan(int port){
if (port >= 0 && port < 65535){
endPoint =
new IPEndPoint(IPAddress.Broadcast, port);}
else{
endPoint =
new IPEndPoint(IPAddress.Broadcast, 7);}
}
Â
/// <summary> /// The IPEndPoint object that will act as a trasport for the packet. /// It is automatically created by New statement, but you can modify it or read it. /// </summary> /// <value>An IPEndPoint object</value> /// <returns>An IPEndPoint object</returns> /// <remarks>Normally there is no need to change this manually.</remarks> public IPEndPoint EndPoint{
get{
return this.endPoint;}
set{
this.endPoint = value;}
}
/// <summary> /// The target machine Network Interface Card MAC address. /// It must be dash-separated, i.e. in the 11-22-33-44-55-66 form /// </summary> /// <value>A string with dash-separated values</value> /// <returns>A string with dash-separated values</returns> /// <remarks>The standard (IEEE 802) separator for cotet are dash (-) and semicolon (:). I resolved to use dashes only in order to avoid any possible confusion and misunderstanding with upcoming IPv6 addressing space.</remarks> public string MacAddress{
get{
StringBuilder textMAC = new StringBuilder(); foreach (byte currByte in this.macAddress){
textMAC.Append(
"-");textMAC.Append(currByte.ToString(
"X2"));}
return textMAC.ToString().Substring(1);}
set{
if (String.IsNullOrEmpty(value)){
throw new FormatException(MacFormatMessage);}
Queue<byte> values = new Queue<byte>(); string[] hexValues = value.Split(‘-‘); if (hexValues.Length != 6){
throw new FormatException(MacFormatMessage);}
foreach (string currByte in hexValues){
byte convertedByte; if (Byte.TryParse(currByte, System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture, out convertedByte)){
values.Enqueue(convertedByte);
}
else{
throw new FormatException(MacFormatMessage);}
}
this.macAddress = values.ToArray();}
}
/// <summary> /// Total bytes sent by WakeIt method. It is 0 until the method is called at least once for this class instance. /// </summary> /// <returns>Integer value, total bytes trasmitted</returns> /// <remarks></remarks> public int BytesSent{
get{
return this.bytesSent;}
}
/// <summary> /// It represent the Magic Packet broadcasted. /// </summary> /// <returns>String containing the text parsing of the Magic Packet</returns> /// <remarks></remarks> public string PacketSent{
get{
return packetSent;}
}
/// <summary> /// Creates a WOL Magic Packet, the datagram that will awake the target PC upon broadcast on the network. /// </summary> /// <param name="macAddress">An array of byte representing the target machine Network Interface Card MAC address</param> /// <returns>An array of byte representing the Magic Packet</returns> /// <remarks>This method can be used indipendently from the rest of the class. If necessary it can create a Magic Packet just providing the MAC address.</remarks> private byte[] MagicPacket(byte[] macAddress){
if (macAddress.Length == 0){
throw new FormatException("Invalid MAC address");}
byte[] payloadData = new byte[0]; StringBuilder packet = new StringBuilder();Â
payloadData =
new byte[HeaderLength + MacLength * repMAC]; for (int i = 0; i < HeaderLength; i++){
payloadData[i] =
Byte.Parse("FF", System.Globalization.NumberStyles.HexNumber);}
for (int i = 0; i < repMAC; i++){
for (int j = 0; j < MacLength; j++){
payloadData[HeaderLength + i * MacLength + j] = macAddress[j];
}
}
foreach (byte currLoad in payloadData){
packet.Append(
"-");packet.Append(currLoad.ToString(
"X2"));}
packetSent = packet.ToString().Substring(1);
Â
return payloadData;}
private int SendUdp(byte[] payload, IPEndPoint endPoint){
int byteSend; if ((payload != null) && (endPoint != null)){
Socket socketClient = new Socket(endPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);socketClient.Connect(endPoint);
byteSend = socketClient.Send(payload, 0, payload.Length,
SocketFlags.None);socketClient.Close();
}
else{
byteSend = 0;
}
return byteSend;}
/// <summary> /// It is the main method of the class. It must be called after the MAC address has been set. It does not return any code, you can see the result of the operation with the bytesSent and packetSent properties of this class. /// </summary> /// <remarks></remarks> public void WakeIt(){
bytesSent = SendUdp(MagicPacket(macAddress), endPoint);
}
const int HeaderLength = 6; const int MacLength = 6; const int repMAC = 16; const string MacFormatMessage = "Mac Format should be; XX-XX-XX-XX-XX, e.g. 00-13-71-BC-C2-CE"; IPEndPoint endPoint; byte[] macAddress; int bytesSent = 0; string packetSent;}
}
Calling the instance of a ContextBoundObject
public
IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink)private
void Postprocess(IMessage msg, IMessage msgReturn)…
…msg.Properties[
"__TypeName"];
Type
sourceType = Type.GetType(typeName); ObjRef objectRef = RemotingServices.Marshal(this.sourceMarshalByRefObject,null,sourceType); object o = Activator.GetObject(sourceType, objectRef.URI); if (o is IMyKnownInterface){
IMyKnownInterface myInterface = (IMyKnownInterface)o;myInterface.MyMethod()
…
A couple of File path tips in Visual Studio 2005
1. Copy full path from the tab
The simplest way to get the full path to a source file is to open the file in the editor and the right-click the source panes tab. One of the options is to copy the full path
2. Quick way to open another file located in the same folder as an existing source file
When you have a number of source files opened from various locations it can be frustrating to go through the File->Open and navigation process time and again. One trick is to keep open an existing project file located in the folder you want to navigate to. When you select File->Open it will start in the same folder location as the active file in the editor.
Cannot add databases on Windows XP or can I?
Mocking Framework
A fundamental difference between OSX (UNIX) and Windows
An Inconvient Truth
Wireless tab gone…and back again
SEO, how long does it take to get indexed?
After launching a site and sending the details to both MSN and Google the speed to getting an index was dramatically different. MSN showed the site after only a few weeks whereas Google took close onto 10 months to becoming fully indexed. At the start I used Google Alerts to register my interest in the words used by the site and got the odd alert about unrelated sites. During this time the web logs were showing that Google had indexed the site but no index and no alerts. Then after the 10 months the site was suddenly indexed and I started to get a steady stream of alerts for each of the pages of the site. I’d never claim to understand how Google works or how it will work tomorrow, but my observations are that Google does seem to index a site and at some point later the index becomes public knowledge. Now whether this is down to the well touted Sandboxing of sites or simply a queue of indexes I can only guess. But if you’ve designed your site correctly and are tearing your hair out wondering why you’re not getting a Google index, then don’t fret too much but be prepared for a wait. Maybe just everyone you meet to use MSN 😉