Example #1
0
 public ProjectBuildArgs(
     [NotNull] SolutionName solutionName,
     [CanBeNull] string templateName   = null,
     [CanBeNull] string version        = null,
     string outputFolder               = null,
     DatabaseProvider databaseProvider = DatabaseProvider.NotSpecified,
     DatabaseManagementSystem databaseManagementSystem = DatabaseManagementSystem.NotSpecified,
     UiFramework uiFramework = UiFramework.NotSpecified,
     MobileApp?mobileApp     = null,
     bool publicWebSite      = false,
     [CanBeNull] string abpGitHubLocalRepositoryPath  = null,
     [CanBeNull] string voloGitHubLocalRepositoryPath = null,
     [CanBeNull] string templateSource           = null,
     Dictionary <string, string> extraProperties = null,
     [CanBeNull] string connectionString         = null,
     bool pwa = false)
 {
     SolutionName                  = Check.NotNull(solutionName, nameof(solutionName));
     TemplateName                  = templateName;
     Version                       = version;
     OutputFolder                  = outputFolder;
     DatabaseProvider              = databaseProvider;
     DatabaseManagementSystem      = databaseManagementSystem;
     UiFramework                   = uiFramework;
     MobileApp                     = mobileApp;
     PublicWebSite                 = publicWebSite;
     AbpGitHubLocalRepositoryPath  = abpGitHubLocalRepositoryPath;
     VoloGitHubLocalRepositoryPath = voloGitHubLocalRepositoryPath;
     TemplateSource                = templateSource;
     ExtraProperties               = extraProperties ?? new Dictionary <string, string>();
     ConnectionString              = connectionString;
     Pwa = pwa;
 }
Example #2
0
        public void DoesNotBreakForRegularStringsThatDoNotNeedToBeReplaced_Solution()
        {
            var actual   = Names.Solution("{..}");
            var expected = new SolutionName("{..}");

            Assert.AreEqual(expected, actual);
        }
Example #3
0
        public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
        {
            if (commandLineArgs.Target == null)
            {
                Logger.LogWarning("Project name is missing.");
                Logger.LogWarning("Usage:");
                Logger.LogWarning("  abp new <project-name> [-t <template-name>]");
                Logger.LogWarning("Examples:");
                Logger.LogWarning("  abp new Acme.BookStore");
                Logger.LogWarning("  abp new Acme.BookStore mvc");
                return;
            }

            Logger.LogInformation("Creating a new project...");
            Logger.LogInformation("Project name: " + commandLineArgs.Target);

            var result = await ProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    SolutionName.Parse(commandLineArgs.Target),
                    GetDatabaseProviderOrNull(commandLineArgs),
                    commandLineArgs.Options.GetOrNull(Options.Template.Short, Options.Template.Long)
                    )
                );

            using (var templateFileStream = new MemoryStream(result.ZipContent))
            {
                using (var templateZipFile = ZipFile.Read(templateFileStream))
                {
                    templateZipFile.ExtractAll(Directory.GetCurrentDirectory(), ExtractExistingFileAction.Throw);
                }
            }

            Logger.LogInformation($"Successfully created the project '{commandLineArgs.Target}'");
        }
Example #4
0
        public override void Execute(ProjectBuildContext context)
        {
            if (MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(context.BuildArgs.TemplateName))
            {
                new SolutionRenamer(
                    context.Files,
                    "MyCompanyName.MyProjectName",
                    "MicroserviceName",
                    context.BuildArgs.SolutionName.CompanyName,
                    context.BuildArgs.SolutionName.ProjectName
                    ).Run();

                new SolutionRenamer(
                    context.Files,
                    null,
                    "MyProjectName",
                    null,
                    SolutionName.Parse(context.BuildArgs.SolutionName.CompanyName).ProjectName
                    ).Run();
            }
            else
            {
                new SolutionRenamer(
                    context.Files,
                    "MyCompanyName",
                    "MyProjectName",
                    context.BuildArgs.SolutionName.CompanyName,
                    context.BuildArgs.SolutionName.ProjectName
                    ).Run();
            }
        }
 public override int GetHashCode()
 {
     unchecked
     {
         return((SolutionName.GetHashCode() * 397) ^ Cells.GetHashCode());
     }
 }
Example #6
0
        public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
        {
            if (commandLineArgs.Target == null)
            {
                Logger.LogWarning("Project name is missing.");
                Logger.LogWarning("");
                Logger.LogWarning("Usage:");
                Logger.LogWarning("  abp new <project-name> [-t|--template] [-d|--database-provider] [-o|--output-folder]");
                Logger.LogWarning("");
                Logger.LogWarning("Options:");
                Logger.LogWarning("-t|--template <template-name>");
                Logger.LogWarning("-d|--database-provider <database-provider>");
                Logger.LogWarning("-o|--output-folder <output-folder>");
                Logger.LogWarning("");
                Logger.LogWarning("Examples:");
                Logger.LogWarning("  abp new Acme.BookStore");
                Logger.LogWarning("  abp new Acme.BookStore -t mvc-module");
                Logger.LogWarning("  abp new Acme.BookStore -t mvc -d mongodb");
                Logger.LogWarning("  abp new Acme.BookStore -t mvc -d mongodb -o d:\\project");
                return;
            }

            Logger.LogInformation("Creating a new project...");
            Logger.LogInformation("Project name: " + commandLineArgs.Target);

            var result = await ProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    SolutionName.Parse(commandLineArgs.Target),
                    GetDatabaseProviderOrNull(commandLineArgs),
                    commandLineArgs.Options.GetOrNull(Options.Template.Short, Options.Template.Long)
                    )
                );

            var outputFolder = commandLineArgs.Options.GetOrNull(Options.OutputFolder.Short, Options.OutputFolder.Long);

            if (outputFolder != null)
            {
                if (!Directory.Exists(outputFolder))
                {
                    Directory.CreateDirectory(outputFolder);
                }

                outputFolder = Path.GetFullPath(outputFolder);
            }
            else
            {
                outputFolder = Directory.GetCurrentDirectory();
            }

            using (var templateFileStream = new MemoryStream(result.ZipContent))
            {
                using (var templateZipFile = ZipFile.Read(templateFileStream))
                {
                    templateZipFile.ExtractAll(outputFolder, ExtractExistingFileAction.Throw);
                }
            }

            Logger.LogInformation($"Successfully created the project '{commandLineArgs.Target}'");
            Logger.LogInformation($"The output folder is: '{outputFolder}'");
        }
Example #7
0
        private void determineShortName(TemplateRequest request)
        {
            var shortName = ShortNameFlag.IsEmpty()
                ? SolutionName.Split('.').Skip(1).Join("")
                : ShortNameFlag;

            request.Substitutions.Set(ProjectPlan.SHORT_NAME, shortName);
        }
