text:
package com.weisong.common.javaconfig;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { JmxTestJavaConfig.class })
public class JmxTest {

    @Autowired
    private JmxTestBean mbean;

    @Test
    public void testJmx() throws Exception {
        final ObjectName objectName = new ObjectName(JmxTestJavaConfig.OBJECT_NAME);
        final JMXServiceURL jmxUrl = new JMXServiceURL(JmxTestJavaConfig.JMX_RMI_URL);
        final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl);
        final MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
        {
            // Test number
            final Integer number = (Integer) mbsc.invoke(objectName, "getNumber", null, null);
            Assert.assertEquals(mbean.getNumber(), number);
        }
        {
            // Test number
            final String name = (String) mbsc.invoke(objectName, "getName", null, null);
            Assert.assertEquals(mbean.getName(), name);
        }
    }
}


text:
/**
    This node creates an output array from a slice of the input array.

    ## Attributes

 Attribute Name  Short Name  Attribute Type

 input           i           doubleArray

 Input array that will be sliced to produce the output.

 start           st          int

            Index in the input array from which to start the slice.
            If start is negative, the slice will start that many indices from the end of the input array.

 stop            sp          int

            Index in the input array at which to end the slice.
            If stop is negative, the slice will end that many indices from end of the input array.

 step            ss          int

            Stride of each step of the slice.
            If step is 1, every index from start to stop will be returned.
            Step may not be 0.

 output          o          doubleArray

 An array containing the values sliced from the `input` array.

*/

#ifndef n_sliceArray_H
#define n_sliceArray_H

#include <maya/MDataBlock.h>
#include <maya/MPlug.h>
#include <maya/MPxNode.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>

class SliceArrayNode : public MPxNode
{
public:
    virtual MStatus         compute(const MPlug& plug, MDataBlock& data);
    virtual void            postConstructor();
    static  void*           creator();
    static  MStatus         initialize();

public:
    static MTypeId          kNODE_ID;
    static MString          kNODE_NAME;

    static MObject          aInput;
    static MObject          aStartIndex;
    static MObject          aStopIndex;
    static MObject          aStepSize;
    static MObject          aOutput;
};

#endif

redpajama_set_name: RedPajamaGithub


text:
'use strict';

/* https://github.com/angular/protractor/blob/master/docs/toc.md */

describe('NumericSequencesApp', function() {

  beforeEach(function() {
    browser.get('index.html');
  });

  it('should have a title', function() {
    expect(browser.getTitle()).toMatch("Numeric Sequences App");
  });

  it('should automatically redirect to / when location hash/fragment is empty', function() {
    expect(browser.getLocationAbsUrl()).toMatch("/");
  });

  it('has 2 menu link buttons', function(){
    var menu  = element.all(by.css('.menu .button'));
    expect(menu.count()).toEqual(2);
  });

  describe('has Sequences page,', function() {

    beforeEach(function() {
      element(by.linkText('SEQUENCES')).click();
    });

    it('which has a input box. ', function() {
      expect(element(by.css('input')).isPresent()).toBe(true);
    });

    describe('if the input box on valid input', function(){

      beforeEach(function() {
        element(by.css('input')).sendKeys('10');
      });

      it('shows the output', function(){
        expect(element(by.id('series-container')).isDisplayed()).toBe(true);
      });

      it('shows whole series', function(){
        expect(element(by.binding('vm.wholeSeries')).getText()).toEqual('0 1 2 3 4 5 6 7 8 9 10');
      });

      it('shows odd series', function(){
        expect(element(by.binding('vm.oddSeries')).getText()).toEqual('1 3 5 7 9');
      });

      it('shows even series', function(){
        expect(element(by.binding('vm.evenSeries')).getText()).toEqual('0 2 4 6 8 10');
      });

      it('shows special series', function(){
        expect(element(by.binding('vm.specialSeries')).getText()).toEqual('Z 1 2 C 4 E C 7 8 C E');
      });

      it('shows fibonacci series', function(){
        expect(element(by.binding('vm.fibonacciSeries')).getText()).toEqual('0 1 1 2 3 5 8');
      });
    });

    describe('If the input box on invalid input, ', function(){

      var inputControl;

      beforeEach(function() {
        inputControl = element(by.css('input'))
        inputControl.sendKeys('-123');
      });

      it('it should show an help error message that only positive input is allowed.', function(){
        expect(element(by.css('.help-block')).getText()).toContain('positive');
      });

      it('it should cause syling class invalid added to the control.', function(){
       expect(inputControl.getAttribute('class').then(function (classes) {
          return classes.split(' ').indexOf('ng-invalid') !== 1;
       })).toBe(true);
      });
    });

    describe('has Sequences page', function() {

      beforeEach(function() {
        element(by.linkText('HELP')).click();
      });

      it('which has instructions', function() {
        expect(element(by.id('instructions')).isPresent()).toBe(true);
      });
    });
  });
});


text:
using System;
using FineBot.API.GroupsApi;

namespace FineBot.API.ChannelApi
{
    public interface IChannelApi
    {
        ChannelListResponseModel ListChannels(string slackApiToken);

        GroupsHistoryResponseModel GetChannelHistory(string slackApiToken, string channel, DateTime startTime, DateTime endTime, int count);

        ChannelInfoResponseModel GetChannelInfo(string slackApiToken, string channel);
    }
}


text:
package com.hotf.client.event;

import com.google.gwt.event.shared.EventHandler;

public interface ChangeCharacterEventHandler extends EventHandler {
  void onChange(ChangeCharacterEvent event);
}


text:
using System.Threading.Tasks;

using Tauco.Dicom.Network;
using Tauco.Dicom.Shared;

namespace Tauco.Dicom.Models
{
    /// <summary>
    /// Provides methods for retrieving the studies.
    /// </summary>
    public interface IStudyInfoProvider : IDownloadProvider<StudyInfo>
    {
        /// <summary>
        /// Gets all studies.
        /// </summary>
        /// <returns>Collecion containing all the studies</returns>
        IDicomQuery<StudyInfo> GetStudies();

        /// <summary>
        /// Gets all studies for the given patient.
        /// </summary>
        /// <param name="patient">Patient the studies are related to</param>
        /// <returns>Collection containing all the studies of the patient</returns>
        IDicomQuery<StudyInfo> GetStudiesForPatient(PatientInfo patient);

        /// <summary>
        /// Gets single study by given identifier asynchronously.
        /// </summary>
        /// <param name="identifier">Identifier of the study</param>
        /// <param name="loadFromCache">Determines whether the <see cref="StudyInfo"/> should be loaded from cache or from server</param>
        /// <returns>Studies with given identifier, if such study exists; otherwise, null</returns>
        Task<StudyInfo> GetStudyByIDAsync(InfoIdentifier identifier, bool loadFromCache = false);
    }
}


text:
#ifndef BOOST_HANA_CORE_DEFAULT_HPP
#define BOOST_HANA_CORE_DEFAULT_HPP

#include <boost/hana/fwd/core/default.hpp>

#include <boost/hana/config.hpp>

#include <type_traits>

BOOST_HANA_NAMESPACE_BEGIN
    template <typename Method, typename>
    struct is_default : std::false_type { };

    template <typename Method>
    struct is_default<Method, decltype((void)
        static_cast<default_>(*(Method*)0)
    )>
        : std::true_type
    { };
BOOST_HANA_NAMESPACE_END

#endif // !BOOST_HANA_CORE_DEFAULT_HPP


text:
<?php

namespace Wpug\PostBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Wpug\PostBundle\Entity\Category;
use Wpug\PostBundle\Form\CategoryType;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Category controller.
 *
 */
class CategoryController extends Controller
{

    /**
     * Lists all Category entities.
     *
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $entities = $em->getRepository('WpugPostBundle:Category')->findAll();

        return $this->render('WpugPostBundle:Category:index.html.twig', array(
            'entities' => $entities,
        ));
    }
    /**
     * Creates a new Category entity.
     *
     */
    public function createAction(Request $request)
    {
        $entity = new Category();
        $form = $this->createCreateForm($entity);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($entity);
            $em->flush();

            return $this->redirect($this->generateUrl('category_show', array('id' => $entity->getId())));
        }

