Exemplo n.º 1
0
        internal Addin(Dictionary <Guid, Addin> guid2Addins, RuntimeSystem runtimeSystem,
                       AddinIndexRecord addinIndex)
        {
            var addinFileSystem = new AddinFileSystem(guid2Addins, addinIndex);

            _adnContext = new AddinContext(runtimeSystem, addinFileSystem);
        }
 /// <summary>
 /// Unloads this instance and all of it _children.
 /// </summary>
 public override void Unload(IAddinContext context)
 {
     //if (!Loaded || Children == null)
     //    return;
     ////foreach (var child in Children)
     ////    child.Unload(context);
     //Loaded = false;
 }
Exemplo n.º 3
0
 protected override MvcMenuItem BuildMenuItem(IAddinContext adnContext)
 {
     return(new MvcMenuItem
     {
         Url = this.Url,
         Text = this.Text,
         Visible = this.Visible
     });
 }
Exemplo n.º 4
0
        //public string Text { get; set; }
        //public string Action { get; set; }
        //public string Controller { get; set; }
        ////public string TagName { get; set; }
        ////public string Class { get; set; }
        ////public string Id { get; set; }
        //public bool Visible { get; set; }

        public TExtension BuildExtension(IAddinContext adnContext)
        {
            if (_menuItem != null)
            {
                return(_menuItem);
            }
            _menuItem = BuildMenuItem(adnContext);
            return(_menuItem);
        }
 /// <summary>
 /// Loads this instance and all of it _children.
 /// </summary>
 public override void Load(IAddinContext context)
 {
     //if (Loaded || Children == null)
     //    return;
     ////foreach (var child in Children)
     ////{
     ////    //child.SetParent(this);
     ////    child.Load(context);
     ////}
     //Loaded = true;
 }
Exemplo n.º 6
0
 public ToolStripItem BuildExtension(IAddinContext adnContext)
 {
     if (_menu != null)
     {
         return(_menu);
     }
     _menu = new ToolStripDropDownButton {
         Text = Name
     };
     return(_menu);
 }
        internal void UnloadExtensionPoint(IAddinContext adnContext, ExtensionPointRecord epRecord)
        {
            _loadedExtensionPointRecords.Remove(epRecord);
            Loader epLoader;

            if (!TryGetAndRemoveLoader(epRecord.Path, true, out epLoader))
            {
                return;
            }
            //if (epLoader.Loaded)
            epLoader.Unload(adnContext);
        }
        internal void LoadExtensions(IAddinContext adnContext, ExtensionPointRecord epRecord, ExtensionRecordGroup exRecordGroup)
        {
            if (exRecordGroup.Children == null)
            {
                return;
            }
            var parentLoader = GetParentLoader(epRecord, exRecordGroup);

            foreach (var child in exRecordGroup.Children)
            {
                LoadExtensionsRecursively(adnContext, parentLoader, child);
            }
        }
