private void AddPlugin(IToolPlugin plugin)
        {
            var tabitem = new TabItem
            {
                Header = plugin.ToolName,
                Content = plugin.GetToolView()
            };

            tabControl.Items.Add(tabitem);
        }
        private void AddPlugin(IToolPlugin plugin)
        {
            var tabitem = new TabItem
            {
                Header  = plugin.ToolName,
                Content = plugin.GetToolView()
            };

            tabControl.Items.Add(tabitem);
        }
Esempio n. 3
0
        public ToolMenuItemExt(string text, IToolPlugin tool, ExternalToolNotify chghnd)
        {
            this.tool        = tool;
            this.Text        = text;
            this.ToolTipText = text;
            Checked          = false;
            Click           += new EventHandler(LinkClicked);
            Click           += new EventHandler(ClickItem);
            chghandler       = chghnd;

            name = tool.GetType().Namespace + "." + tool.GetType().Name;
        }
 private void ExecuteToolPlugin(IToolPlugin obj)
 {
     try
     {
         obj.Execute();
     }
     catch (Exception ex)
     {
         Log.Error("Error refresh session ", ex);
         ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.MainWnd_Message, ex.Message);
     }
 }
Esempio n. 5
0
 public void Register(IToolPlugin tool)
 {
     if (tool != null)
     {
         if (tool.GetType().GetInterface("SimPe.Interfaces.IDockableTool", true) == typeof(SimPe.Interfaces.IDockableTool))
         {
             if (!dtools.Contains(tool))
             {
                 dtools.Add((SimPe.Interfaces.IDockableTool)tool);
             }
         }
         else if (tool.GetType().GetInterface("SimPe.Interfaces.IToolAction", true) == typeof(SimPe.Interfaces.IToolAction))
         {
             if (!atools.Contains(tool))
             {
                 atools.Add((SimPe.Interfaces.IToolAction)tool);
             }
         }
         else if (tool.GetType().GetInterface("SimPe.Interfaces.IToolPlus", true) == typeof(SimPe.Interfaces.IToolPlus))
         {
             if (!toolsp.Contains(tool))
             {
                 toolsp.Add((SimPe.Interfaces.IToolPlus)tool);
             }
         }
         else if (Helper.StartedGui != Executable.Classic && tool.GetType().GetInterface("SimPe.Interfaces.IListener", true) == typeof(SimPe.Interfaces.IListener))
         {
             if (!listeners.Contains((SimPe.Interfaces.IListener)tool))
             {
                 listeners.Add((SimPe.Interfaces.IListener)tool);
             }
         }
         else if (tool.GetType().GetInterface("SimPe.Interfaces.ITool", true) == typeof(SimPe.Interfaces.ITool))
         {
             if (!tools.Contains(tool))
             {
                 tools.Add((SimPe.Interfaces.ITool)tool);
             }
         }
     }
 }
Esempio n. 6
0
        private void Excuted(object obj)
        {
            var item = (Item)obj;

            string[] pathStrings = item.DllPath.Split('\\');
            string[] pathName    = pathStrings[pathStrings.Length - 1].Split('.');
            switch (pathName[0])
            {
            case "Local":
                this.GetType().GetMethod(pathName[pathName.Length - 1])?.Invoke(this, null);
                break;

            default:
                Assembly DLL;
                try
                {
                    DLL = Assembly.LoadFrom(item.DllPath);
                }
                catch (FileNotFoundException exception)
                {
                    MessageBox.Show("Invalid!");
                    return;
                }
                //var tool = (Tools)DLL.CreateInstance(item.ClassName);
                //foreach (var treeItem in tool.treeItems())
                //    treeItem.func();
                IToolPlugin tool = (IToolPlugin)DLL.CreateInstance(item.ClassName);
                try
                {
                    tool.Func(item.Params);
                }
                catch (Exception ex)
                {
                }

                break;
            }
        }
 private void ExecuteToolPlugin(IToolPlugin obj)
 {
     try
     {
         obj.Execute();
     }
     catch (Exception ex)
     {
         Log.Error("Error refresh session ", ex);
         ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.MainWnd_Message, ex.Message);
     }
 }
 private void ExecuteToolPlugin(IToolPlugin obj)
 {
     HideFlatOuts();
     obj.Execute();
 }
 private void ExecuteToolPlugin(IToolPlugin obj)
 {
     HideFlatOuts();
     obj.Execute();
 }
Esempio n. 10
0
 private void ExecuteToolPlugin(IToolPlugin obj)
 {
     Flyouts[0].IsOpen = false;
     Flyouts[1].IsOpen = false;
     obj.Execute();
 }
Esempio n. 11
0
 private void ExecuteToolPlugin(IToolPlugin obj)
 {
     obj.Execute();
 }
Esempio n. 12
0
 public ToolViewModel(IToolPlugin plugin)
 {
     this.plugin = plugin;
 }
