private void mnuSave_Click(object sender, EventArgs e) { if (status == SelectionType.NONE) { currentItem = new WindowsExecutable(); } WriteCurrentApplication(); if (status == SelectionType.SELECTED) { listView.RefreshObject(currentItem); } else { listView.AddObject(currentItem); status = SelectionType.SELECTED; listView.SelectObject(currentItem); listView.RefreshSelectedObjects(); } }
/// <summary> /// Copies the specified origin. /// </summary> /// <param name="origin">The origin.</param> /// <returns></returns> public static NetworkProfile Copy(NetworkProfile origin) { NetworkProfile profile = new NetworkProfile(); profile.Id = 0; profile.Name = origin.Name; profile.ImageName = origin.ImageName; profile.NetworkCardInfo = WindowsNetworkCard.Copy(origin.NetworkCardInfo); profile.ProxyConfig = ProxyConfiguration.Copy(origin.ProxyConfig); profile.ServiceList = new List <IWindowsServiceInfo>(); foreach (IWindowsServiceInfo item in profile.ServiceList) { WindowsServiceInfoImpl temp = (WindowsServiceInfoImpl)item; profile.ServiceList.Add(WindowsServiceInfoImpl.Copy(temp)); } profile.ExecList = new List <WindowsExecutable>(); foreach (WindowsExecutable item in origin.ExecList) { profile.ExecList.Add(WindowsExecutable.Copy(item)); } profile.DriveMapList = new List <DriveMap>(); foreach (DriveMap item in origin.DriveMapList) { profile.DriveMapList.Add(DriveMap.Copy(item)); } profile.DefaultPrinter = origin.DefaultPrinter; foreach (WindowsNetworkCard item in origin.DisabledNetworkCards) { profile.DisabledNetworkCards.Add(WindowsNetworkCard.Copy(item)); } return(profile); }
/// <summary> /// Loads the specified file name. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="imageName">default name of the image.</param> /// <returns></returns> public static List <NetworkProfile> Load(string fileName, string imageName = NetworkProfile.DEFAULT_PROFILE_IMAGE_NAME) { List <NetworkProfile> profiles = new List <NetworkProfile>(); if (!File.Exists(fileName)) { return(null); } profiles.Clear(); XmlTextReader reader = null; try { reader = new XmlTextReader(fileName); NetworkProfile currentProfile = null; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. switch (reader.Name) { case "profile": currentProfile = new NetworkProfile(); currentProfile.Id = Int32.Parse(reader.GetAttribute("id")); currentProfile.Name = reader.GetAttribute("name"); currentProfile.ImageName = XmlUtility.ReadAttributeIfPresent(reader, "imageName", imageName); profiles.Add(currentProfile); break; case "networkcard": currentProfile.NetworkCardInfo = new WindowsNetworkCard(); currentProfile.NetworkCardInfo.Id = XmlUtility.ReadAttributeIfPresent(reader, "id", ""); currentProfile.NetworkCardInfo.ViewId = XmlUtility.ReadAttributeIfPresent(reader, "viewId", ""); currentProfile.NetworkCardInfo.Name = XmlUtility.ReadAttributeIfPresent(reader, "name", ""); currentProfile.NetworkCardInfo.Dhcp = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "dhcp", Boolean.FalseString)); currentProfile.NetworkCardInfo.IpAddress = XmlUtility.ReadAttributeIfPresent(reader, "ipAddress", ""); currentProfile.NetworkCardInfo.SubnetMask = XmlUtility.ReadAttributeIfPresent(reader, "subnetMask", ""); currentProfile.NetworkCardInfo.GatewayAddress = XmlUtility.ReadAttributeIfPresent(reader, "defaultGateway", ""); currentProfile.NetworkCardInfo.MacAddress = XmlUtility.ReadAttributeIfPresent(reader, "macAddress", ""); currentProfile.NetworkCardInfo.DynamicDNS = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "dynamicDns", Boolean.FalseString)); currentProfile.NetworkCardInfo.Dns = XmlUtility.ReadAttributeIfPresent(reader, "dns", ""); currentProfile.NetworkCardInfo.Dns2 = XmlUtility.ReadAttributeIfPresent(reader, "dns2", ""); currentProfile.NetworkCardInfo.HardwareName = XmlUtility.ReadAttributeIfPresent(reader, "hardwareName", ""); currentProfile.NetworkCardInfo.WinsPrimaryServer = XmlUtility.ReadAttributeIfPresent(reader, "winsPrimaryServer", ""); currentProfile.NetworkCardInfo.WinsSecondaryServer = XmlUtility.ReadAttributeIfPresent(reader, "winsSecondaryServer", ""); break; case "proxy": currentProfile.ProxyConfig = new ProxyConfiguration(); currentProfile.ProxyConfig.Enabled = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "enabled", Boolean.FalseString)); currentProfile.ProxyConfig.ServerAddress = XmlUtility.ReadAttributeIfPresent(reader, "serverAddress", ""); currentProfile.ProxyConfig.Port = Int32.Parse(XmlUtility.ReadAttributeIfPresent(reader, "port", "80")); currentProfile.ProxyConfig.ProxyOverrideEnabled = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "overrideEnabled", Boolean.FalseString)); currentProfile.ProxyConfig.ProxyOverride = XmlUtility.ReadAttributeIfPresent(reader, "proxyOverride", ""); break; case "application": WindowsExecutable application = new WindowsExecutable(); application.Name = XmlUtility.ReadAttributeIfPresent(reader, "name", ""); application.Arguments = XmlUtility.ReadAttributeIfPresent(reader, "arguments", ""); application.Description = XmlUtility.ReadAttributeIfPresent(reader, "description", ""); application.Directory = XmlUtility.ReadAttributeIfPresent(reader, "directory", ""); application.File = XmlUtility.ReadAttributeIfPresent(reader, "fileName", ""); application.WaitForExit = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "wait", Boolean.TrueString)); application.Kill = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "kill", Boolean.TrueString)); currentProfile.ExecList.Add(application); break; case "service": WindowsServiceInfoImpl service = new WindowsServiceInfoImpl(); service.ServiceName = XmlUtility.ReadAttributeIfPresent(reader, "name", ""); string temp = XmlUtility.ReadAttributeIfPresent(reader, "status", ServiceForcedStatus.STOPPED.ToString()); if (temp.Equals(ServiceForcedStatus.RUNNING.ToString())) { service.ForcedStatus = ServiceForcedStatus.RUNNING; } else if (temp.Equals(ServiceForcedStatus.STOPPED.ToString())) { service.ForcedStatus = ServiceForcedStatus.STOPPED; } else { service.ForcedStatus = ServiceForcedStatus.NONE; } currentProfile.ServiceList.Add(service); break; case "driveMap": DriveMap drive = new DriveMap(); drive.Name = XmlUtility.ReadAttributeIfPresent(reader, "name", ""); drive.Drive = XmlUtility.ReadAttributeIfPresent(reader, "drive", ""); drive.Description = XmlUtility.ReadAttributeIfPresent(reader, "description", ""); drive.Username = XmlUtility.ReadAttributeIfPresent(reader, "username", ""); drive.Password = XmlUtility.ReadAttributeIfPresent(reader, "password", ""); drive.RealPath = XmlUtility.ReadAttributeIfPresent(reader, "realPath", ""); string temp1 = XmlUtility.ReadAttributeIfPresent(reader, "type", DriveMapType.MOUNT.ToString()); if (temp1.Equals(DriveMapType.MOUNT.ToString())) { drive.Type = DriveMapType.MOUNT; } else { drive.Type = DriveMapType.UNMOUNT; } currentProfile.DriveMapList.Add(drive); break; case "printer": currentProfile.DefaultPrinter = XmlUtility.ReadAttributeIfPresent(reader, "defaultPrinter", ""); break; case "forcedNic": // disabled nic WindowsNetworkCard disabledNIC; disabledNIC = new WindowsNetworkCard(); disabledNIC.Id = XmlUtility.ReadAttributeIfPresent(reader, "id", ""); disabledNIC.HardwareName = XmlUtility.ReadAttributeIfPresent(reader, "hardwareName", ""); currentProfile.DisabledNetworkCards.Add(disabledNIC); break; case "wifi": // wifi string associatedSSID = XmlUtility.ReadAttributeIfPresent(reader, "associatedSSID", ""); currentProfile.AssociatedWifiSSID = associatedSSID; break; } break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine(reader.Value); break; case XmlNodeType.EndElement: //Display the end of the element. break; } } } catch (Exception e) { Debug.WriteLine(e.Message); } finally { if (reader != null) { reader.Close(); } } return(profiles); }
private void mnuNew_Click(object sender, EventArgs e) { status = SelectionType.NEW; currentItem = new WindowsExecutable(); DisplayCurrentApplication(); }
/// <summary> /// Handles the SelectionChanged event of the listView control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void listView_SelectionChanged(object sender, EventArgs e) { status = SelectionType.SELECTED; currentItem = (WindowsExecutable)listView.SelectedObject; DisplayCurrentApplication(); }