Пример #1
0
        private async Task <bool> GetPlugins(string connString)
        {
            _dte.StatusBar.Text = "Connecting to CRM...";
            _dte.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationSync);
            LockMessage.Content    = "Working...";
            LockOverlay.Visibility = Visibility.Visible;

            CrmServiceClient client = SharedConnection.GetCurrentConnection(ConnPane.SelectedConnection.ConnectionString, WindowType, _dte);

            _dte.StatusBar.Text = "Getting assemblies...";

            EntityCollection results = await Task.Run(() => RetrieveAssembliesFromCrm(client));

            if (results == null)
            {
                SharedConnection.ClearCurrentConnection(WindowType, _dte);
                _dte.StatusBar.Clear();
                _dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationSync);
                LockOverlay.Visibility = Visibility.Hidden;
                MessageBox.Show("Error Retrieving Assemblies. See the Output Window for additional details.");
                return(false);
            }

            _logger.WriteToOutputWindow("Retrieved Assemblies From CRM", Logger.MessageType.Info);

            ObservableCollection <AssemblyItem> assemblies = new ObservableCollection <AssemblyItem>();

            AssemblyItem emptyItem = new AssemblyItem
            {
                AssemblyId = Guid.Empty,
                Name       = String.Empty
            };

            assemblies.Add(emptyItem);

            foreach (var entity in results.Entities)
            {
                AssemblyItem aItem = new AssemblyItem
                {
                    AssemblyId         = entity.Id,
                    Name               = entity.GetAttributeValue <string>("name"),
                    Version            = Version.Parse(entity.GetAttributeValue <string>("version")),
                    DisplayName        = entity.GetAttributeValue <string>("name") + " (" + entity.GetAttributeValue <string>("version") + ")",
                    IsWorkflowActivity = false
                };

                //Only need to process the 1st assembly/type combination returned
                if (assemblies.Count(a => a.AssemblyId == aItem.AssemblyId) > 0)
                {
                    continue;
                }

                if (entity.Contains("plugintype.isworkflowactivity"))
                {
                    aItem.IsWorkflowActivity = (bool)entity.GetAttributeValue <AliasedValue>("plugintype.isworkflowactivity").Value;
                }

                aItem.DisplayName += (aItem.IsWorkflowActivity) ? " [Workflow]" : " [Plug-in]";

                assemblies.Add(aItem);
            }

            assemblies             = HandleMappings(assemblies);
            Assemblies.ItemsSource = assemblies;
            if (assemblies.Count(a => !string.IsNullOrEmpty(a.BoundProject)) > 0)
            {
                Assemblies.SelectedItem = assemblies.First(a => !string.IsNullOrEmpty(a.BoundProject));
            }
            Assemblies.IsEnabled = true;

            _dte.StatusBar.Clear();
            _dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationSync);
            LockOverlay.Visibility = Visibility.Hidden;

            return(true);
        }