📄 sectionutility.cs
字号:
//
// CalculateTransformations Method
//
// Precooks transformations for this section.
//
//*********************************************************************
public static string CalculateTransformations(DataRow drowSection, DataSet dstSections) {
string transformations;
string trans;
StringBuilder builder = new StringBuilder();
// Check for inheritance
if ((bool)drowSection["section_inheritTransformations"])
transformations = GetInheritedTransformations( (int)drowSection[ "section_id" ], dstSections );
else
transformations = (string)drowSection["section_transformations"];
// Trim and split transformations
transformations = transformations.Trim();
string[] splitTrans = Regex.Split(transformations, "\n");
// Parse the transformations
foreach (string line in splitTrans) {
trans = line;
if (trans.ToLower().StartsWith("from:"))
{
trans = trans.Remove(0, 5).Trim();
trans = Regex.Escape(trans);
trans = trans.Replace("<CONTENTS>", @"((.|\n)*?)");
trans = trans.Replace("<WORDBOUNDARY>", @"\b");
trans = trans.Replace("<", "<");
trans = trans.Replace(">", ">");
trans = trans.Replace("\"", """);
}
if (trans.ToLower().StartsWith("to:")) {
trans = trans.Remove(0, 3).Trim();
trans = trans.Replace("<CONTENTS>", "$1");
trans = trans.Replace( "~/", CommunityGlobals.AppPath + "/Communities/Common/Images/");
}
builder.AppendFormat("{0}\n", trans);
}
return builder.ToString();
}
//*********************************************************************
//
// GetInheritedTransformations Method
//
// Calculates the inherited transformations for a section.
//
//*********************************************************************
public static string GetInheritedTransformations(int intSectionID, DataSet dstSections) {
DataRow[] drowMatches;
string matchString;
matchString = "section_id=" + intSectionID.ToString();
drowMatches = dstSections.Tables[0].Select( matchString );
while ( ((bool)drowMatches[0]["section_inheritTransformations"]) && (int)drowMatches[0]["section_parentID"]!=-1) {
matchString = "section_id=" + drowMatches[0]["section_parentID"].ToString();
drowMatches = dstSections.Tables[0].Select( matchString );
}
return (string)drowMatches[0]["section_transformations"];
}
//*********************************************************************
//
// GetSectionInfoFromPath Method
//
// Returns section information based on the path to a section.
//
//*********************************************************************
public static SectionInfo GetSectionInfoFromPath(string requestBasePath) {
SectionCollection sectionCollection = GetAllEnabledSections();
return sectionCollection[requestBasePath + "default.aspx"];
}
//*********************************************************************
//
// GetDefaultSectionInfo Method
//
// Returns section information for the default (home) section.
//
//*********************************************************************
public static SectionInfo GetDefaultSectionInfo() {
return GetAllEnabledSections().DefaultSection;
}
//*********************************************************************
//
// DefaultSectionID Property
//
// Returns the ID of the default (home) section.
//
//*********************************************************************
public static int DefaultSectionID {
get { return GetDefaultSectionInfo().ID; }
}
//*********************************************************************
//
// GetSectionInfoFromDB Method
//
// Gets section information by doing a database lookup.
//
//*********************************************************************
public static SectionInfo GetSectionInfoFromDB(int sectionID) {
SqlDataAdapter dadSections = new SqlDataAdapter( "Community_SectionsGetSectionInfo", CommunityGlobals.ConnectionString );
dadSections.SelectCommand.CommandType = CommandType.StoredProcedure;
dadSections.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );
dadSections.SelectCommand.Parameters.Add( "@sectionID", sectionID );
SqlDataAdapter dadSectionSecurity = new SqlDataAdapter( "Community_SectionsGetSectionRoles", CommunityGlobals.ConnectionString );
dadSectionSecurity.SelectCommand.CommandType = CommandType.StoredProcedure;
dadSectionSecurity.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );
dadSectionSecurity.SelectCommand.Parameters.Add( "@sectionID", sectionID );
SqlDataAdapter dadSectionWebBoxes = new SqlDataAdapter( "Community_SectionsGetSectionWebBoxes", CommunityGlobals.ConnectionString );
dadSectionWebBoxes.SelectCommand.CommandType = CommandType.StoredProcedure;
dadSectionWebBoxes.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );
dadSectionWebBoxes.SelectCommand.Parameters.Add( "@sectionID", sectionID );
SqlDataAdapter dadSectionWebServiceBoxes = new SqlDataAdapter( "Community_SectionsGetSectionWebServiceBoxes", CommunityGlobals.ConnectionString );
dadSectionWebServiceBoxes.SelectCommand.CommandType = CommandType.StoredProcedure;
dadSectionWebServiceBoxes.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );
dadSectionWebServiceBoxes.SelectCommand.Parameters.Add( "@sectionID", sectionID );
DataSet dstSections = new DataSet();
dadSections.Fill( dstSections, "Sections" );
dadSectionSecurity.Fill( dstSections, "Security" );
dadSectionWebBoxes.Fill( dstSections, "WebBoxes" );
dadSectionWebServiceBoxes.Fill( dstSections, "WebServiceBoxes" );
if (dstSections.Tables[0].Rows.Count > 0) {
dstSections.Tables[0].Columns.Add("section_path");
dstSections.Tables[0].Rows[0]["section_path"] = "";
return new SectionInfo( dstSections.Tables["Sections"].Rows[0], dstSections.Tables["Security"].Select(), dstSections.Tables["WebBoxes"].Select(), dstSections.Tables["WebServiceBoxes"].Select() );
}
else
return null;
}
//*********************************************************************
//
// GetSectionNameFromID Method
//
// Returns the section name given the section ID.
//
//*********************************************************************
public static string GetSectionNameFromID(int sectionID)
{
SectionInfo objSectionInfo = GetAllEnabledSections().GetSectionByID(sectionID);
return objSectionInfo.Name;
}
//*********************************************************************
//
// GetSectionPath Method
//
// Returns the path for a section with a particular ID.
//
//*********************************************************************
public static string GetSectionPath(int sectionID) {
SectionInfo objSectionInfo = GetAllEnabledSections().GetSectionByID(sectionID);
return objSectionInfo.Path;
}
//*********************************************************************
//
// GetSectionInfo Method
//
// Returns section information given a section ID.
//
//*********************************************************************
public static SectionInfo GetSectionInfo(int sectionID) {
SectionInfo objSectionInfo = GetAllEnabledSections().GetSectionByID(sectionID);
return objSectionInfo;
}
//*********************************************************************
//
// MayModerate Method
//
// Determines whether a particular user can moderate a particular
// section.
//
//*********************************************************************
public static bool MayModerate(UserInfo userInfo, int sectionID) {
SectionInfo sectionInfo = GetSectionInfo(sectionID);
// If moderation disabled, it passes
if (!sectionInfo.EnableModeration)
return true;
if (CheckAuthenticatedPermission(sectionInfo.ModerateRoles))
return true;
else
return false;
}
//*********************************************************************
//
// GetAuthenticatedPermission Method
//
// Support method for determining a user's permissions for a
// section.
//
//*********************************************************************
private static bool CheckAuthenticatedPermission(string[] sectionRoles) {
// If Everyone has permission, return true
if (Array.IndexOf( sectionRoles, "Community-Everyone" ) != -1)
return true;
// If Authenticated has permission, return true
if (Array.IndexOf( sectionRoles, "Community-Authenticated" ) != -1)
return true;
// Otherwise, check each role
foreach (string role in sectionRoles)
if (HttpContext.Current.User.IsInRole(role))
return true;
// Nope, doesn't have permissions
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -