private void LocalNetworkMonitoring() { while (true) { List <LocalNetworkComputer> computerList = lanMonitor.TestLANComputers(); { Application.Current.Dispatcher.BeginInvoke(new Action(() => { int i = 0; for (; i < computerList.Count; i += 1) { if (ComputerCollection.Count <= i) { ComputerCollection.Add(new LANComputerModelView(computerList[i])); } else { ComputerCollection[i].Resolve(computerList[i]); } } while (ComputerCollection.Count > i) { ComputerCollection.RemoveAt(i); } })); } Thread.Sleep(1000); } }
/// <summary> /// Deletes selected component instance /// </summary> /// <param name="t"></param> private void DeleteComponent(Component t) { if (t.GetType() == typeof(Computer)) { var c = ComputerCollection.Where(f => f.Pc == t).Single(); ComputerCollection.Remove(c); } else { List <ComputerItem> tmp = ComputerCollection.Where(i => i.Fields.Where(f => f.fieldInfo.FieldType == t.GetType()).Count() != 0).ToList(); tmp.ForEach(i => i.Fields.Where(f => f.fieldInfo.FieldType == t.GetType()).ToList().ForEach(f => { f.fieldInfo.SetValue(i.Pc, null); f.fieldValue = null; })); var a = ComputerCollection; ComputerCollection = null; ComputerCollection = a; } ComponentCollection.Remove(t); }
/// <summary> /// Create command method used to create components /// </summary> /// <param name="t"></param> private void CreateComponent(Type t) { Component comp = Model.CreateComponent(t, SelectedComponentFieldsList.Select(field => field.fieldValue).ToArray()); if (ComponentCollection.Where(c => c.GetName() == comp.GetName() && c.GetType() == t).Count() == 0) { ComponentCollection.Add(comp); if (comp.GetType() == typeof(Computer)) { ComputerCollection.Add(new ComputerItem(comp as Computer, SelectedComponentFieldsList)); } } else { MessageBox.Show("Component of such type with such name is already added!", "Error", MessageBoxButton.OK); } }
/// <summary> /// Updates component instance from user input /// </summary> /// <param name="t"></param> private void UpdateComponent(Component t) { int index = 0; if (t is Computer) //Required to find match in computer collection because it might be impossible to find it after update call { index = ComputerCollection.IndexOf(ComputerCollection.Single(i => i.Pc == t)); } t.Update(SelectedComponentFieldsList.Select(field => field.fieldValue).ToArray()); SelectedComponentType = null; SelectedComponentType = t.GetType(); SelectedComponentInstance = t; List <ComputerItem> tmp = ComputerCollection.Where(i => i.Fields.Where(f => f.fieldInfo.FieldType == t.GetType()).Count() != 0).ToList(); tmp.ForEach(i => i.Fields.Where(f => f.fieldInfo.FieldType == t.GetType()).ToList().ForEach(f => { f.fieldInfo.SetValue(i.Pc, t); f.fieldValue = t; })); if (t is Computer) { ComputerCollection[index] = new ComputerItem(t as Computer, SelectedComponentFieldsList); } var a = ComputerCollection; ComputerCollection = null; ComputerCollection = a; }
/// <summary> /// Initialize information from PTF config /// </summary> /// <param name="testSite"></param> public override void Initialize(ITestSite testSite) { base.Initialize(testSite); Site.Log.Add(LogEntryKind.Debug, "Read common properties from PTF configure file."); AllowBreakEnvironment = GetBoolProperty(propertyGroup + "AllowBreakEnvironment"); DomainFunctionLevel = GetEnumProperty <DomainFunctionLevel>(propertyGroup + "DomainFunctionLevel"); DomainAdminGroup = GetProperty(propertyGroup + "DomainAdminGroup"); DomainAdministratorName = GetProperty(propertyGroup + "DomainAdministratorName", true); DomainUserPassword = GetProperty(propertyGroup + "DomainUserPassword", true); PrimaryDomainDnsName = GetProperty(propertyGroup + "PrimaryDomain.DNSName", true); PrimaryDomainNetBiosName = GetProperty(propertyGroup + "PrimaryDomain.NetBiosName" ?? (PrimaryDomainDnsName.Split('.'))[0].ToString()); PrimaryDomainSrvGUID = GetProperty(propertyGroup + "PrimaryDomain.ServerGUID", true); PrimaryDomainSID = GetProperty(propertyGroup + "PrimaryDomain.SID", true); PDCNetbiosName = GetProperty(propertyGroup + "WritableDC1.NetbiosName", true); PDCPassword = GetProperty(propertyGroup + "WritableDC1.Password", true); PDCIPAddress = GetProperty(propertyGroup + "WritableDC1.IPAddress"); PDCOSVersion = GetEnumProperty <ServerVersion>(propertyGroup + "WritableDC1.OSVersion"); PDCIsWindows = (PDCOSVersion == ServerVersion.NonWin ? false : true); SDCNetbiosName = GetProperty(propertyGroup + "WritableDC2.NetbiosName"); SDCPassword = GetProperty(propertyGroup + "WritableDC2.Password"); SDCIPAddress = GetProperty(propertyGroup + "WritableDC2.IPAddress"); SDCOSVersion = GetEnumProperty <ServerVersion>(propertyGroup + "WritableDC2.OSVersion"); SDCIsWindows = (SDCOSVersion == ServerVersion.NonWin ? false : true); RODCNetbiosName = GetProperty(propertyGroup + "RODC.NetbiosName"); RODCPassword = GetProperty(propertyGroup + "RODC.Password"); RODCIPAddress = GetProperty(propertyGroup + "RODC.IPAddress"); RODCOSVersion = GetEnumProperty <ServerVersion>(propertyGroup + "RODC.OSVersion"); RODCIsWindows = (RODCOSVersion == ServerVersion.NonWin ? false : true); ChildDomainDnsName = GetProperty(propertyGroup + "ChildDomain.DNSName"); ChildDomainNetBiosName = GetProperty(propertyGroup + "ChildDomain.NetBiosName") ?? (ChildDomainDnsName.Split('.'))[0].ToString(); CDCNetbiosName = GetProperty(propertyGroup + "CDC.NetbiosName"); CDCIPAddress = GetProperty(propertyGroup + "CDC.IPAddress"); CDCOSVersion = GetEnumProperty <ServerVersion>(propertyGroup + "CDC.OSVersion"); CDCIsWindows = (CDCOSVersion == ServerVersion.NonWin ? false : true); TrustDomainDnsName = GetProperty(propertyGroup + "TrustDomain.DNSName"); TrustDomainNetBiosName = GetProperty(propertyGroup + "TrustDomain.NetBiosName") ?? (TrustDomainDnsName.Split('.'))[0].ToString(); TDCNetbiosName = GetProperty(propertyGroup + "TDC.NetbiosName"); TDCIPAddress = GetProperty(propertyGroup + "TDC.IPAddress"); TDCOSVersion = GetEnumProperty <ServerVersion>(propertyGroup + "TDC.OSVersion"); TDCIsWindows = (TDCOSVersion == ServerVersion.NonWin ? false : true); DMNetbiosName = GetProperty(propertyGroup + "DM.NetbiosName"); DMPassword = GetProperty(propertyGroup + "DM.Password"); DMOldPassword = GetProperty(propertyGroup + "DM.OldPassword"); DMIPAddress = GetProperty(propertyGroup + "DM.IPAddress"); ENDPOINTNetbiosName = GetProperty(propertyGroup + "ENDPOINT.NetbiosName", true); ENDPOINTPassword = GetProperty(propertyGroup + "ENDPOINT.Password", true); ENDPOINTOldPassword = GetProperty(propertyGroup + "ENDPOINT.OldPassword"); ENDPOINTIPAddress = GetProperty(propertyGroup + "ENDPOINT.IPAddress"); ADLDSInstanceName = GetProperty(propertyGroup + "ADLDSInstanceName"); ADDSPortNum = GetProperty(propertyGroup + "ADDSPortNum"); ADLDSPortNum = GetProperty(propertyGroup + "ADLDSPortNum"); ADLDSSSLPortNum = GetProperty(propertyGroup + "ADLDSSSLPortNum"); LDSApplicationNC = GetProperty(propertyGroup + "LDSApplicationNC"); ClientUserName = GetProperty(propertyGroup + "ClientUserName"); ClientUserPassword = GetProperty(propertyGroup + "ClientUserPassword"); Site.Log.Add(LogEntryKind.Debug, "Read common properties from PTF configure file completed."); Site.Log.Add(LogEntryKind.Debug, "Construct common classes for domain, domain controller and endpoint."); domains = new DomainCollection(); domainControllers = new DomainControllerCollection(); Domain primaryDomain = new Domain(PrimaryDomainDnsName, PrimaryDomainNetBiosName); domains.Add(primaryDomain); DomainController pdc = new DomainController(primaryDomain, PDCNetbiosName, PDCIPAddress, (ServerVersion)PDCOSVersion); DomainController sdc = new DomainController(primaryDomain, SDCNetbiosName, SDCIPAddress, (ServerVersion)SDCOSVersion); DomainController rodc = new DomainController(primaryDomain, RODCNetbiosName, RODCIPAddress, (ServerVersion)RODCOSVersion); domainControllers.Add(pdc); domainControllers.Add(sdc); domainControllers.Add(rodc); if (string.IsNullOrEmpty(ChildDomainDnsName)) { Site.Log.Add(LogEntryKind.Warning, "ChildDomainDnsName is not configured in PTF, indicating the environment has no child domain."); } else { Domain childDomain = new Domain(ChildDomainDnsName); DomainController cdc = new DomainController(childDomain, CDCNetbiosName, CDCIPAddress, (ServerVersion)CDCOSVersion); domains.Add(childDomain); domainControllers.Add(cdc); } if (string.IsNullOrEmpty(TrustDomainDnsName)) { Site.Log.Add(LogEntryKind.Warning, "TrustDomainDnsName is not configured in PTF, indicating the environment has no trusted domain."); } else { Domain trustDomain = new Domain(TrustDomainDnsName); DomainController tdc = new DomainController(trustDomain, TDCNetbiosName, TDCIPAddress, (ServerVersion)TDCOSVersion); domains.Add(trustDomain); domainControllers.Add(tdc); } Computer endpoint = new Computer(primaryDomain, ENDPOINTNetbiosName, ENDPOINTIPAddress); domainMembers = new ComputerCollection(); domainMembers.Add(endpoint); Site.Log.Add(LogEntryKind.Debug, "Construct common classes for domain, domain controller and endpoint completed."); }