예제 #1
0
        protected void Application_Start()
        {
            try
            {
                //AreaRegistration.RegisterAllAreas(); //slow on startup, not neccessary if areas are not used

                RegisterGlobalFilters(GlobalFilters.Filters);
                RegisterRoutes(RouteTable.Routes);

#if DEBUG
                var debug = true;
#else
                var debug = false;
#endif
                var app = new ShowcaseApplication
                {
                    Optimize             = !debug,
                    PreprocessingEnabled = !debug
                };

                app.Initialize();
                DextopApplication.RegisterApplication(app);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                HttpRuntime.UnloadAppDomain();
                throw;
            }
        }
예제 #2
0
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream output)
        {
            var assembly = this.GetType().Assembly;
            var data     = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DemoAttribute>(assembly, false);

            var types = new[] { "js", "cs", "html" };

            foreach (var entry in data)
            {
                var att = entry.Value;
                foreach (var type in types)
                {
                    CreateSourceHtml(att, type);
                }
            }

            var aboutHtml = ReadAndTransformMarkdownFile(DextopUtil.MapPath("~/Demos/About.txt"));

            using (var stream = File.CreateText(DextopUtil.MapPath("~/source/About.html")))
            {
                stream.WriteLine("<html>");
                stream.WriteLine("<head>");
                stream.WriteLine("<link href=\"../client/css/showcase.css\" type=\"text/css\" rel=\"stylesheet\" />");
                stream.WriteLine("<meta name=\"robots\" content=\"noindex\">");
                stream.WriteLine("</head>");
                stream.WriteLine("<body>");
                stream.WriteLine(aboutHtml);
                stream.WriteLine("</body>");
                stream.WriteLine("</html>");
            }
        }
예제 #3
0
        private void RegisterDextopApplication()
        {
            var app = new Application();

            app.Initialize();
            DextopApplication.RegisterApplication(app);
        }
예제 #4
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var sw = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(sw);
                foreach (var model in application.ModelManager.models)
                {
                    WriteModel(jw, model.Value);
                }

                foreach (var a in assemblies)
                {
                    var list = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DextopModelAttribute>(a, false);
                    foreach (var t in list)
                    {
                        if (typeFilter(t.Key, this))
                        {
                            var model = application.ModelManager.BuildModel(t.Key, t.Value);
                            WriteModel(jw, model);
                        }
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Processes the assemblies and generates the code.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="assemblies">The assemblies.</param>
        /// <param name="outputStream">The output stream.</param>
        public void ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream outputStream)
        {
            using (var sw = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(sw);
                foreach (var model in application.ModelManager.models)
                {
                    WriteModel(jw, model.Value);
                }

                foreach (var a in assemblies)
                {
                    var list = AssemblyHelper.GetTypeAttributeDictionaryForAssembly<DextopModelAttribute>(a, false);
                    foreach (var t in list)
                    {
                        var model = application.ModelManager.BuildModel(t.Key, new DextopModelTypeMeta
                        {
                            IdField = t.Value.Id,
                            ModelName = t.Value.Name
                        });
                        WriteModel(jw, model);
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Processes the assemblies and generates the code.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="assemblies">The assemblies.</param>
        /// <param name="outputStream">The output stream.</param>
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream outputStream)
        {
            using (var sw = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(sw);
                foreach (var model in application.ModelManager.models)
                {
                    WriteModel(jw, model.Value);
                }

                foreach (var a in assemblies)
                {
                    var list = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DextopModelAttribute>(a, false);
                    foreach (var t in list)
                    {
                        var model = application.ModelManager.BuildModel(t.Key, new DextopModelTypeMeta
                        {
                            IdField   = t.Value.Id,
                            ModelName = t.Value.Name
                        });
                        WriteModel(jw, model);
                    }
                }
            }
        }
예제 #7
0
        public void ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream output)
        {
            var assembly = this.GetType().Assembly;
            var data = AssemblyHelper.GetTypeAttributeDictionaryForAssembly<DemoAttribute>(assembly, false);

            var types = new[] { "js", "cs", "html" };
            foreach (var entry in data)
            {
                var att = entry.Value;
                foreach (var type in types)
                    CreateSourceHtml(att, type);
            }

            var aboutHtml = ReadAndTransformMarkdownFile(DextopUtil.MapPath("~/Demos/About.txt"));
            using (var stream = File.CreateText(DextopUtil.MapPath("~/source/About.html")))
            {
                stream.WriteLine("<html>");
                stream.WriteLine("<head>");
                stream.WriteLine("<link href=\"../client/css/showcase.css\" type=\"text/css\" rel=\"stylesheet\" />");
                stream.WriteLine("<meta name=\"robots\" content=\"noindex\">");
                stream.WriteLine("</head>");
                stream.WriteLine("<body>");
                stream.WriteLine(aboutHtml);
                stream.WriteLine("</body>");
                stream.WriteLine("</html>");
            }
        }
예제 #8
0
        Request[] GetActionRequest(HttpContext context)
        {
            var stream = UseBufferlessInputStream ? context.Request.GetBufferlessInputStream() : context.Request.InputStream;

            using (stream)
                using (var tr = new StreamReader(stream))
                    using (var jr = new JsonTextReader(tr))
                    {
                        var js = new JsonSerializer();
                        if (!jr.Read())
                        {
                            return(new Request[0]);
                        }
                        if (jr.TokenType == JsonToken.StartObject)
                        {
                            return new[] { js.Deserialize <Request>(jr) }
                        }
                        ;
                        return(js.Deserialize <Request[]>(jr));
                    }
        }

        DextopSession GetSession(HttpContext context)
        {
            var appKey    = context.Request.QueryString["app"];
            var app       = DextopApplication.GetApplication(appKey);
            var sessionId = context.Request.QueryString["sid"];
            var session   = app.GetSession(sessionId);

            return(session);
        }
    }
예제 #9
0
        private void WriteType(DextopApplication application, StreamWriter sw, Type type)
        {
            var typeName = GetTypeName(application, type);

            sw.WriteLine("Ext.define('{0}', {{", typeName);
            sw.WriteLine("\tstatics: {");
            bool first = true;

            foreach (var ev in Enum.GetValues(type))
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sw.WriteLine(",");
                }
                sw.Write("\t\t{0}: {1}", Enum.GetName(type, ev), (int)ev);
            }
            sw.WriteLine();
            sw.WriteLine("\t}");
            sw.WriteLine("});");
            sw.WriteLine();
        }
