private int DisplayPluginControl(UserControl plugin) { var tabIndex = 0; try { var controlType = (Type)plugin.Tag; var pluginControl = (UserControl)PluginManager.CreateInstance(controlType.Assembly.Location, controlType.FullName); if (service != null) { var clonedService = (OrganizationService)currentConnectionDetail.GetOrganizationService(); ((OrganizationServiceProxy)clonedService.InnerService).SdkClientVersion = currentConnectionDetail.OrganizationVersion; ((IMsCrmToolsPluginUserControl)pluginControl).UpdateConnection(clonedService, currentConnectionDetail); } if (pluginControl is IMessageBusHost) { ((IMessageBusHost)pluginControl).OnOutgoingMessage += MainForm_MessageBroker; } ((IMsCrmToolsPluginUserControl)pluginControl).OnRequestConnection += MainForm_OnRequestConnection; ((IMsCrmToolsPluginUserControl)pluginControl).OnCloseTool += MainForm_OnCloseTool; string name = string.Format("{0} ({1})", pluginControl.GetType().GetTitle(), currentConnectionDetail != null ? currentConnectionDetail.ConnectionName : "Not connected"); var newTab = new TabPage(name); tabControl1.TabPages.Add(newTab); pluginControl.Dock = DockStyle.Fill; pluginControl.Width = newTab.Width; pluginControl.Height = newTab.Height; newTab.Controls.Add(pluginControl); tabIndex = tabControl1.TabPages.Count - 1; tabControl1.SelectTab(tabIndex); var pluginInOption = currentOptions.MostUsedList.FirstOrDefault(i => i.Name == pluginControl.GetType().FullName); if (pluginInOption == null) { pluginInOption = new PluginUseCount { Name = pluginControl.GetType().FullName, Count = 0 }; currentOptions.MostUsedList.Add(pluginInOption); } pluginInOption.Count++; var p1 = plugin as SmallPluginModel; if (p1 != null) { p1.UpdateCount(pluginInOption.Count); } else { var p2 = plugin as LargePluginModel; if (p2 != null) { p2.UpdateCount(pluginInOption.Count); } } if (currentOptions.LastAdvertisementDisplay == new DateTime() || currentOptions.LastAdvertisementDisplay > DateTime.Now || currentOptions.LastAdvertisementDisplay.AddDays(7) < DateTime.Now) { bool displayAdvertisement = true; try { var assembly = Assembly.LoadFile(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory + "\\McTools.StopAdvertisement.dll"); if (assembly != null) { Type type = assembly.GetType("McTools.StopAdvertisement.LicenseManager"); if (type != null) { MethodInfo methodInfo = type.GetMethod("IsValid"); if (methodInfo != null) { object classInstance = Activator.CreateInstance(type, null); if ((bool)methodInfo.Invoke(classInstance, null)) { displayAdvertisement = false; } } } } } catch (FileNotFoundException) { } if (displayAdvertisement) { var sc = new SupportScreen(currentReleaseNote); sc.ShowDialog(this); currentOptions.LastAdvertisementDisplay = DateTime.Now; } } currentOptions.Save(); } catch (Exception error) { MessageBox.Show(this, "An error occured when trying to display this plugin: " + error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(tabIndex); }
private async void MainForm_Load(object sender, EventArgs e) { this.Opacity = 0; tstxtFilterPlugin.Focus(); pManager = new PluginManager(); pManager.LoadPlugins(); this.DisplayPlugins(); var tasks = new List<Task> { this.LaunchWelcomeDialog(), this.LaunchVersionCheck() }; if (!string.IsNullOrEmpty(this.initialConnectionName)) { var connectionDetail = ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(x => x.ConnectionName == this.initialConnectionName); ; if (connectionDetail != null) { // If initiall connection is present, connect to given sever is initiated. // After connection try to open intial plugin will be attempted. tasks.Add(this.launchInitialConnection(connectionDetail)); } else { // Connection detail was not found, so name provided was incorrect. // But if name of the plugin is set, it should be started if (!string.IsNullOrEmpty(this.initialPluginName)) { this.StartPluginWithoutConnection(); } } } else if (!string.IsNullOrEmpty(this.initialPluginName)) { // If there is no initial connection, but initial plugin is set, openning plugin this.StartPluginWithoutConnection(); } tasks.ForEach(x => x.Start()); await Task.WhenAll(tasks.ToArray()); // Adapt size of current form if (currentOptions.Size.IsMaximized) { WindowState = FormWindowState.Maximized; } else { currentOptions.Size.ApplyFormSize(this); } AdaptPluginControlSize(); WebProxyHelper.ApplyProxy(); this.Opacity = 100; }
private async void MainForm_Load(object sender, EventArgs e) { this.Opacity = 0; pManager = new PluginManager(); pManager.LoadPlugins(); this.DisplayPlugins(); var tasks = new List <Task> { this.LaunchWelcomeDialog(), this.LaunchVersionCheck() }; if (!string.IsNullOrEmpty(this.initialConnectionName)) { var connectionDetail = ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(x => x.ConnectionName == this.initialConnectionName);; if (connectionDetail != null) { // If initiall connection is present, connect to given sever is initiated. // After connection try to open intial plugin will be attempted. tasks.Add(this.launchInitialConnection(connectionDetail)); } else { // Connection detail was not found, so name provided was incorrect. // But if name of the plugin is set, it should be started if (!string.IsNullOrEmpty(this.initialPluginName)) { this.StartPluginWithoutConnection(); } } } else if (!string.IsNullOrEmpty(this.initialPluginName)) { // If there is no initial connection, but initial plugin is set, openning plugin this.StartPluginWithoutConnection(); } tasks.ForEach(x => x.Start()); await Task.WhenAll(tasks.ToArray()); // Adapt size of current form if (currentOptions.Size.IsMaximized) { WindowState = FormWindowState.Maximized; } else { currentOptions.Size.ApplyFormSize(this); } AdaptPluginControlSize(); WebProxyHelper.ApplyProxy(); this.Opacity = 100; }