public void LabStarted(byte[] labData, string version, string osVersion, string psVersion) { if (!GetEnvironmentVariableAsBool(_telemetryOptInVar, false)) { return; } var lab = Lab.Import(labData); lab.Machines.ForEach(m => SendUsedRole(m.Roles.Select(r => r.Name.ToString()).ToList())); lab.Machines.ForEach(m => SendUsedRole(m.PostInstallationActivity.Where(p => p.IsCustomRole).Select(c => System.IO.Path.GetFileNameWithoutExtension(c.ScriptFileName)).ToList(), true)); var properties = new Dictionary <string, string> { { "version", version }, { "hypervisor", lab.DefaultVirtualizationEngine }, { "osversion", osVersion }, { "psversion", psVersion } }; var metrics = new Dictionary <string, double> { { "machineCount", lab.Machines.Count } }; labStarted = DateTime.Now; var eventMessage = "Lab started - Transmitting the following:" + $"\r\nversion = {version}" + $"\r\nhypervisor = {lab.DefaultVirtualizationEngine}" + $"\r\nosversion = {osVersion}" + $"\r\npsversion = {psVersion}" + $"\r\nmachineCount = {lab.Machines.Count}"; try { EventLog.WriteEntry("AutomatedLab", eventMessage, EventLogEntryType.Information, 101); } catch { } try { telemetryClient.TrackEvent("LabStarted", properties, metrics); telemetryClient.Flush(); } catch { ; //nothing to catch. If it doesn't work, it doesn't work. } }
public PSCredential GetCredential(Lab lab) { if (isDomainJoined) { var domain = lab.Domains.Where(d => d.Name.ToLower() == domainName.ToLower()).FirstOrDefault(); if (domain == null) { throw new ArgumentException(string.Format("Domain could not be found: {0}", domainName)); } return(domain.GetCredential()); } else { return(GetLocalCredential()); } }
public LabValidator(string labXmlPath) { XmlDocument mainDoc = new XmlDocument(); mainDoc.Load(labXmlPath); docs.Add(mainDoc); var xmlPaths = mainDoc.SelectNodes("//@Path").OfType <XmlAttribute>().Select(e => e.Value).Where(text => text.EndsWith(".xml")); foreach (var path in xmlPaths) { XmlDocument doc = new XmlDocument(); doc.Load(path); docs.Add(doc); } lab = Lab.Import(labXmlPath); lab.MachineDefinitionFiles.ForEach(file => machines.AddFromFile(file.Path)); lab.Machines = machines; }
public void LabFinished(byte[] labData) { if (!GetEnvironmentVariableAsBool(_telemetryOptInVar, false)) { return; } var lab = Lab.Import(labData); var labDuration = DateTime.Now - labStarted; var properties = new Dictionary <string, string> { { "dayOfWeek", labStarted.DayOfWeek.ToString() } }; var metrics = new Dictionary <string, double> { { "timeTakenSeconds", labDuration.TotalSeconds } }; var eventMessage = "Lab finished - Transmitting the following:" + $"\r\ndayOfWeek = {labStarted.DayOfWeek.ToString()}" + $"\r\ntimeTakenSeconds = {labDuration.TotalSeconds}"; try { EventLog.WriteEntry("AutomatedLab", eventMessage, EventLogEntryType.Information, 102); } catch { } try { telemetryClient.TrackEvent("LabFinished", properties, metrics); telemetryClient.Flush(); } catch { ; //nothing to catch. If it doesn't work, it doesn't work. } }
public void LabStarted(byte[] labData, string version, string osVersion, string psVersion) { if (GetEnvironmentVariableAsBool(_telemetryOptoutEnvVar, false)) { return; } var lab = Lab.Import(labData); lab.Machines.ForEach(m => SendUsedRole(m.Roles.Select(r => r.Name.ToString()).ToList())); lab.Machines.ForEach(m => SendUsedRole(m.PostInstallationActivity.Where(p => p.IsCustomRole).Select(c => System.IO.Path.GetFileNameWithoutExtension(c.ScriptFileName)).ToList(), true)); var properties = new Dictionary <string, string> { { "version", version }, { "hypervisor", lab.DefaultVirtualizationEngine }, { "osversion", osVersion }, { "psversion", psVersion } }; var metrics = new Dictionary <string, double> { { "machineCount", lab.Machines.Count } }; labStarted = DateTime.Now; try { telemetryClient.TrackEvent("LabStarted", properties, metrics); telemetryClient.Flush(); } catch { ; //nothing to catch. If it doesn't work, it doesn't work. } }
public static void SerializationTest1() { var m = new Machine(); m.Memory = 1024; m.Name = "Test2"; //m.Network = "lab"; //m.IpAddress = "192.168.10.10"; //m.Gateway = "192.168.10.1"; m.DiskSize = 60; //m.DNSServers.Add("192.168.10.10"); //m.DNSServers.Add("192.168.10.11"); m.HostType = VirtualizationHost.HyperV; m.IsDomainJoined = false; m.UnattendedXml = "unattended.xml"; m.OperatingSystem = new AutomatedLab.OperatingSystem("Windows Server 2012 R2 SERVERDATACENTER", "E:\\", (AutomatedLab.Version) "6.4.12.0"); m.InstallationUser = new User("Administrator", "Password1"); m.DomainName = "vm.net"; m.HostType = VirtualizationHost.HyperV; m.PostInstallationActivity.Add( new PostInstallationActivity() { DependencyFolder = new AutomatedLab.Path() { Value = @"c:\test" }, IsoImage = new AutomatedLab.Path() { Value = @"c:\test\windows.iso" }, ScriptFileName = "SomeScript.ps1" }); m.Roles.Add(new Role() { Name = Roles.RootDC, Properties = new SerializableDictionary <string, string>() { { "DBServer", "Server1" }, { "DBName", "Orch" } } }); var h = new System.Collections.Hashtable() { { "DBServer", "Server1" }, { "DBName", "Orch" } }; var h1 = (SerializableDictionary <string, string>)h; var machines = new ListXmlStore <Machine>(); //machines.Add(m); //machines.Add(m); machines.Add(m); machines.Timestamp = DateTime.Now; machines.Metadata = new List <string>() { "Somedata", "sdafds" }; machines.ID = Guid.NewGuid(); machines.Export("d:\\x.xml"); var lab = new AutomatedLab.Lab(); lab.Domains = new List <Domain>() { new Domain { Name = "vm.net", Administrator = new User("Administrator", "Password1") }, new Domain { Name = "a.vm.net", Administrator = new User() { UserName = "******", Password = "******" } }, new Domain { Name = "b.vm.net", Administrator = new User() { UserName = "******", Password = "******" } } }; lab.MachineDefinitionFiles = new List <MachineDefinitionFile>() { new MachineDefinitionFile() { Path = @"D:\LabTest\DomainControllers.xml" }, new MachineDefinitionFile() { Path = @"D:\LabTest\MemberServers.xml" } }; lab.VirtualNetworks = new List <VirtualNetwork>() { new VirtualNetwork() { Name = "Lab", AddressSpace = "192.168.10.1/24", HostType = VirtualizationHost.HyperV }, new VirtualNetwork() { Name = "Test", AddressSpace = "10.0.0.1/8", HostType = VirtualizationHost.HyperV } }; lab.Sources.ISOs = new ListXmlStore <IsoImage>() { new IsoImage() { Name = "Server", Path = @"E:\LabConfig\ISOs\en_windows_server_2012_x64_dvd_915478.iso", ReferenceDisk = "WindowsServer2012Base.vhdx", ImageType = MachineTypes.Server }, new IsoImage() { Name = "Client", Path = @"E:\LabConfig\ISOs\en_windows_8_x64_dvd_915440.iso", ReferenceDisk = "Windows8Base.vhdx", ImageType = MachineTypes.Client, }, new IsoImage() { Name = "SQL", Path = @"E:\LabConfig\ISOs\en_sql_server_2008_r2_enterprise_x86_x64_ia64_dvd_520517.iso" }, new IsoImage() { Name = "Exchange", Path = @"E:\LabConfig\ISOs\mu_exchange_server_2013_with_sp1_x64_dvd_4059293.iso" }, new IsoImage() { Name = "SQL", Path = @"E:\LabConfig\ISOs\en_visual_studio_ultimate_2012_x86_dvd_920947.iso" } }; lab.Sources.UnattendedXml = new AutomatedLab.Path() { Value = @"D:\LabConfig\Unattended" }; lab.Target.Path = @"D:\LabVMs"; lab.Target.ReferenceDiskSizeInGB = 60; lab.Export("d:\\lab.xml"); var lab1 = Lab.Import("d:\\lab.xml"); lab1.Machines = ListXmlStore <Machine> .Import("d:\\x.xml"); lab1.GetParentDomain("vm.net"); var os = lab.Sources.ISOs.OfType <IsoImage>(); }