我有两个处理程序,ArticleIndexer.ashx和MediaHighlightsIndexer.ashx。为了创建MediaHighlights,我复制了ArticleIndexer并将“article”替换为“highlght”,它们是相似的(两者之间的唯一区别是Article数据对象和MediaHighlight数据对象的属性)。当我试图运行MediaHighlightsIndexer.ashx时,我收到了这个错误:
“无法找到类型或命名空间名称'IMediaHighlightDao'(您是否缺少using指令或程序集引用?')
但ArticleIndexer.ashx没有此问题并正确运行。
这个问题会在哪里发生?这会是处理程序中的问题,还是MediaHighlightDao.cs中的问题?所有MediaHighlight文件都与文章文件位于相同的文件夹中,并且它们都具有相同的引用。
这是界面:
using MITSloan.Common.Model;
using System;
using System.Collections.Generic;
namespace MITSloan.Common.Dao
{
public interface IMediaHighlightDao
{
IEnumerable<MediaHighlight> GetHighlights(Int64 categoryId);
MediaHighlight GetHighlight(Int64 highlightId);
MediaHighlight GetHighlight(Int64 highlightId, string html);
}
}
这是处理程序:
<%@ WebHandler Language="C#" Class="MediaHighlightIndexer" %>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using Ektron.Cms;
using Ektron.Cms.Framework;
using Ektron.Cms.Framework.Organization;
using MITSloan.Common.Dao;
using MITSloan.Common.Model;
using MITSloan.Data.Dao;
using MITSloan.Search;
public class MediaHighlightIndexer : IHttpHandler {
private IndexManager _indexManager;
public IndexManager IndexManager
{
get { return _indexManager ?? (_indexManager = new IndexManager()); }
}
private static IMediaHighlightDao _mediaHighlightDao;
public static IMediaHighlightDao MediaHighlightDao
{
get { return _mediaHighlightDao ?? (_mediaHighlightDao = new MediaHighlightDao()); }
}
private static FolderManager _folderManager;
public static FolderManager FolderManager
{
get { return _folderManager ?? (_folderManager = new FolderManager(ApiAccessMode.Admin)); }
}
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string core = !String.IsNullOrEmpty(context.Request["core"]) ? context.Request["core"] : "offline";
var metadata = new Dictionary<string, object>(1);
var folderHighlights = GetHighlightsByFolderId();
foreach (var f in folderHighlights)
{
metadata["folderId"] = f.Key;
IndexManager.IndexHighlights(f.Value, metadata, core);
}
IndexManager.IndexCommit(core);
context.Response.Write("Success");
}
private Dictionary<long, IEnumerable<MediaHighlight>> GetHighlightsByFolderId()
{
long highlightFolderId;
if (!Int64.TryParse(ConfigurationManager.AppSettings["ektron.highlightFolderId"], out highlightFolderId))
{
return new Dictionary<long, IEnumerable<MediaHighlight>>();
}
//temporary hardcoded folderID for dev folder
highlightFolderId = 471;
FolderData highlightFolder = FolderManager.GetTree(highlightFolderId);
if (highlightFolder == null )
{
return new Dictionary<long, IEnumerable<MediaHighlight>>();
}
// get highlights in highlights folder
Dictionary<long, IEnumerable<MediaHighlight>> rv = new Dictionary<long, IEnumerable<MediaHighlight>>();
var highlights = MediaHighlightDao.GetHighlights(highlightFolder.Id).ToList();
rv.Add(highlightFolder.Id, highlights);
//// in case there are folders within the highlights folder, get those too
//foreach (var f in highlightFolder.ChildFolders)
//{
// highlights = highlightDao.Gethighlights(f.Id).ToList();
// rv.Add(f.Id, highlights);
//}
return rv;
//return highlightFolder.ChildFolders
// .ToDictionary(f => f.Id, f => highlightDao.Gethighlights(f.Id));
}
public bool IsReusable {
get {
return false;
}
}
}