Showing posts with label mscrm. Show all posts
Showing posts with label mscrm. Show all posts

Friday, January 27, 2012

Removing Strong Name from .NET assembly

First in 10+ years of .net practice I had to solve removing the strong name from the assembly and recompiling it after the export with Reflector.

The need for that was caused by customer’s extra security/audit requirements which could not be satisfied through a standard extensibility in MS CRM 3.0. And let us say MS CRM 3.0 is a very old lady now, so one can hardly expect year 2005 code to meet year 2012 security standards.

I found two solutions over the web:

http://blog.fredrikhaglund.se/blog/2009/02/06/how-to-patchfixhack-someone-elses-assembly/

http://www.codeproject.com/Articles/15374/Removing-Strong-Signing-from-assemblies-at-file-le

I was happy I didn’t have to resort to a second one – quite heavier weight for what I needed. First one worked as a charm.

By the way  I tried side by side latest .NET reflector from Red Gate with the last not expired version of original Reflector and should say that I didn’t notice any value added in Red Gate’s version. Nothing to advocate a sudden price tag and 1+ year of ownership, SHAME!

As for decompile and recompile of a CRM assembly in question, just few issues I ran into:

Compiler limit exceeded: Line cannot exceed 2046 characters (CS1034) - C:\CRM\PROJECTS\components.core\Microsoft\Crm\SystemCustomization\Security.cs:31,2046

That was solved easily with splitting the line into several instructions.

Microsoft.Crm.CalendarUtil:

Operator '>=' cannot be applied to operands of type 'System.DayOfWeek' and 'int' (CS0019) - C:\CRM\PROJECTS\components.core\Microsoft\Crm\CalendarUtil.cs:157,17

Corrected version of a method would look like (trick is in casting the enums to int):

public static DateTime GetFirstDayInCalendar(DateTime date)
{
    date = new DateTime(date.Year, date.Month, 1, 0, 0, 0);
    int weekStartDayCode = OrganizationSettings.Current.WeekStartDayCode;
    if ((int)date.DayOfWeek >= weekStartDayCode)
    {
        return date.AddDays((double) (((int)date.DayOfWeek - weekStartDayCode) * ~(int)DayOfWeek.Sunday));
    }
    return date.AddDays((double) ((((int)date.DayOfWeek + 7) - weekStartDayCode) * ~(int)DayOfWeek.Sunday));
}

And again, always something to learn! I was really puzzled with that tilda operator in front of DayOfWeek.Sunday so was glad to learn about it: http://stackoverflow.com/questions/387424/what-is-the-tilde-in-a-c-sharp-enumeration

This is it. Hope my positive experience will ease your decisions once you stay in front of a similar task!

Friday, September 30, 2011

MSCRM – User privileges/access rights “report” script

This is again about MSCRM 3.0 and not sure that would be the same with higher versions. Without further ado, here it is:

A script corresponds to the scenario/constraints I currently face, so in your case you might need to tweak it.

select distinct
    'Right' = case 
    WHEN pb.AccessRight = 1 THEN 'Read'
    WHEN pb.AccessRight = 2 THEN 'Write'
    WHEN pb.AccessRight = 4 THEN 'Append'
    WHEN pb.AccessRight = 16 THEN 'Append To'
    WHEN pb.AccessRight = 32 THEN 'Create'
    WHEN pb.AccessRight = 65536 THEN 'Delete'
    WHEN pb.AccessRight = 262144 THEN 'Share'
    WHEN pb.AccessRight = 524288 THEN 'Assign'
    end, 
 rb.Name, 
    'Scope' = case 
    WHEN rp.PrivilegeDepthMask = 1 THEN 'Own Only'
    WHEN rp.PrivilegeDepthMask = 2 THEN 'Business Unit'
    WHEN rp.PrivilegeDepthMask = 4 THEN 'Parent->Child'        
    WHEN rp.PrivilegeDepthMask = 8 THEN 'Organization'
    WHEN rp.PrivilegeDepthMask = 16 THEN 'Own Only - Inherited'
    WHEN rp.PrivilegeDepthMask = 32 THEN 'Business Unit - Inherited'
    WHEN rp.PrivilegeDepthMask = 64 THEN 'Parent->Child - Inherited'
    WHEN rp.PrivilegeDepthMask = 128 THEN 'Organization - Inherited'
    ELSE cast(rp.PrivilegeDepthMask as varchar(10))
    end,
    pb.Name
    --rp.PrivilegeDepthMask, pb.AccessRight, bub.Name --,*
    from PrivilegeBase pb
    join RolePrivileges rp on rp.PrivilegeId = pb.PrivilegeId
    join RoleBase rb on rb.RoleId = rp.RoleId
    join BusinessUnitBase bub on bub.BusinessUnitId = rb.BusinessUnitId
 
    where pb.Name like '%activity' and rp.PrivilegeDepthMask NOT IN (16, 32, 64, 128)
    order by pb.Name, rb.Name --, bub.Name

