MainToolbar View

Button Click Event handle àMainToolbar.xaml.cs OnConnect() functionàService.Messenger.Send(new NewConnectionEventArgs())

MainToolbar Viewmodel

_messenger.Register<NewConnectionEventArgs>(this, OnOpenNewConnetionWindow)à OnOpenNewConnetionWindow àPopupWindowShowupàNewConnectControlàbtnConnect_Clickà

……

主要写四个部分如何实现(流程等)

1. 程序启动

Shell (GetView top,main status, LoadWindowIcon etc.)à

MCLSPlugin(Constructor, Register IoC objects new ViewModels; new UI components

MainViewModel(Constructor, new MainToolBarViewModel; ControlPanelViewModel(including ChannelViewModel); )à

MCLSUI(Constructor, new MainToolbar; MainUI(including FrontPanel); StatusBar)

2. 链接硬件,显示状态

MainToolbar(Click Connect Button)à

MainToolbarVM(OnOpenNewConnectionWindow, Refresh available COM ports, new an instance of NewConnectControl, wait for user input)à

NewConnectControl(Click Connect Button, Get user input port number then Send Message Call MainToolBar.xaml.cs OnConnect function )à

MainToolBar OnConnect(DeviceConnectingEventArgs e) (open device and start monitoring port, update data to ControlPanelViewModel, trigger Controlpanel set default value)

3. 通过软件更改设备的运行状态

Click on one channel (FrontPanel Binding ChannelClickCommand)à

ControlPanelViewModel(OnClickChannel, set property SelectChannelViewModel)à

ChannelViewModel(set IsSelected property, Binding with FrontPanel get/or set other properties,and update UI)

4. 多语言支持

------------------------------MCLS-----------------------------------------

Maintoolbar (Click Options Button)à

Maintoolbar VM (New Option Window, set some properties, Open)à

-----------------------------Share library---------------------------------

OptionWindow (Binding OptionModel View element, Create instance by ViewType[LocalizationOption, ManufacturerDefaultView])à

LocalizationOption(via LocalizationService to Query status or do some operation, SupportLanguages,CurrentLanguage Add handler to SelectionChanged event)à

LocalizationService(main class of process multi-language support, maintain a group of SupportLanguage Class, notify binding target current language has changed.)à

SupportLanguage(Control load/unload XML file, lookup keys in built-in dictionary feedback actual value)

====================================================================================

IMessenger 用于在程序的各个模块中发送命令进行通信。

ILocalizationService 用于Support多语言环境

Unity

控制反转(Inverse of control): 某一接口具体实现类的选择控制权(控制)从调用类中移除,转交给第三方决定(反转)。依赖对象的获取被反转了。目的是削减计算机程序的耦合问题。解除合作对象之间引用的耦合。

依赖注入(Dependency Injection):由容器来帮忙创建及注入依赖对象,对象只是被动的接受依赖对象。

由IoC容器帮对象找相应的依赖对象并注入,而不是由对象主动去找。

MVVM Light

Register<TMessage>(Object, Action<TMessage>)

Registers a recipient for a type of message TMessage. The action parameter will be executed when a corresponding message is sent.

Registering a recipient does not create a hard reference to it, so if this recipient is deleted, no memory leak is caused.

Shared Library

PoolingService 用于向设备轮询当前值或者Monitor其他对象等。

DataService 用于控制硬件开启、关闭,以及获取数据。

LocalizationService 用于多种语言的Support

WPF引入的一个新的概念,嵌套消息泵,就是在一个While(GetMessage(...))内部又启动了一个While(GetMessage(...))。

Dispacher

每调用一次Invoke和BeginInvoke,即向Dispatcher中加入了一个任务,并且发送消息通知Render(呈现)线程更新界面显示。

AR:

1. 研究PoolingService的作用?什么时候用?

2. Unity的ServiceLocator究竟起什么作用,如何使用?

3. MCLS在轮询data(轮询线程)如何避免与 SetValue(主线程)冲突?

4. XAML DataTemplate,relative binding代表什么含义,学习。

5. 使用串口通讯工具向MCLS发送、接收命令。

【DataService】

Initial:

生成SerialQueue存放task的集合 。

启动另一个线程按顺序执行SerialQueue中的每个Task,确保一次只有一个task被执行。

SetValue所起到的作用只是向SerialQueue中添加任务,交由其他线程执行后获取返回值。因此不会与其他的task产生冲突。

参考TryGetDeviceValue之流程:

1. New a delegate to call get device value API

2. Add new job into task queue.

3. Let queue process thread execute.

4. Wait and get result from last job.

【PoolingService】

1. 向宿主程序集当中不断发送GetDeviceValueArgs类型的消息(通过MVVM的Messenger传递)

2. 驱动ControlPanelViewModel的OnPooling,将当前的设备状态(选中那个channel、系统是否被enable、channel的实际value)同步到前台界面显示。

【ServiceLocator】

Service Locator模式想要解决的问题是解耦合服务提供者和用户,用户无需直接访问具体的服务提供者类。

服务定位器模式的优缺点

服务定位器模式在带来解耦和、可维护性、动态升级服务等好处的同时,也带来一些不好的方面,比如

1、由于用户无法确切知道服务提供者的真实情况,那么如果出现错误,难以定位

2、集中式、单例的注册机是并行计算、系统扩展的瓶颈

3、由于需要集成全局的服务注册代码,执行单元测试也会麻烦些

4、注册机隐藏了类的依赖关系,使得本来在编译期可以暴露的问题,在运行时才发生

MCLS程序中不需要给每个ViewModel传入container,然后再调用container的Resolve方法。例如:

_localService = container.Resolve<ILocalizationService>();

等价于

ServiceLocator.Current.GetInstance<ILocalizationService>();

【XAML Data Template】

MCLS Notes的更多相关文章

  1. ASP.NET Core 1.1.0 Release Notes

    ASP.NET Core 1.1.0 Release Notes We are pleased to announce the release of ASP.NET Core 1.1.0! Antif ...

  2. Android Weekly Notes Issue #237

    Android Weekly Issue #237 December 25th, 2016 Android Weekly Issue #237 这是本年的最后一篇issue, 感谢大家. 本期内容包括 ...

  3. Android Weekly Notes Issue #230

    Android Weekly Notes Issue #230 November 6th, 2016 Android Weekly Issue #230. Android Weekly笔记, 本期内容 ...

  4. Android Weekly Notes Issue #229

    Android Weekly Issue #229 October 30th, 2016 Android Weekly Issue #229 Android Weekly笔记, 本期内容包括: 性能库 ...

  5. Android Weekly Notes Issue #227

    Android Weekly Issue #227 October 16th, 2016 Android Weekly Issue #227. 本期内容包括: Google的Mobile Vision ...

  6. Android Weekly Notes Issue #221

    Android Weekly Issue #221 September 4th, 2016 Android Weekly Issue #221 ARTICLES & TUTORIALS And ...

  7. Android Weekly Notes Issue #219

    Android Weekly Issue #219 August 21st, 2016 Android Weekly Issue #219 ARTICLES & TUTORIALS Andro ...

  8. MAGIC XPA最新版本Magic xpa 2.4c Release Notes

    New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...

  9. Magic xpa 2.5发布 Magic xpa 2.5 Release Notes

    Magic xpa 2.5發佈 Magic xpa 2.5 Release Notes Magic xpa 2.5 Release NotesNew Features, Feature Enhance ...

随机推荐

  1. MD5登陆密码的生成

    package com.cinc.ecmp.userpermission.utils; import java.security.MessageDigest;import java.security. ...

  2. dotnet 通过 WMI 获取系统补丁

    本文告诉大家如何通过 WMI 获取补丁 通过 Win32_QuickFixEngineering 可以获取系统启动的服务 下面代码只是获取补丁的 kb 字符 const string query = ...

  3. Sql Server知识点拨

    一.Sql Server异常捕获try catch 二.集增加与修改的存储过程 三.显示某一列中有重复值的行 转载自:https://www.cnblogs.com/527289276qq/

  4. VRChat之转移地图缓存

    我的电脑是win10,win10的缓存地址和名称可能和win7的名字有所不同. win10缓存路径:C:\Users\Administrator\AppData\LocalLow\VRChat\VRC ...

  5. Linux 操作虚拟机、数据库

    1.打开虚拟机,输入命令:ifconfig 查看iP和端口号,端口号一般为:22 2.打开Xshell(先安装好),连接虚拟机(根据iP和端口号) 若连接成功,Xshell则会显示虚拟机的ip和端口号 ...

  6. 《疯狂Java讲义第4版》PDF+代码+课件 电子书pdf 分享

    <疯狂Java讲义(第4版)>是<疯狂Java讲义>的第4版,第4版保持了前3版系统.全面.讲解浅显.细致的特性,全面新增介绍了Java 9的新特性. <疯狂Java讲义 ...

  7. VC windows 多网卡情况下 获取当前网卡ip地址

    参考 代码如下 记录下以后用得到或者能帮到有需要的朋友 #include <iostream> #include <WinSock2.h> #include <Iphlp ...

  8. VBA工程密码破解

    如何破解VBA密码呢? ​ 见过网上很多关于破解VBA工程密码的方式,最常见的如下这种,但其实对于很多版本是不可行的. 基本都会提示“请先对VBA编码设置一个保护密码...” Sub VBAPassw ...

  9. spring boot 整合freemaker

    前端最好使用vue.js 这里是freemaker 整合spring boot 1.编写pom文件: <dependencies> <dependency> <group ...

  10. 1041 考试座位号 (15 分)C语言

    每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考 ...