The definitive guide to XILINX FPGA digital signal processing from HDL to model and C description.pdf

The definitive guide to XILINX FPGA digital signal processing from HDL to model and C description pdf HD version

File: n459.com/f/25127180-479733547-4ce299 (Access password: 551685)

The following are irrelevant:

-------------------------------------------Dividing line----- ----------------------------------------

Foreword#
​ I once wrote a series of articles about using Prism in .NET Core3.1 for the purpose of learning. NET Core 3 WPF MVVM framework Prism series article index, and thank you for your support. In fact, the original version was Prism7. 2.0.1442 (7.2) version, and now also released.NET5 and the latest Prism8.0.0.1909 (8.0) version, so I also want to upgrade the previous Prism Demo project to the latest, the purpose of writing this article I can learn it myself, and more is to answer the questions that I left under my Prism series of articles. I think I can use them to talk about some questions, and some of the questions are limited in my level (I really don’t want to answer )
 Then I took the previous Prism Demo project. The WPF upgrade from .NET Core3.1 to .NET 5 is actually very simple. It is enough to modify the TargetFramework of the project to net5.0-windows, but when Prism7.2 is upgraded to Prism8. 0, I found a lot of errors were reported when building, so let's take a look at what has been updated in Prism8.0

1. What is updated in Prism8.0? #
Let’s take a look at the assembly references of Prism7.2 and Prism8.0 first, and we can consider some differences:

Here may not be all the details about Prism8.0 update, but I think some of the main functions, we can see that Prism8.0 compared to Prism7.2, in Prism.WPF removed System.Windows.Interactivity and CommonServiceLocator assembly, introduced Microsoft.Xaml.Behaviors.Wpf, in fact Prism8.0 did the following integration:

Replace System.Windows.Interactivity
CommonServiceLocator with Microsoft.Xaml.Behaviors.Wpf and integrate it into Prism.Core
because you may get an error when updating from the old version to Prism8.0, and my purpose is an update guide about Prism8 For the full details of the .0 update, you can see the official ReleaseNote of Prism8.0 on github. Here is also recommended Dior's article about Prism8.0: [Windows] Prism 8.0 Introduction (Part 1): Prism.Core and [Windows] Prism 8.0 Getting Started (Part 2): Prism.Wpf and Prism.Unity

1. The ContainerLocator.Current.Resolve function is removed: #
Copy
ContainerLocator.Current.Resolve
//Replace with
ServiceLocator.Current.GetInstance
 This may be the first upgrade error you encounter, because the api of ContainerLocator.Current.Resolve was originally Under the CommonServiceLocator assembly under Prism.WPF, it was cut in 8.0. In Prism.Core, ServiceLocator.Current.GetInstance was added for replacement, and the CommonServiceLocator assembly was cut out. I think it is very reasonable, because the function itself should It is a public function in IOC

2. Assembly changes related to event-to-command: #
Copy
xmlns:i=“http://schemas.microsoft.com/expression/2010/interactivity”
//Replace with
xmlns:i=“http://schemas.microsoft .com/xaml/behaviors"
 This may be the second upgrade error you encounter. Because Microsoft.Xaml.Behaviors.Wpf is used to replace System.Windows.Interactivity, the xaml xmlns also need to be changed accordingly

3.去除 Bootstrapper :#
Copy
public partial class App : Bootstrapper

//Replace with
public partial class App: PrismApplication //(recommended) Other platforms also support
//or
public partial class App: PrismBootstrapper //WPF unique
 This may be the third upgrade error you encounter, we are in App. CSS will integrate a low-level class for registration or configuration. In fact, Bootstrapper has been marked as deprecated in Prism7.2, and it is deleted directly in Prism8.0. It is recommended to inherit PrismApplication (supported by all platforms), of course You can also choose PrismBootstrapper (WPF unique)

4. IOC adds a new registration function: #Actually,
 I don’t plan to elaborate on this part of the function of IOC, because it is not a feature of Prism, because Prism supports two IOC extensions by default, namely Unity and DryIoc, and the newly added functions It is also achieved through two IOC support, just look at the code example:

Copy
public interface ITestService { }

public interface ITest2Service { }

