コード例 #1
0
ファイル: Program.cs プロジェクト: stereoa/AutomatedLab
        static void Main(string[] args)
        {
            //SerializationTest1();
            var labName = "failover";

            var labPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "AutomatedLab-Labs", labName, "Lab.xml");
            var ltest1  = XmlStore <Lab> .Import(labPath);

            var machines2 = ListXmlStore <Machine> .Import(labPath.Replace("Lab.xml", "Machines.xml"));

            var x2 = machines2.SelectMany(m => m.NetworkAdapters).Select(na => na.Ipv4DnsServers);

            XmlValidatorArgs.XmlPath = labPath;
            LabValidatorArgs.XmlPath = labPath;

            var summaryMessageContainer = new ValidationMessageContainer();

            var a = Assembly.GetAssembly(typeof(ValidatorBase));

            foreach (Type t in a.GetTypes())
            {
                if (t.IsSubclassOf(typeof(ValidatorBase)))
                {
                    var validator = (ValidatorBase)Activator.CreateInstance(t);
                    summaryMessageContainer += validator.MessageContainer;

                    Console.WriteLine(t);
                }
            }

            summaryMessageContainer.AddSummary();
            var dasda = summaryMessageContainer.GetFilteredMessages();

            Console.ReadKey();

            var isov = new PathValidator();

            //var messages2 = isov.Validate().ToList();
            var labsDirectory         = new DirectoryInfo(@"C:\Users\randr\Documents\AutomatedLab-Labs");
            var sampleScriptDirectory = new DirectoryInfo(@"C:\Users\randr\Documents\AutomatedLab Sample Scripts");
            var sampleScriptFiles     = sampleScriptDirectory.EnumerateFiles("*.ps1", SearchOption.AllDirectories);

            foreach (var file in sampleScriptFiles)
            {
                var id = Guid.NewGuid();
                IEnumerable <ErrorRecord> errors;
                var scriptContent = File.ReadAllText(file.FullName)
                                    .Replace("Install-Lab", "Export-LabDefinition");

                var labNameStart = scriptContent.IndexOf("'") + 1;
                var labNameEnd   = scriptContent.IndexOf("'", labNameStart);
                scriptContent = scriptContent.Remove(labNameStart, labNameEnd - labNameStart);
                scriptContent = scriptContent.Insert(labNameStart, id.ToString());

                try
                {
                    var result = PowerShellHelper.InvokeCommand(scriptContent, out errors);

                    var labXmlPath = System.IO.Path.Combine(labsDirectory.FullName, id.ToString(), "Lab.xml");
                    var labPaths   = new List <string>()
                    {
                        System.IO.Path.Combine(labsDirectory.FullName, id.ToString(), "Machines.xml")
                    };
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.ReadKey();

            SerializationTest1();
            var l1 = XmlStore <Lab> .Import(@"D:\POSH\Lab.xml");

            //var l1 = XmlStore<Lab>.Import(@"C:\Users\randr_000\Documents\AutomatedLab-Labs\Small1\Lab.xml");

            //var w2012r2 = new AutomatedLab.OperatingSystem("Windows Server 2012 R2 SERVERDATACENTER");
            //var w2012 = new AutomatedLab.OperatingSystem("Windows Server 2012 SERVERDATACENTER");
            //var w2008r2 = new AutomatedLab.OperatingSystem("Windows Server 2008 R2 SERVERSTANDARD");
            //var w2008 = new AutomatedLab.OperatingSystem("Windows Server 2008 SERVERSTANDARD");
            //var w10 = new AutomatedLab.OperatingSystem("Windows Technical Preview");
            //var w7 = new AutomatedLab.OperatingSystem("Windows 7 ENTERPRISE");
            //var w8 = new AutomatedLab.OperatingSystem("Windows 8 Pro");
            //var w81 = new AutomatedLab.OperatingSystem("Windows 8.1 Pro");

            //var w2012r2 = new AutomatedLab.OperatingSystem("2012 R2");
            //var w2012 = new AutomatedLab.OperatingSystem("2012");
            //var w2008r2 = new AutomatedLab.OperatingSystem("2008 R2 SERVERSTANDARD");
            //var w2008 = new AutomatedLab.OperatingSystem("Windows Server 2008 SERVERSTANDARD");
            //var w10 = new AutomatedLab.OperatingSystem("Windows Technical Preview");
            var w7  = new AutomatedLab.OperatingSystem("Windows 7 ENTERPRISE");
            var w8  = new AutomatedLab.OperatingSystem("Windows 8 Pro");
            var w81 = new AutomatedLab.OperatingSystem("Windows 8.1 Pro");
            //var xx1 = w2012.Version;
            var xx2 = w7.Version;

            var ll = new Lab();

            var labPath2 = @"C:\Users\randr_000\Documents\AutomatedLab-Labs\POSH";
            var paths    = new List <string>()
            {
                string.Format(@"{0}\Machines.xml", labPath2)
            };
            //AutomatedLab.LabXmlValidator lv = new AutomatedLab.LabXmlValidator(string.Format(@"{0}\Lab.xml", labPath2), paths.ToArray());
            //lv.RunTests();

            //var results = lv.GetMessages().ToList();

            var lab      = Lab.Import(System.IO.Path.Combine(labPath2, "Lab.xml"));
            var machines = ListXmlStore <Machine> .Import(System.IO.Path.Combine(labPath2, "Machines.xml"));

            var m1 = machines.Where(m => m.Name == "xAZDC1").FirstOrDefault();
            var c1 = m1.GetLocalCredential();

            var x = 5;
        }
        static void Main(string[] args)
        {
            //XmlDocument doc = new XmlDocument();
            //doc.LoadXml("<book genre='novel' Publicationdate='1997' Test1=''> " +
            //            "  <title>Pride And Prejudice</title>" +
            //            "</book>");

            //var b = Book.Create(doc.ChildNodes[0]);


            var o1 = new TestClass1();

            o1.ResourceGroupName = "T1";
            o1.SomeList.AddRange(new string[] { "1", "2" });
            o1.Tags.Add("K1", "V1"); o1.SomeInt1 = 11;
            o1.SomeInt2 = 22;
            o1.Color1   = ConsoleColor.DarkBlue;
            o1.Color2   = ConsoleColor.Yellow;
            o1.Color3   = MyColor.Green;
            o1.Color4   = MyColor.Red;
            o1.Sub1     = new SubTestClass1()
            {
                Date = DateTime.Now, Name = "Test1", Items = new List <string>()
                {
                    "T1", "T2"
                }
            };
            var o2 = CopiedObject <AzureRmResourceGroup> .Create(o1);

            var exportBytes = o1.Export();
            var import      = TestClass1.Import(exportBytes);


            var p = new PowerShellHelper();

            //var result11 = p.InvokeScript(@"Import-AzureRmContext -Path D:\AL1.json | Out-Null; Get-AzureRmResourceGroup").ToArray();
            //var result12 = CopiedObject<AzureRmResourceGroup>.Create(result11).ToArray();

            //var result21 = p.InvokeScript(@"Import-AzureRmContext -Path D:\AL1.json | Out-Null; Get-AzureRmStorageAccount").ToArray();
            //var result22 = CopiedObject<AzureRmStorageAccount>.Create(result21).ToArray();



            return;

            SerializationTest1();
            var labName = "AzureLab24";

            var labPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "AutomatedLab-Labs", labName, "Lab.xml");
            var ltest1  = XmlStore <Lab> .Import(labPath);

            var machines2 = ListXmlStore <Machine> .Import(labPath.Replace("Lab.xml", "Machines.xml"));

            var x2 = machines2.SelectMany(m => m.NetworkAdapters).Select(na => na.Ipv4DnsServers);

            XmlValidatorArgs.XmlPath = labPath;
            LabValidatorArgs.XmlPath = labPath;

            var summaryMessageContainer = new ValidationMessageContainer();

            var a = Assembly.GetAssembly(typeof(ValidatorBase));

            foreach (Type t in a.GetTypes())
            {
                if (t.IsSubclassOf(typeof(ValidatorBase)))
                {
                    var validator = (ValidatorBase)Activator.CreateInstance(t);
                    summaryMessageContainer += validator.MessageContainer;

                    Console.WriteLine(t);
                }
            }

            summaryMessageContainer.AddSummary();
            var dasda = summaryMessageContainer.GetFilteredMessages();

            Console.ReadKey();

            var isov = new PathValidator();

            //var messages2 = isov.Validate().ToList();
            var labsDirectory         = new DirectoryInfo(@"C:\Users\randr\Documents\AutomatedLab-Labs");
            var sampleScriptDirectory = new DirectoryInfo(@"C:\Users\randr\Documents\AutomatedLab Sample Scripts");
            var sampleScriptFiles     = sampleScriptDirectory.EnumerateFiles("*.ps1", SearchOption.AllDirectories);

            foreach (var file in sampleScriptFiles)
            {
                var id = Guid.NewGuid();
                IEnumerable <ErrorRecord> errors;
                var scriptContent = File.ReadAllText(file.FullName)
                                    .Replace("Install-Lab", "Export-LabDefinition");

                var labNameStart = scriptContent.IndexOf("'") + 1;
                var labNameEnd   = scriptContent.IndexOf("'", labNameStart);
                scriptContent = scriptContent.Remove(labNameStart, labNameEnd - labNameStart);
                scriptContent = scriptContent.Insert(labNameStart, id.ToString());

                try
                {
                    var result = p.InvokeCommand(scriptContent);

                    var labXmlPath = System.IO.Path.Combine(labsDirectory.FullName, id.ToString(), "Lab.xml");
                    var labPaths   = new List <string>()
                    {
                        System.IO.Path.Combine(labsDirectory.FullName, id.ToString(), "Machines.xml")
                    };
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.ReadKey();

            SerializationTest1();
            var l1 = XmlStore <Lab> .Import(@"D:\POSH\Lab.xml");

            //var l1 = XmlStore<Lab>.Import(@"C:\Users\randr_000\Documents\AutomatedLab-Labs\Small1\Lab.xml");

            //var w2012r2 = new AutomatedLab.OperatingSystem("Windows Server 2012 R2 Datacenter (Server with a GUI)");
            //var w2012 = new AutomatedLab.OperatingSystem("Windows Server 2012 Datacenter (Server with a GUI)");
            //var w2008r2 = new AutomatedLab.OperatingSystem("Windows Server 2008 R2 Standard (Full Installation)");
            //var w2008 = new AutomatedLab.OperatingSystem("Windows Server 2008 SERVERSTANDARD");
            //var w10 = new AutomatedLab.OperatingSystem("Windows Technical Preview");
            //var w7 = new AutomatedLab.OperatingSystem("Windows 7 ENTERPRISE");
            //var w8 = new AutomatedLab.OperatingSystem("Windows 8 Pro");
            //var w81 = new AutomatedLab.OperatingSystem("Windows 8.1 Pro");

            //var w2012r2 = new AutomatedLab.OperatingSystem("2012 R2");
            //var w2012 = new AutomatedLab.OperatingSystem("2012");
            //var w2008r2 = new AutomatedLab.OperatingSystem("2008 R2 SERVERSTANDARD");
            //var w2008 = new AutomatedLab.OperatingSystem("Windows Server 2008 SERVERSTANDARD");
            //var w10 = new AutomatedLab.OperatingSystem("Windows Technical Preview");
            var w7  = new AutomatedLab.OperatingSystem("Windows 7 ENTERPRISE");
            var w8  = new AutomatedLab.OperatingSystem("Windows 8 Pro");
            var w81 = new AutomatedLab.OperatingSystem("Windows 8.1 Pro");
            //var xx1 = w2012.Version;
            var xx2 = w7.Version;

            var ll = new Lab();

            var labPath2 = @"C:\Users\randr_000\Documents\AutomatedLab-Labs\POSH";
            var paths    = new List <string>()
            {
                string.Format(@"{0}\Machines.xml", labPath2)
            };
            //AutomatedLab.LabXmlValidator lv = new AutomatedLab.LabXmlValidator(string.Format(@"{0}\Lab.xml", labPath2), paths.ToArray());
            //lv.RunTests();

            //var results = lv.GetMessages().ToList();

            var lab      = Lab.Import(System.IO.Path.Combine(labPath2, "Lab.xml"));
            var machines = ListXmlStore <Machine> .Import(System.IO.Path.Combine(labPath2, "Machines.xml"));

            var m1 = machines.Where(m => m.Name == "xAZDC1").FirstOrDefault();
            var c1 = m1.GetLocalCredential();

            var x = 5;
        }