Exemple #1
0
        public void LoadEntities(bool fromSolution = false)
        {
            List <Entity> solutions = new List <Entity>();

            if (fromSolution)
            {
                var dialog = new SolutionPicker(Service);
                if (dialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                solutions.AddRange(dialog.SelectedSolutions);
            }

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Loading Entities...",
                Work    = (bw, e) =>
                {
                    // Search for all entities metadata

                    currentAllMetadata = GetEntities(solutions);
                    // return listview items
                    e.Result = BuildEntityItems(currentAllMetadata.ToList());
                },
                PostWorkCallBack = e =>
                {
                    entityListView.Items.Clear();
                    // Add listview items to listview
                    entityListView.Items.AddRange(((List <ListViewItem>)e.Result).ToArray());
                }
            });
        }
Exemple #2
0
        public void SolutionPicker_picks_unity_solution()
        {
            var solutions = new[] { "unity.sln", "unity-csharp.sln" };
            var solution  = SolutionPicker.ChooseSolution(null, solutions);

            Assert.Equal("unity-csharp.sln", solution.Solution);
        }
Exemple #3
0
        public void LoadSystemViews(List <Entity> users = null, string returnedTypeExpected = null)
        {
            if (!DisplaySystemView && !DisplayRulesTemplate && !DisplaySystemRules && !lvViews.Columns.ContainsKey("User"))
            {
                lvViews.Columns.Add(new ColumnHeader
                {
                    Text  = "User",
                    Name  = "User",
                    Width = 150
                });

                lvViews.Columns.Add(new ColumnHeader
                {
                    Text  = "State",
                    Name  = "State",
                    Width = 75
                });
            }

            if (DisplayRulesTemplate && !lvViews.Columns.ContainsKey("IsDefault"))
            {
                lvViews.Columns.Add(new ColumnHeader
                {
                    Text  = "Is Default",
                    Name  = "IsDefault",
                    Width = 75
                });
            }

            if (DisplaySystemView || DisplayRulesTemplate)
            {
                lvViews.ShowGroups = true;
            }

            List <Entity> solutions = new List <Entity>();

            if (returnedTypeExpected == null)
            {
                var sp = new SolutionPicker(service);
                if (sp.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                solutions = sp.SelectedSolutions;
            }

            lvViews.Items.Clear();

            loadingPanel = InformationPanel.GetInformationPanel(this, "Retrieving items...", 340, 120);

            var bw = new BackgroundWorker {
                WorkerReportsProgress = true
            };

            bw.DoWork             += bw_DoWork;
            bw.ProgressChanged    += bw_ProgressChanged;
            bw.RunWorkerCompleted += bw_RunWorkerCompleted;
            bw.RunWorkerAsync(new object[] { users, returnedTypeExpected, solutions });
        }
Exemple #4
0
        public void SolutionPicker_logs_info_when_ambiguous_solutions_found()
        {
            var solutions = new[] { "unity.sln", "unity-csharp.sln", "another.sln" };
            var solution  = SolutionPicker.ChooseSolution(null, solutions);

            Assert.Null(solution.Solution);
            Assert.Equal("Could not determine solution file", solution.Message);
        }
Exemple #5
0
        public void SolutionPicker_logs_info_when_no_solutions_found()
        {
            var solutions = new string[0];
            var solution  = SolutionPicker.ChooseSolution("/path", solutions);

            Assert.Null(solution.Solution);
            Assert.Equal("No solution files found in '/path'", solution.Message);
        }
Exemple #6
0
        public void Should_pick_unity_csharp_solution_in_folder_mode()
        {
            var fs = new MockFileSystem();

            fs.File.WriteAllText("Unity.sln", "");
            fs.File.WriteAllText("Unity-csharp.sln", "");
            var solution = new SolutionPicker(fs).LoadSolution(@".", new Logger(Verbosity.Verbose));

            fs.FileInfo.FromFileName(solution.FileName).Name.ShouldEqual("Unity-csharp.sln");
        }
        public void LoadWebresourcesGeneral(bool fromSolution)
        {
            lastSettings = new LoadResourcesSettings();

            // If from solution, display the solution picker so that user can
            // select the solution containing the web resources he wants to
            // display
            if (fromSolution)
            {
                var sPicker = new SolutionPicker(Service)
                {
                    StartPosition = FormStartPosition.CenterParent
                };
                if (sPicker.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    lastSettings.Solution            = sPicker.SelectedSolution;
                    lastSettings.LoadAllWebresources = sPicker.LoadAllWebresources;

                    if (lastSettings.LoadAllWebresources)
                    {
                        lastSettings.FilterByLcid = sPicker.FilterByLcid;
                    }
                }
                else
                {
                    return;
                }
            }

            if (!lastSettings.LoadAllWebresources)
            {
                // Display web resource types selection dialog
                var dialog = new WebResourceTypeSelectorDialog(ConnectionDetail?.OrganizationMajorVersion ?? -1);
                if (dialog.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    lastSettings.TypesToload  = dialog.TypesToLoad;
                    lastSettings.FilterByLcid = dialog.FilterByLcid;
                }
                else
                {
                    return;
                }
            }

            LoadWebresources(lastSettings);
        }
Exemple #8
0
        private void LoadEntities(bool allEntities)
        {
            Guid solutionId = Guid.Empty;

            if (!allEntities)
            {
                var sPicker = new SolutionPicker(Service);
                if (sPicker.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                solutionId = sPicker.SelectedSolution.First().Id;
            }

            lvEntities.Items.Clear();

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Loading entities...",
                Work    = (bw, e) =>
                {
                    List <EntityMetadata> entities = MetadataHelper.RetrieveEntities(Service, solutionId);
                    e.Result = entities;
                },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true);
                        MessageBox.Show(this, errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        foreach (EntityMetadata emd in (List <EntityMetadata>)e.Result)
                        {
                            var item = new ListViewItem {
                                Text = emd.DisplayName?.UserLocalizedLabel?.Label ?? "N/A", Tag = emd
                            };
                            item.SubItems.Add(emd.LogicalName);
                            lvEntities.Items.Add(item);
                        }
                    }
                }
            });
        }
        public void LoadEntities(bool fromSolution = false)
        {
            List <Entity> solutions = new List <Entity>();

            if (fromSolution)
            {
                var dialog = new SolutionPicker(Service);
                if (dialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                solutions.AddRange(dialog.SelectedSolutions);
            }

            lvEntities.Items.Clear();
            cbbLcid.Items.Clear();

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Loading Entities...",
                Work    = (bw, e) =>
                {
                    emdCache = new List <EntityMetadata>();

                    // Search for all entities metadata
                    foreach (var emd in MetadataHelper.GetEntities(solutions, Service))
                    {
                        emdCache.Add(emd);
                    }

                    bw.ReportProgress(0, "Retrieving available languages");

                    var lcidRequest  = new RetrieveProvisionedLanguagesRequest();
                    var lcidResponse = (RetrieveProvisionedLanguagesResponse)Service.Execute(lcidRequest);

                    e.Result =
                        lcidResponse.RetrieveProvisionedLanguages.Select(
                            lcid => new LanguageCode {
                        Lcid = lcid, Label = CultureInfo.GetCultureInfo(lcid).EnglishName
                    });
                },
                PostWorkCallBack = e =>
                {
                    foreach (var emd in emdCache)
                    {
                        var displayName = emd.DisplayName != null && emd.DisplayName.UserLocalizedLabel != null
                            ? emd.DisplayName.UserLocalizedLabel.Label
                            : "N/A";
                        var name = emd.LogicalName;

                        lvEntities.Items.Add(new ListViewItem
                        {
                            Text     = displayName,
                            SubItems =
                            {
                                name
                            },
                            Tag = name
                        });
                    }

                    foreach (var lc in (IEnumerable <LanguageCode>)e.Result)
                    {
                        cbbLcid.Items.Add(lc);
                    }

                    if (cbbLcid.Items.Count > 0)
                    {
                        cbbLcid.SelectedIndex = 0;
                    }

                    SetWorkingState(false);
                },
                ProgressChanged = e => { SetWorkingMessage(e.UserState.ToString()); }
            });
        }
        public void UpdateWebResources(UpdateResourcesSettings us)
        {
            if (us.AddToSolution)
            {
                var sPicker = new SolutionPicker(Service, true)
                {
                    StartPosition = FormStartPosition.CenterParent
                };

                if (sPicker.ShowDialog(this) == DialogResult.OK)
                {
                    us.SolutionUniqueName = sPicker.SelectedSolution["uniquename"].ToString();
                }
                else
                {
                    return;
                }
            }

            // TODO Disable controls during update

            tv.Service = Service;

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "Updating web resources...",
                AsyncArgument = us,
                Work          = (bw, e) =>
                {
                    var settings         = (UpdateResourcesSettings)e.Argument;
                    var resourcesUpdated = new List <Webresource>();
                    var resources        = new List <Webresource>();

                    // Add Regular Resources, and Associated Web Resources
                    foreach (var resource in settings.Webresources)
                    {
                        resources.Add(resource);
                        if (resource.AssociatedResources != null)
                        {
                            resources.AddRange(resource.AssociatedResources);
                        }
                    }

                    foreach (var resource in resources)
                    {
                        try
                        {
                            bw.ReportProgress(1, $"Updating {resource}...");
                            resource.Update(Service, us.Overwrite);

                            resourcesUpdated.Add(resource);
                            resource.LastException = null;
                        }
                        catch (Exception error)
                        {
                            resource.LastException = error;
                        }
                    }

                    // Process post Update command
                    if (!string.IsNullOrEmpty(Settings.Instance.AfterUpdateCommand))
                    {
                        foreach (var webResource in resourcesUpdated)
                        {
                            EventManager.ActAfterUpdate(webResource, Settings.Instance);
                        }
                    }

                    // if publish
                    if (settings.Publish && resourcesUpdated.Count > 0)
                    {
                        bw.ReportProgress(2, "Publishing web resources...");

                        Webresource.Publish(resourcesUpdated, Service);
                    }

                    // Process post Publish command
                    if (!string.IsNullOrEmpty(Settings.Instance.AfterPublishCommand))
                    {
                        foreach (var webResource in resourcesUpdated)
                        {
                            EventManager.ActAfterPublish(webResource, Settings.Instance);
                        }
                    }

                    if (settings.AddToSolution && !string.IsNullOrEmpty(settings.SolutionUniqueName) && resourcesUpdated.Count > 0)
                    {
                        bw.ReportProgress(3, "Adding web resources to solution...");
                        Webresource.AddToSolution(resourcesUpdated, settings.SolutionUniqueName, Service);
                    }

                    e.Result = new UpdateResourcesResult
                    {
                        FaultedResources   = resources.Except(resourcesUpdated),
                        Publish            = settings.Publish,
                        AddToSolution      = settings.AddToSolution,
                        SolutionUniqueName = settings.SolutionUniqueName
                    };
                },
                ProgressChanged  = e => { SetWorkingMessage(e.UserState.ToString()); },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        MessageBox.Show(this, e.Error.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    var result = (UpdateResourcesResult)e.Result;

                    // Identifies resources with concurrency behavior error
                    //var unsyncResources = result.FaultedResources.Where(r =>
                    //    r.LastException is FaultException<OrganizationServiceFault>
                    //    && ((FaultException<OrganizationServiceFault>)r.LastException).Detail.ErrorCode ==
                    //    -2147088254).ToList();
                    var unsyncResources =
                        result.FaultedResources.Where(r => r.LastException is MoreRecentRecordExistsException).ToList();
                    var otherResources = result.FaultedResources.Except(unsyncResources).ToList();

                    if (unsyncResources.Any() || otherResources.Any())
                    {
                        var dialog = new ConcurrencySummaryDialog(unsyncResources, otherResources);
                        if (dialog.ShowDialog(this) == DialogResult.Retry)
                        {
                            var retryUs = new UpdateResourcesSettings
                            {
                                Webresources       = unsyncResources,
                                Publish            = result.Publish,
                                AddToSolution      = result.AddToSolution,
                                SolutionUniqueName = result.SolutionUniqueName,
                                Overwrite          = true
                            };

                            UpdateWebResources(retryUs);
                        }
                    }
                }
            });
        }
