Exemple #1
0
        public void TestDistributeExpiredPackages()
        {
            IPackageRepository  packageRepository  = new MockPackageRepository();
            IEmployeeRepository employeeRepository = new MockEmployeeRepository();
            var controller = new PackageController(employeeRepository, packageRepository);

            Package package = packageRepository.GetPackageWidthBarCode("65985438786");

            List <SelectedPackage> spList = new List <SelectedPackage>();

            SelectedPackage sp = new SelectedPackage();

            sp.BarCode                 = package.BarCode;
            sp.CentreId                = package.CurrentLocation.CentreId;
            sp.ExpirationDate          = package.ExpirationDate;
            sp.PackageId               = package.PackageId;
            sp.PackageTypeId           = package.PackageType.PackageTypeId;
            sp.CurrentEmployeeUserName = "******";

            spList.Add(sp);

            var model = new PackageDistributeViewModel()
            {
                SelectedPackages = spList,
            };

            var result = controller.DistributeSave(model) as ViewResult;

            var modelReturned = result.Model as PackageDistributeViewModel;

            Assert.AreEqual("DistributeComplete", result.ViewName);
            Assert.AreEqual(PackageResult.PackageHasExpired, modelReturned.SelectedPackages[0].ProcessResultMessage);
        }
Exemple #2
0
        public void TestReceivedPackagePage_Distributed()
        {
            var controller = new PackageTransitController(employeeRepository, packageRepository);

            controller.ControllerContext = new ENetCareMVC.UnitTest.FakeClasses.FakeControllerContext(controller, "*****@*****.**", new string[] { "Agent" });

            Package package = packageRepository.GetPackageWidthBarCode("11623542734");

            List <SelectedPackage> spList = new List <SelectedPackage>();

            SelectedPackage sp = new SelectedPackage()
            {
                BarCode = package.BarCode
            };

            spList.Add(sp);

            var model = new PackageTransitReceiveViewModel()
            {
                SelectedPackages = spList,
                BarCode          = package.BarCode,
                ReceiveDate      = DateTime.Today
            };

            var result        = controller.ReceiveSave(model) as ViewResult;
            var modelReturned = result.Model as PackageTransitReceiveViewModel;

            Assert.AreEqual("ReceiveComplete", result.ViewName);
            Assert.AreEqual("Successful!", modelReturned.SelectedPackages[0].ProcessResultMessage);
        }
        private async Task <PackageStub> ConvertPackage(ProjectResource project, SelectedPackage package)
        {
            var packageDetails = await GetPackageId(project, package.ActionName, package.ActionName);

            return(new PackageStub {
                Version = package.Version, StepName = packageDetails.StepName, StepId = packageDetails.StepId, Id = packageDetails.PackageId
            });
        }
        private static async Task CreateRelease(string projectName,
                                                CreateReleaseParams releaseParams, IOctopusAsyncClient octo)
        {
            var project = await octo.Repository.Projects.FindByName(projectName);

            var channel = await octo.GetChannelResource(project, releaseParams.Channel);

            if (channel == null)
            {
                Console.WriteLine($"Skipped as no such channel for {projectName}");
                return;
            }

            var releaseResource = new ReleaseResource()
            {
                ChannelId = channel.Id,
                ProjectId = project.Id,
                Version   = releaseParams.GetEffectiveReleaseName()
            };
            var process = await octo.Repository.DeploymentProcesses.Get(project.DeploymentProcessId);

            var template = await octo.Repository.DeploymentProcesses.GetTemplate(process, channel);

            foreach (var package in template.Packages)
            {
                var selectedPackage = new SelectedPackage
                {
                    ActionName = package.ActionName,
                    Version    = releaseParams.Version
                };
                releaseResource.SelectedPackages.Add(selectedPackage);
            }

            try
            {
                await octo.Repository.Releases.Create(releaseResource);
            }
            catch (OctopusValidationException octoEx)
            {
                if (octoEx.ToString()
                    .Contains("Please use a different version, or look at using a mask to auto-increment the number"))
                {
                    Console.WriteLine(
                        $"Skipped creating release as version {releaseParams.GetEffectiveReleaseName()} for {project.Name} already exists.");
                }
                else
                {
                    Console.Error.WriteLine(
                        $"Failed to create release for {projectName} in channel {channel.Name} {octoEx}");
                    throw;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine($"Failed to create release for {projectName} in channel {channel.Name} {ex}");
                throw;
            }
        }
Exemple #5
0
        public SelectionResult Add(ISelectedBarCodesViewModel model)
        {
            if (model.SelectedPackages == null)
            {
                model.SelectedPackages = new List <SelectedPackage>();
            }

            var result = new SelectionResult();

            var packageService  = GetPackageService();
            var package         = packageService.Retrieve(model.BarCode);
            var currentEmployee = GetCurrentEmployee();

            if (package == null)
            {
                result.Succeeded    = false;
                result.ErrorMessage = "BarCode does not exist";
            }
            else if (model.SelectedPackages.FirstOrDefault(p => p.BarCode == model.BarCode) != null)
            {
                result.Succeeded    = false;
                result.ErrorMessage = "BarCode already selected";
            }
            else
            {
                result = ValidatePackage(package);
            }

            if (result.Succeeded)
            {
                var selectedPackage = new SelectedPackage()
                {
                    BarCode                 = model.BarCode,
                    ExpirationDate          = package.ExpirationDate,
                    PackageId               = package.PackageId,
                    PackageTypeDescription  = package.PackageType.Description,
                    PackageTypeId           = package.PackageTypeId,
                    CentreId                = package.CurrentLocation == null ? 0 : package.CurrentLocation.CentreId,
                    CurrentEmployeeUserName = currentEmployee.UserName
                };

                model.SelectedPackages.Add(selectedPackage);

                model.BarCode = string.Empty;
            }

            return(result);
        }
Exemple #6
0
        private static async Task <int> CreateRelease(string server, string apiKey, string projectName, string semVer, string releaseNotes)
        {
            Console.WriteLine($"Creating Octopus Deploy Release for project: {projectName} {semVer}");

            try
            {
                var octoEndpoint = new OctopusServerEndpoint(server, apiKey);
                using (var client = await OctopusAsyncClient.Create(octoEndpoint).ConfigureAwait(false))
                {
                    var octoRepository = client.Repository;
                    var octoProject    = await octoRepository.Projects.FindOne(projectResource => projectResource.Name.Equals(projectName)).ConfigureAwait(false);

                    var octoProcess = await octoRepository.DeploymentProcesses.Get(octoProject.DeploymentProcessId).ConfigureAwait(false);

                    var octoChannel = await octoRepository.Client.Get <ChannelResource>($"/api/projects/{octoProject.Id}/channels").ConfigureAwait(false);

                    var octoTemplate = await octoRepository.DeploymentProcesses.GetTemplate(octoProcess, octoChannel).ConfigureAwait(false);

                    var octoReleaseResource = new ReleaseResource
                    {
                        Version      = semVer,
                        ProjectId    = octoProject.Id,
                        ReleaseNotes = releaseNotes
                    };

                    foreach (var package in octoTemplate.Packages)
                    {
                        var selectedPackage = new SelectedPackage
                        {
                            ActionName = package.ActionName,
                            Version    = semVer
                        };

                        octoReleaseResource.SelectedPackages.Add(selectedPackage);
                    }

                    await octoRepository.Releases.Create(octoReleaseResource).ConfigureAwait(false);
                }

                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Octopus Deploy Create Release failed with message:{Environment.NewLine}{ex.Message}{Environment.NewLine}{ex.StackTrace}");
                return(1);
            }
        }
Exemple #7
0
        public void TestSendPackagePage_InTransit()
        {
            var controller = new PackageTransitController(employeeRepository, packageRepository);

            controller.ControllerContext = new ENetCareMVC.UnitTest.FakeClasses.FakeControllerContext(controller, "*****@*****.**", new string[] { "Agent" });
            Package package = packageRepository.GetPackageWidthBarCode("13154242431");

            DistributionCentre destinationLocation = new DistributionCentre()
            {
                CentreId = 1,
                Name     = "mainCentre"
            };

            List <SelectedPackage> spList = new List <SelectedPackage>();

            SelectedPackage sp = new SelectedPackage()
            {
                BarCode  = package.BarCode,
                CentreId = package.CurrentLocation.CentreId,
            };

            spList.Add(sp);

            var model = new PackageTransitSendViewModel()
            {
                SelectedPackages    = spList,
                DestinationCentreId = destinationLocation.CentreId,
                BarCode             = package.BarCode,
                SendDate            = DateTime.Today
            };

            var result = controller.SendSave(model) as ViewResult;

            var modelReturned = result.Model as PackageTransitSendViewModel;

            //TransitResult.PackageAlreadyAtDestination

            Assert.AreEqual("SendComplete", result.ViewName);
            Assert.AreEqual(PackageResult.PackageIsNotInStock, modelReturned.SelectedPackages[0].ProcessResultMessage);
        }
        static void Main(string[] args)
        {
            var apiKey              = "API-XXXXXXXXXXXXXXXXXXXXXXXXXX";
            var octopusURL          = "https://octopus.url";
            var projectName         = "testproject2";
            var releaseVersion      = "";
            var channelName         = "Default";
            var environmentName     = "Dev";
            var fixedPackageVersion = "";

            var endpoint   = new OctopusServerEndpoint(octopusURL, apiKey);
            var repository = new OctopusRepository(endpoint);

            var project     = repository.Projects.FindByName(projectName);
            var environment = repository.Environments.FindByName(environmentName);

            var template = new ReleaseTemplateResource();
            var process  = new DeploymentProcessResource();

            process = repository.DeploymentProcesses.Get(project.DeploymentProcessId);
            var channel = repository.Channels.FindByName(project, channelName);

            template = repository.DeploymentProcesses.GetTemplate(process, channel);

            //if you dont pass a value to newReleaseVersion, It'll calculate it using the version template of your project. Just like when you hit the "Create Release" button from the web portal
            if (string.IsNullOrEmpty(releaseVersion))
            {
                releaseVersion = template.NextVersionIncrement;
            }

            //Creating the release object
            var newrelease = new ReleaseResource
            {
                ProjectId = project.Id,
                Version   = releaseVersion
            };

            foreach (var package in template.Packages)
            {
                var selectedPackage = new SelectedPackage
                {
                    ActionName           = package.ActionName,
                    PackageReferenceName = package.PackageReferenceName
                };

                //If you don't pass a value to FixedPackageVersion, Octopus will look for the latest one in the feed.
                if (string.IsNullOrEmpty(fixedPackageVersion))
                {
                    //Gettin the latest version of the package available in the feed.
                    //This is probably the most complicated line. The expression can get tricky, as a step(action) might be a parent and have many children(more nested actions)
                    var packageStep =
                        process.Steps.FirstOrDefault(s => s.Actions.Any(a => a.Name == selectedPackage.ActionName))?
                        .Actions.FirstOrDefault(a => a.Name == selectedPackage.ActionName);

                    var packageId = packageStep.Properties["Octopus.Action.Package.PackageId"].Value;
                    var feedId    = packageStep.Properties["Octopus.Action.Package.FeedId"].Value;

                    var feed = repository.Feeds.Get(feedId);

                    var latestPackageVersion = repository.Feeds.GetVersions(feed, new[] { packageId }).FirstOrDefault();

                    selectedPackage.Version = latestPackageVersion.Version;
                }
                else
                {
                    selectedPackage.Version = fixedPackageVersion;
                }

                newrelease.SelectedPackages.Add(selectedPackage);
            }

            //Creating the release in Octopus
            var release = repository.Releases.Create(newrelease);

            //creating the deployment object
            var deployment = new DeploymentResource
            {
                ReleaseId     = release.Id,
                ProjectId     = project.Id,
                EnvironmentId = environment.Id
            };

            //Deploying the release in Octopus
            repository.Deployments.Create(deployment);
        }
Exemple #9
0
        private IEnumerable <object> Load()
        {
            if (GameSettings.VerboseLogging)
            {
                DebugConsole.NewMessage("LOADING COROUTINE", Color.Lime);
            }
            GUI.GraphicsDevice = base.GraphicsDevice;
            GUI.Init(Content);

            GUIComponent.Init(Window);
            DebugConsole.Init(Window);
            DebugConsole.Log(SelectedPackage == null ? "No content package selected" : "Content package \"" + SelectedPackage.Name + "\" selected");
            yield return(CoroutineStatus.Running);

            LightManager = new Lights.LightManager(base.GraphicsDevice, Content);

            Hull.renderer         = new WaterRenderer(base.GraphicsDevice, Content);
            TitleScreen.LoadState = 1.0f;
            yield return(CoroutineStatus.Running);

            GUI.LoadContent();
            TitleScreen.LoadState = 2.0f;
            yield return(CoroutineStatus.Running);

            Mission.Init();
            MapEntityPrefab.Init();
            LevelGenerationParams.LoadPresets();
            TitleScreen.LoadState = 10.0f;
            yield return(CoroutineStatus.Running);

            JobPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Jobs));
            // Add any missing jobs from the prefab into Config.JobNamePreferences.
            foreach (JobPrefab job in JobPrefab.List)
            {
                if (!Config.JobNamePreferences.Contains(job.Name))
                {
                    Config.JobNamePreferences.Add(job.Name);
                }
            }
            StructurePrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Structure));
            TitleScreen.LoadState = 20.0f;
            yield return(CoroutineStatus.Running);

            ItemPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Item));
            TitleScreen.LoadState = 30.0f;
            yield return(CoroutineStatus.Running);

            Debug.WriteLine("sounds");
            CoroutineManager.StartCoroutine(SoundPlayer.Init());

            int i = 0;

            while (!SoundPlayer.Initialized)
            {
                i++;
                TitleScreen.LoadState = SoundPlayer.SoundCount == 0 ?
                                        30.0f :
                                        Math.Min(30.0f + 40.0f * i / Math.Max(SoundPlayer.SoundCount, 1), 70.0f);
                yield return(CoroutineStatus.Running);
            }

            TitleScreen.LoadState = 70.0f;
            yield return(CoroutineStatus.Running);

            GameModePreset.Init();

            Submarine.RefreshSavedSubs();
            TitleScreen.LoadState = 80.0f;
            yield return(CoroutineStatus.Running);

            GameScreen            = new GameScreen(GraphicsDeviceManager.GraphicsDevice, Content);
            TitleScreen.LoadState = 90.0f;
            yield return(CoroutineStatus.Running);

            MainMenuScreen = new MainMenuScreen(this);
            LobbyScreen    = new LobbyScreen();

            ServerListScreen = new ServerListScreen();

            SubEditorScreen       = new SubEditorScreen(Content);
            CharacterEditorScreen = new CharacterEditorScreen();
            ParticleEditorScreen  = new ParticleEditorScreen();

            yield return(CoroutineStatus.Running);

            ParticleManager = new ParticleManager("Content/Particles/ParticlePrefabs.xml", GameScreen.Cam);
            ParticleManager.LoadPrefabs();
            DecalManager = new DecalManager("Content/Particles/DecalPrefabs.xml");
            yield return(CoroutineStatus.Running);

            LocationType.Init();
            MainMenuScreen.Select();

            TitleScreen.LoadState = 100.0f;
            hasLoaded             = true;
            if (GameSettings.VerboseLogging)
            {
                DebugConsole.NewMessage("LOADING COROUTINE FINISHED", Color.Lime);
            }
            yield return(CoroutineStatus.Success);
        }