Example #8
0
        public static SolutionFileName GetSolutionFileName(SolutionName solutionName, DotnetNewConventions conventions)
        {
            var solutionFileNameWithoutExtension = conventions.SolutionFileNameWithoutExtensionFromSolutionName(solutionName);

            var solutionFileName = VsIoUtilities.GetSolutionFileName(solutionFileNameWithoutExtension);

            return(solutionFileName);
        }
Example #9
0
 public ProjectBuildRequest(
     SolutionName solutionName,
     DatabaseProvider databaseProvider,
     string version)
 {
     SolutionName     = solutionName;
     DatabaseProvider = databaseProvider;
     Version          = version;
 }
Example #10
0
        public async Task DownloadAsync(string moduleName, string outputFolder, string version, string gitHubAbpLocalRepositoryPath, string gitHubVoloLocalRepositoryPath, AbpCommandLineOptions options)
        {
            Logger.LogInformation("Downloading source code of " + moduleName);
            Logger.LogInformation("Version: " + version);
            Logger.LogInformation("Output folder: " + outputFolder);

            var result = await ModuleProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    SolutionName.Parse(moduleName),
                    moduleName,
                    version,
                    DatabaseProvider.NotSpecified,
                    UiFramework.NotSpecified,
                    null,
                    gitHubAbpLocalRepositoryPath,
                    gitHubVoloLocalRepositoryPath,
                    null,
                    options
                    )
                );

            using (var templateFileStream = new MemoryStream(result.ZipContent))
            {
                using (var zipInputStream = new ZipInputStream(templateFileStream))
                {
                    var zipEntry = zipInputStream.GetNextEntry();
                    while (zipEntry != null)
                    {
                        var fullZipToPath = Path.Combine(outputFolder, zipEntry.Name);
                        var directoryName = Path.GetDirectoryName(fullZipToPath);

                        if (!string.IsNullOrEmpty(directoryName))
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        var fileName = Path.GetFileName(fullZipToPath);
                        if (fileName.Length == 0)
                        {
                            zipEntry = zipInputStream.GetNextEntry();
                            continue;
                        }

                        var buffer = new byte[4096]; // 4K is optimum
                        using (var streamWriter = File.Create(fullZipToPath))
                        {
                            StreamUtils.Copy(zipInputStream, streamWriter, buffer);
                        }

                        zipEntry = zipInputStream.GetNextEntry();
                    }
                }
            }

            Logger.LogInformation($"'{moduleName}' has been successfully downloaded to '{outputFolder}'");
        }
Example #11
0
        private void GenerateSolutionName(string filePath)
        {
            AssemblyPlugin = Assembly.LoadFrom(filePath);
            SolutionName   = solutionPreFix + AssemblyPlugin.GetName().Name.Replace(".", "").Replace("_", "").Replace("-", "");

            if (SolutionName.Length > 50)
            {
                SolutionName = SolutionName.Substring(0, 50);
            }
        }
Example #12
0
        public async Task DownloadPackageAsync(string packageName, string outputFolder, string version)
        {
            Logger.LogInformation("Downloading source code of " + packageName);
            Logger.LogInformation("Version: " + version);
            Logger.LogInformation("Output folder: " + outputFolder);

            var result = await PackageProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    SolutionName.Parse(packageName),
                    packageName,
                    version
                    )
                );

            using (var templateFileStream = new MemoryStream(result.ZipContent))
            {
                using (var zipInputStream = new ZipInputStream(templateFileStream))
                {
                    var zipEntry = zipInputStream.GetNextEntry();
                    while (zipEntry != null)
                    {
                        if (IsAngularTestFile(zipEntry.Name))
                        {
                            zipEntry = zipInputStream.GetNextEntry();
                            continue;
                        }

                        var fullZipToPath = Path.Combine(outputFolder, zipEntry.Name);
                        var directoryName = Path.GetDirectoryName(fullZipToPath);

                        if (!string.IsNullOrEmpty(directoryName))
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        var fileName = Path.GetFileName(fullZipToPath);
                        if (fileName.Length == 0)
                        {
                            zipEntry = zipInputStream.GetNextEntry();
                            continue;
                        }

                        var buffer = new byte[4096]; // 4K is optimum
                        using (var streamWriter = File.Create(fullZipToPath))
                        {
                            StreamUtils.Copy(zipInputStream, streamWriter, buffer);
                        }

                        zipEntry = zipInputStream.GetNextEntry();
                    }
                }
            }

            Logger.LogInformation($"'{packageName}' has been successfully downloaded to '{outputFolder}'");
        }
Example #13
0
        public static IMetricCollectorBackendWorker GetMetricCollectorWorker(SolutionName solution, SolutionConfig config)
        {
            switch (solution)
            {
            case SolutionName.SalesIntelligence:
                return(new SalesIntelligenceMetricCollectorWorker(config));

            case SolutionName.CustomerCareIntelligence:
                return(new CustomerCareIntelligenceMetricCollectorBackendWorker(config));

            default:
                return(null);
            }
        }
