internal static int GetNDependLocCount(DevelopmentInstallation installation, bool debug)
        {
            var servicesProvider = new NDependServicesProvider();
            var projectManager   = servicesProvider.ProjectManager;
            var project          = projectManager.CreateTemporaryProject(
                getAssemblyPaths(installation, debug).Select(i => Path.GetFullPath(i).ToAbsoluteFilePath()).ToArray(),
                TemporaryProjectMode.Temporary);

            StatusStatics.SetStatus("Performing NDepend analysis.");
            var analysisResult = project.RunAnalysis();

            StatusStatics.SetStatus("Performed NDepend analysis.");

            var codeBase = analysisResult.CodeBase;
            var generatedCodeAttribute = codeBase.Types.WithFullName("System.CodeDom.Compiler.GeneratedCodeAttribute").SingleOrDefault();
            var methods = from n in codeBase.Application.Namespaces
                          from t in n.ChildTypes
                          where generatedCodeAttribute == null || !t.HasAttribute(generatedCodeAttribute)
                          from m in t.MethodsAndContructors
                          where generatedCodeAttribute == null || !m.HasAttribute(generatedCodeAttribute)
                          // We've considered excluding .designer.cs files here, but decided that they should remain part of the count since they still represent
                          // logic that must be maintained (in the designer).
                          where m.SourceFileDeclAvailable && m.SourceDecls.Any(s => s.SourceFile.FilePath.ParentDirectoryPath.DirectoryName != "Generated Code")
                          select m;

            return(methods.Where(i => i.NbLinesOfCode.HasValue).Sum(i => Convert.ToInt32(i.NbLinesOfCode.Value)));
        }
        public static void DeleteAndReCreateDatabaseFromFile(Database database, bool databaseHasMinimumDataRevision, string dataPackageFolderPath)
        {
            if (database is NoDatabase)
            {
                return;
            }

            var filePath = getDatabaseFilePath(dataPackageFolderPath, database);

            if (!File.Exists(filePath))
            {
                filePath = "";
            }

            if (databaseHasMinimumDataRevision && !filePath.Any())
            {
                throw new UserCorrectableException(
                          "Failed to re-create the {0} because the data package did not exist, or did not contain a file.".FormatWith(GetDatabaseNounPhrase(database)));
            }
            database.DeleteAndReCreateFromFile(filePath);
            if (!filePath.Any())
            {
                StatusStatics.SetStatus(
                    "Created a new {0} because the data package did not exist, or did not contain a file.".FormatWith(GetDatabaseNounPhrase(database)));
            }
        }
        internal static byte[] CreateEwlNuGetPackage(DevelopmentInstallation installation, bool useDebugAssembly, string outputFolderPath, bool?prerelease)
        {
            var localExportDateAndTime = prerelease.HasValue ? null as DateTime? : DateTime.Now;

            IoMethods.ExecuteWithTempFolder(folderPath => {
                var ewlOutputFolderPath = StandardLibraryMethods.CombinePaths(installation.GeneralLogic.Path,
                                                                              "Standard Library",
                                                                              StandardLibraryMethods.GetProjectOutputFolderPath(useDebugAssembly));
                var libFolderPath = StandardLibraryMethods.CombinePaths(folderPath, @"lib\net451-full");
                foreach (var fileName in new[] { "dll", "pdb", "xml" }.Select(i => "EnterpriseWebLibrary." + i))
                {
                    IoMethods.CopyFile(StandardLibraryMethods.CombinePaths(ewlOutputFolderPath, fileName), StandardLibraryMethods.CombinePaths(libFolderPath, fileName));
                }

                IoMethods.CopyFile(StandardLibraryMethods.CombinePaths(installation.GeneralLogic.Path, @"Development Utility\Package Manager Console Commands.ps1"),
                                   StandardLibraryMethods.CombinePaths(folderPath, @"tools\init.ps1"));

                var webSitePath = StandardLibraryMethods.CombinePaths(installation.GeneralLogic.Path, "Web Site");
                var webProjectFilesFolderPath = StandardLibraryMethods.CombinePaths(folderPath, AppStatics.WebProjectFilesFolderName);
                IoMethods.CopyFolder(StandardLibraryMethods.CombinePaths(webSitePath, AppStatics.EwfFolderName),
                                     StandardLibraryMethods.CombinePaths(webProjectFilesFolderPath, AppStatics.EwfFolderName),
                                     false);
                IoMethods.CopyFile(StandardLibraryMethods.CombinePaths(webSitePath, AppStatics.StandardLibraryFilesFileName),
                                   StandardLibraryMethods.CombinePaths(webProjectFilesFolderPath, AppStatics.StandardLibraryFilesFileName));

                const string duProjectAndFolderName = "Development Utility";
                IoMethods.CopyFolder(
                    StandardLibraryMethods.CombinePaths(installation.GeneralLogic.Path,
                                                        duProjectAndFolderName,
                                                        StandardLibraryMethods.GetProjectOutputFolderPath(useDebugAssembly)),
                    StandardLibraryMethods.CombinePaths(folderPath, duProjectAndFolderName),
                    false);
                packageGeneralFiles(installation, folderPath, false);
                IoMethods.CopyFolder(
                    StandardLibraryMethods.CombinePaths(installation.ExistingInstallationLogic.RuntimeConfiguration.ConfigurationFolderPath,
                                                        InstallationConfiguration.InstallationConfigurationFolderName,
                                                        InstallationConfiguration.InstallationsFolderName,
                                                        (!prerelease.HasValue || prerelease.Value ? "Testing" : "Live")),
                    StandardLibraryMethods.CombinePaths(folderPath,
                                                        InstallationConfiguration.ConfigurationFolderName,
                                                        InstallationConfiguration.InstallationConfigurationFolderName),
                    false);

                var manifestPath = StandardLibraryMethods.CombinePaths(folderPath, "Package.nuspec");
                using (var writer = IoMethods.GetTextWriterForWrite(manifestPath))
                    writeNuGetPackageManifest(installation, prerelease, localExportDateAndTime, writer);

                StatusStatics.SetStatus(StandardLibraryMethods.RunProgram(StandardLibraryMethods.CombinePaths(installation.GeneralLogic.Path, @"Solution Files\nuget"),
                                                                          "pack \"" + manifestPath + "\" -OutputDirectory \"" + outputFolderPath + "\"",
                                                                          "",
                                                                          true));
            });

            return
                (File.ReadAllBytes(StandardLibraryMethods.CombinePaths(outputFolderPath,
                                                                       EwlNuGetPackageSpecificationStatics.GetNuGetPackageFileName(installation.ExistingInstallationLogic.RuntimeConfiguration.SystemShortName,
                                                                                                                                   installation.CurrentMajorVersion,
                                                                                                                                   !prerelease.HasValue || prerelease.Value ? installation.NextBuildNumber as int? : null,
                                                                                                                                   localExportDateAndTime: localExportDateAndTime))));
        }
        internal static int GetNDependLocCount(DevelopmentInstallation installation, bool debug)
        {
            var servicesProvider = new NDependServicesProvider();
            var projectManager   = servicesProvider.ProjectManager;
            var project          =
                projectManager.CreateTemporaryProject(getAssemblyPaths(installation, debug).Select(i => Path.GetFullPath(i).ToAbsoluteFilePath()).ToArray(),
                                                      TemporaryProjectMode.Temporary);

            StatusStatics.SetStatus("Performing NDepend analysis.");
            var analysisResult = project.RunAnalysis();

            StatusStatics.SetStatus("Performed NDepend analysis.");

            var codeBase = analysisResult.CodeBase;
            var generatedCodeAttribute = codeBase.Types.WithFullName("System.CodeDom.Compiler.GeneratedCodeAttribute").SingleOrDefault();
            var methods = from n in codeBase.Application.Namespaces
                          where !n.Name.StartsWith(StandardLibraryMethods.EwfFolderBaseNamespace)
                          from t in n.ChildTypes
                          where generatedCodeAttribute == null || !t.HasAttribute(generatedCodeAttribute)
                          from m in t.MethodsAndContructors
                          where generatedCodeAttribute == null || !m.HasAttribute(generatedCodeAttribute)
                          where m.SourceFileDeclAvailable && m.SourceDecls.Any(s => s.SourceFile.FilePath.ParentDirectoryPath.DirectoryName != "Generated Code")
                          select m;

            return(methods.Where(i => i.NbLinesOfCode.HasValue).Sum(i => Convert.ToInt32(i.NbLinesOfCode.Value)));
        }
