Ejemplo n.º 1
0
        private void UpdateErrorInfo()
        {
            AddInDefinition addInDefinition = (AddInDefinition)addinsListView.FocusedItem.Tag;

            if (addInDefinition.HasErrors)
            {
                errorsTextBox.Text = addInDefinition.Error;
            }
            else
            {
                errorsTextBox.Text = String.Format("The add-in '{0}' loaded successfully.", addInDefinition.Instance.Name);
            }
        }
Ejemplo n.º 2
0
 public static ItemDefinition FromAddInDefinition(AddInDefinition addInDefinition)
 {
     return(new ItemDefinition(null, addInDefinition));
 }
Ejemplo n.º 3
0
        private static List <AddInDefinition> LoadAddInDefinitions()
        {
            string addInPath = GetAddInDirectory();

            if (!Directory.Exists(addInPath))
            {
                return(new List <AddInDefinition>());
            }

            string[] addinAssemblyFilenames = Directory.GetFiles(addInPath, "*.addin", SearchOption.AllDirectories);

            List <AddInDefinition> result = new List <AddInDefinition>();

            List <Type> addInTypes = new List <Type>();

            foreach (string addinAssemblyFilename in addinAssemblyFilenames)
            {
                Assembly addInAssembly = Assembly.LoadFrom(addinAssemblyFilename);
                Type[]   exportedTypes = addInAssembly.GetExportedTypes();
                foreach (Type exportedType in exportedTypes)
                {
                    if (!exportedType.IsAbstract && !exportedType.IsInterface)
                    {
                        Type[] interfaces       = exportedType.GetInterfaces();
                        bool   implementsIAddIn = Array.IndexOf(interfaces, typeof(IAddIn)) >= 0;
                        if (implementsIAddIn)
                        {
                            ConstructorInfo defaultConstructor = exportedType.GetConstructor(new Type[0]);
                            if (defaultConstructor != null)
                            {
                                addInTypes.Add(exportedType);
                            }
                            else
                            {
                                string          error           = String.Format("Add-in type '{0}' does not provide a public default constructor.", exportedType.FullName);
                                AddInDefinition addInDefinition = new AddInDefinition(exportedType, null, error);
                                result.Add(addInDefinition);
                            }
                        }
                    }
                }
            }

            foreach (Type addInType in addInTypes)
            {
                AddInDefinition addInDefinition;
                try
                {
                    IAddIn addIn = (IAddIn)Activator.CreateInstance(addInType);
                    addInDefinition = new AddInDefinition(addInType, addIn, null);
                }
                catch (Exception ex)
                {
                    string error = String.Format("Cannot create instance of add-in type '{0}': {1}", addInType.FullName, ex);
                    addInDefinition = new AddInDefinition(addInType, null, error);
                }

                result.Add(addInDefinition);
            }

            return(result);
        }
Ejemplo n.º 4
0
 private ItemDefinition(string dataSetPath, AddInDefinition addInDefinition)
 {
     _dataSetPath     = dataSetPath;
     _addInDefinition = addInDefinition;
 }