Exemple #10
0
        public override void Execute()
        {
            if (string.IsNullOrWhiteSpace(ProjectName))
            {
                throw new CommandException("Please specify a project name using the parameter: --project=XYZ");
            }

            if (Delay.HasValue)
            {
                if (!Wait)
                {
                    Fork();
                    return;
                }
                Log.Debug(string.Format("Waiting {0} to create release ...", Delay.Value));
                Thread.Sleep(Delay.Value);
            }

            Log.Debug("Finding project: " + ProjectName);
            var project = Session.GetProject(ProjectName);

            Log.Debug("Finding environments...");
            var environments = Session.FindEnvironments(DeployToEnvironmentNames);

            Log.Debug("Finding steps for project...");
            var steps = Session.FindStepsForProject(project);

            Log.Debug("Getting package versions for each step...");
            var selected = new List <SelectedPackage>();

            foreach (var step in steps)
            {
                SelectedPackage version;
                var             packageVersionConstraint = GetPackageVersionForStep(step);
                if (packageVersionConstraint != null)
                {
                    if (ForceVersion)
                    {
                        version = new SelectedPackage {
                            StepId = step.Id, NuGetPackageVersion = packageVersionConstraint
                        };
                    }
                    else
                    {
                        version = Session.GetPackageForStep(step, packageVersionConstraint);
                    }
                }
                else
                {
                    version = Session.GetLatestPackageForStep(step);
                }

                Log.DebugFormat("{0} - latest: {1}", step.Description, version.NuGetPackageVersion);
                selected.Add(version);
            }

            var versionNumber = VersionNumber;

            if (string.IsNullOrWhiteSpace(versionNumber))
            {
                versionNumber = selected.Select(p => SemanticVersion.Parse(p.NuGetPackageVersion)).OrderByDescending(v => v).First().ToString();
                Log.Warn("A --version parameter was not specified, so a version number was automatically selected based on the highest package version: " + versionNumber);
            }

            Log.Debug("Creating release: " + versionNumber);
            var release = Session.CreateRelease(project, selected, versionNumber, ReleaseNotes);

            Log.Info("Release created successfully!");

            if (environments != null)
            {
                var linksToDeploymentTasks = Session.GetDeployments(release, environments, Force, Log);

                if (WaitForDeployment)
                {
                    deploymentWatcher.WaitForDeploymentsToFinish(Session, linksToDeploymentTasks, DeploymentTimeout, DeploymentStatusCheckSleepCycle);
                }
            }
        }
        void LoadPackage(string path, bool skipFileAppend)
        {
            if (!string.IsNullOrWhiteSpace(SelectedPackage.UniqueID))
            {
                txtNamespace.Text = SelectedPackage.UniqueID;
            }
            if (!string.IsNullOrWhiteSpace(SelectedPackage.Name))
            {
                txtName.Text = SelectedPackage.Name;
            }
            if (!string.IsNullOrWhiteSpace(SelectedPackage.Version))
            {
                txtVersion.Text = SelectedPackage.Version;
            }
            if (!string.IsNullOrWhiteSpace(SelectedPackage.Author))
            {
                txtAuthor.Text = SelectedPackage.Author;
            }
            if (!string.IsNullOrWhiteSpace(SelectedPackage.URL))
            {
                txtPackURL.Text = SelectedPackage.URL;
            }

            if (SelectedPackage.License != null)
            {
                License = SelectedPackage.License;
                if (License.LicenseSource == RMPackLic.Source.File && !string.IsNullOrWhiteSpace(License.Data))
                {
                    License.Data = path + "\\" + License.Data;
                }
            }

            if (!string.IsNullOrWhiteSpace(SelectedPackage.Description))
            {
                txtDesc.Text = SelectedPackage.Description;
            }

            if (SelectedPackage.Implicit)
            {
                cboxImplicit.Checked = true;
                if (!string.IsNullOrWhiteSpace(path))
                {
                    txtAssetDir.Text = path;
                }
                ProcessLicenseAndImplicitDirCommonPath();
                btnViewAssetDir.Enabled = true;
            }
            else
            {
                CustomAssetPack = SelectedPackage.Clone() as RMPackage;
                if (!skipFileAppend)
                {
                    List <RMPackFile> listOfFiles = CustomAssetPack.RetrieveAllFiles();
                    if (listOfFiles != null)
                    {
                        foreach (RMPackFile file in listOfFiles)
                        {
                            file.Path = path + "\\" + file.Path;
                        }
                    }
                }
                ProcessCustomAssetsCommonPath(MethodBase.GetCurrentMethod().ToLogFormatFullName());
            }
        }