        return $this->render('WpugPostBundle:Category:new.html.twig', array(
            'entity' => $entity,
            'form'   => $form->createView(),
        ));
    }

    /**
    * Creates a form to create a Category entity.
    *
    * @param Category $entity The entity
    *
    * @return \Symfony\Component\Form\Form The form
    */
    private function createCreateForm(Category $entity)
    {
        $form = $this->createForm(new CategoryType(), $entity, array(
            'action' => $this->generateUrl('category_create'),
            'method' => 'POST',
        ));

        $form->add('submit', 'submit', array('label' => 'Create'));

        return $form;
    }

    /**
     * Displays a form to create a new Category entity.
     *
     */
    public function newAction()
    {
        $entity = new Category();
        $form   = $this->createCreateForm($entity);

        return $this->render('WpugPostBundle:Category:new.html.twig', array(
            'entity' => $entity,
            'form'   => $form->createView(),
        ));
    }

    /**
     * Finds and displays a Category entity.
     *
     */
    public function showAction($id)
    {
        $em = $this->getDoctrine()->getManager();

        $entity = $em->getRepository('WpugPostBundle:Category')->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Category entity.');
        }

        $deleteForm = $this->createDeleteForm($id);

        return $this->render('WpugPostBundle:Category:show.html.twig', array(
            'entity'      => $entity,
            'delete_form' => $deleteForm->createView(),        ));
    }

    /**
     * Displays a form to edit an existing Category entity.
     *
     */
    public function editAction($id)
    {
        $em = $this->getDoctrine()->getManager();

        $entity = $em->getRepository('WpugPostBundle:Category')->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Category entity.');
        }

        $editForm = $this->createEditForm($entity);
        $deleteForm = $this->createDeleteForm($id);

        return $this->render('WpugPostBundle:Category:edit.html.twig', array(
            'entity'      => $entity,
            'edit_form'   => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        ));
    }

    /**
    * Creates a form to edit a Category entity.
    *
    * @param Category $entity The entity
    *
    * @return \Symfony\Component\Form\Form The form
    */
    private function createEditForm(Category $entity)
    {
        $form = $this->createForm(new CategoryType(), $entity, array(
            'action' => $this->generateUrl('category_update', array('id' => $entity->getId())),
            'method' => 'PUT',
        ));

        $form->add('submit', 'submit', array('label' => 'Update'));

        return $form;
    }
    /**
     * Edits an existing Category entity.
     *
     */
    public function updateAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();

        $entity = $em->getRepository('WpugPostBundle:Category')->find($id);

        $originalPosts = new ArrayCollection();

        foreach ($entity->getPosts() as $post) {
            $originalPosts->add($post);
        }

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Category entity.');
        }

        $deleteForm = $this->createDeleteForm($id);
        $editForm = $this->createEditForm($entity);
        $editForm->handleRequest($request);

        if ($editForm->isValid()) {
            foreach ($originalPosts as $post) {

                if (false === $entity->getPosts()->contains($post)) {
                    // remove the Task from the Tag

                    $post->setCategory(null);

                    // if it was a many-to-one relationship, remove the relationship like this
                    // $tag->setTask(null);

                    $em->persist($post);

                    // if you wanted to delete the Tag entirely, you can also do that
                    // $em->remove($tag);
                }
            }

            $em->persist($entity);

            $em->flush();
            return $this->redirect($this->generateUrl('category_edit', array('id' => $id)));
        }

        return $this->render('WpugPostBundle:Category:edit.html.twig', array(
            'entity'      => $entity,
            'edit_form'   => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        ));
    }
    /**
     * Deletes a Category entity.
     *
     */
    public function deleteAction(Request $request, $id)
    {
        $form = $this->createDeleteForm($id);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $entity = $em->getRepository('WpugPostBundle:Category')->find($id);

            if (!$entity) {
                throw $this->createNotFoundException('Unable to find Category entity.');
            }

            $em->remove($entity);
            $em->flush();
        }

        return $this->redirect($this->generateUrl('category'));
    }

    /**
     * Creates a form to delete a Category entity by id.
     *
     * @param mixed $id The entity id
     *
     * @return \Symfony\Component\Form\Form The form
     */
    private function createDeleteForm($id)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('category_delete', array('id' => $id)))
            ->setMethod('DELETE')
            ->add('submit', 'submit', array('label' => 'Delete'))
            ->getForm()
        ;
    }
}


text:
package com.aspose.cells.examples.loading_saving;

import com.aspose.cells.FileFormatType;
import com.aspose.cells.TxtSaveOptions;
import com.aspose.cells.Workbook;
import com.aspose.cells.XpsSaveOptions;
import com.aspose.cells.examples.Utils;

import java.io.FileOutputStream;

public class SavingTextFilewithCustomSeparator {

	public static void main(String[] args) throws Exception {

		// The path to the documents directory.
		String dataDir = Utils.getSharedDataDir(SavingTextFilewithCustomSeparator.class) + "loading_saving/";

		// Creating an Workbook object with an Excel file path
		Workbook workbook = new Workbook(dataDir + "Book1.xlsx");

		TxtSaveOptions toptions = new TxtSaveOptions();
		// Specify the separator
		toptions.setSeparator(';');
		workbook.save(dataDir + "STFWCSeparator_out.csv");

		// Print Message
		System.out.println("Worksheets are saved successfully.");

	}
}


text:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Web.Configuration;
using System.Web;
using System.Xml.Linq;

using Models;
using Models.Common;
using Utilities;
using System.Globalization;

namespace Factories
{
    public class BaseFactory
    {
        protected static string DEFAULT_GUID = "00000000-0000-0000-0000-000000000000";
        public static string commonStatusMessage = "";
		public static int MinimumDescriptionLength = UtilityManager.GetAppKeyValue( "minDescriptionTextLength", 25 );

		public static bool IsDevEnv()
        {
            if ( UtilityManager.GetAppKeyValue( "envType", "no" ) == "development" )
                return true;
            else
                return false;
        }
        public static bool IsProduction()
        {

            if ( UtilityManager.GetAppKeyValue( "envType", "no" ) == "production" )
                return true;
            else
                return false;
        }
        #region Entity frameworks helpers
        public static bool HasStateChanged( Data.CTIEntities context )
        {
            if ( context.ChangeTracker.Entries().Any( e =>
                    e.State == EntityState.Added ||
                    e.State == EntityState.Modified ||
                    e.State == EntityState.Deleted ) == true )
                return true;
            else
                return false;
        }

        public static string SetLastUpdatedBy( int lastUpdatedById, Data.Account accountModifier )
        {
            string lastUpdatedBy = "";
            if ( accountModifier != null )
            {
                lastUpdatedBy = accountModifier.FirstName + " " + accountModifier.LastName;
            }
            else
            {
                if ( lastUpdatedById > 0 )
                {
                    AppUser user = AccountManager.AppUser_Get( lastUpdatedById );
                    lastUpdatedBy = user.FullName();
                }
            }
            return lastUpdatedBy;
        }
        #endregion
        #region Database connections
        /// <summary>
        /// Get the read only connection string for the main database
        /// </summary>
        /// <returns></returns>
        public static string DBConnectionRO()
        {

            string conn = WebConfigurationManager.ConnectionStrings["cti_RO"].ConnectionString;
            return conn;

        }
        public static string MainConnection()
        {
            string conn = WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            return conn;
        }
        #endregion

        #region data retrieval

        protected static CodeItemResult Fill_CodeItemResults( DataRow dr, string fieldName, int categoryId, bool hasSchemaName, bool hasTotals, bool hasAnIdentifer = true )
        {
            string list = GetRowPossibleColumn( dr, fieldName, "" );
            //string list = dr[ fieldName ].ToString();
            CodeItemResult item = new CodeItemResult() { CategoryId = categoryId };
            item.HasAnIdentifer = hasAnIdentifer;

            int totals = 0;
            int id = 0;
            string title = "";
            string schema = "";
            string codedNotation = "";

            if ( !string.IsNullOrWhiteSpace( list ) )
            {
                var codeGroup = list.Split( '|' );
                foreach ( string codeSet in codeGroup )
                {
                    var codes = codeSet.Split( '~' );
                    schema = "";
                    totals = 0;
                    id = 0;
                    if ( hasAnIdentifer )
                    {
                        Int32.TryParse( codes[0].Trim(), out id );
                        if ( codes.Length > 1 )
                            title = codes[1].Trim();
                        if ( hasSchemaName )
                        {
                            if ( codes.Length > 2 )
                                schema = codes[2];

                            if ( hasTotals && codes.Length > 3 )
                                totals = Int32.Parse( codes[3] );
                        }
                        else
                        {
                            if ( hasTotals && codes.Length > 2 )
                                totals = Int32.Parse( codes[2] );
                        }
                    }
                    else
                    {
                        //currently if no Id, assume only text value
                        title = codes[0].Trim();
                    }
                    if ( codes.Length > 4 )
                        codedNotation = codes[4];

                    item.Results.Add( new Models.CodeItem() { Id = id, Title = title, SchemaName = schema, Totals = totals, CodedNotation = codedNotation } );
                }
            }

            return item;
        }
        protected static CodeItemResult Fill_CodeItemResultsFromXml( DataRow dr, string fieldName, int categoryId, bool hasSchemaName, bool hasTotals, bool hasAnIdentifer = true )
        {
            string list = GetRowPossibleColumn( dr, fieldName, "" );
            //string list = dr[ fieldName ].ToString();
            CodeItemResult item = new CodeItemResult() { CategoryId = categoryId };
            item.HasAnIdentifer = hasAnIdentifer;
            if ( string.IsNullOrWhiteSpace( list ) )
                return item;

            if ( !string.IsNullOrWhiteSpace( list ) )
            {
                var xDoc = XDocument.Parse( list );
                foreach ( var child in xDoc.Root.Elements() )
                {
                    var prop = new CodeItem
                    {
                        CategoryId = int.Parse( child.Attribute( "CategoryId" ).Value ),
                        Id = int.Parse( child.Attribute( "PropertyValueId" ).Value ),
                        Title = ( string )child.Attribute( "Property" ) ?? "",
                        CodedNotation = ( string )child.Attribute( "CodedNotation" ) ?? "",
                        SchemaName = ( string )child.Attribute( "SchemaName" ) ?? "",
                        //OtherValue = ( string )child.Attribute( "OtherValue" ) ?? "",
                    };
					if ( prop.CategoryId == categoryId)
					{
						item.Results.Add( prop );
					}

                    //item.Results.Add(new Models.CodeItem() { Id = id, Title = title, SchemaName = schema, Totals = totals });
                }

            }

            return item;
        }

