مروری بر ASP.NET Core View Component
Partial Views and Child Actions are one the most used features of ASP.NET MVC. Partial Views provides us a way to create a reusable component that can be used in multiple Views. There are Actions which can be marked as Child Actions and these cannot be invoked via URL but inside views or partial views. Child Actions are no more available with ASP.NET Core. View Components are new way to implement this feature in ASP.NET Core.
مفهوم READ_COMMITTED_SNAPSHOT در EF 6
مواجه میشویم من در دیتابیس از filestreame استفاده کردم برای ذخیره فایلهای مورد نیاز در نرم افزار خودم، میخواستم بدونم آیا استفاده از این روش (filestreame) اصولا خوب هست یا نه؟
public class HandleConcurrencyExceptionAttribute : FilterAttribute, IExceptionFilter { private PropertyMatchingMode _propertyMatchingMode; /// <summary> /// This defines when the concurrencyexception happens, /// </summary> public enum PropertyMatchingMode { /// <summary> /// Uses only the field names in the model to check against the entity. This option is best when you are using /// View Models with limited fields as opposed to an entity that has many fields. The ViewModel (or model) field names will /// be used to check current posted values vs. db values on the entity itself. /// </summary> UseViewModelNamesToCheckEntity = 0, /// <summary> /// Use any non-matching value fields on the entity (except timestamp fields) to add errors to the ModelState. /// </summary> UseEntityFieldsOnly = 1, /// <summary> /// Tells the filter to not attempt to add field differences to the model state. /// This means the end user will not see the specifics of which fields caused issues /// </summary> DontDisplayFieldClashes = 2 } public HandleConcurrencyExceptionAttribute() { _propertyMatchingMode = PropertyMatchingMode.UseViewModelNamesToCheckEntity; } public HandleConcurrencyExceptionAttribute(PropertyMatchingMode propertyMatchingMode) { _propertyMatchingMode = propertyMatchingMode; } /// <summary> /// The main method, called by the mvc runtime when an exception has occured. /// This must be added as a global filter, or as an attribute on a class or action method. /// </summary> /// <param name="filterContext"></param> public void OnException(ExceptionContext filterContext) { if (!filterContext.ExceptionHandled && filterContext.Exception is DbUpdateConcurrencyException) { //Get original and current entity values DbUpdateConcurrencyException ex = (DbUpdateConcurrencyException)filterContext.Exception; var entry = ex.Entries.Single(); //problems with ef4.1/4.2 here because of context/model in different projects. //var databaseValues = entry.CurrentValues.Clone().ToObject(); //var clientValues = entry.Entity; //So - if using EF 4.1/4.2 you may use this workaround var clientValues = entry.CurrentValues.Clone().ToObject(); entry.Reload(); var databaseValues = entry.CurrentValues.ToObject(); List<string> propertyNames; filterContext.Controller.ViewData.ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again to cause your changes to be the current saved values."); PropertyInfo[] entityFromDbProperties = databaseValues.GetType().GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance); if (_propertyMatchingMode == PropertyMatchingMode.UseViewModelNamesToCheckEntity) { //We dont have access to the model here on an exception. Get the field names from modelstate: propertyNames = filterContext.Controller.ViewData.ModelState.Keys.ToList(); } else if (_propertyMatchingMode == PropertyMatchingMode.UseEntityFieldsOnly) { propertyNames = databaseValues.GetType().GetProperties(BindingFlags.Public).Select(o => o.Name).ToList(); } else { filterContext.ExceptionHandled = true; UpdateTimestampField(filterContext, entityFromDbProperties, databaseValues); filterContext.Result = new ViewResult() { ViewData = filterContext.Controller.ViewData }; return; } UpdateTimestampField(filterContext, entityFromDbProperties, databaseValues); //Get all public properties of the entity that have names matching those in our modelstate. foreach (var propertyInfo in entityFromDbProperties) { //If this value is not in the ModelState values, don't compare it as we don't want //to attempt to emit model errors for fields that don't exist. //Compare db value to the current value from the entity we posted. if (propertyNames.Contains(propertyInfo.Name)) { if (propertyInfo.GetValue(databaseValues, null) != propertyInfo.GetValue(clientValues, null)) { var currentValue = propertyInfo.GetValue(databaseValues, null); if (currentValue == null || string.IsNullOrEmpty(currentValue.ToString())) { currentValue = "Empty"; } filterContext.Controller.ViewData.ModelState.AddModelError(propertyInfo.Name, "Current value: " + currentValue); } } //TODO: hmm.... how can we only check values applicable to the model/modelstate rather than the entity we saved? //The problem here is we may only have a few fields used in the viewmodel, but many in the entity //so we could have a problem here with that. //object o = propertyInfo.GetValue(myObject, null); } filterContext.ExceptionHandled = true; filterContext.Result = new ViewResult() { ViewData = filterContext.Controller.ViewData }; } }
Visual Studio 2017 15.7 منتشر شد
- We added support to change installation locations.
- You can Save All your pending changes before you start your update.
- The update dialog provides you even more details about your update during installation.
- C# 7.3 is included in Visual Studio version 15.7.
- We improved solution load time for C# and VB projects.
- We made numerous updates to F# and its tools, with a focus on performance.
- We reduced the time to enable IntelliSense for large .NET Core projects by 25%.
- We made Quick Info improvements and new .NET refactorings like convert
for
-to-foreach
and make private fieldsreadonly
. - We added the ability to publish ASP.NET Core applications to App Service Linux without containers.
- Live Unit Testing works with embedded pdbs and supports projects that use reference assemblies.
- The Test Explorer has more responsive icons during test runs.
- C++ developers can use CodeLens for unit testing.
- We added new rules enforcing items from the C++ Core Guidelines.
- Debugging large solutions with /Debug:fastlink PDBs is more robust.
- CMake integration supports CMake 3.11 and static analysis.
- Python projects support type hints in IntelliSense, and a Run MyPy command has been added to look for typing errors in your code.
- Conda environments are supported in Python projects.
- We added a next version of our Python debugger based on the popular open source pydevd debugger.
- TypeScript 2.8 is included in Visual Studio version 15.7.
- We improved Kestrel HTTPs support during debugging.
- We added support for JavaScript debugging with Microsoft Edge.
- The Debugger supports VSTS and GitHub Authentication for Source Link.
- IntelliTrace’s step-back debugging feature is supported for debugging .NET Core projects.
- We added IntelliTrace support for taking snapshots on exceptions.
- We removed the blocking modal dialog from branch checkouts in Git when a solution or project reload is not required.
- There is an option to choose between OpenSSL and SChannel in Git.
- You can create and associate Azure Key Vaults from within the Visual Studio IDE.
- Visual Studio Tools for Xamarin can automatically install missing Android API levels required by Xamarin.Android projects.
- The Xamarin.Forms XAML editor provides IntelliSense and quick fixes for conditional XAML.
- We added support for Azure, UWP, and additional project types in Visual Studio Build Tools.
- You can create build servers without installing all of Visual Studio.
- The Windows 10 April 2018 Update SDK - Build 17134 is the default required SDK for the Universal Windows Platform development workload.
- We added support for Visual State Management for all UWP apps and more.
- We enabled automatic updates for sideloaded APPX packages.
- You have new tools for migrating to NuGet PackageReference.
- We added support for NuGet package signatures.
- We added Service Fabric Tooling for the 6.2 Service Fabric release.
- We updated Entity Framework Tools to work with the EF 6.2 runtime and to improve reverse engineering of existing databases.
Modern software development practices value quick and continuous updates, following processes that minimize the impact of software failures. As important as identifying bugs early, finding out if changes are improving business value are equally important. These practices can only work when a monitoring solution is in place. This article explores options for adding observability to .NET Core apps. They have been collected based on interactions with customers using .NET Core in different environments. We will be looking into OpenTelemetry and Application Insights SDKs to add observability to a sample distributed application.