Exemplo n.º 9
0
        public ToolStripItem BuildExtension(IAddinContext adnContext)
        {
            _adnContext = adnContext;

            var item = new ToolStripButton();

            item.Text = Name;

            if (CommandType != null)
            {
                item.Click += OnMenuClick; // lazy loading type into the runtime
            }
            return(item);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Notifies that the condition has changed, and that it has to be re-evaluated.
 /// </summary>
 /// <remarks>
 /// This method is to be associated with some external event. It is important to avoid re-load or re-unload an fileExtension.
 /// </remarks>
 internal void NotifyChanged(IAddinContext adnContext)
 {
     if (_loader != null)
     {
         if (Evaluate())
         {
             _loader.Load(adnContext);
         }
         else
         {
             _loader.Unload(adnContext);
         }
     }
 }
        public ToolStripItem BuildExtension(IAddinContext adnContext)
        {
            _adnContext = adnContext;

            var menu = new ToolStripMenuItem();

            menu.Text        = Name;
            menu.ToolTipText = Tooltip;

            if (CommandType != null)
            {
                menu.Click += OnMenuClick; // lazy loading type into the runtime
            }
            return(menu);
        }
        void LoadExtensionsRecursively(IAddinContext adnContext, ICompositeExtensionLoader parentLoader, ExtensionRecord exRecord)
        {
            var exLoader = _loaderFactory.CreateExtensionLoader(exRecord);

            parentLoader.AddChild(exLoader);
            _path2Loaders.Add(exLoader.Path, exLoader);
            exLoader.Load(adnContext); // do load the extension object here.

            if (exRecord.Children != null)
            {
                foreach (var child in exRecord.Children)
                {
                    LoadExtensionsRecursively(adnContext, exLoader as ICompositeExtensionLoader, child);
                }
            }
        }
        internal void LoadExtensionPoint(IAddinContext adnContext, ExtensionPointRecord epRecord, object root)
        {
            ExtensionPointLoader epLoader;

            if (!TryGetLoader(epRecord.Path, false, out epLoader))
            {
                epLoader = _loaderFactory.CreateExtensionPointLoader(epRecord);
                _path2Loaders.Add(epRecord.Path, epLoader);
                _loadedExtensionPointRecords.Add(epRecord);
            }
            //if (!epLoader.Loaded)
            //{
            epLoader.TrySetRoot(root);
            epLoader.Load(adnContext);
            //}
        }
Exemplo n.º 14
0
        void DoUnloadFromExtensionPoint(IAddinContext declaringAddin, ExtensionPointRecord extensionPointRecord)
        {
            // register extensions of other addins (extending addins) that extending the extension point.
            var extendingAddinRecords = _addinRelationManager.TryGetSortedExtendingAddins(extensionPointRecord);

            if (extendingAddinRecords != null)
            {
                for (int i = extendingAddinRecords.Count - 1; i >= 0; i--)
                {
                    var extendingAddin = GetOrCreateAddin(extendingAddinRecords[i]);
                    UnloadFromExtensionPoint(extendingAddin.Context, extensionPointRecord);
                }
            }
            // register extensions of the same addin that extends the extension point
            UnloadFromExtensionPoint(declaringAddin, extensionPointRecord);
        }
Exemplo n.º 15
0
        internal void LoadExtensionPoint(IAddinContext declaringAddin, ExtensionPointRecord extensionPointRecord, object extensionRoot)
        {
            VerifyInitialized();

            if (extensionPointRecord.Loaded)
            {
                return;
            }

            // register the extension point itself
            _runtimeExtensionLoader.RegisterExtensionPoint(extensionPointRecord, extensionRoot.GetType());
            _runtimeExtensionLoader.LoadExtensionPoint(declaringAddin, extensionPointRecord, extensionRoot);
            extensionPointRecord.Loaded = true;

            DoLoadIntoExtensionPoint(declaringAddin, extensionPointRecord);
        }
Exemplo n.º 16
0
        void DoLoadIntoExtensionPoint(IAddinContext declaringAddin, ExtensionPointRecord extensionPointRecord)
        {
            // register extensions of the same addin that extends the extension point
            LoadIntoExtensionPoint(declaringAddin, extensionPointRecord);

            // register extensions of other addins (extending addins) that extending the extension point.
            var extendingAddinRecords = _addinRelationManager.TryGetSortedExtendingAddins(extensionPointRecord);

            if (extendingAddinRecords != null)
            {
                for (int i = 0; i < extendingAddinRecords.Count; i++)
                {
                    var extendingAddin = GetOrCreateAddin(extendingAddinRecords[i]);
                    extendingAddin.Extension.LoadInto(extensionPointRecord);
                }
            }
        }
Exemplo n.º 17
0
        internal void UnloadExtensionPoint(IAddinContext declaringAddin, ExtensionPointRecord extensionPointRecord)
        {
            VerifyInitialized();

            //if (!ExtensionPointIsLoaded(extensionPointRecord))
            //    throw new InvalidOperationException(string.Format("The specified extension point [{0}] is not loaded, which do not need to be unloaded!", extensionPointRecord.Id));

            if (!extensionPointRecord.Loaded)
            {
                return;
            }

            DoUnloadFromExtensionPoint(declaringAddin, extensionPointRecord);

            _runtimeExtensionLoader.UnloadExtensionPoint(declaringAddin, extensionPointRecord);
            _runtimeExtensionLoader.UnregisterExtensionPoint(extensionPointRecord);
            extensionPointRecord.Loaded = false;
        }
Exemplo n.º 18
0
        // register extensions that extends an extenstion point declared in another addin.
        void UnloadFromExtensionPoint(IAddinContext adnContext, ExtensionPointRecord extensionPointRecord)
        {
            var addinRecord = adnContext.Addin.AddinRecord;
            var exGroup     = addinRecord.GetExtensionGroup(extensionPointRecord.Path);

            if (exGroup != null && exGroup.Loaded)
            {
                _runtimeExtensionLoader.UnloadExtensions(adnContext, exGroup);
                exGroup.Loaded = false;
            }

            var ebGroup = addinRecord.GetExtensionBuilderGroup(extensionPointRecord.Path);

            if (ebGroup != null && ebGroup.Loaded)
            {
                _runtimeExtensionLoader.UnregisterExtensionBuilders(ebGroup);
                ebGroup.Loaded = false;
            }
        }
Exemplo n.º 19
0
        internal bool TryLoadExtensionPoint(IAddinContext declaringAddin, ExtensionPointRecord extensionPointRecord, object extensionRoot)
        {
            VerifyInitialized();

            if (extensionPointRecord.Loaded)
            {
                return(true);
            }

            _runtimeExtensionLoader.RegisterExtensionPoint(extensionPointRecord, extensionRoot.GetType());
            if (!_runtimeExtensionLoader.TryLoadExtensionPoint(declaringAddin, extensionPointRecord, extensionRoot))
            {
                return(false);
            }
            extensionPointRecord.Loaded = true;

            DoLoadIntoExtensionPoint(declaringAddin, extensionPointRecord);
            return(true);
        }
Exemplo n.º 20
0
        // register extensions of the specified addin (addinRecord) that extends the specified extenstion point.
        internal void LoadIntoExtensionPoint(IAddinContext adnContext, ExtensionPointRecord extensionPointRecord)
        {
            var addinRecord = adnContext.Addin.AddinRecord;

            var ebGroup = addinRecord.GetExtensionBuilderGroup(extensionPointRecord.Path);

            if (ebGroup != null && !ebGroup.Loaded)
            {
                _runtimeExtensionLoader.RegisterExtensionBuilders(ebGroup);
                ebGroup.Loaded = true;
            }

            var exGroup = addinRecord.GetExtensionGroup(extensionPointRecord.Path);

            if (exGroup != null && !exGroup.Loaded)
            {
                _runtimeExtensionLoader.LoadExtensions(adnContext, extensionPointRecord, exGroup);
                exGroup.Loaded = true;
            }
        }
        internal void UnloadExtensions(IAddinContext adnContext, ExtensionRecordGroup exRecordGroup)
        {
            if (exRecordGroup.Children == null)
            {
                return;
            }

            var extensionRecords = new List <ExtensionRecord>(exRecordGroup.Children);

            GetAllExtensionRecords(extensionRecords);

            // 从最末端开始卸载扩展
            for (int i = extensionRecords.Count - 1; i >= 0; i--)
            {
                var    extensionRecord = extensionRecords[i];
                Loader loader;
                TryGetAndRemoveLoader(extensionRecord.Head.Path, true, out loader);
                loader.Unload(adnContext);
            }
        }
        internal bool TryLoadExtensionPoint(IAddinContext adnContext, ExtensionPointRecord epRecord, object root)
        {
            ExtensionPointLoader epLoader;

            if (!TryGetLoader(epRecord.Path, false, out epLoader))
            {
                if (!_loaderFactory.TryCreateExtensionPointLoader(epRecord, out epLoader))
                {
                    return(false);
                }
                _path2Loaders.Add(epRecord.Path, epLoader);
                _loadedExtensionPointRecords.Add(epRecord);
            }
            //if (!epLoader.Loaded)
            //{
            if (!epLoader.TrySetRoot(root))
            {
                return(false);
            }
            epLoader.Load(adnContext);
            //}
            return(true);
        }
Exemplo n.º 23
0
 public ToolStripItem BuildExtension(IAddinContext adnContext)
 {
     return(new ToolStripLabel {
         Text = Name
     });
 }
Exemplo n.º 24
0
 public void Stop(IAddinContext context)
 {
     Console.WriteLine("I am stopped");
 }
Exemplo n.º 25
0
 /// <summary>
 /// Unloads this instance and all of it children.
 /// </summary>
 public abstract void Unload(IAddinContext context);
Exemplo n.º 26
0
 public void Start(IAddinContext context)
 {
     Console.WriteLine("I am started");
 }
Exemplo n.º 27
0
 public ToolStripItem BuildExtension(IAddinContext adnContext)
 {
     return(new ToolStripSeparator());
 }
Exemplo n.º 28
0
 protected abstract TExtension BuildMenuItem(IAddinContext adnContext);