예제 #1
0
        protected override object FormatOutput(object output)
        {
            var item = output as List <RuntimePackageDetails>;

            if (item == null)
            {
                return(base.FormatOutput(output));
            }

            var itemPsObj = new PSObject(item);
            RuntimePackageDetails goalPackageDetails = item.SingleOrDefault(goalPackage => goalPackage.IsGoalPackage);

            if (goalPackageDetails != null)
            {
                // State
                var statePropertyPsObj = new PSObject(goalPackageDetails.Version);
                statePropertyPsObj.Members.Add(
                    new PSCodeMethod(
                        Constants.ToStringMethodName,
                        typeof(OutputFormatter).GetMethod(Constants.FormatObjectMethodName)));

                itemPsObj.Properties.Add(
                    new PSNoteProperty(
                        Constants.GoalRuntimeVersionPropertyName,
                        statePropertyPsObj));

                var statePropertyPsObj2 = new PSObject(goalPackageDetails.TargetPackageLocation);
                statePropertyPsObj2.Members.Add(
                    new PSCodeMethod(
                        Constants.ToStringMethodName,
                        typeof(OutputFormatter).GetMethod(Constants.FormatObjectMethodName)));

                itemPsObj.Properties.Add(
                    new PSNoteProperty(
                        Constants.GoalRuntimeLocationPropertyName,
                        statePropertyPsObj2));
            }

            var statePropertyPsObj3 = new PSObject(item);

            statePropertyPsObj3.Members.Add(
                new PSCodeMethod(
                    Constants.ToStringMethodName,
                    typeof(OutputFormatter).GetMethod(Constants.FormatObjectMethodName)));

            itemPsObj.Properties.Add(
                new PSNoteProperty(
                    Constants.RuntimePackagesPropertyName,
                    statePropertyPsObj3));

            return(itemPsObj);
        }
예제 #2
0
        internal static async Task <RuntimePackageDetails> ValidateCodeVersionAsync(string targetCodeVersion)
        {
            RuntimePackageDetails targetCodePackage = null;

            if (targetCodeVersion == DMConstants.AutoupgradeCodeVersion)
            {
                try
                {
                    targetCodePackage = DeploymentManager.GetDownloadableRuntimeVersions(DownloadableRuntimeVersionReturnSet.Latest).First <RuntimePackageDetails>();
                }
                catch (Exception ex)
                {
                    SFDeployerTrace.WriteError(
                        "Failed trying to get latest downloadable versions for auto upgrade version. Exception: {0}",
                        ex);
                }
            }
            else
            {
                var currentCodeVersion = await StandaloneUtility.GetCurrentCodeVersion().ConfigureAwait(false);

                var upgradeableVersions = new List <RuntimePackageDetails>();
                try
                {
                    upgradeableVersions = DeploymentManager.GetUpgradeableRuntimeVersions(currentCodeVersion);
                }
                catch (Exception ex)
                {
                    SFDeployerTrace.WriteError(
                        "Failed trying to load upgradeableVersions for the given version. Exception: {0}",
                        ex);

                    return(null);
                }

                targetCodePackage = upgradeableVersions.SingleOrDefault(version => version.Version.Equals(targetCodeVersion));
                if (targetCodePackage == null)
                {
                    // Todo: If no upgradeable version is found, checks for all supported versions.
                    // Need to change this to check for only supported downgradable versions once the goal state file is modified.
                    var allSupportedVersions = DeploymentManager.GetDownloadableRuntimeVersions();
                    if (allSupportedVersions != null && allSupportedVersions.Any(version => version.Version.Equals(targetCodeVersion)))
                    {
                        targetCodePackage = allSupportedVersions.SingleOrDefault(version => version.Version.Equals(targetCodeVersion));
                    }
                }
            }

            return(targetCodePackage);
        }