Few notes.

PrivilegeDepthMask of 16 and 128 is x*2^4, what happens (as I believe) when privilege is inherited from the organization level role to a business unit (I might be wrong, better verify yourself :). In my case inherited privileges are always the same, that’s why that rp.PrivilegeDepthMask NOT IN (16, 128) at the end. I also filter by entity name in a hacky way, you might want to join entities table/view in your case.

This is it.

Links:
http://mscrmking.blogspot.com/2010/10/explination-of-accessright-and.html

[Update: 13-Oct-2011, script updated with parent to child scenarios]

Wednesday, August 31, 2011

MSCRM – Relationships review helper script

Here is a tiny sample script to see all MS CRM relationships in one place and with nice attribute/entities names:

SELECT    r.Name as "RefName", e1.Name as "fromEntity", a1.Name as "fromAttr", e2.Name as "toEntity", a2.Name as "toAttr", 
        r.RelationshipType, r.IsLogical, r.CascadeDelete, r.CascadeAssign, r.CascadeShare,
        r.IsCustomRelationship
    FROM  [dbo].[Relationship] r
    JOIN  [dbo].[Entity] e1 ON e1.EntityId = r.ReferencingEntityId
    JOIN [dbo].[Entity] e2 ON e2.EntityId = r.ReferencedEntityId
    JOIN dbo.Attribute a1 ON r.ReferencingAttributeId = a1.AttributeId
    JOIN dbo.Attribute a2 ON r.ReferencedAttributeId = a2.AttributeId
    
    WHERE e1.EntityId IN (SELECT EntityId
        FROM [dbo].[Entity]
        WHERE Name in 
            ('Lead', 'V2_contract', 'Account', 'Email', 'V2_incidenthistory', 
            'SystemUserLicenses', 'QuoteClose', 'BulkOperation', 'V2_technicalspec'))
            OR 
            e2.EntityId IN (SELECT EntityId
        FROM [dbo].[Entity]
        WHERE Name in 
            ('Lead', 'V2_contract', 'Account', 'Email', 'V2_incidenthistory', 
            'SystemUserLicenses', 'QuoteClose', 'BulkOperation', 'V2_technicalspec'))
    ORDER BY "fromEntity", "fromAttr"
 

Change the entity names in the filter to what you need or delete it altogether. To be executed on the MSCRM metabase DB. Hope might save someone a minute :).

Wednesday, August 10, 2011

MS CRM IFrame request parameters – the look and helper code

Providing for the joy of sharing itself. This is for MS CRM 3.0 and I hope no one really works with it now except for myself :). This is what is being sent when you check the box to send the type and entity id:

image

And here goes the helper code (client-side only) for it:

   1: <p id="debug">
   2:  
   3: </p>
   4:  
   5: <script type="text/javascript">
   6:  
   7:     function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for (var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; }
   8:  
   9:     var urlVars = getUrlVars()
  10:     for (rp in urlVars) {
  11:         $('#debug').append(rp + ":" + urlVars[rp] + "</br>")
  12:     }

Yours, Stan.