예제 #10
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList <System.Reflection.Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var w = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(w, DextopJsWriterOptions.Localization);
                foreach (var assembly in assemblies)
                {
                    var formTypes = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DextopFormAttribute>(assembly, false);
                    foreach (var formTypeAttribute in formTypes)
                    {
                        if (typeFilter(formTypeAttribute.Key, this))
                        {
                            var type       = formTypeAttribute.Key;
                            var formFields = DextopFormBuilder.BuildForm(type);
                            var name       = application.MapTypeName(type, ".form");
                            jw.Write("Ext.define('{0}', ", name);
                            jw.StartLocalizationScope();
                            jw.StartBlock();
                            jw.AddProperty("extend", "Dextop.ItemFactory");
                            jw.StartFunctionBlock("getDictionary", "options");
                            jw.WriteLine("options = options || {};");
                            jw.WriteLine("options.data = options.data || {};");
                            jw.WriteLine("var dict = Ext.apply({}, options.apply);");
                            WriteDictRecursively(jw, formFields);
                            jw.WriteLine("return dict;");
                            jw.CloseBlock();
                            jw.StartFunctionBlock("buildItems", "dict");
                            jw.Write("return [");
                            for (var i = 0; i < formFields.Count; i++)
                            {
                                if (i > 0)
                                {
                                    jw.Write(", ");
                                }
                                if (formFields[i].ItemName != null)
                                {
                                    jw.Write("dict['{0}']", formFields[i].ItemName);
                                }
                                else
                                {
                                    jw.WriteObject(formFields[i]);
                                }
                            }
                            jw.Write("];");
                            jw.CloseBlock();//function
                            jw.WriteLocalizations();
                            jw.CloseBlock();
                            jw.WriteLine(");"); //Ext.define(
                            jw.WriteLine();

                            jw.Flush();
                        }
                    }
                }
            }
        }
예제 #11
0
        DextopSession GetSession(HttpContext context)
        {
            var appKey    = context.Request.QueryString["app"];
            var app       = DextopApplication.GetApplication(appKey);
            var sessionId = context.Request.QueryString["sid"];
            var session   = app.GetSession(sessionId);

            return(session);
        }
예제 #12
0
 protected void Application_End()
 {
     try
     {
         var app = DextopApplication.GetApplication();
         app.Dispose();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
     }
 }
예제 #13
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList<System.Reflection.Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var w = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(w, DextopJsWriterOptions.Localization);
                foreach (var assembly in assemblies)
                {
                    var formTypes = AssemblyHelper.GetTypeAttributeDictionaryForAssembly<DextopFormAttribute>(assembly, false);
                    foreach (var formTypeAttribute in formTypes)
                        if (typeFilter(formTypeAttribute.Key, this))
                        {
                            var type = formTypeAttribute.Key;
                            var formFields = DextopFormBuilder.BuildForm(type);
                            var name = application.MapTypeName(type, ".form");
                            jw.Write("Ext.define('{0}', ", name);
                            jw.StartLocalizationScope();
                            jw.StartBlock();
                            jw.AddProperty("extend", "Dextop.ItemFactory");
                            jw.StartFunctionBlock("getDictionary", "options");
                            jw.WriteLine("options = options || {};");
                            jw.WriteLine("options.data = options.data || {};");
                            jw.WriteLine("var dict = Ext.apply({}, options.apply);");
                            WriteDictRecursively(jw, formFields);
                            jw.WriteLine("return dict;");
                            jw.CloseBlock();
                            jw.StartFunctionBlock("buildItems", "dict");
                            jw.Write("return [");
                            for (var i = 0; i < formFields.Count; i++)
                            {
                                if (i > 0)
                                    jw.Write(", ");
                                if (formFields[i].ItemName != null)
                                    jw.Write("dict['{0}']", formFields[i].ItemName);
                                else
                                    jw.WriteObject(formFields[i]);
                            }
                            jw.Write("];");
                            jw.CloseBlock();//function
                            jw.WriteLocalizations();
                            jw.CloseBlock();
                            jw.WriteLine(");"); //Ext.define(
                            jw.WriteLine();

                            jw.Flush();
                        }

                    
                }
            }
        }
예제 #14
0
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var app     = DextopApplication.GetApplication();
            var session = new ShowcaseSession();
            var config  = app.AddSession(session);

            return(View(new Models.DextopAppConfig
            {
                CssFiles = app.GetCssFiles(session.Culture),
                JsFiles = app.GetJsFiles(session.Culture),
                SessionConfig = new HtmlString(DextopUtil.Encode(config))
            }));
        }
        /// <summary>
        /// Loads data from the input stream.
        /// </summary>
        /// <param name="application"></param>
        /// <param name="module"></param>
        /// <param name="inputStream"></param>
        public void Load(DextopApplication application, DextopModule module, Stream inputStream)
        {
            var invoker = application.RemoteMethodInvoker as ReflectionRemoteMethodInvoker;
            if (invoker == null)
                return;

            JsonReader jr = new JsonTextReader(new StreamReader(inputStream));
            var js = new JsonSerializer();
            var constructors = js.Deserialize<List<DextopRemotableConstructorPreprocessor.Constructor>>(jr);

            foreach (var c in constructors)
                invoker.RegisterTypeAlias(c.name, c.type);
        }
예제 #16
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var w = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(w, DextopJsWriterOptions.Localization | DextopJsWriterOptions.ItemFactory);
                foreach (var assembly in assemblies)
                {
                    var headerTypes = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DextopGridAttribute>(assembly, false);

                    foreach (var cap in headerTypes)
                    {
                        if (typeFilter(cap.Key, this))
                        {
                            var type    = cap.Key;
                            var headers = DextopGridManager.BuildHeaders(type);
                            var name    = application.MapTypeName(type, ".columns");
                            jw.Write("Ext.define('{0}', ", name);
                            jw.StartLocalizationScope();
                            jw.StartBlock();
                            jw.AddProperty("extend", "Dextop.ItemFactory");
                            jw.StartFunctionBlock("getDictionary");
                            jw.WriteLine("var dict = {};");
                            WriteDictRecursively(jw, headers);
                            jw.WriteLine("return dict;");
                            jw.CloseBlock();
                            jw.StartFunctionBlock("buildItems", "dict");
                            jw.Write("return [");
                            for (var i = 0; i < headers.Count; i++)
                            {
                                if (i > 0)
                                {
                                    jw.Write(", ");
                                }
                                jw.Write("dict['{0}']", headers[i].id);
                            }
                            jw.Write("];");
                            jw.CloseBlock();//function
                            jw.WriteLocalizations();
                            jw.CloseBlock();
                            jw.WriteLine(");"); //Ext.define(

                            jw.Flush();
                        }
                    }
                }
            }
        }