Example #14
0
        public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
        {
            if (commandLineArgs.Target == null)
            {
                throw new CliUsageException("Project name is missing!" + Environment.NewLine + Environment.NewLine + GetUsageInfo());
            }

            Logger.LogInformation("Creating a new project...");
            Logger.LogInformation("Project name: " + commandLineArgs.Target);

            var result = await ProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    SolutionName.Parse(commandLineArgs.Target),
                    commandLineArgs.Options.GetOrNull(Options.Template.Short, Options.Template.Long),
                    GetDatabaseProviderOrNull(commandLineArgs),
                    commandLineArgs.Options
                    )
                );

            var outputFolder = commandLineArgs.Options.GetOrNull(Options.OutputFolder.Short, Options.OutputFolder.Long);

            if (outputFolder != null)
            {
                if (!Directory.Exists(outputFolder))
                {
                    Directory.CreateDirectory(outputFolder);
                }

                outputFolder = Path.GetFullPath(outputFolder);
            }
            else
            {
                outputFolder = Directory.GetCurrentDirectory();
            }

            using (var templateFileStream = new MemoryStream(result.ZipContent))
            {
                using (var templateZipFile = ZipFile.Read(templateFileStream))
                {
                    templateZipFile.ExtractAll(outputFolder, ExtractExistingFileAction.Throw);
                }
            }

            Logger.LogInformation($"Successfully created the project '{commandLineArgs.Target}'");
            Logger.LogInformation($"The output folder is: '{outputFolder}'");
        }
 public override bool ValidateProperties(out string error)
 {
     if (SelectedTemplate is TemplateDescriptionViewModel)
     {
         if (!string.IsNullOrWhiteSpace(SolutionLocation) && !UPath.IsValid(SolutionLocation))
         {
             error = "Invalid solution directory.";
             return(ArePropertiesValid = false);
         }
         if (!string.IsNullOrWhiteSpace(SolutionName) && (!UFile.IsValid(SolutionName) || SolutionName.Contains(UPath.DirectorySeparatorString) || SolutionName.Contains(UPath.DirectorySeparatorStringAlt)))
         {
             error = "Invalid solution name.";
             return(ArePropertiesValid = false);
         }
     }
     return(ArePropertiesValid = base.ValidateProperties(out error));
 }
        protected override void ProcessRecord()
        {
            MessageQueue = new ConcurrentQueue <string>();

            try
            {
                var crmParameter = new CrmParameter(ConnectionString)
                {
                    ConnectionTimeOutMinutes = ConnectionTimeOutMinutes
                };

                SolutionDir = SolutionDir + @"\";
                crmParameter.ExecutionDirectory = SolutionDir;

                /* Connect to Dynamics */
                WriteObject($"Connecting ({crmParameter.GetConnectionStringObfuscated()})");

                SolutionTool solutionTool = null;

                var stopwatch = Stopwatch.StartNew();
                var taskInstantiateSolution = Task.Run(() => solutionTool = new SolutionTool(crmParameter));

                while (!taskInstantiateSolution.IsCompleted)
                {
                    WriteVerbose(".");
                    Thread.Sleep(2000);
                }

                solutionTool.MessageLogger += ReceiveMessage;

                var elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s";
                WriteObject($"Done... [{elapsed}]{Environment.NewLine}");

                /* Import Solutions */
                var solutionNames = SolutionName.Split(';');
                foreach (var sol in solutionNames)
                {
                    stopwatch = Stopwatch.StartNew();
                    var fileName = SolutionDir + sol + (Managed ? "_managed" : "") + ".zip";

                    WriteObject($"Uploading '{sol.ToUpper()}' solution ");
                    var solutionBinaryTask = solutionTool.ImportSolutionAsync(fileName);

                    while (!solutionBinaryTask.IsCompleted)
                    {
                        WriteVerbose(".");
                        Thread.Sleep(3000);

                        /* check if any messages from the solution import thread
                         * have been passed back */
                        while (true)
                        {
                            if (MessageQueue.Count == 0)
                            {
                                break; // exit while
                            }
                            var MessageFound = MessageQueue.TryDequeue(out string message);

                            if (MessageFound)
                            {
                                WriteObject(message);
                            }
                        }
                    }

                    if (solutionBinaryTask.IsFaulted)
                    {
                        foreach (var innerException in solutionBinaryTask.Exception.InnerExceptions)
                        {
                            WriteObject($"ERROR - {innerException.Message}");
                            throw new Exception();
                        }
                    }

                    elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s";
                    WriteObject($"Done... [{elapsed}]{Environment.NewLine}");

                    stopwatch = Stopwatch.StartNew();
                    WriteObject($"Publishing ");

                    /* publish solution */
                    var publishTask = solutionTool.PublishAsync();

                    while (!publishTask.IsCompleted)
                    {
                        WriteVerbose(".");
                        Thread.Sleep(3000);
                    }

                    elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s";
                    WriteObject($"Done... [{elapsed}]{Environment.NewLine}");
                }
            }
            catch (Exception ex)
            {
                var errorRecord = new ErrorRecord(new Exception($"Solution Import Failed: {ex.Message}", ex.InnerException), "", ErrorCategory.InvalidResult, null);
                ThrowTerminatingError(errorRecord);
            }
        }
        public static SolutionName AsSolutionName(this string value)
        {
            var solutionName = new SolutionName(value);

            return(solutionName);
        }
Example #18
0
    protected ProjectBuildArgs GetProjectBuildArgs(CommandLineArgs commandLineArgs, string template, string projectName)
    {
        var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long);

        if (version != null)
        {
            Logger.LogInformation("Version: " + version);
        }

        var preview = commandLineArgs.Options.ContainsKey(Options.Preview.Long);

        if (preview)
        {
            Logger.LogInformation("Preview: yes");
        }

        var pwa = commandLineArgs.Options.ContainsKey(Options.ProgressiveWebApp.Short);

        if (pwa)
        {
            Logger.LogInformation("Progressive Web App: yes");
        }

        var databaseProvider = GetDatabaseProvider(commandLineArgs);

        if (databaseProvider != DatabaseProvider.NotSpecified)
        {
            Logger.LogInformation("Database provider: " + databaseProvider);
        }

        var connectionString = GetConnectionString(commandLineArgs);

        if (connectionString != null)
        {
            Logger.LogInformation("Connection string: " + connectionString);
        }

        var databaseManagementSystem = GetDatabaseManagementSystem(commandLineArgs);

        if (databaseManagementSystem != DatabaseManagementSystem.NotSpecified)
        {
            Logger.LogInformation("DBMS: " + databaseManagementSystem);
        }

        var uiFramework = GetUiFramework(commandLineArgs);

        if (uiFramework != UiFramework.NotSpecified)
        {
            Logger.LogInformation("UI Framework: " + uiFramework);
        }

        var theme = uiFramework == UiFramework.None ? (Theme?)null : GetTheme(commandLineArgs);

        if (theme.HasValue)
        {
            Logger.LogInformation("Theme: " + theme);
        }

        var publicWebSite = uiFramework != UiFramework.None && commandLineArgs.Options.ContainsKey(Options.PublicWebSite.Long);

        if (publicWebSite)
        {
            Logger.LogInformation("Public Web Site: yes");
        }

        var mobileApp = GetMobilePreference(commandLineArgs);

        if (mobileApp != MobileApp.None)
        {
            Logger.LogInformation("Mobile App: " + mobileApp);
        }

        var gitHubAbpLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubAbpLocalRepositoryPath.Long);

        if (gitHubAbpLocalRepositoryPath != null)
        {
            Logger.LogInformation("GitHub Abp Local Repository Path: " + gitHubAbpLocalRepositoryPath);
        }

        var gitHubVoloLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubVoloLocalRepositoryPath.Long);

        if (gitHubVoloLocalRepositoryPath != null)
        {
            Logger.LogInformation("GitHub Volo Local Repository Path: " + gitHubVoloLocalRepositoryPath);
        }

        var templateSource = commandLineArgs.Options.GetOrNull(Options.TemplateSource.Short, Options.TemplateSource.Long);

        if (templateSource != null)
        {
            Logger.LogInformation("Template Source: " + templateSource);
        }

        var createSolutionFolder = GetCreateSolutionFolderPreference(commandLineArgs);

        var outputFolder = commandLineArgs.Options.GetOrNull(Options.OutputFolder.Short, Options.OutputFolder.Long);

        var outputFolderRoot =
            outputFolder != null?Path.GetFullPath(outputFolder) : Directory.GetCurrentDirectory();

        SolutionName solutionName;

        if (MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(template))
        {
            var slnPath = commandLineArgs.Options.GetOrNull(Options.MainSolution.Short, Options.MainSolution.Long);

            if (slnPath == null)
            {
                slnPath = Directory.GetFiles(outputFolderRoot, "*.sln").FirstOrDefault();
            }
            else if (slnPath.EndsWith(".sln"))
            {
                Directory.SetCurrentDirectory(Path.GetDirectoryName(slnPath));
                outputFolderRoot = Path.GetDirectoryName(slnPath);
            }
            else if (!Directory.Exists(slnPath))
            {
                slnPath = null;
            }
            else
            {
                Directory.SetCurrentDirectory(slnPath);
                outputFolderRoot = slnPath;
                slnPath          = Directory.GetFiles(outputFolderRoot, "*.sln").FirstOrDefault();
            }

            if (slnPath == null)
            {
                throw new CliUsageException($"This command should be run inside a folder that contains a microservice solution! Or use -{Options.MainSolution.Short} parameter.");
            }

            var microserviceSolutionName = Path.GetFileName(slnPath).RemovePostFix(".sln");

            version ??= SolutionPackageVersionFinder.Find(slnPath);
            solutionName = SolutionName.Parse(microserviceSolutionName, projectName);
            outputFolder = MicroserviceServiceTemplateBase.CalculateTargetFolder(outputFolderRoot, solutionName.ProjectName);
            uiFramework  = uiFramework == UiFramework.NotSpecified ? FindMicroserviceSolutionUiFramework(outputFolderRoot) : uiFramework;
        }
        else
        {
            solutionName = SolutionName.Parse(projectName);

            outputFolder = createSolutionFolder ?
                           Path.Combine(outputFolderRoot, SolutionName.Parse(projectName).FullName) :
                           outputFolderRoot;
        }

        IO.DirectoryHelper.CreateIfNotExists(outputFolder);

        Logger.LogInformation("Output folder: " + outputFolder);

        if (connectionString == null &&
            databaseManagementSystem != DatabaseManagementSystem.NotSpecified &&
            databaseManagementSystem != DatabaseManagementSystem.SQLServer)
        {
            connectionString = ConnectionStringProvider.GetByDbms(databaseManagementSystem, outputFolder);
        }

        commandLineArgs.Options.Add(CliConsts.Command, commandLineArgs.Command);

        return(new ProjectBuildArgs(
                   solutionName,
                   template,
                   version,
                   outputFolder,
                   databaseProvider,
                   databaseManagementSystem,
                   uiFramework,
                   mobileApp,
                   publicWebSite,
                   gitHubAbpLocalRepositoryPath,
                   gitHubVoloLocalRepositoryPath,
                   templateSource,
                   commandLineArgs.Options,
                   connectionString,
                   pwa,
                   theme
                   ));
    }
        /// <summary>
        /// The "dotnet new sln" command allows specifying the directory in which to produce a solution file, and the name of the solution.
        /// However, it does not allows specifying the exact file path of the output solution file.
        /// </summary>
        public static SolutionFilePath CreateSolutionFile(SolutionDirectoryPath solutionDirectoryPath, SolutionName solutionName, ILogger logger)
        {
            var solutionFilePath = Utilities.GetSolutionFilePath(solutionDirectoryPath, solutionName);

            logger.LogDebug($"{solutionName} - Creating solution file:\n{solutionFilePath}");

            // Notes:
            //  --output: This must be the directory in which the solution file should be placed (tested).
            //  --name: This is the name of the solution, to which the .sln extension will be added. If .sln is suffixed to the name argument the resulting solution file will be .sln.sln!
            var arguments = $@"new sln --output ""{solutionDirectoryPath}"" --name {solutionName}";

            ProcessRunner.Run(DotnetCommand.Value, arguments);

            logger.LogInformation($"{solutionName} - Created solution file:\n{solutionFilePath}");

            return(solutionFilePath);
        }
Example #20
0
        public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
        {
            if (commandLineArgs.Target == null)
            {
                throw new CliUsageException("Project name is missing!" + Environment.NewLine + Environment.NewLine + await GetUsageInfo());
            }

            Logger.LogInformation("Creating a new project...");
            Logger.LogInformation("Project name: " + commandLineArgs.Target);

            var result = await ProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    SolutionName.Parse(commandLineArgs.Target),
                    commandLineArgs.Options.GetOrNull(Options.Template.Short, Options.Template.Long),
                    GetDatabaseProviderOrNull(commandLineArgs),
                    commandLineArgs.Options
                    )
                );

            var outputFolder = commandLineArgs.Options.GetOrNull(Options.OutputFolder.Short, Options.OutputFolder.Long);

            if (outputFolder != null)
            {
                if (!Directory.Exists(outputFolder))
                {
                    Directory.CreateDirectory(outputFolder);
                }

                outputFolder = Path.GetFullPath(outputFolder);
            }
            else
            {
                outputFolder = Directory.GetCurrentDirectory();
            }

            using (var templateFileStream = new MemoryStream(result.ZipContent))
            {
                using (var zipInputStream = new ZipInputStream(templateFileStream))
                {
                    var zipEntry = zipInputStream.GetNextEntry();
                    while (zipEntry != null)
                    {
                        var fullZipToPath = Path.Combine(outputFolder, zipEntry.Name);
                        var directoryName = Path.GetDirectoryName(fullZipToPath);

                        if (!string.IsNullOrEmpty(directoryName))
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        var fileName = Path.GetFileName(fullZipToPath);
                        if (fileName.Length == 0)
                        {
                            zipEntry = zipInputStream.GetNextEntry();
                            continue;
                        }

                        var buffer = new byte[4096]; // 4K is optimum
                        using (var streamWriter = File.Create(fullZipToPath))
                        {
                            StreamUtils.Copy(zipInputStream, streamWriter, buffer);
                        }
                        zipEntry = zipInputStream.GetNextEntry();
                    }
                }
            }

            Logger.LogInformation($"Successfully created the project '{commandLineArgs.Target}'");
            Logger.LogInformation($"The output folder is: '{outputFolder}'");
        }