public class TestService : ITestService, ITest2Service { }

private static ITestService TestDelegate() =>new TestService();

//Add the function that supports the registration of multiple services corresponding to a single implementation class
var services = new[] {typeof(ITestService), typeof(ITest2Service) };
IContainerRegistry.RegisterManySingleton(services);//Register as a singleton mode
IContainerRegistry.RegisterMany(services );//Register into instantaneous mode

//Add support for registering service as scope (scope mode)
IContainerRegistry.RegisterScoped(typeof(TestService))//Single service
IContainerRegistry.RegisterScoped(typeof(TestService), typeof(TestService))//Single service
IContainerRegistry.RegisterScoped();/ /Single service generic version
IContainerRegistry.RegisterScoped(typeof(ITestService), typeof(TestService))//Single service order implementation

// add support via delegate methods registrar
IContainerRegistry.Register (typeof (ITestService), TestDelegate ) // registered as a transient mode
IContainerRegistry.RegisterSingleton (typeof (ITestService), TestDelegate ) // registered as a singleton
IContainerRegistry.RegisterScoped (typeof ( ITestService), TestDelegate)//registered as scope mode

5. Added an extension method about waiting for Task asynchronously in the void method:
 #You seem to be useless at first glance, but there is still a saying in it. Let’s look at an example, WPF interface MVVM asynchronous read time-consuming data loading interface , Here is the simplified code of xaml::

Copy
xmlns:i=“http://schemas.microsoft.com/xaml/behaviors”
<i:Interaction.Triggers>
<i:EventTrigger EventName=“Loaded”>
<i:InvokeCommandAction Command="{Binding LoadCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>

ViewModel simplified code:

Copy
private ObservableCollection _allMedicines=new ObservableCollection();

public ObservableCollection AllMedicines
{
get { return _allMedicines; }
set { _allMedicines = value; }
}

private DelegateCommand _loadCommand;
public DelegateCommand LoadCommand =>
_loadCommand ?? (_loadCommand = new DelegateCommand(ExecuteLoadCommand));

async void ExecuteLoadCommand()
{
await ALongTask();
this.AllMedicines.AddRange(_medicineSerivce.GetAllMedicines());

}

private async Task ALongTask()
{ await Task.Delay(3000);//simulate time-consuming operation Debug.WriteLine("time-consuming operation completed"); }


This is the normal way we will implement it, and the same does not cause cross-thread problems (ObservableCollection collections will appear in non-UI threads). About async await in WPF, there will be no cross-thread problems. You can refer to my other article. Article What does the asynchronous function async await do in wpf? , And the same will not block the UI main thread when performing time-consuming operations. If the same effect can be achieved without async void at the top layer, this is the meaning of TaskExtension. The following is an example of the non-generic version of TaskExtension api, , There is actually a generic version of TaskExtension, we take the most parameter overload method to illustrate:

Copy
public static class TaskExtensions
{
public static async void Await(this Task task, Action completedCallback, Action errorCallback, bool configureAwait)
{
try
{
await task.ConfigureAwait(configureAwait);
completedCallback?.Invoke();
}
catch (Exception obj)
{
errorCallback?.Invoke(obj);
}
}
}
1.completedCallback:当前Task的回调函数,指Task执行的后续操作

2.errorCallback: the abnormal callback function of the callback function, which can be executed after the callback function is abnormal

3. configureAwait: Indicate whether the callback function is executed in the current execution context, True is yes, false is no

We can modify the ExecuteLoadCommand method:

Copy
void ExecuteLoadCommand()
{ //TaskExtension for async void Command ALongTask().Await( completedCallback:() => { this.AllMedicines.AddRange(_medicineSerivce.GetAllMedicines()); }, errorCallback:null,configureAwait:true); } The execution effect of this method is the same as before, and asynchronous wait operation can be realized without adding async and await inside the method to the void method. This is only recommended to be used in the Executed Method of the Command, which is also officially recommended, because the general Execution Method returns The value will only be void






2. Answer some questions
#How to use AOP in Prism? #
 In fact, AOP is not belong to prism-specific features, but due to the prism support the expansion of IOC container: Unity and DryIoc, as long as the IOC support the container itself, it can, because the default Prism is the default Unity IOC container, so as an example to Unity :

NuGet references Unity AOP library: Unity.Interception (the latest is 5.11.1)

Add extended AOP to App.cs, the code is as follows:

Copy
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
var container = PrismIocExtensions.GetContainer(containerRegistry);
container.AddNewExtension()//add Extension Aop
//注册服务和添加显示拦截
.RegisterType<IMedicineSerivce, MedicineSerivce>(new Interceptor(), new InterceptionBehavior())
.RegisterType<IPatientService, PatientService>(new Interceptor(), new InterceptionBehavior())
.RegisterType<IUserService, UserService>(new Interceptor(), new InterceptionBehavior());

} The
new class LogHandler inherits ICallHandler to process the interception logic and characteristics LogHandlerAttribute, which simulates the record Log:

Copy
public class LogHandler : ICallHandler
{
public int Order { get ; set ; }

public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
      Debug.WriteLine("-------------Method Excute Befored-------------");
      Debug.WriteLine($"Method Name:{input.MethodBase.Name}");
      if (input.Arguments.Count>0)
      {
          Debug.WriteLine("Arguments:");
          for (int i = 0; i < input.Arguments.Count; i++)
          {
              Debug.WriteLine($"parameterName:{input.Arguments.ParameterName(i)},parameterValue:{input.Arguments[i]}");
          }
      }           
      var methodReturn = getNext()(input, getNext);
      Debug.WriteLine("-------------Method Excute After-------------");
      if (methodReturn.Exception!=null)
      {
          Debug.WriteLine($"Exception:{methodReturn.Exception.Message} \n");
      }
      else
      {
          Debug.WriteLine($"Excuted Successed \n");
      }
      return methodReturn;
}

}