Example #5
0
 /// <summary>
 /// SQL Server takes awhile to recover to a usable state after restoring.  Wait until it is.
 /// </summary>
 public static void WaitForDatabaseRecovery(Database database)
 {
     if (database is NoDatabase)
     {
         return;
     }
     StatusStatics.SetStatus("Waiting for database to be ready...");
     EwlStatics.Retry(() => database.GetLineMarker(), "Database failed to be ready.");
     StatusStatics.SetStatus("Database is ready.");
 }
        void Database.ShrinkAfterPostUpdateDataCommands()
        {
            // Give SQL Server a chance to clean up ghost records that may have been generated by post update data commands.
            // To determine how long this takes for a specified database, repeatedly refresh the Disk Usage by Table report while the ISU is running and watch the
            // Data(KB) column values drop for your LOB tables after the post update data commands have executed.
            StatusStatics.SetStatus("Waiting for ghost record cleanup.");
            Thread.Sleep(TimeSpan.FromMinutes(5));

            ExecuteDbMethod(cn => executeLongRunningCommand(cn, "DBCC SHRINKDATABASE( 0 )"));
        }
Example #7
0
        void Database.ShrinkAfterPostUpdateDataCommands()
        {
            // Give SQL Server a chance to clean up ghost records that may have been generated by post update data commands.
            // To determine how long this takes for a specified database, repeatedly refresh the Disk Usage by Table report while the ISU is running and watch the
            // Data(KB) column values drop for your LOB tables after the post update data commands have executed.
            StatusStatics.SetStatus("Waiting for ghost record cleanup.");
            Thread.Sleep(TimeSpan.FromMinutes(5));

            ExecuteDbMethod(
                cn => {
                executeLongRunningCommand(cn, "ALTER DATABASE {0} SET AUTO_UPDATE_STATISTICS_ASYNC OFF".FormatWith(info.Database));
                executeLongRunningCommand(cn, "ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE".FormatWith(info.Database));
                ActionTools.Retry(
                    () => {
                    // This sometimes fails with "A severe error occurred on the current command."
                    executeLongRunningCommand(cn, "DBCC SHRINKDATABASE( {0}, 10 )".FormatWith(info.Database));
                },
                    "Failed to shrink database.",
                    maxAttempts: 10,
                    retryIntervalMs: 30000);
                executeLongRunningCommand(cn, "ALTER DATABASE {0} SET MULTI_USER".FormatWith(info.Database));
                executeLongRunningCommand(cn, "ALTER DATABASE {0} SET AUTO_UPDATE_STATISTICS_ASYNC ON".FormatWith(info.Database));
            });
        }
