public ShareContent GetShareContent(int targetID, out int userID, out bool isCanShare)
        {
            Photo photo = AlbumBO.Instance.GetPhoto(targetID);
            isCanShare = true;

            userID = photo.UserID;
            User author = UserBO.Instance.GetUser(userID);
            StringBuffer shareContent = new StringBuffer();

            string spaceUrl = UrlHelper.GetSpaceUrlTag(author.UserID);
            string photoUrl = UrlHelper.GetPhotoUrlTag(photo.PhotoID);

            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += photoUrl;
            shareContent += "\" title=\"";
            shareContent += photo.Name;
            shareContent += "\"><img class=\"summaryimg image\" src=\"";
            shareContent += photo.ThumbSrc;
            shareContent += "\" alt=\"";
            shareContent += photo.Name;
            shareContent += "\" onload=\"imageScale(this, 200, 200)\" onerror=\"this.style.display = 'none';\" /></a>";

            shareContent += "<div class=\"detail\">";
            shareContent += "<b><a target=\"_blank\" href=\"";
            shareContent += photoUrl;
            shareContent += "\" title=\"";
            shareContent += photo.Name;
            shareContent += "\">";
            shareContent += photo.Name;
            shareContent += "</a></b><br />";
            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += spaceUrl;
            shareContent += "\" title=\"";
            shareContent += author.Name;
            shareContent += "\">";
            shareContent += author.Name;
            shareContent += "</a><br />";
            shareContent += photo.Description;
            shareContent += "</div>";


            ShareContent content = new ShareContent();
            content.Catagory = ShareType.Picture;
            content.Content = shareContent.ToString();
            content.Title = photo.Name;
            content.URL = photoUrl;

            return content;
        }
        public ShareContent GetShareContent(int targetID, out int userID, out bool isCanShare)
        {
            userID     = 0;
            isCanShare = false;

            BlogArticle article = BlogBO.Instance.GetBlogArticle(targetID);

            if (article == null)
            {
                return(null);
            }

            isCanShare = article.PrivacyType == PrivacyType.AllVisible;

            if (!isCanShare)
            {
                userID = 0;
                return(null);
            }

            userID = article.UserID;

            User author = UserBO.Instance.GetUser(userID);

            StringBuffer shareContent = new StringBuffer();

            string spaceUrl   = UrlHelper.GetSpaceUrlTag(author.UserID);
            string articleUrl = UrlHelper.GetBlogArticleUrlTag(article.ArticleID); //"$url(" + "space/" + article.UserID + "/blog/article-" + targetID + ")";

            shareContent += "<div class=\"detail\">";
            shareContent += "<b><a target=\"_blank\" href=\"";
            shareContent += articleUrl;
            shareContent += "\" title=\"";
            shareContent += article.Subject;
            shareContent += "\">";
            shareContent += article.Subject;
            shareContent += "</a></b><br />";
            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += spaceUrl;
            shareContent += "\" title=\"";
            shareContent += author.Username;
            shareContent += "\">";
            shareContent += author.Username;
            shareContent += "</a><br />";
            shareContent += StringUtil.CutString(StringUtil.ClearAngleBracket(article.Content), Consts.Share_ReviewContentLength);
            shareContent += "</div>";

            if (string.IsNullOrEmpty(article.Thumb) == false)
            {
                shareContent += "<a target=\"_blank\" href=\"" + articleUrl;
                shareContent += "\" title=\"";
                shareContent += article.Subject;
                shareContent += "\"><img class=\"summaryimg image\" src=\"";
                shareContent += article.Thumb;
                shareContent += "\" alt=\"";
                shareContent += article.Subject;
                shareContent += "\" onload=\"imageScale(this, 100, 100)\" onerror=\"this.style.display = 'none';\"  /></a>";
            }


            ShareContent content = new ShareContent();

            content.Catagory = ShareType.Blog;
            content.Content  = shareContent.ToString();
            content.Title    = article.Subject;
            content.URL      = articleUrl;

            return(content);
        }
Exemple #3
0
		private void GenerateLoopExpressionParamAspxCode(TemplateElement node, ScopeData scopeData)
		{
			if (node.ChildNodes.Count == 2)
			{
				if (node.ChildNodes[0].Type == TemplateElementTypes.Variable)
				{
					TemplateElement variable = node.ChildNodes[0];
					TemplateElement target = node.ChildNodes[1];

					StringBuffer codeBody = new StringBuffer();

					Type returnType = null;

					switch (target.Type)
					{
						case TemplateElementTypes.Variable:
							GenerateVariableAspxCode(codeBody, target, out returnType, scopeData);
							break;

						case TemplateElementTypes.Function:
							GenerateFunctionAspxCode(codeBody, target, out returnType, scopeData);
							break;
					}

					if (returnType != null)
					{
						Type enumerType = returnType.GetInterface("IEnumerable`1");

                        if (enumerType == null)
                            enumerType = returnType.GetInterface("IEnumerator`1");

                        Type varType = null;

                        if (enumerType != null)
                            varType = enumerType.GetGenericArguments()[0];
                        else
                        {
                            if (returnType == s_TypeOfStringCollection || returnType.IsSubclassOf(s_TypeOfStringCollection))
                                varType = typeof(string);
                        }

						if (varType != null)
						{
							string varName = variable.Items[TemplateElement.KEY_NAME] as string;

							string i = node.Items["i"] as string;

							if (varName != null)
							{
								ScopeData scope = new ScopeData(scopeData);

								string iVarName = null;
								
								if(i != null)
									iVarName = scope.DeclaringScopeVariable(i, typeof(int));

                                m_CodeBody += "<%\r\nif(" + codeBody + " != null)\r\n{%>";

								if (iVarName != null)
                                    m_CodeBody += "<%\r\nint " + iVarName + "=0;\r\n%>";

                                m_CodeBody += "<%\r\nforeach(" + ReflectionUtil.GetCSharpTypeName(varType) + " " + scope.DeclaringScopeVariable(varName, varType) + " in " + codeBody + "){%>";

								GenerateAspxCode(node.Parent, scope);

                                m_CodeBody += "<%";

								if (iVarName != null)
                                    m_CodeBody += "\r\n" + iVarName + "+=1;";

                                m_CodeBody += "\r\n}\r\n}";

                                m_CodeBody += "%>";
							}
						}
					}
				}
			}
		}