Example #21
0
        public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
        {
            var projectName = NamespaceHelper.NormalizeNamespace(commandLineArgs.Target);

            if (projectName == null)
            {
                throw new CliUsageException(
                          "Project name is missing!" +
                          Environment.NewLine + Environment.NewLine +
                          GetUsageInfo()
                          );
            }

            Logger.LogInformation("Creating your project...");
            Logger.LogInformation("Project name: " + projectName);

            var template = commandLineArgs.Options.GetOrNull(Options.Template.Short, Options.Template.Long);

            if (template != null)
            {
                Logger.LogInformation("Template: " + template);
            }

            var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long);

            if (version != null)
            {
                Logger.LogInformation("Version: " + version);
            }

            var isTiered = commandLineArgs.Options.ContainsKey(Options.Tiered.Long);

            if (isTiered)
            {
                Logger.LogInformation("Tiered: yes");
            }

            var preview = commandLineArgs.Options.ContainsKey(Options.Preview.Long);

            if (preview)
            {
                Logger.LogInformation("Preview: yes if any exist for next version.");
            }

            var databaseProvider = GetDatabaseProvider(commandLineArgs);

            if (databaseProvider != DatabaseProvider.NotSpecified)
            {
                Logger.LogInformation("Database provider: " + databaseProvider);
            }

            var uiFramework = GetUiFramework(commandLineArgs);

            if (uiFramework != UiFramework.NotSpecified)
            {
                Logger.LogInformation("UI Framework: " + uiFramework);
            }

            var connectionString = GetConnectionString(commandLineArgs);

            if (connectionString != null)
            {
                Logger.LogInformation("Connection string: " + connectionString);
            }

            var mobileApp = GetMobilePreference(commandLineArgs);

            if (mobileApp != MobileApp.None)
            {
                Logger.LogInformation("Mobile App: " + mobileApp);
            }

            var gitHubAbpLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubAbpLocalRepositoryPath.Long);

            if (gitHubAbpLocalRepositoryPath != null)
            {
                Logger.LogInformation("GitHub Abp Local Repository Path: " + gitHubAbpLocalRepositoryPath);
            }

            var gitHubVoloLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubVoloLocalRepositoryPath.Long);

            if (gitHubVoloLocalRepositoryPath != null)
            {
                Logger.LogInformation("GitHub Volo Local Repository Path: " + gitHubVoloLocalRepositoryPath);
            }

            var templateSource = commandLineArgs.Options.GetOrNull(Options.TemplateSource.Short, Options.TemplateSource.Long);

            if (templateSource != null)
            {
                Logger.LogInformation("Template Source: " + templateSource);
            }

            var createSolutionFolder = GetCreateSolutionFolderPreference(commandLineArgs);

            if (!createSolutionFolder)
            {
                Logger.LogInformation("Create Solution Folder: no");
            }

            var outputFolder = commandLineArgs.Options.GetOrNull(Options.OutputFolder.Short, Options.OutputFolder.Long);

            var outputFolderRoot =
                outputFolder != null?Path.GetFullPath(outputFolder) : Directory.GetCurrentDirectory();

            outputFolder = createSolutionFolder ?
                           Path.Combine(outputFolderRoot, SolutionName.Parse(projectName).FullName) :
                           outputFolderRoot;

            Volo.Abp.IO.DirectoryHelper.CreateIfNotExists(outputFolder);

            Logger.LogInformation("Output folder: " + outputFolder);

            commandLineArgs.Options.Add(CliConsts.Command, commandLineArgs.Command);

            var result = await TemplateProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    SolutionName.Parse(projectName),
                    template,
                    version,
                    databaseProvider,
                    uiFramework,
                    mobileApp,
                    gitHubAbpLocalRepositoryPath,
                    gitHubVoloLocalRepositoryPath,
                    templateSource,
                    commandLineArgs.Options,
                    connectionString
                    )
                );

            using (var templateFileStream = new MemoryStream(result.ZipContent))
            {
                using (var zipInputStream = new ZipInputStream(templateFileStream))
                {
                    var zipEntry = zipInputStream.GetNextEntry();
                    while (zipEntry != null)
                    {
                        if (string.IsNullOrWhiteSpace(zipEntry.Name))
                        {
                            zipEntry = zipInputStream.GetNextEntry();
                            continue;
                        }

                        var fullZipToPath = Path.Combine(outputFolder, zipEntry.Name);
                        var directoryName = Path.GetDirectoryName(fullZipToPath);

                        if (!string.IsNullOrEmpty(directoryName))
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        var fileName = Path.GetFileName(fullZipToPath);
                        if (fileName.Length == 0)
                        {
                            zipEntry = zipInputStream.GetNextEntry();
                            continue;
                        }

                        var buffer = new byte[4096]; // 4K is optimum
                        using (var streamWriter = File.Create(fullZipToPath))
                        {
                            StreamUtils.Copy(zipInputStream, streamWriter, buffer);
                        }

                        zipEntry = zipInputStream.GetNextEntry();
                    }
                }
            }

            Logger.LogInformation($"'{projectName}' has been successfully created to '{outputFolder}'");

            if (AppTemplateBase.IsAppTemplate(template ?? (await TemplateInfoProvider.GetDefaultAsync()).Name))
            {
                var isCommercial = template == AppProTemplate.TemplateName;
                OpenThanksPage(uiFramework, databaseProvider, isTiered || commandLineArgs.Options.ContainsKey("separate-identity-server"), isCommercial);
            }
        }
