Ejemplo n.º 1
0
 private void AssignSolution()
 {
     SetDialog("Assigning...");
     ThreadManager.Instance.ScheduleTask(() =>
     {
         var isError      = false;
         var errorMessage = string.Empty;
         try
         {
             CurrentSolutionManager
             .AssignWorkSolutionToAggregatedSolution
                 (AggregatedSolution.Id, SelectedWorkSolution.Id);
         }
         catch (Exception ex)
         {
             isError      = true;
             errorMessage = ex.Message;
         }
         System.Windows.Application.Current.Dispatcher.Invoke(() =>
         {
             if (isError)
             {
                 MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
             }
             else
             {
                 _window.Close();
             }
             UnsetDialog();
         });
     }, string.Empty, _assignTaskId);
 }
Ejemplo n.º 2
0
 private void SearchComponent()
 {
     SetDialog("Searching...");
     ThreadManager.Instance.ScheduleTask(() =>
     {
         var isError      = false;
         var errorMessage = string.Empty;
         var components   = new List <SolutionComponentBase>();
         try
         {
             components = CurrentSolutionManager.SearchComponent(SelectedType.Type, Value);
         }
         catch (Exception ex)
         {
             isError      = true;
             errorMessage = ex.Message;
         }
         System.Windows.Application.Current.Dispatcher.Invoke(() =>
         {
             if (isError)
             {
                 MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
             }
             else
             {
                 SearchedComponents = components;
                 _window.Close();
             }
             UnsetDialog();
         });
     }, string.Empty, _searchTaskId);
 }
Ejemplo n.º 3
0
        private void ReloadSolutionComponentFromAggregatedSolution(AggregatedSolution aggregatedSolution)
        {
            SetDialog("Retrieving components...");
            ThreadManager.Instance.ScheduleTask(() =>
            {
                var isError      = false;
                var errorMessage = string.Empty;

                List <MergedInSolutionComponent> mergedSolutionComponents = new List <MergedInSolutionComponent>();
                var workSolutions = new List <WorkSolution>();
                try
                {
                    workSolutions            = CurrentSolutionManager.GetWorkSolutions(aggregatedSolution);
                    mergedSolutionComponents = CurrentSolutionManager.GetMergedSolutionComponents(workSolutions, true);
                }
                catch (Exception ex)
                {
                    isError      = true;
                    errorMessage = ex.Message;
                }
                System.Windows.Application.Current.Dispatcher.Invoke(() =>
                {
                    if (isError)
                    {
                        MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        WorkSolutions      = workSolutions;
                        SolutionComponents = mergedSolutionComponents;
                    }
                    UnsetDialog();
                });
            }, "Retrieving components...", _reloadComponentsTaskId);
        }
Ejemplo n.º 4
0
        private Dictionary <string, string> CloneAffectedSolutions(List <Solution> affectedSuperSolutions)
        {
            var mappingsWithBackpus = new Dictionary <string, string>();

            try
            {
                foreach (var item in affectedSuperSolutions)
                {
                    mappingsWithBackpus.Add(item.UniqueName, string.Format("{0}_backup", item.UniqueName));
                    CurrentSolutionManager
                    .CloneSolution(
                        item.Id,
                        mappingsWithBackpus[item.UniqueName],
                        mappingsWithBackpus[item.UniqueName],
                        item.Version,
                        item.Description);
                }
            }
            catch (Exception)
            {
                UpdateDialogMessage($"Rolling back cloning solutions...");
                foreach (var keyValue in mappingsWithBackpus)
                {
                    var originalSolution = keyValue.Key;
                    var clonedVersion    = keyValue.Value;
                    CurrentSolutionManager.RemoveSolution(clonedVersion);
                }
                throw;
            }

            return(mappingsWithBackpus);
        }
