Start on doc, color devices

This commit is contained in:
Tim Young 2016-10-12 11:39:58 -05:00
parent 077560227a
commit 9b50875c2c
3 changed files with 112 additions and 12 deletions

View File

@ -7,7 +7,7 @@ using System.Drawing;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Xml;
using System.Drawing.Imaging;
namespace EduNetworkBuilder
{
@ -32,6 +32,7 @@ namespace EduNetworkBuilder
public bool MustUseDHCP = false;
public bool CanAddNics = false;
public Color BackgroundColor = Color.Empty;
protected Color MorphColor = Color.Empty;
public NetworkDevice(NetworkComponentType what, string tHostname, Point tLocation, NicType firstNic = NicType.eth)
{
@ -371,6 +372,9 @@ namespace EduNetworkBuilder
IPAddress dhcpip = new IPAddress(Individual);
DHCPRanges.Add(dhcpip);
break;
case "morphcolor":
MorphColor = Color.FromName(Individual.InnerText);
break;
}
}
}
@ -387,6 +391,8 @@ namespace EduNetworkBuilder
writer.WriteElementString("mytype", myType.ToString());
writer.WriteElementString("isdns", isDNSServer.ToString());
writer.WriteElementString("isdhcp", isDHCPServer.ToString());
if(MorphColor != Color.Empty)
writer.WriteElementString("morphcolor", MorphColor.Name);
DefaultGW.Save(writer, "gateway");
foreach (NetworkCard nic in NICs)
{
@ -597,6 +603,43 @@ namespace EduNetworkBuilder
}
}
//This function heavily borrowed from: http://stackoverflow.com/questions/1563038/fast-work-with-bitmaps-in-c-sharp
public Image ColoredImage(Image BaseImage)
{
Bitmap b = new Bitmap(BaseImage);
BitmapData bData = b.LockBits(new Rectangle(0, 0, BaseImage.Width, BaseImage.Height), ImageLockMode.ReadWrite, b.PixelFormat);
/* GetBitsPerPixel just does a switch on the PixelFormat and returns the number */
int bitsPerPixel = Image.GetPixelFormatSize(bData.PixelFormat);
/*the size of the image in bytes */
int size = bData.Stride * bData.Height;
/*Allocate buffer for image*/
byte[] data = new byte[size];
/*This overload copies data of /size/ into /data/ from location specified (/Scan0/)*/
System.Runtime.InteropServices.Marshal.Copy(bData.Scan0, data, 0, size);
for (int i = 0; i < size; i += bitsPerPixel / 8)
{
//double magnitude = 1 / 3d * (data[i] + data[i + 1] + data[i + 2]);
//data[i] is the first of 3 bytes of color
data[i] = (byte)((data[i] + MorphColor.B) /2);
data[i+1] = (byte)((data[i+1] + MorphColor.G) / 2);
data[i+2] = (byte)((data[i+2] + MorphColor.R) / 2);
}
/* This override copies the data back into the location specified */
System.Runtime.InteropServices.Marshal.Copy(data, 0, bData.Scan0, data.Length);
b.UnlockBits(bData);
return b;
}
public bool AtLocation(Point location)
{
if (location.X >= MyLocation.X && location.X <= MyLocation.X + Size &&
@ -902,8 +945,56 @@ namespace EduNetworkBuilder
Network myNet = NB.GetNetwork();
myNet.Invalidate(Location);
}
if(MorphColor == Color.Empty)
Graphics.FromImage(BaseImage).DrawImage(MyImage, MyLocation.X, MyLocation.Y, Size, Size);
else
{
//ColorMap colorMap = new ColorMap();
//int width = MyImage.Width;
//int height = MyImage.Height;
Graphics.FromImage(BaseImage).DrawImage(MyImage, MyLocation.X, MyLocation.Y, Size, Size);
//colorMap.OldColor = Color.FromArgb(33,39,63); // opaque red
//colorMap.NewColor = MorphColor; // opaque blue
//ColorMap[] remapTable = { colorMap };
//ImageAttributes imageAttributes = new ImageAttributes();
//imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
//using (Graphics G = Graphics.FromImage(BaseImage))
//{
// G.DrawImage(
// MyImage,
// new Rectangle(MyLocation.X, MyLocation.Y, Size, Size), // destination rectangle
// 0, 0, // upper-left corner of source rectangle
// width, // width of source rectangle
// height, // height of source rectangle
// GraphicsUnit.Pixel,
// imageAttributes);
//}
//---------------------------
//Color color = MorphColor; //Your desired colour
//Bitmap bmp = new Bitmap(MyImage);
//for (int x = 0; x < bmp.Width; x++)
//{
// for (int y = 0; y < bmp.Height; y++)
// {
// int a = 0;
// int r = 0;
// int g = 0;
// int b = 0;
// Color gotColor = bmp.GetPixel(x, y);
// a = gotColor.A;
// r = (gotColor.R + color.R) / 2;
// g = (gotColor.G + color.G) / 2;
// b = (gotColor.B + color.B) / 2;
// gotColor = Color.FromArgb(a, r, g, b);
// bmp.SetPixel(x, y, gotColor);
// }
//}
//Graphics.FromImage(BaseImage).DrawImage(bmp, MyLocation.X, MyLocation.Y, Size, Size);
//------------------------------------
Image NewBMP = ColoredImage(MyImage);
Graphics.FromImage(BaseImage).DrawImage(NewBMP, MyLocation.X, MyLocation.Y, Size, Size);
}
if(DrawTitle)
{
int x = MyLocation.X + (Size / 2);

View File

@ -76,8 +76,14 @@ namespace EduNetworkBuilder
{
bool foundit = false;
Network theNet = NB.GetNetwork();
if (theNet == null)
return;
NetworkDevice ND = theNet.GetDeviceFromID(AttachedToHostNic);
if (ND == null)
return;
NetworkCard NC = ND.NicFromID(AttachedToHostNic);
if (NC == null)
return;
NicType NT = NC.GetNicType;
bool isPort = NT == NicType.port;

View File

@ -1,6 +1,6 @@
{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033\deflangfe1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\fnil\fcharset0 Calibri;}{\f2\fmodern\fprq1\fcharset0 Courier New;}{\f3\fmodern\fprq1\fcharset0 Consolas;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Riched20 10.0.10240}{\*\mmathPr\mdispDef1\mwrapIndent1440 }\viewkind4\uc1
{\*\generator Riched20 10.0.14393}{\*\mmathPr\mdispDef1\mwrapIndent1440 }\viewkind4\uc1
\pard\widctlpar\sa200\sl276\slmult1\b\f0\fs22\lang9 Help:\b0\par
This is a basic help document for EduNetworkBuilder. You can get to this by going to "Help" -> "Help" from the main network-builder window. Or, if you are working on a puzzle, the number buttons on the right-side should open context help. (Help topics that somehow relate to the specific puzzle).\par
\b Overview:\par
@ -13,7 +13,7 @@ Each network card can have multiple IP addresses. This allows you to have one n
\b Building a network:\b0\par
\pard\widctlpar\sa200\f1{\pict{\*\picprop{\sp{\sn wzDescription}{\sv Image}}{\sp{\sn posv}{\sv 1}}
}\pngblip\picw1056\pich1056\picwgoal599\pichgoal599
}\pngblip\picw1057\pich1057\picwgoal599\pichgoal599
89504e470d0a1a0a0000000d494844520000003f0000003f0802000000d83d8788000000017352
474200aece1ce90000000467414d410000b18f0bfc610500000009704859730000171100001711
01ca26f33f00000d8a494441546843ed595b8c5de575fefecbde67cecc3967c633f6788cb1198f
@ -168,7 +168,7 @@ cbb1afaee0eb6fc6bedd1dfbee7bfcf0e3d84f3fe3975fc77efb7dec8f3ff117d7cf8deb3bf299
664b94d91265b644992d51664b94d91265b644992d3914996b6bff017677e26ba12d6815000000
0049454e44ae426082
}{\pict{\*\picprop{\sp{\sn wzDescription}{\sv Image}}{\sp{\sn posv}{\sv 1}}
}\pngblip\picw1056\pich1056\picwgoal599\pichgoal599
}\pngblip\picw1057\pich1057\picwgoal599\pichgoal599
89504e470d0a1a0a0000000d494844520000003f0000003f0403000000a5710dec000000017352
474200aece1ce90000000467414d410000b18f0bfc610500000030504c5445000000ffffff2127
3f5c7df92e3a694b64c45a7af33a4b8e2a355d445aad5776ea0000000000000000000000000000
@ -179,7 +179,7 @@ ec2634a1c8632a102f87011c6e10524205642858040b225c0a96b840c024b24d181e0a968642c0
241479ec264c14c4a6003394712940911f12d5a2a00000a6e0d650561e0a840000000049454e44
ae426082
}{\pict{\*\picprop{\sp{\sn wzDescription}{\sv Image}}{\sp{\sn posv}{\sv 1}}
}\pngblip\picw1056\pich1056\picwgoal599\pichgoal599
}\pngblip\picw1057\pich1057\picwgoal599\pichgoal599
89504e470d0a1a0a0000000d494844520000003f0000003f0802000000d83d8788000000017352
474200aece1ce90000000467414d410000b18f0bfc610500000009704859730000171100001711
01ca26f33f00000ee2494441546843ed9a7b88ddd511c77fef7b77efeee661d6687dc45a4dd618
@ -979,7 +979,7 @@ c0ff864213588d0000000049454e44ae426082
\pard\widctlpar\sa200\sl276\slmult1 Switches:\par
\b0\f1{\pict{\*\picprop{\sp{\sn wzDescription}{\sv Image}}{\sp{\sn posv}{\sv 1}}
}\pngblip\picw1056\pich1056\picwgoal599\pichgoal599
}\pngblip\picw1057\pich1057\picwgoal599\pichgoal599
89504e470d0a1a0a0000000d494844520000003f0000003f0403000000a5710dec000000017352
474200aece1ce90000000467414d410000b18f0bfc610500000030504c5445000000ffffff2127
3f5c7df946d91f0000000000000000000000000000000000000000000000000000000000000000
@ -1082,7 +1082,7 @@ bc4630278e173b4214afda2c89e1e5a7778549c8d898848c8d49c8d898848c8d49c8d898848c8d
\b Firewall:\par
\pard\widctlpar\sa200\b0\f1{\pict{\*\picprop{\sp{\sn wzDescription}{\sv Image}}{\sp{\sn posv}{\sv 1}}
}\pngblip\picw1056\pich1056\picwgoal599\pichgoal599
}\pngblip\picw1057\pich1057\picwgoal599\pichgoal599
89504e470d0a1a0a0000000d494844520000003f0000003f0802000000d83d8788000000017352
474200aece1ce90000000467414d410000b18f0bfc610500000009704859730000171100001711
01ca26f33f00000d8a494441546843ed595b8c5de575fefecbde67cecc3967c633f6788cb1198f
@ -1180,7 +1180,7 @@ f56292e8fc581afaefef98a1309f2806c81bc62976c503e54beff2bcc1f963d9a015dd7a0cd6e6
\pard\widctlpar\sa200\sl276\slmult1 The firewall can also do VPNs (see the help topic on VPNs for more information). The VPN allows devices behind one firewall to talk to devices behind another firewall.\par
\b Wireless Router:\par
\b0\f1{\pict{\*\picprop{\sp{\sn wzDescription}{\sv Image}}{\sp{\sn posv}{\sv 1}}
}\pngblip\picw1056\pich1056\picwgoal599\pichgoal599
}\pngblip\picw1057\pich1057\picwgoal599\pichgoal599
89504e470d0a1a0a0000000d494844520000003f0000003f0806000000575f10df000000017352
474200aece1ce90000000467414d410000b18f0bfc610500000009704859730000171100001711
01ca26f33f00000e64494441546843ed5a097454d519feef7b3399259330213184408024800412
@ -1281,7 +1281,7 @@ cfc079dfa8fe9102485fca3d4d6842139ad0842634a1094444ff065e6a1a5c3f46d13800000000
49454e44ae426082
}\f0 The wireless router is the most complex device on the network. It functions as a firewall, as a switch (on the wired side) and as a hub (on the wireless side). It has VPN capability and can serve DHCP.\par
\f1{\pict{\*\picprop{\sp{\sn wzDescription}{\sv Image}}{\sp{\sn posv}{\sv 1}}
}\pngblip\picw1056\pich1056\picwgoal599\pichgoal599
}\pngblip\picw1057\pich1057\picwgoal599\pichgoal599
89504e470d0a1a0a0000000d494844520000003f0000003f0806000000575f10df000000017352
474200aece1ce90000000467414d410000b18f0bfc610500000009704859730000171100001711
01ca26f33f00000a4e494441546843ed9a795414471ec76bbae78019601886fb3e74503080881a
@ -1356,7 +1356,7 @@ f69fe3440aa6b10f122b43d12edd9d7bb810e5851f85ea71c619679c71c40180ff02c1d321eeef
}\b\f0 Wireless Access Point:\par
\b0 The WAP (Wireless Access Point) is a simple device, which allows you to plug one Ethernet port into a wire, and attach multiple wireless devices to it. Read up on General Wireless for more information on how to configure it. \b \par
\b0\f1{\pict{\*\picprop{\sp{\sn wzDescription}{\sv Image}}{\sp{\sn posv}{\sv 1}}
}\pngblip\picw1056\pich1056\picwgoal599\pichgoal599
}\pngblip\picw1057\pich1057\picwgoal599\pichgoal599
89504e470d0a1a0a0000000d494844520000003f0000003f0806000000575f10df000000017352
474200aece1ce90000000467414d410000b18f0bfc610500000009704859730000171100001711
01ca26f33f00000a1e494441546843ed9a0954145716866ff542374d2320822ca2b28882a028b8
@ -1430,7 +1430,7 @@ f7d5bf1beea1a8f727e76db4d1461b6db4d1461bef3b00ff03f5ef6e4c8c6d9563000000004945
}\b\f0 Wireless Bridge:\par
\b0 A Wireless Bridge is the opposite end of a Wireless Access Point. It has one wireless client connection, to connect to something that serves a wireless signal, and a built in Ethernet switch to connect to the wired connections. It goes at the far end of a wireless link, and allows you to attach multiple wired devices. The Wireless Bridge is also called Wireless Client Mode (when referring to wireless devices.)\par
\f1{\pict{\*\picprop{\sp{\sn wzDescription}{\sv Image}}{\sp{\sn posv}{\sv 1}}
}\pngblip\picw1056\pich1056\picwgoal599\pichgoal599
}\pngblip\picw1057\pich1057\picwgoal599\pichgoal599
89504e470d0a1a0a0000000d494844520000003f0000003f0806000000575f10df000000017352
474200aece1ce90000000467414d410000b18f0bfc610500000009704859730000171100001711
01ca26f33f00000d33494441546843ed9a095813d716c7cf6481008184a08080b28a88b2098a8a
@ -1634,5 +1634,8 @@ There are a few main rules for how to subnet:\par
\b0 If you plan it right, you should be able to supernet your subnets, and have one route or rule for them. For example, you may have your networking equipment in 1-63, and your printers from 65-127. That means you can have one route or rule that matches all 128 IPs. This makes life a lot simpler for creating many sorts of rules.\b\par
Smaller routing tables require less management and resources.\par
\b0 Again, with the onset of more powerful routers, firewalls, and faster networking speeds, this is no longer quite as critical as it once was. But if you have a finely tuned firewall, you can end up with many rules. Often it is very nice to block all access to a whole range instead of blocking access to each machine one IP at a time. Often, the "less management" simply means less work for the techies who are keeping things running smoothly.\par
\par
\b VLANs:\line\b0 Virtual Local Area Networks (Virtual LANs) allow you to segment your network for security sake. Most managed switches can be configured for VLANs.\par
\par
}