Ejemplo n.º 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..."));
            }
        }
Ejemplo n.º 2
0
        protected override IEnumerable <ICommandOutput> ExecuteCore()
        {
            var targetDescriptor = HostEnvironment.GetOrCreateScopedDescriptor(Scope ?? string.Empty);

            yield return(VerifyDescriptor(targetDescriptor));

            yield return(VerifyProjectRepository());

            yield return(SetupEnvironmentForAdd());

            var sourceRepositories = GetSourceRepositories();


            if (Project && System)
            {
                var sysToAdd = new List <PackageIdentifier>();
                using (ChangeMonitor(targetDescriptor))
                {
                    foreach (var m in PackageManager.AddProjectPackage(PackageRequest, sourceRepositories, targetDescriptor.Value, HostEnvironment.ProjectRepository, AddOptions))
                    {
                        yield return(ToOutput(m));

                        ParseSuccess(m, sysToAdd.Add);
                    }
                    foreach (var identifier in sysToAdd)
                    {
                        foreach (var m in PackageManager.AddSystemPackage(PackageRequest.Exact(identifier.Name, identifier.Version), sourceRepositories, HostEnvironment.SystemRepository))
                        {
                            yield return(ToOutput(m));
                        }
                    }
                }
            }
            else if (Project)
            {
                using (ChangeMonitor(targetDescriptor))
                {
                    foreach (var m in PackageManager.AddProjectPackage(PackageRequest, sourceRepositories, targetDescriptor.Value, HostEnvironment.ProjectRepository, AddOptions))
                    {
                        yield return(ToOutput(m));
                    }
                }
            }
            else if (System)
            {
                foreach (var m in PackageManager.AddSystemPackage(PackageRequest, sourceRepositories, HostEnvironment.SystemRepository, AddOptions))
                {
                    yield return(ToOutput(m));
                }
            }

            if (_packageNotFound)
            {
                var hit = false;
                foreach (var m in PackageManager.ListPackages(sourceRepositories, Name))
                {
                    if (!hit)
                    {
                        yield return(new Info("Did you mean one of the following package?", Name));

                        hit = true;
                    }
                    yield return(ToOutput(m));
                }
            }
            if (ShouldUpdateDescriptor)
            {
                TrySaveDescriptorFile(targetDescriptor);
            }
        }