(CORE) CORE (2022)

Asynchronous MultiThreaded SSH engine for Web (Net Core 6, Linux) - Part 3,4 (CryptoAPI/CryptoService and Database Access).
Protect password in DB and config, Task.Run for Async DB access, Expand POCO classes, Service lifetime list, Linq and Iterator/Yield functions.

3. CryptoAPI/CryptoService.

Based on function EncryptString/DecryptStrin from page Linux shell parser (Renci.SshNet.SshClient, MySqlConnector.NET, RSA encription, Console password, XDocument/XPath, Tuple, Regex, Buffer.BlockCopy, Stream, Base64String, UTF8.GetBytes, ToString("X2")) and on function AES_ENCRYPT and AES_DECRYPT described on this page Working with MySQL Blob. I have created controller AES for using this API by frontend (one of the number of other controllers for my project frontend):



This so basic code:


   1:  Imports System.IO
   2:  Imports System.Text
   3:  Imports BackendAPI.Helper
   4:  Imports BackendAPI.Model
   5:  Imports BackendAPI.Services
   6:  Imports Microsoft.AspNetCore.Http
   7:  Imports Microsoft.AspNetCore.Mvc
   8:  Imports Microsoft.EntityFrameworkCore
   9:  Imports Newtonsoft.Json.Linq
  10:   
  11:  Namespace WebApi.Controllers
  12:   
  13:      <ApiController>
  14:      <Route("[controller]/[action]")>
  15:      Public Class AesController
  16:          Inherits ControllerBase
  17:   
  18:          Private ReadOnly Aes As AesCryptor
  19:          Private ReadOnly _DB As ApplicationDbContext
  20:          Private ReadOnly _UserService As IUserService
  21:          Private ReadOnly _httpContextAccessor As IHttpContextAccessor
  22:   
  23:          Public Sub New(ByVal UserService As IUserService, Cryptor As IAesCryptor, DbContext As ApplicationDbContext, httpContextAccessor As IHttpContextAccessor)
  24:              Aes = Cryptor
  25:              _DB = DbContext
  26:              _UserService = UserService
  27:              _httpContextAccessor = httpContextAccessor
  28:          End Sub
  29:   
  30:          <HttpGet>
  31:          Public Function NetCrypt(Text As String, KeyString As String) As String
  32:              'encrypted/decrypted password and key can less than 15 chars
  33:              Return Aes.EncryptString(Text, KeyString)
  34:          End Function
  35:   
  36:          <HttpGet>
  37:          Public Function NetDeCrypt(CipherText As String, KeyString As String) As String
  38:              'encrypted/decrypted password and key can less than 15 chars
  39:              Return Aes.DecryptString(CipherText, KeyString)
  40:          End Function
  41:   
  42:          'Authorize because vulnerable to SQL injection
  43:          <Jwt.Authorize>
  44:          <HttpGet>
  45:          Public Function SqlCrypt(Text As String, KeyString As String) As JsonResult
  46:              Dim CurUsers = _UserService.GetCurrentUser(_httpContextAccessor.HttpContext.Request.Headers("JwtUserName")(0))
  47:              If CurUsers.IsAdmin Then
  48:                  Dim Buf1 As Byte() = New Byte() {}
  49:                  ReDim Buf1(100)
  50:                  _DB.RawSqlQuery(Of Byte())($"select aes_encrypt('{Text}','{KeyString}') as aes_encrypt", Function(X)
  51:                                                                                                               CType(X("aes_encrypt"), Byte()).CopyTo(Buf1, 0)
  52:                                                                                                               ReDim Preserve Buf1(CType(X("aes_encrypt"), Byte()).Length - 1)
  53:                                                                                                               Return Nothing
  54:                                                                                                           End Function)
  55:                  Dim Sb1 As New StringBuilder
  56:                  For Each One As Byte In Buf1.ToArray
  57:                      Sb1.Append(One.ToString("X2"))
  58:                  Next
  59:                  Dim Ret1 As New With {.ToBase64String = Convert.ToBase64String(Buf1), .Hex = Sb1.ToString, .Utf8String = UTF8Encoding.UTF8.GetString(Buf1)}
  60:                  Return New JsonResult(Ret1)
  61:              Else
  62:                  Return New JsonResult(Unauthorized())
  63:              End If
  64:   
  65:          End Function
  66:   
  67:          <Jwt.Authorize>
  68:          <HttpGet>
  69:          Public Function SqlDeCrypt(HexCipherText As String, KeyString As String) As JsonResult
  70:              Dim CurUsers = _UserService.GetCurrentUser(_httpContextAccessor.HttpContext.Request.Headers("JwtUserName")(0))
  71:              If CurUsers.IsAdmin Then
  72:                  Dim Buf1 As Byte() = New Byte() {}
  73:                  ReDim Buf1(100)
  74:                  _DB.RawSqlQuery(Of Byte())($"select aes_decrypt(X'{HexCipherText}','{KeyString}') as aes_decrypt", Function(X)
  75:                                                                                                                         CType(X("aes_decrypt"), Byte()).CopyTo(Buf1, 0)
  76:                                                                                                                         ReDim Preserve Buf1(CType(X("aes_decrypt"), Byte()).Length - 1)
  77:                                                                                                                         Return Nothing
  78:                                                                                                                     End Function)
  79:                  Dim Sb1 As New StringBuilder
  80:                  For Each One As Byte In Buf1.ToArray
  81:                      Sb1.Append(One.ToString("X2"))
  82:                  Next
  83:                  Dim Ret1 As New With {.ToBase64String = Convert.ToBase64String(Buf1), .Hex = Sb1.ToString, .Utf8String = UTF8Encoding.UTF8.GetString(Buf1)}
  84:                  Return New JsonResult(Ret1)
  85:              Else
  86:                  Return New JsonResult(Unauthorized())
  87:              End If
  88:          End Function
  89:   
  90:          <Jwt.Authorize>
  91:          <HttpGet>
  92:          Public Function UpdateDecryptedPass(Type As PassType, OldPass As String, NewPass As String) As ActionResult
  93:              Dim CurUsers = _UserService.GetCurrentUser(_httpContextAccessor.HttpContext.Request.Headers("JwtUserName")(0))
  94:              If CurUsers.IsAdmin Then
  95:                  Dim Ret1 = UpdDecryptedPass(_DB, Type, OldPass, NewPass)
  96:                  If Ret1.Item2 Is Nothing Then
  97:                      Return Ok(NewPass)
  98:                  Else
  99:                      Return StatusCode(StatusCodes.Status500InternalServerError, Ret1.Item2)
 100:                  End If
 101:              Else
 102:                  Return New JsonResult(Unauthorized())
 103:              End If
 104:          End Function
 105:   
 106:          <Jwt.Authorize>
 107:          <HttpPost>
 108:          Public Function CheckDecryptPass(AllDecryptPass As DecryptPass) As IActionResult
 109:              Dim CurUsers = _UserService.GetCurrentUser(_httpContextAccessor.HttpContext.Request.Headers("JwtUserName")(0))
 110:              If CurUsers.IsAdmin Then
 111:                  Dim ServerDecryptPass = ChkDecryptedPass(_DB, AllDecryptPass, PassType.ServerDecryptPass)
 112:                  Dim VmConnectionDecryptPass = ChkDecryptedPass(_DB, AllDecryptPass, PassType.VmConnectionDecryptPass)
 113:                  Dim DockerHubVmDecryptPass = ChkDecryptedPass(_DB, AllDecryptPass, PassType.DockerHubVmDecryptPass)
 114:                  Dim DockerRegistryVmDecryptPass = ChkDecryptedPass(_DB, AllDecryptPass, PassType.DockerRegistryVmDecryptPass)
 115:                  Return Ok(New With {
 116:                            .ServerDecryptPass = ServerDecryptPass,
 117:                            .VmConnectionDecryptPass = VmConnectionDecryptPass,
 118:                            .DockerHubVmDecryptPass = DockerHubVmDecryptPass,
 119:                            .DockerRegistryVmDecryptPass = DockerRegistryVmDecryptPass
 120:                            })
 121:              Else
 122:                  Return New JsonResult(Unauthorized())
 123:              End If
 124:          End Function
 125:   
 126:          <HttpGet>
 127:          Public Function GetRandomPassword(Len As Integer) As IActionResult
 128:              Return New JsonResult(CreateRandomPassword(Len, FromChagCode:=&H21, ToCharCode:=&H7E))
 129:          End Function
 130:   
 131:          <HttpGet>
 132:          Public Function GetRandomName(Len As Integer) As IActionResult
 133:              Return New JsonResult(CreateRandomPassword(Len, FromChagCode:=&H61, ToCharCode:=&H7A))
 134:          End Function
 135:   
 136:          Public Shared Function UpdDecryptedPass(_DB As ApplicationDbContext, Type As PassType, OldPass As String, NewPass As String) As Tuple(Of Integer, Exception)
 137:              Dim Res1 As Integer
 138:              _DB.Database.OpenConnection
 139:              Dim CMD1 = _DB.Database.GetDbConnection().CreateCommand()
 140:              Try
 141:                  Select Case Type
 142:                      Case PassType.ServerDecryptPass
 143:                          CMD1.CommandText = $"Update `cryptochestmax`.`KvmHost` set `Password`= IF( OCTET_LENGTH(AES_DECRYPT(`Password`,'{OldPass}')) is null, `Password`, AES_ENCRYPT(AES_DECRYPT(`Password`,'{OldPass}'),'{NewPass}'));"
 144:                      Case PassType.VmConnectionDecryptPass
 145:                          CMD1.CommandText = $"Update `cryptochestmax`.`VM` set `AdminPassword`= IF( OCTET_LENGTH(AES_DECRYPT(`AdminPassword`,'{OldPass}')) is null, `AdminPassword`, AES_ENCRYPT(AES_DECRYPT(`AdminPassword`,'{OldPass}'),'{NewPass}'));"
 146:                      Case PassType.DockerHubVmDecryptPass
 147:                          CMD1.CommandText = $"Update `cryptochestmax`.`DockerHubVm` set `Pass`= IF( OCTET_LENGTH(AES_DECRYPT(`Pass`,'{OldPass}')) is null, `Pass`, AES_ENCRYPT(AES_DECRYPT(`Pass`,'{OldPass}'),'{NewPass}'));"
 148:                      Case PassType.DockerRegistryVmDecryptPass
 149:                          CMD1.CommandText = $"Update `cryptochestmax`.`DockerRegistryVm` set `Pass`= IF( OCTET_LENGTH(AES_DECRYPT(`Pass`,'{OldPass}')) is null, `Pass`, AES_ENCRYPT(AES_DECRYPT(`Pass`,'{OldPass}'),'{NewPass}'));"
 150:                      Case PassType.UserDecryptPass
 151:                          CMD1.CommandText = $"Update `cryptochestmax`.`User` set `Password`= IF( OCTET_LENGTH(AES_DECRYPT(`Password`,'{OldPass}')) is null, `Password`, AES_ENCRYPT(AES_DECRYPT(`Password`,'{OldPass}'),'{NewPass}'));"
 152:                  End Select
 153:                  Res1 = CMD1.ExecuteNonQuery
 154:                  Return New Tuple(Of Integer, Exception)(Res1, Nothing)
 155:              Catch ex As Exception
 156:                  Debug.WriteLine(CMD1.CommandText & vbCrLf & ex.Message)
 157:                  Return New Tuple(Of Integer, Exception)(Nothing, ex)
 158:              End Try
 159:          End Function
 160:   
 161:          Public Shared Function ChkDecryptedPass(_DB As ApplicationDbContext, AllDecryptPass As DecryptPass, Type As PassType) As Tuple(Of List(Of Nullable(Of Integer)), Exception)
 162:              Dim Res1 As New List(Of Nullable(Of Integer))
 163:              _DB.Database.OpenConnection
 164:              Dim CMD1 = _DB.Database.GetDbConnection().CreateCommand()
 165:              Try
 166:                  Select Case Type
 167:                      Case PassType.ServerDecryptPass
 168:                          CMD1.CommandText = $"Select OCTET_LENGTH(AES_DECRYPT(`Password`,'{AllDecryptPass.ServerDecryptPass}')) as ServerDecryptPass  from  `cryptochestmax`.`KvmHost`;"
 169:                      Case PassType.VmConnectionDecryptPass
 170:                          CMD1.CommandText = $"Select OCTET_LENGTH(AES_DECRYPT(`AdminPassword`,'{AllDecryptPass.VmConnectionDecryptPass}')) as VmConnectionDecryptPass from `cryptochestmax`.`VM`;"
 171:                      Case PassType.DockerHubVmDecryptPass
 172:                          CMD1.CommandText = $"Select OCTET_LENGTH(AES_DECRYPT(`Pass`,'{AllDecryptPass.DockerHubVmDecryptPass}')) as DockerHubVmDecryptPass from `cryptochestmax`.`DockerHubVm`;"
 173:                      Case PassType.DockerRegistryVmDecryptPass
 174:                          CMD1.CommandText = $"Select OCTET_LENGTH(AES_DECRYPT(`Pass`,'{AllDecryptPass.DockerRegistryVmDecryptPass}')) as DockerRegistryVmDecryptPass from `cryptochestmax`.`DockerRegistryVm`;"
 175:                  End Select
 176:                  Dim RDR1 = CMD1.ExecuteReader
 177:                  While RDR1.Read
 178:                      Select Case Type
 179:                          Case PassType.ServerDecryptPass
 180:                              Res1.Add(RDR1.CheckDBNull(Of Integer)(RDR1("ServerDecryptPass")))
 181:                          Case PassType.VmConnectionDecryptPass
 182:                              Res1.Add(RDR1.CheckDBNull(Of Integer)(RDR1("VmConnectionDecryptPass")))
 183:                          Case PassType.DockerHubVmDecryptPass
 184:                              Res1.Add(RDR1.CheckDBNull(Of Integer)(RDR1("DockerHubVmDecryptPass")))
 185:                          Case PassType.DockerRegistryVmDecryptPass
 186:                              Res1.Add(RDR1.CheckDBNull(Of Integer)(RDR1("DockerRegistryVmDecryptPass")))
 187:                      End Select
 188:                  End While
 189:                  RDR1.Close()
 190:                  Return New Tuple(Of List(Of Nullable(Of Integer)), Exception)(Res1, Nothing)
 191:              Catch ex As Exception
 192:                  Debug.WriteLine(CMD1.CommandText & vbCrLf & ex.Message)
 193:                  Return New Tuple(Of List(Of Nullable(Of Integer)), Exception)(Nothing, ex)
 194:              End Try
 195:          End Function
 196:   
 197:   
 198:   
 199:   
 200:  #Region "Random"
 201:          Public Shared Function CreateRandomPassword(Len As Integer, Optional FromChagCode As UInt32 = &H21, Optional ToCharCode As UInt32 = &H7E, Optional ExcludeChars As String = "<>'""") As String
 202:              Dim Ret1 As New System.Text.StringBuilder
 203:              While Ret1.Length < Len
 204:                  Dim RandomNum As Integer = FromChagCode + GetRandomInteger(ToCharCode - FromChagCode)
 205:                  Dim OneChar As Char = ChrW(RandomNum)
 206:                  If Not ExcludeChars.Contains(OneChar) Then
 207:                      Ret1.Append(OneChar)
 208:                  End If
 209:              End While
 210:              Return Ret1.ToString
 211:          End Function
 212:   
 213:          Public Shared Function GetRandomInteger(MaxValue As Integer) As Integer
 214:              Dim byte_count As Byte() = New Byte(3) {}
 215:              Dim random_number As New System.Security.Cryptography.RNGCryptoServiceProvider()
 216:              random_number.GetBytes(byte_count)
 217:              Return (Math.Abs(BitConverter.ToInt32(byte_count, 0)) / Int32.MaxValue) * MaxValue
 218:          End Function
 219:  #End Region
 220:   
 221:      End Class
 222:   
 223:  End Namespace