예제 #17
0
 /// <summary>
 /// Processes the assemblies and generates the code.
 /// </summary>
 /// <param name="application">The application.</param>
 /// <param name="assemblies">The assemblies.</param>
 /// <param name="outputStream">The output stream.</param>
 public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream outputStream)
 {
     using (var sw = new StreamWriter(outputStream))
     {
         foreach (var assembly in assemblies)
         {
             var            types         = assembly.GetTypes().Where(t => remotableInterfaceType.IsAssignableFrom(t) && remotableInterfaceType != t);
             HashSet <Type> includedTypes = new HashSet <Type>();
             foreach (var type in types)
             {
                 WriteType(application, sw, type, includedTypes);
             }
         }
     }
 }
예제 #18
0
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var app     = DextopApplication.GetApplication();
            var session = new App.Session();
            var config  = app.AddSession(session);

            var model = new Models.AppConfig
            {
                CssFiles      = app.GetCssFiles(session.Culture),
                JsFiles       = app.GetJsFiles(session.Culture),
                SessionConfig = DextopUtil.Encode(config)
            };

            return(View(model));
        }
 /// <summary>
 /// Processes the assemblies and generates the code.
 /// </summary>
 /// <param name="application">The application.</param>
 /// <param name="assemblies">The assemblies.</param>
 /// <param name="outputStream">The output stream.</param>
 public void ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream outputStream)
 {
     using (var sw = new StreamWriter(outputStream))
     {
         foreach (var assembly in assemblies)
         {
             var types = assembly.GetTypes().Where(t => remotableInterfaceType.IsAssignableFrom(t) && remotableInterfaceType != t);
             HashSet<Type> includedTypes = new HashSet<Type>();
             foreach (var type in types)
             {
                 WriteType(application, sw, type, includedTypes);
             }
         }
     }
 }
예제 #20
0
        void IDextopAssemblyPreprocessor.LoadCache(DextopApplication application, IList <Assembly> assemblies, Stream cacheStream)
        {
            using (var tr = new StreamReader(cacheStream))
            {
                String line;
                while ((line = tr.ReadLine()) != null)
                {
                    var colon = line.IndexOf(':');
                    var id    = line.Substring(0, colon);
                    var type  = line.Substring(colon + 1);

                    ((ShowcaseApplication)application).RegisterDemo(id, Type.GetType(type));
                }
            }
        }
예제 #21
0
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream output)
        {
            BaseSrcPath = DextopUtil.MapPath("~/guides/articles/");
            OutputPath  = DextopUtil.MapPath("~/guides/html/");

            var articles = ProcessDirectory(BaseSrcPath);

            using (var tw = new StreamWriter(output))
            {
                tw.WriteLine("Ext.ns('Showcase');");
                tw.Write("Showcase.Guides = ");
                tw.Write(DextopUtil.Encode(articles.ToArray()));
                tw.WriteLine(";");
            }
        }
 void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream outputStream, Stream cacheStream)
 {
     using (var sw = new StreamWriter(outputStream))
     {
         foreach (var assembly in assemblies)
         {
             var types = Common.Reflection.AssemblyHelper.GetTypeAttributeDictionaryForAssembly<DextopEnumAttribute>(assembly, false);
             foreach (var type in types)
                 if (type.Key.IsEnum)
                 {
                     WriteType(application, sw, type.Key);
                 }
         }
     }
 }
예제 #23
0
        public void ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream output, Stream cache)
        {
            BaseSrcPath = DextopUtil.MapPath("~/guides/articles/");
            OutputPath = DextopUtil.MapPath("~/guides/html/");

            var articles = ProcessDirectory(BaseSrcPath);

            using (var tw = new StreamWriter(output))
            {
                tw.WriteLine("Ext.ns('Showcase');");
                tw.Write("Showcase.Guides = ");
                tw.Write(DextopUtil.Encode(articles.ToArray()));
                tw.WriteLine(";");
            }
        }
예제 #24
0
        void IDextopAssemblyPreprocessor.LoadCache(DextopApplication application, IList<Assembly> assemblies, Stream cacheStream)
        {
            using (var tr = new StreamReader(cacheStream))
            {
                String line;
                while ((line = tr.ReadLine()) != null)
                {
                    var colon = line.IndexOf(':');
                    var id = line.Substring(0, colon);
                    var type = line.Substring(colon + 1);

                    ((ShowcaseApplication)application).RegisterDemo(id, Type.GetType(type));
                }
            }
        }
 void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream outputStream, Stream cacheStream)
 {
     using (var cacheWriter = new StreamWriter(cacheStream))
     using (var sw = new StreamWriter(outputStream))
     {
         foreach (var assembly in assemblies)
         {
             var types = assembly.GetTypes().Where(t => apiControllerType.IsAssignableFrom(t) && apiControllerType != t);
             HashSet<Type> includedTypes = new HashSet<Type>();
             foreach (var type in types)
             {
                 WriteType(application, sw, cacheWriter, type, includedTypes);
             }
         }
     }
 }