Exemple #4
0
		private void GenerateAjaxPanelAspxCode(TemplateElement node, ScopeData scopeData)
		{
			TemplateElement attributeList = node.ChildNodes[0];

			string autoID = NewAjaxPanelID();

			string id = null;
			string tag = null;
			string onUpdate = null;
			string idOnly = "false";
			string ajaxOnly = "false";
			Hashtable others = new Hashtable(2);

			foreach (TemplateElement item in attributeList.ChildNodes)
			{
				string name = item.Items[TemplateElement.KEY_NAME] as string;

				name = name.ToLower();

				switch (name)
				{
					case "id":
                        StringBuffer sb = new StringBuffer();

						GenerateDoubleQuteStringAspxCode(sb, item, scopeData);

                        id = sb.ToString();
						break;

					case "tag":
						tag = item.SourceTemplate.Substring(item.Index, item.Length);
						break;

					case "idonly":
						idOnly = "true";
						break;

					case "ajaxonly":
						ajaxOnly = "true";
						break;

					case "onupdate":
						StringBuffer jscode = new StringBuffer();

						GenerateAspxCode(jscode, item, scopeData);

						onUpdate = jscode.ToString();
						break;

					default:
						StringBuffer code = new StringBuffer();

						GenerateAspxCode(code, item, scopeData);

						others.Add(name, code.ToString());
						break;
				}
			}

			if (id == null)
				id = "\"" + autoID + "\"";

			if (tag == null)
				tag = "div";

			m_CodeBody += "<" + tag + " id=\"<%=" + id + "%>\"";

			if (others.Count > 0)
			{
				foreach (DictionaryEntry item in others)
				{
					m_CodeBody += " " + item.Key + "=\"" + item.Value + "\"";
				}
			}

			m_CodeBody += ">";

            m_CodeBody += "<%\r\nusing(MaxLabs.WebEngine.AjaxPanel " + autoID + " = new MaxLabs.WebEngine.AjaxPanel(" + id + ", " + idOnly + ", " + ajaxOnly + ", this.AjaxPanelContext, this.HtmlTextWriter)){%>";

            m_CodeBody += "<%\r\nHtmlTextWriter " + autoID + "__w = __w; if(__w.InnerWriter is AjaxPanelWriter == false) __w = " + autoID + ".Writer; %>";
			
			GenerateAspxCode(node, scopeData);

            m_CodeBody += "<%\r\n__w = " + autoID + "__w; }%>";

			m_CodeBody += "</" + tag + ">";

			if (onUpdate != null)
			{
                m_CodeBody += "<script type=\"text/javascript\">var __<%=" + id + "%>__ = document.getElementById('<%=" + id + "%>'); __<%=" + id + "%>__.onUpdate = function(panel){ " + onUpdate + " }</script>";
			}
		}
Exemple #5
0
		private void GenerateAspxCodeHead2(TemplateFile templateFile, string[] templateImports, string skinID)
		{
			foreach (string nameSpace in templateImports)
			{
				m_CodeHead += "<%@ Import Namespace=\"" + nameSpace + "\" %>";
			}

            m_CodeHead += "<%\r\n DirectoryVirtualPath = \"" + templateFile.VirtualDirectoryPath + "\";\r\nthis.SubmitFillUsers(); %>" + Environment.NewLine;
            m_CodeHead += "<script runat=\"server\">" + Environment.NewLine;
            m_CodeHead += "protected override void OnLoad(System.EventArgs e)" + Environment.NewLine;
            m_CodeHead += "{" + Environment.NewLine;
            m_CodeHead += "this.DirectoryVirtualPath = \"" + templateFile.VirtualDirectoryPath + "\";" + Environment.NewLine;
            m_CodeHead += "base.OnLoad(e);" + Environment.NewLine;
            m_CodeHead += "}";
            
			if (m_DeclaredVariables.Count > 0)
			{
				foreach (KeyValuePair<Type, string> variable in m_DeclaredVariables)
				{
                    string typeName = ReflectionUtil.GetCSharpTypeName(variable.Key);

                    m_CodeHead += Environment.NewLine + typeName + " " + variable.Value + " = new " + typeName + "();";
				}
			}
            m_CodeHead += Environment.NewLine + "</script>";

		}
Exemple #6
0
		private void GenerateIfElseEpxressionAspxCode(TemplateElement expression, ScopeData scopeData)
		{
			if (expression.Type == TemplateElementTypes.IfExpression)
			{
                m_CodeBody += "<%\r\n if (";

				GenerateAspxCode(m_CodeBody, expression.ChildNodes[0], scopeData);

				m_CodeBody += ") { %>";

				GenerateAspxCode(expression, scopeData);

                m_CodeBody += "<%\r\n } %>";
			}
			else if (expression.Type == TemplateElementTypes.ElseExpression)
			{
                m_CodeBody += "<%\r\n } else { %>";
			}
			else if (expression.Type == TemplateElementTypes.ElseIfExpression)
			{
                m_CodeBody += "<%\r\n } else if(";

				GenerateAspxCode(m_CodeBody, expression.ChildNodes[0], scopeData);

				m_CodeBody += ") { %>";
			}
		}
Exemple #7
0
		private void GenerateOutFunctionAspxCode(StringBuffer codeBody, TemplateElement function, ScopeData scopeData)
		{
			if (function.ChildNodes[0].ChildNodes.Count > 0)
			{
				int defaultValueStartIndex = -1;

				TemplateElement param1 = null;

				if (function.ChildNodes[0].ChildNodes[0].Type == TemplateElementTypes.Variable || function.ChildNodes[0].ChildNodes[0].Type == TemplateElementTypes.Function)
				{
					param1 = function.ChildNodes[0].ChildNodes[0];

					if (function.ChildNodes[0].ChildNodes.Count >= 2)
						defaultValueStartIndex = 1;
				}
				else if (function.ChildNodes[0].ChildNodes.Count >= 2)
				{
					param1 = function.ChildNodes[0].ChildNodes[1];

					if (function.ChildNodes[0].ChildNodes.Count >= 3)
						defaultValueStartIndex = 2;
				}

				if (param1 != null && (param1.Type == TemplateElementTypes.Variable || param1.Type == TemplateElementTypes.Function))
				{
					codeBody += "TryToString(";

					Type returnType = null;

					if (param1.Type == TemplateElementTypes.Variable)
					{
						TemplateElement param0 = new TemplateElement(TemplateElementTypes.Variable, param1.Items);

						GenerateVariableAspxCode(codeBody, param0, out returnType, scopeData);
					}
					else
					{
						TemplateElement param0 = new TemplateElement(TemplateElementTypes.Function, param1.Items);

						param0.ChildNodes.Add(param1.ChildNodes[0]);

						GenerateFunctionAspxCode(codeBody, param0, out returnType, scopeData);
					}

					codeBody += ", delegate(){ return ";

					if (param1.Type == TemplateElementTypes.Variable)
						GenerateVariableAspxCode(codeBody, param1, out returnType, scopeData);
					else
						GenerateFunctionAspxCode(codeBody, param1, out returnType, scopeData);

					codeBody += "; }";

					if (defaultValueStartIndex > 0)
					{
						for (int i = defaultValueStartIndex; i < function.ChildNodes[0].ChildNodes.Count; i++)
						{
							TemplateElement node = function.ChildNodes[0].ChildNodes[i];

							switch (node.Type)
							{
								case TemplateElementTypes.Literal:
									GenerateLiteralAspxCode(codeBody, node);
									break;

								case TemplateElementTypes.Variable:
									GenerateVariableAspxCode(codeBody, node, out returnType, scopeData);
									break;

								case TemplateElementTypes.Function:
									GenerateFunctionAspxCode(codeBody, node, out returnType, scopeData);
									break;

								case TemplateElementTypes.CodeBlock:
									GenerateCodeBlockAspxCode(codeBody, node, scopeData);
									break;

								case TemplateElementTypes.SingleQuteString:
									GenerateSingleQuteStringAspxCode(codeBody, node, scopeData);
									break;

								case TemplateElementTypes.DoubleQuteString:
									GenerateDoubleQuteStringAspxCode(codeBody, node, scopeData);
									break;
							}
						}
					}

					codeBody += ")";
				}
			}
		}
