Monday, February 15, 2010

Insert containers into container

A short note about the difference between inserting and adding containers to a container.

If we use += operator to add new containers to a container, they will be added as a consequence of usual values (plainly).


static void SisTestContainer(Args _args)
{
    container   c;
    container   pair;
    int         i;
    ;
    pair = [1, "first"];
    c += pair;
    pair = [2, "second"];
    c += pair;
    pair = [3, "third"];
    c += pair;

    infoLog.add(Exception::Info, strfmt("conlen %1", conlen(c)));
    
    for (i = 0; i<= conLen(c);i++)
    {
        pair = conPeek(c, i);
        infoLOg.add(Exception::Info, strfmt("%1; %2", conpeek(pair,1),conpeek(pair,2)));
    }

Output:

Message (16:25:24)
conlen 6
0; 0
1; 0
first; 0
2; 0
second; 0
3; 0
third; 0


If we use conins() operator, new containers will be added as containers (structured by pairs).


static void SisTestContainer(Args _args)
{
    container   c;
    container   pair;
    int         i;
    ;
    pair = [1, "first"];
    c = conins(c, 1, pair);
    pair = [2, "second"];
    c = conins(c, 2, pair);
    pair = [3, "third"];
    c = conins(c, 3, pair);
    
    infoLog.add(Exception::Info, strfmt("conlen %1", conlen(c)));

    for (i = 1; i<= conLen(c); i++)
    {
        pair = conPeek(c, i);
        infoLOg.add(Exception::Info, strfmt("%1; %2", conpeek(pair,1),conpeek(pair,2)));
    }

Output:

Message (16:10:17)
conlen 3
1; first
2; second
3; third



P.S.: as Dron AKA andy mentioned, the following syntax does the same:

c += [pair];

Tuesday, February 9, 2010

Error 1075: The dependency service does not exist or has been marked for deletion

I do not know why but my Microsoft Windows Server 2003 SP2 unexpectedly refused to restart AOS instance. It gave the error:

Error 1075: The dependency service does not exist or has been marked for deletion.

It is strange because the only thing in the dependcies was Remote Procedure Call (RPC). No events in the logs.

I deinstall the AOS instance and re-install it  with SP2 right away with the same settings without restarting the server. Now it starts fine.

Monday, February 8, 2010

Error: Multiple calls to CodeAccessPermission.Assert

Multiple calls to CodeAccessPermission.Assert
(S)\Classes\SkipAOSValidationPermission\assert
(S)\Classes\BatchRun\runJob - line 166
(S)\Classes\BatchRun\do - line 54
(C)\Forms\BatchRun\Methods\doBatch - line 18

Sometimes I got this error while working with Change based alerts batch processing. After that the status of the related job in batch list changed to Executing, and the only way to get rid of it was deleting that job.


This issue arises in [Classes]BatchRun.runJob method because of absence of closing revertAssert() method in case of exceptions after calling runas() method.

So, my solution is to comment the existing call of revertAssert()...

if (batchClass.runsImpersonated())
        {
            // Ok to assert here because the user name comes from
            // the batch table
            runAsPermission = new RunAsPermission(batch.CreatedBy);
            runAsPermission.assert();
            // BP Deviation Documented
            runas(batch.CreatedBy,
                classnum(BatchRun),
                staticmethodstr(BatchRun, runJobStatic),
                [batchId]);

           // Alexey Voytsekhovskiy (SIS) (2010/02/08) (Demande #0074)
           // CodeAccessPermission::revertAssert();
        }
        else
        {
            BatchRun::runJobStatic([batchId]);
        }

and move it after catching all kind of exceptions:


catch (Exception::UpdateConflictNotRecovered)
    {
        isErrorCaught   = true;
        exception       = Exception::UpdateConflictNotRecovered;
    }

    // Alexey Voytsekhovskiy (SIS) (2010/02/08) (Demande #0074)
    // in case of exception Permssion should be revert anyway!!
    CodeAccessPermission::revertAssert();

It allows to avoid multiple calls to CodeAccessPermission.Assert (there is another call far in this method) and see the log of the job ended with an error.


By the way, here is a short and sweet trick with multiple calls if needed.