Wrappers, DAL and Pub/Sub

Basically, I get to learn new concepts and terms everyday at Tong Hin.

Last week, I got to know what DAL, Pub/Sub and decoupling mean.

I also got exposed to the reason why Wrappers are used instead of ViewModels. The reason is that Wrappers are used to hide the complexity of ViewModels and WrapperServices are used to hide the complexity of Wrappers. Such that programmers get access to the codings they need without having the need to go through the complexity that lies underneath the functions they are using.

Data Access Layer (DAL) is an interface which simplifies and gives access to data stored in persistent storage, it returns a reference to an object instead of returning a row of fields from the database. DAL is used to call methods such as insert, update and delete from methods in the class which would return objects that contain the needed values.

Pub/Sub which is also known as Publish-Subscribe is a software messaging pattern that allows messages to be sent from publishers to users (subscribers) without them getting involved in sending the message to the subscribers. The messages are sent to channels in which these channels are responsible of retrieving the messages from the publishers and sending them to subscribers.

On the other hand, coupling is defined as the level of interdependence among two software modules, thus, decoupling is the opposite, in which it means how unconnected two modules in a software program are found to be. Two software programs or modules are said to be decoupled when a change is done in one module, the other module does not need to be changed or in other words, the other module is not affected by the change that has occurred in the other module.

Lastly, I was taught how to create tests in a better and more efficient way. Instead of using Assert, Fluent Assertion is a better alternative to be used.

That’s basically a summary of what I have been through last week.

Wait for me next week again 🙂

Disable Controls and Make Controls Read Only To Prevent Updating Altered Data in View Mode

To begin the week, I will be fixing bug in Service class by refactor small changes on implementation. My objective is changing Read() to Get() on certain variable in update method. As this variable only has existing Read function, I then added Collection<Variables> GetVariables in Repository class. Hence, I change ReadVariables() to GetVariables() for update/edit/delete and any function that will make changes on the value of this variable.

In the progress, we bump into an issue, where we still able to input despite in detail view mode. This is a serious bug, as any changes would be updated/saved when ReadyToPick is triggered. Thus, we came up with a idea after discussing the issue. I need to set all input/controls to IsReadOnly and disable them. In order to do that, I need to alter code in DetailView XAML class and add new properties in DetailViewModel class.

As an alternative, I add IsEnabled = "{Binding IsControlEnabled}" and IsReadOnly= "{Binding IsControlReadOnly}" for relevant controls. While in DetailViewModel, I introduced two properties which is IsControlEnabled with default value true and IsControlReadOnly with default value false. I then perform logic of IsControlEnabled = false and IsControlReadOnly = true under view mode, making user unable to make changes on all controls.

However, there is a grid data textbox, buttons and combo box that is not set to disable & read only simply by using above method. It happens that I need to link it to ancestor of data grid such as below:
i) IsEnabled="{Binding DataContext.IsControlEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"
ii) IsReadOnly="{Binding DataContext.IsControlReadOnly, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"


After code is altered, system user could use ReadyToPick without able to edit them in view mode. (In edit mode, user able to make changes but ReadyToPick button is disable). Hence, the bug fixed.

Mostly Database!

Last week, What have I done?

Oh yes, I was still doing the invoices module, fixed the issues related to the services and repositories files as well as created tests for the needed methods in the module. All the created tests have passed successfully.

I have also got exposed to new terms this week. Database transaction which means a unit of work carried out in a database management system. Next, a two phase commit as defined by techopedia.com is “a standardized protocol that ensures that a database commit is implementing in the situation where a commit operation must be broken into two separate parts”. Last concept, Concurrency in database that is known as the ability to control data being saved into the database during a concurrent execution, as in two users saving information on the database at the same time.

Concurrency has two types called optimistic and pessimistic. Optimistic concurrency involves the logic of users being informed when a change is being made to a data in the database, and whether they wish to continue with the changes being made, or in the case of different parts of data being changed, both changes gets updated into the database. Pessimistic concurrency revolves around the idea of initiating a lock or a read-only feature, that is activated when one user is making a change such that other users cannot make a change at the same time. Entity Framework implements the logic of Optimistic concurrency.

Aside from new terms and concepts, I was introduced to data migration from visual studio to database. The entities defined in visual studio were created into the database by using the concept of data migration using Package Manager Console in visual studio.

Finally, I started designing the invoice detail view and binding the commands to the correct view model context.

See you all next week again 😀

Fix Overall Bug in Repository and View Model Class

First and foremost, I start the week by removing duplicate integrations tests. Then, fix failure tests on repository test class as all of it failed. It is fix by adding test_server config.xml file to map towards database. However, few tests on UOM (unit of measurement) failed. As the test class is testing actual database tests. Direct initialization is required to ensure function run throw the references, variable able to reach and store directed value.

Next, I have problem with state machine in the system. Upon deletion of selected data, the system would prompt error of state machine. State.DeleteTrigger() is not implemented to go to correct state next. Thus, the only way is to remove State.DeleteTrigger(). By removing State.DeleteTrigger(), the state machine would move from State.SelectedTrigger() to State.DeselectTrigger(), which is logical flow as mapped in State Machine class.

Repository class only handles database code which is CRUD command towards database. Thus, move business logic that wrongly implemented in repository class to Wrapper Service/View Model class. After moving those logic away from repository class, the code in repository is more tidy.

Last but not least, I find it weird that system does not prompt error under a concurrency situation when It suppose to. I ran through the system once and I found out problem occurs at my status checker from last week’s implementation. The value of _selectedStatus is set to SelectedStatus.Normal, which will constantly get latest data to update the list before I save any changes.

