public Solution CreatePatch(string uniqueName,
                                    string versionNumber,
                                    string displayName)
        {
            using (var context = new CIContext(OrganizationService))
            {
                if (string.IsNullOrEmpty(versionNumber))
                {
                    Logger.LogVerbose("VersionNumber not supplied. Generating default VersionNumber");

                    var solution = (from sol in context.SolutionSet
                                    where sol.UniqueName == uniqueName || sol.UniqueName.StartsWith(uniqueName + "_Patch")
                                    orderby sol.Version descending
                                    select new Solution { Version = sol.Version, FriendlyName = sol.FriendlyName }).FirstOrDefault();
                    if (solution == null || string.IsNullOrEmpty(solution.Version))
                    {
                        throw new Exception(string.Format("Parent solution with unique name {0} not found.", uniqueName));
                    }

                    string[] versions = solution.Version.Split('.');
                    char dot = '.';
                    versionNumber = string.Concat(versions[0], dot, versions[1], dot, Convert.ToInt32(versions[2]) + 1, dot, 0);
                    Logger.LogVerbose("New VersionNumber: {0}", versionNumber);
                }

                if (string.IsNullOrEmpty(displayName))
                {
                    Logger.LogVerbose("displayName not supplied. Generating default DisplayName");

                    var solution = (from sol in context.SolutionSet
                                    where sol.UniqueName == uniqueName
                                    select new Solution { FriendlyName = sol.FriendlyName }).FirstOrDefault();

                    if (solution == null || string.IsNullOrEmpty(solution.FriendlyName))
                    {
                        throw new Exception(string.Format("Parent solution with unique name {0} not found.", uniqueName));
                    }

                    displayName = solution.FriendlyName;
                }

                var cloneAsPatch = new CloneAsPatchRequest
                {
                    DisplayName = displayName,
                    ParentSolutionUniqueName = uniqueName,
                    VersionNumber = versionNumber,
                };

                CloneAsPatchResponse response = OrganizationService.Execute(cloneAsPatch) as CloneAsPatchResponse;

                Logger.LogInformation("Patch solution created with Id {0}", response.SolutionId);

                Solution patch = GetSolution(response.SolutionId, new ColumnSet(true));

                Logger.LogInformation("Patch solution name: {0}", patch.UniqueName);

                return patch;
            }
        }
Exemplo n.º 2
0
        public Solution CreatePatch(string uniqueName,
                                    string versionNumber,
                                    string displayName)
        {
            var solution = GetSolution(uniqueName, new ColumnSet("version", "friendlyname"));

            if (solution == null)
            {
                throw new Exception(string.Format("Solution with unique name {0} not found.", uniqueName));
            }

            if (string.IsNullOrEmpty(versionNumber))
            {
                Logger.LogVerbose("VersionNumber not supplied. Generating default VersionNumber");

                var patches = GetSolutionPatches(uniqueName);

                Version version;
                if (patches.Count == 0)
                {
                    version = new Version(solution.Version);
                }
                else
                {
                    version = new Version(patches[0].Version);
                }

                char dot = '.';
                versionNumber = string.Concat(version.Major, dot, version.Minor, dot, version.Build + 1, dot, 0);
                Logger.LogVerbose("New VersionNumber: {0}", versionNumber);
            }

            if (string.IsNullOrEmpty(displayName))
            {
                Logger.LogVerbose("displayName not supplied. Generating default DisplayName");

                displayName = solution.FriendlyName;

                Logger.LogVerbose("New DisplayName: {0}", displayName);
            }

            var cloneAsPatch = new CloneAsPatchRequest
            {
                DisplayName = displayName,
                ParentSolutionUniqueName = uniqueName,
                VersionNumber            = versionNumber,
            };

            CloneAsPatchResponse response = OrganizationService.Execute(cloneAsPatch) as CloneAsPatchResponse;

            Logger.LogInformation("Patch solution created with Id {0}", response.SolutionId);

            Solution patch = GetSolution(response.SolutionId, new ColumnSet(true));

            Logger.LogInformation("Patch solution name: {0}", patch.UniqueName);

            return(patch);
        }
