示例#1
0
        protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
        {
            // ptentially this can cause a racing condition when more than one thread will rush to set the manager_property value
            // I think it is still ok because all of them will get back the same value and if it is assigned more than once it should be
            // no problem
            manager_member = controllerContext.HttpContext.ApplicationInstance.GetType().GetField("DjangoTemplateManager");
            if (manager_member == null)
            {
                manager_member = controllerContext.HttpContext.ApplicationInstance.GetType().GetProperty("DjangoTemplateManager");
            }

            if (manager_member == null ||
                (manager_member.MemberType == MemberTypes.Field && ((FieldInfo)manager_member).FieldType != typeof(ITemplateManager)) ||
                (manager_member.MemberType == MemberTypes.Property && ((PropertyInfo)manager_member).PropertyType != typeof(ITemplateManager) && (!((PropertyInfo)manager_member).CanWrite || !((PropertyInfo)manager_member).CanRead)))
            {
                throw new ApplicationException("Missing or invalid TemplateManager property/field in Global.asax. The required format is\n        public NDjango.Interfaces.ITemplateManager DjangoTemplateManager { get; set; } OR public NDjango.Interfaces.ITemplateManager DjangoTemplateManager");
            }

            ITemplateManager manager;

            if (manager_member.MemberType == MemberTypes.Field)
            {
                manager = (ITemplateManager)((FieldInfo)manager_member).GetValue(controllerContext.HttpContext.ApplicationInstance);
            }
            else
            {
                manager = (ITemplateManager)((PropertyInfo)manager_member).GetValue(controllerContext.HttpContext.ApplicationInstance, new object[] {});
            }

            if (manager == null)
            {
                manager = manager_provider.GetNewManager();
                if (manager_member.MemberType == MemberTypes.Field)
                {
                    ((FieldInfo)manager_member).SetValue(controllerContext.HttpContext.ApplicationInstance, manager);
                }
                else
                {
                    ((PropertyInfo)manager_member).SetValue(controllerContext.HttpContext.ApplicationInstance, manager, new object[] { });
                }
            }

            return(new DjangoView(manager, viewPath));
        }
示例#2
0
        protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
        {
            // ptentially this can cause a racing condition when more than one thread will rush to set the manager_property value
            // I think it is still ok because all of them will get back the same value and if it is assigned more than once it should be
            // no problem
            if (manager_property == null)
            {
                manager_property = controllerContext.HttpContext.ApplicationInstance.GetType().GetProperty("DjangoTemplateManager");
                if (manager_property == null || !manager_property.CanWrite || !manager_property.CanRead || manager_property.PropertyType != typeof(ITemplateManager))
                {
                    throw new ApplicationException("Missing or invalid TemplateManager property in Global.asax. The required format is\n        public NDjango.Interfaces.ITemplateManager DjangoTemplateManager { get; set; }");
                }
            }
            var manager = (ITemplateManager)manager_property.GetValue(controllerContext.HttpContext.ApplicationInstance, new object[] { });

            if (manager == null)
            {
                manager = manager_provider.GetNewManager();
                manager_property.SetValue(controllerContext.HttpContext.ApplicationInstance, manager, new object[] { });
            }

            return(new DjangoView(manager, viewPath));
        }
示例#3
0
文件: entity.cs 项目: krikelin/Entifi
        void service_ObjectLoaded(object sender, Models.IEntifyService.ObjectLoadedEventArgs e)
        {
            String temp_path = Environment.GetEnvironmentVariable("temp") + Path.DirectorySeparatorChar + "entify_razor.tmp";

            this.Token = JsonConvert.DeserializeObject<Object>((string)e.Result);
            webView.LoadHtml(Process(entifyScheme.LoadResource(viewAddress)));
            #if(false)
            using(StreamWriter sr = new StreamWriter(temp_path)) {
                sr.Write(template);
                sr.Close();
            }
            using (var writer = new StringWriter())
            {
                try
                {

                    var context = new Dictionary<String, Object>();
                    context.Add("data", e.Result);
                    context.Add("uri", e.Uri);
                    NDjango.TemplateManagerProvider r = new NDjango.TemplateManagerProvider();
                    NDjango.Interfaces.ITemplateManager manager =
                     r.GetNewManager();

                    TextReader tr = manager.RenderTemplate(temp_path, context);

                    view = (tr.ReadToEnd().ToString());
                    if (webView.IsBrowserInitialized)
                        webView.LoadHtml(view);
                }
                catch (Exception ex)
                {

                }
            }
            #else
             //   this.webView.RegisterJsObject("___data", e.Result);
               //     this.webView.ExecuteScript("application.onrecievedata(__data)");
            #endif
        }