public class LogHandlerAttribute: HandlerAttribute
{ public override ICallHandler CreateHandler(IUnityContainer container) { return new LogHandler() {Order = this.Order }; } } Mark Attribute for those interfaces that need to be intercepted





Copy
[LogHandler]
public interface IMedicineSerivce
{
List GetAllMedicines();
List GetRecipesByPatientId(int patientId);
}
[LogHandler]
public interface IPatientService
{
List GetAllPatients();
}
[LogHandler]
public interface IUserService
{
List GetAllUsers();
}

The effect is as follows:

Vs output:

Copy
-------------Method Excute Befored-------------
Method Name:GetAllMedicines
-------------Method Excute After-------------
Excuted Successed

-------------Method Excute Befored-------------
Method Name:GetRecipesByPatientId
Arguments:
parameterName:patientId,parameterValue:1
-------------Method Excute After-------------
Excuted Successed

-------------Method Excute Befored-------------
Method Name:GetRecipesByPatientId
Arguments:
parameterName:patientId,parameterValue:2
-------------Method Excute After-------------
Excuted Successed

-------------Method Excute Befored-------------
Method Name:GetRecipesByPatientId
Arguments:
parameterName:patientId,parameterValue:3
-------------Method Excute After-------------
Excuted Successed

-------------Method Excute Befored-------------
Method Name:GetRecipesByPatientId
Arguments:
parameterName:patientId,parameterValue:4
-------- -----Method Excute After-------------
Excuted Successed
 Of course, the space here is limited. It is impossible to tell too many details about Unity AOP. In fact, Unity AOP is very powerful and supports the same Configuration file to configure AOP and support the interception of different types of methods, you need to know more details here can recommend the blog post AOP in C#_Use Unity to achieve AOP

Are all events and logic handled in the ViewModel? #
 WPF is a data-driven program. When using MVVM frameworks such as Prism or MVVMLight, we will process business data logic in ViewModel and drive the display of the front-end interface through Binding. If the processing logic is View-related, such as the style of the control Changes, mouse movement, controls, and other View logic are related. At this time, it is recommended to use dependencies or additional attributes, or events in the View’s Code-behind cs file to handle the logic of the View. Don’t use all logic for the so-called MVVM Putting it in ViewModel is actually more inflexible, but it is no different from the previous MVC processing in C.

Guess you like

Origin blog.csdn.net/gumenghua_com1/article/details/112860411
Recommended