Wednesday, October 15, 2014

System.Uri (.NET Framework 4.5) – A Visual Guide

Since I’ve repeated enough times the somewhat cumbersome exercise of inferring what the various properties of the .NET Framework (as of version 4.5) System.Uri class return for a “typical” HTTP/HTTPS URL from the official documentation – and generally resorted to manual testing to be 100% certain of the behavior – here’s a visual guide.

Given a System.Uri instance constructed as follows (C#):

System.Uri uri = new System.Uri("https://www.example.com:8080/dir1/dir2/page.aspx?param1=val1&param2=val2#anchor");

Here’s what the various relevant properties of that Uri instance return:

Property String value
AbsoluteUri
https://www.example.com:8080/dir1/dir2/page.aspx?param1=val1&param2=val2#anchor
OriginalString
https://www.example.com:8080/dir1/dir2/page.aspx?param1=val1&param2=val2#anchor
Scheme
https
Host
        www.example.com
Authority
        www.example.com:8080
Port
                        8080
AbsolutePath
                            /dir1/dir2/page.aspx                            
PathAndQuery
                            /dir1/dir2/page.aspx?param1=val1&param2=val2
Query
                                                ?param1=val1&param2=val2
Fragment
                                                                        #anchor

The Segments property returns the following String array:

String[] {
    "/",
    "dir1/",
    "dir2/",
    "page.aspx"
}

Hopefully this will save a little time for all of you as well as for me!

Wednesday, September 10, 2014

C# – Shorten null check around foreach loops

This is another blog post filed under “So I can remember this for next time. If it helps you too, great!”

In C#, when looping over a collection where the collection object itself might be null, if the desired behavior is to just loop zero times if the collection object is null, typical code would be:

List<MyType> list = PopulateList(); // Some method that returns a List<MyType>, or null 
if (list != null) 
{ 
  foreach (MyType mt in list) 
  { 
    // Do stuff with mt... 
  }
}

Using the C# null-coalescing operator ??, the above code can be condensed to:

List<MyType> list = PopulateList(); // Some method that returns a List<MyType>, or null
foreach (MyType mt in list ?? Enumerable.Empty<MyType>) 
{ 
  // Do stuff with mt... 
}

In that second example, if list is non-null, then the foreach iterates over it as normal. If list is null, then the foreach iterates over an empty collection -- so zero iterations are performed.

Wednesday, August 06, 2014

Double-click-drag to select entire words

Here’s a quick tip on selecting text with the mouse that I’m blogging as much to help myself remember as to inform you, the reader:

You can double-click-drag – that is, double-click, and continue holding the mouse button on the 2nd click – to select multiple entire words from a block of text.  This obviates the need to position the mouse cursor exactly over the small space between words when selecting entire words or sentences, both when beginning and ending the selection.

Bonus tip: You can triple-click to select an entire line or paragraph of text.  (This one I do remember and use frequently – and get annoyed by those few applications that don’t support it.)

These tips work in most applications on both Windows and Mac.

Wednesday, March 05, 2014

Fix: CSS border-radius not working in Internet Explorer 11

In doing browser compatibility testing in a new web form I was developing on my PC this morning, the form looked great in all browsers I had on my local Windows 8.1 PC – except for Internet Explorer 11, where it looked awful: div and form field border corners were squared instead of rounded, form fields rendered with excess height, some text was slightly truncated, and a few other issues.

When I looked at the CSS styles in use on the page in IE11’s built-in F12 developer tools, I noticed that the border-radius property on my form’s enclosing div was present, but it was missing its enable/disable checkbox, and the name of the style was shown with a red squiggle underline, as though IE didn’t recognize it.  It seemed almost as though IE11 was behaving like a legacy browser that didn’t recognize that newer CSS property.

In fact, that did turn out to be exactly the problem. IE11 was rendering the form (running on my local IIS) with its legacy “Compatibility View” engine, which it is by default configured to do for intranet sites.  (Oddly, my IE11 was not using Compatibility View to render another copy of the form that I was trying to use to debug the issue that I had IE loading via the “localhost” domain, which had me confused for a while.)

The solution was to disable IE11’s Compatibility View for intranet sites by doing Setting (gear icon) > Compatibility View Settings > uncheck “Display intranet sites in Compatibility View” checkbox.  Making that configuration change immediately got IE11 to start rendering the page properly.

Tuesday, January 14, 2014

ATG BCC – “Unknown Segment ‘Main’” log error; missing menu items in left nav

This post details a problem, and its corresponding solution, that my team encountered and recently resolved in the ATG 9.3 BCC application.

Symptoms

  1. In the BCC application, in the left nav menu, several of the menu items that should be present are missing, including:
    • Content Administration | Automated Deploy
    • Content Administration | Content Administration Project
    • Merchandising | Manage Commerce Assets
    • Personalization | Targeting and Segmentation
  2. When a user successfully logs into the BCC application, lots of errors like the following are logged in the CA application’s log file: atg.process.ProcessException: Unknown segment "main" in process /Content Administration/CA.wdl at atg.process.ProcessManagerService.getSegmentInfo(ProcessManagerService.java:2122) at atg.process.ProcessManagerService.createProcessInstanceInfo(ProcessManagerService.java:11085) at atg.process.ProcessManagerService.getProcessInstanceInfos(ProcessManagerService.java:10928) ...
  3. When the CA instance is initially started, some errors like the following that mention “atg.nucleus.ServiceException” and “dynamoMessagingSystem.xml” appear in the CA application’s log file: atg.nucleus.ServiceException: Destination "sqldms:/Price/CacheInvalidation" is not found for output port "PriceCacheInvalidator" of "message-source" element with Nucleus name "/com/example/ecom/messaging/PriceCacheMessageSource" for patch bay definition file "/atg/dynamo/messaging/dynamoMessagingSystem.xml" at atg.dms.patchbay.PatchBayManager.createOutputDestination(PatchBayManager.java:1451) at atg.dms.patchbay.PatchBayManager.createOutputPorts(PatchBayManager.java:1249) ...

Solution

(This solution worked for my team’s application; YMMV.)

In one of the dynamoMessagingSystem.xml files in our project’s source code, as child elements of the patchbay XML element, there were message-source and message-sink elements (and sub-elements) that were (apparently) incorrectly defined, and also were not actually being used by the application. 

Removing those bad elements from the dynamoMessagingSystem.xml file, and then rebuilding and redeploying the application, resolved the issue.

Thanks to Miles from Oracle Support for his assistance in troubleshooting this issue!