コード例 #1
0
 /// <summary>
 /// 得到生成后的文件路径
 /// </summary>
 /// <param name="absoluteFilePath">绝对路径</param>
 /// <returns>返回要生成静态文件的物理路径</returns>
 internal static string GenerateFilePath(string absoluteFilePath)
 {
     if (absoluteFilePath.IndexOf("/") == 0 && absoluteFilePath.Length > 1)
     {
         absoluteFilePath = absoluteFilePath.Substring(1);
     }
     return(IOHelper.CombinePath(NVelocityBus._StaticFileDirectory, absoluteFilePath.Replace('/', '\\')));
 }
コード例 #2
0
 /// <summary>
 ///     获取配置文件的服务器物理文件路径
 /// </summary>
 /// <typeparam name="T">配置信息类</typeparam>
 /// <returns>配置文件路径</returns>
 public static string GetConfigPath <T>(string path)
 {
     if (string.IsNullOrWhiteSpace(path))
     {
         return(IOHelper.CombinePath(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), "Config", $"{typeof(T).Name }.config"));
     }
     else
     {
         return(IOHelper.CombinePath(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), "Config", path, $"{typeof(T).Name }.config"));
     }
 }
コード例 #3
0
        /// <summary>
        /// 获取Lucene目录
        /// </summary>
        /// <returns></returns>
        public static string GetLuceneDirectory()
        {
            string luceneDirectory = null;

            if (LuceneDirectory.LastIndexOf(Lucene_1_Directory) > 0)
            {
                luceneDirectory = LuceneDirectory.Replace(Lucene_1_Directory, Lucene_2_Directory);
            }
            else if (LuceneDirectory.LastIndexOf(Lucene_2_Directory) > 0)
            {
                luceneDirectory = LuceneDirectory.Replace(Lucene_2_Directory, Lucene_1_Directory);
            }
            else
            {
                luceneDirectory = IOHelper.CombinePath(LuceneDirectory, Lucene_1_Directory);
            }
            Global.Logger.LogWithTime("GetLuceneDirectory()::luceneDirectory=" + luceneDirectory, Logger.ELogLevel.Trace);
            return(luceneDirectory);
        }
コード例 #4
0
        public static void RenderJs(RenderContext Context, JsTestOption option, string root, RenderRespnose response, JsTestCommand command)
        {
            response.ContentType = "application/javascript";

            if (!string.IsNullOrEmpty(command.JsPath))
            {
                string filename = command.JsPath.Replace("/", "\\");

                if (filename.IndexOf("?") > -1)
                {
                    filename = filename.Substring(0, filename.IndexOf("?"));
                }

                if (filename.StartsWith("\\"))
                {
                    filename = filename.Substring(1);
                }

                string fullname = root;
                string prepath  = option.FolderPath(Context);

                if (!string.IsNullOrEmpty(prepath))
                {
                    fullname = IOHelper.CombinePath(root, prepath);
                }

                fullname = IOHelper.CombinePath(fullname, filename);


                if (!System.IO.File.Exists(fullname))
                {
                    // This is to make sure the render of assert js...
                    foreach (var item in option.AssertJs)
                    {
                        if (filename.EndsWith(item))
                        {
                            fullname = System.IO.Path.Combine(Kooboo.Data.AppSettings.RootPath, "/_admin/kbtest/" + item);
                        }
                    }
                }

                if (System.IO.File.Exists(fullname))
                {
                    string baserelarive = GetRelative(prepath, command.JsPath);


                    if (command.Command == JsTestCommand.JsCommand.run)
                    {
                        string retryurl  = string.Empty;
                        string rawfolder = filename;
                        int    lastslash = rawfolder.LastIndexOf("\\");
                        if (lastslash > -1)
                        {
                            string folder     = rawfolder.Substring(0, lastslash);
                            string jsfilename = rawfolder.Substring(lastslash + 1);
                            retryurl = GenerateUrl(option, JsTestCommand.JsCommand.run, folder, jsfilename);
                        }

                        // TODO: Render the k commands.
                        var alltext = IOHelper.ReadAllText(fullname);
                        alltext = RenderServerSide(alltext, root, Context, baserelarive);

                        response.Body = RenderJs(option, alltext, command.Function, retryurl);
                    }
                    else
                    {
                        var alltext = IOHelper.ReadAllText(fullname);
                        alltext = RenderServerSide(alltext, root, Context, baserelarive);

                        response.Body = alltext;
                    }
                }
            }
        }
コード例 #5
0
        public static string Build(List <string> cultures)
        {
            string message = null;

            if (!IsBuilding)
            {
                IsBuilding = true;
                string luceneDirectory = GetLuceneDirectory();
                LuceneNetConfig.LuceneDirectory     = luceneDirectory;
                LuceneNetConfig.LuceneDictDirectory = LuceneDictDirectory;
                string        luceneBuildDir = null;
                Directory     directory      = null;
                IndexWriter   indexWriter    = null;
                ColumnField[] columnFields   = GetColumnFields();
                List <View_seo_keys_culture> viewSEOKeysCultureList = SelectAllViewSEOKeysCulture();
                foreach (string culture in cultures)
                {
                    luceneBuildDir = IOHelper.CombinePath(luceneDirectory, culture.ToUpper());
                    IOHelper.ClearDirectory(luceneBuildDir);
                    directory = LuceneBus.GetDirectory(luceneBuildDir);
                    if (LuceneBus.IsLocked(directory))
                    {
                        LuceneBus.UnLock(directory);
                    }
                    try
                    {
                        indexWriter = LuceneBus.GetWriter(culture, directory);
                        //http://blog.jobbole.com/80464/
                        int pageCount = Select(culture);
                        if (pageCount > 0)
                        {
                            int spuID = 0;
                            List <LuceneSpuModel> luceneSpuModelList = null;
                            for (int pageIndex = 1; pageIndex <= pageCount; pageIndex++)
                            {
                                luceneSpuModelList = Select(viewSEOKeysCultureList, culture, ref spuID);
                                if (luceneSpuModelList != null && luceneSpuModelList.Count > 0)
                                {
                                    LuceneBus.Insert <LuceneSpuModel>(indexWriter, luceneSpuModelList, columnFields);
                                    luceneSpuModelList.Clear();
                                    luceneSpuModelList = null;
                                }
                                else
                                {
                                    break;
                                }
                            }
                            if (luceneSpuModelList != null)
                            {
                                if (luceneSpuModelList.Count > 0)
                                {
                                    luceneSpuModelList.Clear();
                                }
                                luceneSpuModelList = null;
                            }
                            LuceneBus.MaybeMerge(indexWriter);
                            LuceneBus.Commit(indexWriter);
                        }
                    }
                    catch (Exception ex)
                    {
                        message = "Build(Language[] cultures)出现错误,错误信息:" + ex.Message;
                    }
                    finally
                    {
                        if (indexWriter != null)
                        {
                            LuceneBus.Close(indexWriter);
                            indexWriter = null;
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(message))
                    {
                        break;
                    }
                }
                Change();//索引生成完切换前台搜索目录
                if (columnFields != null)
                {
                    Array.Clear(columnFields, 0, columnFields.Length);
                    columnFields = null;
                }
                IsBuilding = false;
            }
            return(message);
        }