Lots of changes to get the enbu file to load

This commit is contained in:
Tim Young 2017-07-29 18:31:19 -05:00
parent 8d5ccdb159
commit ce8b16c2d6
10 changed files with 229 additions and 58 deletions

View File

@ -383,6 +383,12 @@
<None Include="Resources\ip_phone.png" />
</ItemGroup>
<ItemGroup>
<FileAssociation Include=".enbu">
<Visible>False</Visible>
<Description>EduNetworkBuilder user file</Description>
<Progid>EdunNetworkBuilder</Progid>
<DefaultIcon>Resources\NBIco.ico</DefaultIcon>
</FileAssociation>
<FileAssociation Include=".enbx">
<Visible>False</Visible>
<Description>EduNetworkBuilder network file</Description>

View File

@ -14,6 +14,7 @@ namespace EduNetworkBuilder
public string text="";
public string language="en";
public string tag_type;
private LanguageString() { }
public LanguageString(string lang, string msg, string tag)
{
@ -21,6 +22,14 @@ namespace EduNetworkBuilder
language = lang;
tag_type = tag;
}
public LanguageString Clone()
{
LanguageString newitem = new LanguageString();
newitem.text = text;
newitem.language = language;
newitem.tag_type = tag_type;
return newitem;
}
public LanguageString(XmlNode theNode, string tag)
{
@ -62,6 +71,27 @@ namespace EduNetworkBuilder
{
tag = type;
}
private LanguageStrings() { }
public LanguageStrings(LanguageStrings ToCopy)
{
LanguageStrings.Clone(ToCopy, this);
}
public static void Clone(LanguageStrings source, LanguageStrings dest)
{
dest.tag = source.tag;
dest.TheStrings.Clear();
foreach(LanguageString ls in source.TheStrings)
{
dest.TheStrings.Add(ls.Clone());
}
}
public LanguageStrings Clone()
{
LanguageStrings newitem = new LanguageStrings();
LanguageStrings.Clone(this, newitem);
return newitem;
}
public void Add(XmlNode theNode)
{

View File

@ -7,9 +7,13 @@ using System.Drawing;
using System.Xml;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.IO;
namespace EduNetworkBuilder
{
[Serializable]
public class NetTest
{
public string sHost = "";
@ -547,5 +551,29 @@ namespace EduNetworkBuilder
}
return false;
}
public static T Clone<T>(T source)
{
if (!typeof(T).IsSerializable)
{
throw new ArgumentException(NB.Translate("NC_CloneSerialzable"), NB.Translate("_source"));
}
// Don't serialize a null object, simply return the default for that object
if (Object.ReferenceEquals(source, null))
{
return default(T);
}
IFormatter formatter = new BinaryFormatter();
Stream stream = new MemoryStream();
using (stream)
{
formatter.Serialize(stream, source);
stream.Seek(0, SeekOrigin.Begin);
return (T)formatter.Deserialize(stream);
}
}
}
}

View File

