public
override
ViewEngineResult FindPartialView(ControllerContext controllerContext,
string
partialViewName,
bool
useCache)
{
string
[] strArray;
if
(controllerContext
==
null
)
{
throw
new
ArgumentNullException(
"
controllerContext
"
);
}
if
(
string
.IsNullOrEmpty(partialViewName))
{
throw
new
ArgumentException(
"
MvcResources.Common_NullOrEmpty
"
,
"
partialViewName
"
);
}
string
requiredString
=
controllerContext.RouteData.GetRequiredString(
"
controller
"
);
//
string vp = this.GetParam(controllerContext, "viewpath");
//
if (!string.IsNullOrEmpty(vp))
//
{
//
requiredString = vp;
//
}
string
str2
=
this
.GetPath(controllerContext,
this
.PartialViewLocationFormats,
"
PartialViewLocationFormats
"
, partialViewName, requiredString,
"
Partial
"
,
useCache,
false
,
out
strArray);
if
(
string
.IsNullOrEmpty(str2))
{
return
new
ViewEngineResult(strArray);
}
return
new
ViewEngineResult(
this
.CreatePartialView(controllerContext, str2),
this
);
}
public
override
ViewEngineResult FindView(ControllerContext controllerContext,
string
viewName,
string
masterName,
bool
useCache)
{
string
[] strArray;
string
[] strArray2;
if
(controllerContext
==
null
)
{
throw
new
ArgumentNullException(
"
controllerContext
"
);
}
if
(
string
.IsNullOrEmpty(viewName))
{
throw
new
ArgumentException(
"
ArgumentException
"
,
"
viewName
"
);
}
string
requiredString
=
controllerContext.RouteData.GetRequiredString(
"
controller
"
);
//
string vp=this.GetParam(controllerContext, "viewpath");
//
if (!string.IsNullOrEmpty(vp))
//
{
//
requiredString = vp;
//
}
string
str2
=
this
.GetPath(controllerContext,
this
.ViewLocationFormats,
"
ViewLocationFormats
"
, viewName, requiredString,
"
View
"
, useCache,
true
,
out
strArray);
string
str3
=
this
.GetPath(controllerContext,
this
.MasterLocationFormats,
"
MasterLocationFormats
"
, masterName, requiredString,
"
Master
"
, useCache,
true
,
out
strArray2);
if
(
string
.IsNullOrEmpty(str2)
||
(
string
.IsNullOrEmpty(str3)
&&
!
string
.IsNullOrEmpty(masterName)))
{
return
new
ViewEngineResult(strArray.Union
<
string
>
(strArray2));
}
return
new
ViewEngineResult(
this
.CreateView(controllerContext, str2, str3),
this
);
}
private
string
GetParam(ControllerContext controllerContext,
string
key)
{
return
controllerContext.RouteData.Values[key]
!=
null
?
controllerContext.RouteData.Values[key].ToString() :
string
.Empty;
}
private
string
GetPath(ControllerContext controllerContext,
string
[] locations,
string
locationsPropertyName,
string
name,
string
controllerName,
string
cacheKeyPrefix,
bool
useCache,
bool
isfindview,
out
string
[] searchedLocations)
{
searchedLocations
=
_emptyLocations;
if
(
string
.IsNullOrEmpty(name))
{
return
string
.Empty;
}
if
((locations
==
null
)
||
(locations.Length
==
0
))
{
throw
new
InvalidOperationException(
string
.Format(CultureInfo.CurrentUICulture,
"
MvcResources.Common_PropertyCannotBeNullOrEmpty
"
,
new
object
[] {
locationsPropertyName }));
}
bool
flag
=
IsSpecificPath(name);
string
key
=
this
.CreateCacheKey(cacheKeyPrefix, name, flag
?
string
.Empty : controllerName);
if
(useCache)
{
string
viewLocation
=
this
.ViewLocationCache.GetViewLocation(controllerContext.HttpContext, key);
if
(viewLocation
!=
null
)
{
return
viewLocation;
}
}
return
(flag
?
this
.GetPathFromSpecificName(controllerContext, name, key,isfindview ,
ref
searchedLocations) :
this
.GetPathFromGeneralName(controllerContext,
locations, name, controllerName, key,isfindview ,
ref
searchedLocations));
}
private
string
CreateCacheKey(
string
prefix,
string
name,
string
controllerName)
{
return
string
.Format(CultureInfo.InvariantCulture,
"
:ViewCacheEntry:{0}:{1}:{2}:{3}:
"
,
new
object
[] {
base
.GetType().AssemblyQualifiedName, prefix, name,
controllerName });
}
private
static
bool
IsSpecificPath(
string
name)
{
char
ch
=
name[
0
];
return
((ch
==
'
~
'
)
||
(ch
==
'
/
'
));
}
private
string
GetPathFromSpecificName(ControllerContext controllerContext,
string
name,
string
cacheKey,
bool
isfindview,
ref
string
[] searchedLocations)
{
string
virtualPath
=
name;
if
(
!
this
.FileExists(controllerContext, name))
{
if
(isfindview)
{
string
vp
=
this
.GetParam(controllerContext,
"
viewpath
"
);
if
(
!
string
.IsNullOrEmpty(vp))
{
virtualPath
=
vp;
}
if
(
string
.IsNullOrEmpty(virtualPath))
{
virtualPath
=
string
.Empty;
searchedLocations
=
new
string
[] { name };
}
}
else
{
virtualPath
=
string
.Empty;
searchedLocations
=
new
string
[] { name };
}
}
this
.ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, cacheKey, virtualPath);
return
virtualPath;
}
private
string
GetPathFromGeneralName(ControllerContext controllerContext,
string
[] locations,
string
name,
string
controllerName,
string
cacheKey,
bool
isfindview,
ref
string
[] searchedLocations)
{
string
virtualPath
=
string
.Empty;
searchedLocations
=
new
string
[locations.Length];
for
(
int
i
=
0
; i
<
locations.Length; i
++
)
{
string
str2
=
string
.Format(CultureInfo.InvariantCulture, locations[i],
new
object
[] { name, controllerName });
if
(
this
.FileExists(controllerContext, str2))
{
searchedLocations
=
_emptyLocations;
virtualPath
=
str2;
this
.ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, cacheKey, virtualPath);
return
virtualPath;
}
else
{
if
(isfindview)
{
string
vp
=
this
.GetParam(controllerContext,
"
viewpath
"
);
if
(
!
string
.IsNullOrEmpty(vp))
{
searchedLocations
=
_emptyLocations;
virtualPath
=
vp;
return
virtualPath;
}
}
}
searchedLocations[i]
=
str2;
}
return
virtualPath;
}