Example #8
0
        internal static IReadOnlyCollection <(string id, IReadOnlyList <byte[]> packages)> CreateEwlNuGetPackages(
            DevelopmentInstallation installation, PackagingConfiguration packagingConfiguration, bool useDebugAssembly, string outputFolderPath,
            IEnumerable <bool?> prereleaseValues)
        {
            var now      = DateTime.Now;
            var packages = new List <(string, IReadOnlyList <byte[]>)>();

            var mainId       = packagingConfiguration.SystemShortName;
            var mainPackages = prereleaseValues.Select(
                prerelease => {
                var localExportDateAndTime = prerelease.HasValue ? (DateTime?)null : now;

                IoMethods.ExecuteWithTempFolder(
                    folderPath => {
                    var ewlOutputFolderPath = EwlStatics.CombinePaths(
                        installation.GeneralLogic.Path,
                        EwlStatics.CoreProjectName,
                        EwlStatics.GetProjectOutputFolderPath(useDebugAssembly));
                    var libFolderPath = EwlStatics.CombinePaths(folderPath, @"lib\net472-full");
                    foreach (var fileName in new[] { "dll", "pdb", "xml" }.Select(i => "EnterpriseWebLibrary." + i))
                    {
                        IoMethods.CopyFile(EwlStatics.CombinePaths(ewlOutputFolderPath, fileName), EwlStatics.CombinePaths(libFolderPath, fileName));
                    }

                    IoMethods.CopyFile(
                        EwlStatics.CombinePaths(installation.GeneralLogic.Path, @"Development Utility\Package Manager Console Commands.ps1"),
                        EwlStatics.CombinePaths(folderPath, @"tools\init.ps1"));

                    IoMethods.CopyFolder(
                        EwlStatics.CombinePaths(installation.GeneralLogic.Path, EwlStatics.CoreProjectName, StaticFile.FrameworkStaticFilesSourceFolderPath),
                        EwlStatics.CombinePaths(folderPath, InstallationFileStatics.WebFrameworkStaticFilesFolderName),
                        false);
                    IoMethods.DeleteFolder(
                        EwlStatics.CombinePaths(folderPath, InstallationFileStatics.WebFrameworkStaticFilesFolderName, AppStatics.StaticFileLogicFolderName));

                    const string duProjectAndFolderName = "Development Utility";
                    IoMethods.CopyFolder(
                        EwlStatics.CombinePaths(installation.GeneralLogic.Path, duProjectAndFolderName, EwlStatics.GetProjectOutputFolderPath(useDebugAssembly)),
                        EwlStatics.CombinePaths(folderPath, duProjectAndFolderName),
                        false);
                    packageGeneralFiles(installation, folderPath, false);
                    IoMethods.CopyFolder(
                        EwlStatics.CombinePaths(
                            installation.ExistingInstallationLogic.RuntimeConfiguration.ConfigurationFolderPath,
                            InstallationConfiguration.InstallationConfigurationFolderName,
                            InstallationConfiguration.InstallationsFolderName,
                            !prerelease.HasValue || prerelease.Value ? "Testing" : "Live"),
                        EwlStatics.CombinePaths(
                            folderPath,
                            InstallationConfiguration.ConfigurationFolderName,
                            InstallationConfiguration.InstallationConfigurationFolderName),
                        false);
                    if (File.Exists(installation.ExistingInstallationLogic.RuntimeConfiguration.InstallationSharedConfigurationFilePath))
                    {
                        IoMethods.CopyFile(
                            installation.ExistingInstallationLogic.RuntimeConfiguration.InstallationSharedConfigurationFilePath,
                            EwlStatics.CombinePaths(
                                folderPath,
                                InstallationConfiguration.ConfigurationFolderName,
                                InstallationConfiguration.InstallationConfigurationFolderName,
                                InstallationConfiguration.InstallationSharedConfigurationFileName));
                    }

                    var manifestPath = EwlStatics.CombinePaths(folderPath, "Package.nuspec");
                    using (var writer = IoMethods.GetTextWriterForWrite(manifestPath))
                        writeNuGetPackageManifest(
                            writer,
                            installation,
                            mainId,
                            "",
                            w => {
                            var lines = from line in File.ReadAllLines(
                                EwlStatics.CombinePaths(installation.GeneralLogic.Path, EwlStatics.CoreProjectName, "packages.config"))
                                        let trimmedLine = line.Trim()
                                                          where trimmedLine.StartsWith("<package ")
                                                          select trimmedLine;
                            foreach (var line in lines)
                            {
                                w.WriteLine(Regex.Replace(line.Replace("package", "dependency"), @" targetFramework=""[\w]+""", ""));
                            }
                        },
                            prerelease,
                            localExportDateAndTime);

                    StatusStatics.SetStatus(
                        TewlContrib.ProcessTools.RunProgram(
                            EwlStatics.CombinePaths(installation.GeneralLogic.Path, @"Solution Files\nuget"),
                            "pack \"" + manifestPath + "\" -OutputDirectory \"" + outputFolderPath + "\"",
                            "",
                            true));
                });

                return(File.ReadAllBytes(
                           EwlStatics.CombinePaths(
                               outputFolderPath,
                               EwlNuGetPackageSpecificationStatics.GetNuGetPackageFileName(
                                   mainId,
                                   installation.CurrentMajorVersion,
                                   !prerelease.HasValue || prerelease.Value ? installation.NextBuildNumber as int? : null,
                                   localExportDateAndTime: localExportDateAndTime))));
            })
                               .MaterializeAsList();

            packages.Add((mainId, mainPackages));

            var samlId       = mainId + ".Saml";
            var samlPackages = prereleaseValues.Select(
                prerelease => {
                var localExportDateAndTime = prerelease.HasValue ? (DateTime?)null : now;

                IoMethods.ExecuteWithTempFolder(
                    folderPath => {
                    foreach (var fileName in new[] { "dll", "pdb" }.Select(i => "EnterpriseWebLibrary.Saml." + i))
                    {
                        IoMethods.CopyFile(
                            EwlStatics.CombinePaths(
                                installation.GeneralLogic.Path,
                                EwlStatics.SamlProviderProjectPath,
                                EwlStatics.GetProjectOutputFolderPath(useDebugAssembly),
                                fileName),
                            EwlStatics.CombinePaths(folderPath, @"lib\net472-full", fileName));
                    }

                    var manifestPath = EwlStatics.CombinePaths(folderPath, "Package.nuspec");
                    using (var writer = IoMethods.GetTextWriterForWrite(manifestPath))
                        writeNuGetPackageManifest(
                            writer,
                            installation,
                            samlId,
                            "SAML Provider",
                            w => {
                            w.WriteLine(
                                "<dependency id=\"{0}\" version=\"[{1}]\" />".FormatWith(
                                    mainId,
                                    EwlNuGetPackageSpecificationStatics.GetNuGetPackageVersionString(
                                        installation.CurrentMajorVersion,
                                        !prerelease.HasValue || prerelease.Value ? (int?)installation.NextBuildNumber : null,
                                        localExportDateAndTime: localExportDateAndTime)));
                            w.WriteLine("<dependency id=\"ComponentSpace.Saml2.Net.Licensed\" version=\"5.0.0\" />");
                        },
                            prerelease,
                            localExportDateAndTime);

                    StatusStatics.SetStatus(
                        TewlContrib.ProcessTools.RunProgram(
                            EwlStatics.CombinePaths(installation.GeneralLogic.Path, @"Solution Files\nuget"),
                            "pack \"" + manifestPath + "\" -OutputDirectory \"" + outputFolderPath + "\"",
                            "",
                            true));
                });

                return(File.ReadAllBytes(
                           EwlStatics.CombinePaths(
                               outputFolderPath,
                               EwlNuGetPackageSpecificationStatics.GetNuGetPackageFileName(
                                   samlId,
                                   installation.CurrentMajorVersion,
                                   !prerelease.HasValue || prerelease.Value ? installation.NextBuildNumber as int? : null,
                                   localExportDateAndTime: localExportDateAndTime))));
            })
                               .MaterializeAsList();

            packages.Add((samlId, samlPackages));

            return(packages);
        }