예제 #1
0
        public void Register(View view)
        {
            string[] stringparameters = Array.ConvertAll(_methodInfo.GetParameters(), pi => pi.Name);

            string className  = _targetType.FullName;
            string methodName = _methodInfo.Name;

            if (!string.IsNullOrEmpty(_javaScriptAlias))
            {
                int lastDot = _javaScriptAlias.LastIndexOf('.');

                if (lastDot >= 0)
                {
                    className  = _javaScriptAlias.Substring(0, lastDot);
                    methodName = _javaScriptAlias.Substring(lastDot + 1);
                }
                else
                {
                    className  = "";
                    methodName = _javaScriptAlias;
                }
            }

            if (!view.AjaxGenerated)
            {
                view.RegisterJavascript("_JS_AJAX_SETUP_", true, WebAppConfig.AjaxProvider.SetupFramework());

                view.AjaxGenerated = true;
            }

            Dictionary <string, string> ajaxContext = new Dictionary <string, string>();

            ajaxContext.Add("_VIEWNAME_", view.ViewName);

            string jsMethod = WebAppConfig.AjaxProvider.GenerateJavascriptMethod(PathHelper.TranslateAbsolutePath(_url), className, methodName, stringparameters, _useFormData, ajaxContext, ReturnXml);

            if (className.Length > 0)
            {
                view.RegisterJavascript("_JS_" + className, true, WebAppConfig.AjaxProvider.GenerateJavascriptClassName(className));
            }

            view.RegisterJavascript("_JS_" + className + "." + methodName, true, jsMethod);
        }
예제 #2
0
        private string ReplaceHref(Match match)
        {
            string quote = match.Groups["quote"].Value;
            string url   = match.Groups["url"].Value;

            if (url.StartsWith("~/") || url.StartsWith("/"))
            {
                return(quote + PathHelper.TranslateAbsolutePath(url) + quote);
            }

            string toPath   = _toPath.Replace('\\', '/');
            string fromPath = _fromPath.Replace('\\', '/');

            toPath   = SetLastChar(toPath, "/");
            fromPath = SetLastChar(fromPath, "/");

            string filePath;

            if (url.StartsWith("/"))
            {
                filePath = url;
            }
            else
            {
                filePath = fromPath + url;
            }

            toPath = SetLastChar(toPath, "/");

            if (!filePath.StartsWith("/") && !filePath.StartsWith("\\") && !Path.IsPathRooted(filePath))
            {
                filePath = toPath + filePath;
            }


            string[] pieces = filePath.Split('/');

            filePath = "";

            foreach (string piece in pieces)
            {
                if (piece.Length > 0)
                {
                    if (piece == "..")
                    {
                        filePath = RemoveLastPart(filePath);
                    }
                    else
                    if (piece != ".")
                    {
                        filePath += "/" + piece;
                    }
                }
            }

            pieces = filePath.Split('/');
            string[] piecesTo = toPath.Split('/');

            int firstMismatch = 0;

            for (int i = 0; i < pieces.Length && i < piecesTo.Length; i++)
            {
                if (pieces[i].ToUpper() != piecesTo[i].ToUpper())
                {
                    firstMismatch = 0;

                    for (int j = 0; j < i; j++)
                    {
                        firstMismatch += pieces[j].Length + 1;
                    }

                    break;
                }
            }

            if (firstMismatch <= filePath.Length)
            {
                filePath = filePath.Substring(firstMismatch, filePath.Length - firstMismatch);
            }

            int pos = firstMismatch;

            while (pos < toPath.Length)
            {
                if (toPath.Substring(pos, 1) == "/")
                {
                    filePath = "../" + filePath;
                }

                pos++;
            }

            return(quote + filePath + quote);
        }
예제 #3
0
 public static string CreateResourceUrl(Assembly assembly, string resourceName, string contentType)
 {
     return(PathHelper.TranslateAbsolutePath("~/_$res$_.axd/" + UrlHelper.EncodeToUrl(contentType) + "/" + UrlHelper.EncodeToUrl(assembly.GetName().Name) + '/' + UrlHelper.EncodeToUrl(resourceName)));
 }