@ -19,7 +19,7 @@ namespace EduNetworkBuilder
/// </summary>
public class Network
{
public string PuzzleName="";
public string PuzzleName = "";
public int myHeight = 1024;
public int myWidth = 1024;
public int Level = 0;
@ -38,9 +38,9 @@ namespace EduNetworkBuilder
List<NetworkComponent> NetComponents = new List<NetworkComponent>();
//should have background image
Image TheNetImage = new Bitmap(1024, 1024);
Image TheNetImageBackground = new Bitmap(1024,1024);
Image TheNetImageBackground = new Bitmap(1024, 1024);
public int itemsize = 100; //The size of network components
PictureBox myPBox=null;
PictureBox myPBox = null;
private int UniqueIdentifier = 100; //This gets used for all sorts of things. is auto-incremented every time someone asks for one
private List<Packet> myPackets = new List<Packet>();
private List<PacketMessage> myMessages = new List<PacketMessage>();
@ -58,8 +58,8 @@ namespace EduNetworkBuilder
private int DefaultTimeout = 10;
private int NumberOfSecondsForTimeout = 10;
private List<Rectangle> PacketRectangles = new List<Rectangle>();
public BindingList<VLANName> VlanNames = new BindingList<VLANName>() { new VLANName(1,"Default") };
public BindingList<VLANName> VlanNames = new BindingList<VLANName>() { new VLANName(1, "Default") };
private bool previously_had_packets = false; //used on "tick" to determine if we are starting from scratch
private List<string> PacketColors = new List<string>();
@ -74,7 +74,10 @@ namespace EduNetworkBuilder
NetTitle = new LanguageStrings("title"); //Do not translate this string "title". It is an important word
}
public Network() { } //simple constructor
public Network() {
NetMessage = new LanguageStrings("message");
NetTitle = new LanguageStrings("title"); //Do not translate this string "title". It is an important word
} //simple constructor
private bool isDirty()
{
@ -86,6 +89,38 @@ namespace EduNetworkBuilder
return false;
}
public static void Clone(Network source, Network dest)
{
dest.DefaultTimeout = source.DefaultTimeout;
dest.HintsToDisplay = source.HintsToDisplay;
dest.itemsize = source.itemsize;
dest.Level = source.Level;
dest.myHeight = source.myHeight;
dest.myWidth = source.myWidth;
//dest.NetComponents
foreach(NetworkComponent NC in source.NetComponents)
{
dest.NetComponents.Add(NetworkComponent.Clone(NC));
}
//dest.NetTests
foreach(NetTest NT in source.NetTests)
{
dest.NetTests.Add(NetTest.Clone(NT));
}
dest.NetTitle = source.NetTitle;
dest.NetworkFilename = source.NetworkFilename;
dest.OptionShowLabels = source.OptionShowLabels;
dest.PacketColors = source.PacketColors;
dest.PuzzleName = source.PuzzleName;
dest.NetMessage = new LanguageStrings(source.NetMessage);
}
public Network Clone()
{
Network newitem = new Network();
Network.Clone(this, newitem);
return newitem;
}
public void ClearComponents()
{
@ -289,8 +324,10 @@ namespace EduNetworkBuilder
//save the number of items
//Save all the items
writer.WriteStartElement("Network");
NetMessage.Save(writer);
NetTitle.Save(writer);
if(NetMessage != null)
NetMessage.Save(writer);
if(NetTitle != null)
NetTitle.Save(writer);
writer.WriteElementString("height", myHeight.ToString());
writer.WriteElementString("width", myWidth.ToString());
writer.WriteElementString("itemsize", itemsize.ToString());

View File

@ -43,6 +43,7 @@
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.changeLanguageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.classSetupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.profileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.allToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dHCPRequestToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.clearArpTableToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -81,7 +82,7 @@
this.HelpPanel = new System.Windows.Forms.Panel();
this.cbViewTitles = new System.Windows.Forms.CheckBox();
this.myProgressBar = new System.Windows.Forms.ProgressBar();
this.profileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.addToClassworkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.msMainMenuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbNetworkView)).BeginInit();
this.HelpPanel.SuspendLayout();
@ -160,7 +161,8 @@
this.optionsToolStripMenuItem,
this.changeLanguageToolStripMenuItem,
this.classSetupToolStripMenuItem,
this.profileToolStripMenuItem});
this.profileToolStripMenuItem,
this.addToClassworkToolStripMenuItem});
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(47, 24);
this.editToolStripMenuItem.Text = "Edit";
@ -210,6 +212,13 @@
this.classSetupToolStripMenuItem.Text = "Class Setup";
this.classSetupToolStripMenuItem.Click += new System.EventHandler(this.classSetupToolStripMenuItem_Click);
//
// profileToolStripMenuItem
//
this.profileToolStripMenuItem.Name = "profileToolStripMenuItem";
this.profileToolStripMenuItem.Size = new System.Drawing.Size(203, 26);
this.profileToolStripMenuItem.Text = "Profile";
this.profileToolStripMenuItem.Click += new System.EventHandler(this.profileToolStripMenuItem_Click);
//
// allToolStripMenuItem
//
this.allToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -564,12 +573,12 @@
this.myProgressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
this.myProgressBar.TabIndex = 11;
//
// profileToolStripMenuItem
// addToClassworkToolStripMenuItem
//
this.profileToolStripMenuItem.Name = "profileToolStripMenuItem";
this.profileToolStripMenuItem.Size = new System.Drawing.Size(203, 26);
this.profileToolStripMenuItem.Text = "Profile";
this.profileToolStripMenuItem.Click += new System.EventHandler(this.profileToolStripMenuItem_Click);
this.addToClassworkToolStripMenuItem.Name = "addToClassworkToolStripMenuItem";
this.addToClassworkToolStripMenuItem.Size = new System.Drawing.Size(203, 26);
this.addToClassworkToolStripMenuItem.Text = "Add To Classwork";
this.addToClassworkToolStripMenuItem.Click += new System.EventHandler(this.addToClassworkToolStripMenuItem_Click);
//
// BuilderWindow
//
@ -660,6 +669,7 @@
private System.Windows.Forms.ToolStripMenuItem SolvedVLANToolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem classSetupToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem profileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem addToClassworkToolStripMenuItem;
}
}