예제 #26
0
 /// <summary>
 /// Processes the assemblies and generates the code.
 /// </summary>
 /// <param name="application">The application.</param>
 /// <param name="assemblies">The assemblies.</param>
 /// <param name="outputStream">The output stream.</param>
 public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream outputStream)
 {
     using (var sw = new StreamWriter(outputStream))
     {
         foreach (var assembly in assemblies)
         {
             var types = Common.Reflection.AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DextopEnumAttribute>(assembly, false);
             foreach (var type in types)
             {
                 if (type.Key.IsEnum)
                 {
                     WriteType(application, sw, type.Key);
                 }
             }
         }
     }
 }
 /// <summary>
 /// Processes the assemblies and generates the code.
 /// </summary>
 /// <param name="application">The application.</param>
 /// <param name="assemblies">The assemblies.</param>
 /// <param name="outputStream">The output stream.</param>
 public void ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream outputStream)
 {
     List<Constructor> data = new List<Constructor>();
     using (var sw = new StreamWriter(outputStream))
     {
         foreach (var assembly in assemblies)
         {
             var types = assembly.GetTypes().Where(t => remotableInterfaceType.IsAssignableFrom(t) && remotableInterfaceType != t);
             HashSet<Type> includedTypes = new HashSet<Type>();
             foreach (var type in types)
             {
                 WriteType(application, sw, type, data);
             }
         }
         sw.WriteLine(JsonConvert.SerializeObject(data, Formatting.Indented));
     }
 }
예제 #28
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var w = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(w, DextopJsWriterOptions.Localization | DextopJsWriterOptions.ItemFactory);
                foreach (var assembly in assemblies)
                {
                    var headerTypes = AssemblyHelper.GetTypeAttributeDictionaryForAssembly<DextopGridAttribute>(assembly, false);

                    foreach (var cap in headerTypes)
                        if (typeFilter(cap.Key, this))
                        {
                            var type = cap.Key;
                            var headers = DextopGridManager.BuildHeaders(type);
                            var name = application.MapTypeName(type, ".columns");
                            jw.Write("Ext.define('{0}', ", name);
                            jw.StartLocalizationScope();
                            jw.StartBlock();
                            jw.AddProperty("extend", "Dextop.ItemFactory");
                            jw.StartFunctionBlock("getDictionary");
                            jw.WriteLine("var dict = {};");
                            WriteDictRecursively(jw, headers);
                            jw.WriteLine("return dict;");
                            jw.CloseBlock();
                            jw.StartFunctionBlock("buildItems", "dict");
                            jw.Write("return [");
                            for (var i = 0; i < headers.Count; i++)
                            {
                                if (i > 0)
                                    jw.Write(", ");
                                jw.Write("dict['{0}']", headers[i].id);
                            }
                            jw.Write("];");
                            jw.CloseBlock();//function
                            jw.WriteLocalizations();
                            jw.CloseBlock();
                            jw.WriteLine(");"); //Ext.define(

                            jw.Flush();
                        }
                }
            }
        }
예제 #29
0
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var app     = DextopApplication.GetApplication();
            var session = new ShowcaseSession();
            var config  = app.AddSession(session);

            if (!String.IsNullOrEmpty(Request.QueryString["culture"]))
            {
                session.Culture = new System.Globalization.CultureInfo(Request.QueryString["culture"]);
            }

            return(View(new Models.DextopAppConfig
            {
                CssFiles = app.GetCssFiles(session.Culture),
                JsFiles = app.GetJsFiles(session.Culture),
                SessionConfig = new HtmlString(DextopUtil.Encode(config))
            }));
        }
예제 #30
0
        /// <summary>
        /// Loads data from the input stream.
        /// </summary>
        /// <param name="application"></param>
        /// <param name="module"></param>
        /// <param name="inputStream"></param>
        public void Load(DextopApplication application, DextopModule module, Stream inputStream)
        {
            var invoker = application.RemoteMethodInvoker as ReflectionRemoteMethodInvoker;

            if (invoker == null)
            {
                return;
            }

            JsonReader jr           = new JsonTextReader(new StreamReader(inputStream));
            var        js           = new JsonSerializer();
            var        constructors = js.Deserialize <List <DextopRemotableConstructorPreprocessor.Constructor> >(jr);

            foreach (var c in constructors)
            {
                invoker.RegisterTypeAlias(c.name, c.type);
            }
        }
예제 #31
0
        /// <summary>
        /// Processes the assemblies and generates the code.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="assemblies">The assemblies.</param>
        /// <param name="outputStream">The output stream.</param>
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream outputStream)
        {
            List <Constructor> data = new List <Constructor>();

            using (var sw = new StreamWriter(outputStream))
            {
                foreach (var assembly in assemblies)
                {
                    var            types         = assembly.GetTypes().Where(t => remotableInterfaceType.IsAssignableFrom(t) && remotableInterfaceType != t);
                    HashSet <Type> includedTypes = new HashSet <Type>();
                    foreach (var type in types)
                    {
                        WriteType(application, sw, type, data);
                    }
                }
                sw.WriteLine(JsonConvert.SerializeObject(data, Formatting.Indented));
            }
        }
예제 #32
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var cacheWriter = new StreamWriter(cacheStream))
            using (var sw = new StreamWriter(outputStream))
            {
                foreach (var assembly in assemblies)
                {
                    var types = assembly.GetTypes().Where(t => remotableInterfaceType.IsAssignableFrom(t) && remotableInterfaceType != t);
                    HashSet<Type> includedTypes = new HashSet<Type>();
                    foreach (var type in types)
                        if (typeFilter(type, this))
                        {
                            WriteType(application, sw, cacheWriter, type, includedTypes);
                        }
                }
            }
        }
예제 #33
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var sw = new StreamWriter(outputStream))
            {
                foreach (var assembly in assemblies)
                {
                    var types = Common.Reflection.AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DextopEnumAttribute>(assembly, false);
                    foreach (var type in types)
                    {
                        if (typeFilter(type.Key, this) && type.Key.IsEnum)
                        {
                            WriteType(application, sw, type.Key);
                        }
                    }
                }
            }
        }
예제 #34
0
		private void WriteType(DextopApplication application, StreamWriter sw, Type type)
		{
			var typeName = GetTypeName(application, type);

			sw.WriteLine("Ext.define('{0}', {{", typeName);
			sw.WriteLine("\tstatics: {");
			bool first = true;
			foreach (var ev in Enum.GetValues(type))
			{
				if (first)
					first = false;
				else
					sw.WriteLine(",");
				sw.Write("\t\t{0}: {1}", Enum.GetName(type, ev), (int)ev);
			}
			sw.WriteLine();
			sw.WriteLine("\t}");
			sw.WriteLine("});");
			sw.WriteLine();
		}
