Exemple #1
0
        public IEnumerable <IResource> DoGetResources()
        {
            var rootPath = GetRootPath();

            var instanceName = FileName;

            Logger?.Invoke("Parsing log files...");
            var logFolder = Path.GetDirectoryName(Directory.GetFiles(TempFolderPath, "log*.txt", SearchOption.AllDirectories).OrderBy(x => x.Length).FirstOrDefault());

            var logging = LoggingContext.ParseFolder(logFolder);

            if (logging != null)
            {
                yield return(logging);

                if (instanceName == FileName)
                {
                    var files = Directory.GetFiles(logFolder, "log.*.txt", SearchOption.AllDirectories).OrderByDescending(x => x); // start with last files first
                    foreach (var file in files)
                    {
                        // in first 100 lines Sitecore must write "Sitecore started", otherwise we can skip this file
                        var lines = File.ReadLines(file).Take(100);
                        if (!lines.Any(x => x.Contains("Sitecore started")))
                        {
                            continue;
                        }

                        lines = File.ReadLines(file).Take(2000);

                        // in first 2K rows there must be:
                        // - assemblies e.g. C:\path\to\file.dll (AssemblyProduct, AssemblyDescription, AssemblyInformationalVersion)
                        // - Operating system Microsoft Windows NT 6.3.9600.0
                        // - UTC offset: -04:00:00
                        // - Machine name: WS-ANP
                        // - App pool ID: sc82pool
                        // - Process ID: 9844
                        // - Windows identity used by the process: DK\ANP. Impersonation: False
                        // - Managed pipeline mode: Integrated
                        // - EventQueues enabled: True
                        // - Instance Name:WS-ANP-sc82
                        // - Databases
                        // -   core
                        // -   master
                        // -   web
                        // -   filesystem
                        // - Heartbeat - Initializing
                        // - Heartbeat - Interval set to: 00:00:02
                        // - Heartbeat - Worker thread started
                        // - Trying to load XML configuration /App_Config/Security/Domains.config
                        // -   sitecore
                        // -   extranet
                        // -   ds
                        // -   default
                        // - xDB is disabled.
                        // - Tracking is disabled.
                        // - Missing valid xDB license.

                        var token = "Instance Name:";
                        instanceName = lines.FirstOrDefault(line => line.Contains(token));
                        instanceName = instanceName.Substring(instanceName.IndexOf(token) + token.Length).Trim();

                        // stop parsing files
                        break;
                    }
                }
            }

            if (instanceName == FileName)
            {
                // if log files does not contain instance name - use package metadata
                var instanceInfoPath = Directory.GetFiles(TempFolderPath, "InstanceInfo.xml", SearchOption.AllDirectories).FirstOrDefault();
                if (instanceInfoPath == null || !File.Exists(instanceInfoPath))
                {
                    instanceInfoPath = Directory.GetFiles(TempFolderPath, "PackageInfo.xml", SearchOption.AllDirectories).FirstOrDefault();
                }

                if (instanceInfoPath != null && File.Exists(instanceInfoPath))
                {
                    var xml = new XmlDocument();
                    xml.Load(instanceInfoPath);

                    var name = xml.SelectSingleElement("package/selectedInstance")?.InnerText;
                    if (!string.IsNullOrEmpty(name))
                    {
                        instanceName = name;

                        var machineName = xml.SelectSingleElement("package/machineName")?.InnerText;
                        if (!string.IsNullOrWhiteSpace(machineName))
                        {
                            instanceName = machineName + "-" + instanceName;
                        }
                    }
                }
            }

            Logger?.Invoke("Parsing Sitecore information...");

            var info = SitecoreInformationContext.TryParse(Source.FileSystem.ParseDirectory(TempFolderPath), instanceName, client);

            Assert.IsNotNull(info, nameof(info));

            yield return(info);

            yield return(new ServerRolesContext(Roles ?? ParseRoles(info)));

            Logger?.Invoke("Parsing database data...");
            var databases = SitecorePackageDatabaseContext.TryParse(rootPath, info);

            if (databases != null)
            {
                yield return(databases);
            }

            var webServer = SupportPackageWebServerContext.Parse(rootPath);

            if (webServer != null)
            {
                yield return(webServer);
            }
        }