private void buildListOfCommands()
        {
            AvailableItems = new List <AddToolbarItem>();

            // Add the internal controls assembly
            AssemblyManager.AddAssembly(typeof(ESRI.ArcGIS.Mapping.Controls.CommandBase).Assembly);

            // Add the GP assembly
            AssemblyManager.AddAssembly(typeof(ESRI.ArcGIS.Mapping.GP.GeoprocessingCommand).Assembly);

            IEnumerable <Type> exportedCommands = AssemblyManager.GetExportsForType(typeof(ICommand));

            if (exportedCommands != null)
            {
                foreach (Type type in exportedCommands)
                {
                    ProcessType(type);
                }
            }

            IEnumerable <Type> exportedControls = AssemblyManager.GetExportsForType(typeof(FrameworkElement));

            if (exportedControls != null)
            {
                foreach (Type type in exportedControls)
                {
                    ProcessType(type);
                }
            }

            // Sort items by category and then by name
            AvailableItems = (from item in AvailableItems
                              orderby item.Category, item.Name
                              select item).ToList();
        }
        private void buildListOfAvailableBehaviors()
        {
            AssemblyManager.AddAssembly(typeof(ESRI.ArcGIS.Mapping.Controls.ConstrainExtentBehavior).Assembly);

            MapBehaviors.Clear();
            IEnumerable<Type> exportedBehaviors = AssemblyManager.GetExportsForType(typeof(Behavior<Map>));
            if (exportedBehaviors != null)
            {
                foreach (Type type in exportedBehaviors)
                {
                    Behavior<Map> behavior = Activator.CreateInstance(type) as Behavior<Map>;
                    if (behavior != null)
                        MapBehaviors.Add(behavior);
                }
            }
        }
        private void buildListOfBehaviors()
        {
            addItems = new List <AddBehaviorItem>();

            AssemblyManager.AddAssembly(typeof(ESRI.ArcGIS.Mapping.Controls.ConstrainExtentBehavior).Assembly);

            IEnumerable <Type> exportedBehaviors = AssemblyManager.GetExportsForType(typeof(Behavior <Map>));

            if (exportedBehaviors != null)
            {
                foreach (Type type in exportedBehaviors)
                {
                    ProcessICommandType(type);
                }
            }

            // Sort items by category and then by name
            addItems = (from item in addItems
                        orderby item.Category, item.Name
                        select item).ToList();
        }
        private void validateXap(FileStream fileStream, EventHandler <ValidationCompleteEventArgs> onComplete, object userState)
        {
            List <string> errors   = new List <string>();
            List <string> warnings = new List <string>();
            ObservableCollection <string>     assemblyNames       = null;
            List <System.Reflection.Assembly> extensionAssemblies = new List <System.Reflection.Assembly>();

            if (fileStream != null)
            {
                StreamResourceInfo         xapStreamInfo   = new StreamResourceInfo(fileStream, null);
                IEnumerable <AssemblyPart> deploymentParts = getAssemblyParts(xapStreamInfo, out assemblyNames);
                foreach (AssemblyPart part in deploymentParts)
                {
                    StreamResourceInfo resourceStream = Application.GetResourceStream(xapStreamInfo, new Uri(part.Source, UriKind.Relative));
                    if (resourceStream == null)
                    {
                        continue;
                    }
                    try
                    {
                        System.Reflection.Assembly assembly = part.Load(resourceStream.Stream);
                        string assemblyName = assembly.FullName.Split(',')[0];
                        if (AssemblyManager.IsBuiltInAssembly(assemblyName))
                        {
                            warnings.Add(string.Format(ESRI.ArcGIS.Mapping.Builder.Resources.Strings.AssemblyAlreadyIncludeInTheApplication, assemblyName, System.Environment.NewLine));
                        }
                        extensionAssemblies.Add(assembly);
                    }
                    catch (Exception ex)
                    {
                        ReflectionTypeLoadException refEx = ex as ReflectionTypeLoadException;
                        if (refEx != null && refEx.LoaderExceptions != null)
                        {
                            foreach (Exception e in refEx.LoaderExceptions)
                            {
                                if (!string.IsNullOrWhiteSpace(e.Message) && !errors.Contains(e.Message))
                                {
                                    errors.Add(e.Message);
                                }
                            }
                        }
                        else if (!errors.Contains(ex.Message))
                        {
                            errors.Add(ex.Message);
                        }
                    }
                }
                fileStream.Close();
            }

            if (errors.Count == 0) //only if there have been no errors loading the assemblies attempt to add to the catalog
            {
                try
                {
                    foreach (System.Reflection.Assembly assem in extensionAssemblies)
                    {
                        AssemblyManager.AddAssembly(assem);
                    }
                }
                catch (Exception ex)
                {
                    if (!errors.Contains(ex.Message))
                    {
                        errors.Add(ex.Message);
                    }
                }
            }

            if (errors.Count < 1 && warnings.Count < 1)
            {
                // No errors or warnings
                if (onComplete != null)
                {
                    onComplete(this, new ValidationCompleteEventArgs()
                    {
                        UserState = userState, AssemblyNames = assemblyNames
                    });
                }
            }
            else
            {
                ExtensionUploadWarningDialog warningDialog = new ExtensionUploadWarningDialog(errors, warnings)
                {
                    Tag = new object[] { userState, assemblyNames }
                };
                warningDialog.OkClicked     += new EventHandler(warningDialog_OkClicked);
                warningDialog.CancelClicked += new EventHandler(warningDialog_CancelClicked);
                BuilderApplication.Instance.ShowWindow(ESRI.ArcGIS.Mapping.Builder.Resources.Strings.Errors, warningDialog, true);
            }
        }