예제 #35
0
        protected void Application_Start()
        {
            try
            {
                AreaRegistration.RegisterAllAreas();

                RegisterGlobalFilters(GlobalFilters.Filters);
                RegisterRoutes(RouteTable.Routes);

                var app = new ShowcaseApplication();
                app.Initialize();

                DextopApplication.RegisterApplication(app);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                HttpRuntime.UnloadAppDomain();
                throw;
            }
        }
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            using (var sw = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(sw);
                foreach (var model in application.ModelManager.models)
                {
                    WriteModel(jw, model.Value);
                }

                foreach (var a in assemblies)
                {
                    var list = AssemblyHelper.GetTypeAttributeDictionaryForAssembly<DextopModelAttribute>(a, false);
                    foreach (var t in list)
                    {
                        var model = application.ModelManager.BuildModel(t.Key, t.Value);
                        WriteModel(jw, model);
                    }
                }
            }
        }
        private void WriteType(DextopApplication application, StreamWriter sw, Type type, List<Constructor> data)
        {
            var typeName = GetTypeName(application, type);

            foreach (var mi in type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                DextopRemotableAttribute ra;
                if (AttributeHelper.TryGetAttribute<DextopRemotableAttribute>(mi, out ra, false))
                {
                    String alias = null;
                    var rac = ra as DextopRemotableConstructorAttribute;
                    if (rac!=null)
                        alias = rac.alias;
                    data.Add(new Constructor
                    {
                        name = alias ?? application.MapTypeName(type),
                        type = type.AssemblyQualifiedName
                    });
                }
            }
        }
        void IDextopAssemblyPreprocessor.LoadCache(DextopApplication application, IList<Assembly> assemblies, Stream cacheStream)
        {
            var invoker = application.RemoteMethodInvoker as ReflectionRemoteMethodInvoker;
            if (invoker == null)
                return;

            using (var tr = new StreamReader(cacheStream))
            {
                String line;
                while ((line = tr.ReadLine()) != null)
                {
                    var colon = line.IndexOf(':');
                    var id = line.Substring(0, colon);
                    var type = line.Substring(colon + 1);

                    if (id.StartsWith(routePrefix))
                        invoker.RegisterTypeRoute(id.Substring(routePrefix.Length), type);
                    else
                        invoker.RegisterTypeAlias(id, type);
                }
            }
        }
예제 #39
0
        void IDextopAssemblyPreprocessor.LoadCache(DextopApplication application, IList<Assembly> assemblies, Stream cacheStream)
        {
            var invoker = application.RemoteMethodInvoker as ReflectionRemoteMethodInvoker;
            if (invoker == null)
                return;

            using (var tr = new StreamReader(cacheStream))
            {
                String line;
                while ((line = tr.ReadLine()) != null)
                {
                    var colon = line.IndexOf(':');
                    var id = line.Substring(0, colon);
                    var type = line.Substring(colon + 1);

                    if (id.StartsWith(routePrefix))
                        invoker.RegisterTypeRoute(id.Substring(routePrefix.Length), type);
                    else
                        invoker.RegisterTypeAlias(id, type);
                }
            }
        }
예제 #40
0
        private void WriteType(DextopApplication application, StreamWriter sw, Type type, List <Constructor> data)
        {
            var typeName = GetTypeName(application, type);

            foreach (var mi in type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                DextopRemotableAttribute ra;
                if (AttributeHelper.TryGetAttribute <DextopRemotableAttribute>(mi, out ra, false))
                {
                    String alias = null;
                    var    rac   = ra as DextopRemotableConstructorAttribute;
                    if (rac != null)
                    {
                        alias = rac.alias;
                    }
                    data.Add(new Constructor
                    {
                        name = alias ?? application.MapTypeName(type),
                        type = type.AssemblyQualifiedName
                    });
                }
            }
        }
