private void OnAdd(object parameter) { switch (SelectedTab) { case 0: AuxiliaryApplication newAuxApp = new AuxiliaryApplication(); newAuxApp.Name = "New Auxiliary Application"; AuxiliaryApplicationViewModel newAuxAppViewModel = new AuxiliaryApplicationViewModel(newAuxApp, this); newAuxAppViewModel.StartRequest += OnAuxAppStartRequest; newAuxAppViewModel.StopRequest += OnAuxAppStopRequest; newAuxAppViewModel.CheckRunningRequest += OnAuxAppCheckRunRequest; newAuxAppViewModel.IsExpanded = true; AuxiliaryApplications.Add(newAuxAppViewModel); break; case 1: DriveMap newDriveMap = new DriveMap(@"\\computer\share", "Z"); DriveMapViewModel newDriveMapViewModel = new DriveMapViewModel(newDriveMap); DriveMaps.Add(newDriveMapViewModel); break; default: break; } }
/// <summary> /// Writes the current item. /// </summary> protected void WriteCurrentItem(DriveMap driveMap) { if (driveMap != null) { driveMap.Name = txtName.Text; driveMap.Description = txtDescription.Text; driveMap.RealPath = txtRealPath.Text; driveMap.Username = txtUsername.Text; driveMap.Password = txtPassword.Text; driveMap.Drive = cbDrive.Text; driveMap.Type = cbOperation.SelectedItem.ToString().ToUpper().Equals(DriveMapType.MOUNT.ToString()) ? DriveMapType.MOUNT : DriveMapType.UNMOUNT; } }
/// <summary> /// Handles the Destroy event of the mnu 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 mnu_Destroy(object sender, EventArgs e) { DriveMap driveMap = new DriveMap(); WriteCurrentItem(driveMap); bool ret = DriveMapManager.Unmount(driveMap); string title = "Unmount network drive"; string successMsg = "Operation executed!"; string errorMsg = "Error during execution!"; if (ret) { MessageBox.Show(this, successMsg, title, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, errorMsg, title, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Handles the Click event of the mnuSave 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 mnuSave_Click(object sender, EventArgs e) { if (status == SelectionType.NONE) { currentItem = new DriveMap(); } WriteCurrentItem(currentItem); if (status == SelectionType.SELECTED) { listView.RefreshObject(currentItem); } else { listView.AddObject(currentItem); status = SelectionType.SELECTED; listView.SelectObject(currentItem); listView.RefreshSelectedObjects(); } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("usage: path-kun.exe filepath"); return; } try { DriveMap map = new DriveMap(); SharablePath sharablePath = new SharablePath(map, args[0]); string result = string.Format("<{0}>", sharablePath.ToString()); Console.WriteLine(result); Clipboard.SetText(result); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
/// <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); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("usage: path-kun-explorer.exe filepath"); return; } try { DriveMap map = new DriveMap(); SharablePath sharablePath = new SharablePath(map, args[0]); System.Diagnostics.Process.Start( "EXPLORER.EXE", String.Format(@"/select,""{0}""", sharablePath.ToString()) ); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
/// <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); }
/// <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 = (DriveMap)listView.SelectedObject; DisplayCurrentItem(); }
/// <summary> /// Handles the Click event of the mnuNew 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 mnuNew_Click(object sender, EventArgs e) { currentItem = new DriveMap(); DisplayCurrentItem(); status = SelectionType.NEW; }
public DriveMapViewModel(DriveMap driveMap) { _driveMap = driveMap; ValidationContext = this; }