-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8: Suggest installing EF Core tools if not installed
- Loading branch information
Showing
11 changed files
with
136 additions
and
37 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
src/rider/main/kotlin/me/seclerp/rider/plugins/efcore/KnownNotificationGroups.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package me.seclerp.rider.plugins.efcore | ||
|
||
object KnownNotificationGroups { | ||
val efCore = "EF Core Notifications Group" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/rider/main/kotlin/me/seclerp/rider/plugins/efcore/actions/InstallEfCoreAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package me.seclerp.rider.plugins.efcore.actions | ||
|
||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.components.service | ||
import me.seclerp.rider.plugins.efcore.clients.ManagementClient | ||
import me.seclerp.rider.plugins.efcore.commands.executeCommandUnderProgress | ||
|
||
class InstallEfCoreAction : AnAction("Fix") { | ||
override fun actionPerformed(actionEvent: AnActionEvent) { | ||
executeCommandUnderProgress( | ||
actionEvent.project!!, | ||
"Installing EF Core global tools...", | ||
"EF Core global tools has been successfully installed", | ||
false | ||
) { | ||
val managementClient = actionEvent.project!!.service<ManagementClient>() | ||
managementClient.installEfCoreTools() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/rider/main/kotlin/me/seclerp/rider/plugins/efcore/clients/ManagementClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package me.seclerp.rider.plugins.efcore.clients | ||
|
||
import com.intellij.openapi.components.Service | ||
import me.seclerp.rider.plugins.efcore.commands.CliCommand | ||
import me.seclerp.rider.plugins.efcore.commands.CliCommandResult | ||
|
||
@Service | ||
class ManagementClient : BaseEfCoreClient() { | ||
fun getEfCoreVersion(): String? { | ||
val command = CliCommand("dotnet ef --version") | ||
val result = command.execute() | ||
|
||
return if (result.succeeded) | ||
result.output | ||
else | ||
null | ||
} | ||
|
||
fun installEfCoreTools(): CliCommandResult { | ||
val command = CliCommand("dotnet tool install --global dotnet-ef") | ||
return command.execute() | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/rider/main/kotlin/me/seclerp/rider/plugins/efcore/commands/Extensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package me.seclerp.rider.plugins.efcore.commands | ||
|
||
import com.intellij.ide.SaveAndSyncHandler | ||
import com.intellij.notification.NotificationGroupManager | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.fileEditor.FileDocumentManager | ||
import com.intellij.openapi.progress.runBackgroundableTask | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFileManager | ||
import me.seclerp.rider.plugins.efcore.KnownNotificationGroups | ||
|
||
fun executeCommandUnderProgress( | ||
project: Project, taskTitle: String, succeedText: String, shouldRefreshSolution: Boolean = true, | ||
what: (Unit) -> CliCommandResult | ||
) { | ||
runBackgroundableTask(taskTitle, project, false) { | ||
val result = what(Unit) | ||
if (result.succeeded) { | ||
NotificationGroupManager.getInstance().getNotificationGroup(KnownNotificationGroups.efCore) | ||
.createNotification(succeedText, NotificationType.INFORMATION) | ||
.notify(project) | ||
} else { | ||
NotificationGroupManager.getInstance().getNotificationGroup(KnownNotificationGroups.efCore) | ||
.createNotification( | ||
"EF Core command failed", | ||
"Command: ${result.command}\n\nOutput:\n${result.output}\n\nError:${result.error}\n\nExit code: ${result.exitCode}", | ||
NotificationType.ERROR) | ||
.notify(project) | ||
} | ||
|
||
if (shouldRefreshSolution) { | ||
ApplicationManager.getApplication().invokeAndWait { | ||
refreshSolution() | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun refreshSolution() { | ||
FileDocumentManager.getInstance().saveAllDocuments() | ||
SaveAndSyncHandler.getInstance().refreshOpenFiles() | ||
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true) | ||
} |
38 changes: 38 additions & 0 deletions
38
src/rider/main/kotlin/me/seclerp/rider/plugins/efcore/startup/EfCoreStartupActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package me.seclerp.rider.plugins.efcore.startup | ||
|
||
import com.intellij.notification.NotificationGroupManager | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.project.DumbAware | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.startup.StartupActivity | ||
import com.jetbrains.rider.projectView.solution | ||
import me.seclerp.rider.plugins.efcore.KnownNotificationGroups | ||
import me.seclerp.rider.plugins.efcore.actions.InstallEfCoreAction | ||
import me.seclerp.rider.plugins.efcore.clients.ManagementClient | ||
import me.seclerp.rider.plugins.efcore.rd.StartupProjectInfo | ||
import me.seclerp.rider.plugins.efcore.rd.riderEfCoreModel | ||
|
||
class EfCoreStartupActivity : StartupActivity, DumbAware { | ||
override fun runActivity(intellijProject: Project) { | ||
var efCoreStartupProjects: List<StartupProjectInfo>? = null | ||
ApplicationManager.getApplication().invokeAndWait { | ||
efCoreStartupProjects = intellijProject.solution.riderEfCoreModel.getAvailableStartupProjects.sync(Unit) | ||
} | ||
|
||
if (efCoreStartupProjects?.isEmpty() != false) { | ||
return | ||
} | ||
|
||
val efCoreChecker = intellijProject.service<ManagementClient>() | ||
val version = efCoreChecker.getEfCoreVersion() | ||
|
||
if (version == null) { | ||
NotificationGroupManager.getInstance().getNotificationGroup(KnownNotificationGroups.efCore) | ||
.createNotification("EF Core tools are not installed", "These tools are required to execute EF Core commands", NotificationType.WARNING) | ||
.addAction(InstallEfCoreAction()) | ||
.notify(intellijProject) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters