예제 #1
0
        public void LoadWebResourcesGeneral(Entity specificSolution)
        {
            wrManager = new WebResourceManager(Service);
            tvWebResources.Nodes.Clear();

            var dialog = new WebResourceTypeSelectorDialog();
            if (dialog.ShowDialog(ParentForm) == DialogResult.OK)
            {
                var settings = new LoadCrmResourcesSettings
                {
                    SolutionId = specificSolution != null ? specificSolution.Id : Guid.Empty,
                    SolutionName = specificSolution != null ?specificSolution.GetAttributeValue<string>("friendlyname") : "",
                    SolutionVersion = specificSolution != null ?specificSolution.GetAttributeValue<string>("version") : "",
                    Types = dialog.TypesToLoad
                };

                SetWorkingState(true);
                tvWebResources.Nodes.Clear();

                WorkAsync("Loading web resources...",
                    e =>
                    {
                        Guid solutionId = e.Argument != null ? ((LoadCrmResourcesSettings)e.Argument).SolutionId : Guid.Empty;

                        RetrieveWebResources(solutionId, ((LoadCrmResourcesSettings)e.Argument).Types);

                        e.Result = e.Argument;
                    },
                    e =>
                    {
                        if (e.Error != null)
                        {
                            string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true);
                            MessageBox.Show(this, errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            tvWebResources.Enabled = true;

                            var currentSettings = (LoadCrmResourcesSettings)e.Result;
                            tssCurrentlyLoadedSolution.Visible = currentSettings.SolutionId != Guid.Empty;
                            tslCurrentlyLoadedSolution.Visible = currentSettings.SolutionId != Guid.Empty;
                            tslCurrentlyLoadedSolution.Text = string.Format("Solution loaded: {0} - v{1}", currentSettings.SolutionName, currentSettings.SolutionVersion);
                        }

                        tvWebResources.ExpandAll();
                        tvWebResources.TreeViewNodeSorter = new NodeSorter();
                        tvWebResources.Sort();
                        TvWebResourcesAfterSelect(null, null);

                        tsbClear.Visible = true;

                        SetWorkingState(false);
                    },
                    settings);
            }
        }
예제 #2
0
        public void LoadWebResourcesGeneral(bool fromSolution)
        {
            Guid solutionId = Guid.Empty;
            List<int> typesToload;

            // 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)
                {
                    solutionId = sPicker.SelectedSolution.Id;
                }
                else
                {
                    return;
                }
            }

            // Display web resource types selection dialog
            var dialog = new WebResourceTypeSelectorDialog();
            if (dialog.ShowDialog(ParentForm) == DialogResult.OK)
            {
                typesToload = dialog.TypesToLoad;
            }
            else
            {
                return;
            }

            webresourceTreeView1.Enabled = false;
            webresourceTreeView1.Service = Service;

            WorkAsync(new WorkAsyncInfo("Loading web resources...", e =>
            {
                var args = (Tuple<Guid, List<int>>)e.Argument;

                webresourceTreeView1.LoadWebResourcesFromServer(args.Item1, args.Item2);
            })
            {
                AsyncArgument = new Tuple<Guid, List<int>>(solutionId, typesToload),
                PostWorkCallBack = e =>
                {
                    webresourceTreeView1.DisplayWebResources();

                    webresourceTreeView1.Enabled = true;
                }
            });
        }