        protected static AgentRelationshipResult Fill_AgentItemResultsFromXml( DataRow dr, string fieldName, int categoryId, bool hasSchemaName, bool hasTotals, bool hasAnIdentifer = true )
        {
            string list = GetRowPossibleColumn( dr, fieldName, "" );
            //string list = dr[ fieldName ].ToString();
            AgentRelationshipResult item = new AgentRelationshipResult() { CategoryId = categoryId };
            item.HasAnIdentifer = hasAnIdentifer;
            if ( string.IsNullOrWhiteSpace( list ) )
                return item;

            if ( !string.IsNullOrWhiteSpace( list ) )
            {
                var xDoc = XDocument.Parse( list );
                foreach ( var child in xDoc.Root.Elements() )
                {
                    var prop = new AgentRelationship
                    {
                        RelationshipId = int.Parse( child.Attribute( "RelationshipTypeId" ).Value ),
                        AgentId = int.Parse( child.Attribute( "OrgId" ).Value ),
                        Relationship = ( string )child.Attribute( "Relationship" ) ?? "",
                        Agent = ( string )child.Attribute( "Organization" ) ?? "",
                        AgentUrl = ( string )child.Attribute( "SubjectWebpage" ) ?? "",
                        IsThirdPartyOrganization = ( string )child.Attribute( "IsThirdPartyOrganization" ) ?? "",
                    };
                    if ( prop.IsThirdPartyOrganization == "1" && !IsProduction() && prop.Agent.IndexOf( "[reference]" ) == -1 )
                        prop.Agent += " [reference] ";
                    item.Results.Add( prop );
                    //item.Results.Add(new Models.CodeItem() { Id = id, Title = title, SchemaName = schema, Totals = totals });
                }

            }

            return item;
        }
        /// <summary>
        /// Helper method to retrieve a string column from a row while handling invalid values
        /// </summary>
        /// <param name="row">DataRow</param>
        /// <param name="column">Column Name</param>
        /// <param name="defaultValue">Default value to return if column data is invalid</param>
        /// <returns></returns>

        protected static CredentialConnectionsResult Fill_CredentialConnectionsResult( DataRow dr, string fieldName, int categoryId )
        {
            string list = GetRowPossibleColumn( dr, fieldName, "" );
            CredentialConnectionsResult result = new CredentialConnectionsResult() { CategoryId = categoryId };
            CredentialConnectionItem item = new CredentialConnectionItem();
            int id = 0;

            if ( !string.IsNullOrWhiteSpace( list ) )
            {
                var codeGroup = list.Split( '|' );
                foreach ( string codeSet in codeGroup )
                {
                    var codes = codeSet.Split( '~' );
                    item = new CredentialConnectionItem();

                    id = 0;
                    Int32.TryParse( codes[0].Trim(), out id );
                    item.ConnectionId = id;
                    if ( codes.Length > 1 )
                        item.Connection = codes[1].Trim();
                    if ( codes.Length > 2 )
                        Int32.TryParse( codes[2].Trim(), out id );
                    item.CredentialId = id;
                    if ( codes.Length > 3 )
                        item.Credential = codes[3].Trim();
                    if ( codes.Length > 4 )
                        Int32.TryParse( codes[4].Trim(), out id );
                    item.CredentialOwningOrgId = id;
                    if ( codes.Length > 5 )
                        item.CredentialOwningOrg = codes[5].Trim();

                    result.Results.Add( item );
                }
            }

            return result;
        }

        public static string GetRowColumn( DataRow row, string column, string defaultValue = "" )
        {
            string colValue = "";

            try
            {
                colValue = row[column].ToString();

            }
            catch ( System.FormatException fex )
            {
                //Assuming FormatException means null or invalid value, so can ignore
                colValue = defaultValue;

            }
            catch ( Exception ex )
            {
                if ( HasMessageBeenPreviouslySent( column ) == false )
                {
                    string queryString = GetWebUrl();
                    string exType = ex.GetType().ToString();
                    LoggingHelper.LogError( exType + " Exception in GetRowColumn( DataRow row, string column, string defaultValue ) for column: " + column + ". \r\n" + ex.Message.ToString() + "\r\nLocation: " + queryString, true );
                }

                colValue = defaultValue;
            }
            return colValue;

        }

        public static string GetRowPossibleColumn( DataRow row, string column, string defaultValue = "" )
        {
            string colValue = "";

            try
            {
                colValue = row[column].ToString();

            }
            catch ( System.FormatException fex )
            {
                //Assuming FormatException means null or invalid value, so can ignore
                colValue = defaultValue;

            }
            catch ( Exception ex )
            {

                colValue = defaultValue;
            }
            return colValue;

        }

        /// <summary>
        /// Helper method to retrieve an int column from a row while handling invalid values
        /// </summary>
        /// <param name="row">DataRow</param>
        /// <param name="column">Column Name</param>
        /// <param name="defaultValue">Default value to return if column data is invalid</param>
        /// <returns></returns>
        public static int GetRowColumn( DataRow row, string column, int defaultValue )
        {
            int colValue = 0;

            try
            {
                colValue = Int32.Parse( row[column].ToString() );

            }
            catch ( System.FormatException fex )
            {
                //Assuming FormatException means null or invalid value, so can ignore
                colValue = defaultValue;

            }
            catch ( Exception ex )
            {
                if ( HasMessageBeenPreviouslySent( column ) == false )
                {
                    string queryString = GetWebUrl();
                    LoggingHelper.LogError( "Exception in GetRowColumn( DataRow row, string column, int defaultValue ) for column: " + column + ". \r\n" + ex.Message.ToString() + "\r\nLocation: " + queryString, true );
                }

                colValue = defaultValue;
                //throw ex;
            }
            return colValue;

        }

        public static int GetRowPossibleColumn( DataRow row, string column, int defaultValue )
        {
            int colValue = 0;

            try
            {
                colValue = Int32.Parse( row[column].ToString() );

            }
            catch ( System.FormatException fex )
            {
                //Assuming FormatException means null or invalid value, so can ignore
                colValue = defaultValue;

            }
            catch ( Exception ex )
            {
                colValue = defaultValue;
                //throw ex;
            }
            return colValue;

        }
        public static decimal GetRowPossibleColumn( DataRow row, string column, decimal defaultValue )
        {
            decimal colValue = 0;

            try
            {
                colValue = decimal.Parse( row[column].ToString() );

            }
            catch ( System.FormatException fex )
            {
                //Assuming FormatException means null or invalid value, so can ignore
                colValue = defaultValue;

            }
            catch ( Exception ex )
            {
                //string queryString = GetWebUrl();

                //LoggingHelper.LogError( "Exception in GetRowColumn( DataRow row, string column, int defaultValue ) for column: " + column + ". \r\n" + ex.Message.ToString() + "\r\nLocation: " + queryString, true );
                colValue = defaultValue;
                //throw ex;
            }
            return colValue;

        }
        public static bool GetRowColumn( DataRow row, string column, bool defaultValue )
        {
            bool colValue = false;

            try
            {
                //need to properly handle int values of 0,1, as bool
                string strValue = row[column].ToString();
                if ( !string.IsNullOrWhiteSpace( strValue ) && strValue.Trim().Length == 1 )
                {
                    strValue = strValue.Trim();
                    if ( strValue == "0" )
                        return false;
                    else if ( strValue == "1" )
                        return true;
                }
                colValue = bool.Parse( row[column].ToString() );

            }
            catch ( System.FormatException fex )
            {
                //Assuming FormatException means null or invalid value, so can ignore
                colValue = defaultValue;

            }
            catch ( Exception ex )
            {
                if ( HasMessageBeenPreviouslySent( column ) == false )
                {
                    string queryString = GetWebUrl();
                    LoggingHelper.LogError( "Exception in GetRowColumn( DataRow row, string column, int defaultValue ) for column: " + column + ". \r\n" + ex.Message.ToString() + "\r\nLocation: " + queryString, true );
                }

                colValue = defaultValue;
                //throw ex;
            }
            return colValue;

        }
        public static DateTime GetRowColumn( DataRow row, string column, DateTime defaultValue )
        {
            DateTime colValue;

            try
            {
                string strValue = row[column].ToString();
                if ( DateTime.TryParse( strValue, out colValue ) == false )
                    colValue = defaultValue;
            }
            catch ( System.FormatException fex )
            {
                //Assuming FormatException means null or invalid value, so can ignore
                colValue = defaultValue;

            }
            catch ( Exception ex )
            {
                if ( HasMessageBeenPreviouslySent( column ) == false )
                {
                    string queryString = GetWebUrl();
                    LoggingHelper.LogError( ex, " Exception in GetRowColumn( DataRow row, string column, string defaultValue ) for column: " + column + ". \r\n" + ex.Message.ToString() + "\r\nLocation: " + queryString, true );
                }
                colValue = defaultValue;
                //throw ex;
            }
            return colValue;

        }
        public static bool HasMessageBeenPreviouslySent( string keyName )
        {

            string key = "missingColumn_" + keyName;
            //check cache for keyName
            if ( HttpRuntime.Cache[key] != null )
            {
                return true;
            }
            else
            {
                //not really much to store
                HttpRuntime.Cache.Insert( key, keyName );
            }

            return false;
        }
        protected static int GetField( int? field, int defaultValue = 0 )
        {
            int value = field != null ? ( int )field : defaultValue;

            return value;
        } // end method
        protected static decimal GetField( decimal? field, decimal defaultValue = 0 )
        {
            decimal value = field != null ? ( decimal )field : defaultValue;

            return value;
        } // end method
        protected static Guid GetField( Guid? field, Guid defaultValue )
        {
            Guid value = field != null ? ( Guid )field : defaultValue;

            return value;
        } // end method

        protected static string GetMessages( List<string> messages )
        {
            if ( messages == null || messages.Count == 0 )
                return "";

            return string.Join( "<br/>", messages.ToArray() );

        }
        //protected static List<string> GetArray( string messages )
        //{
        //	List<string> list = new List<string>();
        //	if ( string.IsNullOrWhiteSpace( messages) )
        //		return list;
        //	string[] array = messages.Split( ',' );

