private static List <MountModel> MapMountJson(string _mountJson) { string mountJson2 = _mountJson; mountJson2 = Regex.Replace(_mountJson, @"\s{2,}", " ").Replace("\"", "").Replace("\\n", "\n"); string mountJson = mountJson2; mountJson = Regex.Replace(mountJson2, @"\\t", " "); string[] rowDivider = new String[] { "\n" }; string[] mountJsonRow = new string[] { }; mountJsonRow = mountJson.Split(rowDivider, StringSplitOptions.None).ToArray(); List <MountModel> mounts = new List <MountModel>() { }; foreach (string rowJson in mountJsonRow) { if (rowJson != null && rowJson != "") { var fCh = rowJson.ToArray()[0]; if (fCh != '#') { string[] mountJsonCell = new string[] { }; string[] cellDivider = new String[] { " " }; mountJsonCell = rowJson.Split(cellDivider, StringSplitOptions.None).ToArray(); MountModel mount = MapMount(mountJsonCell); mounts.Add(mount); } } } return(mounts); }
public static List <MountModel> GetAll() { var list = new List <MountModel>(); var directories = Directory.EnumerateDirectories(Parameter.RepoDirs, "DIR*", SearchOption.TopDirectoryOnly).ToArray(); foreach (var directory in directories) { var mo = new MountModel { SystemPath = MountHelper.GetDirsPath(Path.GetFileName(directory)), RepoDirsPath = directory, Context = MountContext.External, Entity = MountEntity.Directory }; list.Add(mo); } var files = Directory.EnumerateFiles(Parameter.RepoDirs, "FILE*", SearchOption.TopDirectoryOnly).ToArray(); foreach (var file in files) { var mo = new MountModel { SystemPath = MountHelper.GetFilesPath(Path.GetFileName(file)), RepoDirsPath = file, Context = MountContext.External, Entity = MountEntity.File }; list.Add(mo); } return(list); }
public EsMount(MountModel model, ConnectionMethod ipProtocol, string ipAddress, int ipPort) { //For creating withTCP or UDP this.MountModel = model; DesiredConnectionMethod = ipProtocol; this.IpProtocol = ipProtocol; IpAddress = ipAddress; this.IpPort = ipPort.ToString(); }
// CONSTRUCTORS public EsMount(MountModel model, string commPort) { if (commPort == "") { throw new ApplicationException("Mount must have valid com port."); } //For creating with a serial connection this.MountModel = model; this.ComPort = commPort; this.DesiredConnectionMethod = ConnectionMethod.Serial; }
private static MountModel MapMount(string[] _mountJsonCell) { string[] mountJsonCell = _mountJsonCell; MountModel mount = new MountModel(); if (mountJsonCell.Length > 1) { mount.device = mountJsonCell[0]; mount.mountpoint = mountJsonCell[1]; mount.fstype = mountJsonCell[2]; mount.rorw = mountJsonCell[3]; mount.dv1 = mountJsonCell[4]; mount.dv2 = mountJsonCell[5]; } return(mount); }
public void SetMountFromGui() { string selectedItem = ""; MountModel m = MountModel.Exos2; string ipAddr = ""; Int32 ipPort = 0; string comPort = ""; try { selectedItem = cmbBasic2MountType.SelectedItem.ToString(); m = (MountModel)Enum.Parse(typeof(MountModel), selectedItem); ipAddr = txtBasic2IpAddress.Text; ipPort = Convert.ToInt32(txtBasic2IpPort.Text); comPort = cmbBasic2SerialPort.Text; Mount = EsMount.GetConnectedMount(m, ipAddr, ipPort); } catch (Exception ex) { MessageBox.Show("Please make sure all settings are valid", "Error"); } }
public static EsMount GetConnectedMount(MountModel model, string ipAddress, Int32 ipPort) { //If wifi Connected //If PMC SSID //If TCP --> Return TCP connected mount //if UDP --> Return UDP connected mount //if Serial ports exist //Try Each serial port -->return serial connected mount EsMount tcpMount = new EsMount(model, ConnectionMethod.TCP, ipAddress, ipPort); if (tcpMount.IsConnectedViaTcp()) { tcpMount.ConnectionMethod = ConnectionMethod.TCP; return(tcpMount); } EsMount udpMount = new EsMount(model, ConnectionMethod.UDP, ipAddress, ipPort); if (tcpMount.IsConnectedViaUdp()) { udpMount.ConnectionMethod = ConnectionMethod.UDP; return(udpMount); } EsMount serialMount = null; foreach (var item in SerialPort.GetPortNames()) { serialMount = new EsMount(model, item); if (serialMount.IsConnectedViaSerial()) { serialMount.ConnectionMethod = ConnectionMethod.Serial; return(serialMount); } } return(null); }
public static void AllDirectories() { var list = new List <MountModel>(); var directories = Directory.EnumerateDirectories(Parameter.RepoDirs, "DIR*", SearchOption.TopDirectoryOnly).ToArray(); foreach (var directory in directories) { var mo = new MountModel { SystemPath = MountHelper.GetDirsPath(Path.GetFileName(directory)), RepoDirsPath = directory, Context = MountContext.External, Entity = MountEntity.Directory }; list.Add(mo); } var files = Directory.EnumerateFiles(Parameter.RepoDirs, "FILE*", SearchOption.TopDirectoryOnly).ToArray(); foreach (var file in files) { var mo = new MountModel { SystemPath = MountHelper.GetFilesPath(Path.GetFileName(file)), RepoDirsPath = file, Context = MountContext.External, Entity = MountEntity.File }; list.Add(mo); } ConsoleLogger.Log("directories and files enumerated"); var directoryMounts = list.Where(m => m.Entity == MountEntity.Directory).ToList(); foreach (var directoryMount in directoryMounts) { try { var dir = directoryMount.SystemPath.Replace("\\", ""); var mntDir = directoryMount.RepoDirsPath; if (MountHelper.IsAlreadyMounted(dir) == false) { Directory.CreateDirectory(dir); Directory.CreateDirectory(mntDir); SetBind(mntDir, dir); ConsoleLogger.Log($"mount {mntDir} -> {dir}"); } } catch (Exception ex) { ConsoleLogger.Warn(ex.Message); } } ConsoleLogger.Log("directories mounted"); var fileMounts = list.Where(m => m.Entity == MountEntity.File).ToList(); foreach (var fileMount in fileMounts) { var file = fileMount.SystemPath.Replace("\\", ""); var mntFile = fileMount.RepoDirsPath; if (System.IO.File.Exists(mntFile)) { var path = Path.GetDirectoryName(file); var mntPath = Path.GetDirectoryName(mntFile); if (MountHelper.IsAlreadyMounted(file) == false) { Bash.Execute($"mkdir -p {path}", false); Bash.Execute($"mkdir -p {mntPath}", false); if (!System.IO.File.Exists(file)) { Bash.Execute($"cp {mntFile} {file}", false); } SetBind(mntFile, file); ConsoleLogger.Log($"mount {mntFile} -> {file}"); } } } ConsoleLogger.Log("files mounted"); }
private static MountModel MapMount(string[] _mountJsonCell) { string[] mountJsonCell = _mountJsonCell; MountModel mount = new MountModel(); if (mountJsonCell.Length > 1) { mount.device = mountJsonCell[0]; mount.mountpoint = mountJsonCell[1]; mount.fstype = mountJsonCell[2]; mount.rorw = mountJsonCell[3]; mount.dv1 = mountJsonCell[4]; mount.dv2 = mountJsonCell[5]; } return mount; }