Thursday, October 15, 2015

RAM DISK

Recently i moved from a HDD to a SDD the results are fantastic. I now boot my windows in less than 20 seconds. This led me to investigate further on SDD drives and understand what else can i do to have a good performance with my laptop (and obsessed i am with performance).

The first thing i understood is that to have a good life for the SSD we should try and limit the no of reads and write. Once of the potentials areas where this can be limited in the temp work folder for windows and internet explorer.

The solution is to create a RAM disk and move the temp contents to this disk. Obviously this would also mean that we will have to find a solution to persist the contents of the RAM Disk which otherwise looses its contents on a restart.

I landed on an application call imdisk which is a freeware and does the job pretty well. Along with imdisk we need a utility called rawcopy to store the contents of this disk on a shutdown. The right solution would be to automate the two events, for this we would need two batch files in windows called shutdown and startup respectively. The details of these files are as follows:-

contents of the shutdown batch file
C:\RAMDISK\rawcopy.exe -mld \\.\R: "C:\RAMDISK\RDrive.img"

contents of the startup batch file
imdisk -a -t vm -f C:\ramdisk\rdrive.img -m R:

These files can be scheduled either using the windows task scheduler. Alternatively an entry can be made in the group policy (gpedit.msc) under
Local Computer Policy -> Computer Configuration -> Windows Settings -> Scripts

Double click on Startup or Shutdown applets on the right pane and add the batch files therein.



Thursday, October 01, 2015

XDS MyConstruct

My construct is a pattern used to implement record level security when the business logic to implement the restriction is not straight forward.

Eg. We had a requirement at a customer where the HR wanted the records to be restricted as per the position hierarchy. So if a manager logs in he should be able to see managers reporting to him and any subordinates below these managers.

The answer to the above problem is to implement the My construct pattern for security. My Construct uses temporary tables of type TempDB which are populated using a table method called XDS().  This method is available for developers to write X++ logic to populate the temporary table. After the temporary table is populated, subsequent policy queries can use this temporary table.

In MyConstructs, we have the ability to refresh the data either PerSession or PerInvocation.

Below is the code for an overridden XDS method of a table

public RefreshFrequency xds()
{
    SPYMYSubordinate                mySubordinate;
    List                            workerList = new List(Types::Int64);
    ListEnumerator                  workerListEnumerator;
    HcmEmployment                   hcmEmployment;

    List subordinate(HcmWorkerRecId _worker,List _workerList)
    {
        HcmPositionHierarchy            positionHierarchy;
        HcmPositionWorkerAssignment     positionWorkerAssignment;

        _workerList.addEnd(_worker);
        while select positionWorkerAssignment join positionHierarchy
            where positionWorkerAssignment.Position == positionHierarchy.Position &&
                  positionHierarchy.ParentPosition == HcmWorker::getPrimaryPosition(_worker) &&
                  positionHierarchy.PositionHierarchyType == HcmPositionHierarchyType::lineHierarchyType()
            join hcmEmployment
            where hcmEmployment.Worker == positionWorkerAssignment.Worker
        {
            _workerlist = subordinate(positionWorkerAssignment.Worker,_workerlist);
        }
        return _workerlist;
    }

    workerList = subordinate(currentWorker(),workerList);
    workerListEnumerator = workerList.getEnumerator();
    while(workerListEnumerator.moveNext())
    {
        mySubordinate.Worker = workerListEnumerator.current();
        mySubordinate.insert();
    }

    return RefreshFrequency::PerSession;
}