public static async Task AddSubnetAndUsedDevices(ProjectLevel pl, Subnet subnet, List <Device> usedDevices) { SubnetLevel subnetlevel = await SubnetLevel.Create(subnet).ConfigureAwait(false); pl.Subnets.Add(subnetlevel); usedDevices.AddRange(subnetlevel.GetDevices()); }
public static async Task <ProjectLevel> Create(Project project) { var ret = new ProjectLevel(); List <Device> usedDevices = new List <Device>(); var subnetTasks = new List <Task>(); foreach (Subnet subnet in project.Subnets) //foreach is not async { subnetTasks.Add(AddSubnetAndUsedDevices(ret, subnet, usedDevices)); } await Task.WhenAll(subnetTasks).ConfigureAwait(false); ret.UnusedDevices = ret.GetAllProjectDevices(project).Except(usedDevices).ToList(); ret.UnusedDeviceItems = await ret.GetUnusedDeviceItems().ConfigureAwait(false); ret.CountDevices(); return(ret); }
private async Task InitializeEditor() { btn_ClearChanges.Enabled = false; btn_Disconnect.Enabled = false; btn_CommitChanges.Enabled = false; btn_ExportToCSV.Enabled = false; txt_Search.Enabled = false; try { await InitializeConnectionWithTiaPortalProject().ConfigureAwait(true); } catch (EngineeringTargetInvocationException ex) { txt_Status.AppendText(ex.Message + Environment.NewLine); btn_Connect.Enabled = true; return; } projectLevel = await ProjectLevel.Create(MyProject); txt_Status.AppendText($"Connected to TIA Portal project: {MyProject.Path}{Environment.NewLine}"); this.Text = $"Net Editor {version}: {MyProject.Path}"; PopulateDeviceTable(lastSortingOrder, txt_Search.Text); FillStatusBar(); this.dgv_PnSubnet.HeaderCell.SortGlyphDirection = SortOrder.Descending; this.dgv_DeviceName.HeaderCell.SortGlyphDirection = SortOrder.Descending; this.dgv_IpAddress.HeaderCell.SortGlyphDirection = SortOrder.Descending; btn_ClearChanges.Enabled = true; btn_Disconnect.Enabled = true; btn_CommitChanges.Enabled = true; btn_ExportToCSV.Enabled = true; txt_Search.Enabled = true; }
public static void Export(ProjectLevel projectLevel) { using (SaveFileDialog saveFileDialog1 = new SaveFileDialog()) { saveFileDialog1.Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*"; saveFileDialog1.FilterIndex = 0; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() != DialogResult.OK) { return; } using (System.IO.StreamWriter file = new StreamWriter(saveFileDialog1.OpenFile())) { file.WriteLine("Interface Mode;Device Name;PN Device Name;Auto PN Name;PN Number;IP Address;Address Mask;" + "Router Address;Subnet Name;IO System Name"); projectLevel.Subnets.ForEach(sn => { sn.IoSystems.ForEach(ios => { file.WriteLine(CreateCSVRecord(ios.IoController, ios)); ios.IoDevices.ForEach(iod => file.WriteLine(CreateCSVRecord(iod, ios))); }); sn.SubnetLvlDevItems.ForEach(sdi => file.WriteLine(CreateCSVRecord(sdi, null))); }); projectLevel.UnusedDeviceItems.ForEach(udi => { file.WriteLine(CreateCSVRecord(udi, null)); }); } } }