        //	return list;
        //}
        /// <summary>
        /// Split a comma separated list into a list of strings
        /// </summary>
        /// <param name="csl"></param>
        /// <returns></returns>
        public static List<string> CommaSeparatedListToStringList( string csl )
        {
            if ( string.IsNullOrWhiteSpace( csl ) )
                return new List<string>();

            try
            {
                return csl.Trim().Split( new string[] { "," }, StringSplitOptions.RemoveEmptyEntries ).ToList();
            }
            catch
            {
                return new List<string>();
            }
        }
        /// <summary>
        /// Get the current url for reporting purposes
        /// </summary>
        /// <returns></returns>
        public static string GetWebUrl()
        {
            string queryString = "n/a";
			try
			{
				if ( HttpContext.Current != null && HttpContext.Current.Request != null )
					queryString = HttpContext.Current.Request.RawUrl.ToString();
			} catch (Exception ex)
			{
				//ignore
			}
            return queryString;
        }

        #endregion
        #region Dynamic Sql
        public static DataTable ReadTable( string tableViewName, string orderBy = "" )
        {
            // Table to store the query results
            DataTable table = new DataTable();
            if ( string.IsNullOrWhiteSpace( tableViewName ) )
                return table;
            if ( tableViewName.IndexOf( "[" ) == -1 )
                tableViewName = "[" + tableViewName.Trim() + "]";
            string sql = string.Format( "SELECT * FROM {0} ", tableViewName );
            if ( !string.IsNullOrWhiteSpace( orderBy ) )
                sql += " Order by " + orderBy;

            string connectionString = DBConnectionRO();
            // Creates a SQL connection
            using ( var connection = new SqlConnection( DBConnectionRO() ) )
            {
                connection.Open();

                // Creates a SQL command
                using ( var command = new SqlCommand( sql, connection ) )
                {
                    // Loads the query results into the table
                    table.Load( command.ExecuteReader() );
                }

                connection.Close();
            }

            return table;
        }
        public static DataTable ReadSql( string sql )
        {
            // Table to store the query results
            DataTable table = new DataTable();
            if ( string.IsNullOrWhiteSpace( sql ) )
                return table;

            string connectionString = DBConnectionRO();
            // Creates a SQL connection
            using ( var connection = new SqlConnection( DBConnectionRO() ) )
            {
                connection.Open();

                // Creates a SQL command
                using ( var command = new SqlCommand( sql, connection ) )
                {
                    // Loads the query results into the table
                    table.Load( command.ExecuteReader() );
                }

                connection.Close();
            }

            return table;
        } //

        public static DataSet DoQuery( string sql )
        {
            DataSet ds = new DataSet();

            try
            {
                string connectionString = DBConnectionRO();
                //use default database connection for sql
               // ds = SqlHelper.ExecuteDataset( connectionString, System.Data.CommandType.Text, sql );

                if ( ds.Tables.Count == 0 )
                    ds = null;

                return ds;
            }

            catch ( Exception e )
            {

                LoggingHelper.LogError( e, string.Format( "DatabaseManager.DoQuery(): "
                    + "\r\nSQL:" + sql
                    + "\r\n" + e.ToString() ) );
                //return SetDataSetMessage( "DatabaseManager.DoQuery(): " + e.Message.ToString() );
                return null;
            }

        } //

        #endregion
        #region validations, etc
        public static bool IsValidDate( DateTime date )
        {
            if ( date != null && date > new DateTime( 1492, 1, 1 ) )
                return true;
            else
                return false;
        }

        public static bool IsValidDate( DateTime? date )
        {
            if ( date != null && date > new DateTime( 1492, 1, 1 ) )
                return true;
            else
                return false;
        }
        public static bool IsValidDate( string date )
        {
            DateTime validDate;
            if ( string.IsNullOrWhiteSpace( date ) || date.Length < 8 )
                return false;

            if ( !string.IsNullOrWhiteSpace( date )
                && DateTime.TryParse( date, out validDate )
                && date.Length >= 8
                && validDate > new DateTime( 1492, 1, 1 )
                )
                return true;
            else
                return false;
        }
        public static bool IsInteger( string nbr )
        {
            int validNbr = 0;
            if ( !string.IsNullOrWhiteSpace( nbr ) && int.TryParse( nbr, out validNbr ) )
                return true;
            else
                return false;
        }
        public static bool IsValid( string nbr )
        {
            int validNbr = 0;
            if ( !string.IsNullOrWhiteSpace( nbr ) && int.TryParse( nbr, out validNbr ) )
                return true;
            else
                return false;
        }

        protected bool IsValidGuid( Guid field )
        {
            if ( ( field == null || field.ToString() == DEFAULT_GUID ) )
                return false;
            else
                return true;
        }
        protected bool IsValidGuid( Guid? field )
        {
            if ( ( field == null || field.ToString() == DEFAULT_GUID ) )
                return false;
            else
                return true;
        }
        public static bool IsValidGuid( string field )
        {
            if ( string.IsNullOrWhiteSpace( field )
                || field.Trim() == DEFAULT_GUID
                || field.Length != 36
                )
                return false;
            else
                return true;
        }
        public static bool IsGuidValid( Guid field )
        {
            if ( ( field == null || field.ToString() == DEFAULT_GUID ) )
                return false;
            else
                return true;
        }

        public static bool IsGuidValid( Guid? field )
        {
            if ( ( field == null || field.ToString() == DEFAULT_GUID ) )
                return false;
            else
                return true;
        }
        public static string GetData( string text, string defaultValue = "" )
        {
            if ( string.IsNullOrWhiteSpace( text ) == false )
                return text.Trim();
            else
                return defaultValue;
        }
        public static int? SetData( int value, int minValue )
        {
            if ( value >= minValue )
                return value;
            else
                return null;
        }
        public static decimal? SetData( decimal value, decimal minValue )
        {
            if ( value >= minValue )
                return value;
            else
                return null;
        }
        public static DateTime? SetDate( string value )
        {
            DateTime output;
            if ( DateTime.TryParse( value, out output ) )
                return output;
            else
                return null;
        }
        public static string NormalizeUrlData( string text, string defaultValue = "" )
        {
            if ( string.IsNullOrWhiteSpace( text ) == false )
            {
                text = text.TrimEnd( '/' );
                return text.Trim();
            }
            else
                return defaultValue;
        }
        /// <summary>
        /// Validates the format of a Url
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        //public static bool IsUrlWellFormed( string url )
        //{
        //	string responseStatus = "";

        //	if ( string.IsNullOrWhiteSpace( url ) )
        //		return true;
        //	if ( !Uri.IsWellFormedUriString( url, UriKind.Absolute ) )
        //	{
        //		responseStatus = "The URL is not in a proper format";
        //		return false;
        //	}

        //	//may need to allow ftp, and others - not likely for this context?
        //	if ( url.ToLower().StartsWith( "http" ) == false )
        //	{
        //		responseStatus = "A URL must begin with http or https";

        //		return false;
        //	}

        //	//NOTE - do NOT use the HEAD option, as many sites reject that type of request
        //	var isOk = DoesRemoteFileExists( url, ref responseStatus );
        //	//optionally try other methods, or again with GET
        //	if ( !isOk && responseStatus == "999" )
        //		isOk = true;

        //	return isOk;
        //}
        public static bool IsUrlValid( string url, ref string statusMessage, bool doingExistanceCheck = true )
        {
            statusMessage = "";
            if ( string.IsNullOrWhiteSpace( url ) )
                return true;

            if ( !Uri.IsWellFormedUriString( url, UriKind.Absolute ) )
            {
                statusMessage = "The URL is not in a proper format (for example, must begin with http or https).";
                return false;
            }

            //may need to allow ftp, and others - not likely for this context?
            if ( url.ToLower().StartsWith( "http" ) == false )
            {
                statusMessage = "A URL must begin with http or https";
                return false;
            }
            if ( !doingExistanceCheck )
                return true;

            bool isaImageUrl = false;
            var isOk = DoesRemoteFileExists( url, ref statusMessage, ref isaImageUrl );
            //optionally try other methods, or again with GET
            if ( !isOk && statusMessage == "999" )
                return true;
            //	isOk = DoesRemoteFileExists( url, ref responseStatus, "GET" );

            //if ( isOk )
            //{
            //    SafeBrowsing.Reputation rep = SafeBrowsing.CheckUrl( url );
            //    if ( rep != SafeBrowsing.Reputation.None )
            //    {
            //        statusMessage = string.Format( "Url ({0}) failed SafeBrowsing check.", url );
            //        return false;
            //    }
            //}
            if(isOk & isaImageUrl)
            {
                statusMessage = " This property should not contain an image URL ";
                return false;
            }

            return isOk;
        }

        public static bool IsImageUrlValid ( string url, ref string statusMessage, bool doingExistanceCheck = true )
        {
            bool isaImageUrl = false;

            if ( !Uri.IsWellFormedUriString( url, UriKind.Absolute ) )
            {
                statusMessage = "The URL is not in a proper format (for example, must begin with http or https).";
                return false;
            }

            //may need to allow ftp, and others - not likely for this context?
            //may want to allow just //. This is more likely with resources like images, stylesheets
                if ( url.ToLower().StartsWith( "http" ) == false && url.ToLower().StartsWith( "//" ) == false )
                {
                    statusMessage = "A URL must begin with http or https";
                    return false;
                }
            if ( !doingExistanceCheck )
                return true;

            if ( DoesRemoteFileExists( url, ref statusMessage, ref isaImageUrl ) )
             {
                if ( isaImageUrl == false )
                {
                    statusMessage = "This property is not a valid Image URL";
                    return false;
                }
                else return true;
            }
            else
            {
                return false;
            }

        }