Exemple #11
0
        public void FindScripts(bool allEntities)
        {
            lvScripts.Items.Clear();
            tsddFindScripts.Enabled = false;
            tsbExportToCsv.Enabled  = false;

            var solutionList = new List <Entity>();

            if (!allEntities)
            {
                var dialog = new SolutionPicker(Service);
                if (dialog.ShowDialog(this) == DialogResult.OK)
                {
                    solutionList = dialog.SelectedSolution;
                }
                else
                {
                    tsddFindScripts.Enabled = true;
                    tsbExportToCsv.Enabled  = true;

                    return;
                }
            }

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "Loading scripts (this can take a while...)",
                AsyncArgument = solutionList,
                Work          = (bw, e) =>
                {
                    _lScripts     = new List <ListViewItem>();
                    var solutions = (List <Entity>)e.Argument;

                    var sManager = new ScriptsManager(Service, bw);
                    sManager.Find(solutions, loadManagedEntities, new Version(ConnectionDetail.OrganizationVersion));
                    _metadata      = sManager.Metadata;
                    _forms         = sManager.Forms;
                    _views         = sManager.Views;
                    _homePageGrids = sManager.HomePageGrids;
                    _userLcid      = sManager.UserLcid;

                    foreach (var script in sManager.Scripts)
                    {
                        var item = new ListViewItem(script.Type)
                        {
                            Tag = script
                        };
                        item.SubItems.Add(script.EntityName);
                        item.SubItems.Add(script.EntityLogicalName);
                        item.SubItems.Add(script.ItemName);
                        item.SubItems.Add(script.FormType);
                        item.SubItems.Add(script.FormState);
                        item.SubItems.Add(script.Event);
                        item.SubItems.Add(script.Attribute);
                        item.SubItems.Add(script.AttributeLogicalName);
                        item.SubItems.Add(script.Library);
                        item.SubItems.Add(script.MethodCalled);
                        item.SubItems.Add(script.PassExecutionContext?.ToString() ?? "");
                        item.SubItems.Add(script.Parameters);
                        item.SubItems.Add(script.Enabled?.ToString() ?? "");
                        item.SubItems.Add(script.Problem);

                        if (script.HasProblem)
                        {
                            item.ForeColor = Color.Red;
                        }
                        _lScripts.Add(item);
                    }

                    e.Result = _lScripts;
                },
                PostWorkCallBack = e =>
                {
                    tsddFindScripts.Enabled = true;
                    tsbExportToCsv.Enabled  = true;

                    if (e.Error != null)
                    {
                        MessageBox.Show(this, e.Error.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    lvScripts.Items.AddRange(((List <ListViewItem>)e.Result).ToArray());
                    tsbApplyChanges.Enabled = lvScripts.Items.Cast <ListViewItem>().Any(i => ((Script)i.Tag).RequiresUpdate);
                },
                ProgressChanged = e =>
                {
                    SetWorkingMessage(e.UserState.ToString());
                }
            });
        }