public string GetInternalPath(string originalPath)
        {
            string path = String.Empty;

            using (LogGroup logGroup = LogGroup.StartDebug("Generating the internal path."))
            {
                if (!Skip(originalPath))
                {
                    string shortPath = GetShortPath(originalPath);

                    LogWriter.Debug("Short path: " + shortPath);

                    string fileName = Path.GetFileName(shortPath);

                    LogWriter.Debug("File name: " + fileName);

                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);

                    LogWriter.Debug("File name without extension: " + fileNameWithoutExtension);

                    string command = GetCommandName(originalPath);

                    LogWriter.Debug("Command name: " + command);

                    ProjectionFormat format = GetFormat(fileName);

                    LogWriter.Debug("Format: " + format.ToString());

                    // If the command name has a dash - in it then it's in the format of [Action]-[TypeName]
                    if (command.IndexOf("-") > -1)
                    {
                        path = GetInternalPathFromCommand(originalPath, command, format);
                    }
                    // Otherwise it's the name of the projection
                    else if (ProjectionState.Projections.Contains(command))
                    {
                        string projectionName = command;

                        path = GetInternalPathFromName(originalPath, projectionName, format);
                    }



                    LogWriter.Debug("Path: " + path);
                }
                else
                {
                    LogWriter.Debug("Skipping rewrite.");
                }
            }
            return(path);
        }
        /// <summary>
        /// Creates a raw/standard URL to the page corresponding with the specified action and entity.
        /// </summary>
        /// <param name="action">The action to be performed at the target page.</param>
        /// <param name="entity">The entity involved in the action.</param>
        /// <param name="format">The format of the target projection.</param>
        /// <returns>The URL to the page handling the provided action in relation to the provided type.</returns>
        public string CreateStandardUrl(string action, IEntity entity, ProjectionFormat format)
        {
            string link = String.Empty;

            using (LogGroup logGroup = LogGroup.StartDebug("Creating a standard URL for the specified action and provided entity type, with the specified format."))
            {
                LogWriter.Debug("Action: " + action);
                LogWriter.Debug("Entity type: " + entity.ShortTypeName);
                LogWriter.Debug("Format: " + format.ToString());

                link = ApplicationPath + "/Projector.aspx?a=" + PrepareForUrl(action) + "&t=" + PrepareForUrl(entity.ShortTypeName) + "&f=" + PrepareForUrl(format.ToString()) + "&" + PrepareForUrl(entity.ShortTypeName) + "-ID=" + PrepareForUrl(entity.ID.ToString());
                link = AddResult(link);

                LogWriter.Debug("Link: " + link);
            }
            return(link);
        }
        /// <summary>
        /// Creates a raw/standard URL to the page corresponding with the specified action and specified type.
        /// </summary>
        /// <param name="action">The action to be performed at the target page.</param>
        /// <param name="typeName">The name of the type being acted upon at the target page.</param>
        /// <param name="propertyName">The name of the property to filter the specified type by.</param>
        /// <param name="value">The value of the property to filter the specified type by.</param>
        /// <param name="format">The format of the target projection.</param>
        /// <returns>The URL to the page handling the provided action in relation to the provided type.</returns>
        public string CreateStandardUrl(string action, string typeName, string propertyName, string value, ProjectionFormat format)
        {
            string link = String.Empty;

            using (LogGroup logGroup = LogGroup.StartDebug("Creating a standard URL for the specified action and provided entity type, with the specified property name and value, as well as the specified format."))
            {
                LogWriter.Debug("Action: " + action);
                LogWriter.Debug("Type name: " + typeName);

                LogWriter.Debug("Property name: " + propertyName);
                LogWriter.Debug("Value: " + value);

                LogWriter.Debug("Format: " + format.ToString());

                link = ApplicationPath + "/Projector.aspx?a=" + PrepareForUrl(action) + "&t=" + PrepareForUrl(typeName) + "&f=" + PrepareForUrl(format.ToString()) + "&" + PrepareForUrl(typeName) + "-" + PrepareForUrl(propertyName) + "=" + PrepareForUrl(value);
                link = AddResult(link);

                LogWriter.Debug("Link: " + link);
            }
            return(link);
        }
        /// <summary>
        /// Locates the projection info for performing the specified action with the specified type.
        /// </summary>
        /// <param name="action">The action that is to be performed by the projection.</param>
        /// <param name="typeName">The short type name of the entity that is involved in the action.</param>
        /// <param name="format">The output format of the projection to locate.</param>
        /// <returns>The projection info for the specified scenario.</returns>
        public ProjectionInfo Locate(string action, string typeName, ProjectionFormat format)
        {
            // Create the projection info variable to hold the return value
            ProjectionInfo projectionInfo = null;

            using (LogGroup logGroup = LogGroup.StartDebug("Locating projection with action '" + action + "', type name '" + typeName + "', and format '" + format.ToString() + "'."))
            {
                // Get the specified type
                Type type = null;

                if (Entities.EntityState.Entities.Contains(typeName))
                {
                    type = Entities.EntityState.Entities[typeName].GetEntityType();
                }

                // Create a direct projection key for the specified type
                string key = Projections.GetProjectionKey(action, typeName, format);

                LogWriter.Debug("Key: " + key);

                // Check the direct key to see if a projection exists
                if (Projections.ContainsKey(key))
                {
                    projectionInfo = Projections.GetByKey(key);
                }
                // If not then navigate up the heirarchy looking for a matching projection
                else if (type != null)
                {
                    projectionInfo = LocateFromHeirarchy(action, type, format);
                }

                /*// If the projection wasn't found in memory then try loading it
                 * if (EnableLoading && projectionInfo == null)
                 * {
                 *      LogWriter.Debug("Projection not found in memory. Loading from file.");
                 *
                 *      projectionInfo = new ProjectionLoader().LoadInfoFromFile(
                 *              new ProjectionFileNamer().CreateInfoFilePath(action, typeName, format)
                 *      );
                 *
                 *      Projections.Add(projectionInfo);
                 * }*/

                if (projectionInfo == null)
                {
                    LogWriter.Debug("No projection found.");
                }
                else
                {
                    LogWriter.Debug("Projection found - Action: " + projectionInfo.Action + " | Type name: " + projectionInfo.TypeName + " | Title: " + projectionInfo.MenuTitle + " | Category: " + projectionInfo.MenuCategory + " | Format: " + projectionInfo.Format.ToString());
                }
            }
            return(projectionInfo);
        }
        /// <summary>
        /// Retrieves the key for the specifid action and type.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public string GetProjectionKey(string name, ProjectionFormat format)
        {
            string fullKey = name.Replace("-", "_") + "_" + format.ToString();

            return(fullKey);
        }
        /// <summary>
        /// Retrieves the key for the specifid action and type.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="type"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public string GetProjectionKey(string action, string type, ProjectionFormat format)
        {
            string fullKey = type + "_" + action + "_" + format.ToString();

            return(fullKey);
        }
        /// <summary>
        /// Creates a raw/standard URL to the page corresponding with the specified action and specified type.
        /// </summary>
        /// <param name="action">The action to be performed at the target page.</param>
        /// <param name="typeName">The name of the type being acted upon at the target page.</param>
        /// <param name="format">The format of the target projection.</param>
        /// <returns>The URL to the page handling the provided action in relation to the provided type.</returns>
        public string CreateStandardUrl(string action, string typeName, ProjectionFormat format)
        {
            string link = String.Empty;

            using (LogGroup logGroup = LogGroup.StartDebug("Creating a standard URL for the specified action and type, with the specified format."))
            {
                LogWriter.Debug("Action: " + action);
                LogWriter.Debug("Type name: " + typeName);

                LogWriter.Debug("Format: " + format);

                link = ApplicationPath + "/Projector.aspx?a=" + PrepareForUrl(action) + "&t=" + PrepareForUrl(typeName) + "&f=" + PrepareForUrl(format.ToString());
                link = AddResult(link);

                LogWriter.Debug("Link: " + link);
            }
            return(link);
        }
        /// <summary>
        /// Creates a raw/standard URL to the page corresponding with the specified action and specified type.
        /// </summary>
        /// <param name="action">The action to be performed at the target page.</param>
        /// <param name="typeName">The name of the type being acted upon at the target page.</param>
        /// <param name="propertyName">The name of the property to filter the specified type by.</param>
        /// <param name="value">The value of the property to filter the specified type by.</param>
        /// <param name="format">The format of the target projection.</param>
        /// <returns>The URL to the page handling the provided action in relation to the provided type.</returns>
        public string CreateStandardUrl(string action, string typeName, string propertyName, string value, ProjectionFormat format)
        {
            string link = String.Empty;
            using (LogGroup logGroup = LogGroup.StartDebug("Creating a standard URL for the specified action and provided entity type, with the specified property name and value, as well as the specified format."))
            {
                LogWriter.Debug("Action: " + action);
                LogWriter.Debug("Type name: " + typeName);

                LogWriter.Debug("Property name: " + propertyName);
                LogWriter.Debug("Value: " + value);

                LogWriter.Debug("Format: " + format.ToString());

                link = ApplicationPath + "/Projector.aspx?a=" + PrepareForUrl(action) + "&t=" + PrepareForUrl(typeName) + "&f=" + PrepareForUrl(format.ToString()) + "&" + PrepareForUrl(typeName) + "-" + PrepareForUrl(propertyName) + "=" + PrepareForUrl(value);
                link = AddResult(link);

                LogWriter.Debug("Link: " + link);
            }
            return link;
        }
        /// <summary>
        /// Creates a raw/standard URL to the page corresponding with the specified action and entity.
        /// </summary>
        /// <param name="action">The action to be performed at the target page.</param>
        /// <param name="entity">The entity involved in the action.</param>
        /// <param name="format">The format of the target projection.</param>
        /// <returns>The URL to the page handling the provided action in relation to the provided type.</returns>
        public string CreateStandardUrl(string action, IEntity entity, ProjectionFormat format)
        {
            string link = String.Empty;
            using (LogGroup logGroup = LogGroup.StartDebug("Creating a standard URL for the specified action and provided entity type, with the specified format."))
            {
                LogWriter.Debug("Action: " + action);
                LogWriter.Debug("Entity type: " + entity.ShortTypeName);
                LogWriter.Debug("Format: " + format.ToString());

                link = ApplicationPath + "/Projector.aspx?a=" + PrepareForUrl(action) + "&t=" + PrepareForUrl(entity.ShortTypeName) + "&f=" + PrepareForUrl(format.ToString()) + "&" + PrepareForUrl(entity.ShortTypeName) + "-ID=" + PrepareForUrl(entity.ID.ToString());
                link = AddResult(link);

                LogWriter.Debug("Link: " + link);
            }
            return link;
        }
        /// <summary>
        /// Creates a raw/standard URL to the page corresponding with the specified action and specified type.
        /// </summary>
        /// <param name="action">The action to be performed at the target page.</param>
        /// <param name="typeName">The name of the type being acted upon at the target page.</param>
        /// <param name="format">The format of the target projection.</param>
        /// <returns>The URL to the page handling the provided action in relation to the provided type.</returns>
        public string CreateStandardUrl(string action, string typeName, ProjectionFormat format)
        {
            string link = String.Empty;
            using (LogGroup logGroup = LogGroup.StartDebug("Creating a standard URL for the specified action and type, with the specified format."))
            {
                LogWriter.Debug("Action: " + action);
                LogWriter.Debug("Type name: " + typeName);

                LogWriter.Debug("Format: " + format);

                link = ApplicationPath + "/Projector.aspx?a=" + PrepareForUrl(action) + "&t=" + PrepareForUrl(typeName) + "&f=" + PrepareForUrl(format.ToString());
                link = AddResult(link);

                LogWriter.Debug("Link: " + link);
            }
            return link;
        }
        /// <summary>
        /// Extracts the page format from teh provided URL and adds it to the query strings dictionary.
        /// </summary>
        /// <param name="friendlyUrl"></param>
        /// <param name="queryStrings"></param>
        /// <returns></returns>
        public void ExtractFormatQueryString(string friendlyUrl, Dictionary <string, string> queryStrings)
        {
            ProjectionFormat format = GetFormat(GetExtension(friendlyUrl));

            queryStrings.Add("f", format.ToString());
        }