View File

@ -1866,5 +1866,16 @@ namespace EduNetworkBuilder
CurrentUser = PPF.Edit();
UpdateMenu();
}
private void addToClassworkToolStripMenuItem_Click(object sender, EventArgs e)
{
if (CurrentUser == null) return;
if (!CurrentUser.isAdmin) return;
PersonProfileForm PPF = new PersonProfileForm(CurrentUser);
CurrentUser = PPF.AddSchoolwork(myNetwork);
UpdateMenu();
}
}
}

View File

@ -41,7 +41,7 @@ namespace EduNetworkBuilder
/// </summary>
List<string> EverCompletedPuzzles = new List<string>();
List<SchoolworkClass> Projects = new List<SchoolworkClass>();
public List<SchoolworkClass> Projects = new List<SchoolworkClass>();
private PersonClass()
{ }
@ -122,6 +122,9 @@ namespace EduNetworkBuilder
Passwords.Add(Individual.InnerText);
break;
case "project":
case "schoolwork":
SchoolworkClass SWC = new SchoolworkClass(Individual);
Projects.Add(SWC);
break;
}
}

View File

@ -59,7 +59,8 @@ namespace EduNetworkBuilder
{
//Prompt for a username
String Dest = NB.TextPromptBox(NB.Translate("PPF_EnterUserName"));
if (Dest == "") Close();//No name given or canceled.
if (Dest == "") { Close(); return; }//No name given or canceled.
if (Dest == null) { Close(); return; }
if (Dest[0] != '_') Dest = "_Teacher_" + Dest; //Make sure it begins with _
//Find a directory for it.
CurrentUser = new PersonClass(Dest, true); //Make an admin person class
@ -100,7 +101,25 @@ namespace EduNetworkBuilder
BW.Show();
}
return CurrentUser;
}
}
public PersonClass AddSchoolwork(Network ToAdd)
{
if (CurrentUser == null) return CurrentUser;
BuilderWindow BW = NB.GetBuilderWin();
SchoolworkClass NewWork = new SchoolworkClass(ToAdd);
CurrentUser.Projects.Add(NewWork);
UpdateFormFromUser(); //make sure we list the right homeworks.
if (BW != null)
{
BW.Hide();
this.tcTabControl.SelectedIndex = 1; //Jump to the items tab
this.ShowDialog();
BW.Show();
}
return CurrentUser;
}
private void UpdateFormFromUser()
{
@ -110,6 +129,24 @@ namespace EduNetworkBuilder
tbUsername.Text = CurrentUser.UserName;
if (CurrentUser.isAdmin) this.Text = "Admin: " + CurrentUser.UserName;
else this.Text = "Student: " + CurrentUser.UserName;
tvClasswork.Nodes.Clear();
TreeNode Node;
if (CurrentUser.isAdmin)
{
//We have a class tree
Node = new TreeNode("Class");
TreeNode Top = Node;
tvClasswork.Nodes.Add(Node);
foreach(SchoolworkClass SWC in CurrentUser.Projects)
{
Node = new TreeNode(SWC.Name);
Top.Nodes.Add(Node);
}
//we have a students tree
Node = new TreeNode("Students");
tvClasswork.Nodes.Add(Node);
}
}
private void SaveUserInfoFromForm()