Ejemplo n.º 5
0
        private void SetSuperSolutions(IOrganizationService service, List <Setting> settings)
        {
            //TODO: set array of valid types = [1, 2, 3, 4, 5, 20, 21, etc...]
            List <string>   solutionUniqueNames = new List <string>();
            List <Solution> solutions           = new List <Solution>();

            this.ComponentTypesSolutionMapping = new Dictionary <string, string>();

            for (int i = 1; i < 999; i++)
            {
                if (i != WebResourceType)
                {
                    var settingForThisComponent = settings.FirstOrDefault(k => k.Key == string.Format(FormatSuperSolutionSettingKeyName, i));
                    if (settingForThisComponent != null)
                    {
                        var value = settingForThisComponent.Value;
                        if (!this.ComponentTypesSolutionMapping.ContainsKey(i.ToString()))
                        {
                            this.ComponentTypesSolutionMapping.Add(i.ToString(), value);
                        }

                        if (solutionUniqueNames.IndexOf(value) < 0)
                        {
                            solutionUniqueNames.Add(settingForThisComponent.Value);
                        }
                    }
                }
                else
                {
                    for (int j = 1; j < 12; j++) //Different types of webresources
                    {
                        var settingForThisComponent = settings.FirstOrDefault(k => k.Key == string.Format(FormatWebResourceSuperSolutionSettingKeyName, i, j));
                        if (settingForThisComponent != null)
                        {
                            var value = settingForThisComponent.Value;
                            if (!this.ComponentTypesSolutionMapping.ContainsKey($"{i}_{j}"))
                            {
                                this.ComponentTypesSolutionMapping.Add($"{i}_{j}", value);
                            }

                            if (solutionUniqueNames.IndexOf(value) < 0)
                            {
                                solutionUniqueNames.Add(settingForThisComponent.Value);
                            }
                        }
                    }
                }
            }

            foreach (var solutionUniqueName in solutionUniqueNames)
            {
                solutions.Add(CurrentSolutionManager.GetSolution(solutionUniqueName));
            }

            this.SuperSolutions = solutions;
            if (this.SuperSolutions.Count > 0)
            {
                SelectedSuperSolution = this.SuperSolutions[0];
            }
        }
Ejemplo n.º 6
0
        private void CleanAndMergeSourceSolutions(List <Solution> affectedSuperSolutions, Dictionary <string, string> mappings)
        {
            foreach (var item in affectedSuperSolutions)
            {
                UpdateDialogMessage($"Cleaning source solution {item.UniqueName}...");
                CurrentSolutionManager.CleanSolution(item.Id);
                UpdateDialogMessage($"Merging new result in source solution {item.UniqueName}...");

                var sourceKey = item.UniqueName;
                var backupKey = mappings[sourceKey];

                var backupSolution             = CurrentSolutionManager.GetSolution(backupKey);
                var componentsInBackupSolution = CurrentSolutionManager.GetSolutionComponents(backupSolution.Id, false);
                UpdateDialogMessage($"Calculating new components for {item.UniqueName}...");
                var componentsForThisSolution = GetSolutionComponentsForSolution(item).Cast <SolutionComponentBase>().ToList();
                var allComponents             = new List <SolutionComponentBase>();
                allComponents.AddRange(componentsInBackupSolution);
                allComponents.AddRange(componentsForThisSolution);

                var newSuperSolutionComponents =
                    CurrentSolutionManager
                    .GetMergedSolutionComponents(allComponents);
                UpdateDialogMessage($"Adding components to supersolution {item.UniqueName}...");
                CurrentSolutionManager.CreateMergedSolution(item.Id, newSuperSolutionComponents);
                UpdateDialogMessage($"Increasing revision version of {item.UniqueName}...");
                CurrentSolutionManager.IncreaseSolutionRevisionVersion(item.Id);
                item.Version = CurrentSolutionManager.GetSolutionVersion(item.Id);
            }
        }
Ejemplo n.º 7
0
 private void CreateSolution()
 {
     SetDialog("Creating...");
     ThreadManager.Instance.ScheduleTask(() =>
     {
         var isError      = false;
         var errorMessage = string.Empty;
         try
         {
             CurrentSolutionManager.CreateAggregatedSolution(this.Name, this.CurrentType.Type);
         }
         catch (Exception ex)
         {
             isError      = true;
             errorMessage = ex.Message;
         }
         System.Windows.Application.Current.Dispatcher.Invoke(() =>
         {
             if (isError)
             {
                 MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
             }
             else
             {
                 _window.Close();
             }
             UnsetDialog();
         });
     }, string.Empty, _createTaskId);
 }
Ejemplo n.º 8
0
        private void RemovedClonedBackupSolutions(List <Solution> affectedSuperSolutions, Dictionary <string, string> mappings)
        {
            UpdateDialogMessage($"Removing backup solutions...");
            foreach (var item in affectedSuperSolutions)
            {
                var sourceKey = item.UniqueName;
                var backupKey = mappings[sourceKey];

                CurrentSolutionManager.RemoveSolution(backupKey);
            }
        }