Exemplo n.º 3
0
        private static void CloneAsPatch(IOrganizationService organizationService, Entity solution)
        {
            string currentVersion = solution.GetAttributeValue <string>("version");
            string version        = VersionNumberUtil.PromptIncrementPatchOrBuild(currentVersion);

            // Create patch
            CloneAsPatchRequest cloneRequest = new CloneAsPatchRequest();

            cloneRequest.DisplayName = $"{solution.GetAttributeValue<string>("friendlyname")} v{version}";
            cloneRequest.ParentSolutionUniqueName = solution.GetAttributeValue <string>("uniquename");
            cloneRequest.VersionNumber            = version;
            CloneAsPatchResponse cloneResponse = (CloneAsPatchResponse)organizationService.Execute(cloneRequest);

            Console.WriteLine($"Created patch solution {cloneRequest.DisplayName}");
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            base.WriteVerbose("Executing CloneAsPatchRequest");
            using (var context = new CIContext(OrganizationService))
            {
                if (string.IsNullOrEmpty(VersionNumber))
                {
                    var solution = (from sol in context.SolutionSet
                                    where sol.UniqueName == ParentSolutionUniqueName || sol.UniqueName.StartsWith(ParentSolutionUniqueName + "_Patch")
                                    orderby sol.Version descending
                                    select new Solution {
                        Version = sol.Version
                    }).FirstOrDefault();
                    if (solution == null || string.IsNullOrEmpty(solution.Version))
                    {
                        throw new Exception(string.Format("Parent solution with unique name {0} not found.", ParentSolutionUniqueName));
                    }

                    string[] versions = solution.Version.Split('.');
                    char     dot      = '.';
                    VersionNumber = string.Concat(versions[0], dot, versions[1], dot, Convert.ToInt32(versions[2]) + 1, dot, versions[3]);
                    base.WriteVerbose(string.Format("New version number {0}", VersionNumber));
                }

                var cloneAsPatch = new CloneAsPatchRequest
                {
                    DisplayName = DisplayName,
                    ParentSolutionUniqueName = ParentSolutionUniqueName,
                    VersionNumber            = VersionNumber,
                };

                OrganizationService.Execute(cloneAsPatch);
            }

            base.WriteVerbose("Completed CloneAsPatchRequest");
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            base.WriteVerbose("Executing CloneAsPatchRequest");

            using (var context = new CIContext(OrganizationService))
            {
                base.WriteVerbose("VersionNumber not supplied. Generating default VersionNumber");

                if (string.IsNullOrEmpty(VersionNumber))
                {
                    var solution = (from sol in context.SolutionSet
                                    where sol.UniqueName == ParentSolutionUniqueName || sol.UniqueName.StartsWith(ParentSolutionUniqueName + "_Patch")
                                    orderby sol.Version descending
                                    select new Solution {
                        Version = sol.Version, FriendlyName = sol.FriendlyName
                    }).FirstOrDefault();
                    if (solution == null || string.IsNullOrEmpty(solution.Version))
                    {
                        throw new Exception(string.Format("Parent solution with unique name {0} not found.", ParentSolutionUniqueName));
                    }

                    string[] versions = solution.Version.Split('.');
                    char     dot      = '.';
                    VersionNumber = string.Concat(versions[0], dot, versions[1], dot, Convert.ToInt32(versions[2]) + 1, dot, 0);
                    base.WriteVerbose(string.Format("New VersionNumber: {0}", VersionNumber));
                }

                if (string.IsNullOrEmpty(DisplayName))
                {
                    var solution = (from sol in context.SolutionSet
                                    where sol.UniqueName == ParentSolutionUniqueName
                                    select new Solution {
                        FriendlyName = sol.FriendlyName
                    }).FirstOrDefault();
                    base.WriteVerbose((solution == null).ToString());
                    base.WriteVerbose(solution.FriendlyName);

                    if (solution == null || string.IsNullOrEmpty(solution.FriendlyName))
                    {
                        throw new Exception(string.Format("Parent solution with unique name {0} not found.", ParentSolutionUniqueName));
                    }

                    DisplayName = solution.FriendlyName;
                }

                var cloneAsPatch = new CloneAsPatchRequest
                {
                    DisplayName = DisplayName,
                    ParentSolutionUniqueName = ParentSolutionUniqueName,
                    VersionNumber            = VersionNumber,
                };

                CloneAsPatchResponse response = OrganizationService.Execute(cloneAsPatch) as CloneAsPatchResponse;

                base.WriteVerbose(string.Format("Patch solution created with Id {0}", response.SolutionId));

                base.WriteVerbose("Retrieving Patch Name");

                var patch = (from sol in context.SolutionSet
                             where sol.Id == response.SolutionId
                             select new Solution {
                    UniqueName = sol.UniqueName
                }).FirstOrDefault();
                if (patch == null || string.IsNullOrEmpty(patch.UniqueName))
                {
                    throw new Exception(string.Format("Solution with Id {0} not found.", response.SolutionId));
                }

                base.WriteVerbose(string.Format("Patch solution name: {0}", patch.UniqueName));

                base.WriteObject(patch.UniqueName);
            }

            base.WriteVerbose("Completed CloneAsPatchRequest");
        }