        /// <summary>
        /// Checks the file exists or not.
        /// </summary>
        /// <param name="url">The URL of the remote file.</param>
        /// <returns>True : If the file exits, False if file not exists</returns>
        public static bool DoesRemoteFileExists( string url, ref string responseStatus,ref bool isaimageurl)
        {
            //the following is only used to handle certain errors.
            //we may want a different property to allow publishing to skip completely (for speed, and already checked)
            bool doingLinkChecking = UtilityManager.GetAppKeyValue( "doingLinkChecking", true );
            //consider stripping off https?
            //or if not found and https, try http
            try
            {
                if ( SkippingValidation( url ) )
                    return true;

                SafeBrowsing.Reputation rep = SafeBrowsing.CheckUrl( url );
                if ( rep != SafeBrowsing.Reputation.None )
                {
                    responseStatus = string.Format( "Url ({0}) failed SafeBrowsing check.", url );
                    return false;
                }
                //Creating the HttpWebRequest
                HttpWebRequest request = WebRequest.Create( url ) as HttpWebRequest;
                //NOTE - do use the HEAD option, as many sites reject that type of request
                //request.Method = "GET";
                //var agent = HttpContext.Current.Request.AcceptTypes;

                //request.ContentType = "text/html;charset=\"utf-8\";image/*";

                request.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17";

                //users may be providing urls to sites that have invalid ssl certs installed.You can ignore those cert problems if you put this line in before you make the actual web request:
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback( AcceptAllCertifications );

                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

                //Getting the Web Response.
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;

                if ( response != null )
                    if ( response.ContentType.ToLower( CultureInfo.InvariantCulture ).Contains( "image/" ) )
                    {
                        isaimageurl = true;
                    }
                //Returns TRUE if the Status code == 200
                response.Close();
                if ( response.StatusCode != HttpStatusCode.OK )
                {
                    if ( url.ToLower().StartsWith( "https:" ) )
                    {
                        url = url.ToLower().Replace( "https:", "http:" );
                        LoggingHelper.DoTrace( 5, string.Format( "_____________Failed for https, trying again using http: {0}", url ) );

                        return DoesRemoteFileExists( url, ref responseStatus, ref isaimageurl );
                    }
                    else
                    {
                        LoggingHelper.DoTrace( 5, string.Format( "Url validation failed for: {0}, using method: GET, with status of: {1}", url, response.StatusCode ) );
                    }
                }
                responseStatus = response.StatusCode.ToString();

                return ( response.StatusCode == HttpStatusCode.OK );
                //apparantly sites like Linked In have can be a  problem
                //http://stackoverflow.com/questions/27231113/999-error-code-on-head-request-to-linkedin
                //may add code to skip linked In?, or allow on fail - which the same.
                //or some update, refer to the latter link

                //
            }
            catch ( WebException wex )
            {
                responseStatus = wex.Message;
                //
                if ( wex.Message.IndexOf( "(404)" ) > 1 )
                    return false;
                else if ( wex.Message.IndexOf( "Too many automatic redirections were attempted" ) > -1 )
                    return false;
                else if ( wex.Message.IndexOf( "(999" ) > 1 )
                    return true;
                else if ( wex.Message.IndexOf( "(400) Bad Request" ) > 1 )
                    return true;
                else if ( wex.Message.IndexOf( "(401) Unauthorized" ) > 1 )
                    return true;
                else if ( wex.Message.IndexOf( "(406) Not Acceptable" ) > 1 )
                    return true;
                else if ( wex.Message.IndexOf( "(500) Internal Server Error" ) > 1 )
                    return true;
                else if ( wex.Message.IndexOf( "Could not create SSL/TLS secure channel" ) > 1 )
                {
                    //https://www.naahq.org/education-careers/credentials/certification-for-apartment-maintenance-technicians
                    return true;

                }
                else if ( wex.Message.IndexOf( "Could not establish trust relationship for the SSL/TLS secure channel" ) > -1 )
                {
                    return true;
                }
                else if ( wex.Message.IndexOf( "The underlying connection was closed: An unexpected error occurred on a send" ) > -1 )
                {
                    return true;
                }
                else if ( wex.Message.IndexOf( "The connection was closed unexpectedly" ) > -1 )
                {
                    return true;
                }
                else if ( wex.Message.IndexOf( "Detail=CR must be followed by LF" ) > 1 )
                {
                    return true;
                }
                //var pageContent = new StreamReader( wex.Response.GetResponseStream() )
                //		 .ReadToEnd();
                if ( !doingLinkChecking )
                {
                    LoggingHelper.LogError( string.Format( "BaseFactory.DoesRemoteFileExists url: {0}. Exception Message:{1}; URL: {2}", url, wex.Message, GetWebUrl() ), true, "SKIPPING - Exception on URL Checking" );

                    return true;
                }

                LoggingHelper.LogError( string.Format( "BaseFactory.DoesRemoteFileExists url: {0}. Exception Message:{1}", url, wex.Message ), true, "Exception on URL Checking" );
                responseStatus = wex.Message;
                return false;
            }
            catch ( Exception ex )
            {

                if ( ex.Message.IndexOf( "(999" ) > -1 )
                {
                    //linked in scenario
                    responseStatus = "999";
                }
                else if ( ex.Message.IndexOf( "Could not create SSL/TLS secure channel" ) > 1 )
                {
                    //https://www.naahq.org/education-careers/credentials/certification-for-apartment-maintenance-technicians
                    return true;

                }
                else if ( ex.Message.IndexOf( "(500) Internal Server Error" ) > 1 )
                {
                    return true;
                }
                else if ( ex.Message.IndexOf( "(401) Unauthorized" ) > 1 )
                {
                    return true;
                }
                else if ( ex.Message.IndexOf( "Could not establish trust relationship for the SSL/TLS secure channel" ) > 1 )
                {
                    return true;
                }
                else if ( ex.Message.IndexOf( "Detail=CR must be followed by LF" ) > 1 )
                {
                    return true;
                }
                if ( !doingLinkChecking )
                {
                    LoggingHelper.LogError( string.Format( "BaseFactory.DoesRemoteFileExists url: {0}. Exception Message:{1}", url, ex.Message ), true, "SKIPPING - Exception on URL Checking" );

                    return true;
                }

                LoggingHelper.LogError( string.Format( "BaseFactory.DoesRemoteFileExists url: {0}. Exception Message:{1}", url, ex.Message ), true, "Exception on URL Checking" );
                //Any exception will returns false.
                responseStatus = ex.Message;
                return false;
            }
        }
        public static bool AcceptAllCertifications( object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors )
        {
            return true;
        }
        private static bool SkippingValidation( string url )
        {

            Uri myUri = new Uri( url );
            string host = myUri.Host;

            string exceptions = UtilityManager.GetAppKeyValue( "urlExceptions" );
            //quick method to avoid loop
            if ( exceptions.IndexOf( host ) > -1 )
                return true;

            //string[] domains = exceptions.Split( ';' );
            //foreach ( string item in domains )
            //{
            //	if ( url.ToLower().IndexOf( item.Trim() ) > 5 )
            //		return true;
            //}

            return false;
        }