Example #22
0
        public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
        {
            var projectName = NamespaceHelper.NormalizeNamespace(commandLineArgs.Target);

            if (projectName == null)
            {
                throw new CliUsageException(
                          "Project name is missing!" +
                          Environment.NewLine + Environment.NewLine +
                          GetUsageInfo()
                          );
            }

            Logger.LogInformation("Creating your project...");
            Logger.LogInformation("Project name: " + projectName);

            var template = commandLineArgs.Options.GetOrNull(Options.Template.Short, Options.Template.Long);

            if (template != null)
            {
                Logger.LogInformation("Template: " + template);
            }

            var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long);

            if (version != null)
            {
                Logger.LogInformation("Version: " + version);
            }

            var databaseProvider = GetDatabaseProvider(commandLineArgs);

            if (databaseProvider != DatabaseProvider.NotSpecified)
            {
                Logger.LogInformation("Database provider: " + databaseProvider);
            }

            var uiFramework = GetUiFramework(commandLineArgs);

            if (uiFramework != UiFramework.NotSpecified)
            {
                Logger.LogInformation("UI Framework: " + uiFramework);
            }

            var gitHubLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubLocalRepositoryPath.Long);

            if (gitHubLocalRepositoryPath != null)
            {
                Logger.LogInformation("GitHub Local Repository Path: " + gitHubLocalRepositoryPath);
            }

            var outputFolder = commandLineArgs.Options.GetOrNull(Options.OutputFolder.Short, Options.OutputFolder.Long);

            outputFolder = Path.Combine(outputFolder != null ? Path.GetFullPath(outputFolder) : Directory.GetCurrentDirectory(),
                                        SolutionName.Parse(projectName).FullName);

            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            Logger.LogInformation("Output folder: " + outputFolder);

            commandLineArgs.Options.Add(CliConsts.Command, commandLineArgs.Command);

            var result = await TemplateProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    SolutionName.Parse(projectName),
                    template,
                    version,
                    databaseProvider,
                    uiFramework,
                    gitHubLocalRepositoryPath,
                    commandLineArgs.Options
                    )
                );

            using (var templateFileStream = new MemoryStream(result.ZipContent))
            {
                using (var zipInputStream = new ZipInputStream(templateFileStream))
                {
                    var zipEntry = zipInputStream.GetNextEntry();
                    while (zipEntry != null)
                    {
                        var fullZipToPath = Path.Combine(outputFolder, zipEntry.Name);
                        var directoryName = Path.GetDirectoryName(fullZipToPath);

                        if (!string.IsNullOrEmpty(directoryName))
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        var fileName = Path.GetFileName(fullZipToPath);
                        if (fileName.Length == 0)
                        {
                            zipEntry = zipInputStream.GetNextEntry();
                            continue;
                        }

                        var buffer = new byte[4096]; // 4K is optimum
                        using (var streamWriter = File.Create(fullZipToPath))
                        {
                            StreamUtils.Copy(zipInputStream, streamWriter, buffer);
                        }

                        zipEntry = zipInputStream.GetNextEntry();
                    }
                }
            }

            Logger.LogInformation($"'{projectName}' has been successfully created to '{outputFolder}'");
        }
Example #23
0
        /// <summary>
        /// The default solution-name is the same as the solution file-name-without-extension
        /// </summary>
        public static SolutionName SolutionNameFromSolutionFileNameWithoutExtension(FileNameWithoutExtension solutionFileNameWithoutExtension)
        {
            var solutionName = new SolutionName(solutionFileNameWithoutExtension.Value);

            return(solutionName);
        }
Example #24
0
 public static IMetricSummaryRequestHandler GetMetricSummaryRequestHandler(SolutionName solution)
 {
     return(map[solution]);
 }
Example #25
0
        public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
        {
            if (commandLineArgs.Target == null)
            {
                throw new CliUsageException(
                          "Module name is missing!" +
                          Environment.NewLine + Environment.NewLine +
                          GetUsageInfo()
                          );
            }

            Logger.LogInformation("Downloading source code of " + commandLineArgs.Target);

            var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long);

            if (version != null)
            {
                Logger.LogInformation("Version: " + version);
            }

            var outputFolder = commandLineArgs.Options.GetOrNull(Options.OutputFolder.Short, Options.OutputFolder.Long);

            if (outputFolder != null)
            {
                if (!Directory.Exists(outputFolder))
                {
                    Directory.CreateDirectory(outputFolder);
                }

                outputFolder = Path.GetFullPath(outputFolder);
            }
            else
            {
                outputFolder = Directory.GetCurrentDirectory();
            }

            Logger.LogInformation("Output folder: " + outputFolder);

            var gitHubLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubLocalRepositoryPath.Long);

            if (gitHubLocalRepositoryPath != null)
            {
                Logger.LogInformation("GitHub Local Repository Path: " + gitHubLocalRepositoryPath);
            }

            commandLineArgs.Options.Add(CliConsts.Command, commandLineArgs.Command);

            var result = await ModuleProjectBuilder.BuildAsync(
                new ProjectBuildArgs(
                    SolutionName.Parse(commandLineArgs.Target),
                    commandLineArgs.Target,
                    version,
                    DatabaseProvider.NotSpecified,
                    UiFramework.NotSpecified,
                    gitHubLocalRepositoryPath,
                    commandLineArgs.Options
                    )
                );

            using (var templateFileStream = new MemoryStream(result.ZipContent))
            {
                using (var zipInputStream = new ZipInputStream(templateFileStream))
                {
                    var zipEntry = zipInputStream.GetNextEntry();
                    while (zipEntry != null)
                    {
                        var fullZipToPath = Path.Combine(outputFolder, zipEntry.Name);
                        var directoryName = Path.GetDirectoryName(fullZipToPath);

                        if (!string.IsNullOrEmpty(directoryName))
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        var fileName = Path.GetFileName(fullZipToPath);
                        if (fileName.Length == 0)
                        {
                            zipEntry = zipInputStream.GetNextEntry();
                            continue;
                        }

                        var buffer = new byte[4096]; // 4K is optimum
                        using (var streamWriter = File.Create(fullZipToPath))
                        {
                            StreamUtils.Copy(zipInputStream, streamWriter, buffer);
                        }

                        zipEntry = zipInputStream.GetNextEntry();
                    }
                }
            }

            Logger.LogInformation($"'{commandLineArgs.Target}' has been successfully downloaded to '{outputFolder}'");
        }