if (_selectedStatus == SelectedStatus.Normal)
{
_selectedStatus = SelectedStatus.Selected;
_eventAggregator.GetEvent().Publish(id); //Get Latest Data
}


Hence, database update is smooth as if there is no concurrency situation. But it will make user think they did not make any changes, if both before and after value appears to be the same. To solve this, I define _selectedStatus == SelectedStatus.Selected before I request to save changes upon editing selected data, so that it does not pass through get latest data event.

Guess What

Heyyyy, it’s me again and this week, I’ve come with new things to share with you all!

Well, I would say that my performance this week was way better than last week. Just imagine, during the first week, when I used to look at the pile of codes and scroll through them, my head spins and I start seeing things in two, hahahahaha, okay I’m exaggerating, but honestly, it was so much to swallow and understand especially with the fact that this is my first time to literally get exposed to these things, everything is brand new to me.

Firstly, I tried to use input binding in resource dictionary but still couldn’t do it, because the problem was raising from the data context, the resource dictionary was not able to get access to the data context of the file which contains the definition of the commands. Then, I tried using the data context concept but still no success. So, I asked my supervisor to move on, yes I did told him that, because I was already losing interest in doing the same thing over and over again. So, I was asked to write a test for the Escape key, well I would say that I only managed to do 50% of the task, I also learnt the difference between Setup and Verify when using Moqs.

Before having a look at the difference between Setup and Verify, a simple definition that can be given to Moqs is that they are objects which mimic or copy the behavior of a class or an interface and allows methods in the test to interact with them as if they were real. Hence, Setups are usually associated with the fact that we set a method and invoke a return that we expect to be returned when the method has been set up or initiated. On the other hand, verify deals with the concept of ensuring that a certain method gets invoked when the requirements are fulfilled, such that we want to verify that when method A is invoked B should be returned, if B is not returned hence our test fails. Unfortunately, the test I wrote was only for checking whether the command gets executed or not, but not whether the escape key was pressed, because the definition of the key was written in the .xaml file not the .cs file.

Next, I was given a new task, in which I had to create a module for invoices which is related to a system being created. I’ve also updated my dictionary of definitions, so initially I had the idea that data context meant giving access to the data in other classes when in reality it means a network connection created among data points in files. I have also learnt that the .sample files extension in projects are not supposed to be deleted but to be kept and used for references.

Lastly, I have also created tests to test the data being saved into the database. Basically, the tests I wrote were to ensure that the data types assigned to each attribute is correct and is the data type required, meaning a test method is written to check whether the attribute name is assigned a string data type, if the name is not assigned to string then the test fails, because the actual and expected data types are not the same.

Basically, that’s a summary of all what I did, see you all again next week. Make sure you read my upcoming blog, which is surely to be filled with new things to learn 🙂

Status Checker To Control System Flow

As we have more implementation in our ongoing project, more and more criteria we need to take care in our system. That includes business logic, flexibility of system, and system flow. Our topic is about managing system flow.

As what you should know, I am implementing function to getItemData() everytime I select an item in list. However, when I select an item, it trigger selected event that would call event1, which event1 would call selected event, forming an infinite loop. I then figure out some idea to handle this situation as I saw my supervisor’s existing code implementation.

To achieve my my implementation, I have to add a custom status checker to control the flow of system. Below are code for my status checker:
private enum SelectedStatus
{
Normal,
Selected,
}

private SelectedStatus _selectedStatus = SelectedStatus.Normal; //declare default value of SelectedStatus

public void SelectedEvent
{
if (_selectedStatus == SelectedStatus.Normal)
{
_selectedStatus = SelectedStatus.Selected;
_eventAggregator.GetEvent().Publish(id); //call event1 that cause loop
}
else
{
//logic//
_selectedStatus = SelectedStatus.Normal;
}

}

When Event1 callback to current function, _selectedStatus would now be SelectedStatus.Selected and will not publish another event to cause infinite loop. At the same time, I am able to get latest item data each time I select the data. My intention of getting latest item data is to ensure I can update data changes and minimize concurrency situation.

In future, if there is more features to add on, we can always add few more variable in SelectedStatus. This way, It provide more alternative for us to control/restrict our system flow.

Fresh start!

My first week have just passed at Tong Hin and all what I can say is, it is a new experience for me.

The first week wasn’t easy, I was exposed to many areas I have never encountered before or heard about, but honestly, it is a great experience to explore more and get to learn new things especially with the guidance and help of my supervisor.

I got exposed to Bitbucket, Sourcetree, and Dropbox. I got to know that Bitbucket and Sourcetree are alternatives that can be used instead of GitHub.

Creating stashes was also something I got to learn, in which you can save changes that have been made to the codes and apply them again after some time.

InputBindings is used to bind an input to a command or invoke a command upon input given by the user. The input can be given from the keyboard or mouse gestures. However, the focus should be adjusted in which the application is set to have an area of focus where the command is executed depending on the area where the user gesture is detected.

Delegate Commands are part of the interface ICommand, in which the delegate commands are used to invoke methods that are assigned to commands when the command’s execute and canExecute methods are called.

Next I was introduced to converting ICommands to become delegate commands and using multiple views into another view. In other words, to use methods in a class in another class.

Resource dictionary are XAML files that can be reused across the application without the need of writing the same code over and over again. With resource dictionary, referencing to the XAML will allow the class or the view class to get access to that part of the code. However, I was having trouble using the Inputbindings method into the resource dictionary, because the dictionary is not able to recognize the function.

Basically, for this week I was able to use the Escape key to open dialogues, and the dialogue displayed uses the cancelDialogueView as well as I was able to create a resource dictionary which needs adjustments to be made next week.

Hopefully by next week I would be able to accomplish more and learn more to share it with you guys, see you all on my blog next week 🙂