        public static bool IsPhoneValid( string phone, string type, ref List<string> messages )
        {
            bool isValid = true;

            string phoneNbr = PhoneNumber.StripPhone( GetData( phone ) );

            if ( !string.IsNullOrWhiteSpace( phoneNbr ) && phoneNbr.Length < 10 )
            {
                messages.Add( string.Format( "Error - A valid {0} ({1}) must have at least 10 numbers.", type, phone ) );
                return false;
            }

            return isValid;
        }
        #endregion
        public static string ConvertSpecialCharacters(string text)
        {
            bool hasChanged = false;

            return ConvertSpecialCharacters(text, ref hasChanged);
        }
        /// <summary>
        /// Convert characters often resulting from external programs like Word
        /// NOTE: keep in sync with the RegistryAssistant Api version
        /// </summary>
        /// <param name="text"></param>
        /// <param name="hasChanged"></param>
        /// <returns></returns>
        public static string ConvertSpecialCharacters( string text, ref bool hasChanged )
        {
            hasChanged = false;
            if ( string.IsNullOrWhiteSpace( text ) )
                return "";
            string orginal = text.Trim();
            if ( ContainsUnicodeCharacter(text) )
            {

                if ( text.IndexOf('\u2013') > -1 ) text = text.Replace('\u2013', '-'); // en dash
                if ( text.IndexOf('\u2014') > -1 ) text = text.Replace('\u2014', '-'); // em dash
                if ( text.IndexOf('\u2015') > -1 ) text = text.Replace('\u2015', '-'); // horizontal bar
                if ( text.IndexOf('\u2017') > -1 ) text = text.Replace('\u2017', '_'); // double low line
                if ( text.IndexOf('\u2018') > -1 ) text = text.Replace('\u2018', '\''); // left single quotation mark
                if ( text.IndexOf('\u2019') > -1 ) text = text.Replace('\u2019', '\''); // right single quotation mark
                if ( text.IndexOf('\u201a') > -1 ) text = text.Replace('\u201a', ','); // single low-9 quotation mark
                if ( text.IndexOf('\u201b') > -1 ) text = text.Replace('\u201b', '\''); // single high-reversed-9 quotation mark
                if ( text.IndexOf('\u201c') > -1 ) text = text.Replace('\u201c', '\"'); // left double quotation mark
                if ( text.IndexOf('\u201d') > -1 ) text = text.Replace('\u201d', '\"'); // right double quotation mark
                if ( text.IndexOf('\u201e') > -1 ) text = text.Replace('\u201e', '\"'); // double low-9 quotation mark
                if ( text.IndexOf('\u201f') > -1 ) text = text.Replace('\u201f', '\"'); // ???
                if ( text.IndexOf('\u2026') > -1 ) text = text.Replace("\u2026", "..."); // horizontal ellipsis
                if ( text.IndexOf('\u2032') > -1 ) text = text.Replace('\u2032', '\''); // prime
                if ( text.IndexOf('\u2033') > -1 ) text = text.Replace('\u2033', '\"'); // double prime
                if ( text.IndexOf('\u2036') > -1 ) text = text.Replace('\u2036', '\"'); // ??
                if ( text.IndexOf('\u0090') > -1 ) text = text.Replace('\u0090', 'ê'); // e circumflex
            }
			text = text.Replace( "'", "'" );
			text = text.Replace( "â€\"", "-" );
			text = text.Replace( "\"â€ú", "-" );
			//
			//don't do this as \r is valid
			text = text.Replace( "\\\\r", "" );

			text = text.Replace( "\u009d", " " ); //
			text = text.Replace( "Ã,Â", "" ); //

			text = Regex.Replace( text, "'", "'" );
			text = Regex.Replace( text, """, "'" );
			text = Regex.Replace( text, """, "'" );
			//BIZARRE
			text = Regex.Replace( text, "ââ,¬â\"¢", "'" );
			text = Regex.Replace( text, "–", "-" );

			text = Regex.Replace(text, "[Õ]", "'");
            text = Regex.Replace(text, "[Ô]", "'");
            text = Regex.Replace(text, "[Ò]", "\"");
            text = Regex.Replace(text, "[Ó]", "\"");
            text = Regex.Replace(text, "[Ñ]", " -"); //Ñ
            text = Regex.Replace(text, "[Ž]", "é");
            text = Regex.Replace(text, "[ˆ]", "à");
            text = Regex.Replace(text, "[Ð]", "-");
            //
            text = text.Replace("‡", "á"); //ó

			text = text.Replace( "ó", "ó" ); //
			text = text.Replace( "ó", "ó" ); //
			//é
			text = text.Replace( "é", "é" ); //
			text = text.Replace( "é", "é" ); //

			text = text.Replace( "á", "á" ); //
			text = text.Replace( "á", "á" ); //á
			text = text.Replace( "ÃÂ", "à" ); //
			//
			text = text.Replace( "ñ", "ñ" ); //
			text = text.Replace( "±", "ñ" ); //"ñ"
											  //
			text = text.Replace( "ÃÂ-", "í" ); //???? same as à
			text = text.Replace( "í", "í" ); //"ías" "gía" "gías"
			text = text.Replace( "gías", "gías" ); //"ías" "gía" "gías"
			text = text.Replace( "'", "í" ); //

			text = text.Replace( "ú", "ú" ); //"ú"
			text = text.Replace( "º", "ú" ); //"ú"
            text = text.Replace("œ", "ú"); //

            text = text.Replace("quÕˆ", "qu'à"); //
            text = text.Replace("qu'ˆ", "qu'à"); //
            text = text.Replace("ci—n ", "ción ");
			//"¨"
			text = text.Replace( "¨", "®" ); //

			text = text.Replace("teor'as", "teorías"); //
            text = text.Replace("log'as", "logías"); //
            text = text.Replace("ense–anza", "enseñanza"); //
			//
			text = text.Replace( "ââ,¬Ãº", "\"" ); //
			text = text.Replace( "ââ,¬Â", "\"" ); //
													//

			//not sure if should do this arbitrarily here?
			if ( text.IndexOf( "Ã" ) > -1 || text.IndexOf( "Â" ) > -1 )
			{
				string queryString = GetWebUrl();
				LoggingHelper.DoTrace( 1, string.Format("@#@#@# found text containing à or Â, setting to blank. URL: {0}, Text:\r{1}", queryString, text ) );
				text = text.Replace( "Ã", "" ); //
				text = text.Replace( ",Â", "" ); //
				text = text.Replace( "Â", "" ); //
			}

			text = text.Replace("ou�ll", "ou'll"); //
            text = text.Replace("�s", "'s"); //
			text = text.Replace( "�", "" ); //
			text = Regex.Replace(text, "[—]", "-"); //

            text = Regex.Replace(text, "[�]", " "); //could be anything
            //covered above
            //text = Regex.Replace(text, "[«»\u201C\u201D\u201E\u201F\u2033\u2036]", "\"");
            //text = Regex.Replace(text, "[\u2026]", "...");

            //

            if ( orginal != text.Trim())
            {
                //should report any changes
                hasChanged = true;
                //text = orginal;
            }
            return text.Trim();
        } //