Example #26
0
        public byte[] GetSolutionBinary()
        {
            if (string.IsNullOrWhiteSpace(SolutionName))
            {
                return(null);
            }

            var stream    = new MemoryStream();
            int copyCount = 0; //use to rename duplicate files

            using (var zip = new ZipFile())
            {
                var           rootPath = Path.GetDirectoryName(SolutionName);
                List <string> files    = GetSolutionFileList(rootPath);

                if (rootPath == null || !files.Any())
                {
                    return(null);
                }

                //need to parse the .sln to grab any added projects now...
                List <string> vcxprojFiles = ParseSolutionForProjects(SolutionName);

                foreach (string vcxprojFile in vcxprojFiles)
                {
                    if (!vcxprojFile.Contains(rootPath)) //if it doesn't contain the root path it must be an external project
                    {                                    //we'll need to grab the files from each external path as the first GetSolutionFileList didn't look in any external directories
                        files.AddRange(GetSolutionFileList(Path.GetDirectoryName(vcxprojFile)));
                    }
                }

                //need to parse identifier on relative path corresponding to their vcxproj file so we can handle them separately
                List <string> relativePathFiles = new List <string>();
                foreach (var file in files)
                {
                    if (file.Contains("$$$")) //used $$$ as a delimiter to keep track of the external project file path
                    {
                        relativePathFiles.Add(file);
                    }
                }

                //temporarily remove the relative path files from the main files list -- will process next
                files = files.Except(relativePathFiles).ToList();
                files = files.Distinct(StringComparer.CurrentCultureIgnoreCase).ToList(); //just in case there are somehow dupes in this list...

                //now verify each of these files exist before adding to the zip
                var fileList = files; //new list so we can remove from the original list
                foreach (var file in fileList)
                {
                    if (!File.Exists(file))
                    {
                        files.Remove(file);
                    }
                }

                foreach (var file in files)
                {
                    if (file.Split('.').Last() == "vcxproj" || file.Split('.').Last() == "sln")
                    {   //don't add the file yet, we need to modify all .vcxproj and the .sln for the new zip path structure and modify relative path references
                        continue;
                    }

                    var name = Path.GetDirectoryName(file);
                    if (name == null)
                    {
                        continue;
                    }
                    string directoryName = "";

                    if (!file.Contains(rootPath)) //we need to account for files with a different root sub-path
                    {
                        List <string> fileParts = file.Split('\\').ToList();
                        directoryName = fileParts.Count() >= 2 ? fileParts[fileParts.Count() - 2] : "";
                    }
                    else
                    {
                        directoryName = name.Replace(rootPath, string.Empty);
                    }

                    try
                    {
                        string parsedFileName = directoryName + "/" + file.Split('\\').Last();

                        if (parsedFileName.Length > 2 || parsedFileName[0] == '\\' && parsedFileName[1] == '\\')
                        {
                            parsedFileName = parsedFileName.Remove(0, 1).Replace('\\', '/');
                        }

                        bool fileExists = zip.EntryFileNames.Contains(parsedFileName);

                        if (!fileExists && File.Exists(file))
                        {
                            zip.AddFile(file, directoryName);
                        }
                    }
                    catch (Exception ex)
                    {   //todo: handle error
                        if (ex is ArgumentException)
                        {
                            try
                            {
                                copyCount++;
                                zip.AddFile(file).FileName = directoryName + "\\ERROR_DuplicateSourceFiles\\" +
                                                             Path.GetFileNameWithoutExtension(file) + " - Copy (" + copyCount + ")" +
                                                             Path.GetExtension(file);
                                WriteErrorLog(ex, rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                            }
                            catch (Exception ex2)
                            {
                                WriteErrorLog(ex2, rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                            }
                        }
                    }
                }

                try                                    //enclose this portion in a try catch just in case something goes wrong... we want to submit as normal if so
                {
                    if (relativePathFiles.Count() > 0) //now add the relative path to the sourceFileDirectory
                    {
                        foreach (string file in relativePathFiles)
                        {
                            if (file.Split('.').Last() == "vcxproj")
                            {   //don't add the file yet, we need to modify it for the new zip path structure
                                continue;
                            }

                            string filePath      = file.Split(new string[] { "$$$" }, StringSplitOptions.None).First();
                            string fileName      = file.Split(new string[] { "$$$" }, StringSplitOptions.None).Last();
                            string directoryName = "";

                            if (!filePath.Contains(rootPath))
                            {
                                directoryName = filePath.Split('\\').ToList().Last();
                            }
                            else
                            {
                                directoryName = filePath.Replace(rootPath, string.Empty);
                            }

                            try
                            {
                                string parsedFileName = directoryName + "/" + fileName.Split('\\').Last();

                                if (parsedFileName.Length > 2 || parsedFileName[0] == '\\' && parsedFileName[1] == '\\')
                                {
                                    parsedFileName = parsedFileName.Remove(0, 1).Replace('\\', '/');
                                }

                                bool fileExists = zip.EntryFileNames.Contains(parsedFileName);

                                if (!fileExists && File.Exists(fileName)) //make sure the file isn't already in the zip and it exists on the local machine
                                {
                                    zip.AddFile(fileName, directoryName);
                                }
                            }
                            catch (Exception ex)
                            {   //todo: handle error
                                if (ex is ArgumentException)
                                {
                                    try
                                    {
                                        copyCount++;
                                        zip.AddFile(fileName).FileName = directoryName + "\\ERROR_DuplicateSourceFiles\\" +
                                                                         Path.GetFileNameWithoutExtension(fileName) + " - Copy (" + copyCount + ")" +
                                                                         Path.GetExtension(fileName);
                                        WriteErrorLog(ex, rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                                    }
                                    catch (Exception ex2)
                                    {
                                        WriteErrorLog(ex2, rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                                    }
                                }
                            }
                        }

                        //We need to parse and modify the vcxproj file to make the relative path files referenced correctly in the submission
                        //modify the .vcxproj file to point to the source folder in the zip instead of the relative path
                        foreach (string vcxprojFile in vcxprojFiles)
                        {
                            var name = Path.GetDirectoryName(vcxprojFile);
                            if (name == null)
                            {
                                continue;
                            }
                            string directoryName = "";
                            string fileName      = vcxprojFile.Split('\\').Last();

                            if (!vcxprojFile.Contains(rootPath))
                            {
                                List <string> fileParts = vcxprojFile.Split('\\').ToList();
                                directoryName = fileParts.Count() >= 2 ? fileParts[fileParts.Count() - 2] : ""; //last is the filename, we want the directory
                            }
                            else
                            {
                                directoryName = name.Replace(rootPath, string.Empty);
                            }

                            try
                            {
                                if (File.Exists(vcxprojFile))
                                {
                                    zip.AddEntry(directoryName + "\\" + fileName, System.Text.Encoding.UTF8.GetBytes(String.Join("\n", ParseVcxproj(vcxprojFile)))); //rebuilds the vcxproj file from parsed string
                                }
                                else
                                {
                                    WriteErrorLog(new Exception("vcxprojFile not found! (relative paths)"), rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                                }
                            }
                            catch (Exception ex)
                            {
                                WriteErrorLog(ex, rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                            }
                        }
                    }
                    else
                    {
                        foreach (string vcxprojFile in vcxprojFiles)
                        {
                            var name = Path.GetDirectoryName(vcxprojFile);
                            if (name == null)
                            {
                                continue;
                            }
                            string directoryName = "";
                            string fileName      = vcxprojFile.Split('\\').Last();

                            if (!vcxprojFile.Contains(rootPath))
                            {
                                List <string> fileParts = vcxprojFile.Split('\\').ToList();
                                directoryName = fileParts.Count() >= 2 ? fileParts[fileParts.Count() - 2] : ""; //last is the filename, we want the directory
                            }
                            else
                            {
                                directoryName = name.Replace(rootPath, string.Empty);
                            }

                            try
                            {
                                if (File.Exists(vcxprojFile))
                                {
                                    zip.AddFile(vcxprojFile, directoryName); //we don't have to parse this because there should be no relative paths
                                }
                                else
                                {
                                    WriteErrorLog(new Exception("vcxprojFile not found! (NO relative paths)"), rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                                }
                            }
                            catch (Exception ex)
                            {   //todo: handle error
                                if (ex is ArgumentException)
                                {
                                    try
                                    {
                                        copyCount++;
                                        zip.AddFile(vcxprojFile).FileName = directoryName + "\\ERROR_DuplicateSourceFiles\\" +
                                                                            Path.GetFileNameWithoutExtension(vcxprojFile) + " - Copy (" + copyCount + ")" +
                                                                            Path.GetExtension(vcxprojFile);
                                        WriteErrorLog(ex, rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                                    }
                                    catch (Exception ex2)
                                    {
                                        WriteErrorLog(ex2, rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteErrorLog(ex, rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                }

                try
                {
                    //need to parse the sln here before adding it to the zip. need to adjust referenced projects (if any)
                    //rebuilds the sln file from parsed string to remove project relative paths
                    zip.AddEntry(SolutionName.Split('\\').Last(), System.Text.Encoding.UTF8.GetBytes(String.Join("\n", ParseSolutionForRelativePaths(SolutionName))));
                }
                catch (Exception ex)
                {
                    WriteErrorLog(ex, rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                }

                try
                {
                    zip.Save(stream);
                    stream.Position = 0;

                    SolutionData = stream.ToArray();
                    return(SolutionData);
                }
                catch (Exception ex)
                {
                    WriteErrorLog(ex, rootPath, filePathVariables(files, SolutionName, relativePathFiles, vcxprojFiles));
                    return(null);
                }
            }
        }
 public static SolutionConfig GetSolutionConfig(SolutionName solution)
 {
     return(mapping[solution]);
 }
Example #28
0
        protected override void ProcessRecord()
        {
            try
            {
                var crmParameter = new CrmParameter(ConnectionString)
                {
                    ConnectionTimeOutMinutes = ConnectionTimeOutMinutes
                };

                SolutionDir = SolutionDir + @"\";
                crmParameter.ExecutionDirectory = SolutionDir;

                /* Connect to Dynamics */
                WriteObject($"Connecting ({crmParameter.GetConnectionStringObfuscated()})");

                SolutionTool solutionTool = null;
                solutionTool = new SolutionTool(crmParameter);

                var stopwatch = Stopwatch.StartNew();
                var taskInstantiateSolution = Task.Run(() => solutionTool = new SolutionTool(crmParameter));

                while (!taskInstantiateSolution.IsCompleted)
                {
                    WriteVerbose(".");
                    Thread.Sleep(2000);
                }

                if (taskInstantiateSolution.IsFaulted)
                {
                    foreach (var innerException in taskInstantiateSolution.Exception.InnerExceptions)
                    {
                        WriteObject($"ERROR - {innerException.Message}");
                    }

                    return;
                }

                var elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s";
                WriteObject($"Done... [{elapsed}]{Environment.NewLine}");

                /* Export Solutions */
                if (!Directory.Exists(SolutionDir))
                {
                    Directory.CreateDirectory(SolutionDir);
                }
                var solutionNames = SolutionName.Split(';');
                foreach (var sol in solutionNames)
                {
                    stopwatch = Stopwatch.StartNew();
                    var fileName = SolutionDir + sol + (Managed ? "_managed" : "") + ".zip";

                    WriteObject($"Downloading '{sol.ToUpper()}' solution ");
                    var solutionBinaryTask = solutionTool.ExportSolutionAsync(sol, Managed);

                    while (!solutionBinaryTask.IsCompleted)
                    {
                        WriteVerbose(".");
                        Thread.Sleep(3000);
                    }

                    if (solutionBinaryTask.IsFaulted)
                    {
                        foreach (var innerException in solutionBinaryTask.Exception.InnerExceptions)
                        {
                            WriteObject($"ERROR - {innerException.Message}");
                        }
                    }
                    else
                    {
                        WriteObject($"Saving file {fileName.ToUpper()} ");
                        elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s";
                        File.WriteAllBytes(fileName, solutionBinaryTask.Result);
                        WriteObject($"Done... [{elapsed}]{Environment.NewLine}");

                        if (crmParameter.ExtractSolutionContent)
                        {
                            var folderToUnzip = solutionTool.ExtractSolution(fileName, crmParameter.ExecutionDirectory, null);

                            WriteObject($"Solution is extracted to {folderToUnzip}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteObject(ex.Message);
                WriteObject(ex.StackTrace);

                if (ex.InnerException != null)
                {
                    WriteObject(ex.InnerException.Message);
                    WriteObject(ex.InnerException.StackTrace);
                }
            }
        }
Example #29
0
 public static BaseDashboardDataReaderFactory GetReaderFactory(SolutionName solution)
 {
     return(readerFactory[solution]);
 }
Example #30
0
        bool CreateProject()
        {
            if (SelectedCategory != null)
            {
                ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.LastSelectedCategory", SelectedCategory.Text);
                ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.LargeImages", SelectedIconSizeIndex);
            }

            string solution         = SolutionName.Trim();
            string name             = ProjectName.Trim();
            string location         = ProjectLocationDirectory.Trim();
            string projectNameError = CheckProjectName(solution, name, location);

            if (projectNameError != null)
            {
                MessageService.ShowError(projectNameError);
                return(false);
            }

            if (SelectedTemplate != null && ProjectLocationDirectory.Length > 0 && SolutionName.Length > 0)
            {
                TemplateItem item = SelectedTemplate;
                try {
                    System.IO.Directory.CreateDirectory(NewProjectDirectory);
                } catch (Exception) {
                    MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.CantCreateDirectoryError}");
                    return(false);
                }

                ProjectTemplateOptions cinfo = new ProjectTemplateOptions();

                if (item.Template.SupportedTargetFrameworks.Any())
                {
                    cinfo.TargetFramework = SelectedTargetFramework;
                    ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.TargetFramework", cinfo.TargetFramework.TargetFrameworkVersion);
                }

                cinfo.ProjectBasePath = DirectoryName.Create(NewProjectDirectory);
                cinfo.ProjectName     = name;

                if (CreateNewSolution)
                {
                    if (!SD.ProjectService.CloseSolution())
                    {
                        return(false);
                    }
                    _result = item.Template.CreateAndOpenSolution(cinfo, NewSolutionDirectory, solution);
                }
                else
                {
                    cinfo.Solution       = SolutionFolder.ParentSolution;
                    cinfo.SolutionFolder = SolutionFolder;
                    _result = item.Template.CreateProjects(cinfo);
                    cinfo.Solution.Save();
                }

                if (_result != null)
                {
                    item.Template.RunOpenActions(_result);
                }

                ProjectBrowserPad.RefreshViewAsync();
                return(true);
            }
            return(false);
        }