Ejemplo n.º 9
0
        private void ExportSolutionToPath(string path, Solution solution, bool managed)
        {
            var fileName = StringFormatter.GetSolutionFileName(solution.UniqueName, solution.Version, managed);
            var fullPath = string.Format("{0}{1}", path, fileName);

            SetDialog($"Exporting solution '{solution.UniqueName}' managed={managed}...");
            CurrentSolutionManager.ExportSolution(solution.UniqueName, fullPath, managed);
            if (BlobService.IsEnabledBlobStorage())
            {
                SetDialog($"Uploading to BlobStorage '{solution.UniqueName}' managed={managed}...");
                BlobService.Upload(solution.UniqueName, fullPath);
            }
        }
Ejemplo n.º 10
0
        private Solution CreateSolution()
        {
            Solution targetSolution;
            var      description = new StringBuilder();

            description
            .AppendLine(
                string.Format("## Solution created by {0} at {1} ##",
                              CurrentCrmConnection.Username,
                              DateTime.Now.ToString()));
            var solution = CurrentSolutionManager.CreateSolution(NewDisplayName, UniqueName, SelectedPublisher, description.ToString());

            targetSolution = solution;
            return(targetSolution);
        }
Ejemplo n.º 11
0
 private void ImportSolution()
 {
     SetDialog($"Importing {Path} async...");
     ThreadManager.Instance.ScheduleTask(() =>
     {
         var isError          = false;
         var errorMessage     = string.Empty;
         var clonedSolutionId = Guid.Empty;
         try
         {
             if (ImportAsync)
             {
                 CurrentSolutionManager
                 .ImportSolutionAsnyc(Path, OverwriteUnmanagedCustomizations, MigrateAsHold, PublishWorkflows);
             }
             else
             {
                 CurrentSolutionManager
                 .ImportSolution(Path, OverwriteUnmanagedCustomizations, MigrateAsHold, PublishWorkflows);
             }
         }
         catch (Exception ex)
         {
             isError      = true;
             errorMessage = ex.Message;
         }
         System.Windows.Application.Current.Dispatcher.Invoke(() =>
         {
             if (isError)
             {
                 MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                 var dependencies = GetRequiredDependencies(errorMessage);
                 if (dependencies != null && !string.IsNullOrEmpty(dependencies.Trim()))
                 {
                     System.Windows.Clipboard.SetText(dependencies);
                     var newMessage = $"(Copied to clipboard)\r\n{dependencies}";
                     MessageBox.Show(newMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                 }
             }
             else
             {
                 _window.Close();
             }
             UnsetDialog();
         });
     }, string.Empty, _importTaskId);
 }
Ejemplo n.º 12
0
        private void CheckDependencies()
        {
            SetDialog("Checking dependencies...");
            ThreadManager.Instance.ScheduleTask(() =>
            {
                var isError      = false;
                var errorMessage = string.Empty;
                //var clonedSolutionId = Guid.Empty;
                try
                {
                    SetDialog("Connecting to destination environment...");
                    var stringConnection       = DestinationCrmConnection.GetStringConnetion(); var solution = CurrentSolutionManager.GetSolution(WorkSolution.SolutionId);
                    DestinationService         = CrmDataProvider.GetService(stringConnection);
                    DestinationSolutionManager = new SolutionManager(DestinationService); var path = Path.GetTempPath();

                    SetDialog("Downloading solution...");

                    var filePath = $@"{path}{solution.UniqueName}.zip";
                    CurrentSolutionManager.ExportSolution(solution.UniqueName, filePath, true);
                    SetDialog("Importing solution in destionation environment...");
                    DestinationSolutionManager.ImportSolution(filePath, false, false, false);
                    SetDialog("Removing solution from destination environment...");
                    DestinationSolutionManager.RemoveSolution(solution.UniqueName);
                    CurrentSolutionManager.SetDependenciesOKForWorkSolution(WorkSolution.Id);
                }
                catch (Exception ex)
                {
                    isError      = true;
                    errorMessage = ex.Message;
                }
                System.Windows.Application.Current.Dispatcher.Invoke(() =>
                {
                    if (isError)
                    {
                        CurrentSolutionManager.SetDependenciesKOForWorkSolution(WorkSolution.Id, errorMessage);
                        MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        //this.ClonedSolutionId = clonedSolutionId;
                        _window.Close();
                    }
                    UnsetDialog();
                });
            }, "Cloning solution...", _checkDependenciesTaskId);
        }
Ejemplo n.º 13
0
        private void MergeWithSuperSolutions()
        {
            string defaultPath = GetDefaultZipPath();
            var    path        = FileDialogManager.SelectPath(defaultPath);

            path = StringFormatter.GetPathWithLastSlash(path);

            SetDialog("Merging...");

            ThreadManager.Instance.ScheduleTask(() =>
            {
                var isError             = false;
                var errorMessage        = string.Empty;
                var mappingsWithBackpus = new Dictionary <string, string>();
                try
                {
                    UpdateDialogMessage($"Publishing all customizations...");
                    CurrentSolutionManager.PublishAll();
                    List <Solution> affectedSuperSolutions = GetAffectedSuperSolutions();
                    UpdateDialogMessage($"Cloning affected solutions... ({affectedSuperSolutions.Count})");
                    mappingsWithBackpus = CloneAffectedSolutions(affectedSuperSolutions);
                    CleanAndMergeSourceSolutions(affectedSuperSolutions, mappingsWithBackpus);
                    RemovedClonedBackupSolutions(affectedSuperSolutions, mappingsWithBackpus);
                    UpdateDialogMessage($"Exporting affected solutions...");
                    ExportAffectedSuperSolutions(affectedSuperSolutions, path);
                }
                catch (Exception ex)
                {
                    isError      = true;
                    errorMessage = ex.Message;
                }
                System.Windows.Application.Current.Dispatcher.Invoke(() =>
                {
                    if (isError)
                    {
                        MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        _window.Close();
                    }
                    UnsetDialog();
                });
            }, string.Empty, _mergeTaskId);
        }
Ejemplo n.º 14
0
 private void CreateSolution()
 {
     SetDialog("Creating...");
     ThreadManager.Instance.ScheduleTask(() =>
     {
         var isError      = false;
         var errorMessage = string.Empty;
         try
         {
             if (IsCreateingMode)
             {
                 var workSolutionId = CurrentSolutionManager.CreateWorkSolution(this.Name, this.Jira);
                 CurrentSolutionManager.AssignWorkSolutionToAggregatedSolution(AggregatedSolution.Id, workSolutionId);
             }
             else
             {
                 if (CurrentWorkSolution != null)
                 {
                     CurrentSolutionManager.AssignWorkSolutionToAggregatedSolution(AggregatedSolution.Id, CurrentWorkSolution.Id);
                 }
             }
         }
         catch (Exception ex)
         {
             isError      = true;
             errorMessage = ex.Message;
         }
         System.Windows.Application.Current.Dispatcher.Invoke(() =>
         {
             if (isError)
             {
                 MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
             }
             else
             {
                 _window.Close();
             }
             UnsetDialog();
         });
     }, string.Empty, _createTaskId);
 }
Ejemplo n.º 15
0
        private void MergeSolutionResult(Solution targetSolution)
        {
            SetDialog("Merging...");
            ThreadManager.Instance.ScheduleTask(() =>
            {
                var isError      = false;
                var errorMessage = string.Empty;

                try
                {
                    var currentComponents = CurrentSolutionManager.GetSolutionComponents(targetSolution.Id, false);
                    if (currentComponents.Count > 0)
                    {
                        throw new Exception("Target solution already has components");
                    }
                    CurrentSolutionManager.CreateMergedSolution(targetSolution, SolutionComponents);
                }
                catch (Exception ex)
                {
                    isError      = true;
                    errorMessage = ex.Message;
                }
                System.Windows.Application.Current.Dispatcher.Invoke(() =>
                {
                    if (isError)
                    {
                        MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        MergedSolution = targetSolution;
                        _window.Close();
                    }
                    UnsetDialog();
                });
            }, "Merging solution components...", _mergeTaskId);
        }
Ejemplo n.º 16
0
        private Solution CreateSolution()
        {
            Solution targetSolution;
            var      description = new StringBuilder();

            description
            .AppendLine(
                string.Format("## Solution generated automatically by {0} at {1} ##",
                              CurrentCrmConnection.Username,
                              DateTime.Now.ToString()));
            if (WorkSolutions != null)
            {
                foreach (var item in WorkSolutions)
                {
                    description.AppendLine($"-{item.Jira}");
                }
            }
            var solution = CurrentSolutionManager.CreateSolution(NewDisplayName, UniqueName, SelectedPublisher, description.ToString());

            CurrentSolutionManager.UpdatedJustCreatedAggregatedSolution(CurrentAggregatedSolution.Id, UniqueName, NewDisplayName);

            targetSolution = solution;
            return(targetSolution);
        }