コード例 #1
0
        private static RankedLanguageIdentifier CreateIdentifier()
        {
            var factory = new RankedLanguageIdentifierFactory();
            var identifierProfilePath =
                RankedLanguageIdentifierFactory.GetSetting("LanguageIdentificationProfileFilePath", (string)null);
            string mappedPath = null;

            if (identifierProfilePath != null && System.IO.File.Exists(identifierProfilePath) == false)
            {
                Log.DebugFormat("Cannot find a profile in the following path: '{0}'. Trying HostingEnvironment.MapPath", identifierProfilePath);
                mappedPath = HostingEnvironment.MapPath(identifierProfilePath);
            }
            var finalPath = mappedPath ?? identifierProfilePath;

            if (finalPath == null || System.IO.File.Exists(finalPath) == false)
            {
                Log.DebugFormat("Cannot find a profile in the following path: '{0}'.", finalPath);
                throw new InvalidOperationException(string.Format("Cannot find a profile in the following path: '{0}'.", finalPath));
            }
            var identifier = factory.Load(finalPath);

            return(identifier);
        }