Пример #1
0
        public IEnumerable <ICommandOutput> Execute()
        {
            var sourceFolder = _environment.CurrentDirectory.GetDirectory("src");
            var zip          = new FastZip();

            zip.ExtractZip(new MemoryStream(Templates.AspNetTemplate), sourceFolder.Path.FullPath,
                           FastZip.Overwrite.Never, x => true, null, null, false, true);
            var projectFolder = sourceFolder.GetDirectory(Namespace);

            sourceFolder.GetDirectory(OR_ASPNET_TEMPLATE).MoveTo(projectFolder);
            // rename project folders
            var solution = sourceFolder.GetFile(Name + ".sln");

            sourceFolder.GetFile("openrasta-aspnettemplate.sln").MoveTo(solution);
            ReplaceTokensAndSave(solution);
            var projectFile = projectFolder.GetFile(Namespace + ".csproj");

            projectFolder.GetFile(OR_ASPNET_TEMPLATE + ".csproj").MoveTo(projectFile);
            ReplaceTokensAndSave(projectFile);
            foreach (var file in sourceFolder.Files("*.cs", SearchScope.SubFolders))
            {
                ReplaceTokensAndSave(file);
            }
            yield return(new Info("Template created."));

            var sourceRepositories = new[] { _environment.CurrentDirectoryRepository, _environment.SystemRepository }
            .Concat(_remotes.FetchRepositories())
            .Concat(new[] { _environment.ProjectRepository })
            .Where(x => x != null);

            _packageManager.AddProjectPackage(
                PackageRequest.Exact("openrasta-hosting-aspnet", "2.1".ToVersion()),
                sourceRepositories,
                _environment.Descriptor,
                _environment.ProjectRepository).ToList();
            yield return(new Info("OpenRasta added and initialized."));

            _environment.ScopedDescriptors[string.Empty].Save();
            if (StartEditor)
            {
                var process = new Process
                {
                    StartInfo = new ProcessStartInfo(solution.Path.FullPath)
                    {
                        UseShellExecute = true
                    }
                };
                process.Start();
                yield return(new Info("Starting editor..."));
            }
        }