예제 #41
0
        protected void Application_Start()
        {
            try
            {
                //AreaRegistration.RegisterAllAreas(); //slow on startup, not neccessary if areas are not used

                RegisterGlobalFilters(GlobalFilters.Filters);
                RegisterRoutes(RouteTable.Routes);

                InitDextopApi();

#if DEBUG
                var debug = true;
#else
                var debug = false;
#endif
                var app = new ShowcaseApplication
                {
                    Optimize             = !debug,
                    PreprocessingEnabled = !debug
                };

                using (var bm = new Codaxy.Common.Benchmarking.BenchmarkStopwatch())
                {
                    app.Initialize();
                    Debug.WriteLine("Dextop application init time: " + bm.Elapsed.TotalMilliseconds + " ms");
                }
                DextopApplication.RegisterApplication(app);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                HttpRuntime.UnloadAppDomain();
                throw;
            }
        }
 internal string GetTypeName(DextopApplication application, Type type)
 {
     var name = application.MapTypeName(type);
     return DextopUtil.GetRemotingProxyTypeName(name);
 }
 void IDextopAssemblyPreprocessor.LoadCache(DextopApplication application, IList<Assembly> assemblies, Stream cacheStream)
 {
 }
        private void WriteType(DextopApplication application, StreamWriter sw, StreamWriter cacheWriter, Type controllerType, HashSet<Type> includedTypes)
        {
            if (includedTypes.Contains(controllerType))
                return;

            if (controllerType.IsGenericType)
                return;

            includedTypes.Add(controllerType);
            String modelType = null;

            var typeName = GetTypeName(application, controllerType);

            List<Type> genericBaseTypes = new List<Type>();

            var baseType = controllerType.BaseType;

            while (baseType != null && baseType.IsGenericType)
            {
                genericBaseTypes.Add(baseType);
                baseType = baseType.BaseType;
            }

            if (baseType != null && controllerType.Assembly == baseType.Assembly)
                WriteType(application, sw, cacheWriter, baseType, includedTypes);

            sw.WriteLine("Ext.define('{0}', {{", typeName);

            if (baseType != null && baseType != apiControllerType)
            {
                sw.WriteLine("\textend: '{0}',", GetTypeName(application, baseType));
            }
            else
            {
                sw.WriteLine("\textend: 'Dextop.api.ApiController',");
            }

            sw.Write("\tcontrollerType: '{0}'", String.Format("{0}, {1}", controllerType.FullName, controllerType.Assembly.GetName().Name));

            DextopApiControllerAliasAttribute aliasAtt;
            if (AttributeHelper.TryGetAttribute(controllerType, out aliasAtt, false))
            {
                sw.WriteLine(",");
                sw.Write("\talias: 'api.{0}'", aliasAtt.Alias);
            }

            var interfaces = controllerType.GetInterfaces();
            var proxyInterface = interfaces.FirstOrDefault(x => x.IsGenericType && typeof(IDextopReadProxy<>).IsAssignableFrom(x.GetGenericTypeDefinition()));

            if (proxyInterface!=null)
            {
                sw.WriteLine(",");
                modelType = application.MapTypeName(proxyInterface.GetGenericArguments()[0], ".model");
                sw.Write("\tmodel: '{0}'", modelType);
            }

            foreach (var mi in controllerType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                if (mi.DeclaringType == controllerType || genericBaseTypes.Contains(mi.DeclaringType))
                {
                    var methodName = mi.Name;
                    sw.WriteLine(",");
                    var parameters = mi.GetParameters();
                    var upload = parameters.Any(a => a.ParameterType == formSubmitType);
                    if (upload)
                    {
                        if (parameters.Length == 0 || parameters[0].ParameterType != formSubmitType)
                            throw new Exception("Form submit methods must have first parameter of type DextopFormSubmit.");
                        sw.Write("\t{0}: function(", methodName);
                        for (var i = 0; i < parameters.Length; i++)
                        {
                            sw.Write(parameters[i].Name);
                            sw.Write(", ");
                        }
                        sw.Write("callback, scope");
                        sw.Write(") {{ this.submitForm(callback, scope, '{0}', {1}, [", methodName, parameters[0].Name);
                        if (parameters.Length > 1)
                        {
                            sw.Write(parameters[1].Name);
                            for (var i = 2; i < parameters.Length; i++)
                            {
                                sw.Write(", ");
                                sw.Write(parameters[i].Name);
                            }
                        }
                        sw.Write("]);}");
                    }
                    else
                    {
                        sw.Write("\t{0}: function(", methodName);
                        for (var i = 0; i < parameters.Length; i++)
                        {
                            sw.Write(parameters[i].Name);
                            sw.Write(", ");
                        }
                        sw.Write("callback, scope");
                        sw.Write(") {{ this.invokeRemoteMethod(callback, scope, '{0}', [", methodName);
                        if (parameters.Length > 0)
                        {
                            sw.Write(parameters[0].Name);
                            for (var i = 1; i < parameters.Length; i++)
                            {
                                sw.Write(", ");
                                sw.Write(parameters[i].Name);
                            }
                        }
                        sw.Write("]);}");
                    }
                }
            }

            sw.WriteLine();
            sw.WriteLine("});");
            sw.WriteLine();

            DextopApiStoreAttribute storeAttribute;
            if (AttributeHelper.TryGetAttribute(controllerType, out storeAttribute, false))
            {
                if (modelType == null)
                    throw new DextopException("Could not generate data store of type '{0}' as it does not implement data proxy interface.", apiControllerType);

                sw.WriteLine("Ext.onReady(function() {{ Ext.create('Ext.data.Store', {{", typeName);
                sw.WriteLine("\t\tstoreId: '{0}',", storeAttribute.StoreId);
                sw.WriteLine("\t\tmodel: '{0}',", modelType);
                sw.WriteLine("\t\tproxy: {{ type: 'api', api: '{0}' }},", typeName);
                sw.WriteLine("\t\tautoLoad: {0}", storeAttribute.autoLoad ? "true" : "false");
                sw.WriteLine("\t});");
                sw.WriteLine("});");
                sw.WriteLine();
            }
        }
예제 #45
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var cacheWriter = new StreamWriter(cacheStream))
            using (var sw = new StreamWriter(outputStream))
            {
                foreach (var assembly in assemblies)
                {
                    var types = assembly.GetTypes().Where(t => remotableInterfaceType.IsAssignableFrom(t) && remotableInterfaceType != t);
                    HashSet<Type> includedTypes = new HashSet<Type>();
                    foreach (var type in types)
                        if (typeFilter(type, this))
                        {
                            WriteType(application, sw, cacheWriter, type, includedTypes);
                        }
                }
            }
        }
예제 #46
0
        internal string GetTypeName(DextopApplication application, Type type)
        {
			var name = application.MapTypeName(type);
			return name;
        }
예제 #47
0
 internal string GetTypeName(DextopApplication application, Type type)
 {
     var name = application.MapTypeName(type);
     return DextopUtil.GetRemotingProxyTypeName(name);
 }
예제 #48
0
        public void ProcessAssemblies(DextopApplication application, IList<Assembly> assemblies, Stream output)
        {
            using (var tw = new StreamWriter(output))
            {
                DextopJsWriter jw = new DextopJsWriter(tw);
                var assembly = this.GetType().Assembly;
                var data = AssemblyHelper.GetTypeAttributeDictionaryForAssembly<DemoAttribute>(assembly, false);
                jw.ExtNamespace("Showcase");
                jw.Write("Showcase.Demos = [");
                bool first = true;

                HashSet<String> levels = new HashSet<string>();
                HashSet<String> categories = new HashSet<string>();
                HashSet<String> topics = new HashSet<string>();

                foreach (var entry in data)
                {
                    var att = entry.Value;
                    if (first)
                        first = false;
                    else
                        jw.Write(", ");
                    jw.StartBlock();
                    jw.AddProperty("id", att.Id);
                    jw.DefaultProperty("title", att.Title);
                    jw.DefaultProperty("description", att.Description);
                    jw.AddProperty("clientLauncher", att.ClientLauncher);
                    LevelAttribute level;
                    if (AttributeHelper.TryGetAttribute<LevelAttribute>(entry.Key, out level, false))
                        jw.AddProperty("level", level.Name);
                    TopicAttribute topic;
                    if (AttributeHelper.TryGetAttribute<TopicAttribute>(entry.Key, out topic, false))
                        jw.AddProperty("topic", topic.Name);
                    CategoryAttribute cat;
                    if (AttributeHelper.TryGetAttribute<CategoryAttribute>(entry.Key, out cat, false))
                        jw.AddProperty("category", cat.Name);

                    jw.AddProperty("sourceUrlBase", DextopUtil.AbsolutePath(String.Format("source/{0}", att.Id)));
                    jw.AddProperty("cacheBuster", GetCacheBuster(att));

                    jw.CloseBlock();
                    ((ShowcaseApplication)application).RegisterDemo(att.Id, entry.Key);

                    if (!levels.Contains(level.Name))
                        levels.Add(level.Name);

                    if (!topics.Contains(topic.Name))
                        topics.Add(topic.Name);

                    if (!categories.Contains(cat.Name))
                        categories.Add(cat.Name);
                }
                jw.WriteLine("];");
                jw.WriteLine();
                jw.Write("Showcase.Topics = ");
                jw.Write(DextopUtil.Encode(topics.ToArray()));
                jw.WriteLine(";");
                jw.WriteLine();
                jw.Write("Showcase.Levels = ");
                jw.Write(DextopUtil.Encode(levels.ToArray()));
                jw.WriteLine(";");
                jw.WriteLine();
                jw.Write("Showcase.Categories = ");
                jw.Write(DextopUtil.Encode(categories.ToArray()));
                jw.WriteLine(";");
            }
        }