Exemple #8
0
		private void GenerateAspxCode(StringBuffer codeBody, TemplateElement element, ScopeData scopeData)
		{
			foreach (TemplateElement node in element.ChildNodes)
			{
				Type returnType = null;

				switch (node.Type)
				{
					case TemplateElementTypes.Literal:
						GenerateLiteralAspxCode(codeBody, node);
						break;

					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(codeBody, node, out returnType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(codeBody, node, out returnType, scopeData);
						break;

					case TemplateElementTypes.CodeBlock:
						GenerateCodeBlockAspxCode(codeBody, node, scopeData);
						break;

					case TemplateElementTypes.DoubleQuteString:
						GenerateDoubleQuteStringAspxCode(codeBody, node, scopeData);
						break;

					case TemplateElementTypes.SingleQuteString:
						GenerateSingleQuteStringAspxCode(codeBody, node, scopeData);
						break;
				}
			}
		}
Exemple #9
0
        private void GenerateUrlFunctionAspxCode(StringBuffer codeBody, TemplateElement function, ScopeData scopeData)
        {
            codeBody += "string.Concat(_Url_Before, ";

            for (int i = 0; i < function.ChildNodes[0].ChildNodes.Count; i++)
            {
                TemplateElement node = function.ChildNodes[0].ChildNodes[i];

                Type returnType;

                switch (node.Type)
                {
                    case TemplateElementTypes.Literal:
                        codeBody += "\"" + node.Text + "\"";
                        break;

                    case TemplateElementTypes.Variable:
                        GenerateVariableAspxCode(codeBody, node, out returnType, scopeData);
                        break;

                    case TemplateElementTypes.Function:
                        GenerateFunctionAspxCode(codeBody, node, out returnType, scopeData);
                        break;

                    case TemplateElementTypes.CodeBlock:
                        GenerateCodeBlockAspxCode(codeBody, node, scopeData);
                        break;

                    case TemplateElementTypes.DoubleQuteString:
                        GenerateDoubleQuteStringAspxCode(codeBody, node, scopeData);
                        break;

                    case TemplateElementTypes.SingleQuteString:
                        GenerateSingleQuteStringAspxCode(codeBody, node, scopeData);
                        break;
                }

                if (i < function.ChildNodes[0].ChildNodes.Count - 1)
                    codeBody += " + ";
            }

            codeBody += ", _Url_After)";
            //}
        }
Exemple #10
0
		private void GenerateFunctionAspxCode(StringBuffer codeBody, TemplateElement function, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			Type funcReturnType = null;

			string thisVarName = null;
			string thisFuncName = null;

			string name = (string)function.Items[TemplateElement.KEY_NAME];

			if (StringUtil.EqualsIgnoreCase(name, "url"))
			{
				GenerateUrlFunctionAspxCode(codeBody, function, scopeData);
				returnType = typeof(string);
			}
			else if (StringUtil.EqualsIgnoreCase(name, "parent"))
			{
				bool onlyOneParam = true;
				TemplateElement funcParam = null;

				foreach (TemplateElement param in function.ChildNodes[0].ChildNodes)
				{
					if (param.Type == TemplateElementTypes.Literal)
						continue;

                    if (funcParam != null)
					{
						onlyOneParam = false;
						break;
					}

					funcParam = param;
				}

				if (onlyOneParam)
				{
					if (funcParam.Type == TemplateElementTypes.Variable)
						GenerateVariableAspxCode(codeBody, funcParam, out returnType, scopeData.Previous);
					else if (funcParam.Type == TemplateElementTypes.Function)
                        GenerateFunctionAspxCode(codeBody, funcParam, out returnType, scopeData.Previous);
				}
			}
            else if (StringUtil.EqualsIgnoreCase(name, "this"))
            {
                bool onlyOneParam = true;
                TemplateElement funcParam = null;

                foreach (TemplateElement param in function.ChildNodes[0].ChildNodes)
                {
                    if (param.Type == TemplateElementTypes.Literal)
                        continue;

                    if (funcParam != null)
                    {
                        onlyOneParam = false;
                        break;
                    }

                    funcParam = param;
                }

                if (onlyOneParam)
                {
                    if (funcParam.Type == TemplateElementTypes.Variable)
                        GenerateVariableAspxCode(codeBody, funcParam, out returnType, scopeData.Last);
                    else if (funcParam.Type == TemplateElementTypes.Function)
                        GenerateFunctionAspxCode(codeBody, funcParam, out returnType, scopeData.Last);
                }
            }
            else if (StringUtil.EqualsIgnoreCase(name, "out"))
            {
                funcReturnType = typeof(string);

                StringBuffer newCodeBody = new StringBuffer();

                GenerateOutFunctionAspxCode(newCodeBody, function, scopeData);

                if (function.ChildNodes.Count > 1)
                    GenerateMemberInvokeAspxCode(newCodeBody, function.ChildNodes[1], funcReturnType, out returnType, scopeData);

                if (returnType == null)
                    returnType = funcReturnType;

                codeBody += newCodeBody.ToString();
            }
            else if (scopeData.SearchThisVariableMethod(name, out funcReturnType, out thisVarName, out thisFuncName))
            {
                StringBuffer newCodeBody = new StringBuffer();

                newCodeBody += thisVarName + "." + thisFuncName + "(";

                GenerateAspxCode(newCodeBody, function.ChildNodes[0], scopeData);

                newCodeBody += ")";

                if (function.ChildNodes.Count > 1)
                    GenerateMemberInvokeAspxCode(newCodeBody, function.ChildNodes[1], funcReturnType, out returnType, scopeData);

                if (returnType == null)
                    returnType = funcReturnType;

                codeBody += newCodeBody.ToString();
            }
            else
            {
                MethodInfo method = SearchMethodForFunction(name);

                if (method != null)
                {
                    StringBuffer newCodeBody = new StringBuffer();

                    string instanceName = DeclaringVariable(method.DeclaringType);

                    newCodeBody += instanceName + "." + method.Name + "(";

                    GenerateAspxCode(newCodeBody, function.ChildNodes[0], scopeData);

                    newCodeBody += ")";

                    if (function.ChildNodes.Count > 1)
                        GenerateMemberInvokeAspxCode(newCodeBody, function.ChildNodes[1], method.ReturnType, out returnType, scopeData);

                    if (returnType == null)
                        returnType = method.ReturnType;

                    codeBody += newCodeBody.ToString();
                }
            }
		}
Exemple #11
0
		private void GenerateFunctionAspxCode(TemplateElement function, ScopeData scopeData)
		{
            string name = (string)function.Items[TemplateElement.KEY_NAME];
			
            //if (StringUtil.EqualsIgnoreCase(name, "url"))
            //{
            //    GenerateUrlFunctionAspxCode(null, function, scopeData);
            //    return;
            //}

			StringBuffer funcBody = new StringBuffer();

			Type returnType = null;

			GenerateFunctionAspxCode(funcBody, function, out returnType, scopeData);

			if (returnType != null && returnType != typeof(void))
				m_CodeBody += "<%=";
			else
                m_CodeBody += "<%\r\n";

			m_CodeBody += funcBody;

			m_CodeBody += "%>";
		}
Exemple #12
0
		private void GenerateVariableAspxCode(StringBuffer codeBody, TemplateElement variable, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			Type varType = null;
			string varName = null;
			string paramName = null;
			string name = (string)variable.Items[TemplateElement.KEY_NAME];

            if (scopeData.SearchScopeVariable(name, out varType, out varName))
			{
				StringBuffer newCodeBody = new StringBuffer();

				newCodeBody += varName;

				if (variable.ChildNodes.Count > 0)
					GenerateMemberInvokeAspxCode(newCodeBody, variable.ChildNodes[0], varType, out returnType, scopeData);

				if (returnType == null)
					returnType = varType;

				codeBody += newCodeBody.ToString();
			}
			else if (scopeData.SearchThisVariableProperty(name, out varType, out varName, out paramName))
			{
				StringBuffer newCodeBody = new StringBuffer();

				newCodeBody += varName + "." + paramName;

				if (variable.ChildNodes.Count > 0)
					GenerateMemberInvokeAspxCode(newCodeBody, variable.ChildNodes[0], varType, out returnType, scopeData);

				if (returnType == null)
					returnType = varType;

				codeBody += newCodeBody.ToString();
			}
			else
			{
				MemberInfo member = SearchMemberForVariable(name);

                if (member != null)
                {
                    string instanceName = DeclaringVariable(member.DeclaringType);

                    StringBuffer newCodeBody = new StringBuffer();

                    newCodeBody += instanceName + "." + member.Name;

                    Type memberType;

                    if (member.MemberType == MemberTypes.Property)
                        memberType = ((PropertyInfo)member).PropertyType;
                    else
                        memberType = ((FieldInfo)member).FieldType;

                    if (variable.ChildNodes.Count > 0)
                        GenerateMemberInvokeAspxCode(newCodeBody, variable.ChildNodes[0], memberType, out returnType, scopeData);

                    if (returnType == null)
                        returnType = memberType;

                    codeBody += newCodeBody.ToString();
                }
                else
                {

                    throw new TemplateVariableNotExistsException(name, variable.TemplateFile.FilePath, variable.SourceTemplate, variable.Index);
                    //codeBody += name;
                    //LogHelper.CreateErrorLog(new TemplateVariableNotExistsException(name, variable.TemplateFile.FilePath, variable.SourceTemplate, variable.Index));

                    //if (returnType == null)
                    //    returnType = typeof(string);
                }
			}
		}
Exemple #13
0
		private void GenerateVariableAspxCode(TemplateElement variable, ScopeData scopeData)
		{
			StringBuffer varBody = new StringBuffer();

			Type returnType = null;

			GenerateVariableAspxCode(varBody, variable, out returnType, scopeData);

			if(returnType != null && returnType != typeof(void))
				m_CodeBody += "<%=";
			else
                m_CodeBody += "<%\r\n";

			m_CodeBody += varBody;

			m_CodeBody += "%>";
		}
        public ShareContent GetShareContent(int targetID, out int userID, out bool isCanShare)
        {
            userID = 0;
            isCanShare = true;

            Album album = AlbumBO.Instance.GetAlbum(targetID);
            
            if (album == null)
            {
                return null;
            }
            
            isCanShare = album.PrivacyType == PrivacyType.AllVisible;
            
            if (!isCanShare)
            {
                userID = 0;
                return null;
            }
            
            userID = album.UserID;
            
            User author = UserBO.Instance.GetUser(userID);
            StringBuffer shareContent = new StringBuffer();

            string spaceUrl = UrlHelper.GetSpaceUrlTag(album.UserID);
            string albumUrl = UrlHelper.GetAblumUrlTag(targetID);

            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += albumUrl;
            shareContent += "\" title=\"";
            shareContent += album.Name;
            shareContent += "\"><img class=\"summaryimg image\" src=\"";
            shareContent += album.CoverSrc;
            shareContent += "\" alt=\"";
            shareContent += album.Name;
            shareContent += "\" onload=\"imageScale(this, 100, 100)\" onerror=\"this.style.display = 'none';\" /></a>";

            shareContent += "<div class=\"detail\">";
            shareContent += "<b><a target=\"_blank\" href=\"";
            shareContent += albumUrl;
            shareContent += "\" title=\"";
            shareContent += album.Name;
            shareContent += "\">";
            shareContent += album.Name;
            shareContent += "</a></b><br />";
            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += spaceUrl;
            shareContent += "\" title=\"";
            shareContent += author.Name;
            shareContent += "\">";
            shareContent += author.Name;
            shareContent += "</a><br />";
            shareContent += "</div>";


            ShareContent content = new ShareContent();
            content.Catagory = ShareType.Album;
            content.Content = shareContent.ToString();
            content.Title = album.Name;
            content.URL = albumUrl;

            return content;
        }
Exemple #15
0
		private void GenerateCodeBlockAspxCode(TemplateElement codeBlock, ScopeData scopeData)
		{
			bool isOutput = (bool)codeBlock.Items[TemplateElement.KEY_OUTPUT];

            m_CodeBody += isOutput ? "<%=" : "<%\r\n";

			GenerateCodeBlockAspxCode(m_CodeBody, codeBlock, scopeData);
			
			m_CodeBody += isOutput ? "%>" : ";%>";
		}
Exemple #16
0
		private void GenerateLiteralAspxCode(StringBuffer codeBody, TemplateElement literal)
		{
			codeBody.InnerBuilder.Append(literal.SourceTemplate, literal.Index, literal.Length);
		}
Exemple #17
0
		private void GenerateCodeBlockAspxCode(StringBuffer codeBody, TemplateElement codeBlock, ScopeData scopeData)
		{
			foreach (TemplateElement element in codeBlock.ChildNodes)
			{
				Type returnType = null;

				switch (element.Type)
				{
					case TemplateElementTypes.Literal:
						GenerateLiteralAspxCode(codeBody, element);
						break;

					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(codeBody, element, out returnType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(codeBody, element, out returnType, scopeData);
						break;
				}
			}
		}
Exemple #18
0
		private void GenerateAspxCodeHead1(TemplateFile templateFile)
		{
			m_CodeHead += "<%@ ";

			if (templateFile.IsControl)
				m_CodeHead += "Control Language=\"C#\" ";
			else
				m_CodeHead += "Page Language=\"C#\" ";

			string inherits = null;

			if(m_Document.ChildNodes.Count > 0)
			{
				TemplateElement firstNode = m_Document.ChildNodes[0];

				if(firstNode.Type == TemplateElementTypes.Tag)
				{
					string tagName = (string)firstNode.Items[TemplateElement.KEY_NAME];

					if (string.Compare(tagName, "page", true) == 0)
					{
						foreach (TemplateElement element in firstNode.ChildNodes[0].ChildNodes)
						{
							string name = (string)element.Items[TemplateElement.KEY_NAME];

							if (string.Compare(name, "inherits", true) == 0)
								inherits = element.SourceTemplate.Substring(element.Index, element.Length);
						}
					}
				}
			}

			if (inherits == null)
			{
				m_CodeHead += "Inherits=\"" + templateFile.CodeFileInherits + "\" %>";
				ParseCodeFile(templateFile.CodeFileInherits);
			}
			else
			{
				m_CodeHead += "Inherits=\"" + inherits + "\" %>";
				ParseCodeFile(inherits);
			}
		}
Exemple #19
0
		private void GenerateMemberInvokeAspxCode(StringBuffer codeBody, TemplateElement memberInvoke, Type type, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			switch (memberInvoke.Type)
			{

				case TemplateElementTypes.IndexInvoke:
					GenerateIndexInvokeAspxCode(codeBody, memberInvoke, type, out returnType, scopeData);
					break;

				case TemplateElementTypes.PropertyInvoke:
					GeneratePropertyInvokeAspxCode(codeBody, memberInvoke, type, out returnType, scopeData);
					break;

				case TemplateElementTypes.FunctionInvoke:
					GenerateFunctionInvokeAspxCode(codeBody, memberInvoke, type, out returnType, scopeData);
					break;
			}
		}
Exemple #20
0
		private void GenerateTagAspxCode(TemplateElement tag, ScopeData scopeData)
		{
            string name = ((string)tag.Items[TemplateElement.KEY_NAME]);

            if (string.Compare(name, "page", true) == 0)
                return;
            else if (string.Compare(name, "break", true) == 0)
            {
                m_CodeBody += "<% break; %>";
                return;
            }
            else if (string.Compare(name, "continue", true) == 0)
            {
                m_CodeBody += "<% continue; %>";
                return;
            }

			MethodInfo method = SearchMethodForTag(tag);

			if (method != null)
			{
				string instanceName = DeclaringVariable(method.DeclaringType);

                m_CodeBody += "<%\r\n" + instanceName + "." + method.Name + "(";

				int templateIndex = -1;		//模板委托类型参数的起始索引
				int templateCount = 0;		//模板委托类型参数的个数

				bool needRemoveDot = false;

				ParameterInfo[] parameters = method.GetParameters();

				#region 将模板标签属性输出为方法参数

				for (int i = 0; i < parameters.Length; i++)
				{
					if (parameters[i].ParameterType.IsSubclassOf(typeof(Delegate)) == false)
					{
						TemplateElement attributeListItem = GetAttributeListItem(parameters[i], tag.ChildNodes[0]);

						if (attributeListItem != null)
						{
							GenerateAttributeListItemAspxCode(parameters[i], attributeListItem, scopeData);
						}

						m_CodeBody += ",";

						needRemoveDot = true;
					}
					else
					{
						if (templateIndex == -1)
							templateIndex = i;

						templateCount++;
					}
				}

				if (needRemoveDot == true)
					m_CodeBody.InnerBuilder.Remove(m_CodeBody.InnerBuilder.Length - 1, 1);

				#endregion

				#region 将模板标签的模板内容输出为匿名委托

				for (int i = templateIndex; i - templateIndex < templateCount; i++)
				{
					ScopeData scope = new ScopeData(scopeData);

					if (needRemoveDot == true)
					{
						m_CodeBody += ",";
					}
					else
					{
						needRemoveDot = true;
					}

					m_CodeBody += "delegate(";

					ParameterInfo[] args = parameters[i].ParameterType.GetMethod("Invoke").GetParameters();

					for (int j = 0; j < args.Length; j++)
					{
						m_CodeBody += ReflectionUtil.GetCSharpTypeName(args[j].ParameterType) + " " + scope.DeclaringScopeVariable(args[j]);

						if (j < args.Length - 1)
							m_CodeBody += ",";
					}

					m_CodeBody += "){\r\n%>";

					if (templateCount == 1)
					{
						GenerateAspxCode(tag, scope);
					}
					else
					{
						for (int j = 1; j < tag.ChildNodes.Count; j++)
						{
							TemplateElement element = tag.ChildNodes[j];

							if (element.Type == TemplateElementTypes.Tag)
							{
								string tagName = (string)element.Items[TemplateElement.KEY_NAME];

								if (StringUtil.EqualsIgnoreCase(parameters[i].Name, tagName))
								{
									GenerateAspxCode(element, scope);
									break;
								}
							}
						}
					}

					m_CodeBody += "<%\r\n}";

					//for (int j = 0; j < args.Length; j++)
					//{
					//    UndeclaringScopeVariable(args[j]);
					//}
				}

				#endregion

				m_CodeBody += ");%>";
			}
			else
			{
                //未能找到合适的注册标签,直接输出
                //if (tag.Index != tag.Length)
                //    m_CodeBody += tag.SourceTemplate.Substring(tag.Index, tag.Length);

                //string name = tag.Items[TemplateElement.KEY_NAME] as string;

                //if (StringUtil.EqualsIgnoreCase(name, "ajaxpanel"))
                //{

                //}
			}
		}
Exemple #21
0
		private void GenerateIndexInvokeAspxCode(StringBuffer codeBody, TemplateElement indexInvoke, Type type, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			Type indexType = null;

			string name = indexInvoke.Items[TemplateElement.KEY_NAME] as string;

			if (type.IsArray)
			{
				indexType = type.GetElementType();
			}
			else
			{
				PropertyInfo property = type.GetProperty("Item", BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);

				if (property != null)
					indexType = property.PropertyType;
			}

			if (indexType != null)
			{
				codeBody += "[";

				GenerateAspxCode(codeBody, indexInvoke.ChildNodes[0], scopeData);

				codeBody += "]";

				if (indexInvoke.ChildNodes.Count > 1)
					GenerateMemberInvokeAspxCode(codeBody, indexInvoke.ChildNodes[1], indexType, out returnType, scopeData);

				if (returnType == null)
					returnType = indexType;
			}
		}
Exemple #22
0
		private void GenerateIncludeExpressionAspxCode(TemplateElement node, ScopeData scopeData)
		{
            m_CodeBody += "<%\r\n Include(__w, ";

			for (int i = 0; i < node.ChildNodes[0].ChildNodes.Count; i++)
			{
				TemplateElement element = node.ChildNodes[0].ChildNodes[i];

				m_CodeBody += "\"" + element.Items[TemplateElement.KEY_NAME] + "\",";

				for (int j = 0; j < element.ChildNodes.Count; j++)
				{
					TemplateElement element2 = element.ChildNodes[j];

					Type returnType = null;

					switch (element2.Type)
					{
						case TemplateElementTypes.Literal:
							m_CodeBody += "\"";
							GenerateLiteralAspxCode(element2);
							m_CodeBody += "\"";
							break;

						case TemplateElementTypes.Variable:
							GenerateVariableAspxCode(m_CodeBody, element2, out returnType, scopeData);
							break;

						case TemplateElementTypes.Function:
							GenerateFunctionAspxCode(m_CodeBody, element2, out returnType, scopeData);
							break;

						case TemplateElementTypes.CodeBlock:
							GenerateCodeBlockAspxCode(m_CodeBody, element2, scopeData);
							break;
					}

					if (j < element.ChildNodes.Count - 1)
						m_CodeBody += "+";
				}

				if (i < node.ChildNodes[0].ChildNodes.Count - 1)
					m_CodeBody += ",";
			}
			
			m_CodeBody += "); %>";
		}
Exemple #23
0
		private void GeneratePropertyInvokeAspxCode(StringBuffer codeBody, TemplateElement propertyInvoke, Type type, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			string name = propertyInvoke.Items[TemplateElement.KEY_NAME] as string;

			MethodInfo extensionProperty = SearchExtensionProperty(name, type);

			if (extensionProperty != null)
			{
				StringBuffer sb = new StringBuffer(ReflectionUtil.GetCSharpTypeName(extensionProperty.DeclaringType));

				sb += "." + extensionProperty.Name + "((";

				codeBody.InnerBuilder.Insert(0, sb);

				codeBody += "),\"" + name + "\")";

				if (propertyInvoke.ChildNodes.Count > 0)
					GenerateMemberInvokeAspxCode(codeBody, propertyInvoke.ChildNodes[0], extensionProperty.ReturnType, out returnType, scopeData);
				
				if(returnType == null)
					returnType = extensionProperty.ReturnType;
			}
			else
			{
				MemberInfo member = SearchPropertyAndField(name, type);

				Type magicPropertyType = null;

				if (member != null)
				{
					codeBody += "." + member.Name;

                    Type memberType;

                    if (member.MemberType == MemberTypes.Property)
                        memberType = ((PropertyInfo)member).PropertyType;

                    else
                        memberType = ((FieldInfo)member).FieldType;

					if (propertyInvoke.ChildNodes.Count > 0)
                        GenerateMemberInvokeAspxCode(codeBody, propertyInvoke.ChildNodes[0], memberType, out returnType, scopeData);

					if(returnType == null)
                        returnType = memberType;
				}
				else if (HasMagicProperty(type, out magicPropertyType))
				{
					codeBody += "[\"" + name + "\"]";

					if (propertyInvoke.ChildNodes.Count > 0)
						GenerateMemberInvokeAspxCode(codeBody, propertyInvoke.ChildNodes[0], magicPropertyType, out returnType, scopeData);
				
					if(returnType == null)
						returnType = magicPropertyType;
				}
			}
		}
Exemple #24
0
		private void GenerateLoopExpressionParam2AspxCode(TemplateElement node, ScopeData scopeData)
		{
			if (node.ChildNodes.Count == 2)
			{
				TemplateElement from = node.ChildNodes[0];
				TemplateElement to = node.ChildNodes[1];

				StringBuffer fromCode = new StringBuffer();

				Type fromType = null;

				switch (from.Type)
				{
					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(fromCode, from, out fromType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(fromCode, from, out fromType, scopeData);
						break;

					case TemplateElementTypes.Literal:
						string fromValue = from.SourceTemplate.Substring(from.Index, from.Length);
						
						int temp = -1;

						if (int.TryParse(fromValue, out temp))
						{
							fromCode += fromValue;
							fromType = typeof(int);
						}
						break;
				}

				StringBuffer toCode = new StringBuffer();

				Type toType = null;

				switch (to.Type)
				{
					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(toCode, to, out toType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(toCode, to, out toType, scopeData);
						break;

					case TemplateElementTypes.Literal:
						string toValue = to.SourceTemplate.Substring(to.Index, to.Length);

						int temp = -1;

						if (int.TryParse(toValue, out temp))
						{
							toCode += toValue;
							toType = typeof(int);
						}
						break;
				}

				if (fromType == typeof(int) && toType == typeof(int))
				{
					string i = node.Items["i"] as string;
					string step = node.Items["step"] as string;

					uint temp = 0;

					if (i != null && (step == null || (uint.TryParse(step, out temp) && temp > 0)))
					{
						if (step == null)
							step = "1";

						ScopeData scope = new ScopeData(scopeData);

						string iVarName = scope.DeclaringScopeVariable(i, typeof(int));

						//example: for (int i = a; a > b ? i >= b : i <= b; i += a > b ? -c : c)

                        m_CodeBody += "<%\r\nfor(int " + iVarName + "=" + fromCode + ";" + fromCode + " > " + toCode + " ? " + iVarName + " >= " + toCode + " : " + iVarName + " <= " + toCode + ";" + iVarName + " += " + fromCode + " > " + toCode + " ? -" + step + " : " + step + "){%>";

						GenerateAspxCode(node.Parent, scope);

                        m_CodeBody += "<%\r\n}%>";
					}
				}
			}
		}
Exemple #25
0
		private void GenerateFunctionInvokeAspxCode(StringBuffer codeBody, TemplateElement functionInvoke, Type type, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			string name = functionInvoke.Items[TemplateElement.KEY_NAME] as string;

			if (name == null)
			{
				#region 委托数组的调用
				if (type.IsSubclassOf(typeof(Delegate)) == false)
				{
					codeBody.InnerBuilder.Append(functionInvoke.SourceTemplate, functionInvoke.Index, functionInvoke.Length);
				}
				else
				{
					codeBody += "(";

					GenerateAspxCode(codeBody, functionInvoke.ChildNodes[0], scopeData);

					codeBody += ")";

					if (functionInvoke.ChildNodes.Count > 1)
						GenerateMemberInvokeAspxCode(codeBody, functionInvoke.ChildNodes[1], type.GetMethod("Invoke").ReturnType, out returnType, scopeData);
					
					if(returnType == null)
						returnType = type.GetMethod("Invoke").ReturnType;
				}
				#endregion
			}
			else
			{
				MethodInfo extensionFunction = SearchExtensionFunction(name, type);

				if (extensionFunction != null)
				{
					#region 扩展函数的调用

                    StringBuffer sb = new StringBuffer(ReflectionUtil.GetCSharpTypeName(extensionFunction.DeclaringType));

					sb += "." + extensionFunction.Name + "(";

					codeBody.InnerBuilder.Insert(0, sb);

					codeBody += ",\"" + name + "\"";

					if (extensionFunction.GetParameters().Length > 2)
					{
						codeBody += ",";

						GenerateAspxCode(codeBody, functionInvoke.ChildNodes[0], scopeData);
					}

					codeBody += ")";

					if (functionInvoke.ChildNodes.Count > 1)
						GenerateMemberInvokeAspxCode(codeBody, functionInvoke.ChildNodes[1], extensionFunction.ReturnType, out returnType, scopeData);
					
					if(returnType == null)
						returnType = extensionFunction.ReturnType;

					#endregion
				}
				else
				{
					#region 普通函数调用

					MethodInfo method = SearchMethod(name, type);

					if (method != null)
					{
						codeBody += "." + method.Name + "(";

						GenerateAspxCode(codeBody, functionInvoke.ChildNodes[0], scopeData);

						codeBody += ")";

						if (functionInvoke.ChildNodes.Count > 1)
							GenerateMemberInvokeAspxCode(codeBody, functionInvoke.ChildNodes[1], method.ReturnType, out returnType, scopeData);
						
						if(returnType == null)
							returnType = method.ReturnType;
					}

					#endregion
				}
			}
		}
        public ShareContent GetShareContent(int targetID, out int userID, out bool isCanShare)
        {
            userID     = 0;
            isCanShare = true;

            Album album = AlbumBO.Instance.GetAlbum(targetID);

            if (album == null)
            {
                return(null);
            }

            isCanShare = album.PrivacyType == PrivacyType.AllVisible;

            if (!isCanShare)
            {
                userID = 0;
                return(null);
            }

            userID = album.UserID;

            User         author       = UserBO.Instance.GetUser(userID);
            StringBuffer shareContent = new StringBuffer();

            string spaceUrl = UrlHelper.GetSpaceUrlTag(album.UserID);
            string albumUrl = UrlHelper.GetAblumUrlTag(targetID);

            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += albumUrl;
            shareContent += "\" title=\"";
            shareContent += album.Name;
            shareContent += "\"><img class=\"summaryimg image\" src=\"";
            shareContent += album.CoverSrc;
            shareContent += "\" alt=\"";
            shareContent += album.Name;
            shareContent += "\" onload=\"imageScale(this, 100, 100)\" onerror=\"this.style.display = 'none';\" /></a>";

            shareContent += "<div class=\"detail\">";
            shareContent += "<b><a target=\"_blank\" href=\"";
            shareContent += albumUrl;
            shareContent += "\" title=\"";
            shareContent += album.Name;
            shareContent += "\">";
            shareContent += album.Name;
            shareContent += "</a></b><br />";
            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += spaceUrl;
            shareContent += "\" title=\"";
            shareContent += author.Name;
            shareContent += "\">";
            shareContent += author.Name;
            shareContent += "</a><br />";
            shareContent += "</div>";


            ShareContent content = new ShareContent();

            content.Catagory = ShareType.Album;
            content.Content  = shareContent.ToString();
            content.Title    = album.Name;
            content.URL      = albumUrl;

            return(content);
        }
Exemple #27
0
		private void GenerateDoubleQuteStringAspxCode(StringBuffer codeBody, TemplateElement node, ScopeData scopeData)
		{
			if (node.ChildNodes.Count == 0)
			{
				codeBody += "\"\"";
				return;
			}

			for (int j = 0; j < node.ChildNodes.Count; j++)
			{
				TemplateElement element2 = node.ChildNodes[j];

				Type returnType = null;

				switch (element2.Type)
				{
					case TemplateElementTypes.Literal:
						codeBody += "\"";
						GenerateLiteralAspxCode(codeBody, element2);
						codeBody += "\"";
						break;

					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(codeBody, element2, out returnType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(codeBody, element2, out returnType, scopeData);
						break;

					case TemplateElementTypes.CodeBlock:
						GenerateCodeBlockAspxCode(codeBody, element2, scopeData);
						break;
				}

				if (j < node.ChildNodes.Count - 1)
					codeBody += " + ";
			}
		}
Exemple #28
0
        /// <summary>
        /// 如果是整数的天 或者 小时 或者 分钟 将转换成对应的单位: 如:"3天"
        /// 0返回 "无限期"
        /// </summary>
        /// <param name="seconds"></param>
        /// <returns></returns>
        public static string FormatSecond(long seconds, TimeUnit timeUnit)
        {

            if (seconds == 0)
                return Lang.Common_Indefinitely;

            int secondOfDay = 24 * 3600;
            int secondOfHour = 3600;
            int secondOfMinute = 60;

            StringBuffer buffer = new StringBuffer();
            if (seconds > secondOfDay)
            {
                int day = (int)(seconds / secondOfDay);
                buffer += day + Lang.Common_Day;
                seconds -= day * secondOfDay;
            }

            if (timeUnit == TimeUnit.Day && buffer.Length > 0) return buffer.ToString();

            if (seconds > secondOfHour)
            {
                int hour;
                hour = (int)seconds / secondOfHour;
                buffer += hour + Lang.Common_Hour;
                seconds -= hour * secondOfHour;
            }

            if (timeUnit == TimeUnit.Hour && buffer.Length > 0) return buffer.ToString();

            if (seconds > secondOfMinute)
            {
                int minute;
                minute = (int)seconds / secondOfMinute;
                buffer += minute + Lang.Common_Minute;
                seconds -= minute * secondOfMinute;
            }

            if (timeUnit == TimeUnit.Minute && buffer.Length > 0) return buffer.ToString();

            if (seconds > 0)
                buffer += seconds + Lang.Common_Second;

            return buffer.ToString();
        }
Exemple #29
0
        public void Dispose()
        {
            m_Document = null;
            m_CodeBody = null;
            m_CodeHead = null;
            m_DeclaredVariables = null;
            m_ExtensionFunctions = null;
            m_ExtensionProperties = null;
            m_MethodBasedFunctions = null;
            m_MethodBasedTags = null;
            m_PropertyBasedVariables = null;

            try
            {
                System.GC.Collect();
            }
            catch
            {
                LogHelper.CreateDebugLog("模板处理完毕,垃圾回收失败,可能会占用较高内存");
            }
        }
Exemple #30
0
        public static string GetUrl(string urlInfo, string query)
        {
            if (string.IsNullOrEmpty(query))
            {
                return(GetUrl(urlInfo));
            }

            int indexOfQuery = urlInfo.IndexOf('?');

            if (indexOfQuery >= 0)
            {
                #region 处理原来有参数同时也要追加参数的情况

                NameValueCollection q2 = HttpUtility.ParseQueryString(query);

                StringBuffer newUrl = new StringBuffer();

                newUrl += Globals.AppRoot;

                if (AllSettings.Current.FriendlyUrlSettings.UrlFormat == UrlFormat.Query)
                {
                    newUrl += "/?";
                }

                else
                {
                    newUrl += "/";
                }

                string query1 = string.Empty;

                if (indexOfQuery >= 0)
                {
                    newUrl += urlInfo.Substring(0, indexOfQuery);

                    query1 = urlInfo.Substring(indexOfQuery + 1);
                }
                else
                {
                    newUrl += urlInfo;
                }

                switch (AllSettings.Current.FriendlyUrlSettings.UrlFormat)
                {
                //case MaxLabs.bbsMax.Enums.UrlFormat.Folder:
                //    newUrl += "/";
                //    break;

                case MaxLabs.bbsMax.Enums.UrlFormat.Aspx:
                    newUrl += ".aspx";
                    break;

                case MaxLabs.bbsMax.Enums.UrlFormat.Html:
                    newUrl += ".html";
                    break;
                }


                NameValueCollection q1 = HttpUtility.ParseQueryString(query1);

                if (q2 != null)
                {
                    for (int i = 0; i < q2.Count; i++)
                    {
                        string value = q2[i];

                        q1[q2.GetKey(i)] = value;
                    }
                }

                StringBuilder newQuery = new StringBuilder("?");

                for (int i = 0; i < q1.Count; i++)
                {
                    newQuery.Append(HttpUtility.UrlEncode(q1.GetKey(i))).Append("=").Append(HttpUtility.UrlEncode(q1[i])).Append("&");
                }

                newQuery.Remove(newQuery.Length - 1, 1);

                newUrl += newQuery;

                #endregion

                return(newUrl.ToString());
            }
            else
            {
                return(string.Concat(GetUrl(urlInfo), "?", query));
            }
        }
Exemple #31
0
        public void GenerateAspxCode(string skinID, TemplateFile templateFile, string[] templateImports)
        {
            string template = templateFile.GetFullTemplate(skinID);

            string checkString = ReadCheckString(templateFile);
            string newCheckString = GetNewCheckString(template);

            if (checkString != newCheckString)
            {
                #region 需要重新解析模板    

                m_Document = TemplateElement.CreateDocument(template, templateFile);

                m_CodeHead = new StringBuffer();
                m_CodeBody = new StringBuffer(template.Length);

                GenerateAspxCodeHead1(templateFile);

                GenerateAspxCode(m_Document, new ScopeData(null));

                GenerateAspxCodeHead2(templateFile, templateImports, skinID);

                string aspxCode = string.Concat("<%--", newCheckString, "--%>\r\n", m_CodeHead.ToString(), m_CodeBody.ToString());

                try
                {
                    using (StreamWriter writer = new StreamWriter(templateFile.ParsedFilePath, false, Encoding.UTF8))
                    {
                        writer.Write(aspxCode);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.CreateErrorLog(ex, templateFile.FileName + "写入文件时出错");
                }

                LogHelper.CreateDebugLog(templateFile.FileName + "发生了重新解析,并写入磁盘");

                #endregion
            }

            TryBuildTempWebConfig();
        }
        public ShareContent GetShareContent(int targetID, out int userID, out bool isCanShare)
        {
            userID = 0;
            isCanShare = false;

            BlogArticle article = BlogBO.Instance.GetBlogArticle(targetID);

            if (article == null)
                return null;

            isCanShare = article.PrivacyType == PrivacyType.AllVisible;

            if (!isCanShare)
            {
                userID = 0;
                return null;
            }

            userID = article.UserID;

            User author = UserBO.Instance.GetUser(userID);

            StringBuffer shareContent = new StringBuffer();

            string spaceUrl = UrlHelper.GetSpaceUrlTag(author.UserID);
            string articleUrl = UrlHelper.GetBlogArticleUrlTag(article.ArticleID); //"$url(" + "space/" + article.UserID + "/blog/article-" + targetID + ")";

            shareContent += "<div class=\"detail\">";
            shareContent += "<b><a target=\"_blank\" href=\"";
            shareContent += articleUrl;
            shareContent += "\" title=\"";
            shareContent += article.Subject;
            shareContent += "\">";
            shareContent += article.Subject;
            shareContent += "</a></b><br />";
            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += spaceUrl;
            shareContent += "\" title=\"";
            shareContent += author.Username;
            shareContent += "\">";
            shareContent += author.Username;
            shareContent += "</a><br />";
            shareContent += StringUtil.CutString(StringUtil.ClearAngleBracket(article.Content), Consts.Share_ReviewContentLength);
            shareContent += "</div>";

            if (string.IsNullOrEmpty(article.Thumb) == false)
            {
                shareContent += "<a target=\"_blank\" href=\"" + articleUrl;
                shareContent += "\" title=\"";
                shareContent += article.Subject;
                shareContent += "\"><img class=\"summaryimg image\" src=\"";
                shareContent += article.Thumb;
                shareContent += "\" alt=\"";
                shareContent += article.Subject;
                shareContent += "\" onload=\"imageScale(this, 100, 100)\" onerror=\"this.style.display = 'none';\"  /></a>";
            }


            ShareContent content = new ShareContent();
            content.Catagory = ShareType.Blog;
            content.Content = shareContent.ToString();
            content.Title = article.Subject;
            content.URL = articleUrl;

            return content;
        }
Exemple #33
0
		private void GenerateAttributeListItemAspxCode(ParameterInfo parameterInfo, TemplateElement attributeListItem, ScopeData scopeData)
		{
			TemplateDefaultValueAttribute defaultValue = TemplateDefaultValueAttribute.GetFromParameter(parameterInfo);

			if (attributeListItem.ChildNodes.Count == 0)
			{
				if (defaultValue != null)
					m_CodeBody += defaultValue.DefaultValue;
				else
					m_CodeBody += "default(" + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType) + ")";
			}
			else if (attributeListItem.ChildNodes.Count == 1)
			{
				StringBuffer newCodeBody = new StringBuffer();

				TemplateElement element = attributeListItem.ChildNodes[0];

				Type returnType = null;

				switch (element.Type)
				{
					case TemplateElementTypes.Literal:
						if (parameterInfo.ParameterType == typeof(string))
						{
							m_CodeBody += "\"";

							GenerateLiteralAspxCode(attributeListItem.ChildNodes[0]);

							m_CodeBody += "\"";
						}
						else if (parameterInfo.ParameterType.IsEnum)
						{
							m_CodeBody += "TryParse<" + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType) + ">(\"";

							GenerateLiteralAspxCode(attributeListItem.ChildNodes[0]);

							m_CodeBody += "\")";
						}
						else if (parameterInfo.ParameterType == typeof(char))
						{
							m_CodeBody += "\'";

							GenerateLiteralAspxCode(attributeListItem.ChildNodes[0]);

							m_CodeBody += "\'";
						}
						else
						{
							GenerateLiteralAspxCode(element);
						}
						break;

					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(newCodeBody, element, out returnType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(newCodeBody, element, out returnType, scopeData);
						break;

					case TemplateElementTypes.CodeBlock:
						GenerateCodeBlockAspxCode(newCodeBody, element, scopeData);
						break;
				}

				if (returnType != null && returnType != parameterInfo.ParameterType)
				{
					if (returnType == typeof(string))
					{
						m_CodeBody += "TryParse<" + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType) + ">(" + newCodeBody + ")";
					}
                    else if (parameterInfo.ParameterType.IsClass)
                    {
                        m_CodeBody += newCodeBody + " as " + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType);
                    }
                    else
                    {
                        m_CodeBody += "(" + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType) + ")" + newCodeBody;
                    }
				}
				else
				{
					m_CodeBody += newCodeBody;
				}
			}
			else if(attributeListItem.ChildNodes.Count > 1)
			{
				StringBuffer newCodeBody = new StringBuffer();

				GenerateDoubleQuteStringAspxCode(newCodeBody, attributeListItem, scopeData);

				if (parameterInfo.ParameterType != typeof(string))
				{
					m_CodeBody += "TryParse<" + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType) + ">(" + newCodeBody + ")";
				}
				else
				{
					m_CodeBody += newCodeBody;
				}
			}
		}