Archive for February, 2008

20
Feb
08

BlackPearl Web Forms Workflow..

K2 (www.k2.com) is one of the pioneer companies in developing business process management (BPM) solutions. Microsoft products are by heart the foundation of K2 workflow platform. Including .NET 3.0, WWF, WPF, and MOSS 2007. Here, I will demonstrate a very basic walkthrough scenario on using K2BP workflow engine through ASPX pages.

The Scenario

Our walkthough scenario is an approval request for a general message generated by an employee. The employee will submit the form and the manager will either approve or reject it. Finally, the originator “employee” will get a copy of the submitted form.

The Solution

First, we need to build a new empty project from VS2005 File->New. Let’s name it “BasicApproval

Create New Project

From the Solution Explorer, add a new process from the New Item context menu.

Add K2 Process

Choose “process” and name it “BasicApprovalProcess.kprx“. Now, Let’s build and design our form that will represent the BasicApproval wrokflow. Basically, we will need three forms to fulfill the process requirements.

  1. BasicRequest.aspx: The first form that will initiate the process and the employee will create a new process instance from it.
  2. BasicApproval.aspx: The second form the will be passed to the originator’s manager. The manager will either approve or reject the request.
  3. BasicApprovalEnd.aspx: The last form that will notify the user of the request result.

Before getting into developing these forms, we need to configure two things. Adding new SourceCode reference and ASPX control. First, right click on the Web Project Icon -> Add Reference -> .NET -> “SourceCode.Workflow.Client”

k2bp6.jpg

The second thing is to add the ASPX Control form K2 BlackMarket (www.k2underground.com). Right click on the VS2005 toolbox -> Choose Items -> .NET Framework Components -> Browse -> Choose the downloaded DLL file “blackpearl.web.controls.dll” and then click OK. Here is the result:

k2bp7.jpg

It’s time to develop the ASPX forms, each page contains the following controls:

  • Subject Textbox: “subject”
  • Message Textbox: “message”

BasicRequest.aspx

We need only to add the submit button “K2Submit” to look like this:

BasicRequest.aspx

Afterwards, add the following code to the submit button’s click event “remember, the code attached is inlined within ASPX tags.”:

k2bp3.jpg

BasicApproval.aspx

Copy and paste the old web form and rename it to “BasicApproval.aspx“. Delete the submit button and replace it with the ASPX Control that we’ve added earlier. Rename the ASPX control to “submit” and check the control’s properties to meet the following:

k2bp8.jpg

Now, let’s us load the workflow data fields according to the workflow item’s serial key.

k2bp9.jpg

Add the following code to the “K2Submit_LoadFields” event:

k2bp11.jpg

BasicApprovalEnd.aspx

This form is identical to the “BasicApproval.aspx” form.

It’s show time now!

The earlier steps are very common for any .NET/ASPX developer. From now on, it’s gonna be nasty and really operative. We’ll publish those forms to a web server through FTP “Even that FTP is not secure, I still love it! since you are not concerned about having Front Page Extensions on the target machine”. Then, we are going to design the BasicApprovalProcess in K2 Designer. Afterwards, we will deploy the process and initiate the process as per our plan.

Before you deploy the web forms, you should enable the “identity impersonate” in the web.config as follows:

k2bp12.jpg

Don’t forget to deploy/copy the “blackpearl.web.controls.dll” to the bin folder in the target website directory path.

Designing the Process

Let’s get back to our K2 Project. Drop two “Default Client Events” into the designer workspace. Here’s the result:

k2bp13.jpg

Activity Configuration

BasicApproval .aspx

Web Form Name: http://ServerName/BasicApproval.aspx

Configure Actions: Add new action, name it “Approval Request”

k2bp14.jpg

Configure Outcomes as following and click Finish.

k2bp15.jpg

BasicApprovalEnd.aspx

Let’s do the same with this activity according to the following:

  • Configure Actions: Name (http://ServerName/BasicApprovalEnd.aspx), Actions: Task Completed
  • Configure Outcomes: Task Completed

Connecting the activities

Now, connect the Start Activity to BasicApproval.aspx Activity (Hold the Ctrl + drag the Start Activity to the BasicApproval.aspx Activity). Also, do the same to the BasicApproval.aspx and BasicApprovalEnd.aspx activities.

k2bp16.jpg

Defining the Data Fields

To map our fields in our web forms, we have to define them first in the K2 Data Fields. From the project workspace (I know that sometimes I use Java terminologies in .NET environment..), view -> K2 Object Browser -> Data Fields -> BasicApprovalProcess -> right click and “Add” -> create the two fields as string “subject” and “message“.

k2bp17.jpg

I guess that we’re ready now to deploy and test the process. Right click on the Solution’s Name “BasicApproval” and choose Deploy. As I always do, click Finish directly in the deployment wizard…

Testing the process

The testing process will start by creating a new instance using the first web form “BasicRequest.aspx”. After that, a work item should be created for the destination user, K2 Workspace can view and operate all these information. The second step is to proceed the process and approve the work item “BasicApproval.aspx“, last thing is to check the returned result “BasicApprovalEnd.aspx“.

k2bp18.jpg

After you submit the form, check the work item flow from the “View Flow” option in Work Item Context Menu in the K2 Workspace

k2bp23.jpg

k2bp21.jpg

Now, let’s Submit and Approve the “BasicApproval.aspx” form.

k2bp20.jpg

The worklist should be updated to reflect the latest activity in the process.
k2bp22.jpg

Last Form to submit is “BasicApprovalEnd.aspx

k2bp24.jpg

Let’s check the process flow after completing all activities.

k2bp25.jpg

Conclusion

K2BP is a helluva BPM solution!. I’ve only scratched the basics of developing, deploying and testing a very simplified workflow process. K2BP can extend these capabilities to integrate with Microsoft Exchange, Office, InfoPath, BizTalk, LCS, Visio and SharePoint.

17
Feb
08

You wanna make a memory!

Aha, I guess it’s kinda nice coincidence! Me and Bon Jovi, one of my favorite songs “(You want to) Make A Memory”. And from my perspective, I really want to make such a thing!

Before diving into memory mysteries, here are few things that need to be clarified. I will start out stating the basic terms in memory management. In MM world, we care most about the Virtual Memory. VM is a virtual and contagious range of memory addresses. In turn, it simplifies working with the Real or Physical Memory. It also extends the PR “Physical RAM” space by using the existing disk space “Paging”. So, the program will deal with a very simplified, optimized, and more importantly addressable version of the Physical RAM. I really should be thanking the MMU “Memory Management Unit” for making this possible.

The demand paging is usually the process of swapping the data “as pages” from disk to the RAM. This process could raise a Page Fault exception, luckily this exception is handled by the OS which will try to find an available physical page to place the faulted data. Sometimes, the OS takes long time to swap data which described as thrashing. It looks obvious that to overcome those bottlenecks you mostly need to add RAM. Have a look at the Windows Task Manager “taskmgr.exe” and add the Page Faults option from the processes tab, view menu, Select Set Columns, check the Page Faults.

Task Manager

Memory Tracing

Most likely, to trace what is going on behind the scene is pretty much tough. Though, it is interesting. The first tool that we are going to use is as previously mentioned, Windows Task Manager. The two misleading columns in the task manager are the Mem Usage and Virtual Memory Size. So, what’s the deal? Mainly, it’s not as it sounds… Mem Usage demonstrates the Working Set “Resident Set”, which means the pages that are currently in main memory and can be shared by other processes. On the other hand, VM Size is the private memory that committed by the process and can’t be shared by other processes.
A very similar but advanced tool to the WTM is the Perfmon “perfmon.msc” which resides in the Administrative Tools. Huge number of counters is adapted in this tool to provide a graphical chart of the counters’ performance. Basically, we can map the WTM attributes to this one as following:

  • Mem Usage -> Process/Working Set
  • VM Size -> Process/Private Bytes
  • Page Faults -> Process/Page Faults

The “Performance” tool can show you (the explanations were taken from the “Performance” tool):

  • Private Bytes -(Corresponds to the “VM Size” from Task Manager). A not-shareable amount of memory “in bytes ” with other processes.
  • Virtual Bytes – (Not shown in Task Manager) Virtual Bytes is the current size in bytes of the virtual address space that the process is using.
  • Working Set “Resident set” – (Corresponds to the “Mem Usage” from Task Manager) – Number of pages that are reside in physical RAM memory. These pages are available for application use without triggering a page fault. The default working set amount is 50 pages for each process, the maximum size can not exceed the system wide maximum. In 32-bit machines, the system can reach up to 2GB memory application. It can also reach up to 3GB using 3-GB user space (precisely 00000000~BFFFFFFF). Above 4GB can be mapped up using PAE (Physical Address Extension) using 36-bit physical address.

Before closing this part, I’m really eager to demystify the difference between Paged and non-paged pool. As mentioned earlier, Paging is the process of writing objects to disk. So Pool Paged is the size of bytes of writing objects to disk when those objects are not currently used. Pool non-paged is the opposite, this means that those objects can not be written to the disk and should remain in the physical memory.

Memory segmentation or linear address decomposition can be described into two parts, the segment and the offset “segment:offset form”. For example, 0AFE:0100 is a segmented address in my debug session. One of the main ideas here is to emphasize the Segment Registers in IA-32 (CS, DS, SS, ES, FS, and GS). Basically, there are three types of storage. Code “text”, data and stack segment. Code segment contains the executable instructions. Data Segment as its name suggests is a portion of memory that deals with variables “data”. Stack segment which stores the procedure stack for the program. x86 processors can operate in two execution modes. Real and protection mode. Real mode execution is limited to map up to 1MB memory space, in this way, the processor needs 20 bits of the address bus for that (2^20 = 1048576 = 1024 * 1024). In this mode, there is no address translation for the memory. And the memory interpretation is processed directly into physical memory. Protected mode execution is what we’re here about. Without this mode, there is no multitasking, memory protection, paging, V86 mode.

VAS

Reading Memory Dump

I always consider debugging one of the most challenging tasks. Especially, when it comes to memory debugging “mini-assemblers”. Sometimes I stuck in boring training labs, I don’t have a tool to give me some challenge and excitement. The best thing to do in this situation is to use the little debug.exe tool that is included in windows.
Start a Windows prompt session using debug command “debug”. And have fun!

DOS Debug

  • “r” command is used to display the contents of the register.
  • “d” can display the memory contents in both hexadecimal and ASCII.
  • “0BB3:0100″ is the memory address which includes the segment “0BB3″ and the offset “0100″
  • The next 16 bytes are the hexadecial content of each byte.
  • In the right, the ASCII representation of each byte.

Conclusion

That was a complete startup for memory management. The next parts will go deeper in how the developer or the administrator can trace and optimize memory management using debuggers and tracing tools. Stay tuned!