예제 #49
0
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream output)
        {
            using (var tw = new StreamWriter(output))
            {
                DextopJsWriter jw       = new DextopJsWriter(tw);
                var            assembly = this.GetType().Assembly;
                var            data     = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DemoAttribute>(assembly, false);
                jw.ExtNamespace("Showcase");
                jw.Write("Showcase.Demos = [");
                bool first = true;

                HashSet <String> levels     = new HashSet <string>();
                HashSet <String> categories = new HashSet <string>();
                HashSet <String> topics     = new HashSet <string>();

                foreach (var entry in data)
                {
                    var att = entry.Value;
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        jw.Write(", ");
                    }
                    jw.StartBlock();
                    jw.AddProperty("id", att.Id);
                    jw.DefaultProperty("title", att.Title);
                    jw.DefaultProperty("description", att.Description);
                    jw.AddProperty("clientLauncher", att.ClientLauncher);
                    LevelAttribute level;
                    if (AttributeHelper.TryGetAttribute <LevelAttribute>(entry.Key, out level, false))
                    {
                        jw.AddProperty("level", level.Name);
                    }
                    TopicAttribute topic;
                    if (AttributeHelper.TryGetAttribute <TopicAttribute>(entry.Key, out topic, false))
                    {
                        jw.AddProperty("topic", topic.Name);
                    }
                    CategoryAttribute cat;
                    if (AttributeHelper.TryGetAttribute <CategoryAttribute>(entry.Key, out cat, false))
                    {
                        jw.AddProperty("category", cat.Name);
                    }

                    jw.AddProperty("sourceUrlBase", DextopUtil.AbsolutePath(String.Format("source/{0}", att.Id)));
                    jw.AddProperty("cacheBuster", GetCacheBuster(att));

                    jw.CloseBlock();
                    ((ShowcaseApplication)application).RegisterDemo(att.Id, entry.Key);

                    if (!levels.Contains(level.Name))
                    {
                        levels.Add(level.Name);
                    }

                    if (!topics.Contains(topic.Name))
                    {
                        topics.Add(topic.Name);
                    }

                    if (!categories.Contains(cat.Name))
                    {
                        categories.Add(cat.Name);
                    }
                }
                jw.WriteLine("];");
                jw.WriteLine();
                jw.Write("Showcase.Topics = ");
                jw.Write(DextopUtil.Encode(topics.ToArray()));
                jw.WriteLine(";");
                jw.WriteLine();
                jw.Write("Showcase.Levels = ");
                jw.Write(DextopUtil.Encode(levels.ToArray()));
                jw.WriteLine(";");
                jw.WriteLine();
                jw.Write("Showcase.Categories = ");
                jw.Write(DextopUtil.Encode(categories.ToArray()));
                jw.WriteLine(";");
            }
        }
예제 #50
0
 void IDextopAssemblyPreprocessor.LoadCache(DextopApplication application, IList <Assembly> assemblies, Stream cacheStream)
 {
     throw new NotSupportedException();
 }
        private void WriteType(DextopApplication application, StreamWriter sw, StreamWriter cacheWriter, Type type, HashSet<Type> includedTypes)
        {
            if (includedTypes.Contains(type))
                return;

            includedTypes.Add(type);

            var typeName = GetTypeName(application, type);

            if (type.BaseType != null && remotableInterfaceType.IsAssignableFrom(type.BaseType) && type.Assembly == type.BaseType.Assembly)
                WriteType(application, sw, cacheWriter, type.BaseType, includedTypes);

            sw.WriteLine("Ext.define('{0}', {{", typeName);

            if (type.BaseType != null && remotableInterfaceType.IsAssignableFrom(type.BaseType))
            {
                sw.Write("\textend: '{0}'", GetTypeName(application, type.BaseType));
            }
            else
            {
                sw.Write("\textend: 'Dextop.remoting.Proxy'");
            }

            bool constructor = false;

            bool firstMethod = !constructor;

            var clientTypeName = application.MapTypeName(type);
            var routes = new List<String>();

            foreach (var mi in type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                DextopRemotableAttribute ra;
                if (AttributeHelper.TryGetAttribute<DextopRemotableAttribute>(mi, out ra, false))
                {

                    ReflectionRemoteMethodInvoker.CacheConstructorInfo(clientTypeName, mi, ra);
                    var ca = ra as DextopRemotableConstructorAttribute;
                    if (ca != null)
                    {
                        if (!String.IsNullOrEmpty(ca.alias))
                            cacheWriter.WriteLine("{0}:{1}", ca.alias, type.AssemblyQualifiedName);
                        if (!String.IsNullOrEmpty(ca.route))
                            cacheWriter.WriteLine("{0}{1}:{2}", routePrefix, ca.route, type.AssemblyQualifiedName);
                    }
                }
            }

            cacheWriter.WriteLine("{0}:{1}", clientTypeName, type.AssemblyQualifiedName);

            foreach (var mi in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                DextopRemotableAttribute ra;
                if (AttributeHelper.TryGetAttribute<DextopRemotableAttribute>(mi, out ra, false))
                {
                    ReflectionRemoteMethodInvoker.CacheMethodInfo(mi, ra);

                    if (mi.DeclaringType == type)
                    {
                        var methodName = mi.Name;
                        sw.WriteLine(",");
                        var parameters = mi.GetParameters();
                        var upload = parameters.Any(a => a.ParameterType == formSubmitType);
                        if (upload)
                        {
                            if (parameters.Length == 0 || parameters[0].ParameterType != formSubmitType)
                                throw new Exception("Form submit methods must have first parameter of type DextopFormSubmit.");
                            sw.Write("\t{0}: function(", methodName);
                            for (var i = 0; i < parameters.Length; i++)
                            {
                                sw.Write(parameters[i].Name);
                                sw.Write(", ");
                            }
                            sw.Write("callback, scope");
                            sw.Write(") {{ this.submitForm(callback, scope, '{0}', {1}, [", methodName, parameters[0].Name);
                            if (parameters.Length > 1)
                            {
                                sw.Write(parameters[1].Name);
                                for (var i = 2; i < parameters.Length; i++)
                                {
                                    sw.Write(", ");
                                    sw.Write(parameters[i].Name);
                                }
                            }
                            sw.Write("]);}");
                        }
                        else
                        {
                            sw.Write("\t{0}: function(", methodName);
                            for (var i = 0; i < parameters.Length; i++)
                            {
                                sw.Write(parameters[i].Name);
                                sw.Write(", ");
                            }
                            sw.Write("callback, scope");
                            sw.Write(") {{ this.invokeRemoteMethod(callback, scope, '{0}', [", methodName);
                            if (parameters.Length > 0)
                            {
                                sw.Write(parameters[0].Name);
                                for (var i = 1; i < parameters.Length; i++)
                                {
                                    sw.Write(", ");
                                    sw.Write(parameters[i].Name);
                                }
                            }
                            sw.Write("]);}");
                        }
                    }
                }
            }

            sw.WriteLine();
            sw.WriteLine("});");
            sw.WriteLine();
        }