View File

@ -17,7 +17,7 @@ namespace EduNetworkBuilder
/// <summary>
/// The name of the project. Homework3, Quiz 4, etc.
/// </summary>
string Name = "";
public string Name = "";
/// <summary>
/// The short description of the project.
/// </summary>
@ -42,6 +42,15 @@ namespace EduNetworkBuilder
Load(TheNode);
}
public SchoolworkClass(Network ToAdd)
{
theProject = ToAdd.Clone();
Name = theProject.PuzzleName;
Description = theProject.PuzzleName;
isMaster = true;
}
#region Load and Save
//Load and save functions
public void Load(string filename)

View File

@ -10,45 +10,45 @@
<ComponentGroupRef Id="ProductComponents" />
<ComponentRef Id="ApplicationShortcut" />
</Feature>
</Product>
<Directory Id="TARGETDIR" Name="SourceDir">
<!-- Add info for program-files location -->
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="EduNetworkBuilder" />
</Directory>
<!-- Add info for the start-menu shortcut -->
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="EduNetworkBuilder"/>
</Directory>
</Directory>
<!-- More for the start-menu shortcut -->
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="ff6bf7dd-e8cc-426b-9b10-981a3b7196fd">
<Shortcut Id="ApplicationStartMenuShortcut"
Name="EduNetworkBuilder"
Description="A program for teaching networking"
Target="[#EduNetworkBuilder.exe]"
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
<RegistryValue Root="HKCU" Key="Software\Microsoft\EduNetworkBuilder" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<!-- Add info for program-files location -->
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="EduNetworkBuilder" />
</Directory>
<!-- Add info for the start-menu shortcut -->
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="EduNetworkBuilder"/>
</Directory>
</Directory>
</Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<Component Id="ProductComponent">
<File Source="$(var.EduNetworkBuilder.TargetPath)" />
<ProgId Id="EduNetworkBuilder.enbxfile" Description="EduNetworkBuilder Network File" >
<Extension Id="enbx">
<Verb Id ="open" Command="open" TargetFile="EduNetworkBuilder.exe" Argument="&quot;%1&quot;"/>
</Extension>
</ProgId>
<ProgId Id="EduNetworkBuilder.enbufile" Description="EduNetworkBuilder User File" >
<Extension Id="enbu">
<Verb Id ="open" Command="open" TargetFile="EduNetworkBuilder.exe" Argument="&quot;%1&quot;"/>
</Extension>
</ProgId>
</Component>
</ComponentGroup>
<Fragment>
<!-- More for the start-menu shortcut -->
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="ff6bf7dd-e8cc-426b-9b10-981a3b7196fd">
<Shortcut Id="ApplicationStartMenuShortcut"
Name="EduNetworkBuilder"
Description="A program for teaching networking"
Target="[#EduNetworkBuilder.exe]"
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
<RegistryValue Root="HKCU" Key="Software\Microsoft\EduNetworkBuilder" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<Component Id="ProductComponent">
<File Source="$(var.EduNetworkBuilder.TargetPath)" />
<Extension Id="enbx">
<Verb Id ="open" Command="open" TargetFile="EduNetworkBuilder.exe" Argument="&quot;%1&quot;"/>
</Extension>
</Component>
</ComponentGroup>
</Fragment>
</Product>
</Wix>