Esempio n. 13
0
        private async Task OnExecuteAsync()
        {
            var toolsOption = GetToolsOptions(ConfigFilePath);

            LoadPlugins(toolsOption.RequiredPlugins);
            LoadPatchs(toolsOption.RequiredPatchs);
            toolPlugins     = GetInstalledPlugins(toolsOption.RequiredPlugins);
            portalPatches   = GetInstalledPortalPatchs(toolsOption.RequiredPatchs);
            identityPatches = GetInstalledIdentityPatchs(toolsOption.RequiredPatchs);
            bool isRunningPlugin = !IsPortal() && !IsIdentity();

            // Check if run with mode patch
            bool isPatchRunning = false;

            if (!isRunningPlugin && !string.IsNullOrEmpty(PatchName) && Command != "install")
            {
                throw new NotSupportedException("Sorry, we only support -pn with install command.");
            }
            else if (!isRunningPlugin && !string.IsNullOrEmpty(PatchName) && Command == "install")
            {
                isPatchRunning = true;
            }


            IToolPlugin toolPlugin = isRunningPlugin ? toolPlugins.First(a => a.AppName == App) : null;
            var         services   = new ServiceCollection();

            ConventionPackDefault.Register();
            MongoDbRegistry.RegisterEntities();
            var dbType         = DatabseType.ToEnum <ConnectionType>(true);
            var databaseOption =
                new DatabaseOptions
            {
                ConnectionString = !string.IsNullOrEmpty(Connection)
                        ? Connection
                            : (isRunningPlugin ?
                               toolPlugin.LoadDefaultDatabase().ConnectionString
                                    : GetDefaultConnectionString(dbType, App, toolsOption)),
                ConnectionType = dbType
            };

            var runningCommand = GetAvailableCommands().FirstOrDefault(a => a.CommandName.ToLower() == Command.ToLower());

            if (runningCommand != null)
            {
                ToolsContext toolsContext       = null;
                var          storingConnections = toolsOption.GetByDatabaseType(dbType);
                switch (dbType)
                {
                case ConnectionType.MongoDB:
                    var mongoConnection        = new MongoConnection(databaseOption);
                    var mongoVersionContext    = new MongoVersionContext(databaseOption);
                    var versionMongoRepository = new VersionMongoRepository(mongoConnection);
                    var patchMongoRepository   = new PatchVersionMongoRepository(mongoConnection);
                    mongoVersionContext.ConnectionType           = ConnectionType.MongoDB;
                    mongoVersionContext.DatabaseOptions          = databaseOption;
                    mongoVersionContext.PortalDatabaseOptions    = toolsOption.MongoStoringConnections.PortalConnection;
                    mongoVersionContext.ServiceManagementOptions = storingConnections.ServiceManagementConnection;
                    mongoVersionContext.IdentityDbOptions        = storingConnections.IdentityConnection;
                    var latestVersion = await versionMongoRepository.GetLastestVersion(App);

                    var allVersions = Enumerable.Empty <IVersion>();
                    IServiceProvider          serviceProvider          = null;
                    PatchVersion              latestPatchVersion       = null;
                    IPortalPatchFeatureTool   portalPatchFeatureTool   = null;
                    IIdentityPatchFeatureTool identityPatchFeatureTool = null;
                    if (IsPortal())
                    {
                        RegisterServicesForPortal(services, databaseOption);
                        if (isPatchRunning)
                        {
                            latestPatchVersion = await patchMongoRepository.GetLatestAsync(App, PatchName);

                            portalPatchFeatureTool = portalPatches.First(a => a.PatchName == PatchName);
                            portalPatchFeatureTool.RegisterServices(services, configuration);
                        }
                        serviceProvider = services.BuildServiceProvider();
                        allVersions     = Scanner.GetAllPortalVersions(serviceProvider);
                    }
                    else if (IsIdentity())
                    {
                        RegisterServicesForIdentity(services, databaseOption);
                        if (isPatchRunning)
                        {
                            latestPatchVersion = await patchMongoRepository.GetLatestAsync(App, PatchName);

                            identityPatchFeatureTool = identityPatches.First(a => a.PatchName == PatchName);
                            identityPatchFeatureTool.RegisterServices(services, configuration);
                        }
                        serviceProvider = services.BuildServiceProvider();
                        allVersions     = Scanner.GetAllIdentityVersions(serviceProvider);
                    }
                    else
                    {
                        var foundPlugin = toolPlugins.First(a => a.AppName.Equals(App, StringComparison.OrdinalIgnoreCase));
                        foundPlugin.RegisterServices(services, configuration);
                        serviceProvider = services.BuildServiceProvider();
                        allVersions     = foundPlugin.GetAllVersions(serviceProvider);
                    }
                    toolsContext = new ToolsContext
                    {
                        LatestVersion          = latestVersion,
                        LatestPatchVersion     = latestPatchVersion,
                        VersionContext         = mongoVersionContext,
                        VersionNumber          = VersionNumber,
                        Versions               = allVersions,
                        VersionRepository      = versionMongoRepository,
                        PatchesFolder          = PatchesFolder,
                        AllowPatch             = !string.IsNullOrEmpty(PatchesFolder),
                        Services               = serviceProvider,
                        PatchVersionRepository = patchMongoRepository,
                        CurrentPatchPortal     = portalPatchFeatureTool,
                        CurrentIdentityPortal  = identityPatchFeatureTool,
                        Arguments              = CombineArguments()
                    };

                    break;

                case ConnectionType.PostgreSQL:
                case ConnectionType.MySQL:
                case ConnectionType.SQLServer:

#pragma warning disable CA2000 // Dispose objects before losing scope
                    var letportalContext = new SaturnFullContext(databaseOption);
#pragma warning restore CA2000 // Dispose objects before losing scope
                    letportalContext.Database.EnsureCreated();

#pragma warning disable CA2000 // Dispose objects before losing scope
                    var letportalContextForRepo = new SaturnFullContext(databaseOption);
#pragma warning restore CA2000 // Dispose objects before losing scope
                    var sqlEFVersionContext = new EFVersionContext(letportalContext)
                    {
                        ConnectionType  = dbType,
                        DatabaseOptions = databaseOption
                    };
                    var patchEFRepository       = new PatchVersionEFRepository(letportalContextForRepo);
                    var portalVersionRepository = new VersionEFRepository(letportalContextForRepo);
                    var latestVersionEF         = await portalVersionRepository.GetLastestVersion(App);

                    sqlEFVersionContext.ServiceManagementOptions = storingConnections.ServiceManagementConnection;
                    sqlEFVersionContext.IdentityDbOptions        = storingConnections.IdentityConnection;
                    sqlEFVersionContext.PortalDatabaseOptions    = storingConnections.PortalConnection;
                    var sqlAllVersions = Enumerable.Empty <IVersion>();
                    IServiceProvider          sqlServiceProvider         = null;
                    PatchVersion              latestEFPatchVersion       = null;
                    IPortalPatchFeatureTool   portalEFPatchFeatureTool   = null;
                    IIdentityPatchFeatureTool identityEFPatchFeatureTool = null;

                    if (IsPortal())
                    {
                        RegisterServicesForPortal(services, databaseOption);
                        if (isPatchRunning)
                        {
                            latestEFPatchVersion = await patchEFRepository.GetLatestAsync(App, PatchName);

                            portalEFPatchFeatureTool = portalPatches.First(a => a.PatchName == PatchName);
                            portalEFPatchFeatureTool.RegisterServices(services, configuration);
                        }
                        sqlServiceProvider = services.BuildServiceProvider();
                        sqlAllVersions     = Scanner.GetAllPortalVersions(sqlServiceProvider);
                    }
                    else if (IsIdentity())
                    {
                        RegisterServicesForIdentity(services, databaseOption);
                        if (isPatchRunning)
                        {
                            latestEFPatchVersion = await patchEFRepository.GetLatestAsync(App, PatchName);

                            identityEFPatchFeatureTool = identityPatches.First(a => a.PatchName == PatchName);
                            identityEFPatchFeatureTool.RegisterServices(services, configuration);
                        }
                        sqlServiceProvider = services.BuildServiceProvider();
                        sqlAllVersions     = Scanner.GetAllIdentityVersions(sqlServiceProvider);
                    }
                    else
                    {
                        var foundPlugin = toolPlugins.First(a => a.AppName.Equals(App, StringComparison.OrdinalIgnoreCase));
                        foundPlugin.RegisterServices(services, configuration);
                        sqlServiceProvider = services.BuildServiceProvider();
                        sqlAllVersions     = foundPlugin.GetAllVersions(sqlServiceProvider);
                    }
                    toolsContext = new ToolsContext
                    {
                        LatestVersion          = latestVersionEF,
                        VersionContext         = sqlEFVersionContext,
                        VersionNumber          = VersionNumber,
                        Versions               = sqlAllVersions,
                        VersionRepository      = portalVersionRepository,
                        AllowPatch             = !string.IsNullOrEmpty(PatchesFolder),
                        Services               = sqlServiceProvider,
                        Arguments              = CombineArguments(),
                        PatchesFolder          = PatchesFolder,
                        PatchVersionRepository = patchEFRepository,
                        CurrentPatchPortal     = portalEFPatchFeatureTool,
                        CurrentIdentityPortal  = identityEFPatchFeatureTool
                    };

                    break;
                }

                if (toolsContext != null)
                {
                    Console.WriteLine("");
                    await runningCommand.RunAsync(toolsContext);

                    toolsContext.Dispose();
                }

                Console.WriteLine("-----------------------++++++DONE++++++-------------------------");
            }
            else
            {
                Console.WriteLine("Oops! We don't find any matching command to execute. If you don't know how to run, please type '--help'");
            }

            Console.ReadLine();
        }