예제 #52
0
 internal DextopModelManager(DextopApplication application)
 {
     Application = application;
 }
 void IDextopAssemblyPreprocessor.LoadCache(DextopApplication application, IList<Assembly> assemblies, Stream cacheStream)
 {
     throw new NotSupportedException();
 }
예제 #54
0
        private void WriteType(DextopApplication application, StreamWriter sw, StreamWriter cacheWriter, Type type, HashSet<Type> includedTypes)
        {
            if (includedTypes.Contains(type))
                return;

            includedTypes.Add(type);

            var typeName = GetTypeName(application, type);

            if (type.BaseType != null && remotableInterfaceType.IsAssignableFrom(type.BaseType) && type.Assembly == type.BaseType.Assembly)
                WriteType(application, sw, cacheWriter, type.BaseType, includedTypes);

            sw.WriteLine("Ext.define('{0}', {{", typeName);

            if (type.BaseType != null && remotableInterfaceType.IsAssignableFrom(type.BaseType))
            {
                sw.Write("\textend: '{0}'", GetTypeName(application, type.BaseType));
            }
            else
            {
                sw.Write("\textend: 'Dextop.remoting.Proxy'");
            }

            bool constructor = false;

            bool firstMethod = !constructor;

            var clientTypeName = application.MapTypeName(type);
            var routes = new List<String>();

            foreach (var mi in type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                DextopRemotableAttribute ra;
                if (AttributeHelper.TryGetAttribute<DextopRemotableAttribute>(mi, out ra, false))
                {

                    ReflectionRemoteMethodInvoker.CacheConstructorInfo(clientTypeName, mi, ra);
                    var ca = ra as DextopRemotableConstructorAttribute;
                    if (ca != null)
                    {
                        if (!String.IsNullOrEmpty(ca.alias))
                            cacheWriter.WriteLine("{0}:{1}", ca.alias, type.AssemblyQualifiedName);
                        if (!String.IsNullOrEmpty(ca.route))
                            cacheWriter.WriteLine("{0}{1}:{2}", routePrefix, ca.route, type.AssemblyQualifiedName);
                    }
                }
            }

            cacheWriter.WriteLine("{0}:{1}", clientTypeName, type.AssemblyQualifiedName);
            cacheWriter.Flush();

            foreach (var mi in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                DextopRemotableAttribute ra;
                if (AttributeHelper.TryGetAttribute<DextopRemotableAttribute>(mi, out ra, false))
                {
                    ReflectionRemoteMethodInvoker.CacheMethodInfo(mi, ra);

                    if (mi.DeclaringType == type)
                    {
                        var methodName = mi.Name;
                        sw.WriteLine(",");
                        var parameters = mi.GetParameters();
                        var upload = parameters.Any(a => a.ParameterType == formSubmitType);
                        if (upload)
                        {
                            if (parameters.Length == 0 || parameters[0].ParameterType != formSubmitType)
                                throw new Exception("Form submit methods must have first parameter of type DextopFormSubmit.");
                            sw.Write("\t{0}: function(", methodName);
                            for (var i = 0; i < parameters.Length; i++)
                            {
                                sw.Write(parameters[i].Name);
                                sw.Write(", ");
                            }
                            sw.Write("callback, scope");
                            sw.Write(") {{ this.submitForm(callback, scope, '{0}', {1}, [", methodName, parameters[0].Name);
                            if (parameters.Length > 1)
                            {
                                sw.Write(parameters[1].Name);
                                for (var i = 2; i < parameters.Length; i++)
                                {
                                    sw.Write(", ");
                                    sw.Write(parameters[i].Name);
                                }
                            }
                            sw.Write("]);}");
                        }
                        else
                        {
                            sw.Write("\t{0}: function(", methodName);
                            for (var i = 0; i < parameters.Length; i++)
                            {
                                sw.Write(parameters[i].Name);
                                sw.Write(", ");
                            }
                            sw.Write("callback, scope");
                            sw.Write(") {{ this.invokeRemoteMethod(callback, scope, '{0}', [", methodName);
                            if (parameters.Length > 0)
                            {
                                sw.Write(parameters[0].Name);
                                for (var i = 1; i < parameters.Length; i++)
                                {
                                    sw.Write(", ");
                                    sw.Write(parameters[i].Name);
                                }
                            }
                            sw.Write("]);}");
                        }
                    }
                }
            }

            sw.WriteLine();
            sw.WriteLine("});");
            sw.WriteLine();
            sw.Flush();
        }