Monday, January 27, 2014

Sitecore Logging for 6.5 and Up: Blank Log Entries



Always reference the assembly, Sitecore.Logging.dll, instead of log4net.dll but still call "using log4net" in your code since this entire namespace in within Sitecore.Logging.dll.

The "using" is referring to a namespace and not an assembly name.

If you don't do this, custom log files and appenders will always have blank entries written.

Solr Setup and Index Creation

Keep in mind this is for an older version of Solr and Tomcat so make all necessary modifications to get your versions to work.



SOLR SETUP PROCESS
==================

1) Download and Install Tomcat 7.0 32bit
Download the .EXE installer file and install

The installation process should prompt you for an administrator username and password to configure Tomcat.  If more users need to be added in the future, refer to the config file here:
C:\Program Files\Apache Software Foundation\Tomcat7.0\conf\tomcat-users.xml


2) Run Tomcat as Windows Service
Control Panel > System and Security > Administrative Tools > Services

Make sure "Apache Tomcat 7" is running. Set it to start automatically (Properties -> Startup type: Automatic)


3) Download Solr
Download version 3.5.0
Unzip files to any location

From this unzipped folder, copy everything from
\example\solr\
to:
C:\solr\

This is where all the configuration and index files will reside

Also check that Java 1.6 or greater is already installed.

4) Install Solr
Look at the unzipped folder from above step.  Locate file:
apache-solr*.war
and copy into the Tomcat webapps folder:
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\
Rename file to solr.war
If Tomcat Windows Service is running, then folder solr will be created automatically

5) Configure Solr to run on Tomcat
Start -> All Programs > Apache Tomcat 7.0 > Configure Tomcat (Right-click, run as administrator)
Hightlight Java tab
Add "-Dsolr.solr.home=C:\solr" to Java Options
This tells Tomcat where to find config files for Solr

6) Edit Solr config properties to use DataImport for SQL Server
Edit C:\solr\solrconfig.xml
Add new request handler:

----------- 
<!-- DataImporter -->
  <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="config">data-config.xml</str>
    </lst>
  </requestHandler>
------------

Create new file "data-config.xml" in the same folder

Datasource type is jdbcdatasource
Driver is com.microsoft.sqlserver.jdbc.SQLServerDriver
Url format is jdbc:sqlserver://jhopkins;databaseName=jhucc

Also check to make sure the dataimport jar file(s) are in Tomcat:
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\solr\WEB-INF\lib\apache-solr-dataimporthandler*.jar

If not, copy them there and get them from the zip file in the dist folder

7) Install SQL Server JDBC driver

Run the downloaded installer and you will be prompted to unzip the files to a location. 
Unzip to any location.

In the unzipped folder look for \sqljdbc_3.0\enu\sqljdbc4.jar and copy to:

c:\Program files\Apache Software Foundation\Tomcat 7.0\lib\

8) Use pre-made config files.  These include index schema definitions.
Get config files from website solution:
\solr\3.5.0\conf\
and drop into C:\solr\conf\


At this point Tomcat and Solr should be set up:

Verify by browsing to http://localhost:8080/solr (or whichever port you designated upon installation) and see a welcome message and a link to admin

If dataimport is set up correctly with queries used to import data for indexes, browsing to http://localhost:8080/solr/admin/dataimport.jsp should also work without errors




INDEX CREATION AND AUTOMATION SETUP PROCESS
===========================================

1) Copy the cURL .EXE from the website solution:
\lib\curl\

into:
C:\curl\

2) Create a Windows Scheduled Task that runs every 15 minutes and have it start the application:




Tuesday, January 21, 2014

Sitecore UI Ribbons and Buttons

This is the beauty of Sitecore.  You can modify and customize anything you want, from the built-in controls to the UI environment.  If you have ever wondered how you can modify the ribbon on top, here it is.



The ribbon configurations and settings reside on the core database.

First, let’s understand all the parts of a Sitecore UI ribbon.  The group of all the buttons along with the tabbed menu on the top of the UI makes a ribbon.

There is currently a default Ribbon set up here:

/sitecore/content/Applications/Content Editor/Ribbons/Ribbons

If you look at all the child items here, you will see they correspond to each of the tabs on the top.

Each of the tabs reference a strip.  A strip is a tab which contains sets of buttons.  If you check out each of the referenced strips, they all reside here:

/sitecore/content/Applications/Content Editor/Ribbons/Strips

Each of the strips have child items.  These child items are called chunks.  They are the set of buttons that appear when the tab is highlighted.  All chunks are located here:

/sitecore/content/Applications/Content Editor/Ribbons/Chunks

The child items of the chunks are the actual buttons.
  
Creating a button is very straightforward and is easiest to duplicate an existing one and then modifying it.  You can choose from large or small buttons and even choose your own icon.  The most important field in this template is the "Click" field.  This is where you set the Sitecore command that gets fired when the button is clicked.  This command must be equivalent to a command that is stored in the commands.config file. For example:

<command name="contenteditor:DoCoolStuff" type="Namespace.ProjectAssembly.Commands.DoCoolStuff,Christies.Sitecore" />

The type is a custom class and the assembly that contains the class.  The custom class inherits from the Sitecore Command class object and this must be the format followed to create commands for buttons.  Basically, there must be an overridden Execute method that accepts a context parameter.  This parameter input tells the command what the current item is in the content editor that is being edited.  This method is where all the work is done so please put all your logic in here.  With this context item, you can determine which strips and/or chunks to hide/show.  The QueryState method does exactly that.  If the button is always visible then you do not need this method. 

Tuesday, January 14, 2014

SQL Connections: Opening and Closing Properly

Bad:

SqlConnection cnn = new SqlConnection();


cnn.Open();
ds = new System.Data.DataSet();
da.Fill(ds);
cnn.Close();

This does not ensure that cnn will get closed if da.Fill(ds) fails.

Good:
      
       SqlConnection cnn = new SqlConnection();


       try
       {
            cnn.Open();
            ds = new System.Data.DataSet();
            da.Fill(ds);
        }
        catch
        {
            throw new Exception("Failed");
        }
        finally
        {
            if (cnn != null)
                cnn.Close();
        }


This example shows that even if things go bad, the connection will always close when exiting.

Better:


       using (SqlConnection cnn = new SqlConnection())


       {
            cnn.Open();
            ds = new System.Data.DataSet();
            da.Fill(ds);
        }
       
Since SqlConnection inherits from IDisposable, the using notataion self-disposes when it is not needed so connection will always be closed at the end.