コード例 #1
0
ファイル: MainForm.cs プロジェクト: tbienvenu/XrmToolBox
        private bool IsMessageValid(object sender, MessageBusEventArgs message)
        {
            if (message == null || sender == null || !(sender is UserControl) || !(sender is IXrmToolBoxPluginControl))
            {
                // Error. Possible reasons are:
                // * empty sender
                // * empty message
                // * sender is not UserControl
                // * sender is not XrmToolBox Plugin
                return(false);
            }

            var sourceControl = (UserControl)sender;

            if (string.IsNullOrEmpty(message.SourcePlugin))
            {
                message.SourcePlugin = sourceControl.GetType().GetTitle();
            }
            else if (message.SourcePlugin != sourceControl.GetType().GetTitle())
            {
                // For some reason incorrect name was set in Source Plugin field
                return(false);
            }

            // Everything went ok
            return(true);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: linoh/XrmToolBox
        void MainForm_MessageBroker(object sender, MessageBusEventArgs message)
        {
            if (!IsMessageValid(sender, message))
            {
                return;
            }

            // Trying to find the tab where plugin is located
            var tab = tabControl1.TabPages.Cast <TabPage>().FirstOrDefault(x => x.Controls[0].GetType().GetTitle() == message.TargetPlugin);

            if (tab != null && !message.NewInstance)
            {
                // Using existing plugin instance, switching to plugin tab
                tabControl1.SelectTab(tabControl1.TabPages.IndexOf(tab));
            }
            else
            {
                // Searching for suitable plugin
                var targetModel = pManager.PluginsControls.FirstOrDefault(x => ((Type)x.Tag).GetTitle() == message.TargetPlugin);
                // Displaying plugin and keeping number of the tab where it was opened
                var tabIndex = DisplayPluginControl((UserControl)targetModel);
                // Getting the tab where plugin was opened
                tab = tabControl1.TabPages[tabIndex];
                // New intance of the plugin was created, even if user did not explicitly asked about this.
                message.NewInstance = true;
            }

            var targetControl = (UserControl)tab.Controls[0];

            if (targetControl is IMessageBusHost)
            {
                ((IMessageBusHost)targetControl).OnIncomingMessage(message);
            }
        }
コード例 #3
0
        private void MainForm_MessageBroker(object sender, MessageBusEventArgs message)
        {
            if (!IsMessageValid(sender, message))
            {
                return;
            }

            // Trying to find the tab where plugin is located
            var tab = tabControl1.TabPages.Cast <TabPage>().FirstOrDefault(x => x.GetPlugin()?.GetType().GetTitle() == message.TargetPlugin);

            if (tab != null && !message.NewInstance)
            {
                // Using existing plugin instance, switching to plugin tab
                tabControl1.SelectTab(tabControl1.TabPages.IndexOf(tab));
            }
            else
            {
                // Searching for suitable plugin
                var target = pManager.Plugins.FirstOrDefault(p => p.Metadata.Name == message.TargetPlugin);
                if (target == null)
                {
                    MessageBox.Show(this,
                                    $"Plugin '{message.TargetPlugin}' was not found.\n\nYou can install it from the Plugins Store", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // Displaying plugin and keeping number of the tab where it was opened
                var tabIndex = DisplayPluginControl(target);
                // Getting the tab where plugin was opened
                tab = tabControl1.TabPages[tabIndex];
                // New intance of the plugin was created, even if user did not explicitly asked about this.
                message.NewInstance = true;
            }

            var targetControl = (UserControl)tab.GetPlugin();

            if (targetControl is IMessageBusHost)
            {
                ((IMessageBusHost)targetControl).OnIncomingMessage(message);
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: NielsMinnee/XrmToolBox
 private bool IsMessageValid(object sender, MessageBusEventArgs message)
 {
     if (message == null || sender == null || !(sender is UserControl) || !(sender is IMsCrmToolsPluginUserControl))
     {
         // Error. Possible reasons are:
         // * empty sender 
         // * empty message
         // * sender is not UserControl
         // * sender is not XrmToolBox Plugin
         return false;
     }
     
     var sourceControl = (UserControl)sender;
     
     if (string.IsNullOrEmpty(message.SourcePlugin))
     {
         message.SourcePlugin = sourceControl.GetType().GetTitle();
     }
     else if (message.SourcePlugin != sourceControl.GetType().GetTitle())
     {
         // For some reason incorrect name was set in Source Plugin field
         return false;
     }
     
     // Everything went ok
     return true;
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: NielsMinnee/XrmToolBox
        private void MainForm_MessageBroker(object sender, MessageBusEventArgs message)
        {
            if (!IsMessageValid(sender, message))
            {
                return;
            }

            // Trying to find the tab where plugin is located
            var tab = tabControl1.TabPages.Cast<TabPage>().FirstOrDefault(x => x.Controls[0].GetType().GetTitle() == message.TargetPlugin);

            if (tab != null && !message.NewInstance)
            {
                // Using existing plugin instance, switching to plugin tab
                tabControl1.SelectTab(tabControl1.TabPages.IndexOf(tab));
            }
            else
            {
                // Searching for suitable plugin
                var targetModel = pManager.PluginsControls.FirstOrDefault(x => ((Type)x.Tag).GetTitle() == message.TargetPlugin);
                if (targetModel == null)
                {
                    throw new PluginNotFoundException("Plugin {0} was not found", message.TargetPlugin);
                }
                // Displaying plugin and keeping number of the tab where it was opened
                var tabIndex = DisplayPluginControl((UserControl)targetModel);
                // Getting the tab where plugin was opened
                tab = tabControl1.TabPages[tabIndex];
                // New intance of the plugin was created, even if user did not explicitly asked about this.
                message.NewInstance = true;
            }

            var targetControl = (UserControl)tab.Controls[0];

            if (targetControl is IMessageBusHost)
            {
                ((IMessageBusHost)targetControl).OnIncomingMessage(message);
            }
        }