        public static bool ContainsUnicodeCharacter(string input)
        {
            const int MaxAnsiCode = 255;

            return input.Any(c => c > MaxAnsiCode);
        }
        public static void ListUnicodeCharacter(string input)
        {
            if ( !ContainsUnicodeCharacter(input) )
                return;

            //string chg = Regex.Match(input, @"[^\u0000-\u007F]", "");

        }
        /// <summary>
        /// Format a title (such as for a library) to be url friendly
        /// NOTE: there are other methods:
        /// ILPathways.Utilities.UtilityManager.UrlFriendlyTitle()
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string FormatFriendlyTitle( string text )
        {
            if ( text == null || text.Trim().Length == 0 )
                return "";

            string title = UrlFriendlyTitle( text );

            //encode just incase
            title = HttpUtility.HtmlEncode( title );
            return title;
        }
        /// <summary>
        /// Format a title (such as for a library) to be url friendly
        /// NOTE: there are other methods:
        /// ILPathways.Utilities.UtilityManager.UrlFriendlyTitle()
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        private static string UrlFriendlyTitle( string title )
        {
            if ( title == null || title.Trim().Length == 0 )
                return "";

            title = title.Trim();

            string encodedTitle = title.Replace( " - ", "-" );
            encodedTitle = encodedTitle.Replace( " ", "_" );

            //for now allow embedded periods
            //encodedTitle = encodedTitle.Replace( ".", "-" );

            encodedTitle = encodedTitle.Replace( "'", "" );
            encodedTitle = encodedTitle.Replace( "&", "-" );
            encodedTitle = encodedTitle.Replace( "#", "" );
            encodedTitle = encodedTitle.Replace( "$", "S" );
            encodedTitle = encodedTitle.Replace( "%", "percent" );
            encodedTitle = encodedTitle.Replace( "^", "" );
            encodedTitle = encodedTitle.Replace( "*", "" );
            encodedTitle = encodedTitle.Replace( "+", "_" );
            encodedTitle = encodedTitle.Replace( "~", "_" );
            encodedTitle = encodedTitle.Replace( "`", "_" );
            encodedTitle = encodedTitle.Replace( "/", "_" );
            encodedTitle = encodedTitle.Replace( "://", "/" );
            encodedTitle = encodedTitle.Replace( ":", "" );
            encodedTitle = encodedTitle.Replace( ";", "" );
            encodedTitle = encodedTitle.Replace( "?", "" );
            encodedTitle = encodedTitle.Replace( "\"", "_" );
            encodedTitle = encodedTitle.Replace( "\\", "_" );
            encodedTitle = encodedTitle.Replace( "<", "_" );
            encodedTitle = encodedTitle.Replace( ">", "_" );
            encodedTitle = encodedTitle.Replace( "__", "_" );
            encodedTitle = encodedTitle.Replace( "__", "_" );
            encodedTitle = encodedTitle.Replace( "..", "_" );
            encodedTitle = encodedTitle.Replace( ".", "_" );

            if ( encodedTitle.EndsWith( "." ) )
                encodedTitle = encodedTitle.Substring( 0, encodedTitle.Length - 1 );

            return encodedTitle;
        } //
        public static string GenerateFriendlyName( string name )
        {
            if ( name == null || name.Trim().Length == 0 )
                return "";
            //another option could be use a pattern like the following?
            //string phrase = string.Format( "{0}-{1}", Id, name );

            string str = RemoveAccent( name ).ToLower();
            // invalid chars
            str = Regex.Replace( str, @"[^a-z0-9\s-]", "" );
            // convert multiple spaces into one space
            str = Regex.Replace( str, @"\s+", " " ).Trim();
            // cut and trim
            str = str.Substring( 0, str.Length <= 45 ? str.Length : 45 ).Trim();
            str = Regex.Replace( str, @"\s", "-" ); // hyphens
            return str;
        }
        private static string RemoveAccent( string text )
        {
            byte[] bytes = System.Text.Encoding.GetEncoding( "Cyrillic" ).GetBytes( text );
            return System.Text.Encoding.ASCII.GetString( bytes );
        }
        protected string HandleDBValidationError( System.Data.Entity.Validation.DbEntityValidationException dbex, string source, string title )
        {
            string message = string.Format( "{0} DbEntityValidationException, Name: {1}", source, title );

            foreach ( var eve in dbex.EntityValidationErrors )
            {
                message += string.Format( "\rEntity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                    eve.Entry.Entity.GetType().Name, eve.Entry.State );
                foreach ( var ve in eve.ValidationErrors )
                {
                    message += string.Format( "- Property: \"{0}\", Error: \"{1}\"",
                        ve.PropertyName, ve.ErrorMessage );
                }

                LoggingHelper.LogError( message, true );
            }

            return message;
        }

        public static string FormatExceptions( Exception ex )
        {
            string message = ex.Message;

            if ( ex.InnerException != null )
            {
                message += FormatExceptions( ex );
            }

            return message;
        }

        /// <summary>
        /// Strip off text that is randomly added that starts with jquery
        /// Will need additional check for numbers - determine actual format
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string StripJqueryTag( string text )
        {
            int pos2 = text.ToLower().IndexOf( "jquery" );
            if ( pos2 > 1 )
            {
                text = text.Substring( 0, pos2 );
            }

            return text;
        }

    }
}


text:
define([],
  function() {

    var xml = {
      // summary:
      //   Methods to aid with XML.

      escape: function(/*String*/ str, /*Boolean?*/ doNotEscapeSingleQuotes, /*String?*/ missing) {
        // summary:
        //	 Adds escape sequences for special characters in XML: `&<>"'`.
        //	 Optionally skips escapes for single quotes.
        //   str is coerced to string with `toString`
        // doNotEscapeSingleQuotes: Boolean?
        //   Do not escape single quotes when this is true.
        // missing: String?
        //   When str is undefined, or null, we return missing. The default is the empty string.
        // description:
        //   Nicked from dijit/_editor/html.
        //   When str is undefined or null, return "".
        //   Actual non-string values are coerced to a string.

        if (!str && str !== "0") { // 0 must pass
          return missing || "";
        }
        var s = "" + str; // coerce to string
        s = s.replace(/&/gm, "&").replace(/</gm, "<").replace(/>/gm, ">").replace(/"/gm, """);
        if (!doNotEscapeSingleQuotes) {
          s = s.replace(/'/gm, "'");
        }
        return s; // string
      }

    };

    return xml;
  }
);


text:
angular.module('videowaypointsModule',[])
    .directive('videoplayer', function ($location,$log) {
      return {
        restrict: 'C', //E = element, A = attribute, C = class, M = comment
        scope: {}, //new scope
        link: function ($scope, element, attrs) {

            /***** page hidden logic *****/
            // Set the name of the hidden property and the change event for visibility
            var hidden, visibilityChange;
            if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
                hidden = "hidden";
                visibilityChange = "visibilitychange";
            } else if (typeof document.mozHidden !== "undefined") {
                hidden = "mozHidden";
                visibilityChange = "mozvisibilitychange";
            } else if (typeof document.msHidden !== "undefined") {
                hidden = "msHidden";
                visibilityChange = "msvisibilitychange";
            } else if (typeof document.webkitHidden !== "undefined") {
                hidden = "webkitHidden";
                visibilityChange = "webkitvisibilitychange";
            }

            /*************
             * If the page is hidden, pause the video;
             * the page is shown, play the video
             */
            function handleVisibilityChange() {
                if (document[hidden]) {
                    element[0].pause();
                } else {
                    element[0].play();
                }
            }

            element.on('$destroy', function () {
                document.removeEventListener(visibilityChange, handleVisibilityChange, false);
                $log.debug("visibilityChange event listener distroyed");
            });

            // Warn if the browser doesn't support addEventListener or the Page Visibility API
            if (typeof document.addEventListener === "undefined" || typeof document[hidden] === "undefined") {
                $log.info("The hide feature requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.");
            } else {
                // Handle page visibility change
                document.addEventListener(visibilityChange, handleVisibilityChange, false);
            }

            /***** END page hidden logic *****/

            /***** Waypoint logic *****/
            if(typeof $(element[0]).data("videowaypointsstopwhenoutofview") != "undefined") {
                $(element[0]).waypoint(function (direction) {
                    if (direction === "down") {
                        //$log.debug("waypoint on video-area down hit");
                        element[0].pause();
                    }
                }, {
                    offset: function () {
                        //when this is init the video area has no size so we need to use the placeholder image
                        return -$(element[0]).height();
                    }
                });
                $(element[0]).data("waypointsSet",true);
            }

            if(typeof $(element[0]).data("videowaypointsstartwheninview") != "undefined") {
                $(element[0]).waypoint(function (direction) {
                    if (direction === "up") {
                        //$log.debug("waypoint on video-area up hit");
                        element[0].play();
                    }
                }, {
                    offset: function () {
                        //when this is init the video area has no size so we need to use the placeholder image
                        return -$(element[0]).height();
                    }
                });
                $(element[0]).data("waypointsSet",true);
            }
            /***** Waypoint logic END*****/

            /***
             * if the avs attribute is set lets look at the sources listed and figure out which ones we need to enable
             */
        }
      }
    });


text:
package ranger

import (
	"github.com/pingcap/tidb/ast"
	"github.com/pingcap/tidb/expression"
	"github.com/pingcap/tidb/model"
	"github.com/pingcap/tidb/sessionctx"
	"github.com/pingcap/tidb/types"
	"github.com/pkg/errors"
)

// detachColumnCNFConditions detaches the condition for calculating range from the other conditions.
// Please make sure that the top level is CNF form.
func detachColumnCNFConditions(sctx sessionctx.Context, conditions []expression.Expression, checker *conditionChecker) ([]expression.Expression, []expression.Expression) {
	var accessConditions, filterConditions []expression.Expression
	for _, cond := range conditions {
		if sf, ok := cond.(*expression.ScalarFunction); ok && sf.FuncName.L == ast.LogicOr {
			dnfItems := expression.FlattenDNFConditions(sf)
			colulmnDNFItems, hasResidual := detachColumnDNFConditions(sctx, dnfItems, checker)
			// If this CNF has expression that cannot be resolved as access condition, then the total DNF expression
			// should be also appended into filter condition.
			if hasResidual {
				filterConditions = append(filterConditions, cond)
			}
			if len(colulmnDNFItems) == 0 {
				continue
			}
			rebuildDNF := expression.ComposeDNFCondition(sctx, colulmnDNFItems...)
			accessConditions = append(accessConditions, rebuildDNF)
			continue
		}
		if !checker.check(cond) {
			filterConditions = append(filterConditions, cond)
			continue
		}
		accessConditions = append(accessConditions, cond)
		if checker.shouldReserve {
			filterConditions = append(filterConditions, cond)
			checker.shouldReserve = checker.length != types.UnspecifiedLength
		}
	}
	return accessConditions, filterConditions
}

// detachColumnDNFConditions detaches the condition for calculating range from the other conditions.
// Please make sure that the top level is DNF form.
func detachColumnDNFConditions(sctx sessionctx.Context, conditions []expression.Expression, checker *conditionChecker) ([]expression.Expression, bool) {
	var (
		hasResidualConditions bool
		accessConditions      []expression.Expression
	)
	for _, cond := range conditions {
		if sf, ok := cond.(*expression.ScalarFunction); ok && sf.FuncName.L == ast.LogicAnd {
			cnfItems := expression.FlattenCNFConditions(sf)
			columnCNFItems, others := detachColumnCNFConditions(sctx, cnfItems, checker)
			if len(others) > 0 {
				hasResidualConditions = true
			}
			// If one part of DNF has no access condition. Then this DNF cannot get range.
			if len(columnCNFItems) == 0 {
				return nil, true
			}
			rebuildCNF := expression.ComposeCNFCondition(sctx, columnCNFItems...)
			accessConditions = append(accessConditions, rebuildCNF)
		} else if checker.check(cond) {
			accessConditions = append(accessConditions, cond)
			if checker.shouldReserve {
				hasResidualConditions = true
				checker.shouldReserve = checker.length != types.UnspecifiedLength
			}
		} else {
			return nil, true
		}
	}
	return accessConditions, hasResidualConditions
}

// getEqOrInColOffset checks if the expression is a eq function that one side is constant and another is column or an
// in function which is `column in (constant list)`.
// If so, it will return the offset of this column in the slice, otherwise return -1 for not found.
func getEqOrInColOffset(expr expression.Expression, cols []*expression.Column) int {
	f, ok := expr.(*expression.ScalarFunction)
	if !ok {
		return -1
	}
	if f.FuncName.L == ast.EQ {
		if c, ok := f.GetArgs()[0].(*expression.Column); ok {
			if _, ok := f.GetArgs()[1].(*expression.Constant); ok {
				for i, col := range cols {
					if col.Equal(nil, c) {
						return i
					}
				}
			}
		}
		if c, ok := f.GetArgs()[1].(*expression.Column); ok {
			if _, ok := f.GetArgs()[0].(*expression.Constant); ok {
				for i, col := range cols {
					if col.Equal(nil, c) {
						return i
					}
				}
			}
		}
	}
	if f.FuncName.L == ast.In {
		c, ok := f.GetArgs()[0].(*expression.Column)
		if !ok {
			return -1
		}
		for _, arg := range f.GetArgs()[1:] {
			if _, ok := arg.(*expression.Constant); !ok {
				return -1
			}
		}
		for i, col := range cols {
			if col.Equal(nil, c) {
				return i
			}
		}
	}
	return -1
}

// detachCNFCondAndBuildRangeForIndex will detach the index filters from table filters. These conditions are connected with `and`
// It will first find the point query column and then extract the range query column.
// considerDNF is true means it will try to extract access conditions from the DNF expressions.
func detachCNFCondAndBuildRangeForIndex(sctx sessionctx.Context, conditions []expression.Expression, cols []*expression.Column,
	tpSlice []*types.FieldType, lengths []int, considerDNF bool) ([]*Range, []expression.Expression, []expression.Expression, int, error) {
	var (
		eqCount int
		ranges  []*Range
		err     error
	)

	accessConds, filterConds, newConditions, emptyRange := extractEqAndInCondition(sctx, conditions, cols, lengths)
	if emptyRange {
		return ranges, nil, nil, 0, nil
	}

	for ; eqCount < len(accessConds); eqCount++ {
		if accessConds[eqCount].(*expression.ScalarFunction).FuncName.L != ast.EQ {
			break
		}
	}
	// We should remove all accessConds, so that they will not be added to filter conditions.
	newConditions = removeAccessConditions(newConditions, accessConds)
	eqOrInCount := len(accessConds)
	if eqOrInCount == len(cols) {
		// If curIndex equals to len of index columns, it means the rest conditions haven't been appended to filter conditions.
		filterConds = append(filterConds, newConditions...)
		ranges, err = buildCNFIndexRange(sctx.GetSessionVars().StmtCtx, cols, tpSlice, lengths, eqOrInCount, accessConds)
		if err != nil {
			return nil, nil, nil, 0, errors.Trace(err)
		}
		return ranges, accessConds, filterConds, eqCount, nil
	}
	checker := &conditionChecker{
		colName:       cols[eqOrInCount].ColName,
		length:        lengths[eqOrInCount],
		shouldReserve: lengths[eqOrInCount] != types.UnspecifiedLength,
	}
	if considerDNF {
		accesses, filters := detachColumnCNFConditions(sctx, newConditions, checker)
		accessConds = append(accessConds, accesses...)
		filterConds = append(filterConds, filters...)
	} else {
		for _, cond := range newConditions {
			if !checker.check(cond) {
				filterConds = append(filterConds, cond)
				continue
			}
			accessConds = append(accessConds, cond)
		}
	}
	ranges, err = buildCNFIndexRange(sctx.GetSessionVars().StmtCtx, cols, tpSlice, lengths, eqOrInCount, accessConds)
	return ranges, accessConds, filterConds, eqCount, errors.Trace(err)
}

func extractEqAndInCondition(sctx sessionctx.Context, conditions []expression.Expression,
	cols []*expression.Column, lengths []int) ([]expression.Expression, []expression.Expression, []expression.Expression, bool) {
	var filters []expression.Expression
	rb := builder{sc: sctx.GetSessionVars().StmtCtx}
	accesses := make([]expression.Expression, len(cols))
	points := make([][]point, len(cols))
	mergedAccesses := make([]expression.Expression, len(cols))
	newConditions := make([]expression.Expression, 0, len(conditions))
	for _, cond := range conditions {
		offset := getEqOrInColOffset(cond, cols)
		if offset == -1 {
			newConditions = append(newConditions, cond)
			continue
		}
		if accesses[offset] == nil {
			accesses[offset] = cond
			continue
		}
		// Multiple Eq/In conditions for one column in CNF, apply intersection on them
		// Lazily compute the points for the previously visited Eq/In
		if mergedAccesses[offset] == nil {
			mergedAccesses[offset] = accesses[offset]
			points[offset] = rb.build(accesses[offset])
		}
		points[offset] = rb.intersection(points[offset], rb.build(cond))
		// Early termination if false expression found
		if len(points[offset]) == 0 {
			return nil, nil, nil, true
		}
	}
	for i, ma := range mergedAccesses {
		if ma == nil {
			if accesses[i] != nil {
				newConditions = append(newConditions, accesses[i])
			}
			continue
		}
		accesses[i] = points2EqOrInCond(sctx, points[i], mergedAccesses[i])
		newConditions = append(newConditions, accesses[i])
	}
	for i, cond := range accesses {
		if cond == nil {
			accesses = accesses[:i]
			break
		}
		if lengths[i] != types.UnspecifiedLength {
			filters = append(filters, cond)
		}
	}
	return accesses, filters, newConditions, false
}

// detachDNFCondAndBuildRangeForIndex will detach the index filters from table filters when it's a DNF.
// We will detach the conditions of every DNF items, then compose them to a DNF.
func detachDNFCondAndBuildRangeForIndex(sctx sessionctx.Context, condition *expression.ScalarFunction,
	cols []*expression.Column, newTpSlice []*types.FieldType, lengths []int) ([]*Range, []expression.Expression, bool, error) {
	sc := sctx.GetSessionVars().StmtCtx
	firstColumnChecker := &conditionChecker{
		colName:       cols[0].ColName,
		shouldReserve: lengths[0] != types.UnspecifiedLength,
		length:        lengths[0],
	}
	rb := builder{sc: sc}
	dnfItems := expression.FlattenDNFConditions(condition)
	newAccessItems := make([]expression.Expression, 0, len(dnfItems))
	var totalRanges []*Range
	hasResidual := false
	for _, item := range dnfItems {
		if sf, ok := item.(*expression.ScalarFunction); ok && sf.FuncName.L == ast.LogicAnd {
			cnfItems := expression.FlattenCNFConditions(sf)
			var accesses, filters []expression.Expression
			ranges, accesses, filters, _, err := detachCNFCondAndBuildRangeForIndex(sctx, cnfItems, cols, newTpSlice, lengths, true)
			if err != nil {
				return nil, nil, false, nil
			}
			if len(accesses) == 0 {
				return FullRange(), nil, true, nil
			}
			if len(filters) > 0 {
				hasResidual = true
			}
			totalRanges = append(totalRanges, ranges...)
			newAccessItems = append(newAccessItems, expression.ComposeCNFCondition(sctx, accesses...))
		} else if firstColumnChecker.check(item) {
			if firstColumnChecker.shouldReserve {
				hasResidual = true
				firstColumnChecker.shouldReserve = lengths[0] != types.UnspecifiedLength
			}
			points := rb.build(item)
			ranges, err := points2Ranges(sc, points, newTpSlice[0])
			if err != nil {
				return nil, nil, false, errors.Trace(err)
			}
			totalRanges = append(totalRanges, ranges...)
			newAccessItems = append(newAccessItems, item)
		} else {
			return FullRange(), nil, true, nil
		}
	}

	totalRanges, err := unionRanges(sc, totalRanges)
	if err != nil {
		return nil, nil, false, errors.Trace(err)
	}

	return totalRanges, []expression.Expression{expression.ComposeDNFCondition(sctx, newAccessItems...)}, hasResidual, nil
}

// DetachCondAndBuildRangeForIndex will detach the index filters from table filters.
// If the top layer is DNF, we return a int slice which is eqAndInCount of every DNF item.
// Otherwise just one number is returned.
func DetachCondAndBuildRangeForIndex(sctx sessionctx.Context, conditions []expression.Expression, cols []*expression.Column,
	lengths []int) ([]*Range, []expression.Expression, []expression.Expression, int, error) {
	newTpSlice := make([]*types.FieldType, 0, len(cols))
	for _, col := range cols {
		newTpSlice = append(newTpSlice, newFieldType(col.RetType))
	}
	if len(conditions) == 1 {
		if sf, ok := conditions[0].(*expression.ScalarFunction); ok && sf.FuncName.L == ast.LogicOr {
			ranges, accesses, hasResidual, err := detachDNFCondAndBuildRangeForIndex(sctx, sf, cols, newTpSlice, lengths)
			if err != nil {
				return nil, nil, nil, 0, errors.Trace(err)
			}
			// If this DNF have something cannot be to calculate range, then all this DNF should be pushed as filter condition.
			if hasResidual {
				return ranges, accesses, conditions, 0, nil
			}
			return ranges, accesses, nil, 0, nil
		}
	}
	return detachCNFCondAndBuildRangeForIndex(sctx, conditions, cols, newTpSlice, lengths, true)
}

// DetachSimpleCondAndBuildRangeForIndex will detach the index filters from table filters.
// It will find the point query column firstly and then extract the range query column.
func DetachSimpleCondAndBuildRangeForIndex(sctx sessionctx.Context, conditions []expression.Expression,
	cols []*expression.Column, lengths []int) (ranges []*Range, accessConds []expression.Expression, err error) {
	newTpSlice := make([]*types.FieldType, 0, len(cols))
	for _, col := range cols {
		newTpSlice = append(newTpSlice, newFieldType(col.RetType))
	}
	ranges, accessConds, _, _, err = detachCNFCondAndBuildRangeForIndex(sctx, conditions, cols, newTpSlice, lengths, false)
	return ranges, accessConds, nil
}

func removeAccessConditions(conditions, accessConds []expression.Expression) []expression.Expression {
	filterConds := make([]expression.Expression, 0, len(conditions))
	for _, cond := range conditions {
		if !expression.Contains(accessConds, cond) {
			filterConds = append(filterConds, cond)
		}
	}
	return filterConds
}

// ExtractAccessConditionsForColumn detaches the access conditions used for range calculation.
func ExtractAccessConditionsForColumn(conds []expression.Expression, colName model.CIStr) []expression.Expression {
	if colName.L == "" {
		return nil
	}
	checker := conditionChecker{
		colName: colName,
		length:  types.UnspecifiedLength,
	}
	accessConds := make([]expression.Expression, 0, 8)
	return expression.Filter(accessConds, conds, checker.check)
}

// DetachCondsForTableRange detaches the conditions used for range calculation form other useless conditions for
// calculating the table range.
func DetachCondsForTableRange(sctx sessionctx.Context, conds []expression.Expression, col *expression.Column) (accessContditions, otherConditions []expression.Expression) {
	checker := &conditionChecker{
		colName: col.ColName,
		length:  types.UnspecifiedLength,
	}
	return detachColumnCNFConditions(sctx, conds, checker)
}


text:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Xml;
using Magecrawl.Utilities;

namespace Magecrawl.GameEngine.Skills
{
    internal class SkillFactory
    {
        public static readonly SkillFactory Instance = new SkillFactory();

