Exemple #1
0
 internal static bool IsSolutionInstalled(SocialSitesSolution solution)
 {
     if (solution == null)
     {
         return(false);
     }
     return(LocalFarm.Get().Solutions[solution.SolutionName] != null);
 }
Exemple #2
0
        internal static OutputQueue ProcessSolutionsStatus(ref Collection <SocialSitesSolution> solutions, string literalPath, bool ignoreMissingSolutions = false)
        {
            var outputQueue = new OutputQueue();

            if (solutions == null)
            {
                solutions = new Collection <SocialSitesSolution>();
            }

            // Check for WSP files
            var filePaths = Directory.GetFiles(literalPath, "*.wsp");

            foreach (var filePath in filePaths)
            {
                var knownSolution = false;
                var solutionName  = Path.GetFileName(filePath);

                if (string.IsNullOrEmpty(solutionName))
                {
                    continue;
                }

                // Known Solution
                foreach (var solution in solutions.Where(solution => string.Equals(solutionName.Trim(), solution.SolutionName.Trim(), StringComparison.OrdinalIgnoreCase)))
                {
                    if (!solution.Ignore)
                    {
                        outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.KnownSolutionFound, solution.SolutionName));
                    }
                    else
                    {
                        outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.KnownSolutionFoundIgnoring, solution.SolutionName));
                    }

                    solution.IsWspAvailable = true;
                    knownSolution           = true;
                }

                // Unknown Solution
                if (!knownSolution)
                {
                    outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.UnknownSolutionFound, solutionName));
                    var solution = new SocialSitesSolution()
                    {
                        IsWspAvailable = true,
                        SolutionName   = solutionName,
                        SolutionSet    = SolutionSet.Unknown,
                        InstallOrder   = 99
                    };
                    var majorVersion = 0;
                    outputQueue.Add(Files.SolutionManifestVersion(solution, literalPath, out majorVersion));
                    if (majorVersion >= 14)
                    {
                        solution.MinimumVersion = majorVersion;
                    }
                    solutions.Add(solution);
                }
            }

            // Check if WSP files are installed
            var farm = LocalFarm.Get();

            if (solutions != null)
            {
                foreach (var solution in solutions)
                {
                    solution.IsInstalled = IsSolutionInstalled(solution);
                }
            }

            // Validate Required Solutions are Available
            if (!ignoreMissingSolutions)
            {
                var majorVersion         = farm.BuildVersion.Major;
                var missingCoreSolutions = solutions.Where(p => (p.SolutionSet == SolutionSet.SocialPlatform) && (!p.IsWspAvailable) && (p.MinimumVersion <= majorVersion) && (p.Required) && (!p.Ignore));
                if (missingCoreSolutions.Count() > 0)
                {
                    var missingSolutions = string.Empty;
                    foreach (var solution in missingCoreSolutions)
                    {
                        outputQueue.Add(string.Format(CultureInfo.CurrentCulture, Exceptions.MissingSolution, solution.SolutionName), OutputType.Error);
                        missingSolutions += string.Format(CultureInfo.CurrentCulture, Exceptions.SolutionMissingFormat, solution.SolutionName);
                    }

                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Exceptions.RequiredSolutionsMissing, missingSolutions));
                }

                var missingInstalledSolutions = solutions.Where(p => (p.IsInstalled) && (!p.IsWspAvailable) && (!p.Ignore));
                if (missingInstalledSolutions.Count() > 0)
                {
                    var missingSolutions = string.Empty;
                    foreach (var solution in missingInstalledSolutions)
                    {
                        outputQueue.Add(string.Format(CultureInfo.CurrentCulture, Exceptions.MissingSolution, solution.SolutionName), OutputType.Error);
                        missingSolutions += string.Format(CultureInfo.CurrentCulture, Exceptions.SolutionMissingFormat, solution.SolutionName);
                    }

                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Exceptions.InstalledSolutionsMissing, missingSolutions));
                }
            }

            return(outputQueue);
        }
Exemple #3
0
        internal static OutputQueue SolutionManifestVersion(SocialSitesSolution solution, string literalPath, out int majorVersion)
        {
            majorVersion = -1;
            var outputQueue = new OutputQueue();

            if (solution != null)
            {
                outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.SolutionManifestCheck, solution.SolutionName));

                try
                {
                    var filePath     = Path.Combine(literalPath, solution.SolutionName);
                    var tempPath     = Path.Combine(literalPath, "temp");
                    var manifestPath = Path.Combine(tempPath, "manifest.xml");
                    if (File.Exists(filePath))
                    {
                        DirectoryInfo directory = null;
                        if (!Directory.Exists(tempPath))
                        {
                            Directory.CreateDirectory(tempPath);
                        }
                        directory = new DirectoryInfo(tempPath);

                        if (File.Exists(manifestPath))
                        {
                            try
                            {
                                File.SetAttributes(manifestPath, FileAttributes.Normal);
                                File.Delete(manifestPath);
                            }
                            catch (IOException)
                            {
                                Thread.Sleep(100);
                                File.SetAttributes(manifestPath, FileAttributes.Normal);
                                File.Delete(manifestPath);
                            }
                        }

                        var command = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\expand.exe";
                        var args    = "\"" + filePath + "\" -f:manifest.xml \"" + tempPath + "\"";
                        outputQueue.Add(RunCommand(command, args));

                        if (File.Exists(manifestPath))
                        {
                            var manifestContents   = File.ReadAllText(manifestPath);
                            var manifestVersionTag = Regex.Unescape(_manifestVersionTag);
                            if (manifestContents.IndexOf(manifestVersionTag, 0, StringComparison.OrdinalIgnoreCase) > 0)
                            {
                                majorVersion = 15;
                            }
                            else
                            {
                                majorVersion = 14;
                            }

                            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.SolutionManifestCheckComplete, solution.SolutionName, majorVersion.ToString(CultureInfo.InvariantCulture)));

                            try
                            {
                                File.SetAttributes(manifestPath, FileAttributes.Normal);
                                File.Delete(manifestPath);
                            }
                            catch (IOException)
                            {
                                Thread.Sleep(100);
                                File.SetAttributes(manifestPath, FileAttributes.Normal);
                                File.Delete(manifestPath);
                            }
                        }

                        directory.Delete(true);
                    }
                }
                catch (Exception exception)
                {
                    outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, Exceptions.SolutionManifestCheckError, solution.SolutionName, exception.Message), OutputType.Error, string.Empty, exception);
                }
            }

            return(outputQueue);
        }