Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="module"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public static async Task <IActionResult> SpaAsync(this Controller controller, string module, string file)
        {
            var env        = controller.ControllerContext.HttpContext.RequestServices.GetService <IHostEnvironment>();
            var moduleName = module ?? controller.GetType().Assembly.GetName().Name;

            if (env.IsDevelopment() && SeedSpaBuilderExtensions.UrlHash.ContainsKey(moduleName))
            {
                var baseUriTaskFactory = SeedSpaBuilderExtensions.UrlHash[moduleName] as Func <Task <Uri> >;
                var request            = (HttpWebRequest)WebRequest.Create($"{await baseUriTaskFactory()}{moduleName}/{file}");
                request.Method      = controller.Request.Method;
                request.ContentType = controller.Request.ContentType;

                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        var responseReader = new StreamReader(responseStream, Encoding.GetEncoding(response.CharacterSet));
                        var responseText   = responseReader.ReadToEnd();
                        return(await Task.FromResult(controller.Content(responseText, response.ContentType)));
                    }
                }
            }

            return(await Task.FromResult(controller.View($"~/Areas/{moduleName}/ClientApp/dist/{file}")));
        }
 public static ActionResult GetODataServiceDocumentJsonV4(
     this Microsoft.AspNetCore.Mvc.Controller ctrl,
     TableSpec[] tables,
     string MetadataPath)
 {
     ctrl.Response.Headers.Add("OData-Version", "4.0");
     return(ctrl.Content(ODataHandler.GetRootMetadataJsonV4(
                             ctrl.Request.Scheme + "://" + ctrl.Request.Host + "/" + MetadataPath,
                             tables),
                         "application/json; odata.metadata=minimal"));
 }
 public static ActionResult GetODataMetadataXmlV4(
     this Microsoft.AspNetCore.Mvc.Controller ctrl,
     TableSpec[] tables,
     string ModelNamespace = null)
 {
     if (string.IsNullOrWhiteSpace(ModelNamespace))
     {
         ModelNamespace = ctrl.ControllerContext.ActionDescriptor.ControllerName + ".Models";
     }
     ctrl.Response.Headers.Add("OData-Version", "4.0"); // Probably not nessecary but someone might need it as root.
     return(ctrl.Content(ODataHandler.GetMetadataXmlV4(tables, ModelNamespace), "application/xml"));
 }
Esempio n. 4
0
        /// <summary>
        /// 重定向並在client端進行Post FormData行為
        /// </summary>
        /// <param name="obj">控制器實例</param>
        /// <param name="url">目標網址</param>
        /// <param name="formData">FormData</param>
        /// <returns>重定向HTML</returns>
        public static IActionResult RedirectWithClientPostFormData(this Controller obj, string url, Dictionary <string, string> formData)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(@"<html><head></head><body><form id=""frm1"" name=""frm1""></form><script>document.frm1.submit()</script></body></html>");

            HtmlNode formNode = doc.DocumentNode.SelectSingleNode("//form");

            if (formNode != null)
            {
                formNode.SetAttributeValue("method", "POST");
                formNode.SetAttributeValue("action", url);
                formData.Keys.ForEach(key => formNode.AppendChild(HtmlNode.CreateNode($"<input type=\"hidden\" name=\"{key}\" value=\"{formData[key]}\" />")));
            }

            return(obj.Content(doc.DocumentNode.OuterHtml, "text/html"));
        }
Esempio n. 5
0
 public static IActionResult RASuccessExecuteScript(this Controller controller, string javascript, params object[] formatArgs)
 {
     return(controller.Content(String.Format(javascript, formatArgs)));
 }
Esempio n. 6
0
 public static IActionResult RASuccessExecuteScript(this Controller controller, string javascript)
 {
     return(controller.Content(javascript));
 }
Esempio n. 7
0
 public static IActionResult RASuccessReloadPage(this Controller controller)
 {
     return(controller.Content("window.location.reload();"));
 }
Esempio n. 8
0
 public static IActionResult RASuccessReplaceWindowTo(
     this Controller controller,
     string url)
 {
     return(controller.Content($"window.location.replace('{url}');"));
 }
Esempio n. 9
0
 public static IActionResult RASuccessNavigateTo(this Controller controller, string url)
 {
     return(controller.Content(String.Format("window.location.href = '{0}';", url)));
 }
Esempio n. 10
0
 public static IActionResult RASuccess(this Controller controller)
 {
     return(controller.Content(String.Empty));
 }