Exemple #12
0
        public static ReleaseResource CreateRelease(string projectName, CreateReleaseSettings settings)
        {
            var client        = WebClient.GetWebClientRef();
            var project       = new OctoProject(projectName);
            var targetChannel = project.GetChannelByName(settings.ReleaseChannel);
            var process       = client.GetDeploymentProcessRepo().Get(project.GetDeploymentProcessId());
            var template      = client.GetDeploymentProcessRepo().GetTemplate(process, targetChannel);

            if (project.IsDisabled() && !settings.IgnoreChannelRules)
            {
                return(null);
            }

            // If no version set up in the createReleaseSettings, Create a version number by using template
            if (string.IsNullOrEmpty(settings.ReleaseVersion))
            {
                settings.ReleaseVersion = template.NextVersionIncrement;
            }

            // Initialize the new release with basic settings
            var newRelease = new ReleaseResource {
                ProjectId    = project.GetProjectId(),
                ChannelId    = targetChannel.Id,
                Version      = settings.ReleaseVersion,
                ReleaseNotes = settings.ReleaseNotes
            };

            Console.WriteLine("Create Release Version: {0} of {1} at {2}", settings.ReleaseVersion, projectName, targetChannel.Name);

            var feedRepo = client.GetFeedRepo();

            // Select packages
            foreach (var package in template.Packages)
            {
                var actionName      = package.ActionName;
                var packageId       = package.PackageId;
                var feedId          = package.FeedId;
                var selectedPackage = new SelectedPackage()
                {
                    ActionName = actionName
                };
                // If the package version is not specify, choose the one with the latest version at the current channel
                if (settings.Packages is null)
                {
                    var feed = feedRepo.Get(feedId);
                    var latestPackageVersion = feedRepo.GetVersions(feed, new[] { packageId }).FirstOrDefault();

                    // When the package needed doesn't exist on Octopus repo
                    if (latestPackageVersion is null)
                    {
                        throw new PackageNotFoundException(
                                  $"Please upload package: {packageId} to Octopus repo");
                    }
                    selectedPackage.Version = latestPackageVersion.Version;
                }
                else
                {
                    selectedPackage.Version = settings.Packages[package.PackageId];
                }

                Console.WriteLine("{0}: {1} {2}", actionName, packageId, selectedPackage.Version);

                newRelease.SelectedPackages.Add(selectedPackage);
            }

            return(client.GetReleaseRepo().Create(newRelease, settings.IgnoreChannelRules));
        }