As you can see this API can be used to protect 5 PassType of password in database, therefore database NEVER store password in clear view, this is protection from rogue intrusion for run-time environment.

And also I have injected CryptoService, I used it for protection password for database in the same way.



And than I add the same class as service (line 57).



By the way, look to line 67-70, in this line I show this list with all services loaded in DI with lifetime.

1. Scoped : BackendAPI.Services.IUserService
2. Scoped : Microsoft.AspNetCore.Authentication.IAuthenticationHandlerProvider
3. Scoped : Microsoft.AspNetCore.Authentication.IAuthenticationService
4. Scoped : Microsoft.AspNetCore.Http.IMiddlewareFactory
5. Scoped : Microsoft.AspNetCore.SignalR.IHubActivator`1[THub]
6. Scoped : Microsoft.Extensions.Options.IOptionsSnapshot`1[TOptions]
7. Singleton : BackendAPI.Services.IAesCryptor
8. Singleton : BackendAPI.Services.INotificationCacheService
9. Singleton : Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider
10. Singleton : Microsoft.AspNetCore.Authentication.IClaimsTransformation
11. Singleton : Microsoft.AspNetCore.Authorization.Policy.AuthorizationPolicyMarkerService
12. Singleton : Microsoft.AspNetCore.Connections.IConnectionListenerFactory
13. Singleton : Microsoft.AspNetCore.Hosting.Builder.IApplicationBuilderFactory
14. Singleton : Microsoft.AspNetCore.Hosting.IApplicationLifetime
15. Singleton : Microsoft.AspNetCore.Hosting.IHostingEnvironment
16. Singleton : Microsoft.AspNetCore.Hosting.IStartupFilter
17. Singleton : Microsoft.AspNetCore.Hosting.IStartupFilter
18. Singleton : Microsoft.AspNetCore.Hosting.IStartupFilter
19. Singleton : Microsoft.AspNetCore.Hosting.IWebHostEnvironment
20. Singleton : Microsoft.AspNetCore.Hosting.Server.IServer
21. Singleton : Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionDispatcher
22. Singleton : Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager
23. Singleton : Microsoft.AspNetCore.Http.IHttpContextAccessor
24. Singleton : Microsoft.AspNetCore.Http.IHttpContextFactory
25. Singleton : Microsoft.AspNetCore.Mvc.ActionConstraints.ActionConstraintCache
26. Singleton : Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider
27. Singleton : Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModelFactory
28. Singleton : Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager
29. Singleton : Microsoft.AspNetCore.Mvc.Controllers.IControllerActivatorProvider
30. Singleton : Microsoft.AspNetCore.Mvc.Controllers.IControllerFactory
31. Singleton : Microsoft.AspNetCore.Mvc.Controllers.IControllerFactoryProvider
32. Singleton : Microsoft.AspNetCore.Mvc.DataAnnotations.IValidationAttributeAdapterProvider
33. Singleton : Microsoft.AspNetCore.Mvc.Filters.IFilterProvider
34. Singleton : Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilder
35. Singleton : Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterConfigurationProvider
36. Singleton : Microsoft.AspNetCore.Mvc.Formatters.FormatFilter
37. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionEndpointDataSourceFactory
38. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvokerCache
39. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorChangeProvider
40. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider
41. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionInvokerFactory
42. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.ContentResult]
43. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.FileContentResult]
44. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.FileStreamResult]
45. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.JsonResult]
46. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.LocalRedirectResult]
47. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.ObjectResult]
48. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.PhysicalFileResult]
49. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.RedirectResult]
50. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.RedirectToActionResult]
51. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.RedirectToPageResult]
52. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.RedirectToRouteResult]
53. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor`1[Microsoft.AspNetCore.Mvc.VirtualFileResult]
54. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultTypeMapper
55. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IActionSelector
56. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IClientErrorFactory
57. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IHttpRequestStreamReaderFactory
58. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.IHttpResponseStreamWriterFactory
59. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.ITypeActivatorCache
60. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.OrderedEndpointsSequenceProviderCache
61. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.OutputFormatterSelector
62. Singleton : Microsoft.AspNetCore.Mvc.Infrastructure.ProblemDetailsFactory
63. Singleton : Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinderFactory
64. Singleton : Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider
65. Singleton : Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder
66. Singleton : Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ClientValidatorCache
67. Singleton : Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator
68. Singleton : Microsoft.AspNetCore.Mvc.Routing.ActionEndpointFactory
69. Singleton : Microsoft.AspNetCore.Mvc.Routing.ControllerActionEndpointDataSourceIdProvider
70. Singleton : Microsoft.AspNetCore.Mvc.Routing.DynamicControllerEndpointSelectorCache
71. Singleton : Microsoft.AspNetCore.Mvc.Routing.IRequestDelegateFactory
72. Singleton : Microsoft.AspNetCore.Mvc.Routing.IUrlHelperFactory
73. Singleton : Microsoft.AspNetCore.Mvc.Routing.MvcRouteHandler
74. Singleton : Microsoft.AspNetCore.Routing.EndpointDataSource
75. Singleton : Microsoft.AspNetCore.Routing.IEndpointAddressScheme`1[Microsoft.AspNetCore.Routing.RouteValuesAddress]
76. Singleton : Microsoft.AspNetCore.Routing.IEndpointAddressScheme`1[System.String]
77. Singleton : Microsoft.AspNetCore.Routing.Internal.DfaGraphWriter
78. Singleton : Microsoft.AspNetCore.Routing.LinkGenerator
79. Singleton : Microsoft.AspNetCore.Routing.LinkParser
80. Singleton : Microsoft.AspNetCore.Routing.MatcherPolicy
81. Singleton : Microsoft.AspNetCore.Routing.MatcherPolicy
82. Singleton : Microsoft.AspNetCore.Routing.MatcherPolicy
83. Singleton : Microsoft.AspNetCore.Routing.MatcherPolicy
84. Singleton : Microsoft.AspNetCore.Routing.MatcherPolicy
85. Singleton : Microsoft.AspNetCore.Routing.Matching.EndpointMetadataComparer
86. Singleton : Microsoft.AspNetCore.Routing.Matching.EndpointSelector
87. Singleton : Microsoft.AspNetCore.Routing.Matching.MatcherFactory
88. Singleton : Microsoft.AspNetCore.Routing.ParameterPolicyFactory
89. Singleton : Microsoft.AspNetCore.Routing.Patterns.RoutePatternTransformer
90. Singleton : Microsoft.AspNetCore.Routing.RoutingMarkerService
91. Singleton : Microsoft.AspNetCore.Routing.Template.TemplateBinderFactory
92. Singleton : Microsoft.AspNetCore.SignalR.HubConnectionHandler`1[THub]
93. Singleton : Microsoft.AspNetCore.SignalR.HubLifetimeManager`1[THub]
94. Singleton : Microsoft.AspNetCore.SignalR.IHubContext`1[THub]
95. Singleton : Microsoft.AspNetCore.SignalR.IHubContext`2[THub,T]
96. Singleton : Microsoft.AspNetCore.SignalR.IHubProtocolResolver
97. Singleton : Microsoft.AspNetCore.SignalR.Internal.HubDispatcher`1[THub]
98. Singleton : Microsoft.AspNetCore.SignalR.Internal.SignalRCoreMarkerService
99. Singleton : Microsoft.AspNetCore.SignalR.IUserIdProvider
100. Singleton : Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol
101. Singleton : Microsoft.Extensions.ApiDescriptions.IDocumentProvider
102. Singleton : Microsoft.Extensions.Configuration.IConfiguration
103. Singleton : Microsoft.Extensions.DependencyInjection.MvcMarkerService
104. Singleton : Microsoft.Extensions.DependencyInjection.SignalRMarkerService
105. Singleton : Microsoft.Extensions.Hosting.HostBuilderContext
106. Singleton : Microsoft.Extensions.Hosting.IApplicationLifetime
107. Singleton : Microsoft.Extensions.Hosting.IHost
108. Singleton : Microsoft.Extensions.Hosting.IHostApplicationLifetime
109. Singleton : Microsoft.Extensions.Hosting.IHostEnvironment
110. Singleton : Microsoft.Extensions.Hosting.IHostingEnvironment
111. Singleton : Microsoft.Extensions.Hosting.IHostLifetime
112. Singleton : Microsoft.Extensions.Logging.Configuration.ILoggerProviderConfiguration`1[T]
113. Singleton : Microsoft.Extensions.Logging.Configuration.ILoggerProviderConfigurationFactory
114. Singleton : Microsoft.Extensions.Logging.Configuration.LoggingConfiguration
115. Singleton : Microsoft.Extensions.Logging.Configuration.LoggingConfiguration
116. Singleton : Microsoft.Extensions.Logging.Console.ConsoleFormatter
117. Singleton : Microsoft.Extensions.Logging.Console.ConsoleFormatter
118. Singleton : Microsoft.Extensions.Logging.Console.ConsoleFormatter
119. Singleton : Microsoft.Extensions.Logging.EventSource.LoggingEventSource
120. Singleton : Microsoft.Extensions.Logging.ILogger`1[TCategoryName]
121. Singleton : Microsoft.Extensions.Logging.ILoggerFactory
122. Singleton : Microsoft.Extensions.Logging.ILoggerProvider
123. Singleton : Microsoft.Extensions.Logging.ILoggerProvider
124. Singleton : Microsoft.Extensions.Logging.ILoggerProvider
125. Singleton : Microsoft.Extensions.Logging.ILoggerProvider
126. Singleton : Microsoft.Extensions.ObjectPool.ObjectPool`1[Microsoft.AspNetCore.Routing.UriBuildingContext]
127. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[BackendAPI.Jwt.JwtSettings]
128. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Builder.WebSocketOptions]
129. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Hosting.GenericWebHostServiceOptions]
130. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Http.Connections.ConnectionOptions]
131. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Mvc.MvcOptions]
132. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Mvc.MvcOptions]
133. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Mvc.MvcOptions]
134. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions]
135. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.SignalR.HubOptions]
136. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.SignalR.HubOptions`1[BackendAPI.Notification.NotificationHub]]
137. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.SignalR.HubOptions`1[BackendAPI.Notification.NotificationHub]]
138. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.SignalR.JsonHubProtocolOptions]
139. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Hosting.HostOptions]
140. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.Console.ConsoleFormatterOptions]
141. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions]
142. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.Console.JsonConsoleFormatterOptions]
143. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.Console.SimpleConsoleFormatterOptions]
144. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]
145. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.LoggerFilterOptions]
146. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.LoggerFilterOptions]
147. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.LoggerFilterOptions]
148. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.LoggerFilterOptions]
149. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.LoggerFilterOptions]
150. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.LoggerFilterOptions]
151. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.Extensions.Logging.LoggerFilterOptions]
152. Singleton : Microsoft.Extensions.Options.IConfigureOptions`1[Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions]
153. Singleton : Microsoft.Extensions.Options.IOptions`1[TOptions]
154. Singleton : Microsoft.Extensions.Options.IOptionsChangeTokenSource`1[BackendAPI.Jwt.JwtSettings]
155. Singleton : Microsoft.Extensions.Options.IOptionsChangeTokenSource`1[Microsoft.AspNetCore.HostFiltering.HostFilteringOptions]
156. Singleton : Microsoft.Extensions.Options.IOptionsChangeTokenSource`1[Microsoft.Extensions.Logging.Console.ConsoleFormatterOptions]
157. Singleton : Microsoft.Extensions.Options.IOptionsChangeTokenSource`1[Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions]
158. Singleton : Microsoft.Extensions.Options.IOptionsChangeTokenSource`1[Microsoft.Extensions.Logging.Console.JsonConsoleFormatterOptions]
159. Singleton : Microsoft.Extensions.Options.IOptionsChangeTokenSource`1[Microsoft.Extensions.Logging.Console.SimpleConsoleFormatterOptions]
160. Singleton : Microsoft.Extensions.Options.IOptionsChangeTokenSource`1[Microsoft.Extensions.Logging.LoggerFilterOptions]
161. Singleton : Microsoft.Extensions.Options.IOptionsChangeTokenSource`1[Microsoft.Extensions.Logging.LoggerFilterOptions]
162. Singleton : Microsoft.Extensions.Options.IOptionsChangeTokenSource`1[Microsoft.Extensions.Logging.LoggerFilterOptions]
163. Singleton : Microsoft.Extensions.Options.IOptionsMonitor`1[TOptions]
164. Singleton : Microsoft.Extensions.Options.IOptionsMonitorCache`1[TOptions]
165. Singleton : Microsoft.Extensions.Options.IPostConfigureOptions`1[Microsoft.AspNetCore.HostFiltering.HostFilteringOptions]
166. Singleton : System.Buffers.ArrayPool`1[System.Byte]
167. Singleton : System.Buffers.ArrayPool`1[System.Char]
168. Singleton : System.Diagnostics.ActivitySource
169. Singleton : System.Diagnostics.DiagnosticListener
170. Singleton : System.Diagnostics.DiagnosticSource
171. Singleton : System.Diagnostics.DistributedContextPropagator
172. Transient : BackendAPI.Model.ApplicationDbContext
173. Transient : BackendAPI.WebApi.Controllers.AesController
174. Transient : BackendAPI.WebApi.Controllers.ContainerController
175. Transient : BackendAPI.WebApi.Controllers.DatacenterController
176. Transient : BackendAPI.WebApi.Controllers.DbMasternodeController
177. Transient : BackendAPI.WebApi.Controllers.DockerController
178. Transient : BackendAPI.WebApi.Controllers.KvmDeployVmController
179. Transient : BackendAPI.WebApi.Controllers.KvmDiskOperation
180. Transient : BackendAPI.WebApi.Controllers.KvmInfoController
181. Transient : BackendAPI.WebApi.Controllers.KvmOperationController
182. Transient : BackendAPI.WebApi.Controllers.KvmVmController
183. Transient : BackendAPI.WebApi.Controllers.NotificationController
184. Transient : BackendAPI.WebApi.Controllers.RegistryController
185. Transient : BackendAPI.WebApi.Controllers.UsersController
186. Transient : BackendAPI.WebApi.Controllers.VmImageController
187. Transient : BackendAPI.WebApi.Controllers.VmMasternodeController
188. Transient : BackendAPI.WebApi.Controllers.VmOperationController
189. Transient : Microsoft.AspNetCore.Authorization.IAuthorizationEvaluator
190. Transient : Microsoft.AspNetCore.Authorization.IAuthorizationHandler
191. Transient : Microsoft.AspNetCore.Authorization.IAuthorizationHandlerContextFactory
192. Transient : Microsoft.AspNetCore.Authorization.IAuthorizationHandlerProvider
193. Transient : Microsoft.AspNetCore.Authorization.IAuthorizationMiddlewareResultHandler
194. Transient : Microsoft.AspNetCore.Authorization.IAuthorizationPolicyProvider
195. Transient : Microsoft.AspNetCore.Authorization.IAuthorizationService
196. Transient : Microsoft.AspNetCore.Authorization.Policy.IPolicyEvaluator
197. Transient : Microsoft.AspNetCore.Cors.Infrastructure.ICorsPolicyProvider
198. Transient : Microsoft.AspNetCore.Cors.Infrastructure.ICorsService
199. Transient : Microsoft.AspNetCore.Hosting.IStartupFilter
200. Transient : Microsoft.AspNetCore.Hosting.IStartupFilter
201. Transient : Microsoft.AspNetCore.Mvc.Abstractions.IActionDescriptorProvider
202. Transient : Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider
203. Transient : Microsoft.AspNetCore.Mvc.ActionConstraints.IActionConstraintProvider
204. Transient : Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionProvider
205. Transient : Microsoft.AspNetCore.Mvc.ApplicationModels.IApplicationModelProvider
206. Transient : Microsoft.AspNetCore.Mvc.ApplicationModels.IApplicationModelProvider
207. Transient : Microsoft.AspNetCore.Mvc.ApplicationModels.IApplicationModelProvider
208. Transient : Microsoft.AspNetCore.Mvc.ApplicationModels.IApplicationModelProvider
209. Transient : Microsoft.AspNetCore.Mvc.Controllers.IControllerActivator
210. Transient : Microsoft.AspNetCore.Mvc.Controllers.IControllerPropertyActivator
211. Transient : Microsoft.AspNetCore.Mvc.Cors.CorsAuthorizationFilter
212. Transient : Microsoft.AspNetCore.Mvc.Filters.DisableRequestSizeLimitFilter
213. Transient : Microsoft.AspNetCore.Mvc.Filters.RequestFormLimitsFilter
214. Transient : Microsoft.AspNetCore.Mvc.Filters.RequestSizeLimitFilter
215. Transient : Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.ICompositeMetadataDetailsProvider
216. Transient : Microsoft.AspNetCore.Mvc.Routing.MvcAttributeRouteHandler
217. Transient : Microsoft.AspNetCore.Routing.IInlineConstraintResolver
218. Transient : Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher+Lifetime
219. Transient : Microsoft.AspNetCore.Routing.Matching.DfaMatcherBuilder
220. Transient : Microsoft.AspNetCore.Routing.Tree.TreeRouteBuilder
221. Transient : Microsoft.EntityFrameworkCore.DbContextOptions
222. Transient : Microsoft.EntityFrameworkCore.DbContextOptions`1[BackendAPI.Model.ApplicationDbContext]
223. Transient : Microsoft.Extensions.ObjectPool.ObjectPoolProvider
224. Transient : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Builder.ForwardedHeadersOptions]
225. Transient : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Mvc.ApiBehaviorOptions]
226. Transient : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Mvc.MvcOptions]
227. Transient : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Mvc.MvcOptions]
228. Transient : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Routing.RouteHandlerOptions]
229. Transient : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Routing.RouteOptions]
230. Transient : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Routing.RouteOptions]
231. Transient : Microsoft.Extensions.Options.IConfigureOptions`1[Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions]
232. Transient : Microsoft.Extensions.Options.IConfigureOptions`1[Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions]
233. Transient : Microsoft.Extensions.Options.IConfigureOptions`1[Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions]
234. Transient : Microsoft.Extensions.Options.IOptionsFactory`1[TOptions]
235. Transient : Microsoft.Extensions.Options.IPostConfigureOptions`1[Microsoft.AspNetCore.Mvc.MvcOptions]
236. Transient : Swashbuckle.AspNetCore.Swagger.ISwaggerProvider
237. Transient : Swashbuckle.AspNetCore.SwaggerGen.ISchemaGenerator
238. Transient : Swashbuckle.AspNetCore.SwaggerGen.ISerializerDataContractResolver
239. Transient : Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions
240. Transient : Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions

4. Database Access.

On current project I use a couple of data access methods. Firstly, I have configured EF environment and appDbContext.



But I don't define DbSet, because EF is extremely stupid framework, I simple reserve using EF opportunity to future. Instead EF I use a number of functions, based on raw SQL command CheckDBNull, RawSqlQuery, ExecRDR, RawSqlQueryAsync, ExecNonQueryAsync (with transaction)- amazing extension for working with data.

I use this functions in two ways - inside POCO classes and sometimes define memory buffer (POCO classes) dynamically. And sometimes directly expand POCO class with dataAcess functions.



Also I always use LINQ and Iterator/Yield functions. This is typical my code fragment of this project.


   1:  Namespace Kvm
   2:      Public Class KvmReport
   3:          Public Property KvmHostList As List(Of KvmHostReport)
   4:          Public Sub New()
   5:              KvmHostList = New List(Of KvmHostReport)
   6:          End Sub
   7:          Public Sub GetFullReport(KvmData As KvmDb)
   8:              Dim AdmKvmReport = Me
   9:              For I As Integer = 0 To KvmData.AdmKvmHostList.Count - 1
  10:                  AdmKvmReport.KvmHostList.Add(New KvmHostReport With {
  11:                                                      .i = KvmData.AdmKvmHostList(I).i,
  12:                                                      .Access = New List(Of KvmHostAccessReport),
  13:                                                      .Storage = New List(Of KvmStorageReport),
  14:                                                      .Network = New List(Of KvmNetworkReport),
  15:                                                      .VirtualStorage = New List(Of KvmPoolReport),
  16:                                                      .VM = New List(Of VmReport),
  17:                                                      .OsVersion = KvmData.AdmKvmHostList(I).OsVersion,
  18:                                                      .ServerName = KvmData.AdmKvmHostList(I).ServerName,
  19:                                                      .KvmVersion = KvmData.AdmKvmHostList(I).KvmVersion,
  20:                                                      .UserName = KvmData.AdmKvmHostList(I).UserName,
  21:                                                      .Password = KvmData.AdmKvmHostList(I).Password,
  22:                                                      .CpuModel = KvmData.AdmKvmHostList(I).CpuModel,
  23:                                                      .CpuCount = KvmData.AdmKvmHostList(I).CpuCount,
  24:                                                      .CpuSocket = KvmData.AdmKvmHostList(I).CpuSocket,
  25:                                                      .CorePerSocket = KvmData.AdmKvmHostList(I).CorePerSocket,
  26:                                                      .ThreadPerSocket = KvmData.AdmKvmHostList(I).ThreadPerSocket,
  27:                                                      .NumaCell = KvmData.AdmKvmHostList(I).NumaCell,
  28:                                                      .MemorySize = KvmData.AdmKvmHostList(I).MemorySize,
  29:                                                      .MainServerIP = KvmData.AdmKvmHostList(I).MainServerIP,
  30:                                                      .MonthPrice = KvmData.AdmKvmHostList(I).MonthPrice,
  31:                                                      .Location = KvmData.AdmKvmHostList(I).Location,
  32:                                                      .Comment = KvmData.AdmKvmHostList(I).Comment,
  33:                                                      .LastUpdate = KvmData.AdmKvmHostList(I).LastUpdate
  34:                                               })
  35:                  'Access node
  36:                  AccessReport(KvmData).ToList.ForEach(Sub(X) AdmKvmReport.KvmHostList(I).Access.Add(X))
  37:                  'Pool node
  38:                  PoolReport(KvmData).ToList.ForEach(Sub(X) AdmKvmReport.KvmHostList(I).VirtualStorage.Add(X))
  39:                  'Storage node
  40:                  StorageReport(KvmData).ToList.ForEach(Sub(X) AdmKvmReport.KvmHostList(I).Storage.Add(X))
  41:                  'Network node
  42:                  NetworkReport(KvmData).ToList.ForEach(Sub(X) AdmKvmReport.KvmHostList(I).Network.Add(X))
  43:                  'VM node
  44:                  VmReport(KvmData).ToList.ForEach(Sub(X) AdmKvmReport.KvmHostList(I).VM.Add(X))
  45:              Next
  46:          End Sub
  47:   
  48:          Public Shared Iterator Function AccessReport(KvmData As KvmDb) As IEnumerable(Of KvmHostAccessReport)
  49:              For j As Integer = 0 To KvmData.AdmKvmHostAccessList.Count - 1
  50:                  Dim KvmHostAccessReport1 = New KvmHostAccessReport With {
  51:                                                          .User = New List(Of String),
  52:                                                          .i = KvmData.AdmKvmHostAccessList(j).i,
  53:                                                          .toKvmHost = KvmData.AdmKvmHostAccessList(j).toKvmHost,
  54:                                                          .toUser = KvmData.AdmKvmHostAccessList(j).toUser,
  55:                                                          .FromIp = KvmData.AdmKvmHostAccessList(j).FromIp,
  56:                                                          .Comment = KvmData.AdmKvmHostAccessList(j).Comment,
  57:                                                          .LastUpdate = KvmData.AdmKvmHostAccessList(j).LastUpdate
  58:                  }
  59:                  KvmHostAccessReport1.User = New List(Of String)
  60:                  KvmData.AdmUserList.Where(Function(X) X.i = KvmData.AdmKvmHostAccessList(j).toUser).ToList.ForEach(Sub(Y) KvmHostAccessReport1.User.Add(Y.Name))
  61:                  Yield KvmHostAccessReport1
  62:              Next
  63:          End Function
  64:          Public Shared Iterator Function PoolReport(KvmData As KvmDb) As IEnumerable(Of KvmPoolReport)
  65:              For j As Integer = 0 To KvmData.AdmKvmPoolList.Count - 1
  66:                  Dim KvmPoolReport1 = New KvmPoolReport With {
  67:                          .Volume = New List(Of AdmKvmVolume),
  68:                          .Extent = New List(Of AdmKvmPoolExtent),
  69:                          .i = KvmData.AdmKvmPoolList(j).i,
  70:                          .toStorageDevice = KvmData.AdmKvmPoolList(j).toStorageDevice,
  71:                          .Type = KvmData.AdmKvmPoolList(j).Type,
  72:                          .Name = KvmData.AdmKvmPoolList(j).Name,
  73:                          .State = KvmData.AdmKvmPoolList(j).State,
  74:                          .Autostart = KvmData.AdmKvmPoolList(j).Autostart,
  75:                          .UUID = KvmData.AdmKvmPoolList(j).UUID,
  76:                          .Format = KvmData.AdmKvmPoolList(j).Format,
  77:                          .Path = KvmData.AdmKvmPoolList(j).Path,
  78:                          .Capacity = KvmData.AdmKvmPoolList(j).Capacity,
  79:                          .Allocation = KvmData.AdmKvmPoolList(j).Allocation,
  80:                          .Available = KvmData.AdmKvmPoolList(j).Available,
  81:                          .Comment = KvmData.AdmKvmPoolList(j).Comment,
  82:                          .LastUpdate = KvmData.AdmKvmPoolList(j).LastUpdate
  83:                  }
  84:                  Dim CurVulume = KvmData.AdmKvmVolumeList.Where(Function(X) X.toKvmPool = KvmPoolReport1.i).ToList
  85:                  CurVulume.ForEach(Sub(X) KvmPoolReport1.Volume.Add(X))
  86:                  Dim CurExtent = KvmData.AdmKvmPoolExtentList.Where(Function(X) X.toKvmPool = KvmPoolReport1.i).ToList
  87:                  CurExtent.ForEach(Sub(X) KvmPoolReport1.Extent.Add(X))
  88:                  Yield KvmPoolReport1
  89:              Next
  90:          End Function
  91:          Public Shared Iterator Function StorageReport(KvmData As KvmDb) As IEnumerable(Of KvmStorageReport)
  92:              For j As Integer = 0 To KvmData.AdmKvmStorageDeviceList.Count - 1
  93:                  Dim KvmStorageReport1 = New KvmStorageReport With {
  94:                              .i = KvmData.AdmKvmStorageDeviceList(j).i,
  95:                              .LvmStorage = New List(Of KvmLVMReport),
  96:                              .PartitionStorage = New List(Of KvmDevicePartitionReport),
  97:                              .ToKvmHost = KvmData.AdmKvmStorageDeviceList(j).ToKvmHost,
  98:                              .Name = KvmData.AdmKvmStorageDeviceList(j).Name,
  99:                              .DiskType = KvmData.AdmKvmStorageDeviceList(j).DiskType,
 100:                              .DiskId = KvmData.AdmKvmStorageDeviceList(j).DiskId,
 101:                              .Model = KvmData.AdmKvmStorageDeviceList(j).Model,
 102:                              .Capacity = KvmData.AdmKvmStorageDeviceList(j).Capacity,
 103:                              .SectorSize = KvmData.AdmKvmStorageDeviceList(j).SectorSize,
 104:                              .Bytes = KvmData.AdmKvmStorageDeviceList(j).Bytes,
 105:                              .Sectors = KvmData.AdmKvmStorageDeviceList(j).Sectors,
 106:                              .Comment = KvmData.AdmKvmStorageDeviceList(j).Comment,
 107:                              .LastUpdate = KvmData.AdmKvmStorageDeviceList(j).LastUpdate
 108:                  }
 109:                  KvmData.AdmKvmLVMList.Where(Function(Y) Y.ToKvmStorage = KvmStorageReport1.i).ToList.
 110:                      ForEach(Sub(X) KvmStorageReport1.LvmStorage.Add(
 111:                               New KvmLVMReport With {
 112:                              .LvmMember = New List(Of AdmKvmLVMmember),
 113:                              .i = X.i,
 114:                              .ToKvmStorage = X.ToKvmStorage,
 115:                              .PartName = X.PartName,
 116:                              .LvmName = X.LvmName,
 117:                              .Fmt = X.Fmt,
 118:                              .Size = X.Size,
 119:                              .Free = X.Free,
 120:                              .Comment = X.Comment,
 121:                              .LastUpdate = X.LastUpdate
 122:                  }))
 123:                  Dim LvmPresent = KvmStorageReport1.LvmStorage.Where(Function(X) X IsNot Nothing).Select(Function(Y) New With {Y.LvmMember, Y.i}).ToList
 124:                  For Each OneLvm In LvmPresent
 125:                      For Each OneLvmMember In KvmData.AdmKvmLVMmemberList
 126:                          If OneLvm.i = OneLvmMember.toKvmLVM Then
 127:                              OneLvm.LvmMember.Add(New AdmKvmLVMmember With {
 128:                                  .i = OneLvmMember.i,
 129:                                  .toKvmLVM = OneLvmMember.toKvmLVM,
 130:                                  .DeviceName = OneLvmMember.DeviceName,
 131:                                  .UUID = OneLvmMember.UUID,
 132:                                  .Type = OneLvmMember.Type,
 133:                                  .BlockSize = OneLvmMember.BlockSize,
 134:                                  .Comment = OneLvmMember.Comment,
 135:                                  .LastUpdate = OneLvmMember.LastUpdate
 136:                              })
 137:                          End If
 138:                      Next
 139:                  Next
 140:                  Dim Partitions = KvmData.AdmKvmDevicePartitionList.Where(Function(Y) Y.ToKvmStorageDevice IsNot Nothing)
 141:                  Partitions.Where(Function(Y) Y.ToKvmStorageDevice = KvmStorageReport1.i).ToList.
 142:                   ForEach(Sub(X) KvmStorageReport1.PartitionStorage.Add(New KvmDevicePartitionReport With {
 143:                           .i = X.i,
 144:                           .ToKvmStorageDevice = X.ToKvmStorageDevice,
 145:                           .ToKvmLvmDevice = X.ToKvmLvmDevice,
 146:                           .Name = X.Name,
 147:                           .Type = X.Type,
 148:                           .UUID = X.UUID,
 149:                           .PartUUID = X.PartUUID,
 150:                           .PtType = X.PtType,
 151:                           .PartLabel = X.PartLabel,
 152:                           .BlockSize = X.BlockSize,
 153:                           .Size = X.Size,
 154:                           .Start = X.Start,
 155:                           .[End] = X.[End],
 156:                           .Sectors = X.Sectors,
 157:                           .Comment = X.Comment,
 158:                           .LastUpdate = X.LastUpdate
 159:                    }))
 160:                  Yield KvmStorageReport1
 161:              Next
 162:          End Function
 163:          Public Shared Iterator Function NetworkReport(KvmData As KvmDb) As IEnumerable(Of KvmNetworkReport)
 164:              For j As Integer = 0 To KvmData.AdmKvmBridgeList.Count - 1
 165:                  Dim KvmNetworkReport1 = New KvmNetworkReport With {
 166:                              .NetworkInterface = New List(Of AdmKvmNetworkInterface),
 167:                              .Bridge = New KvmBridgeReport,
 168:                              .i = KvmData.AdmKvmBridgeList(j).i,
 169:                              .toKvmNetwork = KvmData.AdmKvmBridgeList(j).toKvmNetwork,
 170:                              .toKvmVlanSwitch = KvmData.AdmKvmBridgeList(j).toKvmVlanSwitch,
 171:                              .Name = KvmData.AdmKvmBridgeList(j).Name,
 172:                              .Id = KvmData.AdmKvmBridgeList(j).Id,
 173:                              .STP = KvmData.AdmKvmBridgeList(j).STP,
 174:                              .Ip = KvmData.AdmKvmBridgeList(j).Ip,
 175:                              .Comment = KvmData.AdmKvmBridgeList(j).Comment,
 176:                              .LastUpdate = KvmData.AdmKvmBridgeList(j).LastUpdate
 177:                  }
 178:                  KvmData.AdmKvmNetworkInterfaceList.Where(Function(X) X.toKvmHost = KvmNetworkReport1.i).ToList.
 179:                              ForEach(Sub(X) KvmNetworkReport1.NetworkInterface.Add(New AdmKvmNetworkInterface With {
 180:                              .i = X.i,
 181:                              .toKvmHost = X.toKvmHost,
 182:                              .Name = X.Name,
 183:                              .Ip = X.Ip,
 184:                              .Gateway = X.Gateway,
 185:                              .Netmask = X.Netmask,
 186:                              .Broadcast = X.Broadcast,
 187:                              .Mac = X.Mac,
 188:                              .Comment = X.Comment,
 189:                              .LastUpdate = X.LastUpdate
 190:                              }))
 191:                  If KvmNetworkReport1.toKvmVlanSwitch IsNot Nothing Then
 192:                      For k As Integer = 0 To KvmData.AdmKvmBridgeList.Count - 1
 193:                          If KvmData.AdmKvmBridgeList(k).toKvmVlanSwitch IsNot Nothing Then
 194:                              KvmNetworkReport1.Bridge = New KvmBridgeReport With {
 195:                                  .Bridge = KvmData.AdmKvmBridgeList.Where(Function(X) X.toKvmVlanSwitch IsNot Nothing).Where(Function(X) X.toKvmVlanSwitch = KvmNetworkReport1.toKvmVlanSwitch).FirstOrDefault,
 196:                                  .VlanSwitch = New List(Of AdmKvmVlanSwitch),
 197:                                  .Port = New List(Of KvmBridgePortReport)}
 198:                              KvmData.AdmKvmBridgePortList.Where(Function(X) KvmNetworkReport1.Bridge.Bridge IsNot Nothing).Where(Function(X) X.toKvmBridge = KvmNetworkReport1.Bridge.Bridge.i).ToList.ForEach(Sub(X) KvmNetworkReport1.Bridge.Port.Add(New KvmBridgePortReport With {
 199:                                   .IP = KvmData.AdmVmIpList.Where(Function(Z) Z.toKvmBridgePort = X.i).Select(Function(Z) Z.Ip).ToList,
 200:                                   .i = X.i,
 201:                                   .toKvmBridge = X.toKvmBridge,
 202:                                   .BridgePort = X.BridgePort,
 203:                                   .Name = X.Name,
 204:                                   .BridgePortMac = X.BridgePortMac,
 205:                                   .Comment = X.Comment,
 206:                                   .LastUpdate = X.LastUpdate
 207:                                }))
 208:                              KvmNetworkReport1.Bridge.VlanSwitch = KvmData.AdmKvmVlanList.Where(Function(X) X.i = KvmNetworkReport1.Bridge.Bridge.toKvmVlanSwitch).ToList
 209:                          End If
 210:                      Next
 211:                  End If
 212:                  Yield KvmNetworkReport1
 213:              Next
 214:          End Function
 215:          Public Shared Iterator Function VmReport(KvmData As KvmDb) As IEnumerable(Of VmReport)
 216:              For j As Integer = 0 To KvmData.AdmVMList.Count - 1
 217:                  Dim VmReport1 As New VmReport With {
 218:                                  .VmNetworkName = New List(Of AdmBridge),
 219:                                  .Ip = New List(Of String),
 220:                                  .StorageDeviceName = New List(Of AdmVmStorage),
 221:                                  .i = KvmData.AdmVMList(j).i,
 222:                                  .toKvmHost = KvmData.AdmVMList(j).toKvmHost,
 223:                                  .toUser = KvmData.AdmVMList(j).toUser,
 224:                                  .UUID = KvmData.AdmVMList(j).UUID,
 225:                                  .Id = KvmData.AdmVMList(j).Id,
 226:                                  .Name = KvmData.AdmVMList(j).Name,
 227:                                  .OsVersion = KvmData.AdmVMList(j).OsVersion,
 228:                                  .State = KvmData.AdmVMList(j).State,
 229:                                  .CpuSet = KvmData.AdmVMList(j).CpuSet,
 230:                                  .Vcpu = KvmData.AdmVMList(j).Vcpu,
 231:                                  .Memory = KvmData.AdmVMList(j).Memory,
 232:                                  .SpicePort = KvmData.AdmVMList(j).SpicePort,
 233:                                  .MacAdr = KvmData.AdmVMList(j).MacAdr,
 234:                                  .AdminLogin = KvmData.AdmVMList(j).AdminLogin,
 235:                                  .AdminPassword = KvmData.AdmVMList(j).AdminPassword,
 236:                                  .Comment = KvmData.AdmVMList(j).Comment,
 237:                                  .LastUpdate = KvmData.AdmVMList(j).LastUpdate
 238:                      }
 239:                  VmReport1.UserName = KvmData.AdmUserList.Where(Function(X) X.i = VmReport1.toUser).FirstOrDefault.Name
 240:                  VmReport1.VmNetworkName = KvmData.AdmVmIpList.Where(Function(X) X.toVm = VmReport1.i).Select(Function(Z) New AdmBridge With {.BridgePort = Z.KvmBridgePort_BridgePort, .NetworkName = Z.KvmBridgePort_Name, .BridgeName = Z.Bridge_Name}).ToList
 241:                  VmReport1.Ip = KvmData.AdmVmIpList.Where(Function(X) X.toVm = VmReport1.i).Select(Of String)(Function(X) X.Ip).ToList
 242:                  For Each One In KvmData.AdmVmDiskList
 243:                      If One.toVm = VmReport1.i Then
 244:                          Dim VolumeS As List(Of AdmKvmVolume) = KvmData.AdmKvmVolumeList.Where(Function(X) X.i = One.toKvmVolume).ToList
 245:                          For Each OneVol In VolumeS
 246:                              VmReport1.StorageDeviceName.Add(New AdmVmStorage With {.Device = OneVol.Name, .Capacity = OneVol.Capacity})
 247:                          Next
 248:                      End If
 249:                  Next
 250:                  Yield VmReport1
 251:              Next
 252:          End Function
 253:      End Class
 254:  End Namespace

This way allow me to using each component of project in many places of project, for example.






Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: http://www.vb-net.com/SshQueueNotificationServer/Index1.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>