        private static Dictionary<string, Skill> m_skillMapping;

        private SkillFactory()
        {
            LoadMappings();
        }

        public Skill CreateSkill(string skillName)
        {
            return m_skillMapping[skillName];
        }

        public IEnumerable<Skill> GetAllSkills()
        {
            return m_skillMapping.Values;
        }

        private void LoadMappings()
        {
            m_skillMapping = new Dictionary<string, Skill>();
            XMLResourceReaderBase.ParseFile("Skills.xml", ReadFileCallback);
        }

        private void ReadFileCallback(XmlReader reader, object data)
        {
            if (reader.LocalName != "Skills")
                throw new System.InvalidOperationException("Bad skill defination file");

            bool insideSkillNode = false;
            Skill lastSkill = null;
            string attributeName = null;
            while (true)
            {
                reader.Read();
                if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "Skills")
                    break;

                if (reader.LocalName == "Skill")
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        insideSkillNode = true;

                        string name = reader.GetAttribute("Name");
                        string school = reader.GetAttribute("School");
                        string description = reader.GetAttribute("Description");

                        string costString = reader.GetAttribute("Cost");
                        int cost = int.Parse(costString);

                        Skill newSkill = new Skill(name, cost, school, description);
                        lastSkill = newSkill;

                        m_skillMapping.Add(name, newSkill);
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        insideSkillNode = false;
                        lastSkill = null;
                    }
                }
                else if (insideSkillNode)
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        attributeName = reader.Name;
                        lastSkill.Attributes[attributeName] = null;
                    }
                    else if (reader.NodeType == XmlNodeType.Text)
                    {
                        lastSkill.Attributes[attributeName] = reader.Value;
                        attributeName = null;
                    }
                }
            }
        }
    }
}